blob: 2af714d560bc878b76f76021d43bd05508de3e55 [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>
11#include "lynq_call.h"
12#include <cutils/jstring.h>
13#include <pthread.h>
14#include "liblog/lynq_deflog.h"
lh2afc7732022-01-10 02:24:31 -080015#include <sys/time.h>
lh21502f52022-01-27 00:27:12 -080016#include <string.h>
lh7b0674a2022-01-10 00:34:35 -080017#define LYNQ_SERVICE_PORT 8088
18#define LYNQ_URC_SERVICE_PORT 8086
19#define LYNQ_REC_BUF 8192
20#define LYNQ_REQUEST_PARAM_BUF 8192
21#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
22#define USER_LOG_TAG "LYNQ_CALL"
23
24using ::android::Parcel;
25 typedef enum {
26 LYNQ_CALL_ACTIVE = 0,
27 LYNQ_CALL_HOLDING = 1,
28 LYNQ_CALL_DIALING = 2, /* MO call only */
29 LYNQ_CALL_ALERTING = 3, /* MO call only */
30 LYNQ_CALL_INCOMING = 4, /* MT call only */
31 LYNQ_CALL_WAITING = 5 ,/* MT call only */
32}lynq_call_state_t;
33
34typedef struct{
35 int uToken;
36 int request;
37 int paramLen;
38 char param[LYNQ_REQUEST_PARAM_BUF];
39}lynq_client_t;
40typedef struct
41{
42 int used;
43 int call_id;
44 int call_state;
45 int toa;
46 int direction;/*0: MO call,1:MT call*/
47 char addr[LYNQ_PHONE_NUMBER_MAX];
48 int hasTimeout;
49}lynq_call_list_e_t;
50typedef struct
51{
52 int call_id;
53 int call_state;
54 int toa;
55 int direction;/*0: MO call,1:MT call*/
56 char addr[LYNQ_PHONE_NUMBER_MAX];
57}lynq_call_list_t;
58
59lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
60static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
61static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
ll04ae4142022-01-27 05:54:38 +000062static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
lh7b0674a2022-01-10 00:34:35 -080063static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
64static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
65static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
66
67
lh42c1e572022-01-25 18:47:39 -080068int s_call_urc_event_complete = 1;
lh7b0674a2022-01-10 00:34:35 -080069
70enum{
71 CALL_OFF=0,
72 CALL_ON=1
73}call_state;
ll04ae4142022-01-27 05:54:38 +000074typedef enum{
75 LYNQ_E_CARDSTATE_ERROR=8000,
76 /* The voice service state is out of service*/
77 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
78 /* The voice service state is EMERGENCY_ONLY*/
79 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
80 /* The radio power is power off*/
81 LYNQ_E_STATE_POWER_OFF=8003,
82 LYNQ_E_TIME_OUT=8004,
83 /*create or open sms DB fail */
84 LYNQ_E_SMS_DB_FAIL=8005,
85 /*Failed to execute sql statement*/
86 LYNQ_E_SMS_SQL_FAIL = 8006,
87 LYNQ_E_SMS_NOT_FIND = 8007,
88 /* The logic conflict*/
89 LYNQ_E_CONFLICT=9000,
90 /*Null anomaly*/
91 LYNQ_E_NULL_ANONALY=9001
lh7b0674a2022-01-10 00:34:35 -080092}LYNQ_E;
93
94int lynq_call_state =CALL_OFF;
lh42c1e572022-01-25 18:47:39 -080095int lynq_call_client_sockfd = 0;
96int Global_uToken_call = 0;
lh7b0674a2022-01-10 00:34:35 -080097int global_call_count =0;
98int global_call_auto_answer = 0;
lh42c1e572022-01-25 18:47:39 -080099bool urc_call_recive_status = 1;
lh7b0674a2022-01-10 00:34:35 -0800100bool call_list_loop = 1;
101int isDial = 0;
102int lynqIncomingCallId = 0;
103
104int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
105{
106 if(p.dataAvail() > 0)
107 {
108 p.readInt32(resp_type);
109 p.readInt32(request);
110 p.readInt32(slot_id);
111 p.readInt32(error);
112 return 0;
113 }
114 else
115 {
116 return -1;
117 }
118}
119int send_request(int sockfd,lynq_client_t *client_tmp)
120{
121 int ret=0;
122 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
123 if(ret==-1)
124 {
lh21502f52022-01-27 00:27:12 -0800125 LYERRLOG("write error:%s",strerror(errno));
lh7b0674a2022-01-10 00:34:35 -0800126 return -1;
127 }
128 return 0;
129}
130
131int get_response(int sockfd,Parcel &p)
132{
133 int len = 0;
134 char recvline[LYNQ_REC_BUF];
135 bzero(recvline,LYNQ_REC_BUF);
136 /* receive data from server */
137 len = read(sockfd, recvline, LYNQ_REC_BUF);
138 if(len == -1)
139 {
lh21502f52022-01-27 00:27:12 -0800140 LYERRLOG("read error:%s",strerror(errno));
lh7b0674a2022-01-10 00:34:35 -0800141 return -1;
142 }
lh7b0674a2022-01-10 00:34:35 -0800143 if (recvline != NULL) {
144 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
145 p.setDataPosition(0);
146 }
147 return 0;
148}
149static char *strdupReadString(Parcel &p) {
ll04ae4142022-01-27 05:54:38 +0000150 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800151 const char16_t *s16;
152 s16 = p.readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000153 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800154}
155
156int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
157{
158 Parcel p;
159 lynq_client_t client;
160 int resp_type = -1;
161 int request = -1;
162 int slot_id = -1;
163 int error = -1;
164 int call_num = 0;
165 int temp = 0;
166 char *remote_phoneNum = NULL;
167 char *remote_name= NULL;
168 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800169 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800170 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
171 client.paramLen = 0;
172 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
173 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800174 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800175 {
176 LYERRLOG("send request fail");
177 perror("[LYNQ_CALL] send request fail:");
178 return -1;
179 }
lh42c1e572022-01-25 18:47:39 -0800180 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800181 JumpHeader(p,&resp_type,&request,&slot_id,&error);
182 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
183 if(error == 0)
184 {
185 p.readInt32(&call_num);
186 global_call_count = call_num;
187 if(call_num<=0)
188 {
189 lynq_call_state = CALL_OFF;
190 return 0;
191 }
192 for(int i = 0;i < call_num;i++)
193 {
194 p.readInt32(&temp);
195 call_list[i].call_state = temp;
196 p.readInt32(&call_list[i].call_id);
197 p.readInt32(&call_list[i].toa);
198 p.readInt32(&temp);
199 p.readInt32(&temp);
200 call_list[i].direction = temp;
201 p.readInt32(&temp);
202 p.readInt32(&temp);
203 p.readInt32(&temp);
204 remote_phoneNum = strdupReadString(p);
205 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
206 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
207 call_list[i].direction,call_list[i].addr,call_list[i].toa);
208 p.readInt32(&temp);
209 remote_name = strdupReadString(p);
210 p.readInt32(&temp);
211 p.readInt32(&temp);
212 if(temp==0)
213 {
214 continue;
215 }
216 p.readInt32(&temp); /* UUS Information is present */
217 p.readInt32(&temp);
218 p.readInt32(&temp);
219 p.read(uusData,temp);
220 }
221 }
222 return 0;
223}
224
225void cleanCallList(int lynq_call_id)
226{
227 lynq_call_lists[lynq_call_id].call_id = 0;
228 lynq_call_lists[lynq_call_id].call_state = 0;
229 lynq_call_lists[lynq_call_id].toa = 0;
230 lynq_call_lists[lynq_call_id].direction = 0;
231 lynq_call_lists[lynq_call_id].used = 0;
232 lynq_call_lists[lynq_call_id].hasTimeout = 0;
233 memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
234}
235int getUnusedElement()
236{
237 for(int i=0;i < LYNQ_CALL_MAX; i++)
238 {
239 if(lynq_call_lists[i].used!=1)
240 {
241 return i;
242 }
243 }
244 return -1;
245}
246int updateAddr(char addr[])
247{
248 int ret = 0;
249 ret = getUnusedElement();
250 memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
251 lynq_call_lists[ret].used = 1;
252 return ret;
253}
254void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
255{
256 callList->call_id = call_id;
257 callList->call_state = call_state;
258 callList->toa = toa;
259 callList->direction = direction;
260 callList->used = 1;
261 callList->hasTimeout = 0;
262 return;
263}
264int waitCallstateChange(int mtime)
265{
266 int ret = 0;
267 int sec = 0;
268 int usec = 0;
lh2afc7732022-01-10 02:24:31 -0800269 struct timeval now;
270 struct timespec timeout;
271 gettimeofday(&now,NULL);
lh7b0674a2022-01-10 00:34:35 -0800272 sec = mtime/1000;
273 usec = mtime%1000;
lh2afc7732022-01-10 02:24:31 -0800274 timeout.tv_sec = now.tv_sec+sec;
275 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh7b0674a2022-01-10 00:34:35 -0800276 pthread_mutex_lock(&call_state_change_mutex);
lh2afc7732022-01-10 02:24:31 -0800277 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh7b0674a2022-01-10 00:34:35 -0800278 pthread_mutex_unlock(&call_state_change_mutex);
279 return ret;
280}
281int waitIncomingCall()
282{
283 int ret = 0;
284 pthread_mutex_lock(&s_incoming_call_mutex);
285 ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
286 pthread_mutex_unlock(&s_incoming_call_mutex);
287 return ret;
288}
289int checkHasCall(char addr[])
290{
291 for(int i = 0;i<LYNQ_CALL_MAX;i++)
292 {
293 if(strcmp(lynq_call_lists[i].addr,addr)==0)
294 {
295 return 1;
296 }
297 }
298 return 0;
299}
300void sendSignalToWaitCallStateChange()
301{
302 pthread_mutex_lock(&call_state_change_mutex);
303 pthread_cond_signal(&call_state_change_cond);
304 pthread_mutex_unlock(&call_state_change_mutex);
305}
306void sendSignalIncomingCall()
307{
308 pthread_mutex_lock(&s_incoming_call_mutex);
309 pthread_cond_signal(&s_incoming_call_cond);
310 pthread_mutex_unlock(&s_incoming_call_mutex);
311}
312
313void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
314{
315 callList->call_id = call_id;
316 callList->call_state = call_state;
317 callList->toa = toa;
318 callList->direction = direction;
319 memcpy(callList->addr,addr,strlen(addr)+1);
320 callList->used = 1;
321 callList->hasTimeout = 0;
322 return;
323}
324
325void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000326{
327 int ret=0;
328 lynq_call_list_t call_list[LYNQ_CALL_MAX];
lh7b0674a2022-01-10 00:34:35 -0800329 while(call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000330 {
331 pthread_mutex_lock(&s_urc_call_state_change_mutex);
332 pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800333 LYDBGLOG("triggerGetCallList event!!!\n");
ll04ae4142022-01-27 05:54:38 +0000334 memset(call_list,0,sizeof(call_list));
335 ret = lynq_get_current_call_list(call_list);
336 if(ret != 0)
337 {
338 printf("get current call list failure!!!\n");
339 break;
340 }
lh7b0674a2022-01-10 00:34:35 -0800341 for(int i = 0;i < LYNQ_CALL_MAX;i++)
342 {
343 if(call_list[i].direction == 1)//MT call
344 {
345 if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
346 {
347 if(!checkHasCall(call_list[i].addr))
348 {
349 lynqIncomingCallId = getUnusedElement();
350 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);
351 sendSignalIncomingCall();
352 }
353 }
354 }
355 else
356 {
357 if(call_list[i].call_id==0)
358 {
359 break;
360 }
361 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
362 {
363 if(lynq_call_lists[n].hasTimeout==1)
364 {
365 /*hangup call with id*/
366 lynq_call_hungup(&n);
367 lynq_call_lists[n].hasTimeout==0;
368 continue;
369 }
370 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
371 {
372 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
373 }
374 }
375 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,
376 call_list[i].direction,call_list[i].addr,call_list[i].toa);
377 }
ll04ae4142022-01-27 05:54:38 +0000378 }
lh42c1e572022-01-25 18:47:39 -0800379 s_call_urc_event_complete = 1;
lh7b0674a2022-01-10 00:34:35 -0800380 if(isDial==1)
381 {
382 sendSignalToWaitCallStateChange();
383 isDial = 0;
384 }
ll04ae4142022-01-27 05:54:38 +0000385 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
386 }
387 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800388}
389
390void lynqRespWatingEvent()
ll04ae4142022-01-27 05:54:38 +0000391{
392 if(s_call_urc_event_complete==1)
393 {
394 pthread_mutex_lock(&s_urc_call_state_change_mutex);
395 pthread_cond_signal(&s_urc_call_state_change_cond);
396 s_call_urc_event_complete = 0;
397 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800398 }
ll04ae4142022-01-27 05:54:38 +0000399 return;
lh7b0674a2022-01-10 00:34:35 -0800400}
401
402/*Warren add for T800 platform 2021/11/19 start*/
403int lynq_socket_client_start()
404{
405 struct sockaddr_in lynq_socket_server_addr;
406 /* init lynq_socket_server_addr */
407 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
408 lynq_socket_server_addr.sin_family = AF_INET;
409 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
410 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
411 /*
412 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
413 {
414 printf("[%s] is not a valid IPaddress\n", argv[1]);
415 exit(1);
416 }
417*/
lh42c1e572022-01-25 18:47:39 -0800418 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
419 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800420 {
lh21502f52022-01-27 00:27:12 -0800421 LYERRLOG("connect error:%s",strerror(errno));
lh7b0674a2022-01-10 00:34:35 -0800422 return -1;
423 }
424 return 0;
425}
426int lynq_update_call_list_loop()
427{
428 int ret = 0;
429 pthread_t tid;
430 pthread_attr_t attr;
431 pthread_attr_init(&attr);
432 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
433 ret = pthread_create(&tid,&attr,triggerGetCallList,NULL);
434 if(ret < 0)
435 {
436 LYERRLOG("lynq_update_call_list_loop fail!!!");
437 return -1;
438 }
439 LYDBGLOG("lynq_update_call_list_loop success!!!\n");
440 return 0;
441
442}
443void *thread_urc_recv(void *parg)
ll04ae4142022-01-27 05:54:38 +0000444{
lh7b0674a2022-01-10 00:34:35 -0800445 int socket_fd = (int64_t)parg;
446 int len=0;
447 socklen_t addr_len=0;
448 uint8_t *dataLength = NULL;
449 char urc_data[LYNQ_REC_BUF];
450 int slot_id = -1;
451 int resp_type = -1;
452 int urcid = -1;
453 Parcel *p = NULL;
454 struct sockaddr_in dest_addr;
455 LYINFLOG("thread_urc_recv in running....\n");
lh42c1e572022-01-25 18:47:39 -0800456 while(urc_call_recive_status)
lh7b0674a2022-01-10 00:34:35 -0800457 {
458 bzero(urc_data,LYNQ_REC_BUF);
459 //get data msg
460 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
461 if(len <= 0)
ll04ae4142022-01-27 05:54:38 +0000462 {
lh21502f52022-01-27 00:27:12 -0800463 LYERRLOG("thread_urc_recv step2 fail:%s",strerror(errno));
ll04ae4142022-01-27 05:54:38 +0000464 break;
lh7b0674a2022-01-10 00:34:35 -0800465 }
466 LYDBGLOG("=====>urc data len<=====:%d\n",len);
467 p = new Parcel();
468 if(p==NULL)
469 {
lh21502f52022-01-27 00:27:12 -0800470 LYERRLOG("new parcel failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800471 break;
472 }
473 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
474 p->setDataPosition(0);
475 if(p->dataAvail() > 0)
476 {
477 p->readInt32(&resp_type);
478 p->readInt32(&urcid);
479 p->readInt32(&slot_id);
480 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
481 switch (urcid)
482 {
483 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
484 {
485 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
486 lynqRespWatingEvent();
487 break;
488 }
489 case 1018://RIL_UNSOL_CALL_RING
490 {
491 if(global_call_auto_answer==1)
492 {
493 lynq_call_answer();
494 }
495 break;
496 }
497 case 1029://RIL_UNSOL_RINGBACK_TONE
498 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
499 {
500 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
501 break;
502 }
503 default:
504 break;
505 }
506 }
507 delete p;
508 p = NULL;
509 }
510 close(socket_fd);
511}
512int lynq_socket_urc_start()
513{
514 int socket_fd=0;
515 int rt=0;
516 int len=0;
517 int on=1;
518 struct sockaddr_in urc_local_addr;
519 pthread_t tid;
520 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000521 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000522 if(socket_fd < 0)
523 {
lh21502f52022-01-27 00:27:12 -0800524 LYERRLOG("creaet socket for udp fail:%s",strerror(errno));
ll04ae4142022-01-27 05:54:38 +0000525 return -1;
lh7b0674a2022-01-10 00:34:35 -0800526 }
527 urc_local_addr.sin_family = AF_INET;
528 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
529 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
530 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000531 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
532 if(rt<0)
533 {
lh21502f52022-01-27 00:27:12 -0800534 LYERRLOG("SO_REUSEADDR fail:%s",strerror(errno));
535 perror("SO_REUSEADDR fail:");
lh7b0674a2022-01-10 00:34:35 -0800536 return -1;
537 }
538 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000539 if (rt == -1)
540 {
lh21502f52022-01-27 00:27:12 -0800541 LYERRLOG("bind failed");
542 perror("bind failed:");
ll04ae4142022-01-27 05:54:38 +0000543 return -1;
lh7b0674a2022-01-10 00:34:35 -0800544 }
545 pthread_attr_init(&attr);
546 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
547 rt = pthread_create(&tid,&attr,thread_urc_recv,(void *)socket_fd);
548 if(rt < 0)
549 {
lh21502f52022-01-27 00:27:12 -0800550 LYERRLOG("urc loop failure!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800551 return -1;
552 }
lh21502f52022-01-27 00:27:12 -0800553 LYDBGLOG("urc loop success!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800554 return 0;
555}
556int getSelfElement(char addr[])
557{
558 for(int i=0;i < LYNQ_CALL_MAX; i++)
559 {
560 if(lynq_call_lists[i].used==1)
561 {
562 if(strcmp(lynq_call_lists[i].addr,addr)==0)
563 {
564 return i;
565 }
566
567 }
568 }
569 return -1;
570}
571
572void lynq_call_state_change_test(int soc_id)
573{
574 printf("call state change,sim:%d\n",soc_id);
575}
576int lynq_init_call(int uToken)
577{
578 int result = 0;
lh42c1e572022-01-25 18:47:39 -0800579 Global_uToken_call = uToken;
lh21502f52022-01-27 00:27:12 -0800580 urc_call_recive_status = 1;
lh7b0674a2022-01-10 00:34:35 -0800581 LYLOGSET(LOG_INFO);
582 LYLOGEINIT(USER_LOG_TAG);
583 result = lynq_socket_client_start();
584 if(result!=0)
585 {
586 return -1;
587 }
588 result = lynq_socket_urc_start();
589 if(result!=0)
590 {
591 return -1;
592 }
593 result = lynq_update_call_list_loop();
594 if(result!=0)
595 {
596 return -1;
597 }
598 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
599 LYDBGLOG("lynq init call success!!!");
600 return 0;
601}
602int lynq_deinit_call()
603{
lh42c1e572022-01-25 18:47:39 -0800604 close(lynq_call_client_sockfd);
605 urc_call_recive_status = 0;
lh7b0674a2022-01-10 00:34:35 -0800606 call_list_loop = 0;
607 return 0;
608}
609int lynq_call(int* handle,char addr[])
610{
611 Parcel p;
612 lynq_client_t client;
613 int resp_type = -1;
614 int request = -1;
615 int slot_id = -1;
616 int error = -1;
617 int lynq_call_id = -1;
618 if(addr==NULL)
619 {
620 LYERRLOG("Phone num is null!!!");
621 return -1;
622 }
lh42c1e572022-01-25 18:47:39 -0800623 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800624 client.request = 10;//RIL_REQUEST_DIAL
625 client.paramLen = 2;
626 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
627 memcpy(client.param,addr,strlen(addr)+1);
628 strcat(client.param," 0");
629 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800630 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800631 {
632 LYERRLOG("send request fail");
633 perror("[LYNQ_CALL] send request fail:");
634 return -1;
635 }
lh42c1e572022-01-25 18:47:39 -0800636 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800637 JumpHeader(p,&resp_type,&request,&slot_id,&error);
638 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
639 lynq_call_id = updateAddr(addr);
640 if(error==0)
641 {
642 isDial = 1;
643 if(waitCallstateChange(3000)==ETIMEDOUT)//3000ms
644 {
645 error = LYNQ_E_TIME_OUT;
646 LYERRLOG("timeout:wait Call state fail!!!");
647 lynq_call_lists[lynq_call_id].hasTimeout = 1;
648 return error;
649 }
650 *handle = lynq_call_id;
651 }
652 return error;
653}
654int lynq_call_answer()
655{
656 Parcel p;
657 lynq_client_t client;
658 int resp_type = -1;
659 int request = -1;
660 int slot_id = -1;
661 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800662 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800663 client.request = 40;//RIL_REQUEST_DIAL
664 client.paramLen = 0;
665 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
666 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800667 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800668 {
669 LYERRLOG("send request fail");
670 perror("[LYNQ_CALL] send request fail:");
671 return -1;
672 }
lh42c1e572022-01-25 18:47:39 -0800673 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800674 JumpHeader(p,&resp_type,&request,&slot_id,&error);
675 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
676 return error;
677}
678int lynq_call_hungup(int* handle)
679{
680 Parcel p;
681 lynq_client_t client;
682 int resp_type = -1;
683 int request = -1;
684 int slot_id = -1;
685 int error = -1;
686 int call_id = 0;
687 int lynq_call_id = 0;
lh42c1e572022-01-25 18:47:39 -0800688 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
689 {
690 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
691 return LYNQ_E_CONFLICT;
692 }
693 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800694 client.request = 12;//RIL_REQUEST_HUNGUP
695 client.paramLen = 1;
696 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
697 lynq_call_id = *handle;
698 call_id = lynq_call_lists[lynq_call_id].call_id;
699 sprintf(client.param,"%d",call_id);
700 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800701 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800702 {
703 LYERRLOG("send request fail");
704 perror("[LYNQ_CALL] send request fail:");
705 return -1;
706 }
lh42c1e572022-01-25 18:47:39 -0800707 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800708 JumpHeader(p,&resp_type,&request,&slot_id,&error);
709 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
710 if(error==0)
711 {
712 cleanCallList(lynq_call_id);
713 }
714 return error;
715}
716int lynq_call_hungup_all()
717{
718 Parcel p;
719 lynq_client_t client;
720 int resp_type = -1;
721 int request = -1;
722 int slot_id = -1;
723 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800724 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800725 client.request = 17;//RIL_REQUEST_UDUB
726 client.paramLen = 0;
727 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
728 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800729 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800730 {
731 LYERRLOG("send request fail");
732 perror("[LYNQ_CALL] send request fail:");
733 return -1;
734 }
lh42c1e572022-01-25 18:47:39 -0800735 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800736 JumpHeader(p,&resp_type,&request,&slot_id,&error);
737 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
738 return error;
739}
740int lynq_wait_incoming_call(int *handle)
741{
742 waitIncomingCall();
743 *handle = lynqIncomingCallId;
744 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
745 return 0;
746}
747
748int lynq_set_auto_answercall(const int mode)
749{
750 global_call_auto_answer = mode;
751 LYINFLOG("auto answer call mode =%d",mode);
752 return 0;
753}
754int lynq_get_mute_status(int *status)
755{
756 Parcel p;
757 lynq_client_t client;
758 int resp_type = -1;
759 int request = -1;
760 int slot_id = -1;
761 int error = -1;
762 if(status==NULL)
763 {
764 LYERRLOG("status is null");
765 return -1;
766 }
lh42c1e572022-01-25 18:47:39 -0800767 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800768 client.request = 54;//RIL_REQUEST_GET_MUTE
769 client.paramLen = 0;
770 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
771 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800772 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800773 {
774 LYERRLOG("send request fail");
775 perror("[LYNQ_CALL] send request fail:");
776 return -1;
777 }
lh42c1e572022-01-25 18:47:39 -0800778 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800779 JumpHeader(p,&resp_type,&request,&slot_id,&error);
780 p.readInt32(status);
781 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
782 return error;
783}
lldc99c9b2022-01-24 12:16:22 +0000784
785static int judge_mic(const int enable){
786 if(enable != 1 || enable != 0){
787 return 0;
788 }
ll04ae4142022-01-27 05:54:38 +0000789 return 1;
lldc99c9b2022-01-24 12:16:22 +0000790}
791
lh7b0674a2022-01-10 00:34:35 -0800792int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +0000793{
794 if(!judge_mic(enable)){
795 return LYNQ_E_CONFLICT;
796 }
lh7b0674a2022-01-10 00:34:35 -0800797 Parcel p;
798 lynq_client_t client;
799 int resp_type = -1;
800 int request = -1;
801 int slot_id = -1;
802 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800803 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800804 client.request = 53;//RIL_REQUEST_SET_MUTE
805 client.paramLen = 1;
806 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
807 sprintf(client.param,"%d",enable);
808 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800809 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800810 {
811 LYERRLOG("send request fail");
812 perror("[LYNQ_CALL] send request fail:");
813 return -1;
814 }
lh42c1e572022-01-25 18:47:39 -0800815 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800816 JumpHeader(p,&resp_type,&request,&slot_id,&error);
817 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
818 return error;
819}
820int lynq_set_DTMF(const char callnum)
821{
822 Parcel p;
823 lynq_client_t client;
824 int resp_type = -1;
825 int request = -1;
826 int slot_id = -1;
827 int error = -1;
828 if(!lynq_call_state)
829 {
830 LYERRLOG("LYNQ_E_CONFLICT");
831 return LYNQ_E_CONFLICT;
832 }
lh42c1e572022-01-25 18:47:39 -0800833 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800834 client.request = 24;//RIL_REQUEST_DTMF
835 client.paramLen = 1;
836 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
837 sprintf(client.param,"%c",callnum);
838 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800839 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800840 {
841 LYERRLOG("send request fail");
842 perror("[LYNQ_CALL] send request fail:");
843 return -1;
844 }
lh42c1e572022-01-25 18:47:39 -0800845 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800846 JumpHeader(p,&resp_type,&request,&slot_id,&error);
847 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
848 return error;
849
850}
lldc99c9b2022-01-24 12:16:22 +0000851
852static int judge_volume(const int volume){
853 if(volume < 0 ||volume >36){
854 return 0;
855 }
ll04ae4142022-01-27 05:54:38 +0000856 return 1;
lldc99c9b2022-01-24 12:16:22 +0000857}
858
lh7b0674a2022-01-10 00:34:35 -0800859int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +0000860{
861 if(!judge_volume(volume)){
862 return LYNQ_E_CONFLICT;
863 }
lh7b0674a2022-01-10 00:34:35 -0800864 Parcel p;
865 lynq_client_t client;
866 int resp_type = -1;
867 int request = -1;
868 int slot_id = -1;
869 int error = -1;
870 //if(!lynq_call_state)
871 //{
872 // LYERRLOG("LYNQ_E_CONFLICT");
873 // return LYNQ_E_CONFLICT;
874 //}
lh42c1e572022-01-25 18:47:39 -0800875 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800876 client.request = 8003;//LYNQ_REQUEST_SET_DTMF_VOLUME
877 client.paramLen = 1;
878 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
879 sprintf(client.param,"%d",volume);
880 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800881 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800882 {
883 LYERRLOG("send request fail");
884 perror("[LYNQ_CALL] send request fail:");
885 return -1;
886 }
lh42c1e572022-01-25 18:47:39 -0800887 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800888 JumpHeader(p,&resp_type,&request,&slot_id,&error);
889 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
890 return 0;
891}
892int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
893{
894 int lynq_call_id = 0;
895 if(handle==NULL)
896 {
897 return LYNQ_E_NULL_ANONALY;
898 }
899 lynq_call_id = *handle;
900 *call_state = lynq_call_lists[lynq_call_id].call_state;
901 *toa = lynq_call_lists[lynq_call_id].toa;
902 *direction = lynq_call_lists[lynq_call_id].direction;
903 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
904 return 0;
905}
906
907#if 0
908int main(int argc,char **argv)
909{
910 int n = 0;
911 n = lynq_init_call(lynq_call_state_change_test,2222);
912 if(n<0)
913 {
914 printf("lynq init call fail!!!\n");
915 return -1;
916 }
917 printf("lynq call init success!!!\n");
918 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
919 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
920 lynq_call(phoneNum);
921 while(1)
922 {
923 sleep(1);
924 }
925 return 0;
926}
927#endif
928/*Warren add for T800 platform 2021/11/19 end*/