blob: dd5685ce0341470dd7ac5f48667c7a87e86ea5f3 [file] [log] [blame]
lh25827952022-01-10 00:34:35 -08001#include <stdio.h>
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <arpa/inet.h>
5#include <fcntl.h>
6#include <string.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <binder/Parcel.h>
10#include <log/log.h>
lh25827952022-01-10 00:34:35 -080011#include <cutils/jstring.h>
12#include <pthread.h>
13#include "liblog/lynq_deflog.h"
lh228a7b82022-01-10 02:24:31 -080014#include <sys/time.h>
lh59e0d002022-01-27 00:27:12 -080015#include <string.h>
q.huangfe1b4052022-04-18 00:09:50 -040016#include <vendor-ril/telephony/ril.h>
17#include <vendor-ril/telephony/mtk_ril_sp.h>
18#include <vendor-ril/telephony/mtk_ril_ivt.h>
19#include "lynq_call.h"
20
21
lh25827952022-01-10 00:34:35 -080022#define LYNQ_SERVICE_PORT 8088
rjw8bdc56b2022-02-28 15:01:49 +080023#define DSET_IP_ADDRESS "127.0.0.1"
lh25827952022-01-10 00:34:35 -080024#define LYNQ_URC_SERVICE_PORT 8086
25#define LYNQ_REC_BUF 8192
26#define LYNQ_REQUEST_PARAM_BUF 8192
27#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
q.huang783ed5d2022-06-02 14:49:02 +080028#define INVALID_ID (-1)
lh25827952022-01-10 00:34:35 -080029#define USER_LOG_TAG "LYNQ_CALL"
30
31using ::android::Parcel;
32 typedef enum {
33 LYNQ_CALL_ACTIVE = 0,
34 LYNQ_CALL_HOLDING = 1,
35 LYNQ_CALL_DIALING = 2, /* MO call only */
36 LYNQ_CALL_ALERTING = 3, /* MO call only */
37 LYNQ_CALL_INCOMING = 4, /* MT call only */
lh8657e742022-04-26 00:45:44 -070038 LYNQ_CALL_WAITING = 5, /* MT call only */
39 /*warren add for T800 platform 2022/04/26 start*/
40 LYNQ_CALL_END = 6, /*CALL END*/
41 /*warren add for T800 platform 2022/04/26 end*/
lh25827952022-01-10 00:34:35 -080042}lynq_call_state_t;
43
44typedef struct{
45 int uToken;
46 int request;
47 int paramLen;
48 char param[LYNQ_REQUEST_PARAM_BUF];
49}lynq_client_t;
50typedef struct
51{
52 int used;
53 int call_id;
54 int call_state;
55 int toa;
56 int direction;/*0: MO call,1:MT call*/
57 char addr[LYNQ_PHONE_NUMBER_MAX];
lh25827952022-01-10 00:34:35 -080058}lynq_call_list_e_t;
59typedef struct
60{
61 int call_id;
62 int call_state;
63 int toa;
64 int direction;/*0: MO call,1:MT call*/
65 char addr[LYNQ_PHONE_NUMBER_MAX];
66}lynq_call_list_t;
67
68lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
69static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
70static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
ll375c94d2022-01-27 05:54:38 +000071static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
lh25827952022-01-10 00:34:35 -080072static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
73static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
74static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
ll1343a5b2022-03-17 05:31:33 +000075pthread_t lynq_call_urc_tid = -1;
76pthread_t lynq_call_list_loop_tid = -1;
lhcdf816a2022-02-13 23:56:05 -080077
rjw8bdc56b2022-02-28 15:01:49 +080078/*lei add*/
79/* socket文件描述符 */
80int len_addr_serv;
81struct sockaddr_in addr_serv;
82lynq_client_t client_t;
83int client_size = 0;
84/*lei add*/
lh25827952022-01-10 00:34:35 -080085
lha35d4ee2022-01-25 18:47:39 -080086int s_call_urc_event_complete = 1;
lh25827952022-01-10 00:34:35 -080087
88enum{
89 CALL_OFF=0,
90 CALL_ON=1
91}call_state;
ll375c94d2022-01-27 05:54:38 +000092typedef enum{
93 LYNQ_E_CARDSTATE_ERROR=8000,
94 /* The voice service state is out of service*/
95 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
96 /* The voice service state is EMERGENCY_ONLY*/
97 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
98 /* The radio power is power off*/
99 LYNQ_E_STATE_POWER_OFF=8003,
100 LYNQ_E_TIME_OUT=8004,
101 /*create or open sms DB fail */
102 LYNQ_E_SMS_DB_FAIL=8005,
103 /*Failed to execute sql statement*/
104 LYNQ_E_SMS_SQL_FAIL = 8006,
105 LYNQ_E_SMS_NOT_FIND = 8007,
106 /* The logic conflict*/
107 LYNQ_E_CONFLICT=9000,
108 /*Null anomaly*/
q.huang783ed5d2022-06-02 14:49:02 +0800109 LYNQ_E_NULL_ANONALY=9001,
110 /*Invalid id anomaly*/
111 LYNQ_E_INVALID_ID_ANONALY=9002,
112#ifdef ECALL_SUPPORT
113 LYNQ_E_ECALL_BEING_RUNNING =9003,
114 LYNQ_E_ECALL_MSD_LENGTH_ERROR =9004,
115#endif
lh25827952022-01-10 00:34:35 -0800116}LYNQ_E;
q.huangb0eb7b02022-03-29 04:17:32 -0400117typedef enum{
118 LYNQ_E_VOLUMN_SET_DTMF,
119 LYNQ_E_VOLUMN_SET_SPEECH
120}LYNQ_E_VOLUMN_SET;
lh25827952022-01-10 00:34:35 -0800121
122int lynq_call_state =CALL_OFF;
lha35d4ee2022-01-25 18:47:39 -0800123int lynq_call_client_sockfd = 0;
124int Global_uToken_call = 0;
lh25827952022-01-10 00:34:35 -0800125int global_call_count =0;
126int global_call_auto_answer = 0;
lha35d4ee2022-01-25 18:47:39 -0800127bool urc_call_recive_status = 1;
lh25827952022-01-10 00:34:35 -0800128bool call_list_loop = 1;
129int isDial = 0;
130int lynqIncomingCallId = 0;
q.huang18d08bf2022-04-19 20:27:44 -0400131
132#ifdef ECALL_SUPPORT
q.huang783ed5d2022-06-02 14:49:02 +0800133int lynq_set_common_request(int request_id, int argc, const char* format,...);
134int is_ecall_dial = 0;
135int g_ecallId = INVALID_ID;
q.huang18d08bf2022-04-19 20:27:44 -0400136typedef enum{
137 LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
138 LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
q.huangfe1b4052022-04-18 00:09:50 -0400139 LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
140 LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */\
141}LYNQ_ECall_Type;
142
q.huang783ed5d2022-06-02 14:49:02 +0800143char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"test_ecall","emergency_ecall","reconf_ecall"};
q.huang18d08bf2022-04-19 20:27:44 -0400144
145static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
146static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
147
q.huang783ed5d2022-06-02 14:49:02 +0800148LYNQ_ECall_Indication g_lynqIncomingEcallIndication;
q.huang18d08bf2022-04-19 20:27:44 -0400149
150void sendSignalIncomingECallEvent()
151{
q.huang783ed5d2022-06-02 14:49:02 +0800152 LYINFLOG("send incoming ecall event signal");;
q.huang18d08bf2022-04-19 20:27:44 -0400153 pthread_mutex_lock(&s_incoming_e_call_mutex);
154 pthread_cond_signal(&s_incoming_e_call_cond);
155 pthread_mutex_unlock(&s_incoming_e_call_mutex);
156}
q.huang783ed5d2022-06-02 14:49:02 +0800157
158int lynq_is_msd_suc(LYNQ_ECall_Indication lynqIncomingEcallIndication)
159{
160 if(LYNQ_ECALL_LLACK_RECEIVED == lynqIncomingEcallIndication ||
161 LYNQ_ECALL_ALACK_POSITIVE_RECEIVED == lynqIncomingEcallIndication ||
162 LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED == lynqIncomingEcallIndication ||
163 LYNQ_ECALL_T5_TIMER_OUT == lynqIncomingEcallIndication ||
164 LYNQ_ECALL_T6_TIMER_OUT == lynqIncomingEcallIndication ||
165 LYNQ_ECALL_T7_TIMER_OUT == lynqIncomingEcallIndication)
166 {
167 return 1;
168 }
169
170 return 0;
171}
172
173int lynq_ecall_is_running()
174{
175 return (is_ecall_dial!=0) || (g_ecallId !=INVALID_ID);
176}
177
q.huang18d08bf2022-04-19 20:27:44 -0400178#endif
q.huangfe1b4052022-04-18 00:09:50 -0400179
ll1343a5b2022-03-17 05:31:33 +0000180/**
181 * @brief mark call initialization state
182 * 0: deinit state
183 * 1: init state
184 */
185int g_lynq_call_init_flag = 0;
lh25827952022-01-10 00:34:35 -0800186
187int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
188{
189 if(p.dataAvail() > 0)
190 {
191 p.readInt32(resp_type);
192 p.readInt32(request);
193 p.readInt32(slot_id);
194 p.readInt32(error);
195 return 0;
196 }
197 else
198 {
199 return -1;
200 }
201}
202int send_request(int sockfd,lynq_client_t *client_tmp)
203{
204 int ret=0;
rjw8bdc56b2022-02-28 15:01:49 +0800205 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh25827952022-01-10 00:34:35 -0800206 if(ret==-1)
207 {
q.huang783ed5d2022-06-02 14:49:02 +0800208 LYERRLOG("sendto error");
lh25827952022-01-10 00:34:35 -0800209 return -1;
210 }
211 return 0;
212}
213
214int get_response(int sockfd,Parcel &p)
215{
216 int len = 0;
217 char recvline[LYNQ_REC_BUF];
218 bzero(recvline,LYNQ_REC_BUF);
219 /* receive data from server */
rjw8bdc56b2022-02-28 15:01:49 +0800220 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh25827952022-01-10 00:34:35 -0800221 if(len == -1)
222 {
q.huang783ed5d2022-06-02 14:49:02 +0800223 LYERRLOG("recvfrom error");
lh25827952022-01-10 00:34:35 -0800224 return -1;
225 }
lh25827952022-01-10 00:34:35 -0800226 if (recvline != NULL) {
227 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
228 p.setDataPosition(0);
229 }
230 return 0;
231}
232static char *strdupReadString(Parcel &p) {
ll375c94d2022-01-27 05:54:38 +0000233 size_t stringlen;
lh25827952022-01-10 00:34:35 -0800234 const char16_t *s16;
235 s16 = p.readString16Inplace(&stringlen);
ll375c94d2022-01-27 05:54:38 +0000236 return strndup16to8(s16, stringlen);
lh25827952022-01-10 00:34:35 -0800237}
238
239int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
240{
241 Parcel p;
242 lynq_client_t client;
243 int resp_type = -1;
244 int request = -1;
245 int slot_id = -1;
246 int error = -1;
247 int call_num = 0;
248 int temp = 0;
249 char *remote_phoneNum = NULL;
250 char *remote_name= NULL;
251 char *uusData = NULL;
lha35d4ee2022-01-25 18:47:39 -0800252 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -0800253 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
254 client.paramLen = 0;
255 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +0800256 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800257 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800258 {
259 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800260 return -1;
261 }
lha35d4ee2022-01-25 18:47:39 -0800262 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -0800263 JumpHeader(p,&resp_type,&request,&slot_id,&error);
264 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
265 if(error == 0)
266 {
267 p.readInt32(&call_num);
268 global_call_count = call_num;
269 if(call_num<=0)
270 {
271 lynq_call_state = CALL_OFF;
lhcdf816a2022-02-13 23:56:05 -0800272 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh25827952022-01-10 00:34:35 -0800273 return 0;
274 }
lhcdf816a2022-02-13 23:56:05 -0800275 lynq_call_state = CALL_ON;
q.huang783ed5d2022-06-02 14:49:02 +0800276 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh25827952022-01-10 00:34:35 -0800277 for(int i = 0;i < call_num;i++)
278 {
279 p.readInt32(&temp);
280 call_list[i].call_state = temp;
281 p.readInt32(&call_list[i].call_id);
282 p.readInt32(&call_list[i].toa);
283 p.readInt32(&temp);
284 p.readInt32(&temp);
285 call_list[i].direction = temp;
286 p.readInt32(&temp);
287 p.readInt32(&temp);
288 p.readInt32(&temp);
289 remote_phoneNum = strdupReadString(p);
290 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
291 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
292 call_list[i].direction,call_list[i].addr,call_list[i].toa);
293 p.readInt32(&temp);
294 remote_name = strdupReadString(p);
295 p.readInt32(&temp);
296 p.readInt32(&temp);
297 if(temp==0)
298 {
299 continue;
300 }
301 p.readInt32(&temp); /* UUS Information is present */
302 p.readInt32(&temp);
303 p.readInt32(&temp);
304 p.read(uusData,temp);
305 }
306 }
307 return 0;
308}
309
310void cleanCallList(int lynq_call_id)
311{
q.huang783ed5d2022-06-02 14:49:02 +0800312 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
lh25827952022-01-10 00:34:35 -0800313 lynq_call_lists[lynq_call_id].call_id = 0;
lh8657e742022-04-26 00:45:44 -0700314 lynq_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
lh25827952022-01-10 00:34:35 -0800315 lynq_call_lists[lynq_call_id].toa = 0;
316 lynq_call_lists[lynq_call_id].direction = 0;
317 lynq_call_lists[lynq_call_id].used = 0;
lh25827952022-01-10 00:34:35 -0800318 memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
319}
320int getUnusedElement()
321{
322 for(int i=0;i < LYNQ_CALL_MAX; i++)
323 {
324 if(lynq_call_lists[i].used!=1)
325 {
326 return i;
327 }
328 }
329 return -1;
330}
q.huang783ed5d2022-06-02 14:49:02 +0800331int addAddr(char addr[])
lh25827952022-01-10 00:34:35 -0800332{
333 int ret = 0;
334 ret = getUnusedElement();
335 memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
336 lynq_call_lists[ret].used = 1;
q.huang783ed5d2022-06-02 14:49:02 +0800337 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh25827952022-01-10 00:34:35 -0800338 return ret;
339}
340void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
341{
q.huang783ed5d2022-06-02 14:49:02 +0800342 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh25827952022-01-10 00:34:35 -0800343 callList->call_id = call_id;
344 callList->call_state = call_state;
345 callList->toa = toa;
q.huang783ed5d2022-06-02 14:49:02 +0800346 callList->direction = direction;
lh25827952022-01-10 00:34:35 -0800347 return;
348}
349int waitCallstateChange(int mtime)
350{
lhbe92dd12022-04-19 06:01:25 -0700351 LYINFLOG("wait Call state Change");
lh25827952022-01-10 00:34:35 -0800352 int ret = 0;
353 int sec = 0;
354 int usec = 0;
lh228a7b82022-01-10 02:24:31 -0800355 struct timeval now;
356 struct timespec timeout;
357 gettimeofday(&now,NULL);
lh25827952022-01-10 00:34:35 -0800358 sec = mtime/1000;
359 usec = mtime%1000;
lh228a7b82022-01-10 02:24:31 -0800360 timeout.tv_sec = now.tv_sec+sec;
361 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh25827952022-01-10 00:34:35 -0800362 pthread_mutex_lock(&call_state_change_mutex);
lh228a7b82022-01-10 02:24:31 -0800363 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh25827952022-01-10 00:34:35 -0800364 pthread_mutex_unlock(&call_state_change_mutex);
365 return ret;
366}
367int waitIncomingCall()
368{
lhbe92dd12022-04-19 06:01:25 -0700369 LYINFLOG("wait incming call");
lh25827952022-01-10 00:34:35 -0800370 int ret = 0;
371 pthread_mutex_lock(&s_incoming_call_mutex);
372 ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
373 pthread_mutex_unlock(&s_incoming_call_mutex);
374 return ret;
375}
376int checkHasCall(char addr[])
377{
378 for(int i = 0;i<LYNQ_CALL_MAX;i++)
379 {
380 if(strcmp(lynq_call_lists[i].addr,addr)==0)
381 {
q.huang783ed5d2022-06-02 14:49:02 +0800382 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,lynq_call_lists[i].call_id);
lh25827952022-01-10 00:34:35 -0800383 return 1;
384 }
385 }
q.huang783ed5d2022-06-02 14:49:02 +0800386 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
lh25827952022-01-10 00:34:35 -0800387 return 0;
388}
lhbe92dd12022-04-19 06:01:25 -0700389int find_call_id_with_addr(char *addr)
390{
lhbe92dd12022-04-19 06:01:25 -0700391 for(int id = 0; id < LYNQ_CALL_MAX; id++)
392 {
q.huang783ed5d2022-06-02 14:49:02 +0800393 if(lynq_call_lists[id].used && (strcmp(lynq_call_lists[id].addr,addr) == 0))
lhbe92dd12022-04-19 06:01:25 -0700394 {
q.huang783ed5d2022-06-02 14:49:02 +0800395 LYINFLOG("find addr %s in local list, local idx is %d id is %d",addr,id,lynq_call_lists[id].call_id);
lhbe92dd12022-04-19 06:01:25 -0700396 return id;
397 }
398 }
q.huang783ed5d2022-06-02 14:49:02 +0800399 LYINFLOG("find addr %s in local list , not found",addr);
lhbe92dd12022-04-19 06:01:25 -0700400 return -1;
401}
q.huang783ed5d2022-06-02 14:49:02 +0800402int find_call_id_with_call_id(int call_id)
403{
404 for(int id = 0; id < LYNQ_CALL_MAX; id++)
405 {
406 if(lynq_call_lists[id].used && (lynq_call_lists[id].call_id == call_id))
407 {
408 LYINFLOG("find id %d in local list, local idx is %d, addr is %s",call_id,id,lynq_call_lists[id].addr);
409 return id;
410 }
411 }
412 LYINFLOG("find id %d in local list , not found",call_id);
413 return INVALID_ID;
414}
lh25827952022-01-10 00:34:35 -0800415void sendSignalToWaitCallStateChange()
416{
lhbe92dd12022-04-19 06:01:25 -0700417 LYINFLOG("send Signal To Wait Call State Change");
lh25827952022-01-10 00:34:35 -0800418 pthread_mutex_lock(&call_state_change_mutex);
419 pthread_cond_signal(&call_state_change_cond);
420 pthread_mutex_unlock(&call_state_change_mutex);
421}
422void sendSignalIncomingCall()
423{
lhbe92dd12022-04-19 06:01:25 -0700424 LYINFLOG("send incoming call signal");
lh25827952022-01-10 00:34:35 -0800425 pthread_mutex_lock(&s_incoming_call_mutex);
426 pthread_cond_signal(&s_incoming_call_cond);
427 pthread_mutex_unlock(&s_incoming_call_mutex);
428}
429
430void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
431{
432 callList->call_id = call_id;
433 callList->call_state = call_state;
434 callList->toa = toa;
435 callList->direction = direction;
436 memcpy(callList->addr,addr,strlen(addr)+1);
437 callList->used = 1;
lh25827952022-01-10 00:34:35 -0800438 return;
439}
440
441void *triggerGetCallList(void *parg)
ll375c94d2022-01-27 05:54:38 +0000442{
443 int ret=0;
lhbe92dd12022-04-19 06:01:25 -0700444 bool call_end;
ll375c94d2022-01-27 05:54:38 +0000445 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang18d08bf2022-04-19 20:27:44 -0400446 int update=0;
q.huang783ed5d2022-06-02 14:49:02 +0800447 int cnt;
448 int i,n;
449
lh25827952022-01-10 00:34:35 -0800450 while(call_list_loop)
ll375c94d2022-01-27 05:54:38 +0000451 {
q.huang18d08bf2022-04-19 20:27:44 -0400452 update=0;
ll375c94d2022-01-27 05:54:38 +0000453 pthread_mutex_lock(&s_urc_call_state_change_mutex);
454 pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
q.huang783ed5d2022-06-02 14:49:02 +0800455 LYDBGLOG("triggerGetCallList event!!!");
ll375c94d2022-01-27 05:54:38 +0000456 memset(call_list,0,sizeof(call_list));
457 ret = lynq_get_current_call_list(call_list);
458 if(ret != 0)
459 {
q.huang783ed5d2022-06-02 14:49:02 +0800460 LYDBGLOG("get current call list failure!!!");
ll22101402022-04-11 05:49:51 +0000461 continue;
ll375c94d2022-01-27 05:54:38 +0000462 }
lhbe92dd12022-04-19 06:01:25 -0700463 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huang783ed5d2022-06-02 14:49:02 +0800464 LYINFLOG("clear local index begin");
465 cnt=0;
466 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh25827952022-01-10 00:34:35 -0800467 {
q.huang783ed5d2022-06-02 14:49:02 +0800468 if(lynq_call_lists[i].used ==0)
469 {
470 continue;
471 }
472 cnt++;
473 LYINFLOG("local idx is %d id is %d addr is %s state is %d direction is %d",i,lynq_call_lists[i].call_id,lynq_call_lists[i].addr,lynq_call_lists[i].call_state,lynq_call_lists[i].direction);
474
475 if(lynq_call_lists[i].call_id > 0)
lhbe92dd12022-04-19 06:01:25 -0700476 {
477 call_end = 0;
q.huang783ed5d2022-06-02 14:49:02 +0800478 for(n = 0; n < LYNQ_CALL_MAX; n++)
lhbe92dd12022-04-19 06:01:25 -0700479 {
q.huang783ed5d2022-06-02 14:49:02 +0800480 if(call_list[n].call_id == lynq_call_lists[i].call_id)
lhbe92dd12022-04-19 06:01:25 -0700481 {
482 call_end = 1;
q.huang783ed5d2022-06-02 14:49:02 +0800483 LYINFLOG("find lynq call local idx %d, service idx %d id is %d!!!",i,n,lynq_call_lists[i].call_id);
484 break;
lhbe92dd12022-04-19 06:01:25 -0700485 }
486 }
487 if(call_end == 0)
488 {
q.huang783ed5d2022-06-02 14:49:02 +0800489 LYINFLOG("MT hungup,then clean call info local idx is %d id is %d",i, lynq_call_lists[i].call_id);
490 cleanCallList(i);
lhbe92dd12022-04-19 06:01:25 -0700491 }
492 } //fix bug API-54
q.huang783ed5d2022-06-02 14:49:02 +0800493 else
494 {
495 LYINFLOG("local id is 0");
496 }
497 }
498 LYINFLOG("clear local index end, local used cnt is %d", cnt);
499
500 LYINFLOG("add or update local index begin ");
501 for (i = 0;i < LYNQ_CALL_MAX;i++)
502 {
503 if(call_list[i].call_id==0)
504 {
505 break;
506 }
507
508 LYINFLOG("servie idx %d begin: call_id=%d, call_state=%d, direction=%d, addr=%s, toa=%d",i,call_list[i].call_id, call_list[i].call_state,
509 call_list[i].direction,call_list[i].addr,call_list[i].toa);
510
lh25827952022-01-10 00:34:35 -0800511 if(call_list[i].direction == 1)//MT call
512 {
q.huang783ed5d2022-06-02 14:49:02 +0800513 LYINFLOG("This is a MT CALL");
lh4256e1b2022-05-13 03:02:19 -0700514 /*MT CALL state code
515 **LYNQ_CALL_INCOMING = 4,
516 **LYNQ_CALL_WAITING = 5,
517 */
518 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh25827952022-01-10 00:34:35 -0800519 {
q.huang783ed5d2022-06-02 14:49:02 +0800520#ifdef ECALL_SUPPORT
521 if(lynq_ecall_is_running())
lh25827952022-01-10 00:34:35 -0800522 {
q.huang783ed5d2022-06-02 14:49:02 +0800523 lynq_call_hungup(&(call_list[i].call_id));
524 continue;
lh25827952022-01-10 00:34:35 -0800525 }
q.huang783ed5d2022-06-02 14:49:02 +0800526#endif
527 }
528 /*you call me, and i call you,One party failed to dial*/
529 n = find_call_id_with_addr(call_list[i].addr);
530 if(n ==INVALID_ID)
531 {
532 n = addAddr(call_list[i].addr);
533 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
534 lynqIncomingCallId = call_list[i].call_id;
535 sendSignalIncomingCall();
536 }
537 else if(lynq_call_lists[n].call_state == call_list[i].call_state)
538 {
539 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
540 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lhbe92dd12022-04-19 06:01:25 -0700541 {
lhbe92dd12022-04-19 06:01:25 -0700542 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
543 **an incoming call until the status changes.
544 **fix bug API-54
545 */
q.huang783ed5d2022-06-02 14:49:02 +0800546 LYINFLOG("resend incoming call signal");
547 sendSignalIncomingCall();
lhbe92dd12022-04-19 06:01:25 -0700548 }
lh25827952022-01-10 00:34:35 -0800549 }
q.huang783ed5d2022-06-02 14:49:02 +0800550 else
ll45d3ea92022-03-24 10:22:25 +0800551 {
q.huang783ed5d2022-06-02 14:49:02 +0800552 LYINFLOG("state changed from %d to %d",lynq_call_lists[n].call_state,call_list[i].call_state);
553
554 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
555 }
lh25827952022-01-10 00:34:35 -0800556 }
557 else
q.huang783ed5d2022-06-02 14:49:02 +0800558 {
559 LYINFLOG("This is a MO CALL");
560 call_end = 0;
561 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh25827952022-01-10 00:34:35 -0800562 {
q.huang783ed5d2022-06-02 14:49:02 +0800563 if(lynq_call_lists[n].used && ((strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)||(call_list[i].call_id==lynq_call_lists[n].call_id)))
lh25827952022-01-10 00:34:35 -0800564 {
q.huang783ed5d2022-06-02 14:49:02 +0800565 if(lynq_call_lists[n].call_id==0)
566 {
567 LYINFLOG("add a call id");
568 update=1;
569 }
570 LYINFLOG("local idx %d updated, original call id is %d origial addr is %s original state is %d",n,lynq_call_lists[n].call_id,lynq_call_lists[n].addr,lynq_call_lists[n].call_state);
571 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
572 call_end = 1;
573 break;
574 }
575 }
576
577 if(call_end == 0)
578 {
579 LYINFLOG("need to hangup id %d", call_list[i].call_id);
580#ifdef ECALL_SUPPORT
581 if(is_ecall_dial==1)
582 {
583 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh25827952022-01-10 00:34:35 -0800584 continue;
585 }
q.huang783ed5d2022-06-02 14:49:02 +0800586#endif
587 LYINFLOG("hang up service call id %d",call_list[i].call_id);
588 lynq_call_hungup(&(call_list[i].call_id));
lh25827952022-01-10 00:34:35 -0800589 }
lh25827952022-01-10 00:34:35 -0800590 }
q.huang783ed5d2022-06-02 14:49:02 +0800591 LYDBGLOG("servie idx %d end",i);
ll375c94d2022-01-27 05:54:38 +0000592 }
q.huang783ed5d2022-06-02 14:49:02 +0800593 LYINFLOG("add or update local index end ");
lha35d4ee2022-01-25 18:47:39 -0800594 s_call_urc_event_complete = 1;
q.huang783ed5d2022-06-02 14:49:02 +0800595 if(isDial==1)
lh25827952022-01-10 00:34:35 -0800596 {
q.huang783ed5d2022-06-02 14:49:02 +0800597 LYINFLOG("now is dialing");
598 if(update==1)
599 {
600 LYINFLOG("find added call");
601 sendSignalToWaitCallStateChange();
602 isDial = 0;
603 }
604 else
605 {
606 LYINFLOG("not find added call");
607 }
608 }
609 else
610 {
611 LYINFLOG("now is not dialing");
lh25827952022-01-10 00:34:35 -0800612 }
ll375c94d2022-01-27 05:54:38 +0000613 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
614 }
615 return NULL;
lh25827952022-01-10 00:34:35 -0800616}
617
618void lynqRespWatingEvent()
ll375c94d2022-01-27 05:54:38 +0000619{
620 if(s_call_urc_event_complete==1)
621 {
622 pthread_mutex_lock(&s_urc_call_state_change_mutex);
623 pthread_cond_signal(&s_urc_call_state_change_cond);
624 s_call_urc_event_complete = 0;
625 pthread_mutex_unlock(&s_urc_call_state_change_mutex);
lh25827952022-01-10 00:34:35 -0800626 }
ll375c94d2022-01-27 05:54:38 +0000627 return;
lh25827952022-01-10 00:34:35 -0800628}
629
630/*Warren add for T800 platform 2021/11/19 start*/
631int lynq_socket_client_start()
rjw8bdc56b2022-02-28 15:01:49 +0800632{
633 #if 0
lh25827952022-01-10 00:34:35 -0800634 struct sockaddr_in lynq_socket_server_addr;
635 /* init lynq_socket_server_addr */
636 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
637 lynq_socket_server_addr.sin_family = AF_INET;
638 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
639 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw8bdc56b2022-02-28 15:01:49 +0800640
lh25827952022-01-10 00:34:35 -0800641 /*
642 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
643 {
q.huang783ed5d2022-06-02 14:49:02 +0800644 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh25827952022-01-10 00:34:35 -0800645 exit(1);
646 }
647*/
lha35d4ee2022-01-25 18:47:39 -0800648 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
649 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh25827952022-01-10 00:34:35 -0800650 {
q.huang783ed5d2022-06-02 14:49:02 +0800651 LYERRLOG("connect error");
lh25827952022-01-10 00:34:35 -0800652 return -1;
653 }
rjw8bdc56b2022-02-28 15:01:49 +0800654 #endif
655 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
656 if (-1 == lynq_call_client_sockfd)
657 {
658 return lynq_call_client_sockfd;
659 }
660 /* 设置address */
661 memset(&addr_serv, 0, sizeof(addr_serv));
662 addr_serv.sin_family = AF_INET;
663 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
664 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
665 len_addr_serv = sizeof(addr_serv);
lh25827952022-01-10 00:34:35 -0800666 return 0;
667}
668int lynq_update_call_list_loop()
669{
670 int ret = 0;
lh25827952022-01-10 00:34:35 -0800671 pthread_attr_t attr;
672 pthread_attr_init(&attr);
673 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -0800674 ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
lh25827952022-01-10 00:34:35 -0800675 if(ret < 0)
676 {
677 LYERRLOG("lynq_update_call_list_loop fail!!!");
678 return -1;
679 }
q.huang783ed5d2022-06-02 14:49:02 +0800680 LYDBGLOG("lynq_update_call_list_loop success!!!");
lh25827952022-01-10 00:34:35 -0800681 return 0;
682
683}
q.huang783ed5d2022-06-02 14:49:02 +0800684
lh25827952022-01-10 00:34:35 -0800685void *thread_urc_recv(void *parg)
ll375c94d2022-01-27 05:54:38 +0000686{
lh25827952022-01-10 00:34:35 -0800687 int socket_fd = (int64_t)parg;
688 int len=0;
689 socklen_t addr_len=0;
690 uint8_t *dataLength = NULL;
691 char urc_data[LYNQ_REC_BUF];
692 int slot_id = -1;
693 int resp_type = -1;
694 int urcid = -1;
695 Parcel *p = NULL;
696 struct sockaddr_in dest_addr;
q.huang18d08bf2022-04-19 20:27:44 -0400697#ifdef ECALL_SUPPORT
q.huang783ed5d2022-06-02 14:49:02 +0800698 int ecall_ind;
699 int ecallId;
700 int unused_callid;
q.huang18d08bf2022-04-19 20:27:44 -0400701#endif
702
q.huang783ed5d2022-06-02 14:49:02 +0800703 LYINFLOG("thread_urc_recv in running....");
lha35d4ee2022-01-25 18:47:39 -0800704 while(urc_call_recive_status)
lh25827952022-01-10 00:34:35 -0800705 {
706 bzero(urc_data,LYNQ_REC_BUF);
707 //get data msg
708 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
709 if(len <= 0)
ll375c94d2022-01-27 05:54:38 +0000710 {
q.huang783ed5d2022-06-02 14:49:02 +0800711 LYERRLOG("thread_urc_recv step2 fail");
ll375c94d2022-01-27 05:54:38 +0000712 break;
lh25827952022-01-10 00:34:35 -0800713 }
q.huang783ed5d2022-06-02 14:49:02 +0800714 LYDBGLOG("=====>urc data len<=====:%d",len);
lh25827952022-01-10 00:34:35 -0800715 p = new Parcel();
716 if(p==NULL)
717 {
lh59e0d002022-01-27 00:27:12 -0800718 LYERRLOG("new parcel failure!!!");
lh25827952022-01-10 00:34:35 -0800719 break;
720 }
721 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
722 p->setDataPosition(0);
723 if(p->dataAvail() > 0)
724 {
725 p->readInt32(&resp_type);
726 p->readInt32(&urcid);
727 p->readInt32(&slot_id);
q.huang783ed5d2022-06-02 14:49:02 +0800728 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
lh25827952022-01-10 00:34:35 -0800729 switch (urcid)
730 {
731 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
732 {
q.huang783ed5d2022-06-02 14:49:02 +0800733 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
lh25827952022-01-10 00:34:35 -0800734 lynqRespWatingEvent();
735 break;
736 }
737 case 1018://RIL_UNSOL_CALL_RING
738 {
739 if(global_call_auto_answer==1)
740 {
741 lynq_call_answer();
742 }
743 break;
744 }
745 case 1029://RIL_UNSOL_RINGBACK_TONE
746 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
747 {
q.huang783ed5d2022-06-02 14:49:02 +0800748 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
lh25827952022-01-10 00:34:35 -0800749 break;
750 }
q.huang18d08bf2022-04-19 20:27:44 -0400751#ifdef ECALL_SUPPORT
752 case RIL_UNSOL_ECALL_INDICATIONS:
753 {
q.huang783ed5d2022-06-02 14:49:02 +0800754 p->readInt32(&ecall_ind);
755 g_lynqIncomingEcallIndication = ecall_ind;
756 p->readInt32(&ecallId);
757 LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS ,Id %d, ind %d, ecall dialing is %d, normal dialing is %d, local ecall id is %d",ecallId,ecall_ind,is_ecall_dial,isDial,g_ecallId);
758 if(lynq_is_msd_suc(g_lynqIncomingEcallIndication))
759 {
760 if(is_ecall_dial)
761 {
762 LYINFLOG("ecall is dialing, recv suc indication");
763 is_ecall_dial=0;
764 if(ecallId >0 && find_call_id_with_call_id(ecallId)==INVALID_ID)
765 {
766 LYINFLOG("add ecall in loacl list");
767 g_ecallId = ecallId;
768 unused_callid=addAddr("ecall");
769 lynq_call_lists[unused_callid].call_id=g_ecallId;
770 }
q.huang18d08bf2022-04-19 20:27:44 -0400771 sendSignalToWaitCallStateChange();
q.huang783ed5d2022-06-02 14:49:02 +0800772 }
773 else if(ecallId >0 && (find_call_id_with_call_id(ecallId)==INVALID_ID)){
774 LYERRLOG("ecall is not in dialing and first recv suc indication, hangup");
775 lynq_call_hungup(&ecallId);
776 }
777 else
778 {
779 LYERRLOG("ecall is not in dialing and not first recv suc indication");
780 }
781 }
782 else if (LYNQ_ECALL_PSAP_CALLBACK_START == g_lynqIncomingEcallIndication)
783 {
784 if(lynq_ecall_is_running()==0)
785 {
786 LYINFLOG("ecall is not running, recv psap call back msd start, set ecall in dialing");
q.huang755b3252022-06-06 16:52:13 +0800787 if(find_call_id_with_call_id(ecallId)!=INVALID_ID)
q.huang783ed5d2022-06-02 14:49:02 +0800788 {
q.huang755b3252022-06-06 16:52:13 +0800789 g_ecallId = ecallId;
790 if(isDial)
791 {
792 LYINFLOG("stop normal dial");
793 sendSignalToWaitCallStateChange();
794 }
795 else
796 {
797 LYINFLOG("no normal dial");
798 }
q.huang783ed5d2022-06-02 14:49:02 +0800799 }
800 else
801 {
q.huang755b3252022-06-06 16:52:13 +0800802 LYERRLOG("can't find ecall id in local list");
q.huang783ed5d2022-06-02 14:49:02 +0800803 }
804 }
805 else
806 {
807 LYERRLOG("ecall is running, recv psap call back msd start");
808 }
809 }
810 else if (LYNQ_ECALL_ABNORMAL_HANGUP == g_lynqIncomingEcallIndication)
811 {
812 if(is_ecall_dial==0)
813 {
814 LYERRLOG("ecall is not in dialing, recv abnormal hangup");
815 g_ecallId = INVALID_ID;
816 }
817 else
818 {
819 LYINFLOG("ecall is in dialing, recv abnormal hangup");
820 }
821 }
822 else if (LYNQ_ECALL_DISCONNECTED == g_lynqIncomingEcallIndication ||
823 LYNQ_ECALL_REDIAL_TIMER_OUT == g_lynqIncomingEcallIndication ||
824 LYNQ_ECALL_T2_TIMER_OUT == g_lynqIncomingEcallIndication)
825 {
826 g_ecallId = INVALID_ID;
827 if(is_ecall_dial)
828 {
829 LYERRLOG("ecall is in dialing, recv like disconnect indication");
830 is_ecall_dial=0;
831 sendSignalToWaitCallStateChange();
832 }
833 else
834 {
835 LYINFLOG("ecall is not in dialing, recv like disconnect indication");
836 }
837 }
838 else
839 {
840 LYINFLOG("not special indication");
841 }
q.huang18d08bf2022-04-19 20:27:44 -0400842 sendSignalIncomingECallEvent();
q.huang783ed5d2022-06-02 14:49:02 +0800843 LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS, local ecall id is %d", g_ecallId);
q.huang18d08bf2022-04-19 20:27:44 -0400844 break;
845 }
846#endif
lh25827952022-01-10 00:34:35 -0800847 default:
848 break;
849 }
850 }
851 delete p;
852 p = NULL;
853 }
854 close(socket_fd);
855}
856int lynq_socket_urc_start()
857{
858 int socket_fd=0;
859 int rt=0;
860 int len=0;
861 int on=1;
862 struct sockaddr_in urc_local_addr;
lh25827952022-01-10 00:34:35 -0800863 pthread_attr_t attr;
ll375c94d2022-01-27 05:54:38 +0000864 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll375c94d2022-01-27 05:54:38 +0000865 if(socket_fd < 0)
866 {
q.huang783ed5d2022-06-02 14:49:02 +0800867 LYERRLOG("creaet socket for udp fail");
ll375c94d2022-01-27 05:54:38 +0000868 return -1;
lh25827952022-01-10 00:34:35 -0800869 }
870 urc_local_addr.sin_family = AF_INET;
871 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
872 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
873 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll375c94d2022-01-27 05:54:38 +0000874 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
875 if(rt<0)
876 {
q.huang783ed5d2022-06-02 14:49:02 +0800877 LYERRLOG("SO_REUSEADDR fail");
lh25827952022-01-10 00:34:35 -0800878 return -1;
879 }
880 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll375c94d2022-01-27 05:54:38 +0000881 if (rt == -1)
882 {
lh59e0d002022-01-27 00:27:12 -0800883 LYERRLOG("bind failed");
ll375c94d2022-01-27 05:54:38 +0000884 return -1;
lh25827952022-01-10 00:34:35 -0800885 }
886 pthread_attr_init(&attr);
887 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -0800888 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh25827952022-01-10 00:34:35 -0800889 if(rt < 0)
890 {
q.huang783ed5d2022-06-02 14:49:02 +0800891 LYERRLOG("urc loop failure!!!");
lh25827952022-01-10 00:34:35 -0800892 return -1;
893 }
q.huang783ed5d2022-06-02 14:49:02 +0800894 LYDBGLOG("urc loop success!!!");
lh25827952022-01-10 00:34:35 -0800895 return 0;
896}
897int getSelfElement(char addr[])
898{
899 for(int i=0;i < LYNQ_CALL_MAX; i++)
900 {
901 if(lynq_call_lists[i].used==1)
902 {
903 if(strcmp(lynq_call_lists[i].addr,addr)==0)
904 {
905 return i;
906 }
907
908 }
909 }
910 return -1;
911}
912
913void lynq_call_state_change_test(int soc_id)
914{
q.huang783ed5d2022-06-02 14:49:02 +0800915 LYDBGLOG("call state change,sim:%d",soc_id);
lh25827952022-01-10 00:34:35 -0800916}
917int lynq_init_call(int uToken)
ll1343a5b2022-03-17 05:31:33 +0000918{
919 if(g_lynq_call_init_flag == 1){
920 LYDBGLOG("lynq init call failed!!!");
921 return -1;
922 }
923 g_lynq_call_init_flag = 1;
lh25827952022-01-10 00:34:35 -0800924 int result = 0;
lha35d4ee2022-01-25 18:47:39 -0800925 Global_uToken_call = uToken;
lh59e0d002022-01-27 00:27:12 -0800926 urc_call_recive_status = 1;
rjw8bdc56b2022-02-28 15:01:49 +0800927 client_size = sizeof(client_t);
lh25827952022-01-10 00:34:35 -0800928 LYLOGSET(LOG_INFO);
929 LYLOGEINIT(USER_LOG_TAG);
930 result = lynq_socket_client_start();
931 if(result!=0)
932 {
933 return -1;
934 }
935 result = lynq_socket_urc_start();
936 if(result!=0)
937 {
938 return -1;
939 }
940 result = lynq_update_call_list_loop();
941 if(result!=0)
942 {
943 return -1;
944 }
945 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
946 LYDBGLOG("lynq init call success!!!");
947 return 0;
948}
949int lynq_deinit_call()
950{
q.huang783ed5d2022-06-02 14:49:02 +0800951 int ret;
ll1343a5b2022-03-17 05:31:33 +0000952 if(g_lynq_call_init_flag == 0)
lhcdf816a2022-02-13 23:56:05 -0800953 {
ll1343a5b2022-03-17 05:31:33 +0000954 LYDBGLOG("lynq_deinit_call failed!!!");
955 return -1;
lhcdf816a2022-02-13 23:56:05 -0800956 }
ll1343a5b2022-03-17 05:31:33 +0000957 else
958 {
959 g_lynq_call_init_flag = 0;
q.huang783ed5d2022-06-02 14:49:02 +0800960 lynq_call_hungup_all();
ll1343a5b2022-03-17 05:31:33 +0000961 if(lynq_call_client_sockfd>0)
962 {
963 close(lynq_call_client_sockfd);
964 }
965 urc_call_recive_status = 0;
966 call_list_loop = 0;
967 if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
968 {
969 return -1;
970 }
971 ret = pthread_cancel(lynq_call_urc_tid);
972 LYDBGLOG("pthread cancel ret = %d",ret);
973 ret = pthread_cancel(lynq_call_list_loop_tid);
974 LYDBGLOG("pthread cancel ret = %d",ret);
975 ret = pthread_join(lynq_call_urc_tid,NULL);
976 LYDBGLOG("pthread join ret = %d",ret);
977 ret = pthread_join(lynq_call_list_loop_tid,NULL);
978 LYDBGLOG("pthread join ret = %d",ret);
979 return 0;
980 }
rita47debb92022-04-07 06:08:13 -0400981}
q.huangfe1b4052022-04-18 00:09:50 -0400982
983int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita9b436d82022-04-07 01:55:39 -0400984{
985 Parcel p;
986 lynq_client_t client;
987 int resp_type = -1;
988 int request = -1;
989 int slot_id = -1;
990 int error = -1;
rita9b436d82022-04-07 01:55:39 -0400991
992 client.uToken = Global_uToken_call;
q.huangfe1b4052022-04-18 00:09:50 -0400993 client.request = request_id;
994 client.paramLen = argc;
rita9b436d82022-04-07 01:55:39 -0400995 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangfe1b4052022-04-18 00:09:50 -0400996 if(argc!=0)
997 {
998 va_list args;
999 va_start(args, format);
1000 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
1001 va_end(args);
1002 }
q.huang783ed5d2022-06-02 14:49:02 +08001003 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -04001004 if(send_request(lynq_call_client_sockfd,&client)==-1)
1005 {
1006 LYERRLOG("send request fail");
1007 return -1;
1008 }
q.huangfe1b4052022-04-18 00:09:50 -04001009 if(get_response(lynq_call_client_sockfd,p)==0)
1010 {
1011 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1012 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1013 }
rita9b436d82022-04-07 01:55:39 -04001014 return error;
1015}
1016
q.huangfe1b4052022-04-18 00:09:50 -04001017int lynq_get_common_request(int request_id, int* status)
rita9b436d82022-04-07 01:55:39 -04001018{
1019 Parcel p;
1020 lynq_client_t client;
1021 int resp_type = -1;
1022 int request = -1;
1023 int slot_id = -1;
1024 int error = -1;
q.huangfe1b4052022-04-18 00:09:50 -04001025 if(status==NULL)
1026 {
1027 LYERRLOG("status is null");
1028 return -1;
1029 }
rita9b436d82022-04-07 01:55:39 -04001030 client.uToken = Global_uToken_call;
q.huangfe1b4052022-04-18 00:09:50 -04001031 client.request = request_id;
1032 client.paramLen = 0;
rita9b436d82022-04-07 01:55:39 -04001033 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +08001034 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -04001035 if(send_request(lynq_call_client_sockfd,&client)==-1)
1036 {
1037 LYERRLOG("send request fail");
1038 return -1;
1039 }
q.huangfe1b4052022-04-18 00:09:50 -04001040 if(get_response(lynq_call_client_sockfd,p)==0)
rita9b436d82022-04-07 01:55:39 -04001041 {
q.huangfe1b4052022-04-18 00:09:50 -04001042 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1043 p.readInt32(status);
1044 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
rita9b436d82022-04-07 01:55:39 -04001045 }
rita9b436d82022-04-07 01:55:39 -04001046 return error;
1047}
1048
lh25827952022-01-10 00:34:35 -08001049int lynq_call(int* handle,char addr[])
1050{
1051 Parcel p;
1052 lynq_client_t client;
1053 int resp_type = -1;
1054 int request = -1;
1055 int slot_id = -1;
1056 int error = -1;
1057 int lynq_call_id = -1;
q.huang783ed5d2022-06-02 14:49:02 +08001058
1059 LYINFLOG("lynq_call begin addr %s",addr);
lh25827952022-01-10 00:34:35 -08001060 if(addr==NULL)
1061 {
1062 LYERRLOG("Phone num is null!!!");
1063 return -1;
1064 }
q.huang783ed5d2022-06-02 14:49:02 +08001065
1066 if(find_call_id_with_addr(addr)!=INVALID_ID)
1067 {
1068 LYERRLOG("addr %s exists",addr);
1069 return LYNQ_E_CONFLICT;
1070 }
1071
1072#ifdef ECALL_SUPPORT
1073 if(lynq_ecall_is_running())
1074 {
1075 LYERRLOG("lynq_fast_ecall ecall is running");
1076 return LYNQ_E_ECALL_BEING_RUNNING;
1077 }
1078#endif
1079
lha35d4ee2022-01-25 18:47:39 -08001080 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001081 client.request = 10;//RIL_REQUEST_DIAL
1082 client.paramLen = 2;
1083 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1084 memcpy(client.param,addr,strlen(addr)+1);
1085 strcat(client.param," 0");
q.huang783ed5d2022-06-02 14:49:02 +08001086 lynq_call_id = addAddr(addr);
1087 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -08001088 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001089 {
1090 LYERRLOG("send request fail");
q.huang783ed5d2022-06-02 14:49:02 +08001091 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001092 return -1;
1093 }
lha35d4ee2022-01-25 18:47:39 -08001094 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -08001095 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1096 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lh25827952022-01-10 00:34:35 -08001097 if(error==0)
1098 {
1099 isDial = 1;
ll45d3ea92022-03-24 10:22:25 +08001100 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh25827952022-01-10 00:34:35 -08001101 {
lhbe92dd12022-04-19 06:01:25 -07001102 //if timeout,this call need destroy.
1103 isDial = 0;
lh25827952022-01-10 00:34:35 -08001104 error = LYNQ_E_TIME_OUT;
q.huang783ed5d2022-06-02 14:49:02 +08001105 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
1106 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001107 return error;
1108 }
q.huang783ed5d2022-06-02 14:49:02 +08001109 isDial = 0;
1110 *handle = lynq_call_lists[lynq_call_id].call_id;
1111 if(*handle > 0)
1112 {
1113 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
1114 return 0;
1115 }
1116 else
1117 {
1118 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
1119 cleanCallList(lynq_call_id);
1120 return LYNQ_E_INVALID_ID_ANONALY;
1121 }
1122
lh25827952022-01-10 00:34:35 -08001123 }
q.huang783ed5d2022-06-02 14:49:02 +08001124 LYERRLOG("lynq_call dial addr %s fail, service error %d",addr, error);
1125 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001126 return error;
1127}
1128int lynq_call_answer()
1129{
1130 Parcel p;
1131 lynq_client_t client;
1132 int resp_type = -1;
1133 int request = -1;
1134 int slot_id = -1;
1135 int error = -1;
lha35d4ee2022-01-25 18:47:39 -08001136 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001137 client.request = 40;//RIL_REQUEST_DIAL
1138 client.paramLen = 0;
1139 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +08001140 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -08001141 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001142 {
1143 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001144 return -1;
1145 }
lha35d4ee2022-01-25 18:47:39 -08001146 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -08001147 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1148 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1149 return error;
1150}
1151int lynq_call_hungup(int* handle)
1152{
1153 Parcel p;
1154 lynq_client_t client;
1155 int resp_type = -1;
1156 int request = -1;
1157 int slot_id = -1;
1158 int error = -1;
1159 int call_id = 0;
q.huang783ed5d2022-06-02 14:49:02 +08001160 int lynq_call_id;
lha35d4ee2022-01-25 18:47:39 -08001161 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1162 {
1163 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
1164 return LYNQ_E_CONFLICT;
1165 }
1166 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001167 client.request = 12;//RIL_REQUEST_HUNGUP
1168 client.paramLen = 1;
1169 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +08001170 call_id = *handle;
lh25827952022-01-10 00:34:35 -08001171 sprintf(client.param,"%d",call_id);
q.huang783ed5d2022-06-02 14:49:02 +08001172 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -08001173 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001174 {
1175 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001176 return -1;
1177 }
lha35d4ee2022-01-25 18:47:39 -08001178 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -08001179 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1180 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1181 if(error==0)
1182 {
q.huang783ed5d2022-06-02 14:49:02 +08001183 lynq_call_id=find_call_id_with_call_id(call_id);
1184 if(lynq_call_id!=INVALID_ID)
1185 {
1186 cleanCallList(lynq_call_id);
1187 }
lh25827952022-01-10 00:34:35 -08001188 }
1189 return error;
1190}
1191int lynq_call_hungup_all()
1192{
1193 Parcel p;
1194 lynq_client_t client;
1195 int resp_type = -1;
1196 int request = -1;
1197 int slot_id = -1;
1198 int error = -1;
lha35d4ee2022-01-25 18:47:39 -08001199 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001200 client.request = 17;//RIL_REQUEST_UDUB
1201 client.paramLen = 0;
1202 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +08001203 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -08001204 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001205 {
1206 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001207 return -1;
1208 }
lha35d4ee2022-01-25 18:47:39 -08001209 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -08001210 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1211 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1212 return error;
1213}
1214int lynq_wait_incoming_call(int *handle)
1215{
1216 waitIncomingCall();
1217 *handle = lynqIncomingCallId;
1218 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
1219 return 0;
1220}
1221
1222int lynq_set_auto_answercall(const int mode)
1223{
1224 global_call_auto_answer = mode;
1225 LYINFLOG("auto answer call mode =%d",mode);
1226 return 0;
1227}
q.huangb0eb7b02022-03-29 04:17:32 -04001228int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1229{
1230 int lynq_call_id = 0;
q.huang783ed5d2022-06-02 14:49:02 +08001231 LYINFLOG("lynq_get_current_call_state begin ");
q.huangb0eb7b02022-03-29 04:17:32 -04001232 if(handle==NULL)
1233 {
q.huang783ed5d2022-06-02 14:49:02 +08001234 LYERRLOG("handle is NULL");
q.huangb0eb7b02022-03-29 04:17:32 -04001235 return LYNQ_E_NULL_ANONALY;
1236 }
q.huang783ed5d2022-06-02 14:49:02 +08001237 lynq_call_id = find_call_id_with_call_id(*handle);
1238 if(lynq_call_id==INVALID_ID)
1239 {
1240 return LYNQ_E_INVALID_ID_ANONALY;
1241 }
q.huangb0eb7b02022-03-29 04:17:32 -04001242 *call_state = lynq_call_lists[lynq_call_id].call_state;
1243 *toa = lynq_call_lists[lynq_call_id].toa;
1244 *direction = lynq_call_lists[lynq_call_id].direction;
1245 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
1246 return 0;
1247}
1248
1249/*audio begin*/
ll7e055f22022-01-24 12:16:22 +00001250static int judge_mic(const int enable){
llc6030062022-02-14 08:58:16 +00001251 switch(enable){
1252 case 0:
1253 return 1;
1254 case 1:
1255 return 1;
1256 default:
1257 return 0;
ll7e055f22022-01-24 12:16:22 +00001258 }
1259}
1260
lh25827952022-01-10 00:34:35 -08001261int lynq_set_mute_mic(const int enable)
ll7e055f22022-01-24 12:16:22 +00001262{
1263 if(!judge_mic(enable)){
1264 return LYNQ_E_CONFLICT;
1265 }
q.huangb0eb7b02022-03-29 04:17:32 -04001266 return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1267}
1268int lynq_get_mute_mic(int *status)
1269{
1270 return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
lh25827952022-01-10 00:34:35 -08001271}
ll45d3ea92022-03-24 10:22:25 +08001272
1273/**
1274 * @brief Check whether DTMF is valid
1275 *
1276 * @param callnum dtmf eg:0-9 * #
1277 * @return int
1278 */
1279static int judge_dtmf(const char callnum)
1280{
1281 if(callnum == '#')
1282 {
1283 return 1;
1284 }
1285 if(callnum == '*')
1286 {
1287 return 1;
1288 }
1289 if(callnum >= '0'&& callnum <= '9')
1290 {
1291 return 1;
1292 }
1293 return 0;
1294}
1295
lh25827952022-01-10 00:34:35 -08001296int lynq_set_DTMF(const char callnum)
1297{
ll45d3ea92022-03-24 10:22:25 +08001298 if(!judge_dtmf(callnum))
1299 {
1300 return LYNQ_E_CONFLICT;
1301 }
lh25827952022-01-10 00:34:35 -08001302 if(!lynq_call_state)
1303 {
1304 LYERRLOG("LYNQ_E_CONFLICT");
1305 return LYNQ_E_CONFLICT;
1306 }
q.huangb0eb7b02022-03-29 04:17:32 -04001307 return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
lh25827952022-01-10 00:34:35 -08001308}
q.huangb0eb7b02022-03-29 04:17:32 -04001309static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1310 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1311 if(volume < 0 ||volume >36){
1312 return 0;
1313 }
1314 }
1315 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1316 {
1317 if(volume < 1 ||volume >7){
1318 return 0;
1319 }
ll7e055f22022-01-24 12:16:22 +00001320 }
ll375c94d2022-01-27 05:54:38 +00001321 return 1;
ll7e055f22022-01-24 12:16:22 +00001322}
lh25827952022-01-10 00:34:35 -08001323int lynq_set_DTMF_volume(const int volume)
ll7e055f22022-01-24 12:16:22 +00001324{
q.huangb0eb7b02022-03-29 04:17:32 -04001325 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
ll7e055f22022-01-24 12:16:22 +00001326 return LYNQ_E_CONFLICT;
1327 }
q.huangb0eb7b02022-03-29 04:17:32 -04001328 return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
lh25827952022-01-10 00:34:35 -08001329}
q.huang9ee6d5b2022-04-05 23:11:02 -04001330int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh25827952022-01-10 00:34:35 -08001331{
q.huangb0eb7b02022-03-29 04:17:32 -04001332 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
lh25827952022-01-10 00:34:35 -08001333 {
q.huangb0eb7b02022-03-29 04:17:32 -04001334 return LYNQ_E_CONFLICT;
lh25827952022-01-10 00:34:35 -08001335 }
q.huangb0eb7b02022-03-29 04:17:32 -04001336 return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
lh25827952022-01-10 00:34:35 -08001337}
q.huangb0eb7b02022-03-29 04:17:32 -04001338int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1339{
1340 return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
1341}
q.huang9ee6d5b2022-04-05 23:11:02 -04001342int lynq_incall_record_start(const char* file_path)
q.huangb0eb7b02022-03-29 04:17:32 -04001343{
q.huang783ed5d2022-06-02 14:49:02 +08001344 return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
q.huangb0eb7b02022-03-29 04:17:32 -04001345}
1346int lynq_incall_record_stop()
1347{
q.huang9ee6d5b2022-04-05 23:11:02 -04001348 const char* unused_file="just_ocuupy_paramter_postion";
1349 return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
q.huangb0eb7b02022-03-29 04:17:32 -04001350}
1351/*audio end*/
q.huangfe1b4052022-04-18 00:09:50 -04001352
1353#ifdef ECALL_SUPPORT
1354LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
1355{
1356 switch(type)
1357 {
1358 case LYNQ_ECALL_TYPE_TEST:
1359 return LYNQ_ECALL_TEST;
1360 case LYNQ_ECALL_TYPE_RECONFIG:
1361 return LYNQ_ECALL_RECONFIG;
1362 default:
1363 return LYNQ_ECALL_EMERGENCY;
1364 }
1365}
1366
1367RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
1368{
1369 switch(type)
1370 {
1371 case LYNQ_ECALL_TEST:
1372 return ECALL_TEST;
1373 case LYNQ_ECALL_RECONFIG:
1374 return ECALL_RECONFIG;
1375 default:
1376 return ECALL_EMERGENCY;
1377 }
1378}
1379
1380RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
1381{
1382 switch(cat)
1383 {
1384 case LYNQ_EMER_CAT_MANUAL_ECALL:
1385 return EMER_CAT_MANUAL_ECALL;
1386 default:
1387 return EMER_CAT_AUTO_ECALL;
1388 }
1389}
1390
1391
1392int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
1393{
1394 int error;
1395
1396 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
1397 {
q.huang783ed5d2022-06-02 14:49:02 +08001398 LYERRLOG("test_num is null or test_num_length %d s greater than %d ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
q.huangfe1b4052022-04-18 00:09:50 -04001399 return -1;
1400 }
1401
1402 error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
1403
1404 if(error==0)
1405 {
1406 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
1407 }
1408
1409 return error;
1410}
1411
q.huang892722f2022-05-10 20:37:21 +08001412int lynq_fast_ecall(int* handle, LYNQ_ECall_Category lynq_ecall_cat, LYNQ_ECall_Variant lynq_ecall_variant, const char *addr, int addr_length, const unsigned char *msd_data,int msd_length)
q.huangfe1b4052022-04-18 00:09:50 -04001413{
q.huang783ed5d2022-06-02 14:49:02 +08001414 int error;
q.huangfe1b4052022-04-18 00:09:50 -04001415 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
q.huang9a9b8762022-04-19 05:20:12 -04001416 RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
q.huang6a119762022-05-11 20:10:38 +08001417 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
1418 unsigned int i;
q.huang783ed5d2022-06-02 14:49:02 +08001419 if(lynq_ecall_is_running())
q.huang892722f2022-05-10 20:37:21 +08001420 {
q.huang783ed5d2022-06-02 14:49:02 +08001421 LYERRLOG("lynq_fast_ecall ecall is running");
1422 return LYNQ_E_ECALL_BEING_RUNNING;
1423 }
1424
1425 if(msd_length > MSD_MAX_LENGTH || msd_length <=0)
1426 {
1427 LYERRLOG("lynq_fast_ecall msd_length %d is greater than %d or <= 0, parameter error",msd_length,MSD_MAX_LENGTH);
1428 return LYNQ_E_ECALL_MSD_LENGTH_ERROR;
q.huang892722f2022-05-10 20:37:21 +08001429 }
q.huang892722f2022-05-10 20:37:21 +08001430
q.huang6a119762022-05-11 20:10:38 +08001431 for(i =0; i<msd_length;i++)
q.huang892722f2022-05-10 20:37:21 +08001432 {
q.huang6a119762022-05-11 20:10:38 +08001433 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
q.huang892722f2022-05-10 20:37:21 +08001434 }
1435
q.huang18d08bf2022-04-19 20:27:44 -04001436
q.huang783ed5d2022-06-02 14:49:02 +08001437 LYINFLOG("lynq_fast_ecall addr is %s",e_call_addr[lynq_ecall_variant]);
q.huang18d08bf2022-04-19 20:27:44 -04001438
q.huang892722f2022-05-10 20:37:21 +08001439 error=lynq_set_common_request(RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", lynq_msd_data);
q.huangfe1b4052022-04-18 00:09:50 -04001440
1441 if(error==0)
q.huang783ed5d2022-06-02 14:49:02 +08001442 {
1443 is_ecall_dial = 1;
1444 if(waitCallstateChange(180000)==ETIMEDOUT)//180000ms
q.huangfe1b4052022-04-18 00:09:50 -04001445 {
q.huang783ed5d2022-06-02 14:49:02 +08001446 LYERRLOG("lynq_fast_ecall timeout:wait Call state time out!!!");
1447 is_ecall_dial = 0;
1448 lynqRespWatingEvent();
1449 return LYNQ_E_TIME_OUT;
q.huangfe1b4052022-04-18 00:09:50 -04001450 }
q.huang783ed5d2022-06-02 14:49:02 +08001451 is_ecall_dial = 0;
1452 lynqRespWatingEvent();
q.huang18d08bf2022-04-19 20:27:44 -04001453
q.huang783ed5d2022-06-02 14:49:02 +08001454 if(g_ecallId != INVALID_ID)
1455 {
1456 *handle=g_ecallId;
1457 LYINFLOG("lynq_fast_ecall id is %d",g_ecallId);
1458 return 0;
1459 }
1460 else
1461 {
1462 LYERRLOG("lynq_fast_ecall service return fail");
1463 return LYNQ_E_INVALID_ID_ANONALY;
1464 }
q.huangfe1b4052022-04-18 00:09:50 -04001465 }
1466
1467 return error;
1468}
1469
1470int lynq_set_psap(int enable)
1471{
1472 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
1473}
1474
1475int lynq_psap_pull_msd()
1476{
1477 return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
1478}
1479
1480int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
1481{
1482 LYNQ_ECall_Variant lynq_ecall_variant;
1483 int error = -1;
1484 int lynq_call_id = -1;
1485
1486 if(handle==NULL)
1487 {
q.huang783ed5d2022-06-02 14:49:02 +08001488 LYERRLOG("handle is NULL, parameter error ");
q.huangfe1b4052022-04-18 00:09:50 -04001489 return -1;
1490 }
1491
1492 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
1493
1494 if(error==0)
1495 {
1496 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
1497
q.huang783ed5d2022-06-02 14:49:02 +08001498 lynq_call_id = addAddr(e_call_addr[lynq_ecall_variant]);
q.huangfe1b4052022-04-18 00:09:50 -04001499 isDial = 1;
1500 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1501 {
1502 error = LYNQ_E_TIME_OUT;
1503 LYERRLOG("timeout:wait Call state fail!!!");
q.huangfe1b4052022-04-18 00:09:50 -04001504 return error;
1505 }
1506
1507 *handle = lynq_call_id;
1508 }
1509
1510 return error;
1511}
1512
1513
q.huangbd6a3062022-05-10 20:49:46 +08001514int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length)
q.huangfe1b4052022-04-18 00:09:50 -04001515{
q.huang6a119762022-05-11 20:10:38 +08001516 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
1517 unsigned int i;
1518
q.huang783ed5d2022-06-02 14:49:02 +08001519 if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX) || msd_length > MSD_MAX_LENGTH || msd_length == 0 || msd_data ==NULL)
q.huangfe1b4052022-04-18 00:09:50 -04001520 {
q.huang783ed5d2022-06-02 14:49:02 +08001521 LYERRLOG("lynq_set_msd handle is NULL or *handle %d is greater or equeal to %d or msd_length %d is greater than %d or msd_data %s is NULL, parameter error",*handle,LYNQ_CALL_MAX,msd_length,MSD_MAX_LENGTH, msd_data);
q.huangbd6a3062022-05-10 20:49:46 +08001522 return -1;
1523 }
q.huangbd6a3062022-05-10 20:49:46 +08001524
q.huang6a119762022-05-11 20:10:38 +08001525 for(i=0; i<msd_length;i++)
q.huangbd6a3062022-05-10 20:49:46 +08001526 {
q.huang6a119762022-05-11 20:10:38 +08001527 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
q.huang783ed5d2022-06-02 14:49:02 +08001528 }
1529
1530 LYINFLOG("lynq_set_msd ");
q.huangfe1b4052022-04-18 00:09:50 -04001531
q.huangbd6a3062022-05-10 20:49:46 +08001532 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,lynq_msd_data);
q.huangfe1b4052022-04-18 00:09:50 -04001533}
1534
1535int lynq_set_ivs(int enable)
1536{
q.huang783ed5d2022-06-02 14:49:02 +08001537 if(enable<0)
1538 {
1539 lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
1540 return 0;
1541 }
1542
1543 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
q.huangfe1b4052022-04-18 00:09:50 -04001544}
1545
1546int lynq_reset_ivs()
1547{
1548 return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
1549}
1550
1551int lynq_ivs_push_msd()
1552{
1553 return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
1554}
q.huang18d08bf2022-04-19 20:27:44 -04001555
1556int wait_ecall_event()
1557{
1558 int ret = 0;
1559 pthread_mutex_lock(&s_incoming_e_call_mutex);
1560 ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
q.huang783ed5d2022-06-02 14:49:02 +08001561 pthread_mutex_unlock(&s_incoming_e_call_mutex);
q.huang18d08bf2022-04-19 20:27:44 -04001562 return ret;
1563}
1564
1565int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)
1566{
1567 wait_ecall_event();
q.huang783ed5d2022-06-02 14:49:02 +08001568 *eCall_Indication = g_lynqIncomingEcallIndication;
1569 LYINFLOG("lynq_wait_ecall_indication id: %d",g_lynqIncomingEcallIndication);
q.huang18d08bf2022-04-19 20:27:44 -04001570 return 0;
1571}
1572
q.huangfe1b4052022-04-18 00:09:50 -04001573#endif
1574
q.huang877d6b32022-06-06 16:15:31 +08001575/*Audio Path setting begin*/
1576/*set*/
1577int lynq_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode)
1578{
1579 return 0;
1580}
q.huang65033cb2022-06-06 20:23:15 +08001581int lynq_set_rtp_ip(const LYNQ_Rtp_Mode rtp_mode, const char* ip, const int ip_length)
q.huang877d6b32022-06-06 16:15:31 +08001582{
1583 return 0;
1584}
q.huang65033cb2022-06-06 20:23:15 +08001585int lynq_set_rtp_port(const LYNQ_Rtp_Mode rtp_mode, const int port)
q.huang877d6b32022-06-06 16:15:31 +08001586{
1587 return 0;
1588}
1589int lynq_set_rtp_param(const int clock_rate,const int channels,const int latency) //only for client mode
1590{
1591 return 0;
1592}
1593/*get*/
1594LYNQ_Audio_Mode lynq_get_voice_audio_mode()
1595{
1596 return AUDIO_MODE_CODEC;
1597}
1598int lynq_get_rtp_ip(const LYNQ_Rtp_Mode rtp_mode, char* ip, const int ip_length)
1599{
1600 if(ip==NULL)
1601 {
1602 return 1;
1603 }
1604 return 0;
1605}
1606int lynq_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port)
1607{
1608 if(port==NULL)
1609 {
1610 return 1;
1611 }
1612 return 0;
1613}
1614int lynq_get_rtp_param(int* clock_rate, int* channels, int* latency)//only for client mode
1615{
1616 if(clock_rate == NULL || channels ==NULL || latency ==NULL)
1617 {
1618 return 1;
1619 }
1620
1621 return 0;
1622}
1623/*Audio Path setting end*/
1624
lh25827952022-01-10 00:34:35 -08001625#if 0
1626int main(int argc,char **argv)
1627{
1628 int n = 0;
1629 n = lynq_init_call(lynq_call_state_change_test,2222);
1630 if(n<0)
1631 {
q.huang783ed5d2022-06-02 14:49:02 +08001632 LYDBGLOG("lynq init call fail!!!");
lh25827952022-01-10 00:34:35 -08001633 return -1;
1634 }
q.huang783ed5d2022-06-02 14:49:02 +08001635 LYDBGLOG("lynq call init success!!!");
lh25827952022-01-10 00:34:35 -08001636 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1637 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1638 lynq_call(phoneNum);
1639 while(1)
1640 {
1641 sleep(1);
1642 }
1643 return 0;
1644}
1645#endif
1646/*Warren add for T800 platform 2021/11/19 end*/