blob: fc6a9daac67a1987e6b38b3ecbdff12293b32848 [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 */
37 LYNQ_CALL_WAITING = 5 ,/* MT call only */
38}lynq_call_state_t;
39
40typedef struct{
41 int uToken;
42 int request;
43 int paramLen;
44 char param[LYNQ_REQUEST_PARAM_BUF];
45}lynq_client_t;
46typedef struct
47{
48 int used;
49 int call_id;
50 int call_state;
51 int toa;
52 int direction;/*0: MO call,1:MT call*/
53 char addr[LYNQ_PHONE_NUMBER_MAX];
54 int hasTimeout;
55}lynq_call_list_e_t;
56typedef struct
57{
58 int call_id;
59 int call_state;
60 int toa;
61 int direction;/*0: MO call,1:MT call*/
62 char addr[LYNQ_PHONE_NUMBER_MAX];
63}lynq_call_list_t;
64
65lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
66static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
67static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
ll04ae4142022-01-27 05:54:38 +000068static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
lh7b0674a2022-01-10 00:34:35 -080069static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
70static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
71static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
lla8c25a82022-03-17 05:31:33 +000072pthread_t lynq_call_urc_tid = -1;
73pthread_t lynq_call_list_loop_tid = -1;
lhec17b0a2022-02-13 23:56:05 -080074
rjw5d2a50e2022-02-28 15:01:49 +080075/*lei add*/
76/* socket文件描述符 */
77int len_addr_serv;
78struct sockaddr_in addr_serv;
79lynq_client_t client_t;
80int client_size = 0;
81/*lei add*/
lh7b0674a2022-01-10 00:34:35 -080082
lh42c1e572022-01-25 18:47:39 -080083int s_call_urc_event_complete = 1;
lh7b0674a2022-01-10 00:34:35 -080084
85enum{
86 CALL_OFF=0,
87 CALL_ON=1
88}call_state;
ll04ae4142022-01-27 05:54:38 +000089typedef enum{
90 LYNQ_E_CARDSTATE_ERROR=8000,
91 /* The voice service state is out of service*/
92 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
93 /* The voice service state is EMERGENCY_ONLY*/
94 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
95 /* The radio power is power off*/
96 LYNQ_E_STATE_POWER_OFF=8003,
97 LYNQ_E_TIME_OUT=8004,
98 /*create or open sms DB fail */
99 LYNQ_E_SMS_DB_FAIL=8005,
100 /*Failed to execute sql statement*/
101 LYNQ_E_SMS_SQL_FAIL = 8006,
102 LYNQ_E_SMS_NOT_FIND = 8007,
103 /* The logic conflict*/
104 LYNQ_E_CONFLICT=9000,
105 /*Null anomaly*/
106 LYNQ_E_NULL_ANONALY=9001
lh7b0674a2022-01-10 00:34:35 -0800107}LYNQ_E;
q.huangec88da92022-03-29 04:17:32 -0400108typedef enum{
109 LYNQ_E_VOLUMN_SET_DTMF,
110 LYNQ_E_VOLUMN_SET_SPEECH
111}LYNQ_E_VOLUMN_SET;
lh7b0674a2022-01-10 00:34:35 -0800112
113int lynq_call_state =CALL_OFF;
lh42c1e572022-01-25 18:47:39 -0800114int lynq_call_client_sockfd = 0;
115int Global_uToken_call = 0;
lh7b0674a2022-01-10 00:34:35 -0800116int global_call_count =0;
117int global_call_auto_answer = 0;
lh42c1e572022-01-25 18:47:39 -0800118bool urc_call_recive_status = 1;
lh7b0674a2022-01-10 00:34:35 -0800119bool call_list_loop = 1;
120int isDial = 0;
121int lynqIncomingCallId = 0;
q.huang714145d2022-04-18 00:09:50 -0400122/*E-CALL begin*/
123typedef enum{
124 LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
125 LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
126 LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
127 LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */\
128}LYNQ_ECall_Type;
129
130char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"","112","112"};
131/*E-CALL end*/
132
lla8c25a82022-03-17 05:31:33 +0000133/**
134 * @brief mark call initialization state
135 * 0: deinit state
136 * 1: init state
137 */
138int g_lynq_call_init_flag = 0;
lh7b0674a2022-01-10 00:34:35 -0800139
140int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
141{
142 if(p.dataAvail() > 0)
143 {
144 p.readInt32(resp_type);
145 p.readInt32(request);
146 p.readInt32(slot_id);
147 p.readInt32(error);
148 return 0;
149 }
150 else
151 {
152 return -1;
153 }
154}
155int send_request(int sockfd,lynq_client_t *client_tmp)
156{
157 int ret=0;
rjw5d2a50e2022-02-28 15:01:49 +0800158 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800159 if(ret==-1)
160 {
ll3fe03462022-03-01 09:18:53 +0000161 LYERRLOG("sendto error\n");
lh7b0674a2022-01-10 00:34:35 -0800162 return -1;
163 }
164 return 0;
165}
166
167int get_response(int sockfd,Parcel &p)
168{
169 int len = 0;
170 char recvline[LYNQ_REC_BUF];
171 bzero(recvline,LYNQ_REC_BUF);
172 /* receive data from server */
rjw5d2a50e2022-02-28 15:01:49 +0800173 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800174 if(len == -1)
175 {
ll3fe03462022-03-01 09:18:53 +0000176 LYERRLOG("recvfrom error\n");
lh7b0674a2022-01-10 00:34:35 -0800177 return -1;
178 }
lh7b0674a2022-01-10 00:34:35 -0800179 if (recvline != NULL) {
180 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
181 p.setDataPosition(0);
182 }
183 return 0;
184}
185static char *strdupReadString(Parcel &p) {
ll04ae4142022-01-27 05:54:38 +0000186 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800187 const char16_t *s16;
188 s16 = p.readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000189 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800190}
191
192int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
193{
194 Parcel p;
195 lynq_client_t client;
196 int resp_type = -1;
197 int request = -1;
198 int slot_id = -1;
199 int error = -1;
200 int call_num = 0;
201 int temp = 0;
202 char *remote_phoneNum = NULL;
203 char *remote_name= NULL;
204 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800205 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800206 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
207 client.paramLen = 0;
208 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
209 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800210 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800211 {
212 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800213 return -1;
214 }
lh42c1e572022-01-25 18:47:39 -0800215 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800216 JumpHeader(p,&resp_type,&request,&slot_id,&error);
217 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
218 if(error == 0)
219 {
220 p.readInt32(&call_num);
221 global_call_count = call_num;
222 if(call_num<=0)
223 {
224 lynq_call_state = CALL_OFF;
lhec17b0a2022-02-13 23:56:05 -0800225 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800226 return 0;
227 }
lhec17b0a2022-02-13 23:56:05 -0800228 lynq_call_state = CALL_ON;
229 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800230 for(int i = 0;i < call_num;i++)
231 {
232 p.readInt32(&temp);
233 call_list[i].call_state = temp;
234 p.readInt32(&call_list[i].call_id);
235 p.readInt32(&call_list[i].toa);
236 p.readInt32(&temp);
237 p.readInt32(&temp);
238 call_list[i].direction = temp;
239 p.readInt32(&temp);
240 p.readInt32(&temp);
241 p.readInt32(&temp);
242 remote_phoneNum = strdupReadString(p);
243 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
244 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
245 call_list[i].direction,call_list[i].addr,call_list[i].toa);
246 p.readInt32(&temp);
247 remote_name = strdupReadString(p);
248 p.readInt32(&temp);
249 p.readInt32(&temp);
250 if(temp==0)
251 {
252 continue;
253 }
254 p.readInt32(&temp); /* UUS Information is present */
255 p.readInt32(&temp);
256 p.readInt32(&temp);
257 p.read(uusData,temp);
258 }
259 }
260 return 0;
261}
262
263void cleanCallList(int lynq_call_id)
264{
265 lynq_call_lists[lynq_call_id].call_id = 0;
266 lynq_call_lists[lynq_call_id].call_state = 0;
267 lynq_call_lists[lynq_call_id].toa = 0;
268 lynq_call_lists[lynq_call_id].direction = 0;
269 lynq_call_lists[lynq_call_id].used = 0;
270 lynq_call_lists[lynq_call_id].hasTimeout = 0;
271 memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
272}
273int getUnusedElement()
274{
275 for(int i=0;i < LYNQ_CALL_MAX; i++)
276 {
277 if(lynq_call_lists[i].used!=1)
278 {
279 return i;
280 }
281 }
282 return -1;
283}
284int updateAddr(char addr[])
285{
286 int ret = 0;
287 ret = getUnusedElement();
288 memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
289 lynq_call_lists[ret].used = 1;
290 return ret;
291}
292void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
293{
lhd1e457c2022-04-19 06:01:25 -0700294 LYINFLOG("Update Call List");
lh7b0674a2022-01-10 00:34:35 -0800295 callList->call_id = call_id;
296 callList->call_state = call_state;
297 callList->toa = toa;
298 callList->direction = direction;
299 callList->used = 1;
300 callList->hasTimeout = 0;
301 return;
302}
303int waitCallstateChange(int mtime)
304{
lhd1e457c2022-04-19 06:01:25 -0700305 LYINFLOG("wait Call state Change");
lh7b0674a2022-01-10 00:34:35 -0800306 int ret = 0;
307 int sec = 0;
308 int usec = 0;
lh2afc7732022-01-10 02:24:31 -0800309 struct timeval now;
310 struct timespec timeout;
311 gettimeofday(&now,NULL);
lh7b0674a2022-01-10 00:34:35 -0800312 sec = mtime/1000;
313 usec = mtime%1000;
lh2afc7732022-01-10 02:24:31 -0800314 timeout.tv_sec = now.tv_sec+sec;
315 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh7b0674a2022-01-10 00:34:35 -0800316 pthread_mutex_lock(&call_state_change_mutex);
lh2afc7732022-01-10 02:24:31 -0800317 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh7b0674a2022-01-10 00:34:35 -0800318 pthread_mutex_unlock(&call_state_change_mutex);
319 return ret;
320}
321int waitIncomingCall()
322{
lhd1e457c2022-04-19 06:01:25 -0700323 LYINFLOG("wait incming call");
lh7b0674a2022-01-10 00:34:35 -0800324 int ret = 0;
325 pthread_mutex_lock(&s_incoming_call_mutex);
326 ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
327 pthread_mutex_unlock(&s_incoming_call_mutex);
328 return ret;
329}
330int checkHasCall(char addr[])
331{
lhd1e457c2022-04-19 06:01:25 -0700332 LYINFLOG("check has call");
lh7b0674a2022-01-10 00:34:35 -0800333 for(int i = 0;i<LYNQ_CALL_MAX;i++)
334 {
335 if(strcmp(lynq_call_lists[i].addr,addr)==0)
336 {
337 return 1;
338 }
339 }
340 return 0;
341}
lhd1e457c2022-04-19 06:01:25 -0700342int find_call_id_with_addr(char *addr)
343{
344 LYINFLOG("find call id with addr!!!");
345 for(int id = 0; id < LYNQ_CALL_MAX; id++)
346 {
347 if(strcmp(lynq_call_lists[id].addr,addr) == 0)
348 {
349 return id;
350 }
351 }
352 return -1;
353}
lh7b0674a2022-01-10 00:34:35 -0800354void sendSignalToWaitCallStateChange()
355{
lhd1e457c2022-04-19 06:01:25 -0700356 LYINFLOG("send Signal To Wait Call State Change");
lh7b0674a2022-01-10 00:34:35 -0800357 pthread_mutex_lock(&call_state_change_mutex);
358 pthread_cond_signal(&call_state_change_cond);
359 pthread_mutex_unlock(&call_state_change_mutex);
360}
361void sendSignalIncomingCall()
362{
lhd1e457c2022-04-19 06:01:25 -0700363 LYINFLOG("send incoming call signal");
lh7b0674a2022-01-10 00:34:35 -0800364 pthread_mutex_lock(&s_incoming_call_mutex);
365 pthread_cond_signal(&s_incoming_call_cond);
366 pthread_mutex_unlock(&s_incoming_call_mutex);
367}
368
369void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
370{
371 callList->call_id = call_id;
372 callList->call_state = call_state;
373 callList->toa = toa;
374 callList->direction = direction;
375 memcpy(callList->addr,addr,strlen(addr)+1);
376 callList->used = 1;
377 callList->hasTimeout = 0;
378 return;
379}
380
381void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000382{
383 int ret=0;
lhd1e457c2022-04-19 06:01:25 -0700384 bool call_end;
385 call_end = 0;//0:this call end,1:call on
ll04ae4142022-01-27 05:54:38 +0000386 lynq_call_list_t call_list[LYNQ_CALL_MAX];
lh7b0674a2022-01-10 00:34:35 -0800387 while(call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000388 {
389 pthread_mutex_lock(&s_urc_call_state_change_mutex);
390 pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800391 LYDBGLOG("triggerGetCallList event!!!\n");
ll04ae4142022-01-27 05:54:38 +0000392 memset(call_list,0,sizeof(call_list));
393 ret = lynq_get_current_call_list(call_list);
394 if(ret != 0)
395 {
llbc035332022-04-11 05:49:51 +0000396 LYDBGLOG("get current call list failure!!!\n");
397 continue;
ll04ae4142022-01-27 05:54:38 +0000398 }
lhd1e457c2022-04-19 06:01:25 -0700399 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
lh7b0674a2022-01-10 00:34:35 -0800400 for(int i = 0;i < LYNQ_CALL_MAX;i++)
401 {
lhd1e457c2022-04-19 06:01:25 -0700402 if(strlen(lynq_call_lists[i].addr) != 0)
403 {
404 call_end = 0;
405 for(int id = 0; id < LYNQ_CALL_MAX; id++)
406 {
407 if(strcmp(call_list[id].addr,lynq_call_lists[i].addr) == 0)
408 {
409 call_end = 1;
410 LYINFLOG("find lynq call i %d, id %d!!!",i,id);
411 }
412 }
413 if(call_end == 0)
414 {
415 LYINFLOG("MT hungup,then clean call info");
416 cleanCallList(i);
417 continue;
418 }
419 } //fix bug API-54
lh7b0674a2022-01-10 00:34:35 -0800420 if(call_list[i].direction == 1)//MT call
421 {
422 if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
423 {
ll72bf6c12022-03-24 10:22:25 +0800424 /*you call me, and i call you,One party failed to dial*/
lh7b0674a2022-01-10 00:34:35 -0800425 if(!checkHasCall(call_list[i].addr))
426 {
427 lynqIncomingCallId = getUnusedElement();
428 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);
429 sendSignalIncomingCall();
430 }
lhd1e457c2022-04-19 06:01:25 -0700431 else
432 {
433 int temp_call_id = find_call_id_with_addr(call_list[i].addr);
434 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
435 **an incoming call until the status changes.
436 **fix bug API-54
437 */
438 if((temp_call_id > 0) && (lynq_call_lists[temp_call_id].call_state == call_list[i].call_state))
439 {
440 sendSignalIncomingCall();
441 }
442 }
lh7b0674a2022-01-10 00:34:35 -0800443 }
ll72bf6c12022-03-24 10:22:25 +0800444 /*if state changed*/
445 else
446 {
447 /*update call state*/
448 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
449 {
450 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
451 {
452 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 +0000453 break;
ll72bf6c12022-03-24 10:22:25 +0800454 }
455 }
456 }
lh7b0674a2022-01-10 00:34:35 -0800457 }
458 else
459 {
460 if(call_list[i].call_id==0)
461 {
462 break;
463 }
464 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
465 {
lhd1e457c2022-04-19 06:01:25 -0700466 if((lynq_call_lists[n].hasTimeout == 1) && (strcmp(lynq_call_lists[n].addr,call_list[i].addr) == 0))
lh7b0674a2022-01-10 00:34:35 -0800467 {
lhd1e457c2022-04-19 06:01:25 -0700468 cleanCallList(n);//if this call time out,need clean lynq call list.
469 /*hangup call with call id*/
470 lynq_call_hungup(&call_list[i].call_id);
lh7b0674a2022-01-10 00:34:35 -0800471 lynq_call_lists[n].hasTimeout==0;
472 continue;
473 }
474 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
475 {
476 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
477 }
478 }
479 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,
480 call_list[i].direction,call_list[i].addr,call_list[i].toa);
481 }
ll04ae4142022-01-27 05:54:38 +0000482 }
lh42c1e572022-01-25 18:47:39 -0800483 s_call_urc_event_complete = 1;
lh7b0674a2022-01-10 00:34:35 -0800484 if(isDial==1)
485 {
486 sendSignalToWaitCallStateChange();
487 isDial = 0;
488 }
ll04ae4142022-01-27 05:54:38 +0000489 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
490 }
491 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800492}
493
494void lynqRespWatingEvent()
ll04ae4142022-01-27 05:54:38 +0000495{
496 if(s_call_urc_event_complete==1)
497 {
498 pthread_mutex_lock(&s_urc_call_state_change_mutex);
499 pthread_cond_signal(&s_urc_call_state_change_cond);
500 s_call_urc_event_complete = 0;
501 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800502 }
ll04ae4142022-01-27 05:54:38 +0000503 return;
lh7b0674a2022-01-10 00:34:35 -0800504}
505
506/*Warren add for T800 platform 2021/11/19 start*/
507int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800508{
509 #if 0
lh7b0674a2022-01-10 00:34:35 -0800510 struct sockaddr_in lynq_socket_server_addr;
511 /* init lynq_socket_server_addr */
512 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
513 lynq_socket_server_addr.sin_family = AF_INET;
514 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
515 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800516
lh7b0674a2022-01-10 00:34:35 -0800517 /*
518 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
519 {
llbc035332022-04-11 05:49:51 +0000520 LYDBGLOG("[%s] is not a valid IPaddress\n", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800521 exit(1);
522 }
523*/
lh42c1e572022-01-25 18:47:39 -0800524 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
525 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800526 {
ll3fe03462022-03-01 09:18:53 +0000527 LYERRLOG("connect error\n");
lh7b0674a2022-01-10 00:34:35 -0800528 return -1;
529 }
rjw5d2a50e2022-02-28 15:01:49 +0800530 #endif
531 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
532 if (-1 == lynq_call_client_sockfd)
533 {
534 return lynq_call_client_sockfd;
535 }
536 /* 设置address */
537 memset(&addr_serv, 0, sizeof(addr_serv));
538 addr_serv.sin_family = AF_INET;
539 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
540 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
541 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800542 return 0;
543}
544int lynq_update_call_list_loop()
545{
546 int ret = 0;
lh7b0674a2022-01-10 00:34:35 -0800547 pthread_attr_t attr;
548 pthread_attr_init(&attr);
549 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800550 ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
lh7b0674a2022-01-10 00:34:35 -0800551 if(ret < 0)
552 {
553 LYERRLOG("lynq_update_call_list_loop fail!!!");
554 return -1;
555 }
556 LYDBGLOG("lynq_update_call_list_loop success!!!\n");
557 return 0;
558
559}
560void *thread_urc_recv(void *parg)
ll04ae4142022-01-27 05:54:38 +0000561{
lh7b0674a2022-01-10 00:34:35 -0800562 int socket_fd = (int64_t)parg;
563 int len=0;
564 socklen_t addr_len=0;
565 uint8_t *dataLength = NULL;
566 char urc_data[LYNQ_REC_BUF];
567 int slot_id = -1;
568 int resp_type = -1;
569 int urcid = -1;
570 Parcel *p = NULL;
571 struct sockaddr_in dest_addr;
572 LYINFLOG("thread_urc_recv in running....\n");
lh42c1e572022-01-25 18:47:39 -0800573 while(urc_call_recive_status)
lh7b0674a2022-01-10 00:34:35 -0800574 {
575 bzero(urc_data,LYNQ_REC_BUF);
576 //get data msg
577 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
578 if(len <= 0)
ll04ae4142022-01-27 05:54:38 +0000579 {
ll3fe03462022-03-01 09:18:53 +0000580 LYERRLOG("thread_urc_recv step2 fail\n");
ll04ae4142022-01-27 05:54:38 +0000581 break;
lh7b0674a2022-01-10 00:34:35 -0800582 }
583 LYDBGLOG("=====>urc data len<=====:%d\n",len);
584 p = new Parcel();
585 if(p==NULL)
586 {
lh21502f52022-01-27 00:27:12 -0800587 LYERRLOG("new parcel failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800588 break;
589 }
590 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
591 p->setDataPosition(0);
592 if(p->dataAvail() > 0)
593 {
594 p->readInt32(&resp_type);
595 p->readInt32(&urcid);
596 p->readInt32(&slot_id);
597 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
598 switch (urcid)
599 {
600 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
601 {
602 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
603 lynqRespWatingEvent();
604 break;
605 }
606 case 1018://RIL_UNSOL_CALL_RING
607 {
608 if(global_call_auto_answer==1)
609 {
610 lynq_call_answer();
611 }
612 break;
613 }
614 case 1029://RIL_UNSOL_RINGBACK_TONE
615 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
616 {
617 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
618 break;
619 }
620 default:
621 break;
622 }
623 }
624 delete p;
625 p = NULL;
626 }
627 close(socket_fd);
628}
629int lynq_socket_urc_start()
630{
631 int socket_fd=0;
632 int rt=0;
633 int len=0;
634 int on=1;
635 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800636 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000637 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000638 if(socket_fd < 0)
639 {
ll3fe03462022-03-01 09:18:53 +0000640 LYERRLOG("creaet socket for udp fail\n");
ll04ae4142022-01-27 05:54:38 +0000641 return -1;
lh7b0674a2022-01-10 00:34:35 -0800642 }
643 urc_local_addr.sin_family = AF_INET;
644 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
645 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
646 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000647 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
648 if(rt<0)
649 {
ll3fe03462022-03-01 09:18:53 +0000650 LYERRLOG("SO_REUSEADDR fail\n");
lh7b0674a2022-01-10 00:34:35 -0800651 return -1;
652 }
653 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000654 if (rt == -1)
655 {
lh21502f52022-01-27 00:27:12 -0800656 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000657 return -1;
lh7b0674a2022-01-10 00:34:35 -0800658 }
659 pthread_attr_init(&attr);
660 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800661 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800662 if(rt < 0)
663 {
lh21502f52022-01-27 00:27:12 -0800664 LYERRLOG("urc loop failure!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800665 return -1;
666 }
lh21502f52022-01-27 00:27:12 -0800667 LYDBGLOG("urc loop success!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800668 return 0;
669}
670int getSelfElement(char addr[])
671{
672 for(int i=0;i < LYNQ_CALL_MAX; i++)
673 {
674 if(lynq_call_lists[i].used==1)
675 {
676 if(strcmp(lynq_call_lists[i].addr,addr)==0)
677 {
678 return i;
679 }
680
681 }
682 }
683 return -1;
684}
685
686void lynq_call_state_change_test(int soc_id)
687{
llbc035332022-04-11 05:49:51 +0000688 LYDBGLOG("call state change,sim:%d\n",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800689}
690int lynq_init_call(int uToken)
lla8c25a82022-03-17 05:31:33 +0000691{
692 if(g_lynq_call_init_flag == 1){
693 LYDBGLOG("lynq init call failed!!!");
694 return -1;
695 }
696 g_lynq_call_init_flag = 1;
lh7b0674a2022-01-10 00:34:35 -0800697 int result = 0;
lh42c1e572022-01-25 18:47:39 -0800698 Global_uToken_call = uToken;
lh21502f52022-01-27 00:27:12 -0800699 urc_call_recive_status = 1;
rjw5d2a50e2022-02-28 15:01:49 +0800700 client_size = sizeof(client_t);
lh7b0674a2022-01-10 00:34:35 -0800701 LYLOGSET(LOG_INFO);
702 LYLOGEINIT(USER_LOG_TAG);
703 result = lynq_socket_client_start();
704 if(result!=0)
705 {
706 return -1;
707 }
708 result = lynq_socket_urc_start();
709 if(result!=0)
710 {
711 return -1;
712 }
713 result = lynq_update_call_list_loop();
714 if(result!=0)
715 {
716 return -1;
717 }
718 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
719 LYDBGLOG("lynq init call success!!!");
720 return 0;
721}
722int lynq_deinit_call()
723{
lla8c25a82022-03-17 05:31:33 +0000724 if(g_lynq_call_init_flag == 0)
lhec17b0a2022-02-13 23:56:05 -0800725 {
lla8c25a82022-03-17 05:31:33 +0000726 LYDBGLOG("lynq_deinit_call failed!!!");
727 return -1;
lhec17b0a2022-02-13 23:56:05 -0800728 }
lla8c25a82022-03-17 05:31:33 +0000729 else
730 {
731 g_lynq_call_init_flag = 0;
732 int ret = -1;
733 if(lynq_call_client_sockfd>0)
734 {
735 close(lynq_call_client_sockfd);
736 }
737 urc_call_recive_status = 0;
738 call_list_loop = 0;
739 if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
740 {
741 return -1;
742 }
743 ret = pthread_cancel(lynq_call_urc_tid);
744 LYDBGLOG("pthread cancel ret = %d",ret);
745 ret = pthread_cancel(lynq_call_list_loop_tid);
746 LYDBGLOG("pthread cancel ret = %d",ret);
747 ret = pthread_join(lynq_call_urc_tid,NULL);
748 LYDBGLOG("pthread join ret = %d",ret);
749 ret = pthread_join(lynq_call_list_loop_tid,NULL);
750 LYDBGLOG("pthread join ret = %d",ret);
751 return 0;
752 }
rita98e2e9c2022-04-07 06:08:13 -0400753}
q.huang714145d2022-04-18 00:09:50 -0400754
755int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400756{
757 Parcel p;
758 lynq_client_t client;
759 int resp_type = -1;
760 int request = -1;
761 int slot_id = -1;
762 int error = -1;
rita089527e2022-04-07 01:55:39 -0400763
764 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400765 client.request = request_id;
766 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400767 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400768 if(argc!=0)
769 {
770 va_list args;
771 va_start(args, format);
772 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
773 va_end(args);
774 }
775 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400776 if(send_request(lynq_call_client_sockfd,&client)==-1)
777 {
778 LYERRLOG("send request fail");
779 return -1;
780 }
q.huang714145d2022-04-18 00:09:50 -0400781 if(get_response(lynq_call_client_sockfd,p)==0)
782 {
783 JumpHeader(p,&resp_type,&request,&slot_id,&error);
784 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
785 }
rita089527e2022-04-07 01:55:39 -0400786 return error;
787}
788
q.huang714145d2022-04-18 00:09:50 -0400789int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400790{
791 Parcel p;
792 lynq_client_t client;
793 int resp_type = -1;
794 int request = -1;
795 int slot_id = -1;
796 int error = -1;
q.huang714145d2022-04-18 00:09:50 -0400797 if(status==NULL)
798 {
799 LYERRLOG("status is null");
800 return -1;
801 }
rita089527e2022-04-07 01:55:39 -0400802 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400803 client.request = request_id;
804 client.paramLen = 0;
rita089527e2022-04-07 01:55:39 -0400805 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400806 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400807 if(send_request(lynq_call_client_sockfd,&client)==-1)
808 {
809 LYERRLOG("send request fail");
810 return -1;
811 }
q.huang714145d2022-04-18 00:09:50 -0400812 if(get_response(lynq_call_client_sockfd,p)==0)
rita089527e2022-04-07 01:55:39 -0400813 {
q.huang714145d2022-04-18 00:09:50 -0400814 JumpHeader(p,&resp_type,&request,&slot_id,&error);
815 p.readInt32(status);
816 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
rita089527e2022-04-07 01:55:39 -0400817 }
rita089527e2022-04-07 01:55:39 -0400818 return error;
819}
820
lh7b0674a2022-01-10 00:34:35 -0800821int lynq_call(int* handle,char addr[])
822{
823 Parcel p;
824 lynq_client_t client;
825 int resp_type = -1;
826 int request = -1;
827 int slot_id = -1;
828 int error = -1;
829 int lynq_call_id = -1;
830 if(addr==NULL)
831 {
832 LYERRLOG("Phone num is null!!!");
833 return -1;
834 }
lh42c1e572022-01-25 18:47:39 -0800835 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800836 client.request = 10;//RIL_REQUEST_DIAL
837 client.paramLen = 2;
838 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
839 memcpy(client.param,addr,strlen(addr)+1);
840 strcat(client.param," 0");
841 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800842 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800843 {
844 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800845 return -1;
846 }
lh42c1e572022-01-25 18:47:39 -0800847 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800848 JumpHeader(p,&resp_type,&request,&slot_id,&error);
849 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
850 lynq_call_id = updateAddr(addr);
851 if(error==0)
852 {
853 isDial = 1;
ll72bf6c12022-03-24 10:22:25 +0800854 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -0800855 {
lhd1e457c2022-04-19 06:01:25 -0700856 //if timeout,this call need destroy.
857 isDial = 0;
858
lh7b0674a2022-01-10 00:34:35 -0800859 error = LYNQ_E_TIME_OUT;
860 LYERRLOG("timeout:wait Call state fail!!!");
861 lynq_call_lists[lynq_call_id].hasTimeout = 1;
862 return error;
863 }
864 *handle = lynq_call_id;
865 }
866 return error;
867}
868int lynq_call_answer()
869{
870 Parcel p;
871 lynq_client_t client;
872 int resp_type = -1;
873 int request = -1;
874 int slot_id = -1;
875 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800876 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800877 client.request = 40;//RIL_REQUEST_DIAL
878 client.paramLen = 0;
879 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
880 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800881 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800882 {
883 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800884 return -1;
885 }
lh42c1e572022-01-25 18:47:39 -0800886 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800887 JumpHeader(p,&resp_type,&request,&slot_id,&error);
888 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
889 return error;
890}
891int lynq_call_hungup(int* handle)
892{
893 Parcel p;
894 lynq_client_t client;
895 int resp_type = -1;
896 int request = -1;
897 int slot_id = -1;
898 int error = -1;
899 int call_id = 0;
900 int lynq_call_id = 0;
lh42c1e572022-01-25 18:47:39 -0800901 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
902 {
903 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
904 return LYNQ_E_CONFLICT;
905 }
906 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800907 client.request = 12;//RIL_REQUEST_HUNGUP
908 client.paramLen = 1;
909 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
910 lynq_call_id = *handle;
911 call_id = lynq_call_lists[lynq_call_id].call_id;
912 sprintf(client.param,"%d",call_id);
913 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800914 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800915 {
916 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800917 return -1;
918 }
lh42c1e572022-01-25 18:47:39 -0800919 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800920 JumpHeader(p,&resp_type,&request,&slot_id,&error);
921 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
922 if(error==0)
923 {
924 cleanCallList(lynq_call_id);
925 }
926 return error;
927}
928int lynq_call_hungup_all()
929{
930 Parcel p;
931 lynq_client_t client;
932 int resp_type = -1;
933 int request = -1;
934 int slot_id = -1;
935 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800936 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800937 client.request = 17;//RIL_REQUEST_UDUB
938 client.paramLen = 0;
939 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
940 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800941 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800942 {
943 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800944 return -1;
945 }
lh42c1e572022-01-25 18:47:39 -0800946 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800947 JumpHeader(p,&resp_type,&request,&slot_id,&error);
948 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
949 return error;
950}
951int lynq_wait_incoming_call(int *handle)
952{
953 waitIncomingCall();
954 *handle = lynqIncomingCallId;
955 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
956 return 0;
957}
958
959int lynq_set_auto_answercall(const int mode)
960{
961 global_call_auto_answer = mode;
962 LYINFLOG("auto answer call mode =%d",mode);
963 return 0;
964}
q.huangec88da92022-03-29 04:17:32 -0400965int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
966{
967 int lynq_call_id = 0;
968 if(handle==NULL)
969 {
970 return LYNQ_E_NULL_ANONALY;
971 }
972 lynq_call_id = *handle;
973 *call_state = lynq_call_lists[lynq_call_id].call_state;
974 *toa = lynq_call_lists[lynq_call_id].toa;
975 *direction = lynq_call_lists[lynq_call_id].direction;
976 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
977 return 0;
978}
979
980/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +0000981static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +0000982 switch(enable){
983 case 0:
984 return 1;
985 case 1:
986 return 1;
987 default:
988 return 0;
lldc99c9b2022-01-24 12:16:22 +0000989 }
990}
991
lh7b0674a2022-01-10 00:34:35 -0800992int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +0000993{
994 if(!judge_mic(enable)){
995 return LYNQ_E_CONFLICT;
996 }
q.huangec88da92022-03-29 04:17:32 -0400997 return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
998}
999int lynq_get_mute_mic(int *status)
1000{
1001 return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
lh7b0674a2022-01-10 00:34:35 -08001002}
ll72bf6c12022-03-24 10:22:25 +08001003
1004/**
1005 * @brief Check whether DTMF is valid
1006 *
1007 * @param callnum dtmf eg:0-9 * #
1008 * @return int
1009 */
1010static int judge_dtmf(const char callnum)
1011{
1012 if(callnum == '#')
1013 {
1014 return 1;
1015 }
1016 if(callnum == '*')
1017 {
1018 return 1;
1019 }
1020 if(callnum >= '0'&& callnum <= '9')
1021 {
1022 return 1;
1023 }
1024 return 0;
1025}
1026
lh7b0674a2022-01-10 00:34:35 -08001027int lynq_set_DTMF(const char callnum)
1028{
ll72bf6c12022-03-24 10:22:25 +08001029 if(!judge_dtmf(callnum))
1030 {
1031 return LYNQ_E_CONFLICT;
1032 }
lh7b0674a2022-01-10 00:34:35 -08001033 if(!lynq_call_state)
1034 {
1035 LYERRLOG("LYNQ_E_CONFLICT");
1036 return LYNQ_E_CONFLICT;
1037 }
q.huangec88da92022-03-29 04:17:32 -04001038 return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
lh7b0674a2022-01-10 00:34:35 -08001039}
q.huangec88da92022-03-29 04:17:32 -04001040static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1041 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1042 if(volume < 0 ||volume >36){
1043 return 0;
1044 }
1045 }
1046 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1047 {
1048 if(volume < 1 ||volume >7){
1049 return 0;
1050 }
lldc99c9b2022-01-24 12:16:22 +00001051 }
ll04ae4142022-01-27 05:54:38 +00001052 return 1;
lldc99c9b2022-01-24 12:16:22 +00001053}
lh7b0674a2022-01-10 00:34:35 -08001054int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001055{
q.huangec88da92022-03-29 04:17:32 -04001056 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
lldc99c9b2022-01-24 12:16:22 +00001057 return LYNQ_E_CONFLICT;
1058 }
q.huangec88da92022-03-29 04:17:32 -04001059 return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
lh7b0674a2022-01-10 00:34:35 -08001060}
q.huangb212fde2022-04-05 23:11:02 -04001061int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001062{
q.huangec88da92022-03-29 04:17:32 -04001063 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
lh7b0674a2022-01-10 00:34:35 -08001064 {
q.huangec88da92022-03-29 04:17:32 -04001065 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001066 }
q.huangec88da92022-03-29 04:17:32 -04001067 return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
lh7b0674a2022-01-10 00:34:35 -08001068}
q.huangec88da92022-03-29 04:17:32 -04001069int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1070{
1071 return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
1072}
q.huangb212fde2022-04-05 23:11:02 -04001073int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001074{
q.huangb212fde2022-04-05 23:11:02 -04001075 return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
q.huangec88da92022-03-29 04:17:32 -04001076}
1077int lynq_incall_record_stop()
1078{
q.huangb212fde2022-04-05 23:11:02 -04001079 const char* unused_file="just_ocuupy_paramter_postion";
1080 return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
q.huangec88da92022-03-29 04:17:32 -04001081}
1082/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001083
1084#ifdef ECALL_SUPPORT
1085LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
1086{
1087 switch(type)
1088 {
1089 case LYNQ_ECALL_TYPE_TEST:
1090 return LYNQ_ECALL_TEST;
1091 case LYNQ_ECALL_TYPE_RECONFIG:
1092 return LYNQ_ECALL_RECONFIG;
1093 default:
1094 return LYNQ_ECALL_EMERGENCY;
1095 }
1096}
1097
1098RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
1099{
1100 switch(type)
1101 {
1102 case LYNQ_ECALL_TEST:
1103 return ECALL_TEST;
1104 case LYNQ_ECALL_RECONFIG:
1105 return ECALL_RECONFIG;
1106 default:
1107 return ECALL_EMERGENCY;
1108 }
1109}
1110
1111RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
1112{
1113 switch(cat)
1114 {
1115 case LYNQ_EMER_CAT_MANUAL_ECALL:
1116 return EMER_CAT_MANUAL_ECALL;
1117 default:
1118 return EMER_CAT_AUTO_ECALL;
1119 }
1120}
1121
1122
1123int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
1124{
1125 int error;
1126
1127 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
1128 {
1129 LYERRLOG("test_num is null or test_num_length %d s greater than %d\n ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
1130 return -1;
1131 }
1132
1133 error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
1134
1135 if(error==0)
1136 {
1137 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
1138 }
1139
1140 return error;
1141}
1142
1143
1144int 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)
1145{
1146 int error = -1;
1147 int lynq_call_id = -1;
1148 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
q.huang52473032022-04-19 05:20:12 -04001149 RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
q.huang714145d2022-04-18 00:09:50 -04001150
1151 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);
1152
1153 if(error==0)
1154 {
1155 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1156 isDial = 1;
1157 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1158 {
1159 error = LYNQ_E_TIME_OUT;
1160 LYERRLOG("timeout:wait Call state fail!!!");
1161 lynq_call_lists[lynq_call_id].hasTimeout = 1;
1162 return error;
1163 }
1164
1165 *handle = lynq_call_id;
1166 }
1167
1168 return error;
1169}
1170
1171int lynq_set_psap(int enable)
1172{
1173 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
1174}
1175
1176int lynq_psap_pull_msd()
1177{
1178 return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
1179}
1180
1181int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
1182{
1183 LYNQ_ECall_Variant lynq_ecall_variant;
1184 int error = -1;
1185 int lynq_call_id = -1;
1186
1187 if(handle==NULL)
1188 {
1189 LYERRLOG("handle is NULL, parameter error \n ");
1190 return -1;
1191 }
1192
1193 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
1194
1195 if(error==0)
1196 {
1197 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
1198
1199 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1200 isDial = 1;
1201 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1202 {
1203 error = LYNQ_E_TIME_OUT;
1204 LYERRLOG("timeout:wait Call state fail!!!");
1205 lynq_call_lists[lynq_call_id].hasTimeout = 1;
1206 return error;
1207 }
1208
1209 *handle = lynq_call_id;
1210 }
1211
1212 return error;
1213}
1214
1215
1216int lynq_set_msd(int* handle, const char *msd_data, int msd_length)
1217{
1218 if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX))
1219 {
1220 LYERRLOG("handle is NULL or *handle %d is greater or equeal to %d, parameter error\n",*handle,LYNQ_CALL_MAX);
1221 return -1;
1222 }
1223
1224 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,msd_data);
1225}
1226
1227int lynq_set_ivs(int enable)
1228{
1229 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
1230}
1231
1232int lynq_reset_ivs()
1233{
1234 return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
1235}
1236
1237int lynq_ivs_push_msd()
1238{
1239 return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
1240}
1241#endif
1242
lh7b0674a2022-01-10 00:34:35 -08001243#if 0
1244int main(int argc,char **argv)
1245{
1246 int n = 0;
1247 n = lynq_init_call(lynq_call_state_change_test,2222);
1248 if(n<0)
1249 {
llbc035332022-04-11 05:49:51 +00001250 LYDBGLOG("lynq init call fail!!!\n");
lh7b0674a2022-01-10 00:34:35 -08001251 return -1;
1252 }
llbc035332022-04-11 05:49:51 +00001253 LYDBGLOG("lynq call init success!!!\n");
lh7b0674a2022-01-10 00:34:35 -08001254 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1255 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1256 lynq_call(phoneNum);
1257 while(1)
1258 {
1259 sleep(1);
1260 }
1261 return 0;
1262}
1263#endif
1264/*Warren add for T800 platform 2021/11/19 end*/