blob: 48266b85249d67889ddc121d318637dc8626ad8d [file] [log] [blame]
lh25827952022-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>
lh25827952022-01-10 00:34:35 -080011#include <cutils/jstring.h>
12#include <pthread.h>
13#include "liblog/lynq_deflog.h"
lh228a7b82022-01-10 02:24:31 -080014#include <sys/time.h>
lh59e0d002022-01-27 00:27:12 -080015#include <string.h>
q.huangfe1b4052022-04-18 00:09:50 -040016#include <vendor-ril/telephony/ril.h>
17#include <vendor-ril/telephony/mtk_ril_sp.h>
18#include <vendor-ril/telephony/mtk_ril_ivt.h>
19#include "lynq_call.h"
20
21
lh25827952022-01-10 00:34:35 -080022#define LYNQ_SERVICE_PORT 8088
rjw8bdc56b2022-02-28 15:01:49 +080023#define DSET_IP_ADDRESS "127.0.0.1"
lh25827952022-01-10 00:34:35 -080024#define LYNQ_URC_SERVICE_PORT 8086
25#define LYNQ_REC_BUF 8192
26#define LYNQ_REQUEST_PARAM_BUF 8192
27#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
28#define USER_LOG_TAG "LYNQ_CALL"
29
30using ::android::Parcel;
31 typedef enum {
32 LYNQ_CALL_ACTIVE = 0,
33 LYNQ_CALL_HOLDING = 1,
34 LYNQ_CALL_DIALING = 2, /* MO call only */
35 LYNQ_CALL_ALERTING = 3, /* MO call only */
36 LYNQ_CALL_INCOMING = 4, /* MT call only */
lh8657e742022-04-26 00:45:44 -070037 LYNQ_CALL_WAITING = 5, /* MT call only */
38 /*warren add for T800 platform 2022/04/26 start*/
39 LYNQ_CALL_END = 6, /*CALL END*/
40 /*warren add for T800 platform 2022/04/26 end*/
lh25827952022-01-10 00:34:35 -080041}lynq_call_state_t;
42
43typedef struct{
44 int uToken;
45 int request;
46 int paramLen;
47 char param[LYNQ_REQUEST_PARAM_BUF];
48}lynq_client_t;
49typedef struct
50{
51 int used;
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 int hasTimeout;
58}lynq_call_list_e_t;
59typedef struct
60{
61 int call_id;
62 int call_state;
63 int toa;
64 int direction;/*0: MO call,1:MT call*/
65 char addr[LYNQ_PHONE_NUMBER_MAX];
66}lynq_call_list_t;
67
68lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
69static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
70static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
ll375c94d2022-01-27 05:54:38 +000071static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
lh25827952022-01-10 00:34:35 -080072static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
73static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
74static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
ll1343a5b2022-03-17 05:31:33 +000075pthread_t lynq_call_urc_tid = -1;
76pthread_t lynq_call_list_loop_tid = -1;
lhcdf816a2022-02-13 23:56:05 -080077
rjw8bdc56b2022-02-28 15:01:49 +080078/*lei add*/
79/* socket文件描述符 */
80int len_addr_serv;
81struct sockaddr_in addr_serv;
82lynq_client_t client_t;
83int client_size = 0;
84/*lei add*/
lh25827952022-01-10 00:34:35 -080085
lha35d4ee2022-01-25 18:47:39 -080086int s_call_urc_event_complete = 1;
lh25827952022-01-10 00:34:35 -080087
88enum{
89 CALL_OFF=0,
90 CALL_ON=1
91}call_state;
ll375c94d2022-01-27 05:54:38 +000092typedef enum{
93 LYNQ_E_CARDSTATE_ERROR=8000,
94 /* The voice service state is out of service*/
95 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
96 /* The voice service state is EMERGENCY_ONLY*/
97 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
98 /* The radio power is power off*/
99 LYNQ_E_STATE_POWER_OFF=8003,
100 LYNQ_E_TIME_OUT=8004,
101 /*create or open sms DB fail */
102 LYNQ_E_SMS_DB_FAIL=8005,
103 /*Failed to execute sql statement*/
104 LYNQ_E_SMS_SQL_FAIL = 8006,
105 LYNQ_E_SMS_NOT_FIND = 8007,
106 /* The logic conflict*/
107 LYNQ_E_CONFLICT=9000,
108 /*Null anomaly*/
109 LYNQ_E_NULL_ANONALY=9001
lh25827952022-01-10 00:34:35 -0800110}LYNQ_E;
q.huangb0eb7b02022-03-29 04:17:32 -0400111typedef enum{
112 LYNQ_E_VOLUMN_SET_DTMF,
113 LYNQ_E_VOLUMN_SET_SPEECH
114}LYNQ_E_VOLUMN_SET;
lh25827952022-01-10 00:34:35 -0800115
116int lynq_call_state =CALL_OFF;
lha35d4ee2022-01-25 18:47:39 -0800117int lynq_call_client_sockfd = 0;
118int Global_uToken_call = 0;
lh25827952022-01-10 00:34:35 -0800119int global_call_count =0;
120int global_call_auto_answer = 0;
lha35d4ee2022-01-25 18:47:39 -0800121bool urc_call_recive_status = 1;
lh25827952022-01-10 00:34:35 -0800122bool call_list_loop = 1;
123int isDial = 0;
124int lynqIncomingCallId = 0;
q.huang18d08bf2022-04-19 20:27:44 -0400125
126#ifdef ECALL_SUPPORT
127typedef enum{
128 LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
129 LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
q.huangfe1b4052022-04-18 00:09:50 -0400130 LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
131 LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */\
132}LYNQ_ECall_Type;
133
q.huang18d08bf2022-04-19 20:27:44 -0400134char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"","null","112"};
135
136
137
138static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
139static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
140
141LYNQ_ECall_Indication lynqIncomingEcallIndication;
142int lynqEcallId;
143
144void sendSignalIncomingECallEvent()
145{
146 pthread_mutex_lock(&s_incoming_e_call_mutex);
147 pthread_cond_signal(&s_incoming_e_call_cond);
148 pthread_mutex_unlock(&s_incoming_e_call_mutex);
149}
150#endif
q.huangfe1b4052022-04-18 00:09:50 -0400151
ll1343a5b2022-03-17 05:31:33 +0000152/**
153 * @brief mark call initialization state
154 * 0: deinit state
155 * 1: init state
156 */
157int g_lynq_call_init_flag = 0;
lh25827952022-01-10 00:34:35 -0800158
159int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
160{
161 if(p.dataAvail() > 0)
162 {
163 p.readInt32(resp_type);
164 p.readInt32(request);
165 p.readInt32(slot_id);
166 p.readInt32(error);
167 return 0;
168 }
169 else
170 {
171 return -1;
172 }
173}
174int send_request(int sockfd,lynq_client_t *client_tmp)
175{
176 int ret=0;
rjw8bdc56b2022-02-28 15:01:49 +0800177 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh25827952022-01-10 00:34:35 -0800178 if(ret==-1)
179 {
llc10c9572022-03-01 09:18:53 +0000180 LYERRLOG("sendto error\n");
lh25827952022-01-10 00:34:35 -0800181 return -1;
182 }
183 return 0;
184}
185
186int get_response(int sockfd,Parcel &p)
187{
188 int len = 0;
189 char recvline[LYNQ_REC_BUF];
190 bzero(recvline,LYNQ_REC_BUF);
191 /* receive data from server */
rjw8bdc56b2022-02-28 15:01:49 +0800192 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh25827952022-01-10 00:34:35 -0800193 if(len == -1)
194 {
llc10c9572022-03-01 09:18:53 +0000195 LYERRLOG("recvfrom error\n");
lh25827952022-01-10 00:34:35 -0800196 return -1;
197 }
lh25827952022-01-10 00:34:35 -0800198 if (recvline != NULL) {
199 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
200 p.setDataPosition(0);
201 }
202 return 0;
203}
204static char *strdupReadString(Parcel &p) {
ll375c94d2022-01-27 05:54:38 +0000205 size_t stringlen;
lh25827952022-01-10 00:34:35 -0800206 const char16_t *s16;
207 s16 = p.readString16Inplace(&stringlen);
ll375c94d2022-01-27 05:54:38 +0000208 return strndup16to8(s16, stringlen);
lh25827952022-01-10 00:34:35 -0800209}
210
211int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
212{
213 Parcel p;
214 lynq_client_t client;
215 int resp_type = -1;
216 int request = -1;
217 int slot_id = -1;
218 int error = -1;
219 int call_num = 0;
220 int temp = 0;
221 char *remote_phoneNum = NULL;
222 char *remote_name= NULL;
223 char *uusData = NULL;
lha35d4ee2022-01-25 18:47:39 -0800224 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -0800225 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
226 client.paramLen = 0;
227 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
228 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800229 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800230 {
231 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800232 return -1;
233 }
lha35d4ee2022-01-25 18:47:39 -0800234 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -0800235 JumpHeader(p,&resp_type,&request,&slot_id,&error);
236 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
237 if(error == 0)
238 {
239 p.readInt32(&call_num);
240 global_call_count = call_num;
241 if(call_num<=0)
242 {
243 lynq_call_state = CALL_OFF;
lhcdf816a2022-02-13 23:56:05 -0800244 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh25827952022-01-10 00:34:35 -0800245 return 0;
246 }
lhcdf816a2022-02-13 23:56:05 -0800247 lynq_call_state = CALL_ON;
248 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh25827952022-01-10 00:34:35 -0800249 for(int i = 0;i < call_num;i++)
250 {
251 p.readInt32(&temp);
252 call_list[i].call_state = temp;
253 p.readInt32(&call_list[i].call_id);
254 p.readInt32(&call_list[i].toa);
255 p.readInt32(&temp);
256 p.readInt32(&temp);
257 call_list[i].direction = temp;
258 p.readInt32(&temp);
259 p.readInt32(&temp);
260 p.readInt32(&temp);
261 remote_phoneNum = strdupReadString(p);
262 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
263 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
264 call_list[i].direction,call_list[i].addr,call_list[i].toa);
265 p.readInt32(&temp);
266 remote_name = strdupReadString(p);
267 p.readInt32(&temp);
268 p.readInt32(&temp);
269 if(temp==0)
270 {
271 continue;
272 }
273 p.readInt32(&temp); /* UUS Information is present */
274 p.readInt32(&temp);
275 p.readInt32(&temp);
276 p.read(uusData,temp);
277 }
278 }
279 return 0;
280}
281
282void cleanCallList(int lynq_call_id)
283{
284 lynq_call_lists[lynq_call_id].call_id = 0;
lh8657e742022-04-26 00:45:44 -0700285 lynq_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
lh25827952022-01-10 00:34:35 -0800286 lynq_call_lists[lynq_call_id].toa = 0;
287 lynq_call_lists[lynq_call_id].direction = 0;
288 lynq_call_lists[lynq_call_id].used = 0;
289 lynq_call_lists[lynq_call_id].hasTimeout = 0;
290 memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
291}
292int getUnusedElement()
293{
294 for(int i=0;i < LYNQ_CALL_MAX; i++)
295 {
296 if(lynq_call_lists[i].used!=1)
297 {
298 return i;
299 }
300 }
301 return -1;
302}
303int updateAddr(char addr[])
304{
305 int ret = 0;
306 ret = getUnusedElement();
307 memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
308 lynq_call_lists[ret].used = 1;
309 return ret;
310}
311void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
312{
lhbe92dd12022-04-19 06:01:25 -0700313 LYINFLOG("Update Call List");
lh25827952022-01-10 00:34:35 -0800314 callList->call_id = call_id;
315 callList->call_state = call_state;
316 callList->toa = toa;
317 callList->direction = direction;
318 callList->used = 1;
319 callList->hasTimeout = 0;
320 return;
321}
322int waitCallstateChange(int mtime)
323{
lhbe92dd12022-04-19 06:01:25 -0700324 LYINFLOG("wait Call state Change");
lh25827952022-01-10 00:34:35 -0800325 int ret = 0;
326 int sec = 0;
327 int usec = 0;
lh228a7b82022-01-10 02:24:31 -0800328 struct timeval now;
329 struct timespec timeout;
330 gettimeofday(&now,NULL);
lh25827952022-01-10 00:34:35 -0800331 sec = mtime/1000;
332 usec = mtime%1000;
lh228a7b82022-01-10 02:24:31 -0800333 timeout.tv_sec = now.tv_sec+sec;
334 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh25827952022-01-10 00:34:35 -0800335 pthread_mutex_lock(&call_state_change_mutex);
lh228a7b82022-01-10 02:24:31 -0800336 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh25827952022-01-10 00:34:35 -0800337 pthread_mutex_unlock(&call_state_change_mutex);
338 return ret;
339}
340int waitIncomingCall()
341{
lhbe92dd12022-04-19 06:01:25 -0700342 LYINFLOG("wait incming call");
lh25827952022-01-10 00:34:35 -0800343 int ret = 0;
344 pthread_mutex_lock(&s_incoming_call_mutex);
345 ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
346 pthread_mutex_unlock(&s_incoming_call_mutex);
347 return ret;
348}
349int checkHasCall(char addr[])
350{
lhbe92dd12022-04-19 06:01:25 -0700351 LYINFLOG("check has call");
lh25827952022-01-10 00:34:35 -0800352 for(int i = 0;i<LYNQ_CALL_MAX;i++)
353 {
354 if(strcmp(lynq_call_lists[i].addr,addr)==0)
355 {
356 return 1;
357 }
358 }
359 return 0;
360}
lhbe92dd12022-04-19 06:01:25 -0700361int find_call_id_with_addr(char *addr)
362{
363 LYINFLOG("find call id with addr!!!");
364 for(int id = 0; id < LYNQ_CALL_MAX; id++)
365 {
366 if(strcmp(lynq_call_lists[id].addr,addr) == 0)
367 {
368 return id;
369 }
370 }
371 return -1;
372}
lh25827952022-01-10 00:34:35 -0800373void sendSignalToWaitCallStateChange()
374{
lhbe92dd12022-04-19 06:01:25 -0700375 LYINFLOG("send Signal To Wait Call State Change");
lh25827952022-01-10 00:34:35 -0800376 pthread_mutex_lock(&call_state_change_mutex);
377 pthread_cond_signal(&call_state_change_cond);
378 pthread_mutex_unlock(&call_state_change_mutex);
379}
380void sendSignalIncomingCall()
381{
lhbe92dd12022-04-19 06:01:25 -0700382 LYINFLOG("send incoming call signal");
lh25827952022-01-10 00:34:35 -0800383 pthread_mutex_lock(&s_incoming_call_mutex);
384 pthread_cond_signal(&s_incoming_call_cond);
385 pthread_mutex_unlock(&s_incoming_call_mutex);
386}
387
388void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
389{
390 callList->call_id = call_id;
391 callList->call_state = call_state;
392 callList->toa = toa;
393 callList->direction = direction;
394 memcpy(callList->addr,addr,strlen(addr)+1);
395 callList->used = 1;
396 callList->hasTimeout = 0;
397 return;
398}
399
400void *triggerGetCallList(void *parg)
ll375c94d2022-01-27 05:54:38 +0000401{
402 int ret=0;
lhbe92dd12022-04-19 06:01:25 -0700403 bool call_end;
404 call_end = 0;//0:this call end,1:call on
ll375c94d2022-01-27 05:54:38 +0000405 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang18d08bf2022-04-19 20:27:44 -0400406 int update=0;
lh25827952022-01-10 00:34:35 -0800407 while(call_list_loop)
ll375c94d2022-01-27 05:54:38 +0000408 {
q.huang18d08bf2022-04-19 20:27:44 -0400409 update=0;
ll375c94d2022-01-27 05:54:38 +0000410 pthread_mutex_lock(&s_urc_call_state_change_mutex);
411 pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
lh25827952022-01-10 00:34:35 -0800412 LYDBGLOG("triggerGetCallList event!!!\n");
ll375c94d2022-01-27 05:54:38 +0000413 memset(call_list,0,sizeof(call_list));
414 ret = lynq_get_current_call_list(call_list);
415 if(ret != 0)
416 {
ll22101402022-04-11 05:49:51 +0000417 LYDBGLOG("get current call list failure!!!\n");
418 continue;
ll375c94d2022-01-27 05:54:38 +0000419 }
lhbe92dd12022-04-19 06:01:25 -0700420 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
lh25827952022-01-10 00:34:35 -0800421 for(int i = 0;i < LYNQ_CALL_MAX;i++)
422 {
lhbe92dd12022-04-19 06:01:25 -0700423 if(strlen(lynq_call_lists[i].addr) != 0)
424 {
425 call_end = 0;
426 for(int id = 0; id < LYNQ_CALL_MAX; id++)
427 {
428 if(strcmp(call_list[id].addr,lynq_call_lists[i].addr) == 0)
429 {
430 call_end = 1;
431 LYINFLOG("find lynq call i %d, id %d!!!",i,id);
432 }
433 }
434 if(call_end == 0)
435 {
436 LYINFLOG("MT hungup,then clean call info");
437 cleanCallList(i);
438 continue;
439 }
440 } //fix bug API-54
lh25827952022-01-10 00:34:35 -0800441 if(call_list[i].direction == 1)//MT call
442 {
lh4256e1b2022-05-13 03:02:19 -0700443 /*MT CALL state code
444 **LYNQ_CALL_INCOMING = 4,
445 **LYNQ_CALL_WAITING = 5,
446 */
447 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh25827952022-01-10 00:34:35 -0800448 {
ll45d3ea92022-03-24 10:22:25 +0800449 /*you call me, and i call you,One party failed to dial*/
lh25827952022-01-10 00:34:35 -0800450 if(!checkHasCall(call_list[i].addr))
451 {
452 lynqIncomingCallId = getUnusedElement();
453 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);
454 sendSignalIncomingCall();
455 }
lhbe92dd12022-04-19 06:01:25 -0700456 else
457 {
458 int temp_call_id = find_call_id_with_addr(call_list[i].addr);
459 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
460 **an incoming call until the status changes.
461 **fix bug API-54
462 */
463 if((temp_call_id > 0) && (lynq_call_lists[temp_call_id].call_state == call_list[i].call_state))
464 {
465 sendSignalIncomingCall();
466 }
467 }
lh25827952022-01-10 00:34:35 -0800468 }
ll45d3ea92022-03-24 10:22:25 +0800469 /*if state changed*/
470 else
471 {
472 /*update call state*/
473 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
474 {
475 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
476 {
477 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
ll4461e952022-04-07 09:09:55 +0000478 break;
ll45d3ea92022-03-24 10:22:25 +0800479 }
480 }
481 }
lh25827952022-01-10 00:34:35 -0800482 }
483 else
484 {
485 if(call_list[i].call_id==0)
486 {
487 break;
488 }
489 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
490 {
lhbe92dd12022-04-19 06:01:25 -0700491 if((lynq_call_lists[n].hasTimeout == 1) && (strcmp(lynq_call_lists[n].addr,call_list[i].addr) == 0))
lh25827952022-01-10 00:34:35 -0800492 {
lhbe92dd12022-04-19 06:01:25 -0700493 cleanCallList(n);//if this call time out,need clean lynq call list.
494 /*hangup call with call id*/
495 lynq_call_hungup(&call_list[i].call_id);
lh25827952022-01-10 00:34:35 -0800496 lynq_call_lists[n].hasTimeout==0;
497 continue;
498 }
q.huang18d08bf2022-04-19 20:27:44 -0400499 LYDBGLOG("lynq_call_lists n is %d, used is %d, addr is %s addr2 %s\n",
500 n,lynq_call_lists[n].used,call_list[i].addr,lynq_call_lists[n].addr);
501 if(lynq_call_lists[n].used && (strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0))
lh25827952022-01-10 00:34:35 -0800502 {
q.huang18d08bf2022-04-19 20:27:44 -0400503 LYINFLOG("updated\n");
lh25827952022-01-10 00:34:35 -0800504 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
q.huang18d08bf2022-04-19 20:27:44 -0400505 update=1;
506 break;
lh25827952022-01-10 00:34:35 -0800507 }
508 }
509 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,
510 call_list[i].direction,call_list[i].addr,call_list[i].toa);
511 }
ll375c94d2022-01-27 05:54:38 +0000512 }
lha35d4ee2022-01-25 18:47:39 -0800513 s_call_urc_event_complete = 1;
q.huang18d08bf2022-04-19 20:27:44 -0400514 if((isDial==1) && (update==1))
lh25827952022-01-10 00:34:35 -0800515 {
516 sendSignalToWaitCallStateChange();
517 isDial = 0;
518 }
ll375c94d2022-01-27 05:54:38 +0000519 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
520 }
521 return NULL;
lh25827952022-01-10 00:34:35 -0800522}
523
524void lynqRespWatingEvent()
ll375c94d2022-01-27 05:54:38 +0000525{
526 if(s_call_urc_event_complete==1)
527 {
528 pthread_mutex_lock(&s_urc_call_state_change_mutex);
529 pthread_cond_signal(&s_urc_call_state_change_cond);
530 s_call_urc_event_complete = 0;
531 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
lh25827952022-01-10 00:34:35 -0800532 }
ll375c94d2022-01-27 05:54:38 +0000533 return;
lh25827952022-01-10 00:34:35 -0800534}
535
536/*Warren add for T800 platform 2021/11/19 start*/
537int lynq_socket_client_start()
rjw8bdc56b2022-02-28 15:01:49 +0800538{
539 #if 0
lh25827952022-01-10 00:34:35 -0800540 struct sockaddr_in lynq_socket_server_addr;
541 /* init lynq_socket_server_addr */
542 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
543 lynq_socket_server_addr.sin_family = AF_INET;
544 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
545 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw8bdc56b2022-02-28 15:01:49 +0800546
lh25827952022-01-10 00:34:35 -0800547 /*
548 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
549 {
ll22101402022-04-11 05:49:51 +0000550 LYDBGLOG("[%s] is not a valid IPaddress\n", argv[1]);
lh25827952022-01-10 00:34:35 -0800551 exit(1);
552 }
553*/
lha35d4ee2022-01-25 18:47:39 -0800554 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
555 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh25827952022-01-10 00:34:35 -0800556 {
llc10c9572022-03-01 09:18:53 +0000557 LYERRLOG("connect error\n");
lh25827952022-01-10 00:34:35 -0800558 return -1;
559 }
rjw8bdc56b2022-02-28 15:01:49 +0800560 #endif
561 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
562 if (-1 == lynq_call_client_sockfd)
563 {
564 return lynq_call_client_sockfd;
565 }
566 /* 设置address */
567 memset(&addr_serv, 0, sizeof(addr_serv));
568 addr_serv.sin_family = AF_INET;
569 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
570 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
571 len_addr_serv = sizeof(addr_serv);
lh25827952022-01-10 00:34:35 -0800572 return 0;
573}
574int lynq_update_call_list_loop()
575{
576 int ret = 0;
lh25827952022-01-10 00:34:35 -0800577 pthread_attr_t attr;
578 pthread_attr_init(&attr);
579 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -0800580 ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
lh25827952022-01-10 00:34:35 -0800581 if(ret < 0)
582 {
583 LYERRLOG("lynq_update_call_list_loop fail!!!");
584 return -1;
585 }
586 LYDBGLOG("lynq_update_call_list_loop success!!!\n");
587 return 0;
588
589}
590void *thread_urc_recv(void *parg)
ll375c94d2022-01-27 05:54:38 +0000591{
lh25827952022-01-10 00:34:35 -0800592 int socket_fd = (int64_t)parg;
593 int len=0;
594 socklen_t addr_len=0;
595 uint8_t *dataLength = NULL;
596 char urc_data[LYNQ_REC_BUF];
597 int slot_id = -1;
598 int resp_type = -1;
599 int urcid = -1;
600 Parcel *p = NULL;
601 struct sockaddr_in dest_addr;
q.huang18d08bf2022-04-19 20:27:44 -0400602#ifdef ECALL_SUPPORT
603 int ecall_ind;
604#endif
605
lh25827952022-01-10 00:34:35 -0800606 LYINFLOG("thread_urc_recv in running....\n");
lha35d4ee2022-01-25 18:47:39 -0800607 while(urc_call_recive_status)
lh25827952022-01-10 00:34:35 -0800608 {
609 bzero(urc_data,LYNQ_REC_BUF);
610 //get data msg
611 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
612 if(len <= 0)
ll375c94d2022-01-27 05:54:38 +0000613 {
llc10c9572022-03-01 09:18:53 +0000614 LYERRLOG("thread_urc_recv step2 fail\n");
ll375c94d2022-01-27 05:54:38 +0000615 break;
lh25827952022-01-10 00:34:35 -0800616 }
617 LYDBGLOG("=====>urc data len<=====:%d\n",len);
618 p = new Parcel();
619 if(p==NULL)
620 {
lh59e0d002022-01-27 00:27:12 -0800621 LYERRLOG("new parcel failure!!!");
lh25827952022-01-10 00:34:35 -0800622 break;
623 }
624 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
625 p->setDataPosition(0);
626 if(p->dataAvail() > 0)
627 {
628 p->readInt32(&resp_type);
629 p->readInt32(&urcid);
630 p->readInt32(&slot_id);
631 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
632 switch (urcid)
633 {
634 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
635 {
636 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
637 lynqRespWatingEvent();
638 break;
639 }
640 case 1018://RIL_UNSOL_CALL_RING
641 {
642 if(global_call_auto_answer==1)
643 {
644 lynq_call_answer();
645 }
646 break;
647 }
648 case 1029://RIL_UNSOL_RINGBACK_TONE
649 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
650 {
651 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
652 break;
653 }
q.huang18d08bf2022-04-19 20:27:44 -0400654#ifdef ECALL_SUPPORT
655 case RIL_UNSOL_ECALL_INDICATIONS:
656 {
657 p->readInt32(&ecall_ind);
658 lynqIncomingEcallIndication=ecall_ind;
659 if(LYNQ_ECALL_ACTIVE==lynqIncomingEcallIndication)
660 {
661 if(isDial==1)
662 {
663 p->readInt32(&lynqEcallId);
664 sendSignalToWaitCallStateChange();
665 usleep(300*1000);
666 }
667 }
668 sendSignalIncomingECallEvent();
669 break;
670 }
671#endif
lh25827952022-01-10 00:34:35 -0800672 default:
673 break;
674 }
675 }
676 delete p;
677 p = NULL;
678 }
679 close(socket_fd);
680}
681int lynq_socket_urc_start()
682{
683 int socket_fd=0;
684 int rt=0;
685 int len=0;
686 int on=1;
687 struct sockaddr_in urc_local_addr;
lh25827952022-01-10 00:34:35 -0800688 pthread_attr_t attr;
ll375c94d2022-01-27 05:54:38 +0000689 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll375c94d2022-01-27 05:54:38 +0000690 if(socket_fd < 0)
691 {
llc10c9572022-03-01 09:18:53 +0000692 LYERRLOG("creaet socket for udp fail\n");
ll375c94d2022-01-27 05:54:38 +0000693 return -1;
lh25827952022-01-10 00:34:35 -0800694 }
695 urc_local_addr.sin_family = AF_INET;
696 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
697 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
698 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll375c94d2022-01-27 05:54:38 +0000699 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
700 if(rt<0)
701 {
llc10c9572022-03-01 09:18:53 +0000702 LYERRLOG("SO_REUSEADDR fail\n");
lh25827952022-01-10 00:34:35 -0800703 return -1;
704 }
705 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll375c94d2022-01-27 05:54:38 +0000706 if (rt == -1)
707 {
lh59e0d002022-01-27 00:27:12 -0800708 LYERRLOG("bind failed");
ll375c94d2022-01-27 05:54:38 +0000709 return -1;
lh25827952022-01-10 00:34:35 -0800710 }
711 pthread_attr_init(&attr);
712 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -0800713 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh25827952022-01-10 00:34:35 -0800714 if(rt < 0)
715 {
lh59e0d002022-01-27 00:27:12 -0800716 LYERRLOG("urc loop failure!!!\n");
lh25827952022-01-10 00:34:35 -0800717 return -1;
718 }
lh59e0d002022-01-27 00:27:12 -0800719 LYDBGLOG("urc loop success!!!\n");
lh25827952022-01-10 00:34:35 -0800720 return 0;
721}
722int getSelfElement(char addr[])
723{
724 for(int i=0;i < LYNQ_CALL_MAX; i++)
725 {
726 if(lynq_call_lists[i].used==1)
727 {
728 if(strcmp(lynq_call_lists[i].addr,addr)==0)
729 {
730 return i;
731 }
732
733 }
734 }
735 return -1;
736}
737
738void lynq_call_state_change_test(int soc_id)
739{
ll22101402022-04-11 05:49:51 +0000740 LYDBGLOG("call state change,sim:%d\n",soc_id);
lh25827952022-01-10 00:34:35 -0800741}
742int lynq_init_call(int uToken)
ll1343a5b2022-03-17 05:31:33 +0000743{
744 if(g_lynq_call_init_flag == 1){
745 LYDBGLOG("lynq init call failed!!!");
746 return -1;
747 }
748 g_lynq_call_init_flag = 1;
lh25827952022-01-10 00:34:35 -0800749 int result = 0;
lha35d4ee2022-01-25 18:47:39 -0800750 Global_uToken_call = uToken;
lh59e0d002022-01-27 00:27:12 -0800751 urc_call_recive_status = 1;
rjw8bdc56b2022-02-28 15:01:49 +0800752 client_size = sizeof(client_t);
lh25827952022-01-10 00:34:35 -0800753 LYLOGSET(LOG_INFO);
754 LYLOGEINIT(USER_LOG_TAG);
755 result = lynq_socket_client_start();
756 if(result!=0)
757 {
758 return -1;
759 }
760 result = lynq_socket_urc_start();
761 if(result!=0)
762 {
763 return -1;
764 }
765 result = lynq_update_call_list_loop();
766 if(result!=0)
767 {
768 return -1;
769 }
770 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
771 LYDBGLOG("lynq init call success!!!");
772 return 0;
773}
774int lynq_deinit_call()
775{
ll1343a5b2022-03-17 05:31:33 +0000776 if(g_lynq_call_init_flag == 0)
lhcdf816a2022-02-13 23:56:05 -0800777 {
ll1343a5b2022-03-17 05:31:33 +0000778 LYDBGLOG("lynq_deinit_call failed!!!");
779 return -1;
lhcdf816a2022-02-13 23:56:05 -0800780 }
ll1343a5b2022-03-17 05:31:33 +0000781 else
782 {
783 g_lynq_call_init_flag = 0;
784 int ret = -1;
785 if(lynq_call_client_sockfd>0)
786 {
787 close(lynq_call_client_sockfd);
788 }
789 urc_call_recive_status = 0;
790 call_list_loop = 0;
791 if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
792 {
793 return -1;
794 }
795 ret = pthread_cancel(lynq_call_urc_tid);
796 LYDBGLOG("pthread cancel ret = %d",ret);
797 ret = pthread_cancel(lynq_call_list_loop_tid);
798 LYDBGLOG("pthread cancel ret = %d",ret);
799 ret = pthread_join(lynq_call_urc_tid,NULL);
800 LYDBGLOG("pthread join ret = %d",ret);
801 ret = pthread_join(lynq_call_list_loop_tid,NULL);
802 LYDBGLOG("pthread join ret = %d",ret);
803 return 0;
804 }
rita47debb92022-04-07 06:08:13 -0400805}
q.huangfe1b4052022-04-18 00:09:50 -0400806
807int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita9b436d82022-04-07 01:55:39 -0400808{
809 Parcel p;
810 lynq_client_t client;
811 int resp_type = -1;
812 int request = -1;
813 int slot_id = -1;
814 int error = -1;
rita9b436d82022-04-07 01:55:39 -0400815
816 client.uToken = Global_uToken_call;
q.huangfe1b4052022-04-18 00:09:50 -0400817 client.request = request_id;
818 client.paramLen = argc;
rita9b436d82022-04-07 01:55:39 -0400819 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangfe1b4052022-04-18 00:09:50 -0400820 if(argc!=0)
821 {
822 va_list args;
823 va_start(args, format);
824 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
825 va_end(args);
826 }
827 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -0400828 if(send_request(lynq_call_client_sockfd,&client)==-1)
829 {
830 LYERRLOG("send request fail");
831 return -1;
832 }
q.huangfe1b4052022-04-18 00:09:50 -0400833 if(get_response(lynq_call_client_sockfd,p)==0)
834 {
835 JumpHeader(p,&resp_type,&request,&slot_id,&error);
836 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
837 }
rita9b436d82022-04-07 01:55:39 -0400838 return error;
839}
840
q.huangfe1b4052022-04-18 00:09:50 -0400841int lynq_get_common_request(int request_id, int* status)
rita9b436d82022-04-07 01:55:39 -0400842{
843 Parcel p;
844 lynq_client_t client;
845 int resp_type = -1;
846 int request = -1;
847 int slot_id = -1;
848 int error = -1;
q.huangfe1b4052022-04-18 00:09:50 -0400849 if(status==NULL)
850 {
851 LYERRLOG("status is null");
852 return -1;
853 }
rita9b436d82022-04-07 01:55:39 -0400854 client.uToken = Global_uToken_call;
q.huangfe1b4052022-04-18 00:09:50 -0400855 client.request = request_id;
856 client.paramLen = 0;
rita9b436d82022-04-07 01:55:39 -0400857 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangfe1b4052022-04-18 00:09:50 -0400858 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -0400859 if(send_request(lynq_call_client_sockfd,&client)==-1)
860 {
861 LYERRLOG("send request fail");
862 return -1;
863 }
q.huangfe1b4052022-04-18 00:09:50 -0400864 if(get_response(lynq_call_client_sockfd,p)==0)
rita9b436d82022-04-07 01:55:39 -0400865 {
q.huangfe1b4052022-04-18 00:09:50 -0400866 JumpHeader(p,&resp_type,&request,&slot_id,&error);
867 p.readInt32(status);
868 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
rita9b436d82022-04-07 01:55:39 -0400869 }
rita9b436d82022-04-07 01:55:39 -0400870 return error;
871}
872
lh25827952022-01-10 00:34:35 -0800873int lynq_call(int* handle,char addr[])
874{
875 Parcel p;
876 lynq_client_t client;
877 int resp_type = -1;
878 int request = -1;
879 int slot_id = -1;
880 int error = -1;
881 int lynq_call_id = -1;
882 if(addr==NULL)
883 {
884 LYERRLOG("Phone num is null!!!");
885 return -1;
886 }
lha35d4ee2022-01-25 18:47:39 -0800887 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -0800888 client.request = 10;//RIL_REQUEST_DIAL
889 client.paramLen = 2;
890 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
891 memcpy(client.param,addr,strlen(addr)+1);
892 strcat(client.param," 0");
893 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800894 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800895 {
896 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800897 return -1;
898 }
lha35d4ee2022-01-25 18:47:39 -0800899 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -0800900 JumpHeader(p,&resp_type,&request,&slot_id,&error);
901 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
902 lynq_call_id = updateAddr(addr);
903 if(error==0)
904 {
905 isDial = 1;
ll45d3ea92022-03-24 10:22:25 +0800906 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh25827952022-01-10 00:34:35 -0800907 {
lhbe92dd12022-04-19 06:01:25 -0700908 //if timeout,this call need destroy.
909 isDial = 0;
910
lh25827952022-01-10 00:34:35 -0800911 error = LYNQ_E_TIME_OUT;
912 LYERRLOG("timeout:wait Call state fail!!!");
913 lynq_call_lists[lynq_call_id].hasTimeout = 1;
914 return error;
915 }
916 *handle = lynq_call_id;
917 }
918 return error;
919}
920int lynq_call_answer()
921{
922 Parcel p;
923 lynq_client_t client;
924 int resp_type = -1;
925 int request = -1;
926 int slot_id = -1;
927 int error = -1;
lha35d4ee2022-01-25 18:47:39 -0800928 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -0800929 client.request = 40;//RIL_REQUEST_DIAL
930 client.paramLen = 0;
931 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
932 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800933 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800934 {
935 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800936 return -1;
937 }
lha35d4ee2022-01-25 18:47:39 -0800938 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -0800939 JumpHeader(p,&resp_type,&request,&slot_id,&error);
940 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
941 return error;
942}
943int lynq_call_hungup(int* handle)
944{
945 Parcel p;
946 lynq_client_t client;
947 int resp_type = -1;
948 int request = -1;
949 int slot_id = -1;
950 int error = -1;
951 int call_id = 0;
952 int lynq_call_id = 0;
lha35d4ee2022-01-25 18:47:39 -0800953 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
954 {
955 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
956 return LYNQ_E_CONFLICT;
957 }
958 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -0800959 client.request = 12;//RIL_REQUEST_HUNGUP
960 client.paramLen = 1;
961 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
962 lynq_call_id = *handle;
963 call_id = lynq_call_lists[lynq_call_id].call_id;
964 sprintf(client.param,"%d",call_id);
965 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800966 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800967 {
968 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800969 return -1;
970 }
lha35d4ee2022-01-25 18:47:39 -0800971 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -0800972 JumpHeader(p,&resp_type,&request,&slot_id,&error);
973 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
974 if(error==0)
975 {
976 cleanCallList(lynq_call_id);
977 }
978 return error;
979}
980int lynq_call_hungup_all()
981{
982 Parcel p;
983 lynq_client_t client;
984 int resp_type = -1;
985 int request = -1;
986 int slot_id = -1;
987 int error = -1;
lha35d4ee2022-01-25 18:47:39 -0800988 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -0800989 client.request = 17;//RIL_REQUEST_UDUB
990 client.paramLen = 0;
991 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
992 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800993 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800994 {
995 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800996 return -1;
997 }
lha35d4ee2022-01-25 18:47:39 -0800998 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -0800999 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1000 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1001 return error;
1002}
1003int lynq_wait_incoming_call(int *handle)
1004{
1005 waitIncomingCall();
1006 *handle = lynqIncomingCallId;
1007 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
1008 return 0;
1009}
1010
1011int lynq_set_auto_answercall(const int mode)
1012{
1013 global_call_auto_answer = mode;
1014 LYINFLOG("auto answer call mode =%d",mode);
1015 return 0;
1016}
q.huangb0eb7b02022-03-29 04:17:32 -04001017int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1018{
1019 int lynq_call_id = 0;
1020 if(handle==NULL)
1021 {
1022 return LYNQ_E_NULL_ANONALY;
1023 }
1024 lynq_call_id = *handle;
1025 *call_state = lynq_call_lists[lynq_call_id].call_state;
1026 *toa = lynq_call_lists[lynq_call_id].toa;
1027 *direction = lynq_call_lists[lynq_call_id].direction;
1028 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
1029 return 0;
1030}
1031
1032/*audio begin*/
ll7e055f22022-01-24 12:16:22 +00001033static int judge_mic(const int enable){
llc6030062022-02-14 08:58:16 +00001034 switch(enable){
1035 case 0:
1036 return 1;
1037 case 1:
1038 return 1;
1039 default:
1040 return 0;
ll7e055f22022-01-24 12:16:22 +00001041 }
1042}
1043
lh25827952022-01-10 00:34:35 -08001044int lynq_set_mute_mic(const int enable)
ll7e055f22022-01-24 12:16:22 +00001045{
1046 if(!judge_mic(enable)){
1047 return LYNQ_E_CONFLICT;
1048 }
q.huangb0eb7b02022-03-29 04:17:32 -04001049 return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1050}
1051int lynq_get_mute_mic(int *status)
1052{
1053 return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
lh25827952022-01-10 00:34:35 -08001054}
ll45d3ea92022-03-24 10:22:25 +08001055
1056/**
1057 * @brief Check whether DTMF is valid
1058 *
1059 * @param callnum dtmf eg:0-9 * #
1060 * @return int
1061 */
1062static int judge_dtmf(const char callnum)
1063{
1064 if(callnum == '#')
1065 {
1066 return 1;
1067 }
1068 if(callnum == '*')
1069 {
1070 return 1;
1071 }
1072 if(callnum >= '0'&& callnum <= '9')
1073 {
1074 return 1;
1075 }
1076 return 0;
1077}
1078
lh25827952022-01-10 00:34:35 -08001079int lynq_set_DTMF(const char callnum)
1080{
ll45d3ea92022-03-24 10:22:25 +08001081 if(!judge_dtmf(callnum))
1082 {
1083 return LYNQ_E_CONFLICT;
1084 }
lh25827952022-01-10 00:34:35 -08001085 if(!lynq_call_state)
1086 {
1087 LYERRLOG("LYNQ_E_CONFLICT");
1088 return LYNQ_E_CONFLICT;
1089 }
q.huangb0eb7b02022-03-29 04:17:32 -04001090 return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
lh25827952022-01-10 00:34:35 -08001091}
q.huangb0eb7b02022-03-29 04:17:32 -04001092static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1093 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1094 if(volume < 0 ||volume >36){
1095 return 0;
1096 }
1097 }
1098 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1099 {
1100 if(volume < 1 ||volume >7){
1101 return 0;
1102 }
ll7e055f22022-01-24 12:16:22 +00001103 }
ll375c94d2022-01-27 05:54:38 +00001104 return 1;
ll7e055f22022-01-24 12:16:22 +00001105}
lh25827952022-01-10 00:34:35 -08001106int lynq_set_DTMF_volume(const int volume)
ll7e055f22022-01-24 12:16:22 +00001107{
q.huangb0eb7b02022-03-29 04:17:32 -04001108 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
ll7e055f22022-01-24 12:16:22 +00001109 return LYNQ_E_CONFLICT;
1110 }
q.huangb0eb7b02022-03-29 04:17:32 -04001111 return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
lh25827952022-01-10 00:34:35 -08001112}
q.huang9ee6d5b2022-04-05 23:11:02 -04001113int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh25827952022-01-10 00:34:35 -08001114{
q.huangb0eb7b02022-03-29 04:17:32 -04001115 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
lh25827952022-01-10 00:34:35 -08001116 {
q.huangb0eb7b02022-03-29 04:17:32 -04001117 return LYNQ_E_CONFLICT;
lh25827952022-01-10 00:34:35 -08001118 }
q.huangb0eb7b02022-03-29 04:17:32 -04001119 return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
lh25827952022-01-10 00:34:35 -08001120}
q.huangb0eb7b02022-03-29 04:17:32 -04001121int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1122{
1123 return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
1124}
q.huang9ee6d5b2022-04-05 23:11:02 -04001125int lynq_incall_record_start(const char* file_path)
q.huangb0eb7b02022-03-29 04:17:32 -04001126{
q.huang9ee6d5b2022-04-05 23:11:02 -04001127 return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
q.huangb0eb7b02022-03-29 04:17:32 -04001128}
1129int lynq_incall_record_stop()
1130{
q.huang9ee6d5b2022-04-05 23:11:02 -04001131 const char* unused_file="just_ocuupy_paramter_postion";
1132 return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
q.huangb0eb7b02022-03-29 04:17:32 -04001133}
1134/*audio end*/
q.huangfe1b4052022-04-18 00:09:50 -04001135
1136#ifdef ECALL_SUPPORT
1137LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
1138{
1139 switch(type)
1140 {
1141 case LYNQ_ECALL_TYPE_TEST:
1142 return LYNQ_ECALL_TEST;
1143 case LYNQ_ECALL_TYPE_RECONFIG:
1144 return LYNQ_ECALL_RECONFIG;
1145 default:
1146 return LYNQ_ECALL_EMERGENCY;
1147 }
1148}
1149
1150RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
1151{
1152 switch(type)
1153 {
1154 case LYNQ_ECALL_TEST:
1155 return ECALL_TEST;
1156 case LYNQ_ECALL_RECONFIG:
1157 return ECALL_RECONFIG;
1158 default:
1159 return ECALL_EMERGENCY;
1160 }
1161}
1162
1163RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
1164{
1165 switch(cat)
1166 {
1167 case LYNQ_EMER_CAT_MANUAL_ECALL:
1168 return EMER_CAT_MANUAL_ECALL;
1169 default:
1170 return EMER_CAT_AUTO_ECALL;
1171 }
1172}
1173
1174
1175int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
1176{
1177 int error;
1178
1179 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
1180 {
1181 LYERRLOG("test_num is null or test_num_length %d s greater than %d\n ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
1182 return -1;
1183 }
1184
1185 error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
1186
1187 if(error==0)
1188 {
1189 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
1190 }
1191
1192 return error;
1193}
1194
1195
q.huang892722f2022-05-10 20:37:21 +08001196int lynq_fast_ecall(int* handle, LYNQ_ECall_Category lynq_ecall_cat, LYNQ_ECall_Variant lynq_ecall_variant, const char *addr, int addr_length, const unsigned char *msd_data,int msd_length)
q.huangfe1b4052022-04-18 00:09:50 -04001197{
1198 int error = -1;
1199 int lynq_call_id = -1;
1200 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
q.huang9a9b8762022-04-19 05:20:12 -04001201 RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
q.huang6a119762022-05-11 20:10:38 +08001202 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
1203 unsigned int i;
q.huangfe1b4052022-04-18 00:09:50 -04001204
q.huang892722f2022-05-10 20:37:21 +08001205 if(msd_length > MSD_MAX_LENGTH)
1206 {
1207 LYERRLOG("msd_length %d is greater than %d, parameter error\n",msd_length,MSD_MAX_LENGTH);
1208 return -1;
1209 }
q.huang892722f2022-05-10 20:37:21 +08001210
q.huang6a119762022-05-11 20:10:38 +08001211 for(i =0; i<msd_length;i++)
q.huang892722f2022-05-10 20:37:21 +08001212 {
q.huang6a119762022-05-11 20:10:38 +08001213 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
q.huang892722f2022-05-10 20:37:21 +08001214 }
1215
q.huang18d08bf2022-04-19 20:27:44 -04001216 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1217
1218 LYINFLOG("e_call_addr is %s\n",e_call_addr[lynq_ecall_variant]);
1219
q.huang892722f2022-05-10 20:37:21 +08001220 error=lynq_set_common_request(RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", lynq_msd_data);
q.huangfe1b4052022-04-18 00:09:50 -04001221
1222 if(error==0)
q.huang18d08bf2022-04-19 20:27:44 -04001223 {
q.huangfe1b4052022-04-18 00:09:50 -04001224 isDial = 1;
q.huang18d08bf2022-04-19 20:27:44 -04001225 if(waitCallstateChange(30000)==ETIMEDOUT)//30000ms
q.huangfe1b4052022-04-18 00:09:50 -04001226 {
q.huang18d08bf2022-04-19 20:27:44 -04001227 isDial = 0;
q.huangfe1b4052022-04-18 00:09:50 -04001228 error = LYNQ_E_TIME_OUT;
q.huang18d08bf2022-04-19 20:27:44 -04001229 cleanCallList(lynq_call_id);
1230 LYERRLOG("timeout:wait Call state fail!!!");
q.huangfe1b4052022-04-18 00:09:50 -04001231 return error;
1232 }
q.huang18d08bf2022-04-19 20:27:44 -04001233
q.huangfe1b4052022-04-18 00:09:50 -04001234 *handle = lynq_call_id;
q.huang18d08bf2022-04-19 20:27:44 -04001235 if(lynq_ecall_variant==LYNQ_ECALL_EMERGENCY){
1236 lynq_call_lists[lynq_call_id].call_id=lynqEcallId;
1237 }
1238 LYINFLOG("lynq_fast_ecall handle is:%d, call id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
1239
1240 }
1241 else {
1242 cleanCallList(lynq_call_id);
q.huangfe1b4052022-04-18 00:09:50 -04001243 }
1244
1245 return error;
1246}
1247
1248int lynq_set_psap(int enable)
1249{
1250 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
1251}
1252
1253int lynq_psap_pull_msd()
1254{
1255 return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
1256}
1257
1258int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
1259{
1260 LYNQ_ECall_Variant lynq_ecall_variant;
1261 int error = -1;
1262 int lynq_call_id = -1;
1263
1264 if(handle==NULL)
1265 {
1266 LYERRLOG("handle is NULL, parameter error \n ");
1267 return -1;
1268 }
1269
1270 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
1271
1272 if(error==0)
1273 {
1274 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
1275
1276 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1277 isDial = 1;
1278 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1279 {
1280 error = LYNQ_E_TIME_OUT;
1281 LYERRLOG("timeout:wait Call state fail!!!");
1282 lynq_call_lists[lynq_call_id].hasTimeout = 1;
1283 return error;
1284 }
1285
1286 *handle = lynq_call_id;
1287 }
1288
1289 return error;
1290}
1291
1292
q.huangbd6a3062022-05-10 20:49:46 +08001293int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length)
q.huangfe1b4052022-04-18 00:09:50 -04001294{
q.huang6a119762022-05-11 20:10:38 +08001295 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
1296 unsigned int i;
1297
q.huangbd6a3062022-05-10 20:49:46 +08001298 if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX) || msd_length > MSD_MAX_LENGTH)
q.huangfe1b4052022-04-18 00:09:50 -04001299 {
q.huangbd6a3062022-05-10 20:49:46 +08001300 LYERRLOG("handle is NULL or *handle %d is greater or equeal to %d or msd_length %d is greater than %d, parameter error\n",*handle,LYNQ_CALL_MAX,msd_length,MSD_MAX_LENGTH);
1301 return -1;
1302 }
q.huangbd6a3062022-05-10 20:49:46 +08001303
q.huang6a119762022-05-11 20:10:38 +08001304 for(i=0; i<msd_length;i++)
q.huangbd6a3062022-05-10 20:49:46 +08001305 {
q.huang6a119762022-05-11 20:10:38 +08001306 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
q.huangfe1b4052022-04-18 00:09:50 -04001307 }
1308
q.huangbd6a3062022-05-10 20:49:46 +08001309 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,lynq_msd_data);
q.huangfe1b4052022-04-18 00:09:50 -04001310}
1311
1312int lynq_set_ivs(int enable)
1313{
1314 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
1315}
1316
1317int lynq_reset_ivs()
1318{
1319 return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
1320}
1321
1322int lynq_ivs_push_msd()
1323{
1324 return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
1325}
q.huang18d08bf2022-04-19 20:27:44 -04001326
1327int wait_ecall_event()
1328{
1329 int ret = 0;
1330 pthread_mutex_lock(&s_incoming_e_call_mutex);
1331 ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
1332 pthread_mutex_unlock(&s_incoming_e_call_mutex);
1333 return ret;
1334}
1335
1336int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)
1337{
1338 wait_ecall_event();
1339 *eCall_Indication = lynqIncomingEcallIndication;
1340 LYINFLOG("lynq incoming e-call indication id:%d",lynqIncomingEcallIndication);
1341 return 0;
1342}
1343
q.huangfe1b4052022-04-18 00:09:50 -04001344#endif
1345
lh25827952022-01-10 00:34:35 -08001346#if 0
1347int main(int argc,char **argv)
1348{
1349 int n = 0;
1350 n = lynq_init_call(lynq_call_state_change_test,2222);
1351 if(n<0)
1352 {
ll22101402022-04-11 05:49:51 +00001353 LYDBGLOG("lynq init call fail!!!\n");
lh25827952022-01-10 00:34:35 -08001354 return -1;
1355 }
ll22101402022-04-11 05:49:51 +00001356 LYDBGLOG("lynq call init success!!!\n");
lh25827952022-01-10 00:34:35 -08001357 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1358 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1359 lynq_call(phoneNum);
1360 while(1)
1361 {
1362 sleep(1);
1363 }
1364 return 0;
1365}
1366#endif
1367/*Warren add for T800 platform 2021/11/19 end*/