blob: 15d98413775e8c15043ad319a1b1f9a83b08c24e [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{
294 callList->call_id = call_id;
295 callList->call_state = call_state;
296 callList->toa = toa;
297 callList->direction = direction;
298 callList->used = 1;
299 callList->hasTimeout = 0;
300 return;
301}
302int waitCallstateChange(int mtime)
303{
304 int ret = 0;
305 int sec = 0;
306 int usec = 0;
lh2afc7732022-01-10 02:24:31 -0800307 struct timeval now;
308 struct timespec timeout;
309 gettimeofday(&now,NULL);
lh7b0674a2022-01-10 00:34:35 -0800310 sec = mtime/1000;
311 usec = mtime%1000;
lh2afc7732022-01-10 02:24:31 -0800312 timeout.tv_sec = now.tv_sec+sec;
313 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh7b0674a2022-01-10 00:34:35 -0800314 pthread_mutex_lock(&call_state_change_mutex);
lh2afc7732022-01-10 02:24:31 -0800315 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh7b0674a2022-01-10 00:34:35 -0800316 pthread_mutex_unlock(&call_state_change_mutex);
317 return ret;
318}
319int waitIncomingCall()
320{
321 int ret = 0;
322 pthread_mutex_lock(&s_incoming_call_mutex);
323 ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
324 pthread_mutex_unlock(&s_incoming_call_mutex);
325 return ret;
326}
327int checkHasCall(char addr[])
328{
329 for(int i = 0;i<LYNQ_CALL_MAX;i++)
330 {
331 if(strcmp(lynq_call_lists[i].addr,addr)==0)
332 {
333 return 1;
334 }
335 }
336 return 0;
337}
338void sendSignalToWaitCallStateChange()
339{
340 pthread_mutex_lock(&call_state_change_mutex);
341 pthread_cond_signal(&call_state_change_cond);
342 pthread_mutex_unlock(&call_state_change_mutex);
343}
344void sendSignalIncomingCall()
345{
346 pthread_mutex_lock(&s_incoming_call_mutex);
347 pthread_cond_signal(&s_incoming_call_cond);
348 pthread_mutex_unlock(&s_incoming_call_mutex);
349}
350
351void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
352{
353 callList->call_id = call_id;
354 callList->call_state = call_state;
355 callList->toa = toa;
356 callList->direction = direction;
357 memcpy(callList->addr,addr,strlen(addr)+1);
358 callList->used = 1;
359 callList->hasTimeout = 0;
360 return;
361}
362
363void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000364{
365 int ret=0;
366 lynq_call_list_t call_list[LYNQ_CALL_MAX];
lh7b0674a2022-01-10 00:34:35 -0800367 while(call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000368 {
369 pthread_mutex_lock(&s_urc_call_state_change_mutex);
370 pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800371 LYDBGLOG("triggerGetCallList event!!!\n");
ll04ae4142022-01-27 05:54:38 +0000372 memset(call_list,0,sizeof(call_list));
373 ret = lynq_get_current_call_list(call_list);
374 if(ret != 0)
375 {
llbc035332022-04-11 05:49:51 +0000376 LYDBGLOG("get current call list failure!!!\n");
377 continue;
ll04ae4142022-01-27 05:54:38 +0000378 }
lh7b0674a2022-01-10 00:34:35 -0800379 for(int i = 0;i < LYNQ_CALL_MAX;i++)
380 {
381 if(call_list[i].direction == 1)//MT call
382 {
383 if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
384 {
ll72bf6c12022-03-24 10:22:25 +0800385 /*you call me, and i call you,One party failed to dial*/
lh7b0674a2022-01-10 00:34:35 -0800386 if(!checkHasCall(call_list[i].addr))
387 {
388 lynqIncomingCallId = getUnusedElement();
389 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);
390 sendSignalIncomingCall();
391 }
392 }
ll72bf6c12022-03-24 10:22:25 +0800393 /*if state changed*/
394 else
395 {
396 /*update call state*/
397 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
398 {
399 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
400 {
401 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 +0000402 break;
ll72bf6c12022-03-24 10:22:25 +0800403 }
404 }
405 }
lh7b0674a2022-01-10 00:34:35 -0800406 }
407 else
408 {
409 if(call_list[i].call_id==0)
410 {
411 break;
412 }
413 for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
414 {
415 if(lynq_call_lists[n].hasTimeout==1)
416 {
417 /*hangup call with id*/
418 lynq_call_hungup(&n);
419 lynq_call_lists[n].hasTimeout==0;
420 continue;
421 }
422 if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
423 {
424 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
425 }
426 }
427 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,
428 call_list[i].direction,call_list[i].addr,call_list[i].toa);
429 }
ll04ae4142022-01-27 05:54:38 +0000430 }
lh42c1e572022-01-25 18:47:39 -0800431 s_call_urc_event_complete = 1;
lh7b0674a2022-01-10 00:34:35 -0800432 if(isDial==1)
433 {
434 sendSignalToWaitCallStateChange();
435 isDial = 0;
436 }
ll04ae4142022-01-27 05:54:38 +0000437 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
438 }
439 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800440}
441
442void lynqRespWatingEvent()
ll04ae4142022-01-27 05:54:38 +0000443{
444 if(s_call_urc_event_complete==1)
445 {
446 pthread_mutex_lock(&s_urc_call_state_change_mutex);
447 pthread_cond_signal(&s_urc_call_state_change_cond);
448 s_call_urc_event_complete = 0;
449 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800450 }
ll04ae4142022-01-27 05:54:38 +0000451 return;
lh7b0674a2022-01-10 00:34:35 -0800452}
453
454/*Warren add for T800 platform 2021/11/19 start*/
455int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800456{
457 #if 0
lh7b0674a2022-01-10 00:34:35 -0800458 struct sockaddr_in lynq_socket_server_addr;
459 /* init lynq_socket_server_addr */
460 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
461 lynq_socket_server_addr.sin_family = AF_INET;
462 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
463 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800464
lh7b0674a2022-01-10 00:34:35 -0800465 /*
466 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
467 {
llbc035332022-04-11 05:49:51 +0000468 LYDBGLOG("[%s] is not a valid IPaddress\n", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800469 exit(1);
470 }
471*/
lh42c1e572022-01-25 18:47:39 -0800472 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
473 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800474 {
ll3fe03462022-03-01 09:18:53 +0000475 LYERRLOG("connect error\n");
lh7b0674a2022-01-10 00:34:35 -0800476 return -1;
477 }
rjw5d2a50e2022-02-28 15:01:49 +0800478 #endif
479 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
480 if (-1 == lynq_call_client_sockfd)
481 {
482 return lynq_call_client_sockfd;
483 }
484 /* 设置address */
485 memset(&addr_serv, 0, sizeof(addr_serv));
486 addr_serv.sin_family = AF_INET;
487 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
488 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
489 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800490 return 0;
491}
492int lynq_update_call_list_loop()
493{
494 int ret = 0;
lh7b0674a2022-01-10 00:34:35 -0800495 pthread_attr_t attr;
496 pthread_attr_init(&attr);
497 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800498 ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
lh7b0674a2022-01-10 00:34:35 -0800499 if(ret < 0)
500 {
501 LYERRLOG("lynq_update_call_list_loop fail!!!");
502 return -1;
503 }
504 LYDBGLOG("lynq_update_call_list_loop success!!!\n");
505 return 0;
506
507}
508void *thread_urc_recv(void *parg)
ll04ae4142022-01-27 05:54:38 +0000509{
lh7b0674a2022-01-10 00:34:35 -0800510 int socket_fd = (int64_t)parg;
511 int len=0;
512 socklen_t addr_len=0;
513 uint8_t *dataLength = NULL;
514 char urc_data[LYNQ_REC_BUF];
515 int slot_id = -1;
516 int resp_type = -1;
517 int urcid = -1;
518 Parcel *p = NULL;
519 struct sockaddr_in dest_addr;
520 LYINFLOG("thread_urc_recv in running....\n");
lh42c1e572022-01-25 18:47:39 -0800521 while(urc_call_recive_status)
lh7b0674a2022-01-10 00:34:35 -0800522 {
523 bzero(urc_data,LYNQ_REC_BUF);
524 //get data msg
525 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
526 if(len <= 0)
ll04ae4142022-01-27 05:54:38 +0000527 {
ll3fe03462022-03-01 09:18:53 +0000528 LYERRLOG("thread_urc_recv step2 fail\n");
ll04ae4142022-01-27 05:54:38 +0000529 break;
lh7b0674a2022-01-10 00:34:35 -0800530 }
531 LYDBGLOG("=====>urc data len<=====:%d\n",len);
532 p = new Parcel();
533 if(p==NULL)
534 {
lh21502f52022-01-27 00:27:12 -0800535 LYERRLOG("new parcel failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800536 break;
537 }
538 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
539 p->setDataPosition(0);
540 if(p->dataAvail() > 0)
541 {
542 p->readInt32(&resp_type);
543 p->readInt32(&urcid);
544 p->readInt32(&slot_id);
545 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
546 switch (urcid)
547 {
548 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
549 {
550 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
551 lynqRespWatingEvent();
552 break;
553 }
554 case 1018://RIL_UNSOL_CALL_RING
555 {
556 if(global_call_auto_answer==1)
557 {
558 lynq_call_answer();
559 }
560 break;
561 }
562 case 1029://RIL_UNSOL_RINGBACK_TONE
563 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
564 {
565 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
566 break;
567 }
568 default:
569 break;
570 }
571 }
572 delete p;
573 p = NULL;
574 }
575 close(socket_fd);
576}
577int lynq_socket_urc_start()
578{
579 int socket_fd=0;
580 int rt=0;
581 int len=0;
582 int on=1;
583 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800584 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000585 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000586 if(socket_fd < 0)
587 {
ll3fe03462022-03-01 09:18:53 +0000588 LYERRLOG("creaet socket for udp fail\n");
ll04ae4142022-01-27 05:54:38 +0000589 return -1;
lh7b0674a2022-01-10 00:34:35 -0800590 }
591 urc_local_addr.sin_family = AF_INET;
592 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
593 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
594 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000595 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
596 if(rt<0)
597 {
ll3fe03462022-03-01 09:18:53 +0000598 LYERRLOG("SO_REUSEADDR fail\n");
lh7b0674a2022-01-10 00:34:35 -0800599 return -1;
600 }
601 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000602 if (rt == -1)
603 {
lh21502f52022-01-27 00:27:12 -0800604 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000605 return -1;
lh7b0674a2022-01-10 00:34:35 -0800606 }
607 pthread_attr_init(&attr);
608 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800609 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800610 if(rt < 0)
611 {
lh21502f52022-01-27 00:27:12 -0800612 LYERRLOG("urc loop failure!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800613 return -1;
614 }
lh21502f52022-01-27 00:27:12 -0800615 LYDBGLOG("urc loop success!!!\n");
lh7b0674a2022-01-10 00:34:35 -0800616 return 0;
617}
618int getSelfElement(char addr[])
619{
620 for(int i=0;i < LYNQ_CALL_MAX; i++)
621 {
622 if(lynq_call_lists[i].used==1)
623 {
624 if(strcmp(lynq_call_lists[i].addr,addr)==0)
625 {
626 return i;
627 }
628
629 }
630 }
631 return -1;
632}
633
634void lynq_call_state_change_test(int soc_id)
635{
llbc035332022-04-11 05:49:51 +0000636 LYDBGLOG("call state change,sim:%d\n",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800637}
638int lynq_init_call(int uToken)
lla8c25a82022-03-17 05:31:33 +0000639{
640 if(g_lynq_call_init_flag == 1){
641 LYDBGLOG("lynq init call failed!!!");
642 return -1;
643 }
644 g_lynq_call_init_flag = 1;
lh7b0674a2022-01-10 00:34:35 -0800645 int result = 0;
lh42c1e572022-01-25 18:47:39 -0800646 Global_uToken_call = uToken;
lh21502f52022-01-27 00:27:12 -0800647 urc_call_recive_status = 1;
rjw5d2a50e2022-02-28 15:01:49 +0800648 client_size = sizeof(client_t);
lh7b0674a2022-01-10 00:34:35 -0800649 LYLOGSET(LOG_INFO);
650 LYLOGEINIT(USER_LOG_TAG);
651 result = lynq_socket_client_start();
652 if(result!=0)
653 {
654 return -1;
655 }
656 result = lynq_socket_urc_start();
657 if(result!=0)
658 {
659 return -1;
660 }
661 result = lynq_update_call_list_loop();
662 if(result!=0)
663 {
664 return -1;
665 }
666 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
667 LYDBGLOG("lynq init call success!!!");
668 return 0;
669}
670int lynq_deinit_call()
671{
lla8c25a82022-03-17 05:31:33 +0000672 if(g_lynq_call_init_flag == 0)
lhec17b0a2022-02-13 23:56:05 -0800673 {
lla8c25a82022-03-17 05:31:33 +0000674 LYDBGLOG("lynq_deinit_call failed!!!");
675 return -1;
lhec17b0a2022-02-13 23:56:05 -0800676 }
lla8c25a82022-03-17 05:31:33 +0000677 else
678 {
679 g_lynq_call_init_flag = 0;
680 int ret = -1;
681 if(lynq_call_client_sockfd>0)
682 {
683 close(lynq_call_client_sockfd);
684 }
685 urc_call_recive_status = 0;
686 call_list_loop = 0;
687 if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
688 {
689 return -1;
690 }
691 ret = pthread_cancel(lynq_call_urc_tid);
692 LYDBGLOG("pthread cancel ret = %d",ret);
693 ret = pthread_cancel(lynq_call_list_loop_tid);
694 LYDBGLOG("pthread cancel ret = %d",ret);
695 ret = pthread_join(lynq_call_urc_tid,NULL);
696 LYDBGLOG("pthread join ret = %d",ret);
697 ret = pthread_join(lynq_call_list_loop_tid,NULL);
698 LYDBGLOG("pthread join ret = %d",ret);
699 return 0;
700 }
rita98e2e9c2022-04-07 06:08:13 -0400701}
q.huang714145d2022-04-18 00:09:50 -0400702
703int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400704{
705 Parcel p;
706 lynq_client_t client;
707 int resp_type = -1;
708 int request = -1;
709 int slot_id = -1;
710 int error = -1;
rita089527e2022-04-07 01:55:39 -0400711
712 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400713 client.request = request_id;
714 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400715 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400716 if(argc!=0)
717 {
718 va_list args;
719 va_start(args, format);
720 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
721 va_end(args);
722 }
723 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400724 if(send_request(lynq_call_client_sockfd,&client)==-1)
725 {
726 LYERRLOG("send request fail");
727 return -1;
728 }
q.huang714145d2022-04-18 00:09:50 -0400729 if(get_response(lynq_call_client_sockfd,p)==0)
730 {
731 JumpHeader(p,&resp_type,&request,&slot_id,&error);
732 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
733 }
rita089527e2022-04-07 01:55:39 -0400734 return error;
735}
736
q.huang714145d2022-04-18 00:09:50 -0400737int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400738{
739 Parcel p;
740 lynq_client_t client;
741 int resp_type = -1;
742 int request = -1;
743 int slot_id = -1;
744 int error = -1;
q.huang714145d2022-04-18 00:09:50 -0400745 if(status==NULL)
746 {
747 LYERRLOG("status is null");
748 return -1;
749 }
rita089527e2022-04-07 01:55:39 -0400750 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400751 client.request = request_id;
752 client.paramLen = 0;
rita089527e2022-04-07 01:55:39 -0400753 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400754 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400755 if(send_request(lynq_call_client_sockfd,&client)==-1)
756 {
757 LYERRLOG("send request fail");
758 return -1;
759 }
q.huang714145d2022-04-18 00:09:50 -0400760 if(get_response(lynq_call_client_sockfd,p)==0)
rita089527e2022-04-07 01:55:39 -0400761 {
q.huang714145d2022-04-18 00:09:50 -0400762 JumpHeader(p,&resp_type,&request,&slot_id,&error);
763 p.readInt32(status);
764 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
rita089527e2022-04-07 01:55:39 -0400765 }
rita089527e2022-04-07 01:55:39 -0400766 return error;
767}
768
lh7b0674a2022-01-10 00:34:35 -0800769int lynq_call(int* handle,char addr[])
770{
771 Parcel p;
772 lynq_client_t client;
773 int resp_type = -1;
774 int request = -1;
775 int slot_id = -1;
776 int error = -1;
777 int lynq_call_id = -1;
778 if(addr==NULL)
779 {
780 LYERRLOG("Phone num is null!!!");
781 return -1;
782 }
lh42c1e572022-01-25 18:47:39 -0800783 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800784 client.request = 10;//RIL_REQUEST_DIAL
785 client.paramLen = 2;
786 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
787 memcpy(client.param,addr,strlen(addr)+1);
788 strcat(client.param," 0");
789 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800790 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800791 {
792 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800793 return -1;
794 }
lh42c1e572022-01-25 18:47:39 -0800795 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800796 JumpHeader(p,&resp_type,&request,&slot_id,&error);
797 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
798 lynq_call_id = updateAddr(addr);
799 if(error==0)
800 {
801 isDial = 1;
ll72bf6c12022-03-24 10:22:25 +0800802 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -0800803 {
804 error = LYNQ_E_TIME_OUT;
805 LYERRLOG("timeout:wait Call state fail!!!");
806 lynq_call_lists[lynq_call_id].hasTimeout = 1;
807 return error;
808 }
809 *handle = lynq_call_id;
810 }
811 return error;
812}
813int lynq_call_answer()
814{
815 Parcel p;
816 lynq_client_t client;
817 int resp_type = -1;
818 int request = -1;
819 int slot_id = -1;
820 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800821 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800822 client.request = 40;//RIL_REQUEST_DIAL
823 client.paramLen = 0;
824 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
825 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800826 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800827 {
828 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800829 return -1;
830 }
lh42c1e572022-01-25 18:47:39 -0800831 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800832 JumpHeader(p,&resp_type,&request,&slot_id,&error);
833 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
834 return error;
835}
836int lynq_call_hungup(int* handle)
837{
838 Parcel p;
839 lynq_client_t client;
840 int resp_type = -1;
841 int request = -1;
842 int slot_id = -1;
843 int error = -1;
844 int call_id = 0;
845 int lynq_call_id = 0;
lh42c1e572022-01-25 18:47:39 -0800846 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
847 {
848 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
849 return LYNQ_E_CONFLICT;
850 }
851 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800852 client.request = 12;//RIL_REQUEST_HUNGUP
853 client.paramLen = 1;
854 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
855 lynq_call_id = *handle;
856 call_id = lynq_call_lists[lynq_call_id].call_id;
857 sprintf(client.param,"%d",call_id);
858 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800859 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800860 {
861 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800862 return -1;
863 }
lh42c1e572022-01-25 18:47:39 -0800864 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800865 JumpHeader(p,&resp_type,&request,&slot_id,&error);
866 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
867 if(error==0)
868 {
869 cleanCallList(lynq_call_id);
870 }
871 return error;
872}
873int lynq_call_hungup_all()
874{
875 Parcel p;
876 lynq_client_t client;
877 int resp_type = -1;
878 int request = -1;
879 int slot_id = -1;
880 int error = -1;
lh42c1e572022-01-25 18:47:39 -0800881 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800882 client.request = 17;//RIL_REQUEST_UDUB
883 client.paramLen = 0;
884 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
885 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800886 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800887 {
888 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800889 return -1;
890 }
lh42c1e572022-01-25 18:47:39 -0800891 get_response(lynq_call_client_sockfd,p);
lh7b0674a2022-01-10 00:34:35 -0800892 JumpHeader(p,&resp_type,&request,&slot_id,&error);
893 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
894 return error;
895}
896int lynq_wait_incoming_call(int *handle)
897{
898 waitIncomingCall();
899 *handle = lynqIncomingCallId;
900 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
901 return 0;
902}
903
904int lynq_set_auto_answercall(const int mode)
905{
906 global_call_auto_answer = mode;
907 LYINFLOG("auto answer call mode =%d",mode);
908 return 0;
909}
q.huangec88da92022-03-29 04:17:32 -0400910int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
911{
912 int lynq_call_id = 0;
913 if(handle==NULL)
914 {
915 return LYNQ_E_NULL_ANONALY;
916 }
917 lynq_call_id = *handle;
918 *call_state = lynq_call_lists[lynq_call_id].call_state;
919 *toa = lynq_call_lists[lynq_call_id].toa;
920 *direction = lynq_call_lists[lynq_call_id].direction;
921 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
922 return 0;
923}
924
925/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +0000926static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +0000927 switch(enable){
928 case 0:
929 return 1;
930 case 1:
931 return 1;
932 default:
933 return 0;
lldc99c9b2022-01-24 12:16:22 +0000934 }
935}
936
lh7b0674a2022-01-10 00:34:35 -0800937int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +0000938{
939 if(!judge_mic(enable)){
940 return LYNQ_E_CONFLICT;
941 }
q.huangec88da92022-03-29 04:17:32 -0400942 return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
943}
944int lynq_get_mute_mic(int *status)
945{
946 return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
lh7b0674a2022-01-10 00:34:35 -0800947}
ll72bf6c12022-03-24 10:22:25 +0800948
949/**
950 * @brief Check whether DTMF is valid
951 *
952 * @param callnum dtmf eg:0-9 * #
953 * @return int
954 */
955static int judge_dtmf(const char callnum)
956{
957 if(callnum == '#')
958 {
959 return 1;
960 }
961 if(callnum == '*')
962 {
963 return 1;
964 }
965 if(callnum >= '0'&& callnum <= '9')
966 {
967 return 1;
968 }
969 return 0;
970}
971
lh7b0674a2022-01-10 00:34:35 -0800972int lynq_set_DTMF(const char callnum)
973{
ll72bf6c12022-03-24 10:22:25 +0800974 if(!judge_dtmf(callnum))
975 {
976 return LYNQ_E_CONFLICT;
977 }
lh7b0674a2022-01-10 00:34:35 -0800978 if(!lynq_call_state)
979 {
980 LYERRLOG("LYNQ_E_CONFLICT");
981 return LYNQ_E_CONFLICT;
982 }
q.huangec88da92022-03-29 04:17:32 -0400983 return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
lh7b0674a2022-01-10 00:34:35 -0800984}
q.huangec88da92022-03-29 04:17:32 -0400985static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
986 if(set==LYNQ_E_VOLUMN_SET_DTMF){
987 if(volume < 0 ||volume >36){
988 return 0;
989 }
990 }
991 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
992 {
993 if(volume < 1 ||volume >7){
994 return 0;
995 }
lldc99c9b2022-01-24 12:16:22 +0000996 }
ll04ae4142022-01-27 05:54:38 +0000997 return 1;
lldc99c9b2022-01-24 12:16:22 +0000998}
lh7b0674a2022-01-10 00:34:35 -0800999int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001000{
q.huangec88da92022-03-29 04:17:32 -04001001 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
lldc99c9b2022-01-24 12:16:22 +00001002 return LYNQ_E_CONFLICT;
1003 }
q.huangec88da92022-03-29 04:17:32 -04001004 return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
lh7b0674a2022-01-10 00:34:35 -08001005}
q.huangb212fde2022-04-05 23:11:02 -04001006int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001007{
q.huangec88da92022-03-29 04:17:32 -04001008 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
lh7b0674a2022-01-10 00:34:35 -08001009 {
q.huangec88da92022-03-29 04:17:32 -04001010 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001011 }
q.huangec88da92022-03-29 04:17:32 -04001012 return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
lh7b0674a2022-01-10 00:34:35 -08001013}
q.huangec88da92022-03-29 04:17:32 -04001014int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1015{
1016 return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
1017}
q.huangb212fde2022-04-05 23:11:02 -04001018int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001019{
q.huangb212fde2022-04-05 23:11:02 -04001020 return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
q.huangec88da92022-03-29 04:17:32 -04001021}
1022int lynq_incall_record_stop()
1023{
q.huangb212fde2022-04-05 23:11:02 -04001024 const char* unused_file="just_ocuupy_paramter_postion";
1025 return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
q.huangec88da92022-03-29 04:17:32 -04001026}
1027/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001028
1029#ifdef ECALL_SUPPORT
1030LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
1031{
1032 switch(type)
1033 {
1034 case LYNQ_ECALL_TYPE_TEST:
1035 return LYNQ_ECALL_TEST;
1036 case LYNQ_ECALL_TYPE_RECONFIG:
1037 return LYNQ_ECALL_RECONFIG;
1038 default:
1039 return LYNQ_ECALL_EMERGENCY;
1040 }
1041}
1042
1043RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
1044{
1045 switch(type)
1046 {
1047 case LYNQ_ECALL_TEST:
1048 return ECALL_TEST;
1049 case LYNQ_ECALL_RECONFIG:
1050 return ECALL_RECONFIG;
1051 default:
1052 return ECALL_EMERGENCY;
1053 }
1054}
1055
1056RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
1057{
1058 switch(cat)
1059 {
1060 case LYNQ_EMER_CAT_MANUAL_ECALL:
1061 return EMER_CAT_MANUAL_ECALL;
1062 default:
1063 return EMER_CAT_AUTO_ECALL;
1064 }
1065}
1066
1067
1068int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
1069{
1070 int error;
1071
1072 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
1073 {
1074 LYERRLOG("test_num is null or test_num_length %d s greater than %d\n ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
1075 return -1;
1076 }
1077
1078 error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
1079
1080 if(error==0)
1081 {
1082 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
1083 }
1084
1085 return error;
1086}
1087
1088
1089int 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)
1090{
1091 int error = -1;
1092 int lynq_call_id = -1;
1093 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
1094 LYNQ_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
1095
1096 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);
1097
1098 if(error==0)
1099 {
1100 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1101 isDial = 1;
1102 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1103 {
1104 error = LYNQ_E_TIME_OUT;
1105 LYERRLOG("timeout:wait Call state fail!!!");
1106 lynq_call_lists[lynq_call_id].hasTimeout = 1;
1107 return error;
1108 }
1109
1110 *handle = lynq_call_id;
1111 }
1112
1113 return error;
1114}
1115
1116int lynq_set_psap(int enable)
1117{
1118 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
1119}
1120
1121int lynq_psap_pull_msd()
1122{
1123 return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
1124}
1125
1126int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
1127{
1128 LYNQ_ECall_Variant lynq_ecall_variant;
1129 int error = -1;
1130 int lynq_call_id = -1;
1131
1132 if(handle==NULL)
1133 {
1134 LYERRLOG("handle is NULL, parameter error \n ");
1135 return -1;
1136 }
1137
1138 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
1139
1140 if(error==0)
1141 {
1142 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
1143
1144 lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
1145 isDial = 1;
1146 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1147 {
1148 error = LYNQ_E_TIME_OUT;
1149 LYERRLOG("timeout:wait Call state fail!!!");
1150 lynq_call_lists[lynq_call_id].hasTimeout = 1;
1151 return error;
1152 }
1153
1154 *handle = lynq_call_id;
1155 }
1156
1157 return error;
1158}
1159
1160
1161int lynq_set_msd(int* handle, const char *msd_data, int msd_length)
1162{
1163 if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX))
1164 {
1165 LYERRLOG("handle is NULL or *handle %d is greater or equeal to %d, parameter error\n",*handle,LYNQ_CALL_MAX);
1166 return -1;
1167 }
1168
1169 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,msd_data);
1170}
1171
1172int lynq_set_ivs(int enable)
1173{
1174 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
1175}
1176
1177int lynq_reset_ivs()
1178{
1179 return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
1180}
1181
1182int lynq_ivs_push_msd()
1183{
1184 return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
1185}
1186#endif
1187
lh7b0674a2022-01-10 00:34:35 -08001188#if 0
1189int main(int argc,char **argv)
1190{
1191 int n = 0;
1192 n = lynq_init_call(lynq_call_state_change_test,2222);
1193 if(n<0)
1194 {
llbc035332022-04-11 05:49:51 +00001195 LYDBGLOG("lynq init call fail!!!\n");
lh7b0674a2022-01-10 00:34:35 -08001196 return -1;
1197 }
llbc035332022-04-11 05:49:51 +00001198 LYDBGLOG("lynq call init success!!!\n");
lh7b0674a2022-01-10 00:34:35 -08001199 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1200 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1201 lynq_call(phoneNum);
1202 while(1)
1203 {
1204 sleep(1);
1205 }
1206 return 0;
1207}
1208#endif
1209/*Warren add for T800 platform 2021/11/19 end*/