blob: 742f4b31369dd95e65919c075e0ce4ce34b98639 [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");
787 is_ecall_dial=1;
788 if(isDial)
789 {
790 LYINFLOG("stop normal dial");
791 sendSignalToWaitCallStateChange();
792 }
793 else
794 {
795 LYINFLOG("no normal dial");
796 }
797 }
798 else
799 {
800 LYERRLOG("ecall is running, recv psap call back msd start");
801 }
802 }
803 else if (LYNQ_ECALL_ABNORMAL_HANGUP == g_lynqIncomingEcallIndication)
804 {
805 if(is_ecall_dial==0)
806 {
807 LYERRLOG("ecall is not in dialing, recv abnormal hangup");
808 g_ecallId = INVALID_ID;
809 }
810 else
811 {
812 LYINFLOG("ecall is in dialing, recv abnormal hangup");
813 }
814 }
815 else if (LYNQ_ECALL_DISCONNECTED == g_lynqIncomingEcallIndication ||
816 LYNQ_ECALL_REDIAL_TIMER_OUT == g_lynqIncomingEcallIndication ||
817 LYNQ_ECALL_T2_TIMER_OUT == g_lynqIncomingEcallIndication)
818 {
819 g_ecallId = INVALID_ID;
820 if(is_ecall_dial)
821 {
822 LYERRLOG("ecall is in dialing, recv like disconnect indication");
823 is_ecall_dial=0;
824 sendSignalToWaitCallStateChange();
825 }
826 else
827 {
828 LYINFLOG("ecall is not in dialing, recv like disconnect indication");
829 }
830 }
831 else
832 {
833 LYINFLOG("not special indication");
834 }
q.huang18d08bf2022-04-19 20:27:44 -0400835 sendSignalIncomingECallEvent();
q.huang783ed5d2022-06-02 14:49:02 +0800836 LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS, local ecall id is %d", g_ecallId);
q.huang18d08bf2022-04-19 20:27:44 -0400837 break;
838 }
839#endif
lh25827952022-01-10 00:34:35 -0800840 default:
841 break;
842 }
843 }
844 delete p;
845 p = NULL;
846 }
847 close(socket_fd);
848}
849int lynq_socket_urc_start()
850{
851 int socket_fd=0;
852 int rt=0;
853 int len=0;
854 int on=1;
855 struct sockaddr_in urc_local_addr;
lh25827952022-01-10 00:34:35 -0800856 pthread_attr_t attr;
ll375c94d2022-01-27 05:54:38 +0000857 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll375c94d2022-01-27 05:54:38 +0000858 if(socket_fd < 0)
859 {
q.huang783ed5d2022-06-02 14:49:02 +0800860 LYERRLOG("creaet socket for udp fail");
ll375c94d2022-01-27 05:54:38 +0000861 return -1;
lh25827952022-01-10 00:34:35 -0800862 }
863 urc_local_addr.sin_family = AF_INET;
864 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
865 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
866 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll375c94d2022-01-27 05:54:38 +0000867 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
868 if(rt<0)
869 {
q.huang783ed5d2022-06-02 14:49:02 +0800870 LYERRLOG("SO_REUSEADDR fail");
lh25827952022-01-10 00:34:35 -0800871 return -1;
872 }
873 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll375c94d2022-01-27 05:54:38 +0000874 if (rt == -1)
875 {
lh59e0d002022-01-27 00:27:12 -0800876 LYERRLOG("bind failed");
ll375c94d2022-01-27 05:54:38 +0000877 return -1;
lh25827952022-01-10 00:34:35 -0800878 }
879 pthread_attr_init(&attr);
880 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -0800881 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh25827952022-01-10 00:34:35 -0800882 if(rt < 0)
883 {
q.huang783ed5d2022-06-02 14:49:02 +0800884 LYERRLOG("urc loop failure!!!");
lh25827952022-01-10 00:34:35 -0800885 return -1;
886 }
q.huang783ed5d2022-06-02 14:49:02 +0800887 LYDBGLOG("urc loop success!!!");
lh25827952022-01-10 00:34:35 -0800888 return 0;
889}
890int getSelfElement(char addr[])
891{
892 for(int i=0;i < LYNQ_CALL_MAX; i++)
893 {
894 if(lynq_call_lists[i].used==1)
895 {
896 if(strcmp(lynq_call_lists[i].addr,addr)==0)
897 {
898 return i;
899 }
900
901 }
902 }
903 return -1;
904}
905
906void lynq_call_state_change_test(int soc_id)
907{
q.huang783ed5d2022-06-02 14:49:02 +0800908 LYDBGLOG("call state change,sim:%d",soc_id);
lh25827952022-01-10 00:34:35 -0800909}
910int lynq_init_call(int uToken)
ll1343a5b2022-03-17 05:31:33 +0000911{
912 if(g_lynq_call_init_flag == 1){
913 LYDBGLOG("lynq init call failed!!!");
914 return -1;
915 }
916 g_lynq_call_init_flag = 1;
lh25827952022-01-10 00:34:35 -0800917 int result = 0;
lha35d4ee2022-01-25 18:47:39 -0800918 Global_uToken_call = uToken;
lh59e0d002022-01-27 00:27:12 -0800919 urc_call_recive_status = 1;
rjw8bdc56b2022-02-28 15:01:49 +0800920 client_size = sizeof(client_t);
lh25827952022-01-10 00:34:35 -0800921 LYLOGSET(LOG_INFO);
922 LYLOGEINIT(USER_LOG_TAG);
923 result = lynq_socket_client_start();
924 if(result!=0)
925 {
926 return -1;
927 }
928 result = lynq_socket_urc_start();
929 if(result!=0)
930 {
931 return -1;
932 }
933 result = lynq_update_call_list_loop();
934 if(result!=0)
935 {
936 return -1;
937 }
938 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
939 LYDBGLOG("lynq init call success!!!");
940 return 0;
941}
942int lynq_deinit_call()
943{
q.huang783ed5d2022-06-02 14:49:02 +0800944 int ret;
ll1343a5b2022-03-17 05:31:33 +0000945 if(g_lynq_call_init_flag == 0)
lhcdf816a2022-02-13 23:56:05 -0800946 {
ll1343a5b2022-03-17 05:31:33 +0000947 LYDBGLOG("lynq_deinit_call failed!!!");
948 return -1;
lhcdf816a2022-02-13 23:56:05 -0800949 }
ll1343a5b2022-03-17 05:31:33 +0000950 else
951 {
952 g_lynq_call_init_flag = 0;
q.huang783ed5d2022-06-02 14:49:02 +0800953 lynq_call_hungup_all();
ll1343a5b2022-03-17 05:31:33 +0000954 if(lynq_call_client_sockfd>0)
955 {
956 close(lynq_call_client_sockfd);
957 }
958 urc_call_recive_status = 0;
959 call_list_loop = 0;
960 if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
961 {
962 return -1;
963 }
964 ret = pthread_cancel(lynq_call_urc_tid);
965 LYDBGLOG("pthread cancel ret = %d",ret);
966 ret = pthread_cancel(lynq_call_list_loop_tid);
967 LYDBGLOG("pthread cancel ret = %d",ret);
968 ret = pthread_join(lynq_call_urc_tid,NULL);
969 LYDBGLOG("pthread join ret = %d",ret);
970 ret = pthread_join(lynq_call_list_loop_tid,NULL);
971 LYDBGLOG("pthread join ret = %d",ret);
972 return 0;
973 }
rita47debb92022-04-07 06:08:13 -0400974}
q.huangfe1b4052022-04-18 00:09:50 -0400975
976int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita9b436d82022-04-07 01:55:39 -0400977{
978 Parcel p;
979 lynq_client_t client;
980 int resp_type = -1;
981 int request = -1;
982 int slot_id = -1;
983 int error = -1;
rita9b436d82022-04-07 01:55:39 -0400984
985 client.uToken = Global_uToken_call;
q.huangfe1b4052022-04-18 00:09:50 -0400986 client.request = request_id;
987 client.paramLen = argc;
rita9b436d82022-04-07 01:55:39 -0400988 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangfe1b4052022-04-18 00:09:50 -0400989 if(argc!=0)
990 {
991 va_list args;
992 va_start(args, format);
993 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
994 va_end(args);
995 }
q.huang783ed5d2022-06-02 14:49:02 +0800996 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -0400997 if(send_request(lynq_call_client_sockfd,&client)==-1)
998 {
999 LYERRLOG("send request fail");
1000 return -1;
1001 }
q.huangfe1b4052022-04-18 00:09:50 -04001002 if(get_response(lynq_call_client_sockfd,p)==0)
1003 {
1004 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1005 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1006 }
rita9b436d82022-04-07 01:55:39 -04001007 return error;
1008}
1009
q.huangfe1b4052022-04-18 00:09:50 -04001010int lynq_get_common_request(int request_id, int* status)
rita9b436d82022-04-07 01:55:39 -04001011{
1012 Parcel p;
1013 lynq_client_t client;
1014 int resp_type = -1;
1015 int request = -1;
1016 int slot_id = -1;
1017 int error = -1;
q.huangfe1b4052022-04-18 00:09:50 -04001018 if(status==NULL)
1019 {
1020 LYERRLOG("status is null");
1021 return -1;
1022 }
rita9b436d82022-04-07 01:55:39 -04001023 client.uToken = Global_uToken_call;
q.huangfe1b4052022-04-18 00:09:50 -04001024 client.request = request_id;
1025 client.paramLen = 0;
rita9b436d82022-04-07 01:55:39 -04001026 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +08001027 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -04001028 if(send_request(lynq_call_client_sockfd,&client)==-1)
1029 {
1030 LYERRLOG("send request fail");
1031 return -1;
1032 }
q.huangfe1b4052022-04-18 00:09:50 -04001033 if(get_response(lynq_call_client_sockfd,p)==0)
rita9b436d82022-04-07 01:55:39 -04001034 {
q.huangfe1b4052022-04-18 00:09:50 -04001035 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1036 p.readInt32(status);
1037 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
rita9b436d82022-04-07 01:55:39 -04001038 }
rita9b436d82022-04-07 01:55:39 -04001039 return error;
1040}
1041
lh25827952022-01-10 00:34:35 -08001042int lynq_call(int* handle,char addr[])
1043{
1044 Parcel p;
1045 lynq_client_t client;
1046 int resp_type = -1;
1047 int request = -1;
1048 int slot_id = -1;
1049 int error = -1;
1050 int lynq_call_id = -1;
q.huang783ed5d2022-06-02 14:49:02 +08001051
1052 LYINFLOG("lynq_call begin addr %s",addr);
lh25827952022-01-10 00:34:35 -08001053 if(addr==NULL)
1054 {
1055 LYERRLOG("Phone num is null!!!");
1056 return -1;
1057 }
q.huang783ed5d2022-06-02 14:49:02 +08001058
1059 if(find_call_id_with_addr(addr)!=INVALID_ID)
1060 {
1061 LYERRLOG("addr %s exists",addr);
1062 return LYNQ_E_CONFLICT;
1063 }
1064
1065#ifdef ECALL_SUPPORT
1066 if(lynq_ecall_is_running())
1067 {
1068 LYERRLOG("lynq_fast_ecall ecall is running");
1069 return LYNQ_E_ECALL_BEING_RUNNING;
1070 }
1071#endif
1072
lha35d4ee2022-01-25 18:47:39 -08001073 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001074 client.request = 10;//RIL_REQUEST_DIAL
1075 client.paramLen = 2;
1076 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1077 memcpy(client.param,addr,strlen(addr)+1);
1078 strcat(client.param," 0");
q.huang783ed5d2022-06-02 14:49:02 +08001079 lynq_call_id = addAddr(addr);
1080 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -08001081 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001082 {
1083 LYERRLOG("send request fail");
q.huang783ed5d2022-06-02 14:49:02 +08001084 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001085 return -1;
1086 }
lha35d4ee2022-01-25 18:47:39 -08001087 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -08001088 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1089 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lh25827952022-01-10 00:34:35 -08001090 if(error==0)
1091 {
1092 isDial = 1;
ll45d3ea92022-03-24 10:22:25 +08001093 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh25827952022-01-10 00:34:35 -08001094 {
lhbe92dd12022-04-19 06:01:25 -07001095 //if timeout,this call need destroy.
1096 isDial = 0;
lh25827952022-01-10 00:34:35 -08001097 error = LYNQ_E_TIME_OUT;
q.huang783ed5d2022-06-02 14:49:02 +08001098 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
1099 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001100 return error;
1101 }
q.huang783ed5d2022-06-02 14:49:02 +08001102 isDial = 0;
1103 *handle = lynq_call_lists[lynq_call_id].call_id;
1104 if(*handle > 0)
1105 {
1106 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
1107 return 0;
1108 }
1109 else
1110 {
1111 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
1112 cleanCallList(lynq_call_id);
1113 return LYNQ_E_INVALID_ID_ANONALY;
1114 }
1115
lh25827952022-01-10 00:34:35 -08001116 }
q.huang783ed5d2022-06-02 14:49:02 +08001117 LYERRLOG("lynq_call dial addr %s fail, service error %d",addr, error);
1118 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001119 return error;
1120}
1121int lynq_call_answer()
1122{
1123 Parcel p;
1124 lynq_client_t client;
1125 int resp_type = -1;
1126 int request = -1;
1127 int slot_id = -1;
1128 int error = -1;
lha35d4ee2022-01-25 18:47:39 -08001129 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001130 client.request = 40;//RIL_REQUEST_DIAL
1131 client.paramLen = 0;
1132 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +08001133 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -08001134 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001135 {
1136 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001137 return -1;
1138 }
lha35d4ee2022-01-25 18:47:39 -08001139 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -08001140 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1141 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1142 return error;
1143}
1144int lynq_call_hungup(int* handle)
1145{
1146 Parcel p;
1147 lynq_client_t client;
1148 int resp_type = -1;
1149 int request = -1;
1150 int slot_id = -1;
1151 int error = -1;
1152 int call_id = 0;
q.huang783ed5d2022-06-02 14:49:02 +08001153 int lynq_call_id;
lha35d4ee2022-01-25 18:47:39 -08001154 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1155 {
1156 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
1157 return LYNQ_E_CONFLICT;
1158 }
1159 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001160 client.request = 12;//RIL_REQUEST_HUNGUP
1161 client.paramLen = 1;
1162 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +08001163 call_id = *handle;
lh25827952022-01-10 00:34:35 -08001164 sprintf(client.param,"%d",call_id);
q.huang783ed5d2022-06-02 14:49:02 +08001165 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -08001166 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001167 {
1168 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001169 return -1;
1170 }
lha35d4ee2022-01-25 18:47:39 -08001171 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -08001172 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1173 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1174 if(error==0)
1175 {
q.huang783ed5d2022-06-02 14:49:02 +08001176 lynq_call_id=find_call_id_with_call_id(call_id);
1177 if(lynq_call_id!=INVALID_ID)
1178 {
1179 cleanCallList(lynq_call_id);
1180 }
lh25827952022-01-10 00:34:35 -08001181 }
1182 return error;
1183}
1184int lynq_call_hungup_all()
1185{
1186 Parcel p;
1187 lynq_client_t client;
1188 int resp_type = -1;
1189 int request = -1;
1190 int slot_id = -1;
1191 int error = -1;
lha35d4ee2022-01-25 18:47:39 -08001192 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001193 client.request = 17;//RIL_REQUEST_UDUB
1194 client.paramLen = 0;
1195 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang783ed5d2022-06-02 14:49:02 +08001196 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -08001197 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001198 {
1199 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001200 return -1;
1201 }
lha35d4ee2022-01-25 18:47:39 -08001202 get_response(lynq_call_client_sockfd,p);
lh25827952022-01-10 00:34:35 -08001203 JumpHeader(p,&resp_type,&request,&slot_id,&error);
1204 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1205 return error;
1206}
1207int lynq_wait_incoming_call(int *handle)
1208{
1209 waitIncomingCall();
1210 *handle = lynqIncomingCallId;
1211 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
1212 return 0;
1213}
1214
1215int lynq_set_auto_answercall(const int mode)
1216{
1217 global_call_auto_answer = mode;
1218 LYINFLOG("auto answer call mode =%d",mode);
1219 return 0;
1220}
q.huangb0eb7b02022-03-29 04:17:32 -04001221int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1222{
1223 int lynq_call_id = 0;
q.huang783ed5d2022-06-02 14:49:02 +08001224 LYINFLOG("lynq_get_current_call_state begin ");
q.huangb0eb7b02022-03-29 04:17:32 -04001225 if(handle==NULL)
1226 {
q.huang783ed5d2022-06-02 14:49:02 +08001227 LYERRLOG("handle is NULL");
q.huangb0eb7b02022-03-29 04:17:32 -04001228 return LYNQ_E_NULL_ANONALY;
1229 }
q.huang783ed5d2022-06-02 14:49:02 +08001230 lynq_call_id = find_call_id_with_call_id(*handle);
1231 if(lynq_call_id==INVALID_ID)
1232 {
1233 return LYNQ_E_INVALID_ID_ANONALY;
1234 }
q.huangb0eb7b02022-03-29 04:17:32 -04001235 *call_state = lynq_call_lists[lynq_call_id].call_state;
1236 *toa = lynq_call_lists[lynq_call_id].toa;
1237 *direction = lynq_call_lists[lynq_call_id].direction;
1238 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
1239 return 0;
1240}
1241
1242/*audio begin*/
ll7e055f22022-01-24 12:16:22 +00001243static int judge_mic(const int enable){
llc6030062022-02-14 08:58:16 +00001244 switch(enable){
1245 case 0:
1246 return 1;
1247 case 1:
1248 return 1;
1249 default:
1250 return 0;
ll7e055f22022-01-24 12:16:22 +00001251 }
1252}
1253
lh25827952022-01-10 00:34:35 -08001254int lynq_set_mute_mic(const int enable)
ll7e055f22022-01-24 12:16:22 +00001255{
1256 if(!judge_mic(enable)){
1257 return LYNQ_E_CONFLICT;
1258 }
q.huangb0eb7b02022-03-29 04:17:32 -04001259 return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1260}
1261int lynq_get_mute_mic(int *status)
1262{
1263 return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
lh25827952022-01-10 00:34:35 -08001264}
ll45d3ea92022-03-24 10:22:25 +08001265
1266/**
1267 * @brief Check whether DTMF is valid
1268 *
1269 * @param callnum dtmf eg:0-9 * #
1270 * @return int
1271 */
1272static int judge_dtmf(const char callnum)
1273{
1274 if(callnum == '#')
1275 {
1276 return 1;
1277 }
1278 if(callnum == '*')
1279 {
1280 return 1;
1281 }
1282 if(callnum >= '0'&& callnum <= '9')
1283 {
1284 return 1;
1285 }
1286 return 0;
1287}
1288
lh25827952022-01-10 00:34:35 -08001289int lynq_set_DTMF(const char callnum)
1290{
ll45d3ea92022-03-24 10:22:25 +08001291 if(!judge_dtmf(callnum))
1292 {
1293 return LYNQ_E_CONFLICT;
1294 }
lh25827952022-01-10 00:34:35 -08001295 if(!lynq_call_state)
1296 {
1297 LYERRLOG("LYNQ_E_CONFLICT");
1298 return LYNQ_E_CONFLICT;
1299 }
q.huangb0eb7b02022-03-29 04:17:32 -04001300 return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
lh25827952022-01-10 00:34:35 -08001301}
q.huangb0eb7b02022-03-29 04:17:32 -04001302static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1303 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1304 if(volume < 0 ||volume >36){
1305 return 0;
1306 }
1307 }
1308 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1309 {
1310 if(volume < 1 ||volume >7){
1311 return 0;
1312 }
ll7e055f22022-01-24 12:16:22 +00001313 }
ll375c94d2022-01-27 05:54:38 +00001314 return 1;
ll7e055f22022-01-24 12:16:22 +00001315}
lh25827952022-01-10 00:34:35 -08001316int lynq_set_DTMF_volume(const int volume)
ll7e055f22022-01-24 12:16:22 +00001317{
q.huangb0eb7b02022-03-29 04:17:32 -04001318 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
ll7e055f22022-01-24 12:16:22 +00001319 return LYNQ_E_CONFLICT;
1320 }
q.huangb0eb7b02022-03-29 04:17:32 -04001321 return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
lh25827952022-01-10 00:34:35 -08001322}
q.huang9ee6d5b2022-04-05 23:11:02 -04001323int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh25827952022-01-10 00:34:35 -08001324{
q.huangb0eb7b02022-03-29 04:17:32 -04001325 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
lh25827952022-01-10 00:34:35 -08001326 {
q.huangb0eb7b02022-03-29 04:17:32 -04001327 return LYNQ_E_CONFLICT;
lh25827952022-01-10 00:34:35 -08001328 }
q.huangb0eb7b02022-03-29 04:17:32 -04001329 return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
lh25827952022-01-10 00:34:35 -08001330}
q.huangb0eb7b02022-03-29 04:17:32 -04001331int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1332{
1333 return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
1334}
q.huang9ee6d5b2022-04-05 23:11:02 -04001335int lynq_incall_record_start(const char* file_path)
q.huangb0eb7b02022-03-29 04:17:32 -04001336{
q.huang783ed5d2022-06-02 14:49:02 +08001337 return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
q.huangb0eb7b02022-03-29 04:17:32 -04001338}
1339int lynq_incall_record_stop()
1340{
q.huang9ee6d5b2022-04-05 23:11:02 -04001341 const char* unused_file="just_ocuupy_paramter_postion";
1342 return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
q.huangb0eb7b02022-03-29 04:17:32 -04001343}
1344/*audio end*/
q.huangfe1b4052022-04-18 00:09:50 -04001345
1346#ifdef ECALL_SUPPORT
1347LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
1348{
1349 switch(type)
1350 {
1351 case LYNQ_ECALL_TYPE_TEST:
1352 return LYNQ_ECALL_TEST;
1353 case LYNQ_ECALL_TYPE_RECONFIG:
1354 return LYNQ_ECALL_RECONFIG;
1355 default:
1356 return LYNQ_ECALL_EMERGENCY;
1357 }
1358}
1359
1360RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
1361{
1362 switch(type)
1363 {
1364 case LYNQ_ECALL_TEST:
1365 return ECALL_TEST;
1366 case LYNQ_ECALL_RECONFIG:
1367 return ECALL_RECONFIG;
1368 default:
1369 return ECALL_EMERGENCY;
1370 }
1371}
1372
1373RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
1374{
1375 switch(cat)
1376 {
1377 case LYNQ_EMER_CAT_MANUAL_ECALL:
1378 return EMER_CAT_MANUAL_ECALL;
1379 default:
1380 return EMER_CAT_AUTO_ECALL;
1381 }
1382}
1383
1384
1385int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
1386{
1387 int error;
1388
1389 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
1390 {
q.huang783ed5d2022-06-02 14:49:02 +08001391 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 -04001392 return -1;
1393 }
1394
1395 error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
1396
1397 if(error==0)
1398 {
1399 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
1400 }
1401
1402 return error;
1403}
1404
q.huang892722f2022-05-10 20:37:21 +08001405int 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 -04001406{
q.huang783ed5d2022-06-02 14:49:02 +08001407 int error;
q.huangfe1b4052022-04-18 00:09:50 -04001408 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
q.huang9a9b8762022-04-19 05:20:12 -04001409 RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
q.huang6a119762022-05-11 20:10:38 +08001410 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
1411 unsigned int i;
q.huang783ed5d2022-06-02 14:49:02 +08001412 if(lynq_ecall_is_running())
q.huang892722f2022-05-10 20:37:21 +08001413 {
q.huang783ed5d2022-06-02 14:49:02 +08001414 LYERRLOG("lynq_fast_ecall ecall is running");
1415 return LYNQ_E_ECALL_BEING_RUNNING;
1416 }
1417
1418 if(msd_length > MSD_MAX_LENGTH || msd_length <=0)
1419 {
1420 LYERRLOG("lynq_fast_ecall msd_length %d is greater than %d or <= 0, parameter error",msd_length,MSD_MAX_LENGTH);
1421 return LYNQ_E_ECALL_MSD_LENGTH_ERROR;
q.huang892722f2022-05-10 20:37:21 +08001422 }
q.huang892722f2022-05-10 20:37:21 +08001423
q.huang6a119762022-05-11 20:10:38 +08001424 for(i =0; i<msd_length;i++)
q.huang892722f2022-05-10 20:37:21 +08001425 {
q.huang6a119762022-05-11 20:10:38 +08001426 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
q.huang892722f2022-05-10 20:37:21 +08001427 }
1428
q.huang18d08bf2022-04-19 20:27:44 -04001429
q.huang783ed5d2022-06-02 14:49:02 +08001430 LYINFLOG("lynq_fast_ecall addr is %s",e_call_addr[lynq_ecall_variant]);
q.huang18d08bf2022-04-19 20:27:44 -04001431
q.huang892722f2022-05-10 20:37:21 +08001432 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 -04001433
1434 if(error==0)
q.huang783ed5d2022-06-02 14:49:02 +08001435 {
1436 is_ecall_dial = 1;
1437 if(waitCallstateChange(180000)==ETIMEDOUT)//180000ms
q.huangfe1b4052022-04-18 00:09:50 -04001438 {
q.huang783ed5d2022-06-02 14:49:02 +08001439 LYERRLOG("lynq_fast_ecall timeout:wait Call state time out!!!");
1440 is_ecall_dial = 0;
1441 lynqRespWatingEvent();
1442 return LYNQ_E_TIME_OUT;
q.huangfe1b4052022-04-18 00:09:50 -04001443 }
q.huang783ed5d2022-06-02 14:49:02 +08001444 is_ecall_dial = 0;
1445 lynqRespWatingEvent();
q.huang18d08bf2022-04-19 20:27:44 -04001446
q.huang783ed5d2022-06-02 14:49:02 +08001447 if(g_ecallId != INVALID_ID)
1448 {
1449 *handle=g_ecallId;
1450 LYINFLOG("lynq_fast_ecall id is %d",g_ecallId);
1451 return 0;
1452 }
1453 else
1454 {
1455 LYERRLOG("lynq_fast_ecall service return fail");
1456 return LYNQ_E_INVALID_ID_ANONALY;
1457 }
q.huangfe1b4052022-04-18 00:09:50 -04001458 }
1459
1460 return error;
1461}
1462
1463int lynq_set_psap(int enable)
1464{
1465 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
1466}
1467
1468int lynq_psap_pull_msd()
1469{
1470 return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
1471}
1472
1473int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
1474{
1475 LYNQ_ECall_Variant lynq_ecall_variant;
1476 int error = -1;
1477 int lynq_call_id = -1;
1478
1479 if(handle==NULL)
1480 {
q.huang783ed5d2022-06-02 14:49:02 +08001481 LYERRLOG("handle is NULL, parameter error ");
q.huangfe1b4052022-04-18 00:09:50 -04001482 return -1;
1483 }
1484
1485 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
1486
1487 if(error==0)
1488 {
1489 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
1490
q.huang783ed5d2022-06-02 14:49:02 +08001491 lynq_call_id = addAddr(e_call_addr[lynq_ecall_variant]);
q.huangfe1b4052022-04-18 00:09:50 -04001492 isDial = 1;
1493 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1494 {
1495 error = LYNQ_E_TIME_OUT;
1496 LYERRLOG("timeout:wait Call state fail!!!");
q.huangfe1b4052022-04-18 00:09:50 -04001497 return error;
1498 }
1499
1500 *handle = lynq_call_id;
1501 }
1502
1503 return error;
1504}
1505
1506
q.huangbd6a3062022-05-10 20:49:46 +08001507int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length)
q.huangfe1b4052022-04-18 00:09:50 -04001508{
q.huang6a119762022-05-11 20:10:38 +08001509 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
1510 unsigned int i;
1511
q.huang783ed5d2022-06-02 14:49:02 +08001512 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 -04001513 {
q.huang783ed5d2022-06-02 14:49:02 +08001514 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 +08001515 return -1;
1516 }
q.huangbd6a3062022-05-10 20:49:46 +08001517
q.huang6a119762022-05-11 20:10:38 +08001518 for(i=0; i<msd_length;i++)
q.huangbd6a3062022-05-10 20:49:46 +08001519 {
q.huang6a119762022-05-11 20:10:38 +08001520 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
q.huang783ed5d2022-06-02 14:49:02 +08001521 }
1522
1523 LYINFLOG("lynq_set_msd ");
q.huangfe1b4052022-04-18 00:09:50 -04001524
q.huangbd6a3062022-05-10 20:49:46 +08001525 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 -04001526}
1527
1528int lynq_set_ivs(int enable)
1529{
q.huang783ed5d2022-06-02 14:49:02 +08001530 if(enable<0)
1531 {
1532 lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
1533 return 0;
1534 }
1535
1536 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
q.huangfe1b4052022-04-18 00:09:50 -04001537}
1538
1539int lynq_reset_ivs()
1540{
1541 return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
1542}
1543
1544int lynq_ivs_push_msd()
1545{
1546 return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
1547}
q.huang18d08bf2022-04-19 20:27:44 -04001548
1549int wait_ecall_event()
1550{
1551 int ret = 0;
1552 pthread_mutex_lock(&s_incoming_e_call_mutex);
1553 ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
q.huang783ed5d2022-06-02 14:49:02 +08001554 pthread_mutex_unlock(&s_incoming_e_call_mutex);
q.huang18d08bf2022-04-19 20:27:44 -04001555 return ret;
1556}
1557
1558int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)
1559{
1560 wait_ecall_event();
q.huang783ed5d2022-06-02 14:49:02 +08001561 *eCall_Indication = g_lynqIncomingEcallIndication;
1562 LYINFLOG("lynq_wait_ecall_indication id: %d",g_lynqIncomingEcallIndication);
q.huang18d08bf2022-04-19 20:27:44 -04001563 return 0;
1564}
1565
q.huangfe1b4052022-04-18 00:09:50 -04001566#endif
1567
q.huang877d6b32022-06-06 16:15:31 +08001568/*Audio Path setting begin*/
1569/*set*/
1570int lynq_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode)
1571{
1572 return 0;
1573}
1574int lynq_set_rtp_ip(const LYNQ_Rtp_Mode rtp_mode,const char* ip, const int ip_length)
1575{
1576 return 0;
1577}
1578int lynq_set_rtp_port(const int port)
1579{
1580 return 0;
1581}
1582int lynq_set_rtp_param(const int clock_rate,const int channels,const int latency) //only for client mode
1583{
1584 return 0;
1585}
1586/*get*/
1587LYNQ_Audio_Mode lynq_get_voice_audio_mode()
1588{
1589 return AUDIO_MODE_CODEC;
1590}
1591int lynq_get_rtp_ip(const LYNQ_Rtp_Mode rtp_mode, char* ip, const int ip_length)
1592{
1593 if(ip==NULL)
1594 {
1595 return 1;
1596 }
1597 return 0;
1598}
1599int lynq_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port)
1600{
1601 if(port==NULL)
1602 {
1603 return 1;
1604 }
1605 return 0;
1606}
1607int lynq_get_rtp_param(int* clock_rate, int* channels, int* latency)//only for client mode
1608{
1609 if(clock_rate == NULL || channels ==NULL || latency ==NULL)
1610 {
1611 return 1;
1612 }
1613
1614 return 0;
1615}
1616/*Audio Path setting end*/
1617
lh25827952022-01-10 00:34:35 -08001618#if 0
1619int main(int argc,char **argv)
1620{
1621 int n = 0;
1622 n = lynq_init_call(lynq_call_state_change_test,2222);
1623 if(n<0)
1624 {
q.huang783ed5d2022-06-02 14:49:02 +08001625 LYDBGLOG("lynq init call fail!!!");
lh25827952022-01-10 00:34:35 -08001626 return -1;
1627 }
q.huang783ed5d2022-06-02 14:49:02 +08001628 LYDBGLOG("lynq call init success!!!");
lh25827952022-01-10 00:34:35 -08001629 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1630 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1631 lynq_call(phoneNum);
1632 while(1)
1633 {
1634 sleep(1);
1635 }
1636 return 0;
1637}
1638#endif
1639/*Warren add for T800 platform 2021/11/19 end*/