blob: 6091329f901377e8a74025921995a35fdd29834a [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>
16
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 {
125 perror("write error");
126 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 {
140 perror("read error");
141 return -1;
142 }
143 printf("===>n=%d\n",len);
144 if (recvline != NULL) {
145 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
146 p.setDataPosition(0);
147 }
148 return 0;
149}
150static char *strdupReadString(Parcel &p) {
ll04ae4142022-01-27 05:54:38 +0000151 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800152 const char16_t *s16;
153 s16 = p.readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000154 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800155}
156
157int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
158{
159 Parcel p;
160 lynq_client_t client;
161 int resp_type = -1;
162 int request = -1;
163 int slot_id = -1;
164 int error = -1;
165 int call_num = 0;
166 int temp = 0;
167 char *remote_phoneNum = NULL;
168 char *remote_name= NULL;
169 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800170 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800171 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
172 client.paramLen = 0;
173 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
174 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800175 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800176 {
177 LYERRLOG("send request fail");
178 perror("[LYNQ_CALL] send request fail:");
179 return -1;
180 }
lh42c1e572022-01-25 18:47:39 -0800181 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800182 JumpHeader(p,&resp_type,&request,&slot_id,&error);
183 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
184 if(error == 0)
185 {
186 p.readInt32(&call_num);
187 global_call_count = call_num;
188 if(call_num<=0)
189 {
190 lynq_call_state = CALL_OFF;
191 return 0;
192 }
193 for(int i = 0;i < call_num;i++)
194 {
195 p.readInt32(&temp);
196 call_list[i].call_state = temp;
197 p.readInt32(&call_list[i].call_id);
198 p.readInt32(&call_list[i].toa);
199 p.readInt32(&temp);
200 p.readInt32(&temp);
201 call_list[i].direction = temp;
202 p.readInt32(&temp);
203 p.readInt32(&temp);
204 p.readInt32(&temp);
205 remote_phoneNum = strdupReadString(p);
206 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
207 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
208 call_list[i].direction,call_list[i].addr,call_list[i].toa);
209 p.readInt32(&temp);
210 remote_name = strdupReadString(p);
211 p.readInt32(&temp);
212 p.readInt32(&temp);
213 if(temp==0)
214 {
215 continue;
216 }
217 p.readInt32(&temp); /* UUS Information is present */
218 p.readInt32(&temp);
219 p.readInt32(&temp);
220 p.read(uusData,temp);
221 }
222 }
223 return 0;
224}
225
226void cleanCallList(int lynq_call_id)
227{
228 lynq_call_lists[lynq_call_id].call_id = 0;
229 lynq_call_lists[lynq_call_id].call_state = 0;
230 lynq_call_lists[lynq_call_id].toa = 0;
231 lynq_call_lists[lynq_call_id].direction = 0;
232 lynq_call_lists[lynq_call_id].used = 0;
233 lynq_call_lists[lynq_call_id].hasTimeout = 0;
234 memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
235}
236int getUnusedElement()
237{
238 for(int i=0;i < LYNQ_CALL_MAX; i++)
239 {
240 if(lynq_call_lists[i].used!=1)
241 {
242 return i;
243 }
244 }
245 return -1;
246}
247int updateAddr(char addr[])
248{
249 int ret = 0;
250 ret = getUnusedElement();
251 memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
252 lynq_call_lists[ret].used = 1;
253 return ret;
254}
255void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
256{
257 callList->call_id = call_id;
258 callList->call_state = call_state;
259 callList->toa = toa;
260 callList->direction = direction;
261 callList->used = 1;
262 callList->hasTimeout = 0;
263 return;
264}
265int waitCallstateChange(int mtime)
266{
267 int ret = 0;
268 int sec = 0;
269 int usec = 0;
lh2afc7732022-01-10 02:24:31 -0800270 struct timeval now;
271 struct timespec timeout;
272 gettimeofday(&now,NULL);
lh7b0674a2022-01-10 00:34:35 -0800273 sec = mtime/1000;
274 usec = mtime%1000;
lh2afc7732022-01-10 02:24:31 -0800275 timeout.tv_sec = now.tv_sec+sec;
276 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh7b0674a2022-01-10 00:34:35 -0800277 pthread_mutex_lock(&call_state_change_mutex);
lh2afc7732022-01-10 02:24:31 -0800278 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh7b0674a2022-01-10 00:34:35 -0800279 pthread_mutex_unlock(&call_state_change_mutex);
280 return ret;
281}
282int waitIncomingCall()
283{
284 int ret = 0;
285 pthread_mutex_lock(&s_incoming_call_mutex);
286 ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
287 pthread_mutex_unlock(&s_incoming_call_mutex);
288 return ret;
289}
290int checkHasCall(char addr[])
291{
292 for(int i = 0;i<LYNQ_CALL_MAX;i++)
293 {
294 if(strcmp(lynq_call_lists[i].addr,addr)==0)
295 {
296 return 1;
297 }
298 }
299 return 0;
300}
301void sendSignalToWaitCallStateChange()
302{
303 pthread_mutex_lock(&call_state_change_mutex);
304 pthread_cond_signal(&call_state_change_cond);
305 pthread_mutex_unlock(&call_state_change_mutex);
306}
307void sendSignalIncomingCall()
308{
309 pthread_mutex_lock(&s_incoming_call_mutex);
310 pthread_cond_signal(&s_incoming_call_cond);
311 pthread_mutex_unlock(&s_incoming_call_mutex);
312}
313
314void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
315{
316 callList->call_id = call_id;
317 callList->call_state = call_state;
318 callList->toa = toa;
319 callList->direction = direction;
320 memcpy(callList->addr,addr,strlen(addr)+1);
321 callList->used = 1;
322 callList->hasTimeout = 0;
323 return;
324}
325
326void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000327{
328 int ret=0;
329 lynq_call_list_t call_list[LYNQ_CALL_MAX];
lh7b0674a2022-01-10 00:34:35 -0800330 while(call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000331 {
332 pthread_mutex_lock(&s_urc_call_state_change_mutex);
333 pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800334 LYDBGLOG("triggerGetCallList event!!!\n");
ll04ae4142022-01-27 05:54:38 +0000335 memset(call_list,0,sizeof(call_list));
336 ret = lynq_get_current_call_list(call_list);
337 if(ret != 0)
338 {
339 printf("get current call list failure!!!\n");
340 break;
341 }
lh7b0674a2022-01-10 00:34:35 -0800342 for(int i = 0;i < LYNQ_CALL_MAX;i++)
343 {
344 if(call_list[i].direction == 1)//MT call
345 {
346 if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
347 {
348 if(!checkHasCall(call_list[i].addr))
349 {
350 lynqIncomingCallId = getUnusedElement();
351 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);
352 sendSignalIncomingCall();
353 }
354 }
355 }
356 else
357 {
358 if(call_list[i].call_id==0)
359 {
360 break;
361 }
362 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
363 {
364 if(lynq_call_lists[n].hasTimeout==1)
365 {
366 /*hangup call with id*/
367 lynq_call_hungup(&n);
368 lynq_call_lists[n].hasTimeout==0;
369 continue;
370 }
371 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
372 {
373 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
374 }
375 }
376 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,
377 call_list[i].direction,call_list[i].addr,call_list[i].toa);
378 }
ll04ae4142022-01-27 05:54:38 +0000379 }
lh42c1e572022-01-25 18:47:39 -0800380 s_call_urc_event_complete = 1;
lh7b0674a2022-01-10 00:34:35 -0800381 if(isDial==1)
382 {
383 sendSignalToWaitCallStateChange();
384 isDial = 0;
385 }
ll04ae4142022-01-27 05:54:38 +0000386 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
387 }
388 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800389}
390
391void lynqRespWatingEvent()
ll04ae4142022-01-27 05:54:38 +0000392{
393 if(s_call_urc_event_complete==1)
394 {
395 pthread_mutex_lock(&s_urc_call_state_change_mutex);
396 pthread_cond_signal(&s_urc_call_state_change_cond);
397 s_call_urc_event_complete = 0;
398 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800399 }
ll04ae4142022-01-27 05:54:38 +0000400 return;
lh7b0674a2022-01-10 00:34:35 -0800401}
402
403/*Warren add for T800 platform 2021/11/19 start*/
404int lynq_socket_client_start()
405{
406 struct sockaddr_in lynq_socket_server_addr;
407 /* init lynq_socket_server_addr */
408 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
409 lynq_socket_server_addr.sin_family = AF_INET;
410 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
411 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
412 /*
413 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
414 {
415 printf("[%s] is not a valid IPaddress\n", argv[1]);
416 exit(1);
417 }
418*/
lh42c1e572022-01-25 18:47:39 -0800419 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
420 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800421 {
422 perror("connect error");
423 return -1;
424 }
425 return 0;
426}
427int lynq_update_call_list_loop()
428{
429 int ret = 0;
430 pthread_t tid;
431 pthread_attr_t attr;
432 pthread_attr_init(&attr);
433 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
434 ret = pthread_create(&tid,&attr,triggerGetCallList,NULL);
435 if(ret < 0)
436 {
437 LYERRLOG("lynq_update_call_list_loop fail!!!");
438 return -1;
439 }
440 LYDBGLOG("lynq_update_call_list_loop success!!!\n");
441 return 0;
442
443}
444void *thread_urc_recv(void *parg)
ll04ae4142022-01-27 05:54:38 +0000445{
lh7b0674a2022-01-10 00:34:35 -0800446 int socket_fd = (int64_t)parg;
447 int len=0;
448 socklen_t addr_len=0;
449 uint8_t *dataLength = NULL;
450 char urc_data[LYNQ_REC_BUF];
451 int slot_id = -1;
452 int resp_type = -1;
453 int urcid = -1;
454 Parcel *p = NULL;
455 struct sockaddr_in dest_addr;
456 LYINFLOG("thread_urc_recv in running....\n");
lh42c1e572022-01-25 18:47:39 -0800457 while(urc_call_recive_status)
lh7b0674a2022-01-10 00:34:35 -0800458 {
459 bzero(urc_data,LYNQ_REC_BUF);
460 //get data msg
461 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
462 if(len <= 0)
ll04ae4142022-01-27 05:54:38 +0000463 {
lh7b0674a2022-01-10 00:34:35 -0800464 perror("thread_urc_recv step2 fail:");
ll04ae4142022-01-27 05:54:38 +0000465 break;
lh7b0674a2022-01-10 00:34:35 -0800466 }
467 LYDBGLOG("=====>urc data len<=====:%d\n",len);
468 p = new Parcel();
469 if(p==NULL)
470 {
471 RLOGD("new parcel failure!!!");
472 break;
473 }
474 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
475 p->setDataPosition(0);
476 if(p->dataAvail() > 0)
477 {
478 p->readInt32(&resp_type);
479 p->readInt32(&urcid);
480 p->readInt32(&slot_id);
481 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
482 switch (urcid)
483 {
484 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
485 {
486 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
487 lynqRespWatingEvent();
488 break;
489 }
490 case 1018://RIL_UNSOL_CALL_RING
491 {
492 if(global_call_auto_answer==1)
493 {
494 lynq_call_answer();
495 }
496 break;
497 }
498 case 1029://RIL_UNSOL_RINGBACK_TONE
499 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
500 {
501 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
502 break;
503 }
504 default:
505 break;
506 }
507 }
508 delete p;
509 p = NULL;
510 }
511 close(socket_fd);
512}
513int lynq_socket_urc_start()
514{
515 int socket_fd=0;
516 int rt=0;
517 int len=0;
518 int on=1;
519 struct sockaddr_in urc_local_addr;
520 pthread_t tid;
521 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000522 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
523 printf("test 001\n");
524 if(socket_fd < 0)
525 {
lh7b0674a2022-01-10 00:34:35 -0800526 perror("creaet socket for udp fail");
ll04ae4142022-01-27 05:54:38 +0000527 return -1;
lh7b0674a2022-01-10 00:34:35 -0800528 }
529 urc_local_addr.sin_family = AF_INET;
530 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
531 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
532 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000533 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
534 if(rt<0)
535 {
lh7b0674a2022-01-10 00:34:35 -0800536 perror("SO_REUSEADDR fail\n");
537 return -1;
538 }
539 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000540 if (rt == -1)
541 {
lh7b0674a2022-01-10 00:34:35 -0800542 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 {
550 printf("urc loop failure!!!\n");
551 return -1;
552 }
553 printf("urc loop success!!!\n");
554 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;
580 call_list_loop = 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*/