blob: eef91c6855aa0ec4328819f17ed4d161c2867920 [file] [log] [blame]
lh7b0674a2022-01-10 00:34:35 -08001#include <stdio.h>
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <arpa/inet.h>
5#include <fcntl.h>
6#include <string.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <binder/Parcel.h>
10#include <log/log.h>
lh7b0674a2022-01-10 00:34:35 -080011#include <cutils/jstring.h>
12#include <pthread.h>
13#include "liblog/lynq_deflog.h"
lh2afc7732022-01-10 02:24:31 -080014#include <sys/time.h>
lh21502f52022-01-27 00:27:12 -080015#include <string.h>
q.huang714145d2022-04-18 00:09:50 -040016#include <vendor-ril/telephony/ril.h>
17#include <vendor-ril/telephony/mtk_ril_sp.h>
18#include <vendor-ril/telephony/mtk_ril_ivt.h>
19#include "lynq_call.h"
20
21
lh7b0674a2022-01-10 00:34:35 -080022#define LYNQ_SERVICE_PORT 8088
rjw5d2a50e2022-02-28 15:01:49 +080023#define DSET_IP_ADDRESS "127.0.0.1"
lh7b0674a2022-01-10 00:34:35 -080024#define LYNQ_URC_SERVICE_PORT 8086
25#define LYNQ_REC_BUF 8192
26#define LYNQ_REQUEST_PARAM_BUF 8192
27#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
28#define USER_LOG_TAG "LYNQ_CALL"
29
30using ::android::Parcel;
31 typedef enum {
32 LYNQ_CALL_ACTIVE = 0,
33 LYNQ_CALL_HOLDING = 1,
34 LYNQ_CALL_DIALING = 2, /* MO call only */
35 LYNQ_CALL_ALERTING = 3, /* MO call only */
36 LYNQ_CALL_INCOMING = 4, /* MT call only */
37 LYNQ_CALL_WAITING = 5 ,/* MT call only */
38}lynq_call_state_t;
39
40typedef struct{
41 int uToken;
42 int request;
43 int paramLen;
44 char param[LYNQ_REQUEST_PARAM_BUF];
45}lynq_client_t;
46typedef struct
47{
48 int used;
49 int call_id;
50 int call_state;
51 int toa;
52 int direction;/*0: MO call,1:MT call*/
53 char addr[LYNQ_PHONE_NUMBER_MAX];
54 int hasTimeout;
55}lynq_call_list_e_t;
56typedef struct
57{
58 int call_id;
59 int call_state;
60 int toa;
61 int direction;/*0: MO call,1:MT call*/
62 char addr[LYNQ_PHONE_NUMBER_MAX];
63}lynq_call_list_t;
64
65lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
66static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
67static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
ll04ae4142022-01-27 05:54:38 +000068static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
lh7b0674a2022-01-10 00:34:35 -080069static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
70static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
71static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
lla8c25a82022-03-17 05:31:33 +000072pthread_t lynq_call_urc_tid = -1;
73pthread_t lynq_call_list_loop_tid = -1;
lhec17b0a2022-02-13 23:56:05 -080074
rjw5d2a50e2022-02-28 15:01:49 +080075/*lei add*/
76/* socket文件描述符 */
77int len_addr_serv;
78struct sockaddr_in addr_serv;
79lynq_client_t client_t;
80int client_size = 0;
81/*lei add*/
lh7b0674a2022-01-10 00:34:35 -080082
lh42c1e572022-01-25 18:47:39 -080083int s_call_urc_event_complete = 1;
lh7b0674a2022-01-10 00:34:35 -080084
85enum{
86 CALL_OFF=0,
87 CALL_ON=1
88}call_state;
ll04ae4142022-01-27 05:54:38 +000089typedef enum{
90 LYNQ_E_CARDSTATE_ERROR=8000,
91 /* The voice service state is out of service*/
92 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
93 /* The voice service state is EMERGENCY_ONLY*/
94 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
95 /* The radio power is power off*/
96 LYNQ_E_STATE_POWER_OFF=8003,
97 LYNQ_E_TIME_OUT=8004,
98 /*create or open sms DB fail */
99 LYNQ_E_SMS_DB_FAIL=8005,
100 /*Failed to execute sql statement*/
101 LYNQ_E_SMS_SQL_FAIL = 8006,
102 LYNQ_E_SMS_NOT_FIND = 8007,
103 /* The logic conflict*/
104 LYNQ_E_CONFLICT=9000,
105 /*Null anomaly*/
106 LYNQ_E_NULL_ANONALY=9001
lh7b0674a2022-01-10 00:34:35 -0800107}LYNQ_E;
q.huangec88da92022-03-29 04:17:32 -0400108typedef enum{
109 LYNQ_E_VOLUMN_SET_DTMF,
110 LYNQ_E_VOLUMN_SET_SPEECH
111}LYNQ_E_VOLUMN_SET;
lh7b0674a2022-01-10 00:34:35 -0800112
113int lynq_call_state =CALL_OFF;
lh42c1e572022-01-25 18:47:39 -0800114int lynq_call_client_sockfd = 0;
115int Global_uToken_call = 0;
lh7b0674a2022-01-10 00:34:35 -0800116int global_call_count =0;
117int global_call_auto_answer = 0;
lh42c1e572022-01-25 18:47:39 -0800118bool urc_call_recive_status = 1;
lh7b0674a2022-01-10 00:34:35 -0800119bool call_list_loop = 1;
120int isDial = 0;
121int lynqIncomingCallId = 0;
q.huang8b33ed52022-04-19 20:27:44 -0400122
123#ifdef ECALL_SUPPORT
124typedef enum{
125 LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
126 LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
q.huang714145d2022-04-18 00:09:50 -0400127 LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
128 LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */\
129}LYNQ_ECall_Type;
130
q.huang8b33ed52022-04-19 20:27:44 -0400131char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"","null","112"};
132
133
134
135static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
136static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
137
138LYNQ_ECall_Indication lynqIncomingEcallIndication;
139int lynqEcallId;
140
141void sendSignalIncomingECallEvent()
142{
143 pthread_mutex_lock(&s_incoming_e_call_mutex);
144 pthread_cond_signal(&s_incoming_e_call_cond);
145 pthread_mutex_unlock(&s_incoming_e_call_mutex);
146}
147#endif
q.huang714145d2022-04-18 00:09:50 -0400148
lla8c25a82022-03-17 05:31:33 +0000149/**
150 * @brief mark call initialization state
151 * 0: deinit state
152 * 1: init state
153 */
154int g_lynq_call_init_flag = 0;
lh7b0674a2022-01-10 00:34:35 -0800155
156int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
157{
158 if(p.dataAvail() > 0)
159 {
160 p.readInt32(resp_type);
161 p.readInt32(request);
162 p.readInt32(slot_id);
163 p.readInt32(error);
164 return 0;
165 }
166 else
167 {
168 return -1;
169 }
170}
171int send_request(int sockfd,lynq_client_t *client_tmp)
172{
173 int ret=0;
rjw5d2a50e2022-02-28 15:01:49 +0800174 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800175 if(ret==-1)
176 {
ll3fe03462022-03-01 09:18:53 +0000177 LYERRLOG("sendto error\n");
lh7b0674a2022-01-10 00:34:35 -0800178 return -1;
179 }
180 return 0;
181}
182
183int get_response(int sockfd,Parcel &p)
184{
185 int len = 0;
186 char recvline[LYNQ_REC_BUF];
187 bzero(recvline,LYNQ_REC_BUF);
188 /* receive data from server */
rjw5d2a50e2022-02-28 15:01:49 +0800189 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800190 if(len == -1)
191 {
ll3fe03462022-03-01 09:18:53 +0000192 LYERRLOG("recvfrom error\n");
lh7b0674a2022-01-10 00:34:35 -0800193 return -1;
194 }
lh7b0674a2022-01-10 00:34:35 -0800195 if (recvline != NULL) {
196 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
197 p.setDataPosition(0);
198 }
199 return 0;
200}
201static char *strdupReadString(Parcel &p) {
ll04ae4142022-01-27 05:54:38 +0000202 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800203 const char16_t *s16;
204 s16 = p.readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000205 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800206}
207
208int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
209{
210 Parcel p;
211 lynq_client_t client;
212 int resp_type = -1;
213 int request = -1;
214 int slot_id = -1;
215 int error = -1;
216 int call_num = 0;
217 int temp = 0;
218 char *remote_phoneNum = NULL;
219 char *remote_name= NULL;
220 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800221 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800222 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
223 client.paramLen = 0;
224 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
225 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800226 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800227 {
228 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800229 return -1;
230 }
lh42c1e572022-01-25 18:47:39 -0800231 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800232 JumpHeader(p,&resp_type,&request,&slot_id,&error);
233 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
234 if(error == 0)
235 {
236 p.readInt32(&call_num);
237 global_call_count = call_num;
238 if(call_num<=0)
239 {
240 lynq_call_state = CALL_OFF;
lhec17b0a2022-02-13 23:56:05 -0800241 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800242 return 0;
243 }
lhec17b0a2022-02-13 23:56:05 -0800244 lynq_call_state = CALL_ON;
245 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800246 for(int i = 0;i < call_num;i++)
247 {
248 p.readInt32(&temp);
249 call_list[i].call_state = temp;
250 p.readInt32(&call_list[i].call_id);
251 p.readInt32(&call_list[i].toa);
252 p.readInt32(&temp);
253 p.readInt32(&temp);
254 call_list[i].direction = temp;
255 p.readInt32(&temp);
256 p.readInt32(&temp);
257 p.readInt32(&temp);
258 remote_phoneNum = strdupReadString(p);
259 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
260 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
261 call_list[i].direction,call_list[i].addr,call_list[i].toa);
262 p.readInt32(&temp);
263 remote_name = strdupReadString(p);
264 p.readInt32(&temp);
265 p.readInt32(&temp);
266 if(temp==0)
267 {
268 continue;
269 }
270 p.readInt32(&temp); /* UUS Information is present */
271 p.readInt32(&temp);
272 p.readInt32(&temp);
273 p.read(uusData,temp);
274 }
275 }
276 return 0;
277}
278
279void cleanCallList(int lynq_call_id)
280{
281 lynq_call_lists[lynq_call_id].call_id = 0;
282 lynq_call_lists[lynq_call_id].call_state = 0;
283 lynq_call_lists[lynq_call_id].toa = 0;
284 lynq_call_lists[lynq_call_id].direction = 0;
285 lynq_call_lists[lynq_call_id].used = 0;
286 lynq_call_lists[lynq_call_id].hasTimeout = 0;
287 memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
288}
289int getUnusedElement()
290{
291 for(int i=0;i < LYNQ_CALL_MAX; i++)
292 {
293 if(lynq_call_lists[i].used!=1)
294 {
295 return i;
296 }
297 }
298 return -1;
299}
300int updateAddr(char addr[])
301{
302 int ret = 0;
303 ret = getUnusedElement();
304 memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
305 lynq_call_lists[ret].used = 1;
306 return ret;
307}
308void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
309{
lhd1e457c2022-04-19 06:01:25 -0700310 LYINFLOG("Update Call List");
lh7b0674a2022-01-10 00:34:35 -0800311 callList->call_id = call_id;
312 callList->call_state = call_state;
313 callList->toa = toa;
314 callList->direction = direction;
315 callList->used = 1;
316 callList->hasTimeout = 0;
317 return;
318}
319int waitCallstateChange(int mtime)
320{
lhd1e457c2022-04-19 06:01:25 -0700321 LYINFLOG("wait Call state Change");
lh7b0674a2022-01-10 00:34:35 -0800322 int ret = 0;
323 int sec = 0;
324 int usec = 0;
lh2afc7732022-01-10 02:24:31 -0800325 struct timeval now;
326 struct timespec timeout;
327 gettimeofday(&now,NULL);
lh7b0674a2022-01-10 00:34:35 -0800328 sec = mtime/1000;
329 usec = mtime%1000;
lh2afc7732022-01-10 02:24:31 -0800330 timeout.tv_sec = now.tv_sec+sec;
331 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh7b0674a2022-01-10 00:34:35 -0800332 pthread_mutex_lock(&call_state_change_mutex);
lh2afc7732022-01-10 02:24:31 -0800333 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh7b0674a2022-01-10 00:34:35 -0800334 pthread_mutex_unlock(&call_state_change_mutex);
335 return ret;
336}
337int waitIncomingCall()
338{
lhd1e457c2022-04-19 06:01:25 -0700339 LYINFLOG("wait incming call");
lh7b0674a2022-01-10 00:34:35 -0800340 int ret = 0;
341 pthread_mutex_lock(&s_incoming_call_mutex);
342 ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
343 pthread_mutex_unlock(&s_incoming_call_mutex);
344 return ret;
345}
346int checkHasCall(char addr[])
347{
lhd1e457c2022-04-19 06:01:25 -0700348 LYINFLOG("check has call");
lh7b0674a2022-01-10 00:34:35 -0800349 for(int i = 0;i<LYNQ_CALL_MAX;i++)
350 {
351 if(strcmp(lynq_call_lists[i].addr,addr)==0)
352 {
353 return 1;
354 }
355 }
356 return 0;
357}
lhd1e457c2022-04-19 06:01:25 -0700358int find_call_id_with_addr(char *addr)
359{
360 LYINFLOG("find call id with addr!!!");
361 for(int id = 0; id < LYNQ_CALL_MAX; id++)
362 {
363 if(strcmp(lynq_call_lists[id].addr,addr) == 0)
364 {
365 return id;
366 }
367 }
368 return -1;
369}
lh7b0674a2022-01-10 00:34:35 -0800370void sendSignalToWaitCallStateChange()
371{
lhd1e457c2022-04-19 06:01:25 -0700372 LYINFLOG("send Signal To Wait Call State Change");
lh7b0674a2022-01-10 00:34:35 -0800373 pthread_mutex_lock(&call_state_change_mutex);
374 pthread_cond_signal(&call_state_change_cond);
375 pthread_mutex_unlock(&call_state_change_mutex);
376}
377void sendSignalIncomingCall()
378{
lhd1e457c2022-04-19 06:01:25 -0700379 LYINFLOG("send incoming call signal");
lh7b0674a2022-01-10 00:34:35 -0800380 pthread_mutex_lock(&s_incoming_call_mutex);
381 pthread_cond_signal(&s_incoming_call_cond);
382 pthread_mutex_unlock(&s_incoming_call_mutex);
383}
384
385void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
386{
387 callList->call_id = call_id;
388 callList->call_state = call_state;
389 callList->toa = toa;
390 callList->direction = direction;
391 memcpy(callList->addr,addr,strlen(addr)+1);
392 callList->used = 1;
393 callList->hasTimeout = 0;
394 return;
395}
396
397void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000398{
399 int ret=0;
lhd1e457c2022-04-19 06:01:25 -0700400 bool call_end;
401 call_end = 0;//0:this call end,1:call on
ll04ae4142022-01-27 05:54:38 +0000402 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang8b33ed52022-04-19 20:27:44 -0400403 int update=0;
lh7b0674a2022-01-10 00:34:35 -0800404 while(call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000405 {
q.huang8b33ed52022-04-19 20:27:44 -0400406 update=0;
ll04ae4142022-01-27 05:54:38 +0000407 pthread_mutex_lock(&s_urc_call_state_change_mutex);
408 pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800409 LYDBGLOG("triggerGetCallList event!!!\n");
ll04ae4142022-01-27 05:54:38 +0000410 memset(call_list,0,sizeof(call_list));
411 ret = lynq_get_current_call_list(call_list);
412 if(ret != 0)
413 {
llbc035332022-04-11 05:49:51 +0000414 LYDBGLOG("get current call list failure!!!\n");
415 continue;
ll04ae4142022-01-27 05:54:38 +0000416 }
lhd1e457c2022-04-19 06:01:25 -0700417 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
lh7b0674a2022-01-10 00:34:35 -0800418 for(int i = 0;i < LYNQ_CALL_MAX;i++)
419 {
lhd1e457c2022-04-19 06:01:25 -0700420 if(strlen(lynq_call_lists[i].addr) != 0)
421 {
422 call_end = 0;
423 for(int id = 0; id < LYNQ_CALL_MAX; id++)
424 {
425 if(strcmp(call_list[id].addr,lynq_call_lists[i].addr) == 0)
426 {
427 call_end = 1;
428 LYINFLOG("find lynq call i %d, id %d!!!",i,id);
429 }
430 }
431 if(call_end == 0)
432 {
433 LYINFLOG("MT hungup,then clean call info");
434 cleanCallList(i);
435 continue;
436 }
437 } //fix bug API-54
lh7b0674a2022-01-10 00:34:35 -0800438 if(call_list[i].direction == 1)//MT call
439 {
440 if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
441 {
ll72bf6c12022-03-24 10:22:25 +0800442 /*you call me, and i call you,One party failed to dial*/
lh7b0674a2022-01-10 00:34:35 -0800443 if(!checkHasCall(call_list[i].addr))
444 {
445 lynqIncomingCallId = getUnusedElement();
446 addCallListToLynqCallList(&lynq_call_lists[lynqIncomingCallId],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction,call_list[i].addr);
447 sendSignalIncomingCall();
448 }
lhd1e457c2022-04-19 06:01:25 -0700449 else
450 {
451 int temp_call_id = find_call_id_with_addr(call_list[i].addr);
452 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
453 **an incoming call until the status changes.
454 **fix bug API-54
455 */
456 if((temp_call_id > 0) && (lynq_call_lists[temp_call_id].call_state == call_list[i].call_state))
457 {
458 sendSignalIncomingCall();
459 }
460 }
lh7b0674a2022-01-10 00:34:35 -0800461 }
ll72bf6c12022-03-24 10:22:25 +0800462 /*if state changed*/
463 else
464 {
465 /*update call state*/
466 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
467 {
468 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
469 {
470 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
ll90a255c2022-04-07 09:09:55 +0000471 break;
ll72bf6c12022-03-24 10:22:25 +0800472 }
473 }
474 }
lh7b0674a2022-01-10 00:34:35 -0800475 }
476 else
477 {
478 if(call_list[i].call_id==0)
479 {
480 break;
481 }
482 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
483 {
lhd1e457c2022-04-19 06:01:25 -0700484 if((lynq_call_lists[n].hasTimeout == 1) && (strcmp(lynq_call_lists[n].addr,call_list[i].addr) == 0))
lh7b0674a2022-01-10 00:34:35 -0800485 {
lhd1e457c2022-04-19 06:01:25 -0700486 cleanCallList(n);//if this call time out,need clean lynq call list.
487 /*hangup call with call id*/
488 lynq_call_hungup(&call_list[i].call_id);
lh7b0674a2022-01-10 00:34:35 -0800489 lynq_call_lists[n].hasTimeout==0;
490 continue;
491 }
q.huang8b33ed52022-04-19 20:27:44 -0400492 LYDBGLOG("lynq_call_lists n is %d, used is %d, addr is %s addr2 %s\n",
493 n,lynq_call_lists[n].used,call_list[i].addr,lynq_call_lists[n].addr);
494 if(lynq_call_lists[n].used && (strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0))
lh7b0674a2022-01-10 00:34:35 -0800495 {
q.huang8b33ed52022-04-19 20:27:44 -0400496 LYINFLOG("updated\n");
lh7b0674a2022-01-10 00:34:35 -0800497 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
q.huang8b33ed52022-04-19 20:27:44 -0400498 update=1;
499 break;
lh7b0674a2022-01-10 00:34:35 -0800500 }
501 }
502 LYDBGLOG("[count:%d]call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",i,call_list[i].call_id,call_list[i].call_state,
503 call_list[i].direction,call_list[i].addr,call_list[i].toa);
504 }
ll04ae4142022-01-27 05:54:38 +0000505 }
lh42c1e572022-01-25 18:47:39 -0800506 s_call_urc_event_complete = 1;
q.huang8b33ed52022-04-19 20:27:44 -0400507 if((isDial==1) && (update==1))
lh7b0674a2022-01-10 00:34:35 -0800508 {
509 sendSignalToWaitCallStateChange();
510 isDial = 0;
511 }
ll04ae4142022-01-27 05:54:38 +0000512 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
513 }
514 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800515}
516
517void lynqRespWatingEvent()
ll04ae4142022-01-27 05:54:38 +0000518{
519 if(s_call_urc_event_complete==1)
520 {
521 pthread_mutex_lock(&s_urc_call_state_change_mutex);
522 pthread_cond_signal(&s_urc_call_state_change_cond);
523 s_call_urc_event_complete = 0;
524 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800525 }
ll04ae4142022-01-27 05:54:38 +0000526 return;
lh7b0674a2022-01-10 00:34:35 -0800527}
528
529/*Warren add for T800 platform 2021/11/19 start*/
530int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800531{
532 #if 0
lh7b0674a2022-01-10 00:34:35 -0800533 struct sockaddr_in lynq_socket_server_addr;
534 /* init lynq_socket_server_addr */
535 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
536 lynq_socket_server_addr.sin_family = AF_INET;
537 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
538 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800539
lh7b0674a2022-01-10 00:34:35 -0800540 /*
541 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
542 {
llbc035332022-04-11 05:49:51 +0000543 LYDBGLOG("[%s] is not a valid IPaddress\n", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800544 exit(1);
545 }
546*/
lh42c1e572022-01-25 18:47:39 -0800547 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
548 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800549 {
ll3fe03462022-03-01 09:18:53 +0000550 LYERRLOG("connect error\n");
lh7b0674a2022-01-10 00:34:35 -0800551 return -1;
552 }
rjw5d2a50e2022-02-28 15:01:49 +0800553 #endif
554 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
555 if (-1 == lynq_call_client_sockfd)
556 {
557 return lynq_call_client_sockfd;
558 }
559 /* 设置address */
560 memset(&addr_serv, 0, sizeof(addr_serv));
561 addr_serv.sin_family = AF_INET;
562 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
563 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
564 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800565 return 0;
566}
567int lynq_update_call_list_loop()
568{
569 int ret = 0;
lh7b0674a2022-01-10 00:34:35 -0800570 pthread_attr_t attr;
571 pthread_attr_init(&attr);
572 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800573 ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
lh7b0674a2022-01-10 00:34:35 -0800574 if(ret < 0)
575 {
576 LYERRLOG("lynq_update_call_list_loop fail!!!");
577 return -1;
578 }
579 LYDBGLOG("lynq_update_call_list_loop success!!!\n");
580 return 0;
581
582}
583void *thread_urc_recv(void *parg)
ll04ae4142022-01-27 05:54:38 +0000584{
lh7b0674a2022-01-10 00:34:35 -0800585 int socket_fd = (int64_t)parg;
586 int len=0;
587 socklen_t addr_len=0;
588 uint8_t *dataLength = NULL;
589 char urc_data[LYNQ_REC_BUF];
590 int slot_id = -1;
591 int resp_type = -1;
592 int urcid = -1;
593 Parcel *p = NULL;
594 struct sockaddr_in dest_addr;
q.huang8b33ed52022-04-19 20:27:44 -0400595#ifdef ECALL_SUPPORT
596 int ecall_ind;
597#endif
598
lh7b0674a2022-01-10 00:34:35 -0800599 LYINFLOG("thread_urc_recv in running....\n");
lh42c1e572022-01-25 18:47:39 -0800600 while(urc_call_recive_status)
lh7b0674a2022-01-10 00:34:35 -0800601 {
602 bzero(urc_data,LYNQ_REC_BUF);
603 //get data msg
604 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
605 if(len <= 0)
ll04ae4142022-01-27 05:54:38 +0000606 {
ll3fe03462022-03-01 09:18:53 +0000607 LYERRLOG("thread_urc_recv step2 fail\n");
ll04ae4142022-01-27 05:54:38 +0000608 break;
lh7b0674a2022-01-10 00:34:35 -0800609 }
610 LYDBGLOG("=====>urc data len<=====:%d\n",len);
611 p = new Parcel();
612 if(p==NULL)
613 {
lh21502f52022-01-27 00:27:12 -0800614 LYERRLOG("new parcel failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800615 break;
616 }
617 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
618 p->setDataPosition(0);
619 if(p->dataAvail() > 0)
620 {
621 p->readInt32(&resp_type);
622 p->readInt32(&urcid);
623 p->readInt32(&slot_id);
624 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
625 switch (urcid)
626 {
627 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
628 {
629 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
630 lynqRespWatingEvent();
631 break;
632 }
633 case 1018://RIL_UNSOL_CALL_RING
634 {
635 if(global_call_auto_answer==1)
636 {
637 lynq_call_answer();
638 }
639 break;
640 }
641 case 1029://RIL_UNSOL_RINGBACK_TONE
642 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
643 {
644 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
645 break;
646 }
q.huang8b33ed52022-04-19 20:27:44 -0400647#ifdef ECALL_SUPPORT
648 case RIL_UNSOL_ECALL_INDICATIONS:
649 {
650 p->readInt32(&ecall_ind);
651 lynqIncomingEcallIndication=ecall_ind;
652 if(LYNQ_ECALL_ACTIVE==lynqIncomingEcallIndication)
653 {
654 if(isDial==1)
655 {
656 p->readInt32(&lynqEcallId);
657 sendSignalToWaitCallStateChange();
658 usleep(300*1000);
659 }
660 }
661 sendSignalIncomingECallEvent();
662 break;
663 }
664#endif
lh7b0674a2022-01-10 00:34:35 -0800665 default:
666 break;
667 }
668 }
669 delete p;
670 p = NULL;
671 }
672 close(socket_fd);
673}
674int lynq_socket_urc_start()
675{
676 int socket_fd=0;
677 int rt=0;
678 int len=0;
679 int on=1;
680 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800681 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000682 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000683 if(socket_fd < 0)
684 {
ll3fe03462022-03-01 09:18:53 +0000685 LYERRLOG("creaet socket for udp fail\n");
ll04ae4142022-01-27 05:54:38 +0000686 return -1;
lh7b0674a2022-01-10 00:34:35 -0800687 }
688 urc_local_addr.sin_family = AF_INET;
689 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
690 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
691 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000692 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
693 if(rt<0)
694 {
ll3fe03462022-03-01 09:18:53 +0000695 LYERRLOG("SO_REUSEADDR fail\n");
lh7b0674a2022-01-10 00:34:35 -0800696 return -1;
697 }
698 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000699 if (rt == -1)
700 {
lh21502f52022-01-27 00:27:12 -0800701 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000702 return -1;
lh7b0674a2022-01-10 00:34:35 -0800703 }
704 pthread_attr_init(&attr);
705 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800706 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800707 if(rt < 0)
708 {
lh21502f52022-01-27 00:27:12 -0800709 LYERRLOG("urc loop failure!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800710 return -1;
711 }
lh21502f52022-01-27 00:27:12 -0800712 LYDBGLOG("urc loop success!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800713 return 0;
714}
715int getSelfElement(char addr[])
716{
717 for(int i=0;i < LYNQ_CALL_MAX; i++)
718 {
719 if(lynq_call_lists[i].used==1)
720 {
721 if(strcmp(lynq_call_lists[i].addr,addr)==0)
722 {
723 return i;
724 }
725
726 }
727 }
728 return -1;
729}
730
731void lynq_call_state_change_test(int soc_id)
732{
llbc035332022-04-11 05:49:51 +0000733 LYDBGLOG("call state change,sim:%d\n",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800734}
735int lynq_init_call(int uToken)
lla8c25a82022-03-17 05:31:33 +0000736{
737 if(g_lynq_call_init_flag == 1){
738 LYDBGLOG("lynq init call failed!!!");
739 return -1;
740 }
741 g_lynq_call_init_flag = 1;
lh7b0674a2022-01-10 00:34:35 -0800742 int result = 0;
lh42c1e572022-01-25 18:47:39 -0800743 Global_uToken_call = uToken;
lh21502f52022-01-27 00:27:12 -0800744 urc_call_recive_status = 1;
rjw5d2a50e2022-02-28 15:01:49 +0800745 client_size = sizeof(client_t);
lh7b0674a2022-01-10 00:34:35 -0800746 LYLOGSET(LOG_INFO);
747 LYLOGEINIT(USER_LOG_TAG);
748 result = lynq_socket_client_start();
749 if(result!=0)
750 {
751 return -1;
752 }
753 result = lynq_socket_urc_start();
754 if(result!=0)
755 {
756 return -1;
757 }
758 result = lynq_update_call_list_loop();
759 if(result!=0)
760 {
761 return -1;
762 }
763 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
764 LYDBGLOG("lynq init call success!!!");
765 return 0;
766}
767int lynq_deinit_call()
768{
lla8c25a82022-03-17 05:31:33 +0000769 if(g_lynq_call_init_flag == 0)
lhec17b0a2022-02-13 23:56:05 -0800770 {
lla8c25a82022-03-17 05:31:33 +0000771 LYDBGLOG("lynq_deinit_call failed!!!");
772 return -1;
lhec17b0a2022-02-13 23:56:05 -0800773 }
lla8c25a82022-03-17 05:31:33 +0000774 else
775 {
776 g_lynq_call_init_flag = 0;
777 int ret = -1;
778 if(lynq_call_client_sockfd>0)
779 {
780 close(lynq_call_client_sockfd);
781 }
782 urc_call_recive_status = 0;
783 call_list_loop = 0;
784 if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
785 {
786 return -1;
787 }
788 ret = pthread_cancel(lynq_call_urc_tid);
789 LYDBGLOG("pthread cancel ret = %d",ret);
790 ret = pthread_cancel(lynq_call_list_loop_tid);
791 LYDBGLOG("pthread cancel ret = %d",ret);
792 ret = pthread_join(lynq_call_urc_tid,NULL);
793 LYDBGLOG("pthread join ret = %d",ret);
794 ret = pthread_join(lynq_call_list_loop_tid,NULL);
795 LYDBGLOG("pthread join ret = %d",ret);
796 return 0;
797 }
rita98e2e9c2022-04-07 06:08:13 -0400798}
q.huang714145d2022-04-18 00:09:50 -0400799
800int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400801{
802 Parcel p;
803 lynq_client_t client;
804 int resp_type = -1;
805 int request = -1;
806 int slot_id = -1;
807 int error = -1;
rita089527e2022-04-07 01:55:39 -0400808
809 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400810 client.request = request_id;
811 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400812 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400813 if(argc!=0)
814 {
815 va_list args;
816 va_start(args, format);
817 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
818 va_end(args);
819 }
820 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400821 if(send_request(lynq_call_client_sockfd,&client)==-1)
822 {
823 LYERRLOG("send request fail");
824 return -1;
825 }
q.huang714145d2022-04-18 00:09:50 -0400826 if(get_response(lynq_call_client_sockfd,p)==0)
827 {
828 JumpHeader(p,&resp_type,&request,&slot_id,&error);
829 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
830 }
rita089527e2022-04-07 01:55:39 -0400831 return error;
832}
833
q.huang714145d2022-04-18 00:09:50 -0400834int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400835{
836 Parcel p;
837 lynq_client_t client;
838 int resp_type = -1;
839 int request = -1;
840 int slot_id = -1;
841 int error = -1;
q.huang714145d2022-04-18 00:09:50 -0400842 if(status==NULL)
843 {
844 LYERRLOG("status is null");
845 return -1;
846 }
rita089527e2022-04-07 01:55:39 -0400847 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400848 client.request = request_id;
849 client.paramLen = 0;
rita089527e2022-04-07 01:55:39 -0400850 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400851 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400852 if(send_request(lynq_call_client_sockfd,&client)==-1)
853 {
854 LYERRLOG("send request fail");
855 return -1;
856 }
q.huang714145d2022-04-18 00:09:50 -0400857 if(get_response(lynq_call_client_sockfd,p)==0)
rita089527e2022-04-07 01:55:39 -0400858 {
q.huang714145d2022-04-18 00:09:50 -0400859 JumpHeader(p,&resp_type,&request,&slot_id,&error);
860 p.readInt32(status);
861 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
rita089527e2022-04-07 01:55:39 -0400862 }
rita089527e2022-04-07 01:55:39 -0400863 return error;
864}
865
lh7b0674a2022-01-10 00:34:35 -0800866int lynq_call(int* handle,char addr[])
867{
868 Parcel p;
869 lynq_client_t client;
870 int resp_type = -1;
871 int request = -1;
872 int slot_id = -1;
873 int error = -1;
874 int lynq_call_id = -1;
875 if(addr==NULL)
876 {
877 LYERRLOG("Phone num is null!!!");
878 return -1;
879 }
lh42c1e572022-01-25 18:47:39 -0800880 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800881 client.request = 10;//RIL_REQUEST_DIAL
882 client.paramLen = 2;
883 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
884 memcpy(client.param,addr,strlen(addr)+1);
885 strcat(client.param," 0");
886 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800887 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800888 {
889 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800890 return -1;
891 }
lh42c1e572022-01-25 18:47:39 -0800892 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800893 JumpHeader(p,&resp_type,&request,&slot_id,&error);
894 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
895 lynq_call_id = updateAddr(addr);
896 if(error==0)
897 {
898 isDial = 1;
ll72bf6c12022-03-24 10:22:25 +0800899 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -0800900 {
lhd1e457c2022-04-19 06:01:25 -0700901 //if timeout,this call need destroy.
902 isDial = 0;
903
lh7b0674a2022-01-10 00:34:35 -0800904 error = LYNQ_E_TIME_OUT;
905 LYERRLOG("timeout:wait Call state fail!!!");
906 lynq_call_lists[lynq_call_id].hasTimeout = 1;
907 return error;
908 }
909 *handle = lynq_call_id;
910 }
911 return error;
912}
913int lynq_call_answer()
914{
915 Parcel p;
916 lynq_client_t client;
917 int resp_type = -1;
918 int request = -1;
919 int slot_id = -1;
920 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800921 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800922 client.request = 40;//RIL_REQUEST_DIAL
923 client.paramLen = 0;
924 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
925 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800926 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800927 {
928 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800929 return -1;
930 }
lh42c1e572022-01-25 18:47:39 -0800931 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800932 JumpHeader(p,&resp_type,&request,&slot_id,&error);
933 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
934 return error;
935}
936int lynq_call_hungup(int* handle)
937{
938 Parcel p;
939 lynq_client_t client;
940 int resp_type = -1;
941 int request = -1;
942 int slot_id = -1;
943 int error = -1;
944 int call_id = 0;
945 int lynq_call_id = 0;
lh42c1e572022-01-25 18:47:39 -0800946 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
947 {
948 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
949 return LYNQ_E_CONFLICT;
950 }
951 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800952 client.request = 12;//RIL_REQUEST_HUNGUP
953 client.paramLen = 1;
954 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
955 lynq_call_id = *handle;
956 call_id = lynq_call_lists[lynq_call_id].call_id;
957 sprintf(client.param,"%d",call_id);
958 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800959 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800960 {
961 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800962 return -1;
963 }
lh42c1e572022-01-25 18:47:39 -0800964 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800965 JumpHeader(p,&resp_type,&request,&slot_id,&error);
966 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
967 if(error==0)
968 {
969 cleanCallList(lynq_call_id);
970 }
971 return error;
972}
973int lynq_call_hungup_all()
974{
975 Parcel p;
976 lynq_client_t client;
977 int resp_type = -1;
978 int request = -1;
979 int slot_id = -1;
980 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800981 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800982 client.request = 17;//RIL_REQUEST_UDUB
983 client.paramLen = 0;
984 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
985 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800986 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800987 {
988 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800989 return -1;
990 }
lh42c1e572022-01-25 18:47:39 -0800991 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800992 JumpHeader(p,&resp_type,&request,&slot_id,&error);
993 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
994 return error;
995}
996int lynq_wait_incoming_call(int *handle)
997{
998 waitIncomingCall();
999 *handle = lynqIncomingCallId;
1000 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
1001 return 0;
1002}
1003
1004int lynq_set_auto_answercall(const int mode)
1005{
1006 global_call_auto_answer = mode;
1007 LYINFLOG("auto answer call mode =%d",mode);
1008 return 0;
1009}
q.huangec88da92022-03-29 04:17:32 -04001010int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1011{
1012 int lynq_call_id = 0;
1013 if(handle==NULL)
1014 {
1015 return LYNQ_E_NULL_ANONALY;
1016 }
1017 lynq_call_id = *handle;
1018 *call_state = lynq_call_lists[lynq_call_id].call_state;
1019 *toa = lynq_call_lists[lynq_call_id].toa;
1020 *direction = lynq_call_lists[lynq_call_id].direction;
1021 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
1022 return 0;
1023}
1024
1025/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001026static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001027 switch(enable){
1028 case 0:
1029 return 1;
1030 case 1:
1031 return 1;
1032 default:
1033 return 0;
lldc99c9b2022-01-24 12:16:22 +00001034 }
1035}
1036
lh7b0674a2022-01-10 00:34:35 -08001037int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001038{
1039 if(!judge_mic(enable)){
1040 return LYNQ_E_CONFLICT;
1041 }
q.huangec88da92022-03-29 04:17:32 -04001042 return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1043}
1044int lynq_get_mute_mic(int *status)
1045{
1046 return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
lh7b0674a2022-01-10 00:34:35 -08001047}
ll72bf6c12022-03-24 10:22:25 +08001048
1049/**
1050 * @brief Check whether DTMF is valid
1051 *
1052 * @param callnum dtmf eg:0-9 * #
1053 * @return int
1054 */
1055static int judge_dtmf(const char callnum)
1056{
1057 if(callnum == '#')
1058 {
1059 return 1;
1060 }
1061 if(callnum == '*')
1062 {
1063 return 1;
1064 }
1065 if(callnum >= '0'&& callnum <= '9')
1066 {
1067 return 1;
1068 }
1069 return 0;
1070}
1071
lh7b0674a2022-01-10 00:34:35 -08001072int lynq_set_DTMF(const char callnum)
1073{
ll72bf6c12022-03-24 10:22:25 +08001074 if(!judge_dtmf(callnum))
1075 {
1076 return LYNQ_E_CONFLICT;
1077 }
lh7b0674a2022-01-10 00:34:35 -08001078 if(!lynq_call_state)
1079 {
1080 LYERRLOG("LYNQ_E_CONFLICT");
1081 return LYNQ_E_CONFLICT;
1082 }
q.huangec88da92022-03-29 04:17:32 -04001083 return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
lh7b0674a2022-01-10 00:34:35 -08001084}
q.huangec88da92022-03-29 04:17:32 -04001085static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1086 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1087 if(volume < 0 ||volume >36){
1088 return 0;
1089 }
1090 }
1091 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1092 {
1093 if(volume < 1 ||volume >7){
1094 return 0;
1095 }
lldc99c9b2022-01-24 12:16:22 +00001096 }
ll04ae4142022-01-27 05:54:38 +00001097 return 1;
lldc99c9b2022-01-24 12:16:22 +00001098}
lh7b0674a2022-01-10 00:34:35 -08001099int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001100{
q.huangec88da92022-03-29 04:17:32 -04001101 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
lldc99c9b2022-01-24 12:16:22 +00001102 return LYNQ_E_CONFLICT;
1103 }
q.huangec88da92022-03-29 04:17:32 -04001104 return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
lh7b0674a2022-01-10 00:34:35 -08001105}
q.huangb212fde2022-04-05 23:11:02 -04001106int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001107{
q.huangec88da92022-03-29 04:17:32 -04001108 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
lh7b0674a2022-01-10 00:34:35 -08001109 {
q.huangec88da92022-03-29 04:17:32 -04001110 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001111 }
q.huangec88da92022-03-29 04:17:32 -04001112 return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
lh7b0674a2022-01-10 00:34:35 -08001113}
q.huangec88da92022-03-29 04:17:32 -04001114int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1115{
1116 return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
1117}
q.huangb212fde2022-04-05 23:11:02 -04001118int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001119{
q.huangb212fde2022-04-05 23:11:02 -04001120 return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
q.huangec88da92022-03-29 04:17:32 -04001121}
1122int lynq_incall_record_stop()
1123{
q.huangb212fde2022-04-05 23:11:02 -04001124 const char* unused_file="just_ocuupy_paramter_postion";
1125 return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
q.huangec88da92022-03-29 04:17:32 -04001126}
1127/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001128
1129#ifdef ECALL_SUPPORT
1130LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
1131{
1132 switch(type)
1133 {
1134 case LYNQ_ECALL_TYPE_TEST:
1135 return LYNQ_ECALL_TEST;
1136 case LYNQ_ECALL_TYPE_RECONFIG:
1137 return LYNQ_ECALL_RECONFIG;
1138 default:
1139 return LYNQ_ECALL_EMERGENCY;
1140 }
1141}
1142
1143RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
1144{
1145 switch(type)
1146 {
1147 case LYNQ_ECALL_TEST:
1148 return ECALL_TEST;
1149 case LYNQ_ECALL_RECONFIG:
1150 return ECALL_RECONFIG;
1151 default:
1152 return ECALL_EMERGENCY;
1153 }
1154}
1155
1156RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
1157{
1158 switch(cat)
1159 {
1160 case LYNQ_EMER_CAT_MANUAL_ECALL:
1161 return EMER_CAT_MANUAL_ECALL;
1162 default:
1163 return EMER_CAT_AUTO_ECALL;
1164 }
1165}
1166
1167
1168int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
1169{
1170 int error;
1171
1172 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
1173 {
1174 LYERRLOG("test_num is null or test_num_length %d s greater than %d\n ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
1175 return -1;
1176 }
1177
1178 error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
1179
1180 if(error==0)
1181 {
1182 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
1183 }
1184
1185 return error;
1186}
1187
1188
1189int lynq_fast_ecall(int* handle, LYNQ_ECall_Category lynq_ecall_cat, LYNQ_ECall_Variant lynq_ecall_variant, const char *addr, int addr_length, const char *msd_data, int msd_length)
1190{
1191 int error = -1;
1192 int lynq_call_id = -1;
1193 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
q.huang52473032022-04-19 05:20:12 -04001194 RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
q.huang714145d2022-04-18 00:09:50 -04001195
q.huang8b33ed52022-04-19 20:27:44 -04001196 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1197
1198 LYINFLOG("e_call_addr is %s\n",e_call_addr[lynq_ecall_variant]);
1199
q.huang714145d2022-04-18 00:09:50 -04001200 error=lynq_set_common_request(RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", msd_data);
1201
1202 if(error==0)
q.huang8b33ed52022-04-19 20:27:44 -04001203 {
q.huang714145d2022-04-18 00:09:50 -04001204 isDial = 1;
q.huang8b33ed52022-04-19 20:27:44 -04001205 if(waitCallstateChange(30000)==ETIMEDOUT)//30000ms
q.huang714145d2022-04-18 00:09:50 -04001206 {
q.huang8b33ed52022-04-19 20:27:44 -04001207 isDial = 0;
q.huang714145d2022-04-18 00:09:50 -04001208 error = LYNQ_E_TIME_OUT;
q.huang8b33ed52022-04-19 20:27:44 -04001209 cleanCallList(lynq_call_id);
1210 LYERRLOG("timeout:wait Call state fail!!!");
q.huang714145d2022-04-18 00:09:50 -04001211 return error;
1212 }
q.huang8b33ed52022-04-19 20:27:44 -04001213
q.huang714145d2022-04-18 00:09:50 -04001214 *handle = lynq_call_id;
q.huang8b33ed52022-04-19 20:27:44 -04001215 if(lynq_ecall_variant==LYNQ_ECALL_EMERGENCY){
1216 lynq_call_lists[lynq_call_id].call_id=lynqEcallId;
1217 }
1218 LYINFLOG("lynq_fast_ecall handle is:%d, call id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
1219
1220 }
1221 else {
1222 cleanCallList(lynq_call_id);
q.huang714145d2022-04-18 00:09:50 -04001223 }
1224
1225 return error;
1226}
1227
1228int lynq_set_psap(int enable)
1229{
1230 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
1231}
1232
1233int lynq_psap_pull_msd()
1234{
1235 return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
1236}
1237
1238int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
1239{
1240 LYNQ_ECall_Variant lynq_ecall_variant;
1241 int error = -1;
1242 int lynq_call_id = -1;
1243
1244 if(handle==NULL)
1245 {
1246 LYERRLOG("handle is NULL, parameter error \n ");
1247 return -1;
1248 }
1249
1250 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
1251
1252 if(error==0)
1253 {
1254 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
1255
1256 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1257 isDial = 1;
1258 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1259 {
1260 error = LYNQ_E_TIME_OUT;
1261 LYERRLOG("timeout:wait Call state fail!!!");
1262 lynq_call_lists[lynq_call_id].hasTimeout = 1;
1263 return error;
1264 }
1265
1266 *handle = lynq_call_id;
1267 }
1268
1269 return error;
1270}
1271
1272
1273int lynq_set_msd(int* handle, const char *msd_data, int msd_length)
1274{
1275 if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX))
1276 {
1277 LYERRLOG("handle is NULL or *handle %d is greater or equeal to %d, parameter error\n",*handle,LYNQ_CALL_MAX);
1278 return -1;
1279 }
1280
1281 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,msd_data);
1282}
1283
1284int lynq_set_ivs(int enable)
1285{
1286 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
1287}
1288
1289int lynq_reset_ivs()
1290{
1291 return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
1292}
1293
1294int lynq_ivs_push_msd()
1295{
1296 return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
1297}
q.huang8b33ed52022-04-19 20:27:44 -04001298
1299int wait_ecall_event()
1300{
1301 int ret = 0;
1302 pthread_mutex_lock(&s_incoming_e_call_mutex);
1303 ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
1304 pthread_mutex_unlock(&s_incoming_e_call_mutex);
1305 return ret;
1306}
1307
1308int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)
1309{
1310 wait_ecall_event();
1311 *eCall_Indication = lynqIncomingEcallIndication;
1312 LYINFLOG("lynq incoming e-call indication id:%d",lynqIncomingEcallIndication);
1313 return 0;
1314}
1315
q.huang714145d2022-04-18 00:09:50 -04001316#endif
1317
lh7b0674a2022-01-10 00:34:35 -08001318#if 0
1319int main(int argc,char **argv)
1320{
1321 int n = 0;
1322 n = lynq_init_call(lynq_call_state_change_test,2222);
1323 if(n<0)
1324 {
llbc035332022-04-11 05:49:51 +00001325 LYDBGLOG("lynq init call fail!!!\n");
lh7b0674a2022-01-10 00:34:35 -08001326 return -1;
1327 }
llbc035332022-04-11 05:49:51 +00001328 LYDBGLOG("lynq call init success!!!\n");
lh7b0674a2022-01-10 00:34:35 -08001329 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1330 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1331 lynq_call(phoneNum);
1332 while(1)
1333 {
1334 sleep(1);
1335 }
1336 return 0;
1337}
1338#endif
1339/*Warren add for T800 platform 2021/11/19 end*/