blob: 0b7e3850a8e37671e181fa956ae5ec82c8d4c6be [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
lh7b0674a2022-01-10 00:34:35 -080093
q.huangec88da92022-03-29 04:17:32 -040094typedef enum{
95 LYNQ_E_VOLUMN_SET_DTMF,
96 LYNQ_E_VOLUMN_SET_SPEECH
q.huang52921662022-10-20 15:25:45 +080097}LYNQ_E_VOLUMN_SET;
lh7b0674a2022-01-10 00:34:35 -080098
q.huang52921662022-10-20 15:25:45 +080099#if 0
q.huang7de1d662022-09-13 14:19:24 +0800100int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
lh7b0674a2022-01-10 00:34:35 -0800101{
102 if(p.dataAvail() > 0)
103 {
104 p.readInt32(resp_type);
q.huang7de1d662022-09-13 14:19:24 +0800105 p.readInt32(token);
lh7b0674a2022-01-10 00:34:35 -0800106 p.readInt32(request);
107 p.readInt32(slot_id);
108 p.readInt32(error);
109 return 0;
110 }
111 else
112 {
113 return -1;
114 }
115}
116int send_request(int sockfd,lynq_client_t *client_tmp)
117{
118 int ret=0;
rjw5d2a50e2022-02-28 15:01:49 +0800119 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800120 if(ret==-1)
121 {
q.huang70b76492022-06-02 14:49:02 +0800122 LYERRLOG("sendto error");
lh7b0674a2022-01-10 00:34:35 -0800123 return -1;
124 }
125 return 0;
126}
127
128int get_response(int sockfd,Parcel &p)
129{
130 int len = 0;
131 char recvline[LYNQ_REC_BUF];
132 bzero(recvline,LYNQ_REC_BUF);
133 /* receive data from server */
rjw5d2a50e2022-02-28 15:01:49 +0800134 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800135 if(len == -1)
136 {
q.huang70b76492022-06-02 14:49:02 +0800137 LYERRLOG("recvfrom error");
lh7b0674a2022-01-10 00:34:35 -0800138 return -1;
139 }
lh7b0674a2022-01-10 00:34:35 -0800140 if (recvline != NULL) {
141 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
142 p.setDataPosition(0);
143 }
144 return 0;
145}
q.huang52921662022-10-20 15:25:45 +0800146#endif
147static char *strdupReadString(Parcel* &p) {
ll04ae4142022-01-27 05:54:38 +0000148 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800149 const char16_t *s16;
q.huang52921662022-10-20 15:25:45 +0800150 s16 = p->readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000151 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800152}
153
154int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
155{
q.huang52921662022-10-20 15:25:45 +0800156 Parcel* p=NULL;
157 int ret=lynq_send_common_request(p,8,RIL_REQUEST_GET_CURRENT_CALLS,0,"");
158 if(ret!=0)
159 {
160 return ret;
161 }
162
163 int call_num = 0;
164 int temp = 0;
165 char *remote_phoneNum;
166 char *remote_name;
167 char uusData[128];
168
169 p->readInt32(&call_num);
170
171 if(call_num<=0)
172 {
173 s_module_call_state = CALL_OFF;
174 LYINFLOG("lynq_call_state:%d",s_module_call_state);
175 delete p;
176 return RESULT_OK;
177 }
178 s_module_call_state = CALL_ON;
179 LYINFLOG("lynq_call_state:%d, call num is %d ",s_module_call_state,call_num);
180 for(int i = 0;i < call_num;i++)
181 {
182 p->readInt32(&temp);
183 call_list[i].call_state = temp;
184 p->readInt32(&call_list[i].call_id);
185 p->readInt32(&call_list[i].toa);
186 p->readInt32(&temp);
187 p->readInt32(&temp);
188 call_list[i].direction = temp;
189 p->readInt32(&temp);
190 p->readInt32(&temp);
191 p->readInt32(&temp);
192 remote_phoneNum = strdupReadString(p);
193 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
194 if(remote_phoneNum !=NULL)
195 {
196 free(remote_phoneNum);
197 }
198 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
199 call_list[i].direction,call_list[i].addr,call_list[i].toa);
200 p->readInt32(&temp);
201 remote_name = strdupReadString(p);
202 if(remote_name !=NULL)
203 {
204 free(remote_name);
205 }
206 p->readInt32(&temp);
207 p->readInt32(&temp);
208 if(temp==0)
209 {
210 continue;
211 }
212 p->readInt32(&temp); /* UUS Information is present */
213 p->readInt32(&temp);
214 p->readInt32(&temp);
215 if(temp<=128)
216 {
217 p->read(uusData,temp);
218 }
219 else
220 {
221 LYERRLOG("%s len %d is too great",__func__,temp);
222 delete p;
223 return LYNQ_E_MALLOC_ERROR;
224 }
225 }
226
227 delete p;
228 return RESULT_OK;
229
230#if 0
lh7b0674a2022-01-10 00:34:35 -0800231 Parcel p;
232 lynq_client_t client;
233 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800234 int token;
lh7b0674a2022-01-10 00:34:35 -0800235 int request = -1;
236 int slot_id = -1;
237 int error = -1;
238 int call_num = 0;
239 int temp = 0;
240 char *remote_phoneNum = NULL;
241 char *remote_name= NULL;
242 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800243 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800244 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
245 client.paramLen = 0;
246 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang70b76492022-06-02 14:49:02 +0800247 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800248 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800249 {
250 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800251 return -1;
252 }
lh42c1e572022-01-25 18:47:39 -0800253 get_response(lynq_call_client_sockfd,p);
q.huang7de1d662022-09-13 14:19:24 +0800254 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh7b0674a2022-01-10 00:34:35 -0800255 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
256 if(error == 0)
257 {
258 p.readInt32(&call_num);
259 global_call_count = call_num;
260 if(call_num<=0)
261 {
262 lynq_call_state = CALL_OFF;
lhec17b0a2022-02-13 23:56:05 -0800263 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800264 return 0;
265 }
lhec17b0a2022-02-13 23:56:05 -0800266 lynq_call_state = CALL_ON;
q.huang70b76492022-06-02 14:49:02 +0800267 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh7b0674a2022-01-10 00:34:35 -0800268 for(int i = 0;i < call_num;i++)
269 {
270 p.readInt32(&temp);
271 call_list[i].call_state = temp;
272 p.readInt32(&call_list[i].call_id);
273 p.readInt32(&call_list[i].toa);
274 p.readInt32(&temp);
275 p.readInt32(&temp);
276 call_list[i].direction = temp;
277 p.readInt32(&temp);
278 p.readInt32(&temp);
279 p.readInt32(&temp);
280 remote_phoneNum = strdupReadString(p);
281 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
282 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
283 call_list[i].direction,call_list[i].addr,call_list[i].toa);
284 p.readInt32(&temp);
285 remote_name = strdupReadString(p);
286 p.readInt32(&temp);
287 p.readInt32(&temp);
288 if(temp==0)
289 {
290 continue;
291 }
292 p.readInt32(&temp); /* UUS Information is present */
293 p.readInt32(&temp);
294 p.readInt32(&temp);
295 p.read(uusData,temp);
296 }
297 }
298 return 0;
q.huang52921662022-10-20 15:25:45 +0800299#endif
lh7b0674a2022-01-10 00:34:35 -0800300}
301
302void cleanCallList(int lynq_call_id)
303{
q.huang52921662022-10-20 15:25:45 +0800304 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
305 s_call_lists[lynq_call_id].call_id = 0;
306 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
307 s_call_lists[lynq_call_id].toa = 0;
308 s_call_lists[lynq_call_id].direction = 0;
309 s_call_lists[lynq_call_id].used = 0;
310 memset(s_call_lists[lynq_call_id].addr,0,sizeof(s_call_lists[lynq_call_id].addr));
lh7b0674a2022-01-10 00:34:35 -0800311}
llb3921072023-01-10 14:47:46 +0800312
313
lh7b0674a2022-01-10 00:34:35 -0800314int getUnusedElement()
315{
316 for(int i=0;i < LYNQ_CALL_MAX; i++)
317 {
q.huang52921662022-10-20 15:25:45 +0800318 if(s_call_lists[i].used!=1)
lh7b0674a2022-01-10 00:34:35 -0800319 {
320 return i;
321 }
322 }
q.huang52921662022-10-20 15:25:45 +0800323 return INVALID_ID;
lh7b0674a2022-01-10 00:34:35 -0800324}
q.huang52921662022-10-20 15:25:45 +0800325int addAddr(char addr[], int call_id)
lh7b0674a2022-01-10 00:34:35 -0800326{
327 int ret = 0;
328 ret = getUnusedElement();
q.huang52921662022-10-20 15:25:45 +0800329 memcpy(s_call_lists[ret].addr,addr,strlen(addr)+1);
330 s_call_lists[ret].call_id=call_id;
331 s_call_lists[ret].used = 1;
q.huang70b76492022-06-02 14:49:02 +0800332 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh7b0674a2022-01-10 00:34:35 -0800333 return ret;
334}
335void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
336{
q.huang70b76492022-06-02 14:49:02 +0800337 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh7b0674a2022-01-10 00:34:35 -0800338 callList->call_id = call_id;
339 callList->call_state = call_state;
340 callList->toa = toa;
q.huang70b76492022-06-02 14:49:02 +0800341 callList->direction = direction;
lh7b0674a2022-01-10 00:34:35 -0800342 return;
343}
llb3921072023-01-10 14:47:46 +0800344
345void wait_call_state()
lh7b0674a2022-01-10 00:34:35 -0800346{
llb3921072023-01-10 14:47:46 +0800347 LYINFLOG("call state changed");
348 pthread_mutex_lock(&s_call_state_change_mutex);
349 pthread_cond_wait(&s_call_state_change_cond,&s_call_state_change_mutex);
350 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800351}
llb3921072023-01-10 14:47:46 +0800352
lh7b0674a2022-01-10 00:34:35 -0800353int checkHasCall(char addr[])
354{
355 for(int i = 0;i<LYNQ_CALL_MAX;i++)
356 {
q.huang52921662022-10-20 15:25:45 +0800357 if(strcmp(s_call_lists[i].addr,addr)==0)
lh7b0674a2022-01-10 00:34:35 -0800358 {
q.huang52921662022-10-20 15:25:45 +0800359 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,s_call_lists[i].call_id);
360 return true;
lh7b0674a2022-01-10 00:34:35 -0800361 }
362 }
q.huang70b76492022-06-02 14:49:02 +0800363 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
q.huang52921662022-10-20 15:25:45 +0800364 return false;
lh7b0674a2022-01-10 00:34:35 -0800365}
lhd1e457c2022-04-19 06:01:25 -0700366int find_call_id_with_addr(char *addr)
367{
lhd1e457c2022-04-19 06:01:25 -0700368 for(int id = 0; id < LYNQ_CALL_MAX; id++)
369 {
q.huang52921662022-10-20 15:25:45 +0800370 if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
lhd1e457c2022-04-19 06:01:25 -0700371 {
q.huang52921662022-10-20 15:25:45 +0800372 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 -0700373 return id;
374 }
375 }
q.huang70b76492022-06-02 14:49:02 +0800376 LYINFLOG("find addr %s in local list , not found",addr);
q.huang52921662022-10-20 15:25:45 +0800377 return INVALID_ID;
lhd1e457c2022-04-19 06:01:25 -0700378}
q.huang70b76492022-06-02 14:49:02 +0800379int find_call_id_with_call_id(int call_id)
380{
381 for(int id = 0; id < LYNQ_CALL_MAX; id++)
382 {
q.huang52921662022-10-20 15:25:45 +0800383 if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
q.huang70b76492022-06-02 14:49:02 +0800384 {
q.huang52921662022-10-20 15:25:45 +0800385 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 +0800386 return id;
387 }
388 }
389 LYINFLOG("find id %d in local list , not found",call_id);
390 return INVALID_ID;
391}
lh7b0674a2022-01-10 00:34:35 -0800392void sendSignalToWaitCallStateChange()
393{
lhd1e457c2022-04-19 06:01:25 -0700394 LYINFLOG("send Signal To Wait Call State Change");
lh7b0674a2022-01-10 00:34:35 -0800395 pthread_mutex_lock(&call_state_change_mutex);
396 pthread_cond_signal(&call_state_change_cond);
397 pthread_mutex_unlock(&call_state_change_mutex);
398}
you.chen79d8f932023-12-26 17:03:44 +0800399void send_call_state_change(int callid)
lh7b0674a2022-01-10 00:34:35 -0800400{
llb3921072023-01-10 14:47:46 +0800401 LYINFLOG("send call state change");
you.chen79d8f932023-12-26 17:03:44 +0800402 s_CallId = callid;
llb3921072023-01-10 14:47:46 +0800403 pthread_mutex_lock(&s_call_state_change_mutex);
404 pthread_cond_signal(&s_call_state_change_cond);
405 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800406}
407
q.huang52921662022-10-20 15:25:45 +0800408void cleanup_call_list_mutex(void *arg)
lh7b0674a2022-01-10 00:34:35 -0800409{
q.huang52921662022-10-20 15:25:45 +0800410 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
lh7b0674a2022-01-10 00:34:35 -0800411}
llb3921072023-01-10 14:47:46 +0800412
413void update_end_state(int lynq_call_id)
414{
415 LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
416 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
417}
418
lh7b0674a2022-01-10 00:34:35 -0800419void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000420{
421 int ret=0;
lhd1e457c2022-04-19 06:01:25 -0700422 bool call_end;
ll04ae4142022-01-27 05:54:38 +0000423 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang8b33ed52022-04-19 20:27:44 -0400424 int update=0;
q.huang70b76492022-06-02 14:49:02 +0800425 int cnt;
426 int i,n;
q.huange97cfcf2022-08-29 20:04:31 +0800427#ifdef ECALL_SUPPORT
428 int handupIncomingMT=0;
429#endif
q.huang305fadc2024-01-02 18:40:40 +0800430 unsigned long interval;
431 time_t now;
432
433
q.huang52921662022-10-20 15:25:45 +0800434 pthread_mutex_lock(&s_notice_get_call_list_mutex);
435 pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
you.chen79d8f932023-12-26 17:03:44 +0800436 int tmp_call_id;
q.huang52921662022-10-20 15:25:45 +0800437 while(s_call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000438 {
q.huang52921662022-10-20 15:25:45 +0800439 update=0;
440 pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
you.chen79d8f932023-12-26 17:03:44 +0800441 LYINFLOG("triggerGetCallList event %p!!!", pthread_self());
ll04ae4142022-01-27 05:54:38 +0000442 memset(call_list,0,sizeof(call_list));
443 ret = lynq_get_current_call_list(call_list);
q.huang52921662022-10-20 15:25:45 +0800444 if(ret != RESULT_OK)
ll04ae4142022-01-27 05:54:38 +0000445 {
you.chen79d8f932023-12-26 17:03:44 +0800446 LYERRLOG("get current call list failure!!!");
llbc035332022-04-11 05:49:51 +0000447 continue;
ll04ae4142022-01-27 05:54:38 +0000448 }
lhd1e457c2022-04-19 06:01:25 -0700449 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huang70b76492022-06-02 14:49:02 +0800450 LYINFLOG("clear local index begin");
451 cnt=0;
452 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh7b0674a2022-01-10 00:34:35 -0800453 {
q.huang52921662022-10-20 15:25:45 +0800454 if(s_call_lists[i].used ==0)
q.huang70b76492022-06-02 14:49:02 +0800455 {
456 continue;
457 }
458 cnt++;
q.huang52921662022-10-20 15:25:45 +0800459 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 +0800460
q.huang52921662022-10-20 15:25:45 +0800461 if(s_call_lists[i].call_id > 0)
lhd1e457c2022-04-19 06:01:25 -0700462 {
463 call_end = 0;
q.huang70b76492022-06-02 14:49:02 +0800464 for(n = 0; n < LYNQ_CALL_MAX; n++)
lhd1e457c2022-04-19 06:01:25 -0700465 {
q.huang52921662022-10-20 15:25:45 +0800466 if(call_list[n].call_id == s_call_lists[i].call_id)
lhd1e457c2022-04-19 06:01:25 -0700467 {
468 call_end = 1;
q.huang52921662022-10-20 15:25:45 +0800469 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 +0800470 break;
lhd1e457c2022-04-19 06:01:25 -0700471 }
472 }
473 if(call_end == 0)
474 {
llb3921072023-01-10 14:47:46 +0800475 LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
476 //update_end_state(i);//lei modify for:update end state for this call
you.chen79d8f932023-12-26 17:03:44 +0800477 tmp_call_id = s_call_lists[i].call_id;
llb3921072023-01-10 14:47:46 +0800478 cleanCallList(i);
you.chen79d8f932023-12-26 17:03:44 +0800479 //Release the end handle
480 send_call_state_change(tmp_call_id);//means mt/mo call is end
llb3921072023-01-10 14:47:46 +0800481 //cleanCallList(i);
lhd1e457c2022-04-19 06:01:25 -0700482 }
483 } //fix bug API-54
q.huang70b76492022-06-02 14:49:02 +0800484 else
485 {
486 LYINFLOG("local id is 0");
487 }
488 }
489 LYINFLOG("clear local index end, local used cnt is %d", cnt);
490
491 LYINFLOG("add or update local index begin ");
492 for (i = 0;i < LYNQ_CALL_MAX;i++)
493 {
494 if(call_list[i].call_id==0)
495 {
496 break;
497 }
498
499 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,
500 call_list[i].direction,call_list[i].addr,call_list[i].toa);
501
lh7b0674a2022-01-10 00:34:35 -0800502 if(call_list[i].direction == 1)//MT call
503 {
q.huang70b76492022-06-02 14:49:02 +0800504 LYINFLOG("This is a MT CALL");
lh0fd3b012022-05-13 03:02:19 -0700505 /*MT CALL state code
506 **LYNQ_CALL_INCOMING = 4,
507 **LYNQ_CALL_WAITING = 5,
508 */
q.huange97cfcf2022-08-29 20:04:31 +0800509#ifdef ECALL_SUPPORT
lh0fd3b012022-05-13 03:02:19 -0700510 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh7b0674a2022-01-10 00:34:35 -0800511 {
q.huang52921662022-10-20 15:25:45 +0800512 handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
q.huange97cfcf2022-08-29 20:04:31 +0800513 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
514 if(handupIncomingMT)
lh7b0674a2022-01-10 00:34:35 -0800515 {
q.huang70b76492022-06-02 14:49:02 +0800516 lynq_call_hungup(&(call_list[i].call_id));
517 continue;
q.huange97cfcf2022-08-29 20:04:31 +0800518 }
q.huang70b76492022-06-02 14:49:02 +0800519 }
q.huange97cfcf2022-08-29 20:04:31 +0800520#endif
q.huang70b76492022-06-02 14:49:02 +0800521 /*you call me, and i call you,One party failed to dial*/
522 n = find_call_id_with_addr(call_list[i].addr);
523 if(n ==INVALID_ID)
524 {
q.huang305fadc2024-01-02 18:40:40 +0800525 if(s_call_auto_answer==false && call_list[i].call_state==LYNQ_CALL_INCOMING)
526 {
527 time(&now);
528 interval = difftime(now,s_rev_ring_time);
529 if(interval>MAX_RING_INCOMING_INTERVAL)
530 {
531 LYINFLOG("recv incoming, %d second no ril ring",interval);
532 continue;
533 }
534 }
535
q.huang52921662022-10-20 15:25:45 +0800536 n = addAddr(call_list[i].addr,call_list[i].call_id);
537 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 +0800538 send_call_state_change(call_list[i].call_id);
q.huang70b76492022-06-02 14:49:02 +0800539 }
q.huang52921662022-10-20 15:25:45 +0800540 else if(s_call_lists[n].call_state == call_list[i].call_state)
q.huang70b76492022-06-02 14:49:02 +0800541 {
542 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
543 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lhd1e457c2022-04-19 06:01:25 -0700544 {
lhd1e457c2022-04-19 06:01:25 -0700545 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
546 **an incoming call until the status changes.
547 **fix bug API-54
548 */
q.huang70b76492022-06-02 14:49:02 +0800549 LYINFLOG("resend incoming call signal");
you.chen79d8f932023-12-26 17:03:44 +0800550 send_call_state_change(call_list[i].call_id);
lhd1e457c2022-04-19 06:01:25 -0700551 }
lh7b0674a2022-01-10 00:34:35 -0800552 }
q.huang70b76492022-06-02 14:49:02 +0800553 else
ll72bf6c12022-03-24 10:22:25 +0800554 {
q.huang52921662022-10-20 15:25:45 +0800555 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 +0800556
llb3921072023-01-10 14:47:46 +0800557 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 +0800558 send_call_state_change(call_list[i].call_id);
llb3921072023-01-10 14:47:46 +0800559 }
lh7b0674a2022-01-10 00:34:35 -0800560 }
561 else
q.huang70b76492022-06-02 14:49:02 +0800562 {
563 LYINFLOG("This is a MO CALL");
564 call_end = 0;
565 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh7b0674a2022-01-10 00:34:35 -0800566 {
q.huang52921662022-10-20 15:25:45 +0800567 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 -0800568 {
q.huang52921662022-10-20 15:25:45 +0800569 if(s_call_lists[n].call_id==0)
q.huang70b76492022-06-02 14:49:02 +0800570 {
llb3921072023-01-10 14:47:46 +0800571 LYINFLOG("add a call id");
572 update=1;//for send sigal
q.huang70b76492022-06-02 14:49:02 +0800573 }
q.huang52921662022-10-20 15:25:45 +0800574 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);
575 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 +0800576 call_end = 1;
you.chen79d8f932023-12-26 17:03:44 +0800577 send_call_state_change(call_list[i].call_id);//means mo call is success
q.huang70b76492022-06-02 14:49:02 +0800578 break;
579 }
580 }
llb3921072023-01-10 14:47:46 +0800581 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 +0800582 {
583 LYINFLOG("need to hangup id %d", call_list[i].call_id);
584#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +0800585 if(IsECallDialing())
q.huang70b76492022-06-02 14:49:02 +0800586 {
587 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh7b0674a2022-01-10 00:34:35 -0800588 continue;
589 }
q.huang70b76492022-06-02 14:49:02 +0800590#endif
591 LYINFLOG("hang up service call id %d",call_list[i].call_id);
592 lynq_call_hungup(&(call_list[i].call_id));
lh7b0674a2022-01-10 00:34:35 -0800593 }
llb3921072023-01-10 14:47:46 +0800594
lh7b0674a2022-01-10 00:34:35 -0800595 }
q.huang70b76492022-06-02 14:49:02 +0800596 LYDBGLOG("servie idx %d end",i);
ll04ae4142022-01-27 05:54:38 +0000597 }
q.huang52921662022-10-20 15:25:45 +0800598 LYINFLOG("add or update local index end ");
599 if(s_module_isDial==1)
lh7b0674a2022-01-10 00:34:35 -0800600 {
q.huang70b76492022-06-02 14:49:02 +0800601 LYINFLOG("now is dialing");
602 if(update==1)
603 {
604 LYINFLOG("find added call");
605 sendSignalToWaitCallStateChange();
q.huang52921662022-10-20 15:25:45 +0800606 s_module_isDial = 0;
q.huang70b76492022-06-02 14:49:02 +0800607 }
608 else
609 {
610 LYINFLOG("not find added call");
611 }
612 }
613 else
614 {
615 LYINFLOG("now is not dialing");
q.huang52921662022-10-20 15:25:45 +0800616 }
ll04ae4142022-01-27 05:54:38 +0000617 }
q.huang52921662022-10-20 15:25:45 +0800618 pthread_cleanup_pop(0);
619 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
ll04ae4142022-01-27 05:54:38 +0000620 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800621}
622
q.huang52921662022-10-20 15:25:45 +0800623void lynqNoticeGetModuleCallList()
ll04ae4142022-01-27 05:54:38 +0000624{
you.chen79d8f932023-12-26 17:03:44 +0800625 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send start");
q.huang52921662022-10-20 15:25:45 +0800626 pthread_mutex_lock(&s_notice_get_call_list_mutex);
627 pthread_cond_signal(&s_notice_get_call_list_cond);
628 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
you.chen79d8f932023-12-26 17:03:44 +0800629 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send end");
lh7b0674a2022-01-10 00:34:35 -0800630}
631
q.huang52921662022-10-20 15:25:45 +0800632#if 0
lh7b0674a2022-01-10 00:34:35 -0800633/*Warren add for T800 platform 2021/11/19 start*/
634int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800635{
636 #if 0
lh7b0674a2022-01-10 00:34:35 -0800637 struct sockaddr_in lynq_socket_server_addr;
638 /* init lynq_socket_server_addr */
639 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
640 lynq_socket_server_addr.sin_family = AF_INET;
641 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
642 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800643
lh7b0674a2022-01-10 00:34:35 -0800644 /*
645 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
646 {
q.huang70b76492022-06-02 14:49:02 +0800647 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800648 exit(1);
649 }
650*/
lh42c1e572022-01-25 18:47:39 -0800651 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
652 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800653 {
q.huang70b76492022-06-02 14:49:02 +0800654 LYERRLOG("connect error");
lh7b0674a2022-01-10 00:34:35 -0800655 return -1;
656 }
rjw5d2a50e2022-02-28 15:01:49 +0800657 #endif
658 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
659 if (-1 == lynq_call_client_sockfd)
660 {
661 return lynq_call_client_sockfd;
662 }
ll630be412022-07-25 05:52:14 +0000663 struct timeval timeOut;
664 timeOut.tv_sec = 60;
665 timeOut.tv_usec = 0;
666 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
667 {
668 RLOGD("time out setting failed\n");
669 return -1;
670 }
rjw5d2a50e2022-02-28 15:01:49 +0800671 /* 设置address */
672 memset(&addr_serv, 0, sizeof(addr_serv));
673 addr_serv.sin_family = AF_INET;
674 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
675 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
676 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800677 return 0;
678}
lh7b0674a2022-01-10 00:34:35 -0800679
lh7b0674a2022-01-10 00:34:35 -0800680int lynq_socket_urc_start()
681{
682 int socket_fd=0;
683 int rt=0;
684 int len=0;
685 int on=1;
686 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800687 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000688 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000689 if(socket_fd < 0)
690 {
q.huang70b76492022-06-02 14:49:02 +0800691 LYERRLOG("creaet socket for udp fail");
ll04ae4142022-01-27 05:54:38 +0000692 return -1;
lh7b0674a2022-01-10 00:34:35 -0800693 }
694 urc_local_addr.sin_family = AF_INET;
695 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
696 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
697 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000698 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
699 if(rt<0)
700 {
q.huang70b76492022-06-02 14:49:02 +0800701 LYERRLOG("SO_REUSEADDR fail");
lh7b0674a2022-01-10 00:34:35 -0800702 return -1;
703 }
704 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000705 if (rt == -1)
706 {
lh21502f52022-01-27 00:27:12 -0800707 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000708 return -1;
lh7b0674a2022-01-10 00:34:35 -0800709 }
710 pthread_attr_init(&attr);
711 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800712 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800713 if(rt < 0)
714 {
q.huang70b76492022-06-02 14:49:02 +0800715 LYERRLOG("urc loop failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800716 return -1;
717 }
q.huang70b76492022-06-02 14:49:02 +0800718 LYDBGLOG("urc loop success!!!");
lh7b0674a2022-01-10 00:34:35 -0800719 return 0;
720}
q.huang52921662022-10-20 15:25:45 +0800721#endif
lh7b0674a2022-01-10 00:34:35 -0800722
723void lynq_call_state_change_test(int soc_id)
724{
q.huang70b76492022-06-02 14:49:02 +0800725 LYDBGLOG("call state change,sim:%d",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800726}
q.huangcb7b7292022-06-28 20:12:01 +0800727
q.huang52921662022-10-20 15:25:45 +0800728int lynq_start_call_list_loop()
729{
730#if 0
731 int ret = 0;
732 pthread_attr_t attr;
733 pthread_attr_init(&attr);
734 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
q.huangcb7b7292022-06-28 20:12:01 +0800735
q.huang52921662022-10-20 15:25:45 +0800736 s_notice_get_call_list_mutex = new pthread_mutex_t;
737 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
738 s_notice_get_call_list_cond = new pthread_cond_t;
739 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
740 pthread_cond_init(s_notice_get_call_list_cond, NULL);
741 LYINFLOG("liulei s_notice_get_call_list_cond\n");
742#endif
q.huangcb7b7292022-06-28 20:12:01 +0800743
q.huang52921662022-10-20 15:25:45 +0800744 s_call_list_loop = 1;
745 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
746 if(ret < 0)
q.huangcb7b7292022-06-28 20:12:01 +0800747 {
q.huang52921662022-10-20 15:25:45 +0800748 LYERRLOG("lynq_update_call_list_loop fail!!!");
lla8c25a82022-03-17 05:31:33 +0000749 return -1;
750 }
q.huang52921662022-10-20 15:25:45 +0800751 LYINFLOG("lynq_update_call_list_loop success!!!");
q.huangcb7b7292022-06-28 20:12:01 +0800752
q.huang52921662022-10-20 15:25:45 +0800753 memset(s_call_lists,0,sizeof(s_call_lists));
lh7b0674a2022-01-10 00:34:35 -0800754 return 0;
755}
q.huang52921662022-10-20 15:25:45 +0800756
757int lynq_stop_call_list_loop()
lh7b0674a2022-01-10 00:34:35 -0800758{
q.huang70b76492022-06-02 14:49:02 +0800759 int ret;
q.huang52921662022-10-20 15:25:45 +0800760 pthread_mutex_lock(&s_notice_get_call_list_mutex);
761 s_call_list_loop = 0;
762 ret = pthread_cancel(s_call_list_loop_tid);
763 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
764 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
765 ret = pthread_join(s_call_list_loop_tid,NULL);
766 LYINFLOG("pthread join w_c_list ret = %d",ret);
767 s_call_list_loop_tid=-1;
768#if 0
769 pthread_mutex_destroy(s_notice_get_call_list_mutex);
770 pthread_cond_destroy(s_notice_get_call_list_cond);
771 delete s_notice_get_call_list_mutex;
772 //s_notice_get_call_list_mutex = NULL;
773 delete s_notice_get_call_list_cond;
774 //s_notice_get_call_list_cond = NULL;
775#endif
776
777 return 0;
rita98e2e9c2022-04-07 06:08:13 -0400778}
q.huang714145d2022-04-18 00:09:50 -0400779
q.huang52921662022-10-20 15:25:45 +0800780int lynq_init_call(int utoken){
q.huangf6a9ddc2023-12-08 20:23:56 +0800781
782 LYLOGSET(LOG_INFO);
783 LYLOGEINIT(USER_LOG_TAG);
784 LYERRLOG("%s start, parameter is %d", __func__,utoken);
785
q.huang52921662022-10-20 15:25:45 +0800786 if(g_module_init_flag != MODULE_CLOSED)
787 {
788 LYERRLOG("module state is %d",g_module_init_flag);
789 return LYNQ_E_CONFLICT;
790 }
791 if(utoken <0){
792 LYERRLOG("utoken is less than 0",utoken);
793 return LYNQ_E_PARAMETER_ANONALY;
794 }
795 g_module_init_flag = MODULE_SWITCHING;
q.huangf6a9ddc2023-12-08 20:23:56 +0800796
q.huang52921662022-10-20 15:25:45 +0800797
798 g_module_Global_uToken = utoken;
799
q.huang036b6cf2023-01-10 14:29:20 +0800800 int ret = lynq_start_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800801 if(ret != RESULT_OK)
802 {
803 LYERRLOG("init socket urc fail!!!");
804 g_module_init_flag = MODULE_CLOSED;
805 return LYNQ_E_INNER_ERROR;
806 }
807
q.huang036b6cf2023-01-10 14:29:20 +0800808 ret = lynq_start_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800809 if(ret !=RESULT_OK)
810 {
811 LYERRLOG("init socket client fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800812 lynq_close_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800813 g_module_init_flag = MODULE_CLOSED;
814 return LYNQ_E_INNER_ERROR;
815 }
816
817
818 int result = lynq_start_call_list_loop();
819 if(ret != RESULT_OK)
820 {
821 LYERRLOG("lynq_start_call_list_loop fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800822 lynq_close_all_urc_socket_thread();
823 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800824 g_module_init_flag = MODULE_CLOSED;
825 return LYNQ_E_INNER_ERROR;
826 }
827
q.huang52921662022-10-20 15:25:45 +0800828 g_module_init_flag = MODULE_RUNNING;
q.huangf6a9ddc2023-12-08 20:23:56 +0800829
830 LYERRLOG("%s end suc", __func__);
q.huang52921662022-10-20 15:25:45 +0800831 return 0;
832}
833
834int lynq_deinit_call(void){
q.huangf6a9ddc2023-12-08 20:23:56 +0800835 LYERRLOG("%s start", __func__);
q.huang52921662022-10-20 15:25:45 +0800836
837 if (g_module_init_flag != MODULE_RUNNING)
838 {
839 LYERRLOG("module state is %d",g_module_init_flag);
840 return LYNQ_E_CONFLICT;
841 }
842 lynq_call_hungup_all();
q.huang52921662022-10-20 15:25:45 +0800843 g_module_init_flag = MODULE_SWITCHING;
q.huang036b6cf2023-01-10 14:29:20 +0800844 lynq_close_all_urc_socket_thread();
845 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800846 lynq_stop_call_list_loop();
847 g_module_init_flag = MODULE_CLOSED;
q.huangf6a9ddc2023-12-08 20:23:56 +0800848
849 LYERRLOG("%s end suc", __func__);
q.huang52921662022-10-20 15:25:45 +0800850 return 0;
851}
852
853#if 0
q.huang714145d2022-04-18 00:09:50 -0400854int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400855{
856 Parcel p;
857 lynq_client_t client;
858 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800859 int token;
rita089527e2022-04-07 01:55:39 -0400860 int request = -1;
861 int slot_id = -1;
862 int error = -1;
rita089527e2022-04-07 01:55:39 -0400863
q.huang52921662022-10-20 15:25:45 +0800864 Parcel* p=NULL;
865 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
866 if(ret==RESULT_OK)
867 {
868 delete p;
869 }
870 return ret;
871
rita089527e2022-04-07 01:55:39 -0400872 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400873 client.request = request_id;
874 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400875 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400876 if(argc!=0)
877 {
878 va_list args;
879 va_start(args, format);
880 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
881 va_end(args);
882 }
q.huang70b76492022-06-02 14:49:02 +0800883 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400884 if(send_request(lynq_call_client_sockfd,&client)==-1)
885 {
886 LYERRLOG("send request fail");
887 return -1;
888 }
q.huang714145d2022-04-18 00:09:50 -0400889 if(get_response(lynq_call_client_sockfd,p)==0)
890 {
q.huang7de1d662022-09-13 14:19:24 +0800891 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang714145d2022-04-18 00:09:50 -0400892 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
893 }
rita089527e2022-04-07 01:55:39 -0400894 return error;
q.huang52921662022-10-20 15:25:45 +0800895
896
rita089527e2022-04-07 01:55:39 -0400897}
q.huang52921662022-10-20 15:25:45 +0800898#endif
rita089527e2022-04-07 01:55:39 -0400899
q.huang714145d2022-04-18 00:09:50 -0400900int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400901{
q.huang714145d2022-04-18 00:09:50 -0400902 if(status==NULL)
903 {
904 LYERRLOG("status is null");
q.huang52921662022-10-20 15:25:45 +0800905 return LYNQ_E_PARAMETER_ANONALY;
q.huang714145d2022-04-18 00:09:50 -0400906 }
q.huang52921662022-10-20 15:25:45 +0800907
908 Parcel* p=NULL;
909 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
910 if(ret==RESULT_OK)
rita089527e2022-04-07 01:55:39 -0400911 {
q.huang52921662022-10-20 15:25:45 +0800912 p->readInt32(status);
913 delete p;
rita089527e2022-04-07 01:55:39 -0400914 }
q.huang52921662022-10-20 15:25:45 +0800915 return ret;
916}
917
918int waitCallstateChange(int mtime)
919{
920 LYINFLOG("wait Call state Change");
921 int ret = 0;
922 int sec = 0;
you.chen79d8f932023-12-26 17:03:44 +0800923 int ms = 0;
q.huang52921662022-10-20 15:25:45 +0800924 struct timeval now;
925 struct timespec timeout;
926 gettimeofday(&now,NULL);
927 sec = mtime/1000;
you.chen79d8f932023-12-26 17:03:44 +0800928 ms = mtime%1000;
q.huang52921662022-10-20 15:25:45 +0800929 timeout.tv_sec = now.tv_sec+sec;
you.chen79d8f932023-12-26 17:03:44 +0800930 unsigned long long ns;
931 ns = now.tv_usec*1000ull + ms*1000000ull;
932 timeout.tv_sec += ns/1000000000;
933 timeout.tv_nsec = ns % 1000000000;
q.huang52921662022-10-20 15:25:45 +0800934 pthread_mutex_lock(&call_state_change_mutex);
935 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
936 pthread_mutex_unlock(&call_state_change_mutex);
937 return ret;
938}
939
940int IsNormalCallDailing()
941{
942 return s_module_isDial;
rita089527e2022-04-07 01:55:39 -0400943}
944
llb3921072023-01-10 14:47:46 +0800945
lh3b6f7ea2023-11-08 01:16:42 -0800946int check_file_access(const char *fileName)
947{
948 if(0 == access(fileName,F_OK))
949 {
950 LYINFLOG("find file %s success",fileName);
951 return 0;
952 }
953 LYERRLOG("find file %s fail",fileName);
954 return 1;
955}
956int try_reset_audio_service()
957{
958 //check files:audio-ctrl-service,libmodem-afe-service,speech_daemon
959 int ap_speech = 0;
960 int audio_ctrl_ser = 0;
961 int md_afe = 0;
962 int tele_demo_lock = 0;
963 LYINFLOG("try_reset_audio_service start");
964 ap_speech = check_file_access(AP_SPEECH);
965 audio_ctrl_ser = check_file_access(AUDIO_CTRL_SER);
966 md_afe = check_file_access(LIBMODEM_AFE);
967 tele_demo_lock = check_file_access(TELE_DEMO_LOCK);
968 if((ap_speech + audio_ctrl_ser + md_afe) > 0)
969 {
970 system("systemctl stop audio-ctrl-service");
971 system("systemctl stop speech_daemon");
972 system("systemctl stop libmodem_afe_service");
973 usleep(200000);//200ms
974 system("rm /tmp/audio_ctrl_service -rf");
975 system("rm /tmp/ap_speech -rf");
976 system("rm /tmp/libmodem-afe-ctrl -rf");
977 usleep(100000);//100ms
978 system("systemctl start libmodem_afe_service");
979 usleep(200000);//200ms
980 system("systemctl start speech_daemon");
981 usleep(200000);//200ms
982 system("systemctl start audio-ctrl-service");
983 sleep(1);//1s
984 LYERRLOG("reset audio relation service");
985 }
986 if(tele_demo_lock)
987 {
988 LYERRLOG("%s lose,why?",TELE_DEMO_LOCK);
989 }
990 return 0;
991}
992
l.yangd25d3712024-03-04 17:55:39 -0800993int call_boot_check()
994{
995 FILE *file = NULL;
996 int uptime = 0;
997
998 file = fopen("/proc/uptime", "r");
999 if(file == NULL)
1000 {
1001 LYERRLOG("Error opening /proc/uptime");
1002 return -1;
1003 }
1004
1005 if(fscanf(file, "%d ", &uptime) != 1)
1006 {
1007 LYERRLOG("Error reading uptime value");
1008 }
1009
1010 fclose(file);
1011
1012 if(uptime > SYSTEM_UPTIME)
1013 {
1014 LYINFLOG("System uptime is greater than 40 seconds.");
1015 }
1016 else
1017 {
1018 LYINFLOG("System uptime is less than 40 seconds.");
1019 FILE *fp = NULL;
1020 if(check_file_access(CALL_REBOOT_FLAG) != 0)
1021 {
1022 usleep(3000000);
1023 fp = fopen(CALL_REBOOT_FLAG,"w");
1024 if(fp == NULL)
1025 {
1026 LYERRLOG("Creat call reboot flag file failed !!!!");
1027 return -1;
1028 }
1029 LYINFLOG("Creat flag file success");
1030 fclose(fp);
1031 }
1032 }
1033 return 0;
1034
1035}
lh7b0674a2022-01-10 00:34:35 -08001036int lynq_call(int* handle,char addr[])
1037{
q.huang52921662022-10-20 15:25:45 +08001038 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001039 {
q.huang52921662022-10-20 15:25:45 +08001040 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1041 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001042 }
lh3b6f7ea2023-11-08 01:16:42 -08001043 try_reset_audio_service();
l.yangd25d3712024-03-04 17:55:39 -08001044
1045#ifdef GSW_RIL_CFG
1046 call_boot_check();
1047#endif
1048
lh7b0674a2022-01-10 00:34:35 -08001049 int lynq_call_id = -1;
q.huang70b76492022-06-02 14:49:02 +08001050
1051 LYINFLOG("lynq_call begin addr %s",addr);
lh7b0674a2022-01-10 00:34:35 -08001052 if(addr==NULL)
1053 {
1054 LYERRLOG("Phone num is null!!!");
q.huang52921662022-10-20 15:25:45 +08001055 return LYNQ_E_PARAMETER_ANONALY;
lh7b0674a2022-01-10 00:34:35 -08001056 }
q.huang70b76492022-06-02 14:49:02 +08001057
1058 if(find_call_id_with_addr(addr)!=INVALID_ID)
1059 {
1060 LYERRLOG("addr %s exists",addr);
1061 return LYNQ_E_CONFLICT;
1062 }
1063
1064#ifdef ECALL_SUPPORT
1065 if(lynq_ecall_is_running())
1066 {
1067 LYERRLOG("lynq_fast_ecall ecall is running");
1068 return LYNQ_E_ECALL_BEING_RUNNING;
1069 }
1070#endif
q.huang52921662022-10-20 15:25:45 +08001071 Parcel* p=NULL;
1072 lynq_call_id = addAddr(addr,0);
1073 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
1074 if(ret!=0)
1075 {
llb3921072023-01-10 14:47:46 +08001076 cleanCallList(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001077 return ret;
llb3921072023-01-10 14:47:46 +08001078 }
1079 delete p;
q.huang52921662022-10-20 15:25:45 +08001080 s_module_isDial = 1;
1081 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -08001082 {
q.huang52921662022-10-20 15:25:45 +08001083 //if timeout,this call need destroy.
1084 s_module_isDial = 0;
1085 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
llb3921072023-01-10 14:47:46 +08001086 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001087 send_call_state_change(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001088 return LYNQ_E_TIME_OUT;
lh7b0674a2022-01-10 00:34:35 -08001089 }
q.huang52921662022-10-20 15:25:45 +08001090 s_module_isDial = 0;
1091 *handle = s_call_lists[lynq_call_id].call_id;
1092 if(*handle > 0)
lh7b0674a2022-01-10 00:34:35 -08001093 {
q.huang52921662022-10-20 15:25:45 +08001094 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
1095 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001096 }
q.huang52921662022-10-20 15:25:45 +08001097 else
1098 {
1099 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
lle3b9a232023-01-14 13:21:20 +08001100 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001101 send_call_state_change(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001102 return LYNQ_E_INVALID_ID_ANONALY;
llb3921072023-01-10 14:47:46 +08001103 }
lh7b0674a2022-01-10 00:34:35 -08001104}
llb3921072023-01-10 14:47:46 +08001105
lh7b0674a2022-01-10 00:34:35 -08001106int lynq_call_answer()
1107{
q.huang52921662022-10-20 15:25:45 +08001108 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001109 {
q.huang52921662022-10-20 15:25:45 +08001110 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1111 return LYNQ_E_CONFLICT;
1112 }
1113
1114 Parcel* p=NULL;
1115 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
1116 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001117 {
q.huang52921662022-10-20 15:25:45 +08001118 delete p;
1119 }
1120 return ret;
lh7b0674a2022-01-10 00:34:35 -08001121}
llb3921072023-01-10 14:47:46 +08001122
lh7b0674a2022-01-10 00:34:35 -08001123int lynq_call_hungup(int* handle)
1124{
q.huang52921662022-10-20 15:25:45 +08001125 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001126 {
q.huang52921662022-10-20 15:25:45 +08001127 return LYNQ_E_CONFLICT;
1128 }
1129
lh42c1e572022-01-25 18:47:39 -08001130 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1131 {
q.huang52921662022-10-20 15:25:45 +08001132 LYERRLOG("%s illegal input!!!!",__func__);
1133 return LYNQ_E_PARAMETER_ANONALY;
lh42c1e572022-01-25 18:47:39 -08001134 }
q.huang52921662022-10-20 15:25:45 +08001135
1136 int call_id = *handle;
1137 Parcel* p=NULL;
1138 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1139 if(ret!=0)
lh7b0674a2022-01-10 00:34:35 -08001140 {
q.huang52921662022-10-20 15:25:45 +08001141 return ret;
you.chen79d8f932023-12-26 17:03:44 +08001142 }
q.huang52921662022-10-20 15:25:45 +08001143 delete p;
1144
you.chen79d8f932023-12-26 17:03:44 +08001145 int lynq_call_id=find_call_id_with_call_id(call_id);
q.huang52921662022-10-20 15:25:45 +08001146 if(lynq_call_id!=INVALID_ID)
lh7b0674a2022-01-10 00:34:35 -08001147 {
you.chen79d8f932023-12-26 17:03:44 +08001148 //lei modify for API-857
q.huang52921662022-10-20 15:25:45 +08001149 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001150 send_call_state_change(call_id);
1151 }
1152 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001153}
1154int lynq_call_hungup_all()
1155{
q.huang52921662022-10-20 15:25:45 +08001156 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001157 {
q.huang52921662022-10-20 15:25:45 +08001158 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1159 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001160 }
q.huang52921662022-10-20 15:25:45 +08001161
1162 Parcel* p=NULL;
1163 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1164 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001165 {
q.huang52921662022-10-20 15:25:45 +08001166 delete p;
1167 }
1168 return ret;
lh7b0674a2022-01-10 00:34:35 -08001169}
llb3921072023-01-10 14:47:46 +08001170
1171int lynq_wait_call_state_change(int *handle)
lh7b0674a2022-01-10 00:34:35 -08001172{
q.huang52921662022-10-20 15:25:45 +08001173 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001174 {
q.huang52921662022-10-20 15:25:45 +08001175 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1176 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001177 }
llb3921072023-01-10 14:47:46 +08001178 wait_call_state();
1179 *handle = s_CallId;
1180 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1181 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001182}
1183
1184int lynq_set_auto_answercall(const int mode)
1185{
q.huang52921662022-10-20 15:25:45 +08001186 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001187 {
q.huang52921662022-10-20 15:25:45 +08001188 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1189 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001190 }
q.huang52921662022-10-20 15:25:45 +08001191 s_call_auto_answer = mode;
lh7b0674a2022-01-10 00:34:35 -08001192 LYINFLOG("auto answer call mode =%d",mode);
q.huang52921662022-10-20 15:25:45 +08001193 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001194}
llb3921072023-01-10 14:47:46 +08001195
1196int lynq_find_already_end()
1197{
1198 for(int i=0;i < LYNQ_CALL_MAX; i++)
1199 {
1200 if(s_call_lists[i].call_state == 6)
1201 {
1202 return 0;
1203 }
1204 }
1205 return INVALID_ID;
1206}
1207
q.huangec88da92022-03-29 04:17:32 -04001208int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1209{
q.huang52921662022-10-20 15:25:45 +08001210 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001211 {
q.huang52921662022-10-20 15:25:45 +08001212 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1213 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001214 }
q.huangec88da92022-03-29 04:17:32 -04001215 int lynq_call_id = 0;
q.huang70b76492022-06-02 14:49:02 +08001216 LYINFLOG("lynq_get_current_call_state begin ");
q.huangec88da92022-03-29 04:17:32 -04001217 if(handle==NULL)
1218 {
q.huang70b76492022-06-02 14:49:02 +08001219 LYERRLOG("handle is NULL");
q.huang52921662022-10-20 15:25:45 +08001220 return LYNQ_E_PARAMETER_ANONALY;
q.huangec88da92022-03-29 04:17:32 -04001221 }
you.chen79d8f932023-12-26 17:03:44 +08001222 if((*handle) <= 0)
1223 {
1224 LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);
1225 return LYNQ_E_INVALID_ID_ANONALY;
1226 }
llb3921072023-01-10 14:47:46 +08001227 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huang70b76492022-06-02 14:49:02 +08001228 lynq_call_id = find_call_id_with_call_id(*handle);
1229 if(lynq_call_id==INVALID_ID)
1230 {
llb3921072023-01-10 14:47:46 +08001231 //find end state
1232 if((*handle) >= 0)
1233 {
1234 *call_state = (int)LYNQ_CALL_END;
1235 return RESULT_OK;
1236 }
1237 else
1238 {
1239 return LYNQ_E_INVALID_ID_ANONALY;
1240 }
q.huang70b76492022-06-02 14:49:02 +08001241 }
q.huang52921662022-10-20 15:25:45 +08001242 *call_state = s_call_lists[lynq_call_id].call_state;
1243 *toa = s_call_lists[lynq_call_id].toa;
1244 *direction = s_call_lists[lynq_call_id].direction;
1245 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
llb3921072023-01-10 14:47:46 +08001246 return RESULT_OK;
q.huangec88da92022-03-29 04:17:32 -04001247}
1248
q.huange97cfcf2022-08-29 20:04:31 +08001249int lynq_get_current_call_number()
1250{
1251 int cnt=0;
1252 int i;
1253 for(i = 0;i < LYNQ_CALL_MAX;i++)
1254 {
q.huang52921662022-10-20 15:25:45 +08001255 if(s_call_lists[i].used !=0)
q.huange97cfcf2022-08-29 20:04:31 +08001256 {
1257 cnt++;
1258 }
1259 }
1260
1261 return cnt;
1262}
1263
q.huangec88da92022-03-29 04:17:32 -04001264/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001265static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001266 switch(enable){
1267 case 0:
q.huang52921662022-10-20 15:25:45 +08001268 return true;
llf512fa32022-02-14 08:58:16 +00001269 case 1:
q.huang52921662022-10-20 15:25:45 +08001270 return true;
llf512fa32022-02-14 08:58:16 +00001271 default:
q.huang52921662022-10-20 15:25:45 +08001272 return false;
lldc99c9b2022-01-24 12:16:22 +00001273 }
1274}
1275
lh7b0674a2022-01-10 00:34:35 -08001276int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001277{
q.huang52921662022-10-20 15:25:45 +08001278 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001279 {
q.huang52921662022-10-20 15:25:45 +08001280 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001281 return LYNQ_E_CONFLICT;
1282 }
q.huang52921662022-10-20 15:25:45 +08001283 if(!judge_mic(enable)){
1284 return LYNQ_E_PARAMETER_ANONALY;
1285 }
1286 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1287
1288 Parcel* p=NULL;
1289 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1290 if(ret==RESULT_OK)
1291 {
1292 delete p;
1293 }
1294 return ret;
q.huangec88da92022-03-29 04:17:32 -04001295}
1296int lynq_get_mute_mic(int *status)
1297{
q.huang52921662022-10-20 15:25:45 +08001298 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001299 {
q.huang52921662022-10-20 15:25:45 +08001300 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1301 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001302 }
q.huang52921662022-10-20 15:25:45 +08001303 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh7b0674a2022-01-10 00:34:35 -08001304}
ll72bf6c12022-03-24 10:22:25 +08001305
1306/**
1307 * @brief Check whether DTMF is valid
1308 *
1309 * @param callnum dtmf eg:0-9 * #
1310 * @return int
1311 */
1312static int judge_dtmf(const char callnum)
1313{
1314 if(callnum == '#')
1315 {
q.huang52921662022-10-20 15:25:45 +08001316 return true;
ll72bf6c12022-03-24 10:22:25 +08001317 }
1318 if(callnum == '*')
1319 {
q.huang52921662022-10-20 15:25:45 +08001320 return true;
ll72bf6c12022-03-24 10:22:25 +08001321 }
1322 if(callnum >= '0'&& callnum <= '9')
1323 {
q.huang52921662022-10-20 15:25:45 +08001324 return true;
ll72bf6c12022-03-24 10:22:25 +08001325 }
q.huang52921662022-10-20 15:25:45 +08001326 return false;
ll72bf6c12022-03-24 10:22:25 +08001327}
1328
ll209e6112022-07-20 09:30:19 +00001329int lynq_switch_waiting_or_holding_and_active(void)
1330{
q.huang52921662022-10-20 15:25:45 +08001331 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001332 {
q.huang52921662022-10-20 15:25:45 +08001333 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1334 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001335 }
q.huang52921662022-10-20 15:25:45 +08001336
1337 Parcel* p=NULL;
1338 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1339 if(ret==RESULT_OK)
1340 {
1341 delete p;
1342 }
1343 return ret;
1344
1345#if 0
ll209e6112022-07-20 09:30:19 +00001346 Parcel p;
1347 lynq_client_t client;
1348 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001349 int token;
ll209e6112022-07-20 09:30:19 +00001350 int request = -1;
1351 int slot_id = -1;
1352 int error = -1;
1353 client.uToken = Global_uToken_call;
1354 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1355 client.paramLen = 0;
1356 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1357 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001358 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001359 if(send_request(lynq_call_client_sockfd,&client)==-1)
1360 {
1361 LYERRLOG("send request fail");
1362 return -1;
1363 }
1364 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001365 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001366 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001367 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1368 return error;
q.huang52921662022-10-20 15:25:45 +08001369#endif
ll209e6112022-07-20 09:30:19 +00001370}
1371
1372int lynq_hangup_waiting_or_background(void)
1373{
q.huang52921662022-10-20 15:25:45 +08001374 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001375 {
q.huang52921662022-10-20 15:25:45 +08001376 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1377 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001378 }
q.huang52921662022-10-20 15:25:45 +08001379
1380 Parcel* p=NULL;
1381 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1382 if(ret==RESULT_OK)
1383 {
1384 delete p;
1385 }
1386 return ret;
1387#if 0
ll209e6112022-07-20 09:30:19 +00001388 Parcel p;
1389 lynq_client_t client;
1390 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001391 int token;
ll209e6112022-07-20 09:30:19 +00001392 int request = -1;
1393 int slot_id = -1;
1394 int error = -1;
1395 client.uToken = Global_uToken_call;
1396 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1397 client.paramLen = 0;
1398 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1399 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001400 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001401 if(send_request(lynq_call_client_sockfd,&client)==-1)
1402 {
1403 LYERRLOG("send request fail");
1404 return -1;
1405 }
1406 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001407 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001408 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001409 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1410 return error;
q.huang52921662022-10-20 15:25:45 +08001411#endif
ll209e6112022-07-20 09:30:19 +00001412}
1413
1414int lynq_hangup_foreground_resume_background(void)
1415{
q.huang52921662022-10-20 15:25:45 +08001416 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001417 {
q.huang52921662022-10-20 15:25:45 +08001418 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1419 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001420 }
q.huang52921662022-10-20 15:25:45 +08001421
1422 Parcel* p=NULL;
1423 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1424 if(ret==RESULT_OK)
1425 {
1426 delete p;
1427 }
1428 return ret;
1429#if 0
ll209e6112022-07-20 09:30:19 +00001430 Parcel p;
1431 lynq_client_t client;
1432 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001433 int token;
ll209e6112022-07-20 09:30:19 +00001434 int request = -1;
1435 int slot_id = -1;
1436 int error = -1;
1437 client.uToken = Global_uToken_call;
1438 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1439 client.paramLen = 0;
1440 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1441 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001442 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001443 if(send_request(lynq_call_client_sockfd,&client)==-1)
1444 {
1445 LYERRLOG("send request fail");
1446 return -1;
1447 }
1448 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001449 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001450 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001451 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1452 return error;
q.huang52921662022-10-20 15:25:45 +08001453#endif
ll209e6112022-07-20 09:30:19 +00001454}
1455
lh7b0674a2022-01-10 00:34:35 -08001456int lynq_set_DTMF(const char callnum)
1457{
q.huang52921662022-10-20 15:25:45 +08001458 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001459 {
q.huang52921662022-10-20 15:25:45 +08001460 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1461 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001462 }
ll72bf6c12022-03-24 10:22:25 +08001463 if(!judge_dtmf(callnum))
1464 {
1465 return LYNQ_E_CONFLICT;
1466 }
q.huang52921662022-10-20 15:25:45 +08001467 if(s_module_call_state!=CALL_ON)
lh7b0674a2022-01-10 00:34:35 -08001468 {
1469 LYERRLOG("LYNQ_E_CONFLICT");
1470 return LYNQ_E_CONFLICT;
1471 }
q.huang52921662022-10-20 15:25:45 +08001472
1473// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1474
1475 Parcel* p=NULL;
1476 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1477 if(ret==RESULT_OK)
1478 {
1479 delete p;
1480 }
1481 return ret;
lh7b0674a2022-01-10 00:34:35 -08001482}
q.huangec88da92022-03-29 04:17:32 -04001483static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1484 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1485 if(volume < 0 ||volume >36){
1486 return 0;
1487 }
1488 }
1489 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1490 {
1491 if(volume < 1 ||volume >7){
1492 return 0;
1493 }
lldc99c9b2022-01-24 12:16:22 +00001494 }
ll04ae4142022-01-27 05:54:38 +00001495 return 1;
lldc99c9b2022-01-24 12:16:22 +00001496}
lh7b0674a2022-01-10 00:34:35 -08001497int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001498{
q.huang52921662022-10-20 15:25:45 +08001499 if(g_module_init_flag != MODULE_RUNNING)
1500 {
1501 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001502 return LYNQ_E_CONFLICT;
1503 }
q.huang52921662022-10-20 15:25:45 +08001504 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1505 return LYNQ_E_PARAMETER_ANONALY;
1506 }
1507// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1508 Parcel* p=NULL;
1509 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1510 if(ret==RESULT_OK)
1511 {
1512 delete p;
1513 }
1514 return ret;
lh7b0674a2022-01-10 00:34:35 -08001515}
q.huangb212fde2022-04-05 23:11:02 -04001516int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001517{
q.huang52921662022-10-20 15:25:45 +08001518 if(g_module_init_flag != MODULE_RUNNING)
lh7b0674a2022-01-10 00:34:35 -08001519 {
q.huang52921662022-10-20 15:25:45 +08001520 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangec88da92022-03-29 04:17:32 -04001521 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001522 }
q.huang52921662022-10-20 15:25:45 +08001523 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1524 {
1525 return LYNQ_E_PARAMETER_ANONALY;
1526 }
1527// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1528 Parcel* p=NULL;
1529 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1530 if(ret==RESULT_OK)
1531 {
1532 delete p;
1533 }
1534 return ret;
lh7b0674a2022-01-10 00:34:35 -08001535}
q.huangec88da92022-03-29 04:17:32 -04001536int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1537{
q.huang52921662022-10-20 15:25:45 +08001538 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangec88da92022-03-29 04:17:32 -04001539}
q.huangb212fde2022-04-05 23:11:02 -04001540int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001541{
q.huang52921662022-10-20 15:25:45 +08001542// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1543 Parcel* p=NULL;
1544 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1545 if(ret==RESULT_OK)
1546 {
1547 delete p;
1548 }
1549 return ret;
q.huangec88da92022-03-29 04:17:32 -04001550}
1551int lynq_incall_record_stop()
1552{
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);
1556 return LYNQ_E_CONFLICT;
1557 }
q.huangb212fde2022-04-05 23:11:02 -04001558 const char* unused_file="just_ocuupy_paramter_postion";
q.huang52921662022-10-20 15:25:45 +08001559// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1560 Parcel* p=NULL;
1561 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1562 if(ret==RESULT_OK)
1563 {
1564 delete p;
1565 }
1566 return ret;
q.huangec88da92022-03-29 04:17:32 -04001567}
1568/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001569
q.huang036b6cf2023-01-10 14:29:20 +08001570
1571
1572bool is_support_urc(int urc_id)
1573{
1574 switch(urc_id)
1575 {
1576 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1577 case RIL_UNSOL_CALL_RING:
1578 case RIL_UNSOL_RINGBACK_TONE:
1579 case RIL_UNSOL_CALL_INFO_INDICATION:
1580#ifdef ECALL_SUPPORT
1581 case RIL_UNSOL_ECALL_INDICATIONS://9502
1582#endif
1583 return true;
1584 default:
1585 return false;
1586 }
1587}
1588
q.huang52921662022-10-20 15:25:45 +08001589void urc_msg_process(Parcel *p)
1590{
1591 int resp_type;
1592 int urcid;
1593 int slot_id;
q.huang036b6cf2023-01-10 14:29:20 +08001594
1595 int size=p->dataSize();
q.huang52921662022-10-20 15:25:45 +08001596 p->readInt32(&resp_type);
1597 p->readInt32(&urcid);
1598 p->readInt32(&slot_id);
q.huang036b6cf2023-01-10 14:29:20 +08001599 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 +08001600 switch (urcid)
1601 {
1602 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1603 {
1604 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1605 lynqNoticeGetModuleCallList();
1606 break;
1607 }
1608 case RIL_UNSOL_CALL_RING: //1018
1609 {
q.huang305fadc2024-01-02 18:40:40 +08001610 time(&s_rev_ring_time);
q.huang52921662022-10-20 15:25:45 +08001611 if(s_call_auto_answer==1)
1612 {
1613 lynq_call_answer();
1614 }
1615 break;
1616 }
1617 case RIL_UNSOL_RINGBACK_TONE: //1029
1618 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1619 {
1620 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1621 break;
1622 }
q.huang714145d2022-04-18 00:09:50 -04001623#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +08001624 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange97cfcf2022-08-29 20:04:31 +08001625 {
q.huang52921662022-10-20 15:25:45 +08001626 urc_ecall_msg_process(p);
q.huange97cfcf2022-08-29 20:04:31 +08001627 }
q.huange97cfcf2022-08-29 20:04:31 +08001628#endif
q.huang52921662022-10-20 15:25:45 +08001629 default:
1630 break;
q.huangcb7b7292022-06-28 20:12:01 +08001631 }
q.huang5ca6c072022-06-06 16:15:31 +08001632}
q.huang5ca6c072022-06-06 16:15:31 +08001633
lh7b0674a2022-01-10 00:34:35 -08001634#if 0
1635int main(int argc,char **argv)
1636{
1637 int n = 0;
1638 n = lynq_init_call(lynq_call_state_change_test,2222);
1639 if(n<0)
1640 {
q.huang70b76492022-06-02 14:49:02 +08001641 LYDBGLOG("lynq init call fail!!!");
lh7b0674a2022-01-10 00:34:35 -08001642 return -1;
1643 }
q.huang70b76492022-06-02 14:49:02 +08001644 LYDBGLOG("lynq call init success!!!");
lh7b0674a2022-01-10 00:34:35 -08001645 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1646 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1647 lynq_call(phoneNum);
1648 while(1)
1649 {
1650 sleep(1);
1651 }
1652 return 0;
1653}
1654#endif
1655/*Warren add for T800 platform 2021/11/19 end*/