blob: 292c4fe317b8d8e1250014b6c69d17d1adf459e6 [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"
l.yangd25d3712024-03-04 17:55:39 -080033#define CALL_REBOOT_FLAG "/tmp/.call_reboot_flag"
34#define SYSTEM_UPTIME 40
q.huang305fadc2024-01-02 18:40:40 +080035#define MAX_RING_INCOMING_INTERVAL 10
36
lh7b0674a2022-01-10 00:34:35 -080037using ::android::Parcel;
q.huang52921662022-10-20 15:25:45 +080038
39/**
40 * @brief mark call initialization state
41 * 0: deinit state
42 * 1: init state
43 */
44int g_module_init_flag = 0;
45
lh7b0674a2022-01-10 00:34:35 -080046 typedef enum {
47 LYNQ_CALL_ACTIVE = 0,
48 LYNQ_CALL_HOLDING = 1,
49 LYNQ_CALL_DIALING = 2, /* MO call only */
50 LYNQ_CALL_ALERTING = 3, /* MO call only */
51 LYNQ_CALL_INCOMING = 4, /* MT call only */
lhe45b7002022-04-26 00:45:44 -070052 LYNQ_CALL_WAITING = 5, /* MT call only */
53 /*warren add for T800 platform 2022/04/26 start*/
54 LYNQ_CALL_END = 6, /*CALL END*/
55 /*warren add for T800 platform 2022/04/26 end*/
lh7b0674a2022-01-10 00:34:35 -080056}lynq_call_state_t;
57
lh7b0674a2022-01-10 00:34:35 -080058typedef struct
59{
60 int used;
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];
lh7b0674a2022-01-10 00:34:35 -080066}lynq_call_list_e_t;
67typedef struct
68{
69 int call_id;
70 int call_state;
71 int toa;
72 int direction;/*0: MO call,1:MT call*/
73 char addr[LYNQ_PHONE_NUMBER_MAX];
74}lynq_call_list_t;
75
q.huang52921662022-10-20 15:25:45 +080076static lynq_call_list_e_t s_call_lists[LYNQ_CALL_MAX]={};
77static bool s_call_list_loop = 0;
78static pthread_t s_call_list_loop_tid = -1;
79static pthread_mutex_t s_notice_get_call_list_mutex = PTHREAD_MUTEX_INITIALIZER;
80static pthread_cond_t s_notice_get_call_list_cond = PTHREAD_COND_INITIALIZER;
81
82static int s_module_isDial = 0;
lh7b0674a2022-01-10 00:34:35 -080083static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
84static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
llb3921072023-01-10 14:47:46 +080085static int s_CallId = 0;
86static pthread_mutex_t s_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
87static pthread_cond_t s_call_state_change_cond = PTHREAD_COND_INITIALIZER;
lhec17b0a2022-02-13 23:56:05 -080088
q.huang52921662022-10-20 15:25:45 +080089static int s_module_call_state =CALL_OFF;
90static int s_call_auto_answer = 0;
q.huang305fadc2024-01-02 18:40:40 +080091static time_t s_rev_ring_time=0;
92
l.yang4419f452024-04-24 23:52:25 -070093#ifdef MODE_DSDS
94int global_slot = -1;
l.yang1d80f782024-05-13 19:35:54 -070095int urc_slot = -1;
l.yang4419f452024-04-24 23:52:25 -070096#endif
97
lh7b0674a2022-01-10 00:34:35 -080098
q.huangec88da92022-03-29 04:17:32 -040099typedef enum{
100 LYNQ_E_VOLUMN_SET_DTMF,
101 LYNQ_E_VOLUMN_SET_SPEECH
q.huang52921662022-10-20 15:25:45 +0800102}LYNQ_E_VOLUMN_SET;
lh7b0674a2022-01-10 00:34:35 -0800103
q.huang52921662022-10-20 15:25:45 +0800104#if 0
q.huang7de1d662022-09-13 14:19:24 +0800105int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
lh7b0674a2022-01-10 00:34:35 -0800106{
107 if(p.dataAvail() > 0)
108 {
109 p.readInt32(resp_type);
q.huang7de1d662022-09-13 14:19:24 +0800110 p.readInt32(token);
lh7b0674a2022-01-10 00:34:35 -0800111 p.readInt32(request);
112 p.readInt32(slot_id);
113 p.readInt32(error);
114 return 0;
115 }
116 else
117 {
118 return -1;
119 }
120}
121int send_request(int sockfd,lynq_client_t *client_tmp)
122{
123 int ret=0;
rjw5d2a50e2022-02-28 15:01:49 +0800124 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800125 if(ret==-1)
126 {
q.huang70b76492022-06-02 14:49:02 +0800127 LYERRLOG("sendto error");
lh7b0674a2022-01-10 00:34:35 -0800128 return -1;
129 }
130 return 0;
131}
132
133int get_response(int sockfd,Parcel &p)
134{
135 int len = 0;
136 char recvline[LYNQ_REC_BUF];
137 bzero(recvline,LYNQ_REC_BUF);
138 /* receive data from server */
rjw5d2a50e2022-02-28 15:01:49 +0800139 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800140 if(len == -1)
141 {
q.huang70b76492022-06-02 14:49:02 +0800142 LYERRLOG("recvfrom error");
lh7b0674a2022-01-10 00:34:35 -0800143 return -1;
144 }
lh7b0674a2022-01-10 00:34:35 -0800145 if (recvline != NULL) {
146 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
147 p.setDataPosition(0);
148 }
149 return 0;
150}
q.huang52921662022-10-20 15:25:45 +0800151#endif
152static char *strdupReadString(Parcel* &p) {
ll04ae4142022-01-27 05:54:38 +0000153 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800154 const char16_t *s16;
q.huang52921662022-10-20 15:25:45 +0800155 s16 = p->readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000156 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800157}
158
159int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
160{
q.huang52921662022-10-20 15:25:45 +0800161 Parcel* p=NULL;
162 int ret=lynq_send_common_request(p,8,RIL_REQUEST_GET_CURRENT_CALLS,0,"");
163 if(ret!=0)
164 {
165 return ret;
166 }
167
168 int call_num = 0;
169 int temp = 0;
170 char *remote_phoneNum;
171 char *remote_name;
172 char uusData[128];
173
174 p->readInt32(&call_num);
175
176 if(call_num<=0)
177 {
178 s_module_call_state = CALL_OFF;
179 LYINFLOG("lynq_call_state:%d",s_module_call_state);
180 delete p;
181 return RESULT_OK;
182 }
183 s_module_call_state = CALL_ON;
184 LYINFLOG("lynq_call_state:%d, call num is %d ",s_module_call_state,call_num);
185 for(int i = 0;i < call_num;i++)
186 {
187 p->readInt32(&temp);
188 call_list[i].call_state = temp;
189 p->readInt32(&call_list[i].call_id);
190 p->readInt32(&call_list[i].toa);
191 p->readInt32(&temp);
192 p->readInt32(&temp);
193 call_list[i].direction = temp;
194 p->readInt32(&temp);
195 p->readInt32(&temp);
196 p->readInt32(&temp);
197 remote_phoneNum = strdupReadString(p);
198 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
199 if(remote_phoneNum !=NULL)
200 {
201 free(remote_phoneNum);
202 }
203 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
204 call_list[i].direction,call_list[i].addr,call_list[i].toa);
205 p->readInt32(&temp);
206 remote_name = strdupReadString(p);
207 if(remote_name !=NULL)
208 {
209 free(remote_name);
210 }
211 p->readInt32(&temp);
212 p->readInt32(&temp);
213 if(temp==0)
214 {
215 continue;
216 }
217 p->readInt32(&temp); /* UUS Information is present */
218 p->readInt32(&temp);
219 p->readInt32(&temp);
220 if(temp<=128)
221 {
222 p->read(uusData,temp);
223 }
224 else
225 {
226 LYERRLOG("%s len %d is too great",__func__,temp);
227 delete p;
228 return LYNQ_E_MALLOC_ERROR;
229 }
230 }
231
232 delete p;
233 return RESULT_OK;
234
235#if 0
lh7b0674a2022-01-10 00:34:35 -0800236 Parcel p;
237 lynq_client_t client;
238 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800239 int token;
lh7b0674a2022-01-10 00:34:35 -0800240 int request = -1;
241 int slot_id = -1;
242 int error = -1;
243 int call_num = 0;
244 int temp = 0;
245 char *remote_phoneNum = NULL;
246 char *remote_name= NULL;
247 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800248 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800249 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
250 client.paramLen = 0;
251 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang70b76492022-06-02 14:49:02 +0800252 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800253 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800254 {
255 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800256 return -1;
257 }
lh42c1e572022-01-25 18:47:39 -0800258 get_response(lynq_call_client_sockfd,p);
q.huang7de1d662022-09-13 14:19:24 +0800259 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh7b0674a2022-01-10 00:34:35 -0800260 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
261 if(error == 0)
262 {
263 p.readInt32(&call_num);
264 global_call_count = call_num;
265 if(call_num<=0)
266 {
267 lynq_call_state = CALL_OFF;
lhec17b0a2022-02-13 23:56:05 -0800268 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800269 return 0;
270 }
lhec17b0a2022-02-13 23:56:05 -0800271 lynq_call_state = CALL_ON;
q.huang70b76492022-06-02 14:49:02 +0800272 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh7b0674a2022-01-10 00:34:35 -0800273 for(int i = 0;i < call_num;i++)
274 {
275 p.readInt32(&temp);
276 call_list[i].call_state = temp;
277 p.readInt32(&call_list[i].call_id);
278 p.readInt32(&call_list[i].toa);
279 p.readInt32(&temp);
280 p.readInt32(&temp);
281 call_list[i].direction = temp;
282 p.readInt32(&temp);
283 p.readInt32(&temp);
284 p.readInt32(&temp);
285 remote_phoneNum = strdupReadString(p);
286 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
287 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
288 call_list[i].direction,call_list[i].addr,call_list[i].toa);
289 p.readInt32(&temp);
290 remote_name = strdupReadString(p);
291 p.readInt32(&temp);
292 p.readInt32(&temp);
293 if(temp==0)
294 {
295 continue;
296 }
297 p.readInt32(&temp); /* UUS Information is present */
298 p.readInt32(&temp);
299 p.readInt32(&temp);
300 p.read(uusData,temp);
301 }
302 }
303 return 0;
q.huang52921662022-10-20 15:25:45 +0800304#endif
lh7b0674a2022-01-10 00:34:35 -0800305}
306
307void cleanCallList(int lynq_call_id)
308{
q.huang52921662022-10-20 15:25:45 +0800309 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
310 s_call_lists[lynq_call_id].call_id = 0;
311 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
312 s_call_lists[lynq_call_id].toa = 0;
313 s_call_lists[lynq_call_id].direction = 0;
314 s_call_lists[lynq_call_id].used = 0;
315 memset(s_call_lists[lynq_call_id].addr,0,sizeof(s_call_lists[lynq_call_id].addr));
lh7b0674a2022-01-10 00:34:35 -0800316}
llb3921072023-01-10 14:47:46 +0800317
318
lh7b0674a2022-01-10 00:34:35 -0800319int getUnusedElement()
320{
321 for(int i=0;i < LYNQ_CALL_MAX; i++)
322 {
q.huang52921662022-10-20 15:25:45 +0800323 if(s_call_lists[i].used!=1)
lh7b0674a2022-01-10 00:34:35 -0800324 {
325 return i;
326 }
327 }
q.huang52921662022-10-20 15:25:45 +0800328 return INVALID_ID;
lh7b0674a2022-01-10 00:34:35 -0800329}
q.huang52921662022-10-20 15:25:45 +0800330int addAddr(char addr[], int call_id)
lh7b0674a2022-01-10 00:34:35 -0800331{
332 int ret = 0;
333 ret = getUnusedElement();
q.huang52921662022-10-20 15:25:45 +0800334 memcpy(s_call_lists[ret].addr,addr,strlen(addr)+1);
335 s_call_lists[ret].call_id=call_id;
336 s_call_lists[ret].used = 1;
q.huang70b76492022-06-02 14:49:02 +0800337 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh7b0674a2022-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.huang70b76492022-06-02 14:49:02 +0800342 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh7b0674a2022-01-10 00:34:35 -0800343 callList->call_id = call_id;
344 callList->call_state = call_state;
345 callList->toa = toa;
q.huang70b76492022-06-02 14:49:02 +0800346 callList->direction = direction;
lh7b0674a2022-01-10 00:34:35 -0800347 return;
348}
llb3921072023-01-10 14:47:46 +0800349
350void wait_call_state()
lh7b0674a2022-01-10 00:34:35 -0800351{
llb3921072023-01-10 14:47:46 +0800352 LYINFLOG("call state changed");
353 pthread_mutex_lock(&s_call_state_change_mutex);
354 pthread_cond_wait(&s_call_state_change_cond,&s_call_state_change_mutex);
355 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800356}
llb3921072023-01-10 14:47:46 +0800357
lh7b0674a2022-01-10 00:34:35 -0800358int checkHasCall(char addr[])
359{
360 for(int i = 0;i<LYNQ_CALL_MAX;i++)
361 {
q.huang52921662022-10-20 15:25:45 +0800362 if(strcmp(s_call_lists[i].addr,addr)==0)
lh7b0674a2022-01-10 00:34:35 -0800363 {
q.huang52921662022-10-20 15:25:45 +0800364 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,s_call_lists[i].call_id);
365 return true;
lh7b0674a2022-01-10 00:34:35 -0800366 }
367 }
q.huang70b76492022-06-02 14:49:02 +0800368 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
q.huang52921662022-10-20 15:25:45 +0800369 return false;
lh7b0674a2022-01-10 00:34:35 -0800370}
lhd1e457c2022-04-19 06:01:25 -0700371int find_call_id_with_addr(char *addr)
372{
lhd1e457c2022-04-19 06:01:25 -0700373 for(int id = 0; id < LYNQ_CALL_MAX; id++)
374 {
q.huang52921662022-10-20 15:25:45 +0800375 if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
lhd1e457c2022-04-19 06:01:25 -0700376 {
q.huang52921662022-10-20 15:25:45 +0800377 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 -0700378 return id;
379 }
380 }
q.huang70b76492022-06-02 14:49:02 +0800381 LYINFLOG("find addr %s in local list , not found",addr);
q.huang52921662022-10-20 15:25:45 +0800382 return INVALID_ID;
lhd1e457c2022-04-19 06:01:25 -0700383}
q.huang70b76492022-06-02 14:49:02 +0800384int find_call_id_with_call_id(int call_id)
385{
386 for(int id = 0; id < LYNQ_CALL_MAX; id++)
387 {
q.huang52921662022-10-20 15:25:45 +0800388 if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
q.huang70b76492022-06-02 14:49:02 +0800389 {
q.huang52921662022-10-20 15:25:45 +0800390 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 +0800391 return id;
392 }
393 }
394 LYINFLOG("find id %d in local list , not found",call_id);
395 return INVALID_ID;
396}
lh7b0674a2022-01-10 00:34:35 -0800397void sendSignalToWaitCallStateChange()
398{
lhd1e457c2022-04-19 06:01:25 -0700399 LYINFLOG("send Signal To Wait Call State Change");
lh7b0674a2022-01-10 00:34:35 -0800400 pthread_mutex_lock(&call_state_change_mutex);
401 pthread_cond_signal(&call_state_change_cond);
402 pthread_mutex_unlock(&call_state_change_mutex);
403}
you.chen79d8f932023-12-26 17:03:44 +0800404void send_call_state_change(int callid)
lh7b0674a2022-01-10 00:34:35 -0800405{
llb3921072023-01-10 14:47:46 +0800406 LYINFLOG("send call state change");
you.chen79d8f932023-12-26 17:03:44 +0800407 s_CallId = callid;
llb3921072023-01-10 14:47:46 +0800408 pthread_mutex_lock(&s_call_state_change_mutex);
409 pthread_cond_signal(&s_call_state_change_cond);
410 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800411}
412
q.huang52921662022-10-20 15:25:45 +0800413void cleanup_call_list_mutex(void *arg)
lh7b0674a2022-01-10 00:34:35 -0800414{
q.huang52921662022-10-20 15:25:45 +0800415 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
lh7b0674a2022-01-10 00:34:35 -0800416}
llb3921072023-01-10 14:47:46 +0800417
418void update_end_state(int lynq_call_id)
419{
420 LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
421 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
422}
423
lh7b0674a2022-01-10 00:34:35 -0800424void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000425{
426 int ret=0;
lhd1e457c2022-04-19 06:01:25 -0700427 bool call_end;
ll04ae4142022-01-27 05:54:38 +0000428 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang8b33ed52022-04-19 20:27:44 -0400429 int update=0;
q.huang70b76492022-06-02 14:49:02 +0800430 int cnt;
431 int i,n;
q.huange97cfcf2022-08-29 20:04:31 +0800432#ifdef ECALL_SUPPORT
433 int handupIncomingMT=0;
434#endif
q.huang305fadc2024-01-02 18:40:40 +0800435 unsigned long interval;
436 time_t now;
437
438
q.huang52921662022-10-20 15:25:45 +0800439 pthread_mutex_lock(&s_notice_get_call_list_mutex);
440 pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
you.chen79d8f932023-12-26 17:03:44 +0800441 int tmp_call_id;
q.huang52921662022-10-20 15:25:45 +0800442 while(s_call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000443 {
q.huang52921662022-10-20 15:25:45 +0800444 update=0;
445 pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
you.chen79d8f932023-12-26 17:03:44 +0800446 LYINFLOG("triggerGetCallList event %p!!!", pthread_self());
ll04ae4142022-01-27 05:54:38 +0000447 memset(call_list,0,sizeof(call_list));
448 ret = lynq_get_current_call_list(call_list);
q.huang52921662022-10-20 15:25:45 +0800449 if(ret != RESULT_OK)
ll04ae4142022-01-27 05:54:38 +0000450 {
you.chen79d8f932023-12-26 17:03:44 +0800451 LYERRLOG("get current call list failure!!!");
llbc035332022-04-11 05:49:51 +0000452 continue;
ll04ae4142022-01-27 05:54:38 +0000453 }
lhd1e457c2022-04-19 06:01:25 -0700454 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huang70b76492022-06-02 14:49:02 +0800455 LYINFLOG("clear local index begin");
456 cnt=0;
457 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh7b0674a2022-01-10 00:34:35 -0800458 {
q.huang52921662022-10-20 15:25:45 +0800459 if(s_call_lists[i].used ==0)
q.huang70b76492022-06-02 14:49:02 +0800460 {
461 continue;
462 }
463 cnt++;
q.huang52921662022-10-20 15:25:45 +0800464 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 +0800465
q.huang52921662022-10-20 15:25:45 +0800466 if(s_call_lists[i].call_id > 0)
lhd1e457c2022-04-19 06:01:25 -0700467 {
468 call_end = 0;
q.huang70b76492022-06-02 14:49:02 +0800469 for(n = 0; n < LYNQ_CALL_MAX; n++)
lhd1e457c2022-04-19 06:01:25 -0700470 {
q.huang52921662022-10-20 15:25:45 +0800471 if(call_list[n].call_id == s_call_lists[i].call_id)
lhd1e457c2022-04-19 06:01:25 -0700472 {
473 call_end = 1;
q.huang52921662022-10-20 15:25:45 +0800474 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 +0800475 break;
lhd1e457c2022-04-19 06:01:25 -0700476 }
477 }
478 if(call_end == 0)
479 {
llb3921072023-01-10 14:47:46 +0800480 LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
481 //update_end_state(i);//lei modify for:update end state for this call
you.chen79d8f932023-12-26 17:03:44 +0800482 tmp_call_id = s_call_lists[i].call_id;
llb3921072023-01-10 14:47:46 +0800483 cleanCallList(i);
you.chen79d8f932023-12-26 17:03:44 +0800484 //Release the end handle
485 send_call_state_change(tmp_call_id);//means mt/mo call is end
llb3921072023-01-10 14:47:46 +0800486 //cleanCallList(i);
lhd1e457c2022-04-19 06:01:25 -0700487 }
488 } //fix bug API-54
q.huang70b76492022-06-02 14:49:02 +0800489 else
490 {
491 LYINFLOG("local id is 0");
492 }
493 }
494 LYINFLOG("clear local index end, local used cnt is %d", cnt);
495
496 LYINFLOG("add or update local index begin ");
497 for (i = 0;i < LYNQ_CALL_MAX;i++)
498 {
499 if(call_list[i].call_id==0)
500 {
501 break;
502 }
503
504 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,
505 call_list[i].direction,call_list[i].addr,call_list[i].toa);
506
lh7b0674a2022-01-10 00:34:35 -0800507 if(call_list[i].direction == 1)//MT call
508 {
q.huang70b76492022-06-02 14:49:02 +0800509 LYINFLOG("This is a MT CALL");
lh0fd3b012022-05-13 03:02:19 -0700510 /*MT CALL state code
511 **LYNQ_CALL_INCOMING = 4,
512 **LYNQ_CALL_WAITING = 5,
513 */
q.huange97cfcf2022-08-29 20:04:31 +0800514#ifdef ECALL_SUPPORT
lh0fd3b012022-05-13 03:02:19 -0700515 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh7b0674a2022-01-10 00:34:35 -0800516 {
q.huang52921662022-10-20 15:25:45 +0800517 handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
q.huange97cfcf2022-08-29 20:04:31 +0800518 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
519 if(handupIncomingMT)
lh7b0674a2022-01-10 00:34:35 -0800520 {
q.huang70b76492022-06-02 14:49:02 +0800521 lynq_call_hungup(&(call_list[i].call_id));
522 continue;
q.huange97cfcf2022-08-29 20:04:31 +0800523 }
q.huang70b76492022-06-02 14:49:02 +0800524 }
q.huange97cfcf2022-08-29 20:04:31 +0800525#endif
q.huang70b76492022-06-02 14:49:02 +0800526 /*you call me, and i call you,One party failed to dial*/
527 n = find_call_id_with_addr(call_list[i].addr);
528 if(n ==INVALID_ID)
529 {
q.huang305fadc2024-01-02 18:40:40 +0800530 if(s_call_auto_answer==false && call_list[i].call_state==LYNQ_CALL_INCOMING)
531 {
532 time(&now);
533 interval = difftime(now,s_rev_ring_time);
534 if(interval>MAX_RING_INCOMING_INTERVAL)
535 {
536 LYINFLOG("recv incoming, %d second no ril ring",interval);
537 continue;
538 }
539 }
540
q.huang52921662022-10-20 15:25:45 +0800541 n = addAddr(call_list[i].addr,call_list[i].call_id);
542 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 +0800543 send_call_state_change(call_list[i].call_id);
q.huang70b76492022-06-02 14:49:02 +0800544 }
q.huang52921662022-10-20 15:25:45 +0800545 else if(s_call_lists[n].call_state == call_list[i].call_state)
q.huang70b76492022-06-02 14:49:02 +0800546 {
547 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
548 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lhd1e457c2022-04-19 06:01:25 -0700549 {
lhd1e457c2022-04-19 06:01:25 -0700550 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
551 **an incoming call until the status changes.
552 **fix bug API-54
553 */
q.huang70b76492022-06-02 14:49:02 +0800554 LYINFLOG("resend incoming call signal");
you.chen79d8f932023-12-26 17:03:44 +0800555 send_call_state_change(call_list[i].call_id);
lhd1e457c2022-04-19 06:01:25 -0700556 }
lh7b0674a2022-01-10 00:34:35 -0800557 }
q.huang70b76492022-06-02 14:49:02 +0800558 else
ll72bf6c12022-03-24 10:22:25 +0800559 {
q.huang52921662022-10-20 15:25:45 +0800560 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 +0800561
llb3921072023-01-10 14:47:46 +0800562 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 +0800563 send_call_state_change(call_list[i].call_id);
llb3921072023-01-10 14:47:46 +0800564 }
lh7b0674a2022-01-10 00:34:35 -0800565 }
566 else
q.huang70b76492022-06-02 14:49:02 +0800567 {
568 LYINFLOG("This is a MO CALL");
569 call_end = 0;
570 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh7b0674a2022-01-10 00:34:35 -0800571 {
q.huang52921662022-10-20 15:25:45 +0800572 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 -0800573 {
q.huang52921662022-10-20 15:25:45 +0800574 if(s_call_lists[n].call_id==0)
q.huang70b76492022-06-02 14:49:02 +0800575 {
llb3921072023-01-10 14:47:46 +0800576 LYINFLOG("add a call id");
577 update=1;//for send sigal
q.huang70b76492022-06-02 14:49:02 +0800578 }
q.huang52921662022-10-20 15:25:45 +0800579 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);
580 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 +0800581 call_end = 1;
you.chen79d8f932023-12-26 17:03:44 +0800582 send_call_state_change(call_list[i].call_id);//means mo call is success
q.huang70b76492022-06-02 14:49:02 +0800583 break;
584 }
585 }
llb3921072023-01-10 14:47:46 +0800586 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 +0800587 {
588 LYINFLOG("need to hangup id %d", call_list[i].call_id);
589#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +0800590 if(IsECallDialing())
q.huang70b76492022-06-02 14:49:02 +0800591 {
592 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh7b0674a2022-01-10 00:34:35 -0800593 continue;
594 }
q.huang70b76492022-06-02 14:49:02 +0800595#endif
596 LYINFLOG("hang up service call id %d",call_list[i].call_id);
597 lynq_call_hungup(&(call_list[i].call_id));
lh7b0674a2022-01-10 00:34:35 -0800598 }
llb3921072023-01-10 14:47:46 +0800599
lh7b0674a2022-01-10 00:34:35 -0800600 }
q.huang70b76492022-06-02 14:49:02 +0800601 LYDBGLOG("servie idx %d end",i);
ll04ae4142022-01-27 05:54:38 +0000602 }
q.huang52921662022-10-20 15:25:45 +0800603 LYINFLOG("add or update local index end ");
604 if(s_module_isDial==1)
lh7b0674a2022-01-10 00:34:35 -0800605 {
q.huang70b76492022-06-02 14:49:02 +0800606 LYINFLOG("now is dialing");
607 if(update==1)
608 {
609 LYINFLOG("find added call");
610 sendSignalToWaitCallStateChange();
q.huang52921662022-10-20 15:25:45 +0800611 s_module_isDial = 0;
q.huang70b76492022-06-02 14:49:02 +0800612 }
613 else
614 {
615 LYINFLOG("not find added call");
616 }
617 }
618 else
619 {
620 LYINFLOG("now is not dialing");
q.huang52921662022-10-20 15:25:45 +0800621 }
ll04ae4142022-01-27 05:54:38 +0000622 }
q.huang52921662022-10-20 15:25:45 +0800623 pthread_cleanup_pop(0);
624 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
ll04ae4142022-01-27 05:54:38 +0000625 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800626}
627
q.huang52921662022-10-20 15:25:45 +0800628void lynqNoticeGetModuleCallList()
ll04ae4142022-01-27 05:54:38 +0000629{
you.chen79d8f932023-12-26 17:03:44 +0800630 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send start");
q.huang52921662022-10-20 15:25:45 +0800631 pthread_mutex_lock(&s_notice_get_call_list_mutex);
632 pthread_cond_signal(&s_notice_get_call_list_cond);
633 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
you.chen79d8f932023-12-26 17:03:44 +0800634 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send end");
lh7b0674a2022-01-10 00:34:35 -0800635}
636
q.huang52921662022-10-20 15:25:45 +0800637#if 0
lh7b0674a2022-01-10 00:34:35 -0800638/*Warren add for T800 platform 2021/11/19 start*/
639int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800640{
641 #if 0
lh7b0674a2022-01-10 00:34:35 -0800642 struct sockaddr_in lynq_socket_server_addr;
643 /* init lynq_socket_server_addr */
644 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
645 lynq_socket_server_addr.sin_family = AF_INET;
646 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
647 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800648
lh7b0674a2022-01-10 00:34:35 -0800649 /*
650 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
651 {
q.huang70b76492022-06-02 14:49:02 +0800652 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800653 exit(1);
654 }
655*/
lh42c1e572022-01-25 18:47:39 -0800656 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
657 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800658 {
q.huang70b76492022-06-02 14:49:02 +0800659 LYERRLOG("connect error");
lh7b0674a2022-01-10 00:34:35 -0800660 return -1;
661 }
rjw5d2a50e2022-02-28 15:01:49 +0800662 #endif
663 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
664 if (-1 == lynq_call_client_sockfd)
665 {
666 return lynq_call_client_sockfd;
667 }
ll630be412022-07-25 05:52:14 +0000668 struct timeval timeOut;
669 timeOut.tv_sec = 60;
670 timeOut.tv_usec = 0;
671 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
672 {
673 RLOGD("time out setting failed\n");
674 return -1;
675 }
rjw5d2a50e2022-02-28 15:01:49 +0800676 /* 设置address */
677 memset(&addr_serv, 0, sizeof(addr_serv));
678 addr_serv.sin_family = AF_INET;
679 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
680 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
681 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800682 return 0;
683}
lh7b0674a2022-01-10 00:34:35 -0800684
lh7b0674a2022-01-10 00:34:35 -0800685int lynq_socket_urc_start()
686{
687 int socket_fd=0;
688 int rt=0;
689 int len=0;
690 int on=1;
691 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800692 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000693 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000694 if(socket_fd < 0)
695 {
q.huang70b76492022-06-02 14:49:02 +0800696 LYERRLOG("creaet socket for udp fail");
ll04ae4142022-01-27 05:54:38 +0000697 return -1;
lh7b0674a2022-01-10 00:34:35 -0800698 }
699 urc_local_addr.sin_family = AF_INET;
700 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
701 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
702 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000703 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
704 if(rt<0)
705 {
q.huang70b76492022-06-02 14:49:02 +0800706 LYERRLOG("SO_REUSEADDR fail");
lh7b0674a2022-01-10 00:34:35 -0800707 return -1;
708 }
709 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000710 if (rt == -1)
711 {
lh21502f52022-01-27 00:27:12 -0800712 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000713 return -1;
lh7b0674a2022-01-10 00:34:35 -0800714 }
715 pthread_attr_init(&attr);
716 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800717 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800718 if(rt < 0)
719 {
q.huang70b76492022-06-02 14:49:02 +0800720 LYERRLOG("urc loop failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800721 return -1;
722 }
q.huang70b76492022-06-02 14:49:02 +0800723 LYDBGLOG("urc loop success!!!");
lh7b0674a2022-01-10 00:34:35 -0800724 return 0;
725}
q.huang52921662022-10-20 15:25:45 +0800726#endif
lh7b0674a2022-01-10 00:34:35 -0800727
728void lynq_call_state_change_test(int soc_id)
729{
q.huang70b76492022-06-02 14:49:02 +0800730 LYDBGLOG("call state change,sim:%d",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800731}
q.huangcb7b7292022-06-28 20:12:01 +0800732
q.huang52921662022-10-20 15:25:45 +0800733int lynq_start_call_list_loop()
734{
735#if 0
736 int ret = 0;
737 pthread_attr_t attr;
738 pthread_attr_init(&attr);
739 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
q.huangcb7b7292022-06-28 20:12:01 +0800740
q.huang52921662022-10-20 15:25:45 +0800741 s_notice_get_call_list_mutex = new pthread_mutex_t;
742 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
743 s_notice_get_call_list_cond = new pthread_cond_t;
744 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
745 pthread_cond_init(s_notice_get_call_list_cond, NULL);
746 LYINFLOG("liulei s_notice_get_call_list_cond\n");
747#endif
q.huangcb7b7292022-06-28 20:12:01 +0800748
q.huang52921662022-10-20 15:25:45 +0800749 s_call_list_loop = 1;
750 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
751 if(ret < 0)
q.huangcb7b7292022-06-28 20:12:01 +0800752 {
q.huang52921662022-10-20 15:25:45 +0800753 LYERRLOG("lynq_update_call_list_loop fail!!!");
lla8c25a82022-03-17 05:31:33 +0000754 return -1;
755 }
q.huang52921662022-10-20 15:25:45 +0800756 LYINFLOG("lynq_update_call_list_loop success!!!");
q.huangcb7b7292022-06-28 20:12:01 +0800757
q.huang52921662022-10-20 15:25:45 +0800758 memset(s_call_lists,0,sizeof(s_call_lists));
lh7b0674a2022-01-10 00:34:35 -0800759 return 0;
760}
q.huang52921662022-10-20 15:25:45 +0800761
762int lynq_stop_call_list_loop()
lh7b0674a2022-01-10 00:34:35 -0800763{
q.huang70b76492022-06-02 14:49:02 +0800764 int ret;
q.huang52921662022-10-20 15:25:45 +0800765 pthread_mutex_lock(&s_notice_get_call_list_mutex);
766 s_call_list_loop = 0;
767 ret = pthread_cancel(s_call_list_loop_tid);
768 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
769 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
770 ret = pthread_join(s_call_list_loop_tid,NULL);
771 LYINFLOG("pthread join w_c_list ret = %d",ret);
772 s_call_list_loop_tid=-1;
773#if 0
774 pthread_mutex_destroy(s_notice_get_call_list_mutex);
775 pthread_cond_destroy(s_notice_get_call_list_cond);
776 delete s_notice_get_call_list_mutex;
777 //s_notice_get_call_list_mutex = NULL;
778 delete s_notice_get_call_list_cond;
779 //s_notice_get_call_list_cond = NULL;
780#endif
781
782 return 0;
rita98e2e9c2022-04-07 06:08:13 -0400783}
q.huang714145d2022-04-18 00:09:50 -0400784
q.huang52921662022-10-20 15:25:45 +0800785int lynq_init_call(int utoken){
q.huangf6a9ddc2023-12-08 20:23:56 +0800786
787 LYLOGSET(LOG_INFO);
788 LYLOGEINIT(USER_LOG_TAG);
789 LYERRLOG("%s start, parameter is %d", __func__,utoken);
790
q.huang52921662022-10-20 15:25:45 +0800791 if(g_module_init_flag != MODULE_CLOSED)
792 {
793 LYERRLOG("module state is %d",g_module_init_flag);
794 return LYNQ_E_CONFLICT;
795 }
796 if(utoken <0){
797 LYERRLOG("utoken is less than 0",utoken);
798 return LYNQ_E_PARAMETER_ANONALY;
799 }
800 g_module_init_flag = MODULE_SWITCHING;
q.huangf6a9ddc2023-12-08 20:23:56 +0800801
q.huang52921662022-10-20 15:25:45 +0800802
803 g_module_Global_uToken = utoken;
804
q.huang036b6cf2023-01-10 14:29:20 +0800805 int ret = lynq_start_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800806 if(ret != RESULT_OK)
807 {
808 LYERRLOG("init socket urc fail!!!");
809 g_module_init_flag = MODULE_CLOSED;
810 return LYNQ_E_INNER_ERROR;
811 }
812
q.huang036b6cf2023-01-10 14:29:20 +0800813 ret = lynq_start_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800814 if(ret !=RESULT_OK)
815 {
816 LYERRLOG("init socket client fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800817 lynq_close_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800818 g_module_init_flag = MODULE_CLOSED;
819 return LYNQ_E_INNER_ERROR;
820 }
821
822
823 int result = lynq_start_call_list_loop();
824 if(ret != RESULT_OK)
825 {
826 LYERRLOG("lynq_start_call_list_loop fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800827 lynq_close_all_urc_socket_thread();
828 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800829 g_module_init_flag = MODULE_CLOSED;
830 return LYNQ_E_INNER_ERROR;
831 }
832
q.huang52921662022-10-20 15:25:45 +0800833 g_module_init_flag = MODULE_RUNNING;
q.huangf6a9ddc2023-12-08 20:23:56 +0800834
835 LYERRLOG("%s end suc", __func__);
q.huang52921662022-10-20 15:25:45 +0800836 return 0;
837}
838
839int lynq_deinit_call(void){
q.huangf6a9ddc2023-12-08 20:23:56 +0800840 LYERRLOG("%s start", __func__);
q.huang52921662022-10-20 15:25:45 +0800841
842 if (g_module_init_flag != MODULE_RUNNING)
843 {
844 LYERRLOG("module state is %d",g_module_init_flag);
845 return LYNQ_E_CONFLICT;
846 }
847 lynq_call_hungup_all();
q.huang52921662022-10-20 15:25:45 +0800848 g_module_init_flag = MODULE_SWITCHING;
q.huang036b6cf2023-01-10 14:29:20 +0800849 lynq_close_all_urc_socket_thread();
850 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800851 lynq_stop_call_list_loop();
852 g_module_init_flag = MODULE_CLOSED;
q.huangf6a9ddc2023-12-08 20:23:56 +0800853
854 LYERRLOG("%s end suc", __func__);
q.huang52921662022-10-20 15:25:45 +0800855 return 0;
856}
857
858#if 0
q.huang714145d2022-04-18 00:09:50 -0400859int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400860{
861 Parcel p;
862 lynq_client_t client;
863 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800864 int token;
rita089527e2022-04-07 01:55:39 -0400865 int request = -1;
866 int slot_id = -1;
867 int error = -1;
rita089527e2022-04-07 01:55:39 -0400868
q.huang52921662022-10-20 15:25:45 +0800869 Parcel* p=NULL;
870 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
871 if(ret==RESULT_OK)
872 {
873 delete p;
874 }
875 return ret;
876
rita089527e2022-04-07 01:55:39 -0400877 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400878 client.request = request_id;
879 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400880 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400881 if(argc!=0)
882 {
883 va_list args;
884 va_start(args, format);
885 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
886 va_end(args);
887 }
q.huang70b76492022-06-02 14:49:02 +0800888 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400889 if(send_request(lynq_call_client_sockfd,&client)==-1)
890 {
891 LYERRLOG("send request fail");
892 return -1;
893 }
q.huang714145d2022-04-18 00:09:50 -0400894 if(get_response(lynq_call_client_sockfd,p)==0)
895 {
q.huang7de1d662022-09-13 14:19:24 +0800896 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang714145d2022-04-18 00:09:50 -0400897 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
898 }
rita089527e2022-04-07 01:55:39 -0400899 return error;
q.huang52921662022-10-20 15:25:45 +0800900
901
rita089527e2022-04-07 01:55:39 -0400902}
q.huang52921662022-10-20 15:25:45 +0800903#endif
rita089527e2022-04-07 01:55:39 -0400904
q.huang714145d2022-04-18 00:09:50 -0400905int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400906{
q.huang714145d2022-04-18 00:09:50 -0400907 if(status==NULL)
908 {
909 LYERRLOG("status is null");
q.huang52921662022-10-20 15:25:45 +0800910 return LYNQ_E_PARAMETER_ANONALY;
q.huang714145d2022-04-18 00:09:50 -0400911 }
q.huang52921662022-10-20 15:25:45 +0800912
913 Parcel* p=NULL;
914 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
915 if(ret==RESULT_OK)
rita089527e2022-04-07 01:55:39 -0400916 {
q.huang52921662022-10-20 15:25:45 +0800917 p->readInt32(status);
918 delete p;
rita089527e2022-04-07 01:55:39 -0400919 }
q.huang52921662022-10-20 15:25:45 +0800920 return ret;
921}
922
923int waitCallstateChange(int mtime)
924{
925 LYINFLOG("wait Call state Change");
926 int ret = 0;
927 int sec = 0;
you.chen79d8f932023-12-26 17:03:44 +0800928 int ms = 0;
q.huang52921662022-10-20 15:25:45 +0800929 struct timeval now;
930 struct timespec timeout;
931 gettimeofday(&now,NULL);
932 sec = mtime/1000;
you.chen79d8f932023-12-26 17:03:44 +0800933 ms = mtime%1000;
q.huang52921662022-10-20 15:25:45 +0800934 timeout.tv_sec = now.tv_sec+sec;
you.chen79d8f932023-12-26 17:03:44 +0800935 unsigned long long ns;
936 ns = now.tv_usec*1000ull + ms*1000000ull;
937 timeout.tv_sec += ns/1000000000;
938 timeout.tv_nsec = ns % 1000000000;
q.huang52921662022-10-20 15:25:45 +0800939 pthread_mutex_lock(&call_state_change_mutex);
940 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
941 pthread_mutex_unlock(&call_state_change_mutex);
942 return ret;
943}
944
945int IsNormalCallDailing()
946{
947 return s_module_isDial;
rita089527e2022-04-07 01:55:39 -0400948}
949
llb3921072023-01-10 14:47:46 +0800950
lh3b6f7ea2023-11-08 01:16:42 -0800951int check_file_access(const char *fileName)
952{
953 if(0 == access(fileName,F_OK))
954 {
955 LYINFLOG("find file %s success",fileName);
956 return 0;
957 }
958 LYERRLOG("find file %s fail",fileName);
959 return 1;
960}
961int try_reset_audio_service()
962{
963 //check files:audio-ctrl-service,libmodem-afe-service,speech_daemon
964 int ap_speech = 0;
965 int audio_ctrl_ser = 0;
966 int md_afe = 0;
967 int tele_demo_lock = 0;
968 LYINFLOG("try_reset_audio_service start");
969 ap_speech = check_file_access(AP_SPEECH);
970 audio_ctrl_ser = check_file_access(AUDIO_CTRL_SER);
971 md_afe = check_file_access(LIBMODEM_AFE);
972 tele_demo_lock = check_file_access(TELE_DEMO_LOCK);
973 if((ap_speech + audio_ctrl_ser + md_afe) > 0)
974 {
975 system("systemctl stop audio-ctrl-service");
976 system("systemctl stop speech_daemon");
977 system("systemctl stop libmodem_afe_service");
978 usleep(200000);//200ms
979 system("rm /tmp/audio_ctrl_service -rf");
980 system("rm /tmp/ap_speech -rf");
981 system("rm /tmp/libmodem-afe-ctrl -rf");
982 usleep(100000);//100ms
983 system("systemctl start libmodem_afe_service");
984 usleep(200000);//200ms
985 system("systemctl start speech_daemon");
986 usleep(200000);//200ms
987 system("systemctl start audio-ctrl-service");
988 sleep(1);//1s
989 LYERRLOG("reset audio relation service");
990 }
991 if(tele_demo_lock)
992 {
993 LYERRLOG("%s lose,why?",TELE_DEMO_LOCK);
994 }
995 return 0;
996}
997
l.yangd25d3712024-03-04 17:55:39 -0800998int call_boot_check()
999{
1000 FILE *file = NULL;
1001 int uptime = 0;
1002
1003 file = fopen("/proc/uptime", "r");
1004 if(file == NULL)
1005 {
1006 LYERRLOG("Error opening /proc/uptime");
1007 return -1;
1008 }
1009
1010 if(fscanf(file, "%d ", &uptime) != 1)
1011 {
1012 LYERRLOG("Error reading uptime value");
1013 }
1014
1015 fclose(file);
1016
1017 if(uptime > SYSTEM_UPTIME)
1018 {
1019 LYINFLOG("System uptime is greater than 40 seconds.");
1020 }
1021 else
1022 {
1023 LYINFLOG("System uptime is less than 40 seconds.");
1024 FILE *fp = NULL;
1025 if(check_file_access(CALL_REBOOT_FLAG) != 0)
1026 {
1027 usleep(3000000);
1028 fp = fopen(CALL_REBOOT_FLAG,"w");
1029 if(fp == NULL)
1030 {
1031 LYERRLOG("Creat call reboot flag file failed !!!!");
1032 return -1;
1033 }
1034 LYINFLOG("Creat flag file success");
1035 fclose(fp);
1036 }
1037 }
1038 return 0;
1039
1040}
lh7b0674a2022-01-10 00:34:35 -08001041int lynq_call(int* handle,char addr[])
1042{
q.huang52921662022-10-20 15:25:45 +08001043 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001044 {
q.huang52921662022-10-20 15:25:45 +08001045 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1046 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001047 }
l.yang1d80f782024-05-13 19:35:54 -07001048
1049#ifdef MODE_DSDS
1050 urc_slot = -1;
1051#endif
lh3b6f7ea2023-11-08 01:16:42 -08001052 try_reset_audio_service();
l.yangd25d3712024-03-04 17:55:39 -08001053
1054#ifdef GSW_RIL_CFG
1055 call_boot_check();
1056#endif
1057
lh7b0674a2022-01-10 00:34:35 -08001058 int lynq_call_id = -1;
q.huang70b76492022-06-02 14:49:02 +08001059
1060 LYINFLOG("lynq_call begin addr %s",addr);
lh7b0674a2022-01-10 00:34:35 -08001061 if(addr==NULL)
1062 {
1063 LYERRLOG("Phone num is null!!!");
q.huang52921662022-10-20 15:25:45 +08001064 return LYNQ_E_PARAMETER_ANONALY;
lh7b0674a2022-01-10 00:34:35 -08001065 }
q.huang70b76492022-06-02 14:49:02 +08001066
1067 if(find_call_id_with_addr(addr)!=INVALID_ID)
1068 {
1069 LYERRLOG("addr %s exists",addr);
1070 return LYNQ_E_CONFLICT;
1071 }
1072
1073#ifdef ECALL_SUPPORT
1074 if(lynq_ecall_is_running())
1075 {
1076 LYERRLOG("lynq_fast_ecall ecall is running");
1077 return LYNQ_E_ECALL_BEING_RUNNING;
1078 }
1079#endif
q.huang52921662022-10-20 15:25:45 +08001080 Parcel* p=NULL;
1081 lynq_call_id = addAddr(addr,0);
1082 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
1083 if(ret!=0)
1084 {
llb3921072023-01-10 14:47:46 +08001085 cleanCallList(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001086 return ret;
llb3921072023-01-10 14:47:46 +08001087 }
1088 delete p;
q.huang52921662022-10-20 15:25:45 +08001089 s_module_isDial = 1;
1090 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -08001091 {
q.huang52921662022-10-20 15:25:45 +08001092 //if timeout,this call need destroy.
1093 s_module_isDial = 0;
1094 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
llb3921072023-01-10 14:47:46 +08001095 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001096 send_call_state_change(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001097 return LYNQ_E_TIME_OUT;
lh7b0674a2022-01-10 00:34:35 -08001098 }
q.huang52921662022-10-20 15:25:45 +08001099 s_module_isDial = 0;
1100 *handle = s_call_lists[lynq_call_id].call_id;
1101 if(*handle > 0)
lh7b0674a2022-01-10 00:34:35 -08001102 {
q.huang52921662022-10-20 15:25:45 +08001103 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
1104 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001105 }
q.huang52921662022-10-20 15:25:45 +08001106 else
1107 {
1108 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
lle3b9a232023-01-14 13:21:20 +08001109 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001110 send_call_state_change(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001111 return LYNQ_E_INVALID_ID_ANONALY;
llb3921072023-01-10 14:47:46 +08001112 }
lh7b0674a2022-01-10 00:34:35 -08001113}
llb3921072023-01-10 14:47:46 +08001114
lh7b0674a2022-01-10 00:34:35 -08001115int lynq_call_answer()
1116{
q.huang52921662022-10-20 15:25:45 +08001117 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001118 {
q.huang52921662022-10-20 15:25:45 +08001119 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1120 return LYNQ_E_CONFLICT;
1121 }
1122
1123 Parcel* p=NULL;
1124 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
1125 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001126 {
q.huang52921662022-10-20 15:25:45 +08001127 delete p;
1128 }
1129 return ret;
lh7b0674a2022-01-10 00:34:35 -08001130}
llb3921072023-01-10 14:47:46 +08001131
lh7b0674a2022-01-10 00:34:35 -08001132int lynq_call_hungup(int* handle)
1133{
q.huang52921662022-10-20 15:25:45 +08001134 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001135 {
q.huang52921662022-10-20 15:25:45 +08001136 return LYNQ_E_CONFLICT;
1137 }
1138
lh42c1e572022-01-25 18:47:39 -08001139 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1140 {
q.huang52921662022-10-20 15:25:45 +08001141 LYERRLOG("%s illegal input!!!!",__func__);
1142 return LYNQ_E_PARAMETER_ANONALY;
lh42c1e572022-01-25 18:47:39 -08001143 }
q.huang52921662022-10-20 15:25:45 +08001144
1145 int call_id = *handle;
1146 Parcel* p=NULL;
1147 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1148 if(ret!=0)
lh7b0674a2022-01-10 00:34:35 -08001149 {
q.huang52921662022-10-20 15:25:45 +08001150 return ret;
you.chen79d8f932023-12-26 17:03:44 +08001151 }
q.huang52921662022-10-20 15:25:45 +08001152 delete p;
1153
you.chen79d8f932023-12-26 17:03:44 +08001154 int lynq_call_id=find_call_id_with_call_id(call_id);
q.huang52921662022-10-20 15:25:45 +08001155 if(lynq_call_id!=INVALID_ID)
lh7b0674a2022-01-10 00:34:35 -08001156 {
you.chen79d8f932023-12-26 17:03:44 +08001157 //lei modify for API-857
q.huang52921662022-10-20 15:25:45 +08001158 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001159 send_call_state_change(call_id);
1160 }
1161 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001162}
1163int lynq_call_hungup_all()
1164{
q.huang52921662022-10-20 15:25:45 +08001165 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001166 {
q.huang52921662022-10-20 15:25:45 +08001167 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1168 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001169 }
q.huang52921662022-10-20 15:25:45 +08001170
1171 Parcel* p=NULL;
1172 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1173 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001174 {
q.huang52921662022-10-20 15:25:45 +08001175 delete p;
1176 }
1177 return ret;
lh7b0674a2022-01-10 00:34:35 -08001178}
llb3921072023-01-10 14:47:46 +08001179
1180int lynq_wait_call_state_change(int *handle)
lh7b0674a2022-01-10 00:34:35 -08001181{
q.huang52921662022-10-20 15:25:45 +08001182 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001183 {
q.huang52921662022-10-20 15:25:45 +08001184 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1185 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001186 }
llb3921072023-01-10 14:47:46 +08001187 wait_call_state();
1188 *handle = s_CallId;
1189 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1190 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001191}
1192
1193int lynq_set_auto_answercall(const int mode)
1194{
q.huang52921662022-10-20 15:25:45 +08001195 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001196 {
q.huang52921662022-10-20 15:25:45 +08001197 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1198 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001199 }
q.huang52921662022-10-20 15:25:45 +08001200 s_call_auto_answer = mode;
lh7b0674a2022-01-10 00:34:35 -08001201 LYINFLOG("auto answer call mode =%d",mode);
q.huang52921662022-10-20 15:25:45 +08001202 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001203}
llb3921072023-01-10 14:47:46 +08001204
1205int lynq_find_already_end()
1206{
1207 for(int i=0;i < LYNQ_CALL_MAX; i++)
1208 {
1209 if(s_call_lists[i].call_state == 6)
1210 {
1211 return 0;
1212 }
1213 }
1214 return INVALID_ID;
1215}
1216
l.yang4419f452024-04-24 23:52:25 -07001217#ifdef MODE_DSDS
1218int lynq_get_current_call_state_ext(int *handle, int *slot,int *call_state,int *toa,int *direction,char addr[])
1219{
1220 if(g_module_init_flag != MODULE_RUNNING)
1221 {
1222 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1223 return LYNQ_E_CONFLICT;
1224 }
1225 int lynq_call_id = 0;
1226 LYINFLOG("lynq_get_current_call_state begin ");
1227 if(handle==NULL)
1228 {
1229 LYERRLOG("handle is NULL");
1230 return LYNQ_E_PARAMETER_ANONALY;
1231 }
1232 if((*handle) <= 0)
1233 {
1234 LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);
1235 return LYNQ_E_INVALID_ID_ANONALY;
1236 }
1237 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
1238 lynq_call_id = find_call_id_with_call_id(*handle);
1239 if(lynq_call_id==INVALID_ID)
1240 {
1241 //find end state
1242 if((*handle) >= 0)
1243 {
1244 *call_state = (int)LYNQ_CALL_END;
l.yang01331722024-05-06 19:45:16 -07001245 *slot = global_slot;
l.yang4419f452024-04-24 23:52:25 -07001246 return RESULT_OK;
1247 }
1248 else
1249 {
1250 return LYNQ_E_INVALID_ID_ANONALY;
1251 }
1252 }
1253 *slot = global_slot;
1254 *call_state = s_call_lists[lynq_call_id].call_state;
1255 *toa = s_call_lists[lynq_call_id].toa;
1256 *direction = s_call_lists[lynq_call_id].direction;
1257 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
1258 return RESULT_OK;
1259}
1260#endif
1261
q.huangec88da92022-03-29 04:17:32 -04001262int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1263{
q.huang52921662022-10-20 15:25:45 +08001264 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001265 {
q.huang52921662022-10-20 15:25:45 +08001266 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1267 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001268 }
q.huangec88da92022-03-29 04:17:32 -04001269 int lynq_call_id = 0;
q.huang70b76492022-06-02 14:49:02 +08001270 LYINFLOG("lynq_get_current_call_state begin ");
q.huangec88da92022-03-29 04:17:32 -04001271 if(handle==NULL)
1272 {
q.huang70b76492022-06-02 14:49:02 +08001273 LYERRLOG("handle is NULL");
q.huang52921662022-10-20 15:25:45 +08001274 return LYNQ_E_PARAMETER_ANONALY;
q.huangec88da92022-03-29 04:17:32 -04001275 }
you.chen79d8f932023-12-26 17:03:44 +08001276 if((*handle) <= 0)
1277 {
1278 LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);
1279 return LYNQ_E_INVALID_ID_ANONALY;
1280 }
llb3921072023-01-10 14:47:46 +08001281 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huang70b76492022-06-02 14:49:02 +08001282 lynq_call_id = find_call_id_with_call_id(*handle);
1283 if(lynq_call_id==INVALID_ID)
1284 {
llb3921072023-01-10 14:47:46 +08001285 //find end state
1286 if((*handle) >= 0)
1287 {
1288 *call_state = (int)LYNQ_CALL_END;
1289 return RESULT_OK;
1290 }
1291 else
1292 {
1293 return LYNQ_E_INVALID_ID_ANONALY;
1294 }
q.huang70b76492022-06-02 14:49:02 +08001295 }
q.huang52921662022-10-20 15:25:45 +08001296 *call_state = s_call_lists[lynq_call_id].call_state;
1297 *toa = s_call_lists[lynq_call_id].toa;
1298 *direction = s_call_lists[lynq_call_id].direction;
1299 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
llb3921072023-01-10 14:47:46 +08001300 return RESULT_OK;
q.huangec88da92022-03-29 04:17:32 -04001301}
1302
q.huange97cfcf2022-08-29 20:04:31 +08001303int lynq_get_current_call_number()
1304{
1305 int cnt=0;
1306 int i;
1307 for(i = 0;i < LYNQ_CALL_MAX;i++)
1308 {
q.huang52921662022-10-20 15:25:45 +08001309 if(s_call_lists[i].used !=0)
q.huange97cfcf2022-08-29 20:04:31 +08001310 {
1311 cnt++;
1312 }
1313 }
1314
1315 return cnt;
1316}
1317
q.huangec88da92022-03-29 04:17:32 -04001318/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001319static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001320 switch(enable){
1321 case 0:
q.huang52921662022-10-20 15:25:45 +08001322 return true;
llf512fa32022-02-14 08:58:16 +00001323 case 1:
q.huang52921662022-10-20 15:25:45 +08001324 return true;
llf512fa32022-02-14 08:58:16 +00001325 default:
q.huang52921662022-10-20 15:25:45 +08001326 return false;
lldc99c9b2022-01-24 12:16:22 +00001327 }
1328}
1329
lh7b0674a2022-01-10 00:34:35 -08001330int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001331{
q.huang52921662022-10-20 15:25:45 +08001332 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001333 {
q.huang52921662022-10-20 15:25:45 +08001334 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001335 return LYNQ_E_CONFLICT;
1336 }
q.huang52921662022-10-20 15:25:45 +08001337 if(!judge_mic(enable)){
1338 return LYNQ_E_PARAMETER_ANONALY;
1339 }
1340 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1341
1342 Parcel* p=NULL;
1343 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1344 if(ret==RESULT_OK)
1345 {
1346 delete p;
1347 }
1348 return ret;
q.huangec88da92022-03-29 04:17:32 -04001349}
1350int lynq_get_mute_mic(int *status)
1351{
q.huang52921662022-10-20 15:25:45 +08001352 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001353 {
q.huang52921662022-10-20 15:25:45 +08001354 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1355 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001356 }
q.huang52921662022-10-20 15:25:45 +08001357 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh7b0674a2022-01-10 00:34:35 -08001358}
ll72bf6c12022-03-24 10:22:25 +08001359
1360/**
1361 * @brief Check whether DTMF is valid
1362 *
1363 * @param callnum dtmf eg:0-9 * #
1364 * @return int
1365 */
1366static int judge_dtmf(const char callnum)
1367{
1368 if(callnum == '#')
1369 {
q.huang52921662022-10-20 15:25:45 +08001370 return true;
ll72bf6c12022-03-24 10:22:25 +08001371 }
1372 if(callnum == '*')
1373 {
q.huang52921662022-10-20 15:25:45 +08001374 return true;
ll72bf6c12022-03-24 10:22:25 +08001375 }
1376 if(callnum >= '0'&& callnum <= '9')
1377 {
q.huang52921662022-10-20 15:25:45 +08001378 return true;
ll72bf6c12022-03-24 10:22:25 +08001379 }
q.huang52921662022-10-20 15:25:45 +08001380 return false;
ll72bf6c12022-03-24 10:22:25 +08001381}
1382
ll209e6112022-07-20 09:30:19 +00001383int lynq_switch_waiting_or_holding_and_active(void)
1384{
q.huang52921662022-10-20 15:25:45 +08001385 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001386 {
q.huang52921662022-10-20 15:25:45 +08001387 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1388 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001389 }
q.huang52921662022-10-20 15:25:45 +08001390
1391 Parcel* p=NULL;
1392 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1393 if(ret==RESULT_OK)
1394 {
1395 delete p;
1396 }
1397 return ret;
1398
1399#if 0
ll209e6112022-07-20 09:30:19 +00001400 Parcel p;
1401 lynq_client_t client;
1402 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001403 int token;
ll209e6112022-07-20 09:30:19 +00001404 int request = -1;
1405 int slot_id = -1;
1406 int error = -1;
1407 client.uToken = Global_uToken_call;
1408 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1409 client.paramLen = 0;
1410 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1411 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001412 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001413 if(send_request(lynq_call_client_sockfd,&client)==-1)
1414 {
1415 LYERRLOG("send request fail");
1416 return -1;
1417 }
1418 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001419 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001420 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001421 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1422 return error;
q.huang52921662022-10-20 15:25:45 +08001423#endif
ll209e6112022-07-20 09:30:19 +00001424}
1425
1426int lynq_hangup_waiting_or_background(void)
1427{
q.huang52921662022-10-20 15:25:45 +08001428 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001429 {
q.huang52921662022-10-20 15:25:45 +08001430 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1431 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001432 }
q.huang52921662022-10-20 15:25:45 +08001433
1434 Parcel* p=NULL;
1435 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1436 if(ret==RESULT_OK)
1437 {
1438 delete p;
1439 }
1440 return ret;
1441#if 0
ll209e6112022-07-20 09:30:19 +00001442 Parcel p;
1443 lynq_client_t client;
1444 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001445 int token;
ll209e6112022-07-20 09:30:19 +00001446 int request = -1;
1447 int slot_id = -1;
1448 int error = -1;
1449 client.uToken = Global_uToken_call;
1450 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1451 client.paramLen = 0;
1452 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1453 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001454 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001455 if(send_request(lynq_call_client_sockfd,&client)==-1)
1456 {
1457 LYERRLOG("send request fail");
1458 return -1;
1459 }
1460 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001461 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001462 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001463 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1464 return error;
q.huang52921662022-10-20 15:25:45 +08001465#endif
ll209e6112022-07-20 09:30:19 +00001466}
1467
1468int lynq_hangup_foreground_resume_background(void)
1469{
q.huang52921662022-10-20 15:25:45 +08001470 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001471 {
q.huang52921662022-10-20 15:25:45 +08001472 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1473 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001474 }
q.huang52921662022-10-20 15:25:45 +08001475
1476 Parcel* p=NULL;
1477 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1478 if(ret==RESULT_OK)
1479 {
1480 delete p;
1481 }
1482 return ret;
1483#if 0
ll209e6112022-07-20 09:30:19 +00001484 Parcel p;
1485 lynq_client_t client;
1486 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001487 int token;
ll209e6112022-07-20 09:30:19 +00001488 int request = -1;
1489 int slot_id = -1;
1490 int error = -1;
1491 client.uToken = Global_uToken_call;
1492 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1493 client.paramLen = 0;
1494 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1495 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001496 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001497 if(send_request(lynq_call_client_sockfd,&client)==-1)
1498 {
1499 LYERRLOG("send request fail");
1500 return -1;
1501 }
1502 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001503 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001504 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001505 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1506 return error;
q.huang52921662022-10-20 15:25:45 +08001507#endif
ll209e6112022-07-20 09:30:19 +00001508}
1509
lh7b0674a2022-01-10 00:34:35 -08001510int lynq_set_DTMF(const char callnum)
1511{
q.huang52921662022-10-20 15:25:45 +08001512 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001513 {
q.huang52921662022-10-20 15:25:45 +08001514 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1515 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001516 }
ll72bf6c12022-03-24 10:22:25 +08001517 if(!judge_dtmf(callnum))
1518 {
1519 return LYNQ_E_CONFLICT;
1520 }
q.huang52921662022-10-20 15:25:45 +08001521 if(s_module_call_state!=CALL_ON)
lh7b0674a2022-01-10 00:34:35 -08001522 {
1523 LYERRLOG("LYNQ_E_CONFLICT");
1524 return LYNQ_E_CONFLICT;
1525 }
q.huang52921662022-10-20 15:25:45 +08001526
1527// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1528
1529 Parcel* p=NULL;
1530 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1531 if(ret==RESULT_OK)
1532 {
1533 delete p;
1534 }
1535 return ret;
lh7b0674a2022-01-10 00:34:35 -08001536}
q.huangec88da92022-03-29 04:17:32 -04001537static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1538 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1539 if(volume < 0 ||volume >36){
1540 return 0;
1541 }
1542 }
1543 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1544 {
1545 if(volume < 1 ||volume >7){
1546 return 0;
1547 }
lldc99c9b2022-01-24 12:16:22 +00001548 }
ll04ae4142022-01-27 05:54:38 +00001549 return 1;
lldc99c9b2022-01-24 12:16:22 +00001550}
lh7b0674a2022-01-10 00:34:35 -08001551int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001552{
q.huang52921662022-10-20 15:25:45 +08001553 if(g_module_init_flag != MODULE_RUNNING)
1554 {
1555 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001556 return LYNQ_E_CONFLICT;
1557 }
q.huang52921662022-10-20 15:25:45 +08001558 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1559 return LYNQ_E_PARAMETER_ANONALY;
1560 }
1561// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1562 Parcel* p=NULL;
1563 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1564 if(ret==RESULT_OK)
1565 {
1566 delete p;
1567 }
1568 return ret;
lh7b0674a2022-01-10 00:34:35 -08001569}
q.huangb212fde2022-04-05 23:11:02 -04001570int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001571{
q.huang52921662022-10-20 15:25:45 +08001572 if(g_module_init_flag != MODULE_RUNNING)
lh7b0674a2022-01-10 00:34:35 -08001573 {
q.huang52921662022-10-20 15:25:45 +08001574 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangec88da92022-03-29 04:17:32 -04001575 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001576 }
q.huang52921662022-10-20 15:25:45 +08001577 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1578 {
1579 return LYNQ_E_PARAMETER_ANONALY;
1580 }
1581// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1582 Parcel* p=NULL;
1583 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1584 if(ret==RESULT_OK)
1585 {
1586 delete p;
1587 }
1588 return ret;
lh7b0674a2022-01-10 00:34:35 -08001589}
q.huangec88da92022-03-29 04:17:32 -04001590int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1591{
q.huang52921662022-10-20 15:25:45 +08001592 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangec88da92022-03-29 04:17:32 -04001593}
q.huangb212fde2022-04-05 23:11:02 -04001594int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001595{
q.huang52921662022-10-20 15:25:45 +08001596// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1597 Parcel* p=NULL;
1598 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1599 if(ret==RESULT_OK)
1600 {
1601 delete p;
1602 }
1603 return ret;
q.huangec88da92022-03-29 04:17:32 -04001604}
1605int lynq_incall_record_stop()
1606{
q.huang52921662022-10-20 15:25:45 +08001607 if(g_module_init_flag != MODULE_RUNNING)
1608 {
1609 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1610 return LYNQ_E_CONFLICT;
1611 }
q.huangb212fde2022-04-05 23:11:02 -04001612 const char* unused_file="just_ocuupy_paramter_postion";
q.huang52921662022-10-20 15:25:45 +08001613// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1614 Parcel* p=NULL;
1615 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1616 if(ret==RESULT_OK)
1617 {
1618 delete p;
1619 }
1620 return ret;
q.huangec88da92022-03-29 04:17:32 -04001621}
1622/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001623
q.huang036b6cf2023-01-10 14:29:20 +08001624
1625
1626bool is_support_urc(int urc_id)
1627{
1628 switch(urc_id)
1629 {
1630 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1631 case RIL_UNSOL_CALL_RING:
1632 case RIL_UNSOL_RINGBACK_TONE:
1633 case RIL_UNSOL_CALL_INFO_INDICATION:
1634#ifdef ECALL_SUPPORT
1635 case RIL_UNSOL_ECALL_INDICATIONS://9502
1636#endif
1637 return true;
1638 default:
1639 return false;
1640 }
1641}
1642
q.huang52921662022-10-20 15:25:45 +08001643void urc_msg_process(Parcel *p)
1644{
1645 int resp_type;
1646 int urcid;
1647 int slot_id;
q.huang036b6cf2023-01-10 14:29:20 +08001648
1649 int size=p->dataSize();
q.huang52921662022-10-20 15:25:45 +08001650 p->readInt32(&resp_type);
1651 p->readInt32(&urcid);
1652 p->readInt32(&slot_id);
l.yang1d80f782024-05-13 19:35:54 -07001653#ifdef MODE_DSDS
1654 urc_slot = slot_id;
1655#endif
q.huang036b6cf2023-01-10 14:29:20 +08001656 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 +08001657 switch (urcid)
1658 {
1659 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1660 {
1661 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1662 lynqNoticeGetModuleCallList();
1663 break;
1664 }
1665 case RIL_UNSOL_CALL_RING: //1018
1666 {
q.huang305fadc2024-01-02 18:40:40 +08001667 time(&s_rev_ring_time);
q.huang52921662022-10-20 15:25:45 +08001668 if(s_call_auto_answer==1)
1669 {
1670 lynq_call_answer();
1671 }
1672 break;
1673 }
1674 case RIL_UNSOL_RINGBACK_TONE: //1029
1675 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1676 {
1677 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1678 break;
1679 }
q.huang714145d2022-04-18 00:09:50 -04001680#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +08001681 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange97cfcf2022-08-29 20:04:31 +08001682 {
q.huang52921662022-10-20 15:25:45 +08001683 urc_ecall_msg_process(p);
q.huange97cfcf2022-08-29 20:04:31 +08001684 }
q.huange97cfcf2022-08-29 20:04:31 +08001685#endif
q.huang52921662022-10-20 15:25:45 +08001686 default:
1687 break;
q.huangcb7b7292022-06-28 20:12:01 +08001688 }
q.huang5ca6c072022-06-06 16:15:31 +08001689}
q.huang5ca6c072022-06-06 16:15:31 +08001690
lh7b0674a2022-01-10 00:34:35 -08001691#if 0
1692int main(int argc,char **argv)
1693{
1694 int n = 0;
1695 n = lynq_init_call(lynq_call_state_change_test,2222);
1696 if(n<0)
1697 {
q.huang70b76492022-06-02 14:49:02 +08001698 LYDBGLOG("lynq init call fail!!!");
lh7b0674a2022-01-10 00:34:35 -08001699 return -1;
1700 }
q.huang70b76492022-06-02 14:49:02 +08001701 LYDBGLOG("lynq call init success!!!");
lh7b0674a2022-01-10 00:34:35 -08001702 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1703 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1704 lynq_call(phoneNum);
1705 while(1)
1706 {
1707 sleep(1);
1708 }
1709 return 0;
1710}
1711#endif
1712/*Warren add for T800 platform 2021/11/19 end*/