blob: 8e6943d4018ecabd516be996b45a64c55fe3f07d [file] [log] [blame]
ll630be412022-07-25 05:52:14 +00001
lh7b0674a2022-01-10 00:34:35 -08002#include <stdio.h>
3#include <sys/types.h>
4#include <sys/socket.h>
5#include <arpa/inet.h>
6#include <fcntl.h>
7#include <string.h>
8#include <stdlib.h>
9#include <unistd.h>
10#include <binder/Parcel.h>
11#include <log/log.h>
lh7b0674a2022-01-10 00:34:35 -080012#include <cutils/jstring.h>
13#include <pthread.h>
14#include "liblog/lynq_deflog.h"
lh2afc7732022-01-10 02:24:31 -080015#include <sys/time.h>
lh21502f52022-01-27 00:27:12 -080016#include <string.h>
q.huang714145d2022-04-18 00:09:50 -040017#include <vendor-ril/telephony/ril.h>
18#include <vendor-ril/telephony/mtk_ril_sp.h>
19#include <vendor-ril/telephony/mtk_ril_ivt.h>
20#include "lynq_call.h"
q.huang52921662022-10-20 15:25:45 +080021#include "lynq_module_common.h"
22#include "lynq_module_socket.h"
23#include "lynq_call_common.h"
q.huang714145d2022-04-18 00:09:50 -040024
q.huang52921662022-10-20 15:25:45 +080025#define CALL_OFF (0)
26#define CALL_ON (1)
lh7b0674a2022-01-10 00:34:35 -080027#define USER_LOG_TAG "LYNQ_CALL"
28
lh3b6f7ea2023-11-08 01:16:42 -080029#define AP_SPEECH "/tmp/ap_speech"
30#define AUDIO_CTRL_SER "/tmp/audio_ctrl_service"
31#define LIBMODEM_AFE "/tmp/libmodem-afe-ctrl"
32#define TELE_DEMO_LOCK "/tmp/tel_demo_single_proc.lock"
33
q.huang305fadc2024-01-02 18:40:40 +080034#define MAX_RING_INCOMING_INTERVAL 10
35
lh7b0674a2022-01-10 00:34:35 -080036using ::android::Parcel;
q.huang52921662022-10-20 15:25:45 +080037
38/**
39 * @brief mark call initialization state
40 * 0: deinit state
41 * 1: init state
42 */
43int g_module_init_flag = 0;
44
lh7b0674a2022-01-10 00:34:35 -080045 typedef enum {
46 LYNQ_CALL_ACTIVE = 0,
47 LYNQ_CALL_HOLDING = 1,
48 LYNQ_CALL_DIALING = 2, /* MO call only */
49 LYNQ_CALL_ALERTING = 3, /* MO call only */
50 LYNQ_CALL_INCOMING = 4, /* MT call only */
lhe45b7002022-04-26 00:45:44 -070051 LYNQ_CALL_WAITING = 5, /* MT call only */
52 /*warren add for T800 platform 2022/04/26 start*/
53 LYNQ_CALL_END = 6, /*CALL END*/
54 /*warren add for T800 platform 2022/04/26 end*/
lh7b0674a2022-01-10 00:34:35 -080055}lynq_call_state_t;
56
lh7b0674a2022-01-10 00:34:35 -080057typedef struct
58{
59 int used;
60 int call_id;
61 int call_state;
62 int toa;
63 int direction;/*0: MO call,1:MT call*/
64 char addr[LYNQ_PHONE_NUMBER_MAX];
lh7b0674a2022-01-10 00:34:35 -080065}lynq_call_list_e_t;
66typedef struct
67{
68 int call_id;
69 int call_state;
70 int toa;
71 int direction;/*0: MO call,1:MT call*/
72 char addr[LYNQ_PHONE_NUMBER_MAX];
73}lynq_call_list_t;
74
q.huang52921662022-10-20 15:25:45 +080075static lynq_call_list_e_t s_call_lists[LYNQ_CALL_MAX]={};
76static bool s_call_list_loop = 0;
77static pthread_t s_call_list_loop_tid = -1;
78static pthread_mutex_t s_notice_get_call_list_mutex = PTHREAD_MUTEX_INITIALIZER;
79static pthread_cond_t s_notice_get_call_list_cond = PTHREAD_COND_INITIALIZER;
80
81static int s_module_isDial = 0;
lh7b0674a2022-01-10 00:34:35 -080082static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
83static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
llb3921072023-01-10 14:47:46 +080084static int s_CallId = 0;
85static pthread_mutex_t s_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
86static pthread_cond_t s_call_state_change_cond = PTHREAD_COND_INITIALIZER;
lhec17b0a2022-02-13 23:56:05 -080087
q.huang52921662022-10-20 15:25:45 +080088static int s_module_call_state =CALL_OFF;
89static int s_call_auto_answer = 0;
q.huang305fadc2024-01-02 18:40:40 +080090static time_t s_rev_ring_time=0;
91
lh7b0674a2022-01-10 00:34:35 -080092
q.huangec88da92022-03-29 04:17:32 -040093typedef enum{
94 LYNQ_E_VOLUMN_SET_DTMF,
95 LYNQ_E_VOLUMN_SET_SPEECH
q.huang52921662022-10-20 15:25:45 +080096}LYNQ_E_VOLUMN_SET;
lh7b0674a2022-01-10 00:34:35 -080097
q.huang52921662022-10-20 15:25:45 +080098#if 0
q.huang7de1d662022-09-13 14:19:24 +080099int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
lh7b0674a2022-01-10 00:34:35 -0800100{
101 if(p.dataAvail() > 0)
102 {
103 p.readInt32(resp_type);
q.huang7de1d662022-09-13 14:19:24 +0800104 p.readInt32(token);
lh7b0674a2022-01-10 00:34:35 -0800105 p.readInt32(request);
106 p.readInt32(slot_id);
107 p.readInt32(error);
108 return 0;
109 }
110 else
111 {
112 return -1;
113 }
114}
115int send_request(int sockfd,lynq_client_t *client_tmp)
116{
117 int ret=0;
rjw5d2a50e2022-02-28 15:01:49 +0800118 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800119 if(ret==-1)
120 {
q.huang70b76492022-06-02 14:49:02 +0800121 LYERRLOG("sendto error");
lh7b0674a2022-01-10 00:34:35 -0800122 return -1;
123 }
124 return 0;
125}
126
127int get_response(int sockfd,Parcel &p)
128{
129 int len = 0;
130 char recvline[LYNQ_REC_BUF];
131 bzero(recvline,LYNQ_REC_BUF);
132 /* receive data from server */
rjw5d2a50e2022-02-28 15:01:49 +0800133 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800134 if(len == -1)
135 {
q.huang70b76492022-06-02 14:49:02 +0800136 LYERRLOG("recvfrom error");
lh7b0674a2022-01-10 00:34:35 -0800137 return -1;
138 }
lh7b0674a2022-01-10 00:34:35 -0800139 if (recvline != NULL) {
140 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
141 p.setDataPosition(0);
142 }
143 return 0;
144}
q.huang52921662022-10-20 15:25:45 +0800145#endif
146static char *strdupReadString(Parcel* &p) {
ll04ae4142022-01-27 05:54:38 +0000147 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800148 const char16_t *s16;
q.huang52921662022-10-20 15:25:45 +0800149 s16 = p->readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000150 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800151}
152
153int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
154{
q.huang52921662022-10-20 15:25:45 +0800155 Parcel* p=NULL;
156 int ret=lynq_send_common_request(p,8,RIL_REQUEST_GET_CURRENT_CALLS,0,"");
157 if(ret!=0)
158 {
159 return ret;
160 }
161
162 int call_num = 0;
163 int temp = 0;
164 char *remote_phoneNum;
165 char *remote_name;
166 char uusData[128];
167
168 p->readInt32(&call_num);
169
170 if(call_num<=0)
171 {
172 s_module_call_state = CALL_OFF;
173 LYINFLOG("lynq_call_state:%d",s_module_call_state);
174 delete p;
175 return RESULT_OK;
176 }
177 s_module_call_state = CALL_ON;
178 LYINFLOG("lynq_call_state:%d, call num is %d ",s_module_call_state,call_num);
179 for(int i = 0;i < call_num;i++)
180 {
181 p->readInt32(&temp);
182 call_list[i].call_state = temp;
183 p->readInt32(&call_list[i].call_id);
184 p->readInt32(&call_list[i].toa);
185 p->readInt32(&temp);
186 p->readInt32(&temp);
187 call_list[i].direction = temp;
188 p->readInt32(&temp);
189 p->readInt32(&temp);
190 p->readInt32(&temp);
191 remote_phoneNum = strdupReadString(p);
192 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
193 if(remote_phoneNum !=NULL)
194 {
195 free(remote_phoneNum);
196 }
197 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
198 call_list[i].direction,call_list[i].addr,call_list[i].toa);
199 p->readInt32(&temp);
200 remote_name = strdupReadString(p);
201 if(remote_name !=NULL)
202 {
203 free(remote_name);
204 }
205 p->readInt32(&temp);
206 p->readInt32(&temp);
207 if(temp==0)
208 {
209 continue;
210 }
211 p->readInt32(&temp); /* UUS Information is present */
212 p->readInt32(&temp);
213 p->readInt32(&temp);
214 if(temp<=128)
215 {
216 p->read(uusData,temp);
217 }
218 else
219 {
220 LYERRLOG("%s len %d is too great",__func__,temp);
221 delete p;
222 return LYNQ_E_MALLOC_ERROR;
223 }
224 }
225
226 delete p;
227 return RESULT_OK;
228
229#if 0
lh7b0674a2022-01-10 00:34:35 -0800230 Parcel p;
231 lynq_client_t client;
232 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800233 int token;
lh7b0674a2022-01-10 00:34:35 -0800234 int request = -1;
235 int slot_id = -1;
236 int error = -1;
237 int call_num = 0;
238 int temp = 0;
239 char *remote_phoneNum = NULL;
240 char *remote_name= NULL;
241 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800242 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800243 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
244 client.paramLen = 0;
245 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang70b76492022-06-02 14:49:02 +0800246 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800247 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800248 {
249 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800250 return -1;
251 }
lh42c1e572022-01-25 18:47:39 -0800252 get_response(lynq_call_client_sockfd,p);
q.huang7de1d662022-09-13 14:19:24 +0800253 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh7b0674a2022-01-10 00:34:35 -0800254 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
255 if(error == 0)
256 {
257 p.readInt32(&call_num);
258 global_call_count = call_num;
259 if(call_num<=0)
260 {
261 lynq_call_state = CALL_OFF;
lhec17b0a2022-02-13 23:56:05 -0800262 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800263 return 0;
264 }
lhec17b0a2022-02-13 23:56:05 -0800265 lynq_call_state = CALL_ON;
q.huang70b76492022-06-02 14:49:02 +0800266 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh7b0674a2022-01-10 00:34:35 -0800267 for(int i = 0;i < call_num;i++)
268 {
269 p.readInt32(&temp);
270 call_list[i].call_state = temp;
271 p.readInt32(&call_list[i].call_id);
272 p.readInt32(&call_list[i].toa);
273 p.readInt32(&temp);
274 p.readInt32(&temp);
275 call_list[i].direction = temp;
276 p.readInt32(&temp);
277 p.readInt32(&temp);
278 p.readInt32(&temp);
279 remote_phoneNum = strdupReadString(p);
280 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
281 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
282 call_list[i].direction,call_list[i].addr,call_list[i].toa);
283 p.readInt32(&temp);
284 remote_name = strdupReadString(p);
285 p.readInt32(&temp);
286 p.readInt32(&temp);
287 if(temp==0)
288 {
289 continue;
290 }
291 p.readInt32(&temp); /* UUS Information is present */
292 p.readInt32(&temp);
293 p.readInt32(&temp);
294 p.read(uusData,temp);
295 }
296 }
297 return 0;
q.huang52921662022-10-20 15:25:45 +0800298#endif
lh7b0674a2022-01-10 00:34:35 -0800299}
300
301void cleanCallList(int lynq_call_id)
302{
q.huang52921662022-10-20 15:25:45 +0800303 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
304 s_call_lists[lynq_call_id].call_id = 0;
305 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
306 s_call_lists[lynq_call_id].toa = 0;
307 s_call_lists[lynq_call_id].direction = 0;
308 s_call_lists[lynq_call_id].used = 0;
309 memset(s_call_lists[lynq_call_id].addr,0,sizeof(s_call_lists[lynq_call_id].addr));
lh7b0674a2022-01-10 00:34:35 -0800310}
llb3921072023-01-10 14:47:46 +0800311
312
lh7b0674a2022-01-10 00:34:35 -0800313int getUnusedElement()
314{
315 for(int i=0;i < LYNQ_CALL_MAX; i++)
316 {
q.huang52921662022-10-20 15:25:45 +0800317 if(s_call_lists[i].used!=1)
lh7b0674a2022-01-10 00:34:35 -0800318 {
319 return i;
320 }
321 }
q.huang52921662022-10-20 15:25:45 +0800322 return INVALID_ID;
lh7b0674a2022-01-10 00:34:35 -0800323}
q.huang52921662022-10-20 15:25:45 +0800324int addAddr(char addr[], int call_id)
lh7b0674a2022-01-10 00:34:35 -0800325{
326 int ret = 0;
327 ret = getUnusedElement();
q.huang52921662022-10-20 15:25:45 +0800328 memcpy(s_call_lists[ret].addr,addr,strlen(addr)+1);
329 s_call_lists[ret].call_id=call_id;
330 s_call_lists[ret].used = 1;
q.huang70b76492022-06-02 14:49:02 +0800331 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh7b0674a2022-01-10 00:34:35 -0800332 return ret;
333}
334void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
335{
q.huang70b76492022-06-02 14:49:02 +0800336 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh7b0674a2022-01-10 00:34:35 -0800337 callList->call_id = call_id;
338 callList->call_state = call_state;
339 callList->toa = toa;
q.huang70b76492022-06-02 14:49:02 +0800340 callList->direction = direction;
lh7b0674a2022-01-10 00:34:35 -0800341 return;
342}
llb3921072023-01-10 14:47:46 +0800343
344void wait_call_state()
lh7b0674a2022-01-10 00:34:35 -0800345{
llb3921072023-01-10 14:47:46 +0800346 LYINFLOG("call state changed");
347 pthread_mutex_lock(&s_call_state_change_mutex);
348 pthread_cond_wait(&s_call_state_change_cond,&s_call_state_change_mutex);
349 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800350}
llb3921072023-01-10 14:47:46 +0800351
lh7b0674a2022-01-10 00:34:35 -0800352int checkHasCall(char addr[])
353{
354 for(int i = 0;i<LYNQ_CALL_MAX;i++)
355 {
q.huang52921662022-10-20 15:25:45 +0800356 if(strcmp(s_call_lists[i].addr,addr)==0)
lh7b0674a2022-01-10 00:34:35 -0800357 {
q.huang52921662022-10-20 15:25:45 +0800358 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,s_call_lists[i].call_id);
359 return true;
lh7b0674a2022-01-10 00:34:35 -0800360 }
361 }
q.huang70b76492022-06-02 14:49:02 +0800362 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
q.huang52921662022-10-20 15:25:45 +0800363 return false;
lh7b0674a2022-01-10 00:34:35 -0800364}
lhd1e457c2022-04-19 06:01:25 -0700365int find_call_id_with_addr(char *addr)
366{
lhd1e457c2022-04-19 06:01:25 -0700367 for(int id = 0; id < LYNQ_CALL_MAX; id++)
368 {
q.huang52921662022-10-20 15:25:45 +0800369 if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
lhd1e457c2022-04-19 06:01:25 -0700370 {
q.huang52921662022-10-20 15:25:45 +0800371 LYINFLOG("find addr %s in local list, local idx is %d id is %d",addr,id,s_call_lists[id].call_id);
lhd1e457c2022-04-19 06:01:25 -0700372 return id;
373 }
374 }
q.huang70b76492022-06-02 14:49:02 +0800375 LYINFLOG("find addr %s in local list , not found",addr);
q.huang52921662022-10-20 15:25:45 +0800376 return INVALID_ID;
lhd1e457c2022-04-19 06:01:25 -0700377}
q.huang70b76492022-06-02 14:49:02 +0800378int find_call_id_with_call_id(int call_id)
379{
380 for(int id = 0; id < LYNQ_CALL_MAX; id++)
381 {
q.huang52921662022-10-20 15:25:45 +0800382 if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
q.huang70b76492022-06-02 14:49:02 +0800383 {
q.huang52921662022-10-20 15:25:45 +0800384 LYINFLOG("find id %d in local list, local idx is %d, addr is %s",call_id,id,s_call_lists[id].addr);
q.huang70b76492022-06-02 14:49:02 +0800385 return id;
386 }
387 }
388 LYINFLOG("find id %d in local list , not found",call_id);
389 return INVALID_ID;
390}
lh7b0674a2022-01-10 00:34:35 -0800391void sendSignalToWaitCallStateChange()
392{
lhd1e457c2022-04-19 06:01:25 -0700393 LYINFLOG("send Signal To Wait Call State Change");
lh7b0674a2022-01-10 00:34:35 -0800394 pthread_mutex_lock(&call_state_change_mutex);
395 pthread_cond_signal(&call_state_change_cond);
396 pthread_mutex_unlock(&call_state_change_mutex);
397}
you.chen79d8f932023-12-26 17:03:44 +0800398void send_call_state_change(int callid)
lh7b0674a2022-01-10 00:34:35 -0800399{
llb3921072023-01-10 14:47:46 +0800400 LYINFLOG("send call state change");
you.chen79d8f932023-12-26 17:03:44 +0800401 s_CallId = callid;
llb3921072023-01-10 14:47:46 +0800402 pthread_mutex_lock(&s_call_state_change_mutex);
403 pthread_cond_signal(&s_call_state_change_cond);
404 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800405}
406
q.huang52921662022-10-20 15:25:45 +0800407void cleanup_call_list_mutex(void *arg)
lh7b0674a2022-01-10 00:34:35 -0800408{
q.huang52921662022-10-20 15:25:45 +0800409 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
lh7b0674a2022-01-10 00:34:35 -0800410}
llb3921072023-01-10 14:47:46 +0800411
412void update_end_state(int lynq_call_id)
413{
414 LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
415 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
416}
417
lh7b0674a2022-01-10 00:34:35 -0800418void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000419{
420 int ret=0;
lhd1e457c2022-04-19 06:01:25 -0700421 bool call_end;
ll04ae4142022-01-27 05:54:38 +0000422 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang8b33ed52022-04-19 20:27:44 -0400423 int update=0;
q.huang70b76492022-06-02 14:49:02 +0800424 int cnt;
425 int i,n;
q.huange97cfcf2022-08-29 20:04:31 +0800426#ifdef ECALL_SUPPORT
427 int handupIncomingMT=0;
428#endif
q.huang305fadc2024-01-02 18:40:40 +0800429 unsigned long interval;
430 time_t now;
431
432
q.huang52921662022-10-20 15:25:45 +0800433 pthread_mutex_lock(&s_notice_get_call_list_mutex);
434 pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
you.chen79d8f932023-12-26 17:03:44 +0800435 int tmp_call_id;
q.huang52921662022-10-20 15:25:45 +0800436 while(s_call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000437 {
q.huang52921662022-10-20 15:25:45 +0800438 update=0;
439 pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
you.chen79d8f932023-12-26 17:03:44 +0800440 LYINFLOG("triggerGetCallList event %p!!!", pthread_self());
ll04ae4142022-01-27 05:54:38 +0000441 memset(call_list,0,sizeof(call_list));
442 ret = lynq_get_current_call_list(call_list);
q.huang52921662022-10-20 15:25:45 +0800443 if(ret != RESULT_OK)
ll04ae4142022-01-27 05:54:38 +0000444 {
you.chen79d8f932023-12-26 17:03:44 +0800445 LYERRLOG("get current call list failure!!!");
llbc035332022-04-11 05:49:51 +0000446 continue;
ll04ae4142022-01-27 05:54:38 +0000447 }
lhd1e457c2022-04-19 06:01:25 -0700448 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huang70b76492022-06-02 14:49:02 +0800449 LYINFLOG("clear local index begin");
450 cnt=0;
451 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh7b0674a2022-01-10 00:34:35 -0800452 {
q.huang52921662022-10-20 15:25:45 +0800453 if(s_call_lists[i].used ==0)
q.huang70b76492022-06-02 14:49:02 +0800454 {
455 continue;
456 }
457 cnt++;
q.huang52921662022-10-20 15:25:45 +0800458 LYINFLOG("local idx is %d id is %d addr is %s state is %d direction is %d",i,s_call_lists[i].call_id,s_call_lists[i].addr,s_call_lists[i].call_state,s_call_lists[i].direction);
q.huang70b76492022-06-02 14:49:02 +0800459
q.huang52921662022-10-20 15:25:45 +0800460 if(s_call_lists[i].call_id > 0)
lhd1e457c2022-04-19 06:01:25 -0700461 {
462 call_end = 0;
q.huang70b76492022-06-02 14:49:02 +0800463 for(n = 0; n < LYNQ_CALL_MAX; n++)
lhd1e457c2022-04-19 06:01:25 -0700464 {
q.huang52921662022-10-20 15:25:45 +0800465 if(call_list[n].call_id == s_call_lists[i].call_id)
lhd1e457c2022-04-19 06:01:25 -0700466 {
467 call_end = 1;
q.huang52921662022-10-20 15:25:45 +0800468 LYINFLOG("find lynq call local idx %d, service idx %d id is %d!!!",i,n,s_call_lists[i].call_id);
q.huang70b76492022-06-02 14:49:02 +0800469 break;
lhd1e457c2022-04-19 06:01:25 -0700470 }
471 }
472 if(call_end == 0)
473 {
llb3921072023-01-10 14:47:46 +0800474 LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
475 //update_end_state(i);//lei modify for:update end state for this call
you.chen79d8f932023-12-26 17:03:44 +0800476 tmp_call_id = s_call_lists[i].call_id;
llb3921072023-01-10 14:47:46 +0800477 cleanCallList(i);
you.chen79d8f932023-12-26 17:03:44 +0800478 //Release the end handle
479 send_call_state_change(tmp_call_id);//means mt/mo call is end
llb3921072023-01-10 14:47:46 +0800480 //cleanCallList(i);
lhd1e457c2022-04-19 06:01:25 -0700481 }
482 } //fix bug API-54
q.huang70b76492022-06-02 14:49:02 +0800483 else
484 {
485 LYINFLOG("local id is 0");
486 }
487 }
488 LYINFLOG("clear local index end, local used cnt is %d", cnt);
489
490 LYINFLOG("add or update local index begin ");
491 for (i = 0;i < LYNQ_CALL_MAX;i++)
492 {
493 if(call_list[i].call_id==0)
494 {
495 break;
496 }
497
498 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,
499 call_list[i].direction,call_list[i].addr,call_list[i].toa);
500
lh7b0674a2022-01-10 00:34:35 -0800501 if(call_list[i].direction == 1)//MT call
502 {
q.huang70b76492022-06-02 14:49:02 +0800503 LYINFLOG("This is a MT CALL");
lh0fd3b012022-05-13 03:02:19 -0700504 /*MT CALL state code
505 **LYNQ_CALL_INCOMING = 4,
506 **LYNQ_CALL_WAITING = 5,
507 */
q.huange97cfcf2022-08-29 20:04:31 +0800508#ifdef ECALL_SUPPORT
lh0fd3b012022-05-13 03:02:19 -0700509 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh7b0674a2022-01-10 00:34:35 -0800510 {
q.huang52921662022-10-20 15:25:45 +0800511 handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
q.huange97cfcf2022-08-29 20:04:31 +0800512 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
513 if(handupIncomingMT)
lh7b0674a2022-01-10 00:34:35 -0800514 {
q.huang70b76492022-06-02 14:49:02 +0800515 lynq_call_hungup(&(call_list[i].call_id));
516 continue;
q.huange97cfcf2022-08-29 20:04:31 +0800517 }
q.huang70b76492022-06-02 14:49:02 +0800518 }
q.huange97cfcf2022-08-29 20:04:31 +0800519#endif
q.huang70b76492022-06-02 14:49:02 +0800520 /*you call me, and i call you,One party failed to dial*/
521 n = find_call_id_with_addr(call_list[i].addr);
522 if(n ==INVALID_ID)
523 {
q.huang305fadc2024-01-02 18:40:40 +0800524 if(s_call_auto_answer==false && call_list[i].call_state==LYNQ_CALL_INCOMING)
525 {
526 time(&now);
527 interval = difftime(now,s_rev_ring_time);
528 if(interval>MAX_RING_INCOMING_INTERVAL)
529 {
530 LYINFLOG("recv incoming, %d second no ril ring",interval);
531 continue;
532 }
533 }
534
q.huang52921662022-10-20 15:25:45 +0800535 n = addAddr(call_list[i].addr,call_list[i].call_id);
536 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
you.chen79d8f932023-12-26 17:03:44 +0800537 send_call_state_change(call_list[i].call_id);
q.huang70b76492022-06-02 14:49:02 +0800538 }
q.huang52921662022-10-20 15:25:45 +0800539 else if(s_call_lists[n].call_state == call_list[i].call_state)
q.huang70b76492022-06-02 14:49:02 +0800540 {
541 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
542 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lhd1e457c2022-04-19 06:01:25 -0700543 {
lhd1e457c2022-04-19 06:01:25 -0700544 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
545 **an incoming call until the status changes.
546 **fix bug API-54
547 */
q.huang70b76492022-06-02 14:49:02 +0800548 LYINFLOG("resend incoming call signal");
you.chen79d8f932023-12-26 17:03:44 +0800549 send_call_state_change(call_list[i].call_id);
lhd1e457c2022-04-19 06:01:25 -0700550 }
lh7b0674a2022-01-10 00:34:35 -0800551 }
q.huang70b76492022-06-02 14:49:02 +0800552 else
ll72bf6c12022-03-24 10:22:25 +0800553 {
q.huang52921662022-10-20 15:25:45 +0800554 LYINFLOG("state changed from %d to %d",s_call_lists[n].call_state,call_list[i].call_state);
q.huang70b76492022-06-02 14:49:02 +0800555
llb3921072023-01-10 14:47:46 +0800556 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);//update mt call
you.chen79d8f932023-12-26 17:03:44 +0800557 send_call_state_change(call_list[i].call_id);
llb3921072023-01-10 14:47:46 +0800558 }
lh7b0674a2022-01-10 00:34:35 -0800559 }
560 else
q.huang70b76492022-06-02 14:49:02 +0800561 {
562 LYINFLOG("This is a MO CALL");
563 call_end = 0;
564 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh7b0674a2022-01-10 00:34:35 -0800565 {
q.huang52921662022-10-20 15:25:45 +0800566 if(s_call_lists[n].used && ((strcmp(call_list[i].addr,s_call_lists[n].addr)==0)||(call_list[i].call_id==s_call_lists[n].call_id)))
lh7b0674a2022-01-10 00:34:35 -0800567 {
q.huang52921662022-10-20 15:25:45 +0800568 if(s_call_lists[n].call_id==0)
q.huang70b76492022-06-02 14:49:02 +0800569 {
llb3921072023-01-10 14:47:46 +0800570 LYINFLOG("add a call id");
571 update=1;//for send sigal
q.huang70b76492022-06-02 14:49:02 +0800572 }
q.huang52921662022-10-20 15:25:45 +0800573 LYINFLOG("local idx %d updated, original call id is %d origial addr is %s original state is %d",n,s_call_lists[n].call_id,s_call_lists[n].addr,s_call_lists[n].call_state);
574 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
q.huang70b76492022-06-02 14:49:02 +0800575 call_end = 1;
you.chen79d8f932023-12-26 17:03:44 +0800576 send_call_state_change(call_list[i].call_id);//means mo call is success
q.huang70b76492022-06-02 14:49:02 +0800577 break;
578 }
579 }
llb3921072023-01-10 14:47:46 +0800580 if(call_end == 0)//1.there is no space to use 2.can't find addr in buffer 3.call_id not equal eg:when call is error return 8004/handle <= 0 will into this
q.huang70b76492022-06-02 14:49:02 +0800581 {
582 LYINFLOG("need to hangup id %d", call_list[i].call_id);
583#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +0800584 if(IsECallDialing())
q.huang70b76492022-06-02 14:49:02 +0800585 {
586 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh7b0674a2022-01-10 00:34:35 -0800587 continue;
588 }
q.huang70b76492022-06-02 14:49:02 +0800589#endif
590 LYINFLOG("hang up service call id %d",call_list[i].call_id);
591 lynq_call_hungup(&(call_list[i].call_id));
lh7b0674a2022-01-10 00:34:35 -0800592 }
llb3921072023-01-10 14:47:46 +0800593
lh7b0674a2022-01-10 00:34:35 -0800594 }
q.huang70b76492022-06-02 14:49:02 +0800595 LYDBGLOG("servie idx %d end",i);
ll04ae4142022-01-27 05:54:38 +0000596 }
q.huang52921662022-10-20 15:25:45 +0800597 LYINFLOG("add or update local index end ");
598 if(s_module_isDial==1)
lh7b0674a2022-01-10 00:34:35 -0800599 {
q.huang70b76492022-06-02 14:49:02 +0800600 LYINFLOG("now is dialing");
601 if(update==1)
602 {
603 LYINFLOG("find added call");
604 sendSignalToWaitCallStateChange();
q.huang52921662022-10-20 15:25:45 +0800605 s_module_isDial = 0;
q.huang70b76492022-06-02 14:49:02 +0800606 }
607 else
608 {
609 LYINFLOG("not find added call");
610 }
611 }
612 else
613 {
614 LYINFLOG("now is not dialing");
q.huang52921662022-10-20 15:25:45 +0800615 }
ll04ae4142022-01-27 05:54:38 +0000616 }
q.huang52921662022-10-20 15:25:45 +0800617 pthread_cleanup_pop(0);
618 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
ll04ae4142022-01-27 05:54:38 +0000619 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800620}
621
q.huang52921662022-10-20 15:25:45 +0800622void lynqNoticeGetModuleCallList()
ll04ae4142022-01-27 05:54:38 +0000623{
you.chen79d8f932023-12-26 17:03:44 +0800624 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send start");
q.huang52921662022-10-20 15:25:45 +0800625 pthread_mutex_lock(&s_notice_get_call_list_mutex);
626 pthread_cond_signal(&s_notice_get_call_list_cond);
627 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
you.chen79d8f932023-12-26 17:03:44 +0800628 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send end");
lh7b0674a2022-01-10 00:34:35 -0800629}
630
q.huang52921662022-10-20 15:25:45 +0800631#if 0
lh7b0674a2022-01-10 00:34:35 -0800632/*Warren add for T800 platform 2021/11/19 start*/
633int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800634{
635 #if 0
lh7b0674a2022-01-10 00:34:35 -0800636 struct sockaddr_in lynq_socket_server_addr;
637 /* init lynq_socket_server_addr */
638 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
639 lynq_socket_server_addr.sin_family = AF_INET;
640 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
641 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800642
lh7b0674a2022-01-10 00:34:35 -0800643 /*
644 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
645 {
q.huang70b76492022-06-02 14:49:02 +0800646 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800647 exit(1);
648 }
649*/
lh42c1e572022-01-25 18:47:39 -0800650 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
651 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800652 {
q.huang70b76492022-06-02 14:49:02 +0800653 LYERRLOG("connect error");
lh7b0674a2022-01-10 00:34:35 -0800654 return -1;
655 }
rjw5d2a50e2022-02-28 15:01:49 +0800656 #endif
657 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
658 if (-1 == lynq_call_client_sockfd)
659 {
660 return lynq_call_client_sockfd;
661 }
ll630be412022-07-25 05:52:14 +0000662 struct timeval timeOut;
663 timeOut.tv_sec = 60;
664 timeOut.tv_usec = 0;
665 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
666 {
667 RLOGD("time out setting failed\n");
668 return -1;
669 }
rjw5d2a50e2022-02-28 15:01:49 +0800670 /* 设置address */
671 memset(&addr_serv, 0, sizeof(addr_serv));
672 addr_serv.sin_family = AF_INET;
673 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
674 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
675 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800676 return 0;
677}
lh7b0674a2022-01-10 00:34:35 -0800678
lh7b0674a2022-01-10 00:34:35 -0800679int lynq_socket_urc_start()
680{
681 int socket_fd=0;
682 int rt=0;
683 int len=0;
684 int on=1;
685 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800686 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000687 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000688 if(socket_fd < 0)
689 {
q.huang70b76492022-06-02 14:49:02 +0800690 LYERRLOG("creaet socket for udp fail");
ll04ae4142022-01-27 05:54:38 +0000691 return -1;
lh7b0674a2022-01-10 00:34:35 -0800692 }
693 urc_local_addr.sin_family = AF_INET;
694 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
695 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
696 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000697 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
698 if(rt<0)
699 {
q.huang70b76492022-06-02 14:49:02 +0800700 LYERRLOG("SO_REUSEADDR fail");
lh7b0674a2022-01-10 00:34:35 -0800701 return -1;
702 }
703 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000704 if (rt == -1)
705 {
lh21502f52022-01-27 00:27:12 -0800706 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000707 return -1;
lh7b0674a2022-01-10 00:34:35 -0800708 }
709 pthread_attr_init(&attr);
710 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800711 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800712 if(rt < 0)
713 {
q.huang70b76492022-06-02 14:49:02 +0800714 LYERRLOG("urc loop failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800715 return -1;
716 }
q.huang70b76492022-06-02 14:49:02 +0800717 LYDBGLOG("urc loop success!!!");
lh7b0674a2022-01-10 00:34:35 -0800718 return 0;
719}
q.huang52921662022-10-20 15:25:45 +0800720#endif
lh7b0674a2022-01-10 00:34:35 -0800721
722void lynq_call_state_change_test(int soc_id)
723{
q.huang70b76492022-06-02 14:49:02 +0800724 LYDBGLOG("call state change,sim:%d",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800725}
q.huangcb7b7292022-06-28 20:12:01 +0800726
q.huang52921662022-10-20 15:25:45 +0800727int lynq_start_call_list_loop()
728{
729#if 0
730 int ret = 0;
731 pthread_attr_t attr;
732 pthread_attr_init(&attr);
733 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
q.huangcb7b7292022-06-28 20:12:01 +0800734
q.huang52921662022-10-20 15:25:45 +0800735 s_notice_get_call_list_mutex = new pthread_mutex_t;
736 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
737 s_notice_get_call_list_cond = new pthread_cond_t;
738 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
739 pthread_cond_init(s_notice_get_call_list_cond, NULL);
740 LYINFLOG("liulei s_notice_get_call_list_cond\n");
741#endif
q.huangcb7b7292022-06-28 20:12:01 +0800742
q.huang52921662022-10-20 15:25:45 +0800743 s_call_list_loop = 1;
744 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
745 if(ret < 0)
q.huangcb7b7292022-06-28 20:12:01 +0800746 {
q.huang52921662022-10-20 15:25:45 +0800747 LYERRLOG("lynq_update_call_list_loop fail!!!");
lla8c25a82022-03-17 05:31:33 +0000748 return -1;
749 }
q.huang52921662022-10-20 15:25:45 +0800750 LYINFLOG("lynq_update_call_list_loop success!!!");
q.huangcb7b7292022-06-28 20:12:01 +0800751
q.huang52921662022-10-20 15:25:45 +0800752 memset(s_call_lists,0,sizeof(s_call_lists));
lh7b0674a2022-01-10 00:34:35 -0800753 return 0;
754}
q.huang52921662022-10-20 15:25:45 +0800755
756int lynq_stop_call_list_loop()
lh7b0674a2022-01-10 00:34:35 -0800757{
q.huang70b76492022-06-02 14:49:02 +0800758 int ret;
q.huang52921662022-10-20 15:25:45 +0800759 pthread_mutex_lock(&s_notice_get_call_list_mutex);
760 s_call_list_loop = 0;
761 ret = pthread_cancel(s_call_list_loop_tid);
762 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
763 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
764 ret = pthread_join(s_call_list_loop_tid,NULL);
765 LYINFLOG("pthread join w_c_list ret = %d",ret);
766 s_call_list_loop_tid=-1;
767#if 0
768 pthread_mutex_destroy(s_notice_get_call_list_mutex);
769 pthread_cond_destroy(s_notice_get_call_list_cond);
770 delete s_notice_get_call_list_mutex;
771 //s_notice_get_call_list_mutex = NULL;
772 delete s_notice_get_call_list_cond;
773 //s_notice_get_call_list_cond = NULL;
774#endif
775
776 return 0;
rita98e2e9c2022-04-07 06:08:13 -0400777}
q.huang714145d2022-04-18 00:09:50 -0400778
q.huang52921662022-10-20 15:25:45 +0800779int lynq_init_call(int utoken){
q.huangf6a9ddc2023-12-08 20:23:56 +0800780
781 LYLOGSET(LOG_INFO);
782 LYLOGEINIT(USER_LOG_TAG);
783 LYERRLOG("%s start, parameter is %d", __func__,utoken);
784
q.huang52921662022-10-20 15:25:45 +0800785 if(g_module_init_flag != MODULE_CLOSED)
786 {
787 LYERRLOG("module state is %d",g_module_init_flag);
788 return LYNQ_E_CONFLICT;
789 }
790 if(utoken <0){
791 LYERRLOG("utoken is less than 0",utoken);
792 return LYNQ_E_PARAMETER_ANONALY;
793 }
794 g_module_init_flag = MODULE_SWITCHING;
q.huangf6a9ddc2023-12-08 20:23:56 +0800795
q.huang52921662022-10-20 15:25:45 +0800796
797 g_module_Global_uToken = utoken;
798
q.huang036b6cf2023-01-10 14:29:20 +0800799 int ret = lynq_start_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800800 if(ret != RESULT_OK)
801 {
802 LYERRLOG("init socket urc fail!!!");
803 g_module_init_flag = MODULE_CLOSED;
804 return LYNQ_E_INNER_ERROR;
805 }
806
q.huang036b6cf2023-01-10 14:29:20 +0800807 ret = lynq_start_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800808 if(ret !=RESULT_OK)
809 {
810 LYERRLOG("init socket client fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800811 lynq_close_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800812 g_module_init_flag = MODULE_CLOSED;
813 return LYNQ_E_INNER_ERROR;
814 }
815
816
817 int result = lynq_start_call_list_loop();
818 if(ret != RESULT_OK)
819 {
820 LYERRLOG("lynq_start_call_list_loop fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800821 lynq_close_all_urc_socket_thread();
822 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800823 g_module_init_flag = MODULE_CLOSED;
824 return LYNQ_E_INNER_ERROR;
825 }
826
q.huang52921662022-10-20 15:25:45 +0800827 g_module_init_flag = MODULE_RUNNING;
q.huangf6a9ddc2023-12-08 20:23:56 +0800828
829 LYERRLOG("%s end suc", __func__);
q.huang52921662022-10-20 15:25:45 +0800830 return 0;
831}
832
833int lynq_deinit_call(void){
q.huangf6a9ddc2023-12-08 20:23:56 +0800834 LYERRLOG("%s start", __func__);
q.huang52921662022-10-20 15:25:45 +0800835
836 if (g_module_init_flag != MODULE_RUNNING)
837 {
838 LYERRLOG("module state is %d",g_module_init_flag);
839 return LYNQ_E_CONFLICT;
840 }
841 lynq_call_hungup_all();
q.huang52921662022-10-20 15:25:45 +0800842 g_module_init_flag = MODULE_SWITCHING;
q.huang036b6cf2023-01-10 14:29:20 +0800843 lynq_close_all_urc_socket_thread();
844 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800845 lynq_stop_call_list_loop();
846 g_module_init_flag = MODULE_CLOSED;
q.huangf6a9ddc2023-12-08 20:23:56 +0800847
848 LYERRLOG("%s end suc", __func__);
q.huang52921662022-10-20 15:25:45 +0800849 return 0;
850}
851
852#if 0
q.huang714145d2022-04-18 00:09:50 -0400853int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400854{
855 Parcel p;
856 lynq_client_t client;
857 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800858 int token;
rita089527e2022-04-07 01:55:39 -0400859 int request = -1;
860 int slot_id = -1;
861 int error = -1;
rita089527e2022-04-07 01:55:39 -0400862
q.huang52921662022-10-20 15:25:45 +0800863 Parcel* p=NULL;
864 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
865 if(ret==RESULT_OK)
866 {
867 delete p;
868 }
869 return ret;
870
rita089527e2022-04-07 01:55:39 -0400871 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400872 client.request = request_id;
873 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400874 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400875 if(argc!=0)
876 {
877 va_list args;
878 va_start(args, format);
879 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
880 va_end(args);
881 }
q.huang70b76492022-06-02 14:49:02 +0800882 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400883 if(send_request(lynq_call_client_sockfd,&client)==-1)
884 {
885 LYERRLOG("send request fail");
886 return -1;
887 }
q.huang714145d2022-04-18 00:09:50 -0400888 if(get_response(lynq_call_client_sockfd,p)==0)
889 {
q.huang7de1d662022-09-13 14:19:24 +0800890 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang714145d2022-04-18 00:09:50 -0400891 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
892 }
rita089527e2022-04-07 01:55:39 -0400893 return error;
q.huang52921662022-10-20 15:25:45 +0800894
895
rita089527e2022-04-07 01:55:39 -0400896}
q.huang52921662022-10-20 15:25:45 +0800897#endif
rita089527e2022-04-07 01:55:39 -0400898
q.huang714145d2022-04-18 00:09:50 -0400899int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400900{
q.huang714145d2022-04-18 00:09:50 -0400901 if(status==NULL)
902 {
903 LYERRLOG("status is null");
q.huang52921662022-10-20 15:25:45 +0800904 return LYNQ_E_PARAMETER_ANONALY;
q.huang714145d2022-04-18 00:09:50 -0400905 }
q.huang52921662022-10-20 15:25:45 +0800906
907 Parcel* p=NULL;
908 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
909 if(ret==RESULT_OK)
rita089527e2022-04-07 01:55:39 -0400910 {
q.huang52921662022-10-20 15:25:45 +0800911 p->readInt32(status);
912 delete p;
rita089527e2022-04-07 01:55:39 -0400913 }
q.huang52921662022-10-20 15:25:45 +0800914 return ret;
915}
916
917int waitCallstateChange(int mtime)
918{
919 LYINFLOG("wait Call state Change");
920 int ret = 0;
921 int sec = 0;
you.chen79d8f932023-12-26 17:03:44 +0800922 int ms = 0;
q.huang52921662022-10-20 15:25:45 +0800923 struct timeval now;
924 struct timespec timeout;
925 gettimeofday(&now,NULL);
926 sec = mtime/1000;
you.chen79d8f932023-12-26 17:03:44 +0800927 ms = mtime%1000;
q.huang52921662022-10-20 15:25:45 +0800928 timeout.tv_sec = now.tv_sec+sec;
you.chen79d8f932023-12-26 17:03:44 +0800929 unsigned long long ns;
930 ns = now.tv_usec*1000ull + ms*1000000ull;
931 timeout.tv_sec += ns/1000000000;
932 timeout.tv_nsec = ns % 1000000000;
q.huang52921662022-10-20 15:25:45 +0800933 pthread_mutex_lock(&call_state_change_mutex);
934 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
935 pthread_mutex_unlock(&call_state_change_mutex);
936 return ret;
937}
938
939int IsNormalCallDailing()
940{
941 return s_module_isDial;
rita089527e2022-04-07 01:55:39 -0400942}
943
llb3921072023-01-10 14:47:46 +0800944
lh3b6f7ea2023-11-08 01:16:42 -0800945int check_file_access(const char *fileName)
946{
947 if(0 == access(fileName,F_OK))
948 {
949 LYINFLOG("find file %s success",fileName);
950 return 0;
951 }
952 LYERRLOG("find file %s fail",fileName);
953 return 1;
954}
955int try_reset_audio_service()
956{
957 //check files:audio-ctrl-service,libmodem-afe-service,speech_daemon
958 int ap_speech = 0;
959 int audio_ctrl_ser = 0;
960 int md_afe = 0;
961 int tele_demo_lock = 0;
962 LYINFLOG("try_reset_audio_service start");
963 ap_speech = check_file_access(AP_SPEECH);
964 audio_ctrl_ser = check_file_access(AUDIO_CTRL_SER);
965 md_afe = check_file_access(LIBMODEM_AFE);
966 tele_demo_lock = check_file_access(TELE_DEMO_LOCK);
967 if((ap_speech + audio_ctrl_ser + md_afe) > 0)
968 {
969 system("systemctl stop audio-ctrl-service");
970 system("systemctl stop speech_daemon");
971 system("systemctl stop libmodem_afe_service");
972 usleep(200000);//200ms
973 system("rm /tmp/audio_ctrl_service -rf");
974 system("rm /tmp/ap_speech -rf");
975 system("rm /tmp/libmodem-afe-ctrl -rf");
976 usleep(100000);//100ms
977 system("systemctl start libmodem_afe_service");
978 usleep(200000);//200ms
979 system("systemctl start speech_daemon");
980 usleep(200000);//200ms
981 system("systemctl start audio-ctrl-service");
982 sleep(1);//1s
983 LYERRLOG("reset audio relation service");
984 }
985 if(tele_demo_lock)
986 {
987 LYERRLOG("%s lose,why?",TELE_DEMO_LOCK);
988 }
989 return 0;
990}
991
lh7b0674a2022-01-10 00:34:35 -0800992int lynq_call(int* handle,char addr[])
993{
q.huang52921662022-10-20 15:25:45 +0800994 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700995 {
q.huang52921662022-10-20 15:25:45 +0800996 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
997 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -0700998 }
lh3b6f7ea2023-11-08 01:16:42 -0800999 try_reset_audio_service();
lh7b0674a2022-01-10 00:34:35 -08001000 int lynq_call_id = -1;
q.huang70b76492022-06-02 14:49:02 +08001001
1002 LYINFLOG("lynq_call begin addr %s",addr);
lh7b0674a2022-01-10 00:34:35 -08001003 if(addr==NULL)
1004 {
1005 LYERRLOG("Phone num is null!!!");
q.huang52921662022-10-20 15:25:45 +08001006 return LYNQ_E_PARAMETER_ANONALY;
lh7b0674a2022-01-10 00:34:35 -08001007 }
q.huang70b76492022-06-02 14:49:02 +08001008
1009 if(find_call_id_with_addr(addr)!=INVALID_ID)
1010 {
1011 LYERRLOG("addr %s exists",addr);
1012 return LYNQ_E_CONFLICT;
1013 }
1014
1015#ifdef ECALL_SUPPORT
1016 if(lynq_ecall_is_running())
1017 {
1018 LYERRLOG("lynq_fast_ecall ecall is running");
1019 return LYNQ_E_ECALL_BEING_RUNNING;
1020 }
1021#endif
q.huang52921662022-10-20 15:25:45 +08001022 Parcel* p=NULL;
1023 lynq_call_id = addAddr(addr,0);
1024 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
1025 if(ret!=0)
1026 {
llb3921072023-01-10 14:47:46 +08001027 cleanCallList(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001028 return ret;
llb3921072023-01-10 14:47:46 +08001029 }
1030 delete p;
q.huang52921662022-10-20 15:25:45 +08001031 s_module_isDial = 1;
1032 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -08001033 {
q.huang52921662022-10-20 15:25:45 +08001034 //if timeout,this call need destroy.
1035 s_module_isDial = 0;
1036 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
llb3921072023-01-10 14:47:46 +08001037 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001038 send_call_state_change(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001039 return LYNQ_E_TIME_OUT;
lh7b0674a2022-01-10 00:34:35 -08001040 }
q.huang52921662022-10-20 15:25:45 +08001041 s_module_isDial = 0;
1042 *handle = s_call_lists[lynq_call_id].call_id;
1043 if(*handle > 0)
lh7b0674a2022-01-10 00:34:35 -08001044 {
q.huang52921662022-10-20 15:25:45 +08001045 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
1046 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001047 }
q.huang52921662022-10-20 15:25:45 +08001048 else
1049 {
1050 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
lle3b9a232023-01-14 13:21:20 +08001051 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001052 send_call_state_change(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001053 return LYNQ_E_INVALID_ID_ANONALY;
llb3921072023-01-10 14:47:46 +08001054 }
lh7b0674a2022-01-10 00:34:35 -08001055}
llb3921072023-01-10 14:47:46 +08001056
lh7b0674a2022-01-10 00:34:35 -08001057int lynq_call_answer()
1058{
q.huang52921662022-10-20 15:25:45 +08001059 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001060 {
q.huang52921662022-10-20 15:25:45 +08001061 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1062 return LYNQ_E_CONFLICT;
1063 }
1064
1065 Parcel* p=NULL;
1066 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
1067 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001068 {
q.huang52921662022-10-20 15:25:45 +08001069 delete p;
1070 }
1071 return ret;
lh7b0674a2022-01-10 00:34:35 -08001072}
llb3921072023-01-10 14:47:46 +08001073
lh7b0674a2022-01-10 00:34:35 -08001074int lynq_call_hungup(int* handle)
1075{
q.huang52921662022-10-20 15:25:45 +08001076 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001077 {
q.huang52921662022-10-20 15:25:45 +08001078 return LYNQ_E_CONFLICT;
1079 }
1080
lh42c1e572022-01-25 18:47:39 -08001081 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1082 {
q.huang52921662022-10-20 15:25:45 +08001083 LYERRLOG("%s illegal input!!!!",__func__);
1084 return LYNQ_E_PARAMETER_ANONALY;
lh42c1e572022-01-25 18:47:39 -08001085 }
q.huang52921662022-10-20 15:25:45 +08001086
1087 int call_id = *handle;
1088 Parcel* p=NULL;
1089 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1090 if(ret!=0)
lh7b0674a2022-01-10 00:34:35 -08001091 {
q.huang52921662022-10-20 15:25:45 +08001092 return ret;
you.chen79d8f932023-12-26 17:03:44 +08001093 }
q.huang52921662022-10-20 15:25:45 +08001094 delete p;
1095
you.chen79d8f932023-12-26 17:03:44 +08001096 int lynq_call_id=find_call_id_with_call_id(call_id);
q.huang52921662022-10-20 15:25:45 +08001097 if(lynq_call_id!=INVALID_ID)
lh7b0674a2022-01-10 00:34:35 -08001098 {
you.chen79d8f932023-12-26 17:03:44 +08001099 //lei modify for API-857
q.huang52921662022-10-20 15:25:45 +08001100 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001101 send_call_state_change(call_id);
1102 }
1103 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001104}
1105int lynq_call_hungup_all()
1106{
q.huang52921662022-10-20 15:25:45 +08001107 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001108 {
q.huang52921662022-10-20 15:25:45 +08001109 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1110 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001111 }
q.huang52921662022-10-20 15:25:45 +08001112
1113 Parcel* p=NULL;
1114 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1115 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001116 {
q.huang52921662022-10-20 15:25:45 +08001117 delete p;
1118 }
1119 return ret;
lh7b0674a2022-01-10 00:34:35 -08001120}
llb3921072023-01-10 14:47:46 +08001121
1122int lynq_wait_call_state_change(int *handle)
lh7b0674a2022-01-10 00:34:35 -08001123{
q.huang52921662022-10-20 15:25:45 +08001124 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001125 {
q.huang52921662022-10-20 15:25:45 +08001126 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1127 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001128 }
llb3921072023-01-10 14:47:46 +08001129 wait_call_state();
1130 *handle = s_CallId;
1131 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1132 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001133}
1134
1135int lynq_set_auto_answercall(const int mode)
1136{
q.huang52921662022-10-20 15:25:45 +08001137 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001138 {
q.huang52921662022-10-20 15:25:45 +08001139 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1140 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001141 }
q.huang52921662022-10-20 15:25:45 +08001142 s_call_auto_answer = mode;
lh7b0674a2022-01-10 00:34:35 -08001143 LYINFLOG("auto answer call mode =%d",mode);
q.huang52921662022-10-20 15:25:45 +08001144 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001145}
llb3921072023-01-10 14:47:46 +08001146
1147int lynq_find_already_end()
1148{
1149 for(int i=0;i < LYNQ_CALL_MAX; i++)
1150 {
1151 if(s_call_lists[i].call_state == 6)
1152 {
1153 return 0;
1154 }
1155 }
1156 return INVALID_ID;
1157}
1158
q.huangec88da92022-03-29 04:17:32 -04001159int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1160{
q.huang52921662022-10-20 15:25:45 +08001161 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001162 {
q.huang52921662022-10-20 15:25:45 +08001163 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1164 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001165 }
q.huangec88da92022-03-29 04:17:32 -04001166 int lynq_call_id = 0;
q.huang70b76492022-06-02 14:49:02 +08001167 LYINFLOG("lynq_get_current_call_state begin ");
q.huangec88da92022-03-29 04:17:32 -04001168 if(handle==NULL)
1169 {
q.huang70b76492022-06-02 14:49:02 +08001170 LYERRLOG("handle is NULL");
q.huang52921662022-10-20 15:25:45 +08001171 return LYNQ_E_PARAMETER_ANONALY;
q.huangec88da92022-03-29 04:17:32 -04001172 }
you.chen79d8f932023-12-26 17:03:44 +08001173 if((*handle) <= 0)
1174 {
1175 LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);
1176 return LYNQ_E_INVALID_ID_ANONALY;
1177 }
llb3921072023-01-10 14:47:46 +08001178 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huang70b76492022-06-02 14:49:02 +08001179 lynq_call_id = find_call_id_with_call_id(*handle);
1180 if(lynq_call_id==INVALID_ID)
1181 {
llb3921072023-01-10 14:47:46 +08001182 //find end state
1183 if((*handle) >= 0)
1184 {
1185 *call_state = (int)LYNQ_CALL_END;
1186 return RESULT_OK;
1187 }
1188 else
1189 {
1190 return LYNQ_E_INVALID_ID_ANONALY;
1191 }
q.huang70b76492022-06-02 14:49:02 +08001192 }
q.huang52921662022-10-20 15:25:45 +08001193 *call_state = s_call_lists[lynq_call_id].call_state;
1194 *toa = s_call_lists[lynq_call_id].toa;
1195 *direction = s_call_lists[lynq_call_id].direction;
1196 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
llb3921072023-01-10 14:47:46 +08001197 return RESULT_OK;
q.huangec88da92022-03-29 04:17:32 -04001198}
1199
q.huange97cfcf2022-08-29 20:04:31 +08001200int lynq_get_current_call_number()
1201{
1202 int cnt=0;
1203 int i;
1204 for(i = 0;i < LYNQ_CALL_MAX;i++)
1205 {
q.huang52921662022-10-20 15:25:45 +08001206 if(s_call_lists[i].used !=0)
q.huange97cfcf2022-08-29 20:04:31 +08001207 {
1208 cnt++;
1209 }
1210 }
1211
1212 return cnt;
1213}
1214
q.huangec88da92022-03-29 04:17:32 -04001215/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001216static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001217 switch(enable){
1218 case 0:
q.huang52921662022-10-20 15:25:45 +08001219 return true;
llf512fa32022-02-14 08:58:16 +00001220 case 1:
q.huang52921662022-10-20 15:25:45 +08001221 return true;
llf512fa32022-02-14 08:58:16 +00001222 default:
q.huang52921662022-10-20 15:25:45 +08001223 return false;
lldc99c9b2022-01-24 12:16:22 +00001224 }
1225}
1226
lh7b0674a2022-01-10 00:34:35 -08001227int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001228{
q.huang52921662022-10-20 15:25:45 +08001229 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001230 {
q.huang52921662022-10-20 15:25:45 +08001231 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001232 return LYNQ_E_CONFLICT;
1233 }
q.huang52921662022-10-20 15:25:45 +08001234 if(!judge_mic(enable)){
1235 return LYNQ_E_PARAMETER_ANONALY;
1236 }
1237 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1238
1239 Parcel* p=NULL;
1240 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1241 if(ret==RESULT_OK)
1242 {
1243 delete p;
1244 }
1245 return ret;
q.huangec88da92022-03-29 04:17:32 -04001246}
1247int lynq_get_mute_mic(int *status)
1248{
q.huang52921662022-10-20 15:25:45 +08001249 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001250 {
q.huang52921662022-10-20 15:25:45 +08001251 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1252 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001253 }
q.huang52921662022-10-20 15:25:45 +08001254 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh7b0674a2022-01-10 00:34:35 -08001255}
ll72bf6c12022-03-24 10:22:25 +08001256
1257/**
1258 * @brief Check whether DTMF is valid
1259 *
1260 * @param callnum dtmf eg:0-9 * #
1261 * @return int
1262 */
1263static int judge_dtmf(const char callnum)
1264{
1265 if(callnum == '#')
1266 {
q.huang52921662022-10-20 15:25:45 +08001267 return true;
ll72bf6c12022-03-24 10:22:25 +08001268 }
1269 if(callnum == '*')
1270 {
q.huang52921662022-10-20 15:25:45 +08001271 return true;
ll72bf6c12022-03-24 10:22:25 +08001272 }
1273 if(callnum >= '0'&& callnum <= '9')
1274 {
q.huang52921662022-10-20 15:25:45 +08001275 return true;
ll72bf6c12022-03-24 10:22:25 +08001276 }
q.huang52921662022-10-20 15:25:45 +08001277 return false;
ll72bf6c12022-03-24 10:22:25 +08001278}
1279
ll209e6112022-07-20 09:30:19 +00001280int lynq_switch_waiting_or_holding_and_active(void)
1281{
q.huang52921662022-10-20 15:25:45 +08001282 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001283 {
q.huang52921662022-10-20 15:25:45 +08001284 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1285 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001286 }
q.huang52921662022-10-20 15:25:45 +08001287
1288 Parcel* p=NULL;
1289 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1290 if(ret==RESULT_OK)
1291 {
1292 delete p;
1293 }
1294 return ret;
1295
1296#if 0
ll209e6112022-07-20 09:30:19 +00001297 Parcel p;
1298 lynq_client_t client;
1299 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001300 int token;
ll209e6112022-07-20 09:30:19 +00001301 int request = -1;
1302 int slot_id = -1;
1303 int error = -1;
1304 client.uToken = Global_uToken_call;
1305 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1306 client.paramLen = 0;
1307 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1308 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001309 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001310 if(send_request(lynq_call_client_sockfd,&client)==-1)
1311 {
1312 LYERRLOG("send request fail");
1313 return -1;
1314 }
1315 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001316 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001317 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001318 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1319 return error;
q.huang52921662022-10-20 15:25:45 +08001320#endif
ll209e6112022-07-20 09:30:19 +00001321}
1322
1323int lynq_hangup_waiting_or_background(void)
1324{
q.huang52921662022-10-20 15:25:45 +08001325 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001326 {
q.huang52921662022-10-20 15:25:45 +08001327 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1328 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001329 }
q.huang52921662022-10-20 15:25:45 +08001330
1331 Parcel* p=NULL;
1332 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1333 if(ret==RESULT_OK)
1334 {
1335 delete p;
1336 }
1337 return ret;
1338#if 0
ll209e6112022-07-20 09:30:19 +00001339 Parcel p;
1340 lynq_client_t client;
1341 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001342 int token;
ll209e6112022-07-20 09:30:19 +00001343 int request = -1;
1344 int slot_id = -1;
1345 int error = -1;
1346 client.uToken = Global_uToken_call;
1347 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1348 client.paramLen = 0;
1349 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1350 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001351 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001352 if(send_request(lynq_call_client_sockfd,&client)==-1)
1353 {
1354 LYERRLOG("send request fail");
1355 return -1;
1356 }
1357 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001358 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001359 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001360 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1361 return error;
q.huang52921662022-10-20 15:25:45 +08001362#endif
ll209e6112022-07-20 09:30:19 +00001363}
1364
1365int lynq_hangup_foreground_resume_background(void)
1366{
q.huang52921662022-10-20 15:25:45 +08001367 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001368 {
q.huang52921662022-10-20 15:25:45 +08001369 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1370 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001371 }
q.huang52921662022-10-20 15:25:45 +08001372
1373 Parcel* p=NULL;
1374 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1375 if(ret==RESULT_OK)
1376 {
1377 delete p;
1378 }
1379 return ret;
1380#if 0
ll209e6112022-07-20 09:30:19 +00001381 Parcel p;
1382 lynq_client_t client;
1383 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001384 int token;
ll209e6112022-07-20 09:30:19 +00001385 int request = -1;
1386 int slot_id = -1;
1387 int error = -1;
1388 client.uToken = Global_uToken_call;
1389 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1390 client.paramLen = 0;
1391 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1392 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001393 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001394 if(send_request(lynq_call_client_sockfd,&client)==-1)
1395 {
1396 LYERRLOG("send request fail");
1397 return -1;
1398 }
1399 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001400 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001401 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001402 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1403 return error;
q.huang52921662022-10-20 15:25:45 +08001404#endif
ll209e6112022-07-20 09:30:19 +00001405}
1406
lh7b0674a2022-01-10 00:34:35 -08001407int lynq_set_DTMF(const char callnum)
1408{
q.huang52921662022-10-20 15:25:45 +08001409 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001410 {
q.huang52921662022-10-20 15:25:45 +08001411 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1412 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001413 }
ll72bf6c12022-03-24 10:22:25 +08001414 if(!judge_dtmf(callnum))
1415 {
1416 return LYNQ_E_CONFLICT;
1417 }
q.huang52921662022-10-20 15:25:45 +08001418 if(s_module_call_state!=CALL_ON)
lh7b0674a2022-01-10 00:34:35 -08001419 {
1420 LYERRLOG("LYNQ_E_CONFLICT");
1421 return LYNQ_E_CONFLICT;
1422 }
q.huang52921662022-10-20 15:25:45 +08001423
1424// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1425
1426 Parcel* p=NULL;
1427 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1428 if(ret==RESULT_OK)
1429 {
1430 delete p;
1431 }
1432 return ret;
lh7b0674a2022-01-10 00:34:35 -08001433}
q.huangec88da92022-03-29 04:17:32 -04001434static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1435 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1436 if(volume < 0 ||volume >36){
1437 return 0;
1438 }
1439 }
1440 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1441 {
1442 if(volume < 1 ||volume >7){
1443 return 0;
1444 }
lldc99c9b2022-01-24 12:16:22 +00001445 }
ll04ae4142022-01-27 05:54:38 +00001446 return 1;
lldc99c9b2022-01-24 12:16:22 +00001447}
lh7b0674a2022-01-10 00:34:35 -08001448int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001449{
q.huang52921662022-10-20 15:25:45 +08001450 if(g_module_init_flag != MODULE_RUNNING)
1451 {
1452 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001453 return LYNQ_E_CONFLICT;
1454 }
q.huang52921662022-10-20 15:25:45 +08001455 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1456 return LYNQ_E_PARAMETER_ANONALY;
1457 }
1458// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1459 Parcel* p=NULL;
1460 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1461 if(ret==RESULT_OK)
1462 {
1463 delete p;
1464 }
1465 return ret;
lh7b0674a2022-01-10 00:34:35 -08001466}
q.huangb212fde2022-04-05 23:11:02 -04001467int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001468{
q.huang52921662022-10-20 15:25:45 +08001469 if(g_module_init_flag != MODULE_RUNNING)
lh7b0674a2022-01-10 00:34:35 -08001470 {
q.huang52921662022-10-20 15:25:45 +08001471 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangec88da92022-03-29 04:17:32 -04001472 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001473 }
q.huang52921662022-10-20 15:25:45 +08001474 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1475 {
1476 return LYNQ_E_PARAMETER_ANONALY;
1477 }
1478// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1479 Parcel* p=NULL;
1480 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1481 if(ret==RESULT_OK)
1482 {
1483 delete p;
1484 }
1485 return ret;
lh7b0674a2022-01-10 00:34:35 -08001486}
q.huangec88da92022-03-29 04:17:32 -04001487int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1488{
q.huang52921662022-10-20 15:25:45 +08001489 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangec88da92022-03-29 04:17:32 -04001490}
q.huangb212fde2022-04-05 23:11:02 -04001491int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001492{
q.huang52921662022-10-20 15:25:45 +08001493// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1494 Parcel* p=NULL;
1495 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1496 if(ret==RESULT_OK)
1497 {
1498 delete p;
1499 }
1500 return ret;
q.huangec88da92022-03-29 04:17:32 -04001501}
1502int lynq_incall_record_stop()
1503{
q.huang52921662022-10-20 15:25:45 +08001504 if(g_module_init_flag != MODULE_RUNNING)
1505 {
1506 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1507 return LYNQ_E_CONFLICT;
1508 }
q.huangb212fde2022-04-05 23:11:02 -04001509 const char* unused_file="just_ocuupy_paramter_postion";
q.huang52921662022-10-20 15:25:45 +08001510// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1511 Parcel* p=NULL;
1512 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1513 if(ret==RESULT_OK)
1514 {
1515 delete p;
1516 }
1517 return ret;
q.huangec88da92022-03-29 04:17:32 -04001518}
1519/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001520
q.huang036b6cf2023-01-10 14:29:20 +08001521
1522
1523bool is_support_urc(int urc_id)
1524{
1525 switch(urc_id)
1526 {
1527 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1528 case RIL_UNSOL_CALL_RING:
1529 case RIL_UNSOL_RINGBACK_TONE:
1530 case RIL_UNSOL_CALL_INFO_INDICATION:
1531#ifdef ECALL_SUPPORT
1532 case RIL_UNSOL_ECALL_INDICATIONS://9502
1533#endif
1534 return true;
1535 default:
1536 return false;
1537 }
1538}
1539
q.huang52921662022-10-20 15:25:45 +08001540void urc_msg_process(Parcel *p)
1541{
1542 int resp_type;
1543 int urcid;
1544 int slot_id;
q.huang036b6cf2023-01-10 14:29:20 +08001545
1546 int size=p->dataSize();
q.huang52921662022-10-20 15:25:45 +08001547 p->readInt32(&resp_type);
1548 p->readInt32(&urcid);
1549 p->readInt32(&slot_id);
q.huang036b6cf2023-01-10 14:29:20 +08001550 LYINFLOG("%s urc id = %d, slot_id = %d, size is %d, msg is %s",__func__, urcid,slot_id,size,requestToString(urcid));
q.huang52921662022-10-20 15:25:45 +08001551 switch (urcid)
1552 {
1553 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1554 {
1555 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1556 lynqNoticeGetModuleCallList();
1557 break;
1558 }
1559 case RIL_UNSOL_CALL_RING: //1018
1560 {
q.huang305fadc2024-01-02 18:40:40 +08001561 time(&s_rev_ring_time);
q.huang52921662022-10-20 15:25:45 +08001562 if(s_call_auto_answer==1)
1563 {
1564 lynq_call_answer();
1565 }
1566 break;
1567 }
1568 case RIL_UNSOL_RINGBACK_TONE: //1029
1569 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1570 {
1571 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1572 break;
1573 }
q.huang714145d2022-04-18 00:09:50 -04001574#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +08001575 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange97cfcf2022-08-29 20:04:31 +08001576 {
q.huang52921662022-10-20 15:25:45 +08001577 urc_ecall_msg_process(p);
q.huange97cfcf2022-08-29 20:04:31 +08001578 }
q.huange97cfcf2022-08-29 20:04:31 +08001579#endif
q.huang52921662022-10-20 15:25:45 +08001580 default:
1581 break;
q.huangcb7b7292022-06-28 20:12:01 +08001582 }
q.huang5ca6c072022-06-06 16:15:31 +08001583}
q.huang5ca6c072022-06-06 16:15:31 +08001584
lh7b0674a2022-01-10 00:34:35 -08001585#if 0
1586int main(int argc,char **argv)
1587{
1588 int n = 0;
1589 n = lynq_init_call(lynq_call_state_change_test,2222);
1590 if(n<0)
1591 {
q.huang70b76492022-06-02 14:49:02 +08001592 LYDBGLOG("lynq init call fail!!!");
lh7b0674a2022-01-10 00:34:35 -08001593 return -1;
1594 }
q.huang70b76492022-06-02 14:49:02 +08001595 LYDBGLOG("lynq call init success!!!");
lh7b0674a2022-01-10 00:34:35 -08001596 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1597 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1598 lynq_call(phoneNum);
1599 while(1)
1600 {
1601 sleep(1);
1602 }
1603 return 0;
1604}
1605#endif
1606/*Warren add for T800 platform 2021/11/19 end*/