blob: 8e80462f73e1fca0e821856036f1687368644e04 [file] [log] [blame]
you.chen5ef374a2023-12-26 17:25:16 +08001
2#include <stdio.h>
3#include <sys/types.h>
4#include <sys/socket.h>
5#include <arpa/inet.h>
6#include <fcntl.h>
7#include <string.h>
8#include <stdlib.h>
9#include <unistd.h>
10#include <binder/Parcel.h>
11#include <log/log.h>
12#include <cutils/jstring.h>
13#include <pthread.h>
14#include "liblog/lynq_deflog.h"
15#include <sys/time.h>
16#include <string.h>
17#include <vendor-ril/telephony/ril.h>
18#include <vendor-ril/telephony/mtk_ril_sp.h>
19#include <vendor-ril/telephony/mtk_ril_ivt.h>
20#include "lynq_call.h"
21#include "lynq_module_common.h"
22#include "lynq_module_socket.h"
23#include "lynq_call_common.h"
24
25#define CALL_OFF (0)
26#define CALL_ON (1)
27#define USER_LOG_TAG "LYNQ_CALL"
28
29#define AP_SPEECH "/tmp/ap_speech"
30#define AUDIO_CTRL_SER "/tmp/audio_ctrl_service"
31#define LIBMODEM_AFE "/tmp/libmodem-afe-ctrl"
32#define TELE_DEMO_LOCK "/tmp/tel_demo_single_proc.lock"
33
34using ::android::Parcel;
35
36/**
37 * @brief mark call initialization state
38 * 0: deinit state
39 * 1: init state
40 */
41int g_module_init_flag = 0;
42
43 typedef enum {
44 LYNQ_CALL_ACTIVE = 0,
45 LYNQ_CALL_HOLDING = 1,
46 LYNQ_CALL_DIALING = 2, /* MO call only */
47 LYNQ_CALL_ALERTING = 3, /* MO call only */
48 LYNQ_CALL_INCOMING = 4, /* MT call only */
49 LYNQ_CALL_WAITING = 5, /* MT call only */
50 /*warren add for T800 platform 2022/04/26 start*/
51 LYNQ_CALL_END = 6, /*CALL END*/
52 /*warren add for T800 platform 2022/04/26 end*/
53}lynq_call_state_t;
54
55typedef struct
56{
57 int used;
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_e_t;
64typedef struct
65{
66 int call_id;
67 int call_state;
68 int toa;
69 int direction;/*0: MO call,1:MT call*/
70 char addr[LYNQ_PHONE_NUMBER_MAX];
71}lynq_call_list_t;
72
73static lynq_call_list_e_t s_call_lists[LYNQ_CALL_MAX]={};
74static bool s_call_list_loop = 0;
75static pthread_t s_call_list_loop_tid = -1;
76static pthread_mutex_t s_notice_get_call_list_mutex = PTHREAD_MUTEX_INITIALIZER;
77static pthread_cond_t s_notice_get_call_list_cond = PTHREAD_COND_INITIALIZER;
78
79static int s_module_isDial = 0;
80static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
81static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
82static int s_CallId = 0;
83static pthread_mutex_t s_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
84static pthread_cond_t s_call_state_change_cond = PTHREAD_COND_INITIALIZER;
85
86static int s_module_call_state =CALL_OFF;
87static int s_call_auto_answer = 0;
88
89typedef enum{
90 LYNQ_E_VOLUMN_SET_DTMF,
91 LYNQ_E_VOLUMN_SET_SPEECH
92}LYNQ_E_VOLUMN_SET;
93
94#if 0
95int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
96{
97 if(p.dataAvail() > 0)
98 {
99 p.readInt32(resp_type);
100 p.readInt32(token);
101 p.readInt32(request);
102 p.readInt32(slot_id);
103 p.readInt32(error);
104 return 0;
105 }
106 else
107 {
108 return -1;
109 }
110}
111int send_request(int sockfd,lynq_client_t *client_tmp)
112{
113 int ret=0;
114 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
115 if(ret==-1)
116 {
117 LYERRLOG("sendto error");
118 return -1;
119 }
120 return 0;
121}
122
123int get_response(int sockfd,Parcel &p)
124{
125 int len = 0;
126 char recvline[LYNQ_REC_BUF];
127 bzero(recvline,LYNQ_REC_BUF);
128 /* receive data from server */
129 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
130 if(len == -1)
131 {
132 LYERRLOG("recvfrom error");
133 return -1;
134 }
135 if (recvline != NULL) {
136 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
137 p.setDataPosition(0);
138 }
139 return 0;
140}
141#endif
142static char *strdupReadString(Parcel* &p) {
143 size_t stringlen;
144 const char16_t *s16;
145 s16 = p->readString16Inplace(&stringlen);
146 return strndup16to8(s16, stringlen);
147}
148
149int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
150{
151 Parcel* p=NULL;
152 int ret=lynq_send_common_request(p,8,RIL_REQUEST_GET_CURRENT_CALLS,0,"");
153 if(ret!=0)
154 {
155 return ret;
156 }
157
158 int call_num = 0;
159 int temp = 0;
160 char *remote_phoneNum;
161 char *remote_name;
162 char uusData[128];
163
164 p->readInt32(&call_num);
165
166 if(call_num<=0)
167 {
168 s_module_call_state = CALL_OFF;
169 LYINFLOG("lynq_call_state:%d",s_module_call_state);
170 delete p;
171 return RESULT_OK;
172 }
173 s_module_call_state = CALL_ON;
174 LYINFLOG("lynq_call_state:%d, call num is %d ",s_module_call_state,call_num);
175 for(int i = 0;i < call_num;i++)
176 {
177 p->readInt32(&temp);
178 call_list[i].call_state = temp;
179 p->readInt32(&call_list[i].call_id);
180 p->readInt32(&call_list[i].toa);
181 p->readInt32(&temp);
182 p->readInt32(&temp);
183 call_list[i].direction = temp;
184 p->readInt32(&temp);
185 p->readInt32(&temp);
186 p->readInt32(&temp);
187 remote_phoneNum = strdupReadString(p);
188 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
189 if(remote_phoneNum !=NULL)
190 {
191 free(remote_phoneNum);
192 }
193 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
194 call_list[i].direction,call_list[i].addr,call_list[i].toa);
195 p->readInt32(&temp);
196 remote_name = strdupReadString(p);
197 if(remote_name !=NULL)
198 {
199 free(remote_name);
200 }
201 p->readInt32(&temp);
202 p->readInt32(&temp);
203 if(temp==0)
204 {
205 continue;
206 }
207 p->readInt32(&temp); /* UUS Information is present */
208 p->readInt32(&temp);
209 p->readInt32(&temp);
210 if(temp<=128)
211 {
212 p->read(uusData,temp);
213 }
214 else
215 {
216 LYERRLOG("%s len %d is too great",__func__,temp);
217 delete p;
218 return LYNQ_E_MALLOC_ERROR;
219 }
220 }
221
222 delete p;
223 return RESULT_OK;
224
225#if 0
226 Parcel p;
227 lynq_client_t client;
228 int resp_type = -1;
229 int token;
230 int request = -1;
231 int slot_id = -1;
232 int error = -1;
233 int call_num = 0;
234 int temp = 0;
235 char *remote_phoneNum = NULL;
236 char *remote_name= NULL;
237 char *uusData = NULL;
238 client.uToken = Global_uToken_call;
239 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
240 client.paramLen = 0;
241 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
242 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
243 if(send_request(lynq_call_client_sockfd,&client)==-1)
244 {
245 LYERRLOG("send request fail");
246 return -1;
247 }
248 get_response(lynq_call_client_sockfd,p);
249 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
250 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
251 if(error == 0)
252 {
253 p.readInt32(&call_num);
254 global_call_count = call_num;
255 if(call_num<=0)
256 {
257 lynq_call_state = CALL_OFF;
258 LYINFLOG("lynq_call_state:%d",lynq_call_state);
259 return 0;
260 }
261 lynq_call_state = CALL_ON;
262 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
263 for(int i = 0;i < call_num;i++)
264 {
265 p.readInt32(&temp);
266 call_list[i].call_state = temp;
267 p.readInt32(&call_list[i].call_id);
268 p.readInt32(&call_list[i].toa);
269 p.readInt32(&temp);
270 p.readInt32(&temp);
271 call_list[i].direction = temp;
272 p.readInt32(&temp);
273 p.readInt32(&temp);
274 p.readInt32(&temp);
275 remote_phoneNum = strdupReadString(p);
276 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
277 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
278 call_list[i].direction,call_list[i].addr,call_list[i].toa);
279 p.readInt32(&temp);
280 remote_name = strdupReadString(p);
281 p.readInt32(&temp);
282 p.readInt32(&temp);
283 if(temp==0)
284 {
285 continue;
286 }
287 p.readInt32(&temp); /* UUS Information is present */
288 p.readInt32(&temp);
289 p.readInt32(&temp);
290 p.read(uusData,temp);
291 }
292 }
293 return 0;
294#endif
295}
296
297void cleanCallList(int lynq_call_id)
298{
299 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
300 s_call_lists[lynq_call_id].call_id = 0;
301 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
302 s_call_lists[lynq_call_id].toa = 0;
303 s_call_lists[lynq_call_id].direction = 0;
304 s_call_lists[lynq_call_id].used = 0;
305 memset(s_call_lists[lynq_call_id].addr,0,sizeof(s_call_lists[lynq_call_id].addr));
306}
307
308
309int getUnusedElement()
310{
311 for(int i=0;i < LYNQ_CALL_MAX; i++)
312 {
313 if(s_call_lists[i].used!=1)
314 {
315 return i;
316 }
317 }
318 return INVALID_ID;
319}
320int addAddr(char addr[], int call_id)
321{
322 int ret = 0;
323 ret = getUnusedElement();
324 memcpy(s_call_lists[ret].addr,addr,strlen(addr)+1);
325 s_call_lists[ret].call_id=call_id;
326 s_call_lists[ret].used = 1;
327 LYINFLOG("add local idx is %d addr is %s",ret,addr);
328 return ret;
329}
330void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
331{
332 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
333 callList->call_id = call_id;
334 callList->call_state = call_state;
335 callList->toa = toa;
336 callList->direction = direction;
337 return;
338}
339
340void wait_call_state()
341{
342 LYINFLOG("call state changed");
343 pthread_mutex_lock(&s_call_state_change_mutex);
344 pthread_cond_wait(&s_call_state_change_cond,&s_call_state_change_mutex);
345 pthread_mutex_unlock(&s_call_state_change_mutex);
346}
347
348int checkHasCall(char addr[])
349{
350 for(int i = 0;i<LYNQ_CALL_MAX;i++)
351 {
352 if(strcmp(s_call_lists[i].addr,addr)==0)
353 {
354 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,s_call_lists[i].call_id);
355 return true;
356 }
357 }
358 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
359 return false;
360}
361int find_call_id_with_addr(char *addr)
362{
363 for(int id = 0; id < LYNQ_CALL_MAX; id++)
364 {
365 if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
366 {
367 LYINFLOG("find addr %s in local list, local idx is %d id is %d",addr,id,s_call_lists[id].call_id);
368 return id;
369 }
370 }
371 LYINFLOG("find addr %s in local list , not found",addr);
372 return INVALID_ID;
373}
374int find_call_id_with_call_id(int call_id)
375{
376 for(int id = 0; id < LYNQ_CALL_MAX; id++)
377 {
378 if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
379 {
380 LYINFLOG("find id %d in local list, local idx is %d, addr is %s",call_id,id,s_call_lists[id].addr);
381 return id;
382 }
383 }
384 LYINFLOG("find id %d in local list , not found",call_id);
385 return INVALID_ID;
386}
387void sendSignalToWaitCallStateChange()
388{
389 LYINFLOG("send Signal To Wait Call State Change");
390 pthread_mutex_lock(&call_state_change_mutex);
391 pthread_cond_signal(&call_state_change_cond);
392 pthread_mutex_unlock(&call_state_change_mutex);
393}
394void send_call_state_change(int callid)
395{
396 LYINFLOG("send call state change");
397 s_CallId = callid;
398 pthread_mutex_lock(&s_call_state_change_mutex);
399 pthread_cond_signal(&s_call_state_change_cond);
400 pthread_mutex_unlock(&s_call_state_change_mutex);
401}
402
403void cleanup_call_list_mutex(void *arg)
404{
405 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
406}
407
408void update_end_state(int lynq_call_id)
409{
410 LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
411 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
412}
413
414void *triggerGetCallList(void *parg)
415{
416 int ret=0;
417 bool call_end;
418 lynq_call_list_t call_list[LYNQ_CALL_MAX];
419 int update=0;
420 int cnt;
421 int i,n;
422#ifdef ECALL_SUPPORT
423 int handupIncomingMT=0;
424#endif
425 pthread_mutex_lock(&s_notice_get_call_list_mutex);
426 pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
427 int tmp_call_id;
428 while(s_call_list_loop)
429 {
430 update=0;
431 pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
432 LYINFLOG("triggerGetCallList event %p!!!", pthread_self());
433 memset(call_list,0,sizeof(call_list));
434 ret = lynq_get_current_call_list(call_list);
435 if(ret != RESULT_OK)
436 {
437 LYERRLOG("get current call list failure!!!");
438 continue;
439 }
440 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
441 LYINFLOG("clear local index begin");
442 cnt=0;
443 for(i = 0;i < LYNQ_CALL_MAX;i++)
444 {
445 if(s_call_lists[i].used ==0)
446 {
447 continue;
448 }
449 cnt++;
450 LYINFLOG("local idx is %d id is %d addr is %s state is %d direction is %d",i,s_call_lists[i].call_id,s_call_lists[i].addr,s_call_lists[i].call_state,s_call_lists[i].direction);
451
452 if(s_call_lists[i].call_id > 0)
453 {
454 call_end = 0;
455 for(n = 0; n < LYNQ_CALL_MAX; n++)
456 {
457 if(call_list[n].call_id == s_call_lists[i].call_id)
458 {
459 call_end = 1;
460 LYINFLOG("find lynq call local idx %d, service idx %d id is %d!!!",i,n,s_call_lists[i].call_id);
461 break;
462 }
463 }
464 if(call_end == 0)
465 {
466 LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
467 //update_end_state(i);//lei modify for:update end state for this call
468 tmp_call_id = s_call_lists[i].call_id;
469 cleanCallList(i);
470 //Release the end handle
471 send_call_state_change(tmp_call_id);//means mt/mo call is end
472 //cleanCallList(i);
473 }
474 } //fix bug API-54
475 else
476 {
477 LYINFLOG("local id is 0");
478 }
479 }
480 LYINFLOG("clear local index end, local used cnt is %d", cnt);
481
482 LYINFLOG("add or update local index begin ");
483 for (i = 0;i < LYNQ_CALL_MAX;i++)
484 {
485 if(call_list[i].call_id==0)
486 {
487 break;
488 }
489
490 LYINFLOG("servie idx %d begin: call_id=%d, call_state=%d, direction=%d, addr=%s, toa=%d",i,call_list[i].call_id, call_list[i].call_state,
491 call_list[i].direction,call_list[i].addr,call_list[i].toa);
492
493 if(call_list[i].direction == 1)//MT call
494 {
495 LYINFLOG("This is a MT CALL");
496 /*MT CALL state code
497 **LYNQ_CALL_INCOMING = 4,
498 **LYNQ_CALL_WAITING = 5,
499 */
500#ifdef ECALL_SUPPORT
501 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
502 {
503 handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
504 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
505 if(handupIncomingMT)
506 {
507 lynq_call_hungup(&(call_list[i].call_id));
508 continue;
509 }
510 }
511#endif
512 /*you call me, and i call you,One party failed to dial*/
513 n = find_call_id_with_addr(call_list[i].addr);
514 if(n ==INVALID_ID)
515 {
516 n = addAddr(call_list[i].addr,call_list[i].call_id);
517 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
518 send_call_state_change(call_list[i].call_id);
519 }
520 else if(s_call_lists[n].call_state == call_list[i].call_state)
521 {
522 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
523 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
524 {
525 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
526 **an incoming call until the status changes.
527 **fix bug API-54
528 */
529 LYINFLOG("resend incoming call signal");
530 send_call_state_change(call_list[i].call_id);
531 }
532 }
533 else
534 {
535 LYINFLOG("state changed from %d to %d",s_call_lists[n].call_state,call_list[i].call_state);
536
537 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);//update mt call
538 send_call_state_change(call_list[i].call_id);
539 }
540 }
541 else
542 {
543 LYINFLOG("This is a MO CALL");
544 call_end = 0;
545 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
546 {
547 if(s_call_lists[n].used && ((strcmp(call_list[i].addr,s_call_lists[n].addr)==0)||(call_list[i].call_id==s_call_lists[n].call_id)))
548 {
549 if(s_call_lists[n].call_id==0)
550 {
551 LYINFLOG("add a call id");
552 update=1;//for send sigal
553 }
554 LYINFLOG("local idx %d updated, original call id is %d origial addr is %s original state is %d",n,s_call_lists[n].call_id,s_call_lists[n].addr,s_call_lists[n].call_state);
555 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
556 call_end = 1;
557 send_call_state_change(call_list[i].call_id);//means mo call is success
558 break;
559 }
560 }
561 if(call_end == 0)//1.there is no space to use 2.can't find addr in buffer 3.call_id not equal eg:when call is error return 8004/handle <= 0 will into this
562 {
563 LYINFLOG("need to hangup id %d", call_list[i].call_id);
564#ifdef ECALL_SUPPORT
565 if(IsECallDialing())
566 {
567 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
568 continue;
569 }
570#endif
571 LYINFLOG("hang up service call id %d",call_list[i].call_id);
572 lynq_call_hungup(&(call_list[i].call_id));
573 }
574
575 }
576 LYDBGLOG("servie idx %d end",i);
577 }
578 LYINFLOG("add or update local index end ");
579 if(s_module_isDial==1)
580 {
581 LYINFLOG("now is dialing");
582 if(update==1)
583 {
584 LYINFLOG("find added call");
585 sendSignalToWaitCallStateChange();
586 s_module_isDial = 0;
587 }
588 else
589 {
590 LYINFLOG("not find added call");
591 }
592 }
593 else
594 {
595 LYINFLOG("now is not dialing");
596 }
597 }
598 pthread_cleanup_pop(0);
599 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
600 return NULL;
601}
602
603void lynqNoticeGetModuleCallList()
604{
605 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send start");
606 pthread_mutex_lock(&s_notice_get_call_list_mutex);
607 pthread_cond_signal(&s_notice_get_call_list_cond);
608 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
609 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send end");
610}
611
612#if 0
613/*Warren add for T800 platform 2021/11/19 start*/
614int lynq_socket_client_start()
615{
616 #if 0
617 struct sockaddr_in lynq_socket_server_addr;
618 /* init lynq_socket_server_addr */
619 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
620 lynq_socket_server_addr.sin_family = AF_INET;
621 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
622 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
623
624 /*
625 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
626 {
627 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
628 exit(1);
629 }
630*/
631 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
632 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
633 {
634 LYERRLOG("connect error");
635 return -1;
636 }
637 #endif
638 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
639 if (-1 == lynq_call_client_sockfd)
640 {
641 return lynq_call_client_sockfd;
642 }
643 struct timeval timeOut;
644 timeOut.tv_sec = 60;
645 timeOut.tv_usec = 0;
646 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
647 {
648 RLOGD("time out setting failed\n");
649 return -1;
650 }
651 /* 设置address */
652 memset(&addr_serv, 0, sizeof(addr_serv));
653 addr_serv.sin_family = AF_INET;
654 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
655 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
656 len_addr_serv = sizeof(addr_serv);
657 return 0;
658}
659
660int lynq_socket_urc_start()
661{
662 int socket_fd=0;
663 int rt=0;
664 int len=0;
665 int on=1;
666 struct sockaddr_in urc_local_addr;
667 pthread_attr_t attr;
668 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
669 if(socket_fd < 0)
670 {
671 LYERRLOG("creaet socket for udp fail");
672 return -1;
673 }
674 urc_local_addr.sin_family = AF_INET;
675 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
676 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
677 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
678 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
679 if(rt<0)
680 {
681 LYERRLOG("SO_REUSEADDR fail");
682 return -1;
683 }
684 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
685 if (rt == -1)
686 {
687 LYERRLOG("bind failed");
688 return -1;
689 }
690 pthread_attr_init(&attr);
691 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
692 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
693 if(rt < 0)
694 {
695 LYERRLOG("urc loop failure!!!");
696 return -1;
697 }
698 LYDBGLOG("urc loop success!!!");
699 return 0;
700}
701#endif
702
703void lynq_call_state_change_test(int soc_id)
704{
705 LYDBGLOG("call state change,sim:%d",soc_id);
706}
707
708int lynq_start_call_list_loop()
709{
710#if 0
711 int ret = 0;
712 pthread_attr_t attr;
713 pthread_attr_init(&attr);
714 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
715
716 s_notice_get_call_list_mutex = new pthread_mutex_t;
717 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
718 s_notice_get_call_list_cond = new pthread_cond_t;
719 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
720 pthread_cond_init(s_notice_get_call_list_cond, NULL);
721 LYINFLOG("liulei s_notice_get_call_list_cond\n");
722#endif
723
724 s_call_list_loop = 1;
725 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
726 if(ret < 0)
727 {
728 LYERRLOG("lynq_update_call_list_loop fail!!!");
729 return -1;
730 }
731 LYINFLOG("lynq_update_call_list_loop success!!!");
732
733 memset(s_call_lists,0,sizeof(s_call_lists));
734 return 0;
735}
736
737int lynq_stop_call_list_loop()
738{
739 int ret;
740 pthread_mutex_lock(&s_notice_get_call_list_mutex);
741 s_call_list_loop = 0;
742 ret = pthread_cancel(s_call_list_loop_tid);
743 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
744 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
745 ret = pthread_join(s_call_list_loop_tid,NULL);
746 LYINFLOG("pthread join w_c_list ret = %d",ret);
747 s_call_list_loop_tid=-1;
748#if 0
749 pthread_mutex_destroy(s_notice_get_call_list_mutex);
750 pthread_cond_destroy(s_notice_get_call_list_cond);
751 delete s_notice_get_call_list_mutex;
752 //s_notice_get_call_list_mutex = NULL;
753 delete s_notice_get_call_list_cond;
754 //s_notice_get_call_list_cond = NULL;
755#endif
756
757 return 0;
758}
759
760int lynq_init_call(int utoken){
761
762 LYLOGSET(LOG_INFO);
763 LYLOGEINIT(USER_LOG_TAG);
764 LYERRLOG("%s start, parameter is %d", __func__,utoken);
765
766 if(g_module_init_flag != MODULE_CLOSED)
767 {
768 LYERRLOG("module state is %d",g_module_init_flag);
769 return LYNQ_E_CONFLICT;
770 }
771 if(utoken <0){
772 LYERRLOG("utoken is less than 0",utoken);
773 return LYNQ_E_PARAMETER_ANONALY;
774 }
775 g_module_init_flag = MODULE_SWITCHING;
776
777
778 g_module_Global_uToken = utoken;
779
780 int ret = lynq_start_all_urc_socket_thread();
781 if(ret != RESULT_OK)
782 {
783 LYERRLOG("init socket urc fail!!!");
784 g_module_init_flag = MODULE_CLOSED;
785 return LYNQ_E_INNER_ERROR;
786 }
787
788 ret = lynq_start_all_rc_socket_thread();
789 if(ret !=RESULT_OK)
790 {
791 LYERRLOG("init socket client fail!!!");
792 lynq_close_all_urc_socket_thread();
793 g_module_init_flag = MODULE_CLOSED;
794 return LYNQ_E_INNER_ERROR;
795 }
796
797
798 int result = lynq_start_call_list_loop();
799 if(ret != RESULT_OK)
800 {
801 LYERRLOG("lynq_start_call_list_loop fail!!!");
802 lynq_close_all_urc_socket_thread();
803 lynq_close_all_rc_socket_thread();
804 g_module_init_flag = MODULE_CLOSED;
805 return LYNQ_E_INNER_ERROR;
806 }
807
808 g_module_init_flag = MODULE_RUNNING;
809
810 LYERRLOG("%s end suc", __func__);
811 return 0;
812}
813
814int lynq_deinit_call(void){
815 LYERRLOG("%s start", __func__);
816
817 if (g_module_init_flag != MODULE_RUNNING)
818 {
819 LYERRLOG("module state is %d",g_module_init_flag);
820 return LYNQ_E_CONFLICT;
821 }
822 lynq_call_hungup_all();
823 g_module_init_flag = MODULE_SWITCHING;
824 lynq_close_all_urc_socket_thread();
825 lynq_close_all_rc_socket_thread();
826 lynq_stop_call_list_loop();
827 g_module_init_flag = MODULE_CLOSED;
828
829 LYERRLOG("%s end suc", __func__);
830 return 0;
831}
832
833#if 0
834int lynq_set_common_request(int request_id, int argc, const char* format,...)
835{
836 Parcel p;
837 lynq_client_t client;
838 int resp_type = -1;
839 int token;
840 int request = -1;
841 int slot_id = -1;
842 int error = -1;
843
844 Parcel* p=NULL;
845 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
846 if(ret==RESULT_OK)
847 {
848 delete p;
849 }
850 return ret;
851
852 client.uToken = Global_uToken_call;
853 client.request = request_id;
854 client.paramLen = argc;
855 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
856 if(argc!=0)
857 {
858 va_list args;
859 va_start(args, format);
860 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
861 va_end(args);
862 }
863 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
864 if(send_request(lynq_call_client_sockfd,&client)==-1)
865 {
866 LYERRLOG("send request fail");
867 return -1;
868 }
869 if(get_response(lynq_call_client_sockfd,p)==0)
870 {
871 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
872 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
873 }
874 return error;
875
876
877}
878#endif
879
880int lynq_get_common_request(int request_id, int* status)
881{
882 if(status==NULL)
883 {
884 LYERRLOG("status is null");
885 return LYNQ_E_PARAMETER_ANONALY;
886 }
887
888 Parcel* p=NULL;
889 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
890 if(ret==RESULT_OK)
891 {
892 p->readInt32(status);
893 delete p;
894 }
895 return ret;
896}
897
898int waitCallstateChange(int mtime)
899{
900 LYINFLOG("wait Call state Change");
901 int ret = 0;
902 int sec = 0;
903 int ms = 0;
904 struct timeval now;
905 struct timespec timeout;
906 gettimeofday(&now,NULL);
907 sec = mtime/1000;
908 ms = mtime%1000;
909 timeout.tv_sec = now.tv_sec+sec;
910 unsigned long long ns;
911 ns = now.tv_usec*1000ull + ms*1000000ull;
912 timeout.tv_sec += ns/1000000000;
913 timeout.tv_nsec = ns % 1000000000;
914 pthread_mutex_lock(&call_state_change_mutex);
915 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
916 pthread_mutex_unlock(&call_state_change_mutex);
917 return ret;
918}
919
920int IsNormalCallDailing()
921{
922 return s_module_isDial;
923}
924
925
926int check_file_access(const char *fileName)
927{
928 if(0 == access(fileName,F_OK))
929 {
930 LYINFLOG("find file %s success",fileName);
931 return 0;
932 }
933 LYERRLOG("find file %s fail",fileName);
934 return 1;
935}
936int try_reset_audio_service()
937{
938 //check files:audio-ctrl-service,libmodem-afe-service,speech_daemon
939 int ap_speech = 0;
940 int audio_ctrl_ser = 0;
941 int md_afe = 0;
942 int tele_demo_lock = 0;
943 LYINFLOG("try_reset_audio_service start");
944 ap_speech = check_file_access(AP_SPEECH);
945 audio_ctrl_ser = check_file_access(AUDIO_CTRL_SER);
946 md_afe = check_file_access(LIBMODEM_AFE);
947 tele_demo_lock = check_file_access(TELE_DEMO_LOCK);
948 if((ap_speech + audio_ctrl_ser + md_afe) > 0)
949 {
950 system("systemctl stop audio-ctrl-service");
951 system("systemctl stop speech_daemon");
952 system("systemctl stop libmodem_afe_service");
953 usleep(200000);//200ms
954 system("rm /tmp/audio_ctrl_service -rf");
955 system("rm /tmp/ap_speech -rf");
956 system("rm /tmp/libmodem-afe-ctrl -rf");
957 usleep(100000);//100ms
958 system("systemctl start libmodem_afe_service");
959 usleep(200000);//200ms
960 system("systemctl start speech_daemon");
961 usleep(200000);//200ms
962 system("systemctl start audio-ctrl-service");
963 sleep(1);//1s
964 LYERRLOG("reset audio relation service");
965 }
966 if(tele_demo_lock)
967 {
968 LYERRLOG("%s lose,why?",TELE_DEMO_LOCK);
969 }
970 return 0;
971}
972
973int lynq_call(int* handle,char addr[])
974{
975 if(g_module_init_flag != MODULE_RUNNING)
976 {
977 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
978 return LYNQ_E_CONFLICT;
979 }
980 try_reset_audio_service();
981 int lynq_call_id = -1;
982
983 LYINFLOG("lynq_call begin addr %s",addr);
984 if(addr==NULL)
985 {
986 LYERRLOG("Phone num is null!!!");
987 return LYNQ_E_PARAMETER_ANONALY;
988 }
989
990 if(find_call_id_with_addr(addr)!=INVALID_ID)
991 {
992 LYERRLOG("addr %s exists",addr);
993 return LYNQ_E_CONFLICT;
994 }
995
996#ifdef ECALL_SUPPORT
997 if(lynq_ecall_is_running())
998 {
999 LYERRLOG("lynq_fast_ecall ecall is running");
1000 return LYNQ_E_ECALL_BEING_RUNNING;
1001 }
1002#endif
1003 Parcel* p=NULL;
1004 lynq_call_id = addAddr(addr,0);
1005 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
1006 if(ret!=0)
1007 {
1008 cleanCallList(lynq_call_id);
1009 return ret;
1010 }
1011 delete p;
1012 s_module_isDial = 1;
1013 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
1014 {
1015 //if timeout,this call need destroy.
1016 s_module_isDial = 0;
1017 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
1018 cleanCallList(lynq_call_id);
1019 send_call_state_change(lynq_call_id);
1020 return LYNQ_E_TIME_OUT;
1021 }
1022 s_module_isDial = 0;
1023 *handle = s_call_lists[lynq_call_id].call_id;
1024 if(*handle > 0)
1025 {
1026 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
1027 return RESULT_OK;
1028 }
1029 else
1030 {
1031 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
1032 cleanCallList(lynq_call_id);
1033 send_call_state_change(lynq_call_id);
1034 return LYNQ_E_INVALID_ID_ANONALY;
1035 }
1036}
1037
1038int lynq_call_answer()
1039{
1040 if(g_module_init_flag != MODULE_RUNNING)
1041 {
1042 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1043 return LYNQ_E_CONFLICT;
1044 }
1045
1046 Parcel* p=NULL;
1047 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
1048 if(ret==RESULT_OK)
1049 {
1050 delete p;
1051 }
1052 return ret;
1053}
1054
1055int lynq_call_hungup(int* handle)
1056{
1057 if(g_module_init_flag != MODULE_RUNNING)
1058 {
1059 return LYNQ_E_CONFLICT;
1060 }
1061
1062 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1063 {
1064 LYERRLOG("%s illegal input!!!!",__func__);
1065 return LYNQ_E_PARAMETER_ANONALY;
1066 }
1067
1068 int call_id = *handle;
1069 Parcel* p=NULL;
1070 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1071 if(ret!=0)
1072 {
1073 return ret;
1074 }
1075 delete p;
1076
1077 int lynq_call_id=find_call_id_with_call_id(call_id);
1078 if(lynq_call_id!=INVALID_ID)
1079 {
1080 //lei modify for API-857
1081 cleanCallList(lynq_call_id);
1082 send_call_state_change(call_id);
1083 }
1084 return RESULT_OK;
1085}
1086int lynq_call_hungup_all()
1087{
1088 if(g_module_init_flag != MODULE_RUNNING)
1089 {
1090 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1091 return LYNQ_E_CONFLICT;
1092 }
1093
1094 Parcel* p=NULL;
1095 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1096 if(ret==RESULT_OK)
1097 {
1098 delete p;
1099 }
1100 return ret;
1101}
1102
1103int lynq_wait_call_state_change(int *handle)
1104{
1105 if(g_module_init_flag != MODULE_RUNNING)
1106 {
1107 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1108 return LYNQ_E_CONFLICT;
1109 }
1110 wait_call_state();
1111 *handle = s_CallId;
1112 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1113 return RESULT_OK;
1114}
1115
1116int lynq_set_auto_answercall(const int mode)
1117{
1118 if(g_module_init_flag != MODULE_RUNNING)
1119 {
1120 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1121 return LYNQ_E_CONFLICT;
1122 }
1123 s_call_auto_answer = mode;
1124 LYINFLOG("auto answer call mode =%d",mode);
1125 return RESULT_OK;
1126}
1127
1128int lynq_find_already_end()
1129{
1130 for(int i=0;i < LYNQ_CALL_MAX; i++)
1131 {
1132 if(s_call_lists[i].call_state == 6)
1133 {
1134 return 0;
1135 }
1136 }
1137 return INVALID_ID;
1138}
1139
1140int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1141{
1142 if(g_module_init_flag != MODULE_RUNNING)
1143 {
1144 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1145 return LYNQ_E_CONFLICT;
1146 }
1147 int lynq_call_id = 0;
1148 LYINFLOG("lynq_get_current_call_state begin ");
1149 if(handle==NULL)
1150 {
1151 LYERRLOG("handle is NULL");
1152 return LYNQ_E_PARAMETER_ANONALY;
1153 }
1154 if((*handle) <= 0)
1155 {
1156 LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);
1157 return LYNQ_E_INVALID_ID_ANONALY;
1158 }
1159 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
1160 lynq_call_id = find_call_id_with_call_id(*handle);
1161 if(lynq_call_id==INVALID_ID)
1162 {
1163 //find end state
1164 if((*handle) >= 0)
1165 {
1166 *call_state = (int)LYNQ_CALL_END;
1167 return RESULT_OK;
1168 }
1169 else
1170 {
1171 return LYNQ_E_INVALID_ID_ANONALY;
1172 }
1173 }
1174 *call_state = s_call_lists[lynq_call_id].call_state;
1175 *toa = s_call_lists[lynq_call_id].toa;
1176 *direction = s_call_lists[lynq_call_id].direction;
1177 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
1178 return RESULT_OK;
1179}
1180
1181int lynq_get_current_call_number()
1182{
1183 int cnt=0;
1184 int i;
1185 for(i = 0;i < LYNQ_CALL_MAX;i++)
1186 {
1187 if(s_call_lists[i].used !=0)
1188 {
1189 cnt++;
1190 }
1191 }
1192
1193 return cnt;
1194}
1195
1196/*audio begin*/
1197static int judge_mic(const int enable){
1198 switch(enable){
1199 case 0:
1200 return true;
1201 case 1:
1202 return true;
1203 default:
1204 return false;
1205 }
1206}
1207
1208int lynq_set_mute_mic(const int enable)
1209{
1210 if(g_module_init_flag != MODULE_RUNNING)
1211 {
1212 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1213 return LYNQ_E_CONFLICT;
1214 }
1215 if(!judge_mic(enable)){
1216 return LYNQ_E_PARAMETER_ANONALY;
1217 }
1218 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1219
1220 Parcel* p=NULL;
1221 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1222 if(ret==RESULT_OK)
1223 {
1224 delete p;
1225 }
1226 return ret;
1227}
1228int lynq_get_mute_mic(int *status)
1229{
1230 if(g_module_init_flag != MODULE_RUNNING)
1231 {
1232 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1233 return LYNQ_E_CONFLICT;
1234 }
1235 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
1236}
1237
1238/**
1239 * @brief Check whether DTMF is valid
1240 *
1241 * @param callnum dtmf eg:0-9 * #
1242 * @return int
1243 */
1244static int judge_dtmf(const char callnum)
1245{
1246 if(callnum == '#')
1247 {
1248 return true;
1249 }
1250 if(callnum == '*')
1251 {
1252 return true;
1253 }
1254 if(callnum >= '0'&& callnum <= '9')
1255 {
1256 return true;
1257 }
1258 return false;
1259}
1260
1261int lynq_switch_waiting_or_holding_and_active(void)
1262{
1263 if(g_module_init_flag != MODULE_RUNNING)
1264 {
1265 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1266 return LYNQ_E_CONFLICT;
1267 }
1268
1269 Parcel* p=NULL;
1270 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1271 if(ret==RESULT_OK)
1272 {
1273 delete p;
1274 }
1275 return ret;
1276
1277#if 0
1278 Parcel p;
1279 lynq_client_t client;
1280 int resp_type = -1;
1281 int token;
1282 int request = -1;
1283 int slot_id = -1;
1284 int error = -1;
1285 client.uToken = Global_uToken_call;
1286 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1287 client.paramLen = 0;
1288 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1289 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1290 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
1291 if(send_request(lynq_call_client_sockfd,&client)==-1)
1292 {
1293 LYERRLOG("send request fail");
1294 return -1;
1295 }
1296 get_response(lynq_call_client_sockfd,p);
1297 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
1298 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
1299 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1300 return error;
1301#endif
1302}
1303
1304int lynq_hangup_waiting_or_background(void)
1305{
1306 if(g_module_init_flag != MODULE_RUNNING)
1307 {
1308 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1309 return LYNQ_E_CONFLICT;
1310 }
1311
1312 Parcel* p=NULL;
1313 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1314 if(ret==RESULT_OK)
1315 {
1316 delete p;
1317 }
1318 return ret;
1319#if 0
1320 Parcel p;
1321 lynq_client_t client;
1322 int resp_type = -1;
1323 int token;
1324 int request = -1;
1325 int slot_id = -1;
1326 int error = -1;
1327 client.uToken = Global_uToken_call;
1328 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1329 client.paramLen = 0;
1330 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1331 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1332 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
1333 if(send_request(lynq_call_client_sockfd,&client)==-1)
1334 {
1335 LYERRLOG("send request fail");
1336 return -1;
1337 }
1338 get_response(lynq_call_client_sockfd,p);
1339 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
1340 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
1341 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1342 return error;
1343#endif
1344}
1345
1346int lynq_hangup_foreground_resume_background(void)
1347{
1348 if(g_module_init_flag != MODULE_RUNNING)
1349 {
1350 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1351 return LYNQ_E_CONFLICT;
1352 }
1353
1354 Parcel* p=NULL;
1355 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1356 if(ret==RESULT_OK)
1357 {
1358 delete p;
1359 }
1360 return ret;
1361#if 0
1362 Parcel p;
1363 lynq_client_t client;
1364 int resp_type = -1;
1365 int token;
1366 int request = -1;
1367 int slot_id = -1;
1368 int error = -1;
1369 client.uToken = Global_uToken_call;
1370 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1371 client.paramLen = 0;
1372 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1373 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1374 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
1375 if(send_request(lynq_call_client_sockfd,&client)==-1)
1376 {
1377 LYERRLOG("send request fail");
1378 return -1;
1379 }
1380 get_response(lynq_call_client_sockfd,p);
1381 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
1382 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
1383 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1384 return error;
1385#endif
1386}
1387
1388int lynq_set_DTMF(const char callnum)
1389{
1390 if(g_module_init_flag != MODULE_RUNNING)
1391 {
1392 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1393 return LYNQ_E_CONFLICT;
1394 }
1395 if(!judge_dtmf(callnum))
1396 {
1397 return LYNQ_E_CONFLICT;
1398 }
1399 if(s_module_call_state!=CALL_ON)
1400 {
1401 LYERRLOG("LYNQ_E_CONFLICT");
1402 return LYNQ_E_CONFLICT;
1403 }
1404
1405// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1406
1407 Parcel* p=NULL;
1408 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1409 if(ret==RESULT_OK)
1410 {
1411 delete p;
1412 }
1413 return ret;
1414}
1415static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1416 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1417 if(volume < 0 ||volume >36){
1418 return 0;
1419 }
1420 }
1421 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1422 {
1423 if(volume < 1 ||volume >7){
1424 return 0;
1425 }
1426 }
1427 return 1;
1428}
1429int lynq_set_DTMF_volume(const int volume)
1430{
1431 if(g_module_init_flag != MODULE_RUNNING)
1432 {
1433 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1434 return LYNQ_E_CONFLICT;
1435 }
1436 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1437 return LYNQ_E_PARAMETER_ANONALY;
1438 }
1439// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1440 Parcel* p=NULL;
1441 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1442 if(ret==RESULT_OK)
1443 {
1444 delete p;
1445 }
1446 return ret;
1447}
1448int lynq_set_speech_volume(const int volume)//mixer_set_volume
1449{
1450 if(g_module_init_flag != MODULE_RUNNING)
1451 {
1452 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1453 return LYNQ_E_CONFLICT;
1454 }
1455 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1456 {
1457 return LYNQ_E_PARAMETER_ANONALY;
1458 }
1459// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1460 Parcel* p=NULL;
1461 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1462 if(ret==RESULT_OK)
1463 {
1464 delete p;
1465 }
1466 return ret;
1467}
1468int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1469{
1470 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
1471}
1472int lynq_incall_record_start(const char* file_path)
1473{
1474// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1475 Parcel* p=NULL;
1476 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1477 if(ret==RESULT_OK)
1478 {
1479 delete p;
1480 }
1481 return ret;
1482}
1483int lynq_incall_record_stop()
1484{
1485 if(g_module_init_flag != MODULE_RUNNING)
1486 {
1487 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1488 return LYNQ_E_CONFLICT;
1489 }
1490 const char* unused_file="just_ocuupy_paramter_postion";
1491// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1492 Parcel* p=NULL;
1493 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1494 if(ret==RESULT_OK)
1495 {
1496 delete p;
1497 }
1498 return ret;
1499}
1500/*audio end*/
1501
1502
1503
1504bool is_support_urc(int urc_id)
1505{
1506 switch(urc_id)
1507 {
1508 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1509 case RIL_UNSOL_CALL_RING:
1510 case RIL_UNSOL_RINGBACK_TONE:
1511 case RIL_UNSOL_CALL_INFO_INDICATION:
1512#ifdef ECALL_SUPPORT
1513 case RIL_UNSOL_ECALL_INDICATIONS://9502
1514#endif
1515 return true;
1516 default:
1517 return false;
1518 }
1519}
1520
1521void urc_msg_process(Parcel *p)
1522{
1523 int resp_type;
1524 int urcid;
1525 int slot_id;
1526
1527 int size=p->dataSize();
1528 p->readInt32(&resp_type);
1529 p->readInt32(&urcid);
1530 p->readInt32(&slot_id);
1531 LYINFLOG("%s urc id = %d, slot_id = %d, size is %d, msg is %s",__func__, urcid,slot_id,size,requestToString(urcid));
1532 switch (urcid)
1533 {
1534 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1535 {
1536 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1537 lynqNoticeGetModuleCallList();
1538 break;
1539 }
1540 case RIL_UNSOL_CALL_RING: //1018
1541 {
1542 if(s_call_auto_answer==1)
1543 {
1544 lynq_call_answer();
1545 }
1546 break;
1547 }
1548 case RIL_UNSOL_RINGBACK_TONE: //1029
1549 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1550 {
1551 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1552 break;
1553 }
1554#ifdef ECALL_SUPPORT
1555 case RIL_UNSOL_ECALL_INDICATIONS://9502
1556 {
1557 urc_ecall_msg_process(p);
1558 }
1559#endif
1560 default:
1561 break;
1562 }
1563}
1564
1565#if 0
1566int main(int argc,char **argv)
1567{
1568 int n = 0;
1569 n = lynq_init_call(lynq_call_state_change_test,2222);
1570 if(n<0)
1571 {
1572 LYDBGLOG("lynq init call fail!!!");
1573 return -1;
1574 }
1575 LYDBGLOG("lynq call init success!!!");
1576 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1577 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1578 lynq_call(phoneNum);
1579 while(1)
1580 {
1581 sleep(1);
1582 }
1583 return 0;
1584}
1585#endif
1586/*Warren add for T800 platform 2021/11/19 end*/