blob: 93b105823cb8b011a85b2847f33c82aae34bf95f [file] [log] [blame]
lh7b0674a2022-01-10 00:34:35 -08001#include <stdio.h>
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <arpa/inet.h>
5#include <fcntl.h>
6#include <string.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <binder/Parcel.h>
10#include <log/log.h>
lh7b0674a2022-01-10 00:34:35 -080011#include <cutils/jstring.h>
12#include <pthread.h>
13#include "liblog/lynq_deflog.h"
lh2afc7732022-01-10 02:24:31 -080014#include <sys/time.h>
lh21502f52022-01-27 00:27:12 -080015#include <string.h>
q.huang714145d2022-04-18 00:09:50 -040016#include <vendor-ril/telephony/ril.h>
17#include <vendor-ril/telephony/mtk_ril_sp.h>
18#include <vendor-ril/telephony/mtk_ril_ivt.h>
19#include "lynq_call.h"
20
21
lh7b0674a2022-01-10 00:34:35 -080022#define LYNQ_SERVICE_PORT 8088
rjw5d2a50e2022-02-28 15:01:49 +080023#define DSET_IP_ADDRESS "127.0.0.1"
lh7b0674a2022-01-10 00:34:35 -080024#define LYNQ_URC_SERVICE_PORT 8086
25#define LYNQ_REC_BUF 8192
26#define LYNQ_REQUEST_PARAM_BUF 8192
27#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
28#define USER_LOG_TAG "LYNQ_CALL"
29
30using ::android::Parcel;
31 typedef enum {
32 LYNQ_CALL_ACTIVE = 0,
33 LYNQ_CALL_HOLDING = 1,
34 LYNQ_CALL_DIALING = 2, /* MO call only */
35 LYNQ_CALL_ALERTING = 3, /* MO call only */
36 LYNQ_CALL_INCOMING = 4, /* MT call only */
lhe45b7002022-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*/
lh7b0674a2022-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;
ll04ae4142022-01-27 05:54:38 +000071static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
lh7b0674a2022-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;
lla8c25a82022-03-17 05:31:33 +000075pthread_t lynq_call_urc_tid = -1;
76pthread_t lynq_call_list_loop_tid = -1;
lhec17b0a2022-02-13 23:56:05 -080077
rjw5d2a50e2022-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*/
lh7b0674a2022-01-10 00:34:35 -080085
lh42c1e572022-01-25 18:47:39 -080086int s_call_urc_event_complete = 1;
lh7b0674a2022-01-10 00:34:35 -080087
88enum{
89 CALL_OFF=0,
90 CALL_ON=1
91}call_state;
ll04ae4142022-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
lh7b0674a2022-01-10 00:34:35 -0800110}LYNQ_E;
q.huangec88da92022-03-29 04:17:32 -0400111typedef enum{
112 LYNQ_E_VOLUMN_SET_DTMF,
113 LYNQ_E_VOLUMN_SET_SPEECH
114}LYNQ_E_VOLUMN_SET;
lh7b0674a2022-01-10 00:34:35 -0800115
116int lynq_call_state =CALL_OFF;
lh42c1e572022-01-25 18:47:39 -0800117int lynq_call_client_sockfd = 0;
118int Global_uToken_call = 0;
lh7b0674a2022-01-10 00:34:35 -0800119int global_call_count =0;
120int global_call_auto_answer = 0;
lh42c1e572022-01-25 18:47:39 -0800121bool urc_call_recive_status = 1;
lh7b0674a2022-01-10 00:34:35 -0800122bool call_list_loop = 1;
123int isDial = 0;
124int lynqIncomingCallId = 0;
q.huang8b33ed52022-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.huang714145d2022-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.huang8b33ed52022-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.huang714145d2022-04-18 00:09:50 -0400151
lla8c25a82022-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;
lh7b0674a2022-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;
rjw5d2a50e2022-02-28 15:01:49 +0800177 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800178 if(ret==-1)
179 {
ll3fe03462022-03-01 09:18:53 +0000180 LYERRLOG("sendto error\n");
lh7b0674a2022-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 */
rjw5d2a50e2022-02-28 15:01:49 +0800192 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800193 if(len == -1)
194 {
ll3fe03462022-03-01 09:18:53 +0000195 LYERRLOG("recvfrom error\n");
lh7b0674a2022-01-10 00:34:35 -0800196 return -1;
197 }
lh7b0674a2022-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) {
ll04ae4142022-01-27 05:54:38 +0000205 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800206 const char16_t *s16;
207 s16 = p.readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000208 return strndup16to8(s16, stringlen);
lh7b0674a2022-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;
lh42c1e572022-01-25 18:47:39 -0800224 client.uToken = Global_uToken_call;
lh7b0674a2022-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);
lh42c1e572022-01-25 18:47:39 -0800229 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800230 {
231 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800232 return -1;
233 }
lh42c1e572022-01-25 18:47:39 -0800234 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-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;
lhec17b0a2022-02-13 23:56:05 -0800244 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800245 return 0;
246 }
lhec17b0a2022-02-13 23:56:05 -0800247 lynq_call_state = CALL_ON;
248 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-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;
lhe45b7002022-04-26 00:45:44 -0700285 lynq_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
lh7b0674a2022-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{
lhd1e457c2022-04-19 06:01:25 -0700313 LYINFLOG("Update Call List");
lh7b0674a2022-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{
lhd1e457c2022-04-19 06:01:25 -0700324 LYINFLOG("wait Call state Change");
lh7b0674a2022-01-10 00:34:35 -0800325 int ret = 0;
326 int sec = 0;
327 int usec = 0;
lh2afc7732022-01-10 02:24:31 -0800328 struct timeval now;
329 struct timespec timeout;
330 gettimeofday(&now,NULL);
lh7b0674a2022-01-10 00:34:35 -0800331 sec = mtime/1000;
332 usec = mtime%1000;
lh2afc7732022-01-10 02:24:31 -0800333 timeout.tv_sec = now.tv_sec+sec;
334 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh7b0674a2022-01-10 00:34:35 -0800335 pthread_mutex_lock(&call_state_change_mutex);
lh2afc7732022-01-10 02:24:31 -0800336 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh7b0674a2022-01-10 00:34:35 -0800337 pthread_mutex_unlock(&call_state_change_mutex);
338 return ret;
339}
340int waitIncomingCall()
341{
lhd1e457c2022-04-19 06:01:25 -0700342 LYINFLOG("wait incming call");
lh7b0674a2022-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{
lhd1e457c2022-04-19 06:01:25 -0700351 LYINFLOG("check has call");
lh7b0674a2022-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}
lhd1e457c2022-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}
lh7b0674a2022-01-10 00:34:35 -0800373void sendSignalToWaitCallStateChange()
374{
lhd1e457c2022-04-19 06:01:25 -0700375 LYINFLOG("send Signal To Wait Call State Change");
lh7b0674a2022-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{
lhd1e457c2022-04-19 06:01:25 -0700382 LYINFLOG("send incoming call signal");
lh7b0674a2022-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)
ll04ae4142022-01-27 05:54:38 +0000401{
402 int ret=0;
lhd1e457c2022-04-19 06:01:25 -0700403 bool call_end;
404 call_end = 0;//0:this call end,1:call on
ll04ae4142022-01-27 05:54:38 +0000405 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang8b33ed52022-04-19 20:27:44 -0400406 int update=0;
lh7b0674a2022-01-10 00:34:35 -0800407 while(call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000408 {
q.huang8b33ed52022-04-19 20:27:44 -0400409 update=0;
ll04ae4142022-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);
lh7b0674a2022-01-10 00:34:35 -0800412 LYDBGLOG("triggerGetCallList event!!!\n");
ll04ae4142022-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 {
llbc035332022-04-11 05:49:51 +0000417 LYDBGLOG("get current call list failure!!!\n");
418 continue;
ll04ae4142022-01-27 05:54:38 +0000419 }
lhd1e457c2022-04-19 06:01:25 -0700420 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
lh7b0674a2022-01-10 00:34:35 -0800421 for(int i = 0;i < LYNQ_CALL_MAX;i++)
422 {
lhd1e457c2022-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
lh7b0674a2022-01-10 00:34:35 -0800441 if(call_list[i].direction == 1)//MT call
442 {
443 if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
444 {
ll72bf6c12022-03-24 10:22:25 +0800445 /*you call me, and i call you,One party failed to dial*/
lh7b0674a2022-01-10 00:34:35 -0800446 if(!checkHasCall(call_list[i].addr))
447 {
448 lynqIncomingCallId = getUnusedElement();
449 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);
450 sendSignalIncomingCall();
451 }
lhd1e457c2022-04-19 06:01:25 -0700452 else
453 {
454 int temp_call_id = find_call_id_with_addr(call_list[i].addr);
455 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
456 **an incoming call until the status changes.
457 **fix bug API-54
458 */
459 if((temp_call_id > 0) && (lynq_call_lists[temp_call_id].call_state == call_list[i].call_state))
460 {
461 sendSignalIncomingCall();
462 }
463 }
lh7b0674a2022-01-10 00:34:35 -0800464 }
ll72bf6c12022-03-24 10:22:25 +0800465 /*if state changed*/
466 else
467 {
468 /*update call state*/
469 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
470 {
471 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
472 {
473 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
ll90a255c2022-04-07 09:09:55 +0000474 break;
ll72bf6c12022-03-24 10:22:25 +0800475 }
476 }
477 }
lh7b0674a2022-01-10 00:34:35 -0800478 }
479 else
480 {
481 if(call_list[i].call_id==0)
482 {
483 break;
484 }
485 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
486 {
lhd1e457c2022-04-19 06:01:25 -0700487 if((lynq_call_lists[n].hasTimeout == 1) && (strcmp(lynq_call_lists[n].addr,call_list[i].addr) == 0))
lh7b0674a2022-01-10 00:34:35 -0800488 {
lhd1e457c2022-04-19 06:01:25 -0700489 cleanCallList(n);//if this call time out,need clean lynq call list.
490 /*hangup call with call id*/
491 lynq_call_hungup(&call_list[i].call_id);
lh7b0674a2022-01-10 00:34:35 -0800492 lynq_call_lists[n].hasTimeout==0;
493 continue;
494 }
q.huang8b33ed52022-04-19 20:27:44 -0400495 LYDBGLOG("lynq_call_lists n is %d, used is %d, addr is %s addr2 %s\n",
496 n,lynq_call_lists[n].used,call_list[i].addr,lynq_call_lists[n].addr);
497 if(lynq_call_lists[n].used && (strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0))
lh7b0674a2022-01-10 00:34:35 -0800498 {
q.huang8b33ed52022-04-19 20:27:44 -0400499 LYINFLOG("updated\n");
lh7b0674a2022-01-10 00:34:35 -0800500 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
q.huang8b33ed52022-04-19 20:27:44 -0400501 update=1;
502 break;
lh7b0674a2022-01-10 00:34:35 -0800503 }
504 }
505 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,
506 call_list[i].direction,call_list[i].addr,call_list[i].toa);
507 }
ll04ae4142022-01-27 05:54:38 +0000508 }
lh42c1e572022-01-25 18:47:39 -0800509 s_call_urc_event_complete = 1;
q.huang8b33ed52022-04-19 20:27:44 -0400510 if((isDial==1) && (update==1))
lh7b0674a2022-01-10 00:34:35 -0800511 {
512 sendSignalToWaitCallStateChange();
513 isDial = 0;
514 }
ll04ae4142022-01-27 05:54:38 +0000515 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
516 }
517 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800518}
519
520void lynqRespWatingEvent()
ll04ae4142022-01-27 05:54:38 +0000521{
522 if(s_call_urc_event_complete==1)
523 {
524 pthread_mutex_lock(&s_urc_call_state_change_mutex);
525 pthread_cond_signal(&s_urc_call_state_change_cond);
526 s_call_urc_event_complete = 0;
527 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800528 }
ll04ae4142022-01-27 05:54:38 +0000529 return;
lh7b0674a2022-01-10 00:34:35 -0800530}
531
532/*Warren add for T800 platform 2021/11/19 start*/
533int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800534{
535 #if 0
lh7b0674a2022-01-10 00:34:35 -0800536 struct sockaddr_in lynq_socket_server_addr;
537 /* init lynq_socket_server_addr */
538 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
539 lynq_socket_server_addr.sin_family = AF_INET;
540 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
541 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800542
lh7b0674a2022-01-10 00:34:35 -0800543 /*
544 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
545 {
llbc035332022-04-11 05:49:51 +0000546 LYDBGLOG("[%s] is not a valid IPaddress\n", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800547 exit(1);
548 }
549*/
lh42c1e572022-01-25 18:47:39 -0800550 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
551 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800552 {
ll3fe03462022-03-01 09:18:53 +0000553 LYERRLOG("connect error\n");
lh7b0674a2022-01-10 00:34:35 -0800554 return -1;
555 }
rjw5d2a50e2022-02-28 15:01:49 +0800556 #endif
557 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
558 if (-1 == lynq_call_client_sockfd)
559 {
560 return lynq_call_client_sockfd;
561 }
562 /* 设置address */
563 memset(&addr_serv, 0, sizeof(addr_serv));
564 addr_serv.sin_family = AF_INET;
565 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
566 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
567 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800568 return 0;
569}
570int lynq_update_call_list_loop()
571{
572 int ret = 0;
lh7b0674a2022-01-10 00:34:35 -0800573 pthread_attr_t attr;
574 pthread_attr_init(&attr);
575 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800576 ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
lh7b0674a2022-01-10 00:34:35 -0800577 if(ret < 0)
578 {
579 LYERRLOG("lynq_update_call_list_loop fail!!!");
580 return -1;
581 }
582 LYDBGLOG("lynq_update_call_list_loop success!!!\n");
583 return 0;
584
585}
586void *thread_urc_recv(void *parg)
ll04ae4142022-01-27 05:54:38 +0000587{
lh7b0674a2022-01-10 00:34:35 -0800588 int socket_fd = (int64_t)parg;
589 int len=0;
590 socklen_t addr_len=0;
591 uint8_t *dataLength = NULL;
592 char urc_data[LYNQ_REC_BUF];
593 int slot_id = -1;
594 int resp_type = -1;
595 int urcid = -1;
596 Parcel *p = NULL;
597 struct sockaddr_in dest_addr;
q.huang8b33ed52022-04-19 20:27:44 -0400598#ifdef ECALL_SUPPORT
599 int ecall_ind;
600#endif
601
lh7b0674a2022-01-10 00:34:35 -0800602 LYINFLOG("thread_urc_recv in running....\n");
lh42c1e572022-01-25 18:47:39 -0800603 while(urc_call_recive_status)
lh7b0674a2022-01-10 00:34:35 -0800604 {
605 bzero(urc_data,LYNQ_REC_BUF);
606 //get data msg
607 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
608 if(len <= 0)
ll04ae4142022-01-27 05:54:38 +0000609 {
ll3fe03462022-03-01 09:18:53 +0000610 LYERRLOG("thread_urc_recv step2 fail\n");
ll04ae4142022-01-27 05:54:38 +0000611 break;
lh7b0674a2022-01-10 00:34:35 -0800612 }
613 LYDBGLOG("=====>urc data len<=====:%d\n",len);
614 p = new Parcel();
615 if(p==NULL)
616 {
lh21502f52022-01-27 00:27:12 -0800617 LYERRLOG("new parcel failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800618 break;
619 }
620 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
621 p->setDataPosition(0);
622 if(p->dataAvail() > 0)
623 {
624 p->readInt32(&resp_type);
625 p->readInt32(&urcid);
626 p->readInt32(&slot_id);
627 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
628 switch (urcid)
629 {
630 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
631 {
632 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
633 lynqRespWatingEvent();
634 break;
635 }
636 case 1018://RIL_UNSOL_CALL_RING
637 {
638 if(global_call_auto_answer==1)
639 {
640 lynq_call_answer();
641 }
642 break;
643 }
644 case 1029://RIL_UNSOL_RINGBACK_TONE
645 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
646 {
647 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
648 break;
649 }
q.huang8b33ed52022-04-19 20:27:44 -0400650#ifdef ECALL_SUPPORT
651 case RIL_UNSOL_ECALL_INDICATIONS:
652 {
653 p->readInt32(&ecall_ind);
654 lynqIncomingEcallIndication=ecall_ind;
655 if(LYNQ_ECALL_ACTIVE==lynqIncomingEcallIndication)
656 {
657 if(isDial==1)
658 {
659 p->readInt32(&lynqEcallId);
660 sendSignalToWaitCallStateChange();
661 usleep(300*1000);
662 }
663 }
664 sendSignalIncomingECallEvent();
665 break;
666 }
667#endif
lh7b0674a2022-01-10 00:34:35 -0800668 default:
669 break;
670 }
671 }
672 delete p;
673 p = NULL;
674 }
675 close(socket_fd);
676}
677int lynq_socket_urc_start()
678{
679 int socket_fd=0;
680 int rt=0;
681 int len=0;
682 int on=1;
683 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800684 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000685 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000686 if(socket_fd < 0)
687 {
ll3fe03462022-03-01 09:18:53 +0000688 LYERRLOG("creaet socket for udp fail\n");
ll04ae4142022-01-27 05:54:38 +0000689 return -1;
lh7b0674a2022-01-10 00:34:35 -0800690 }
691 urc_local_addr.sin_family = AF_INET;
692 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
693 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
694 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000695 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
696 if(rt<0)
697 {
ll3fe03462022-03-01 09:18:53 +0000698 LYERRLOG("SO_REUSEADDR fail\n");
lh7b0674a2022-01-10 00:34:35 -0800699 return -1;
700 }
701 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000702 if (rt == -1)
703 {
lh21502f52022-01-27 00:27:12 -0800704 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000705 return -1;
lh7b0674a2022-01-10 00:34:35 -0800706 }
707 pthread_attr_init(&attr);
708 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800709 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800710 if(rt < 0)
711 {
lh21502f52022-01-27 00:27:12 -0800712 LYERRLOG("urc loop failure!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800713 return -1;
714 }
lh21502f52022-01-27 00:27:12 -0800715 LYDBGLOG("urc loop success!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800716 return 0;
717}
718int getSelfElement(char addr[])
719{
720 for(int i=0;i < LYNQ_CALL_MAX; i++)
721 {
722 if(lynq_call_lists[i].used==1)
723 {
724 if(strcmp(lynq_call_lists[i].addr,addr)==0)
725 {
726 return i;
727 }
728
729 }
730 }
731 return -1;
732}
733
734void lynq_call_state_change_test(int soc_id)
735{
llbc035332022-04-11 05:49:51 +0000736 LYDBGLOG("call state change,sim:%d\n",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800737}
738int lynq_init_call(int uToken)
lla8c25a82022-03-17 05:31:33 +0000739{
740 if(g_lynq_call_init_flag == 1){
741 LYDBGLOG("lynq init call failed!!!");
742 return -1;
743 }
744 g_lynq_call_init_flag = 1;
lh7b0674a2022-01-10 00:34:35 -0800745 int result = 0;
lh42c1e572022-01-25 18:47:39 -0800746 Global_uToken_call = uToken;
lh21502f52022-01-27 00:27:12 -0800747 urc_call_recive_status = 1;
rjw5d2a50e2022-02-28 15:01:49 +0800748 client_size = sizeof(client_t);
lh7b0674a2022-01-10 00:34:35 -0800749 LYLOGSET(LOG_INFO);
750 LYLOGEINIT(USER_LOG_TAG);
751 result = lynq_socket_client_start();
752 if(result!=0)
753 {
754 return -1;
755 }
756 result = lynq_socket_urc_start();
757 if(result!=0)
758 {
759 return -1;
760 }
761 result = lynq_update_call_list_loop();
762 if(result!=0)
763 {
764 return -1;
765 }
766 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
767 LYDBGLOG("lynq init call success!!!");
768 return 0;
769}
770int lynq_deinit_call()
771{
lla8c25a82022-03-17 05:31:33 +0000772 if(g_lynq_call_init_flag == 0)
lhec17b0a2022-02-13 23:56:05 -0800773 {
lla8c25a82022-03-17 05:31:33 +0000774 LYDBGLOG("lynq_deinit_call failed!!!");
775 return -1;
lhec17b0a2022-02-13 23:56:05 -0800776 }
lla8c25a82022-03-17 05:31:33 +0000777 else
778 {
779 g_lynq_call_init_flag = 0;
780 int ret = -1;
781 if(lynq_call_client_sockfd>0)
782 {
783 close(lynq_call_client_sockfd);
784 }
785 urc_call_recive_status = 0;
786 call_list_loop = 0;
787 if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
788 {
789 return -1;
790 }
791 ret = pthread_cancel(lynq_call_urc_tid);
792 LYDBGLOG("pthread cancel ret = %d",ret);
793 ret = pthread_cancel(lynq_call_list_loop_tid);
794 LYDBGLOG("pthread cancel ret = %d",ret);
795 ret = pthread_join(lynq_call_urc_tid,NULL);
796 LYDBGLOG("pthread join ret = %d",ret);
797 ret = pthread_join(lynq_call_list_loop_tid,NULL);
798 LYDBGLOG("pthread join ret = %d",ret);
799 return 0;
800 }
rita98e2e9c2022-04-07 06:08:13 -0400801}
q.huang714145d2022-04-18 00:09:50 -0400802
803int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400804{
805 Parcel p;
806 lynq_client_t client;
807 int resp_type = -1;
808 int request = -1;
809 int slot_id = -1;
810 int error = -1;
rita089527e2022-04-07 01:55:39 -0400811
812 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400813 client.request = request_id;
814 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400815 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400816 if(argc!=0)
817 {
818 va_list args;
819 va_start(args, format);
820 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
821 va_end(args);
822 }
823 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400824 if(send_request(lynq_call_client_sockfd,&client)==-1)
825 {
826 LYERRLOG("send request fail");
827 return -1;
828 }
q.huang714145d2022-04-18 00:09:50 -0400829 if(get_response(lynq_call_client_sockfd,p)==0)
830 {
831 JumpHeader(p,&resp_type,&request,&slot_id,&error);
832 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
833 }
rita089527e2022-04-07 01:55:39 -0400834 return error;
835}
836
q.huang714145d2022-04-18 00:09:50 -0400837int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400838{
839 Parcel p;
840 lynq_client_t client;
841 int resp_type = -1;
842 int request = -1;
843 int slot_id = -1;
844 int error = -1;
q.huang714145d2022-04-18 00:09:50 -0400845 if(status==NULL)
846 {
847 LYERRLOG("status is null");
848 return -1;
849 }
rita089527e2022-04-07 01:55:39 -0400850 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400851 client.request = request_id;
852 client.paramLen = 0;
rita089527e2022-04-07 01:55:39 -0400853 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400854 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400855 if(send_request(lynq_call_client_sockfd,&client)==-1)
856 {
857 LYERRLOG("send request fail");
858 return -1;
859 }
q.huang714145d2022-04-18 00:09:50 -0400860 if(get_response(lynq_call_client_sockfd,p)==0)
rita089527e2022-04-07 01:55:39 -0400861 {
q.huang714145d2022-04-18 00:09:50 -0400862 JumpHeader(p,&resp_type,&request,&slot_id,&error);
863 p.readInt32(status);
864 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
rita089527e2022-04-07 01:55:39 -0400865 }
rita089527e2022-04-07 01:55:39 -0400866 return error;
867}
868
lh7b0674a2022-01-10 00:34:35 -0800869int lynq_call(int* handle,char addr[])
870{
871 Parcel p;
872 lynq_client_t client;
873 int resp_type = -1;
874 int request = -1;
875 int slot_id = -1;
876 int error = -1;
877 int lynq_call_id = -1;
878 if(addr==NULL)
879 {
880 LYERRLOG("Phone num is null!!!");
881 return -1;
882 }
lh42c1e572022-01-25 18:47:39 -0800883 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800884 client.request = 10;//RIL_REQUEST_DIAL
885 client.paramLen = 2;
886 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
887 memcpy(client.param,addr,strlen(addr)+1);
888 strcat(client.param," 0");
889 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800890 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800891 {
892 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800893 return -1;
894 }
lh42c1e572022-01-25 18:47:39 -0800895 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800896 JumpHeader(p,&resp_type,&request,&slot_id,&error);
897 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
898 lynq_call_id = updateAddr(addr);
899 if(error==0)
900 {
901 isDial = 1;
ll72bf6c12022-03-24 10:22:25 +0800902 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -0800903 {
lhd1e457c2022-04-19 06:01:25 -0700904 //if timeout,this call need destroy.
905 isDial = 0;
906
lh7b0674a2022-01-10 00:34:35 -0800907 error = LYNQ_E_TIME_OUT;
908 LYERRLOG("timeout:wait Call state fail!!!");
909 lynq_call_lists[lynq_call_id].hasTimeout = 1;
910 return error;
911 }
912 *handle = lynq_call_id;
913 }
914 return error;
915}
916int lynq_call_answer()
917{
918 Parcel p;
919 lynq_client_t client;
920 int resp_type = -1;
921 int request = -1;
922 int slot_id = -1;
923 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800924 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800925 client.request = 40;//RIL_REQUEST_DIAL
926 client.paramLen = 0;
927 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
928 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800929 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800930 {
931 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800932 return -1;
933 }
lh42c1e572022-01-25 18:47:39 -0800934 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800935 JumpHeader(p,&resp_type,&request,&slot_id,&error);
936 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
937 return error;
938}
939int lynq_call_hungup(int* handle)
940{
941 Parcel p;
942 lynq_client_t client;
943 int resp_type = -1;
944 int request = -1;
945 int slot_id = -1;
946 int error = -1;
947 int call_id = 0;
948 int lynq_call_id = 0;
lh42c1e572022-01-25 18:47:39 -0800949 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
950 {
951 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
952 return LYNQ_E_CONFLICT;
953 }
954 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800955 client.request = 12;//RIL_REQUEST_HUNGUP
956 client.paramLen = 1;
957 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
958 lynq_call_id = *handle;
959 call_id = lynq_call_lists[lynq_call_id].call_id;
960 sprintf(client.param,"%d",call_id);
961 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800962 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800963 {
964 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800965 return -1;
966 }
lh42c1e572022-01-25 18:47:39 -0800967 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800968 JumpHeader(p,&resp_type,&request,&slot_id,&error);
969 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
970 if(error==0)
971 {
972 cleanCallList(lynq_call_id);
973 }
974 return error;
975}
976int lynq_call_hungup_all()
977{
978 Parcel p;
979 lynq_client_t client;
980 int resp_type = -1;
981 int request = -1;
982 int slot_id = -1;
983 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800984 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800985 client.request = 17;//RIL_REQUEST_UDUB
986 client.paramLen = 0;
987 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
988 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800989 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800990 {
991 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800992 return -1;
993 }
lh42c1e572022-01-25 18:47:39 -0800994 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800995 JumpHeader(p,&resp_type,&request,&slot_id,&error);
996 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
997 return error;
998}
999int lynq_wait_incoming_call(int *handle)
1000{
1001 waitIncomingCall();
1002 *handle = lynqIncomingCallId;
1003 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
1004 return 0;
1005}
1006
1007int lynq_set_auto_answercall(const int mode)
1008{
1009 global_call_auto_answer = mode;
1010 LYINFLOG("auto answer call mode =%d",mode);
1011 return 0;
1012}
q.huangec88da92022-03-29 04:17:32 -04001013int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1014{
1015 int lynq_call_id = 0;
1016 if(handle==NULL)
1017 {
1018 return LYNQ_E_NULL_ANONALY;
1019 }
1020 lynq_call_id = *handle;
1021 *call_state = lynq_call_lists[lynq_call_id].call_state;
1022 *toa = lynq_call_lists[lynq_call_id].toa;
1023 *direction = lynq_call_lists[lynq_call_id].direction;
1024 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
1025 return 0;
1026}
1027
1028/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001029static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001030 switch(enable){
1031 case 0:
1032 return 1;
1033 case 1:
1034 return 1;
1035 default:
1036 return 0;
lldc99c9b2022-01-24 12:16:22 +00001037 }
1038}
1039
lh7b0674a2022-01-10 00:34:35 -08001040int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001041{
1042 if(!judge_mic(enable)){
1043 return LYNQ_E_CONFLICT;
1044 }
q.huangec88da92022-03-29 04:17:32 -04001045 return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1046}
1047int lynq_get_mute_mic(int *status)
1048{
1049 return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
lh7b0674a2022-01-10 00:34:35 -08001050}
ll72bf6c12022-03-24 10:22:25 +08001051
1052/**
1053 * @brief Check whether DTMF is valid
1054 *
1055 * @param callnum dtmf eg:0-9 * #
1056 * @return int
1057 */
1058static int judge_dtmf(const char callnum)
1059{
1060 if(callnum == '#')
1061 {
1062 return 1;
1063 }
1064 if(callnum == '*')
1065 {
1066 return 1;
1067 }
1068 if(callnum >= '0'&& callnum <= '9')
1069 {
1070 return 1;
1071 }
1072 return 0;
1073}
1074
lh7b0674a2022-01-10 00:34:35 -08001075int lynq_set_DTMF(const char callnum)
1076{
ll72bf6c12022-03-24 10:22:25 +08001077 if(!judge_dtmf(callnum))
1078 {
1079 return LYNQ_E_CONFLICT;
1080 }
lh7b0674a2022-01-10 00:34:35 -08001081 if(!lynq_call_state)
1082 {
1083 LYERRLOG("LYNQ_E_CONFLICT");
1084 return LYNQ_E_CONFLICT;
1085 }
q.huangec88da92022-03-29 04:17:32 -04001086 return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
lh7b0674a2022-01-10 00:34:35 -08001087}
q.huangec88da92022-03-29 04:17:32 -04001088static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1089 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1090 if(volume < 0 ||volume >36){
1091 return 0;
1092 }
1093 }
1094 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1095 {
1096 if(volume < 1 ||volume >7){
1097 return 0;
1098 }
lldc99c9b2022-01-24 12:16:22 +00001099 }
ll04ae4142022-01-27 05:54:38 +00001100 return 1;
lldc99c9b2022-01-24 12:16:22 +00001101}
lh7b0674a2022-01-10 00:34:35 -08001102int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001103{
q.huangec88da92022-03-29 04:17:32 -04001104 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
lldc99c9b2022-01-24 12:16:22 +00001105 return LYNQ_E_CONFLICT;
1106 }
q.huangec88da92022-03-29 04:17:32 -04001107 return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
lh7b0674a2022-01-10 00:34:35 -08001108}
q.huangb212fde2022-04-05 23:11:02 -04001109int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001110{
q.huangec88da92022-03-29 04:17:32 -04001111 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
lh7b0674a2022-01-10 00:34:35 -08001112 {
q.huangec88da92022-03-29 04:17:32 -04001113 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001114 }
q.huangec88da92022-03-29 04:17:32 -04001115 return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
lh7b0674a2022-01-10 00:34:35 -08001116}
q.huangec88da92022-03-29 04:17:32 -04001117int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1118{
1119 return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
1120}
q.huangb212fde2022-04-05 23:11:02 -04001121int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001122{
q.huangb212fde2022-04-05 23:11:02 -04001123 return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
q.huangec88da92022-03-29 04:17:32 -04001124}
1125int lynq_incall_record_stop()
1126{
q.huangb212fde2022-04-05 23:11:02 -04001127 const char* unused_file="just_ocuupy_paramter_postion";
1128 return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
q.huangec88da92022-03-29 04:17:32 -04001129}
1130/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001131
1132#ifdef ECALL_SUPPORT
1133LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
1134{
1135 switch(type)
1136 {
1137 case LYNQ_ECALL_TYPE_TEST:
1138 return LYNQ_ECALL_TEST;
1139 case LYNQ_ECALL_TYPE_RECONFIG:
1140 return LYNQ_ECALL_RECONFIG;
1141 default:
1142 return LYNQ_ECALL_EMERGENCY;
1143 }
1144}
1145
1146RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
1147{
1148 switch(type)
1149 {
1150 case LYNQ_ECALL_TEST:
1151 return ECALL_TEST;
1152 case LYNQ_ECALL_RECONFIG:
1153 return ECALL_RECONFIG;
1154 default:
1155 return ECALL_EMERGENCY;
1156 }
1157}
1158
1159RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
1160{
1161 switch(cat)
1162 {
1163 case LYNQ_EMER_CAT_MANUAL_ECALL:
1164 return EMER_CAT_MANUAL_ECALL;
1165 default:
1166 return EMER_CAT_AUTO_ECALL;
1167 }
1168}
1169
1170
1171int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
1172{
1173 int error;
1174
1175 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
1176 {
1177 LYERRLOG("test_num is null or test_num_length %d s greater than %d\n ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
1178 return -1;
1179 }
1180
1181 error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
1182
1183 if(error==0)
1184 {
1185 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
1186 }
1187
1188 return error;
1189}
1190
1191
1192int lynq_fast_ecall(int* handle, LYNQ_ECall_Category lynq_ecall_cat, LYNQ_ECall_Variant lynq_ecall_variant, const char *addr, int addr_length, const char *msd_data, int msd_length)
1193{
1194 int error = -1;
1195 int lynq_call_id = -1;
1196 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
q.huang52473032022-04-19 05:20:12 -04001197 RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
q.huang714145d2022-04-18 00:09:50 -04001198
q.huang8b33ed52022-04-19 20:27:44 -04001199 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1200
1201 LYINFLOG("e_call_addr is %s\n",e_call_addr[lynq_ecall_variant]);
1202
q.huang714145d2022-04-18 00:09:50 -04001203 error=lynq_set_common_request(RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", msd_data);
1204
1205 if(error==0)
q.huang8b33ed52022-04-19 20:27:44 -04001206 {
q.huang714145d2022-04-18 00:09:50 -04001207 isDial = 1;
q.huang8b33ed52022-04-19 20:27:44 -04001208 if(waitCallstateChange(30000)==ETIMEDOUT)//30000ms
q.huang714145d2022-04-18 00:09:50 -04001209 {
q.huang8b33ed52022-04-19 20:27:44 -04001210 isDial = 0;
q.huang714145d2022-04-18 00:09:50 -04001211 error = LYNQ_E_TIME_OUT;
q.huang8b33ed52022-04-19 20:27:44 -04001212 cleanCallList(lynq_call_id);
1213 LYERRLOG("timeout:wait Call state fail!!!");
q.huang714145d2022-04-18 00:09:50 -04001214 return error;
1215 }
q.huang8b33ed52022-04-19 20:27:44 -04001216
q.huang714145d2022-04-18 00:09:50 -04001217 *handle = lynq_call_id;
q.huang8b33ed52022-04-19 20:27:44 -04001218 if(lynq_ecall_variant==LYNQ_ECALL_EMERGENCY){
1219 lynq_call_lists[lynq_call_id].call_id=lynqEcallId;
1220 }
1221 LYINFLOG("lynq_fast_ecall handle is:%d, call id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
1222
1223 }
1224 else {
1225 cleanCallList(lynq_call_id);
q.huang714145d2022-04-18 00:09:50 -04001226 }
1227
1228 return error;
1229}
1230
1231int lynq_set_psap(int enable)
1232{
1233 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
1234}
1235
1236int lynq_psap_pull_msd()
1237{
1238 return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
1239}
1240
1241int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
1242{
1243 LYNQ_ECall_Variant lynq_ecall_variant;
1244 int error = -1;
1245 int lynq_call_id = -1;
1246
1247 if(handle==NULL)
1248 {
1249 LYERRLOG("handle is NULL, parameter error \n ");
1250 return -1;
1251 }
1252
1253 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
1254
1255 if(error==0)
1256 {
1257 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
1258
1259 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1260 isDial = 1;
1261 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1262 {
1263 error = LYNQ_E_TIME_OUT;
1264 LYERRLOG("timeout:wait Call state fail!!!");
1265 lynq_call_lists[lynq_call_id].hasTimeout = 1;
1266 return error;
1267 }
1268
1269 *handle = lynq_call_id;
1270 }
1271
1272 return error;
1273}
1274
1275
1276int lynq_set_msd(int* handle, const char *msd_data, int msd_length)
1277{
1278 if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX))
1279 {
1280 LYERRLOG("handle is NULL or *handle %d is greater or equeal to %d, parameter error\n",*handle,LYNQ_CALL_MAX);
1281 return -1;
1282 }
1283
1284 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,msd_data);
1285}
1286
1287int lynq_set_ivs(int enable)
1288{
1289 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
1290}
1291
1292int lynq_reset_ivs()
1293{
1294 return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
1295}
1296
1297int lynq_ivs_push_msd()
1298{
1299 return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
1300}
q.huang8b33ed52022-04-19 20:27:44 -04001301
1302int wait_ecall_event()
1303{
1304 int ret = 0;
1305 pthread_mutex_lock(&s_incoming_e_call_mutex);
1306 ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
1307 pthread_mutex_unlock(&s_incoming_e_call_mutex);
1308 return ret;
1309}
1310
1311int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)
1312{
1313 wait_ecall_event();
1314 *eCall_Indication = lynqIncomingEcallIndication;
1315 LYINFLOG("lynq incoming e-call indication id:%d",lynqIncomingEcallIndication);
1316 return 0;
1317}
1318
q.huang714145d2022-04-18 00:09:50 -04001319#endif
1320
lh7b0674a2022-01-10 00:34:35 -08001321#if 0
1322int main(int argc,char **argv)
1323{
1324 int n = 0;
1325 n = lynq_init_call(lynq_call_state_change_test,2222);
1326 if(n<0)
1327 {
llbc035332022-04-11 05:49:51 +00001328 LYDBGLOG("lynq init call fail!!!\n");
lh7b0674a2022-01-10 00:34:35 -08001329 return -1;
1330 }
llbc035332022-04-11 05:49:51 +00001331 LYDBGLOG("lynq call init success!!!\n");
lh7b0674a2022-01-10 00:34:35 -08001332 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1333 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1334 lynq_call(phoneNum);
1335 while(1)
1336 {
1337 sleep(1);
1338 }
1339 return 0;
1340}
1341#endif
1342/*Warren add for T800 platform 2021/11/19 end*/