blob: 8e80462f73e1fca0e821856036f1687368644e04 [file] [log] [blame]
ll630be412022-07-25 05:52:14 +00001
lh7b0674a2022-01-10 00:34:35 -08002#include <stdio.h>
3#include <sys/types.h>
4#include <sys/socket.h>
5#include <arpa/inet.h>
6#include <fcntl.h>
7#include <string.h>
8#include <stdlib.h>
9#include <unistd.h>
10#include <binder/Parcel.h>
11#include <log/log.h>
lh7b0674a2022-01-10 00:34:35 -080012#include <cutils/jstring.h>
13#include <pthread.h>
14#include "liblog/lynq_deflog.h"
lh2afc7732022-01-10 02:24:31 -080015#include <sys/time.h>
lh21502f52022-01-27 00:27:12 -080016#include <string.h>
q.huang714145d2022-04-18 00:09:50 -040017#include <vendor-ril/telephony/ril.h>
18#include <vendor-ril/telephony/mtk_ril_sp.h>
19#include <vendor-ril/telephony/mtk_ril_ivt.h>
20#include "lynq_call.h"
q.huang52921662022-10-20 15:25:45 +080021#include "lynq_module_common.h"
22#include "lynq_module_socket.h"
23#include "lynq_call_common.h"
q.huang714145d2022-04-18 00:09:50 -040024
q.huang52921662022-10-20 15:25:45 +080025#define CALL_OFF (0)
26#define CALL_ON (1)
lh7b0674a2022-01-10 00:34:35 -080027#define USER_LOG_TAG "LYNQ_CALL"
28
lh3b6f7ea2023-11-08 01:16:42 -080029#define AP_SPEECH "/tmp/ap_speech"
30#define AUDIO_CTRL_SER "/tmp/audio_ctrl_service"
31#define LIBMODEM_AFE "/tmp/libmodem-afe-ctrl"
32#define TELE_DEMO_LOCK "/tmp/tel_demo_single_proc.lock"
33
lh7b0674a2022-01-10 00:34:35 -080034using ::android::Parcel;
q.huang52921662022-10-20 15:25:45 +080035
36/**
37 * @brief mark call initialization state
38 * 0: deinit state
39 * 1: init state
40 */
41int g_module_init_flag = 0;
42
lh7b0674a2022-01-10 00:34:35 -080043 typedef enum {
44 LYNQ_CALL_ACTIVE = 0,
45 LYNQ_CALL_HOLDING = 1,
46 LYNQ_CALL_DIALING = 2, /* MO call only */
47 LYNQ_CALL_ALERTING = 3, /* MO call only */
48 LYNQ_CALL_INCOMING = 4, /* MT call only */
lhe45b7002022-04-26 00:45:44 -070049 LYNQ_CALL_WAITING = 5, /* MT call only */
50 /*warren add for T800 platform 2022/04/26 start*/
51 LYNQ_CALL_END = 6, /*CALL END*/
52 /*warren add for T800 platform 2022/04/26 end*/
lh7b0674a2022-01-10 00:34:35 -080053}lynq_call_state_t;
54
lh7b0674a2022-01-10 00:34:35 -080055typedef struct
56{
57 int used;
58 int call_id;
59 int call_state;
60 int toa;
61 int direction;/*0: MO call,1:MT call*/
62 char addr[LYNQ_PHONE_NUMBER_MAX];
lh7b0674a2022-01-10 00:34:35 -080063}lynq_call_list_e_t;
64typedef struct
65{
66 int call_id;
67 int call_state;
68 int toa;
69 int direction;/*0: MO call,1:MT call*/
70 char addr[LYNQ_PHONE_NUMBER_MAX];
71}lynq_call_list_t;
72
q.huang52921662022-10-20 15:25:45 +080073static lynq_call_list_e_t s_call_lists[LYNQ_CALL_MAX]={};
74static bool s_call_list_loop = 0;
75static pthread_t s_call_list_loop_tid = -1;
76static pthread_mutex_t s_notice_get_call_list_mutex = PTHREAD_MUTEX_INITIALIZER;
77static pthread_cond_t s_notice_get_call_list_cond = PTHREAD_COND_INITIALIZER;
78
79static int s_module_isDial = 0;
lh7b0674a2022-01-10 00:34:35 -080080static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
81static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
llb3921072023-01-10 14:47:46 +080082static int s_CallId = 0;
83static pthread_mutex_t s_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
84static pthread_cond_t s_call_state_change_cond = PTHREAD_COND_INITIALIZER;
lhec17b0a2022-02-13 23:56:05 -080085
q.huang52921662022-10-20 15:25:45 +080086static int s_module_call_state =CALL_OFF;
87static int s_call_auto_answer = 0;
lh7b0674a2022-01-10 00:34:35 -080088
q.huangec88da92022-03-29 04:17:32 -040089typedef enum{
90 LYNQ_E_VOLUMN_SET_DTMF,
91 LYNQ_E_VOLUMN_SET_SPEECH
q.huang52921662022-10-20 15:25:45 +080092}LYNQ_E_VOLUMN_SET;
lh7b0674a2022-01-10 00:34:35 -080093
q.huang52921662022-10-20 15:25:45 +080094#if 0
q.huang7de1d662022-09-13 14:19:24 +080095int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
lh7b0674a2022-01-10 00:34:35 -080096{
97 if(p.dataAvail() > 0)
98 {
99 p.readInt32(resp_type);
q.huang7de1d662022-09-13 14:19:24 +0800100 p.readInt32(token);
lh7b0674a2022-01-10 00:34:35 -0800101 p.readInt32(request);
102 p.readInt32(slot_id);
103 p.readInt32(error);
104 return 0;
105 }
106 else
107 {
108 return -1;
109 }
110}
111int send_request(int sockfd,lynq_client_t *client_tmp)
112{
113 int ret=0;
rjw5d2a50e2022-02-28 15:01:49 +0800114 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800115 if(ret==-1)
116 {
q.huang70b76492022-06-02 14:49:02 +0800117 LYERRLOG("sendto error");
lh7b0674a2022-01-10 00:34:35 -0800118 return -1;
119 }
120 return 0;
121}
122
123int get_response(int sockfd,Parcel &p)
124{
125 int len = 0;
126 char recvline[LYNQ_REC_BUF];
127 bzero(recvline,LYNQ_REC_BUF);
128 /* receive data from server */
rjw5d2a50e2022-02-28 15:01:49 +0800129 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800130 if(len == -1)
131 {
q.huang70b76492022-06-02 14:49:02 +0800132 LYERRLOG("recvfrom error");
lh7b0674a2022-01-10 00:34:35 -0800133 return -1;
134 }
lh7b0674a2022-01-10 00:34:35 -0800135 if (recvline != NULL) {
136 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
137 p.setDataPosition(0);
138 }
139 return 0;
140}
q.huang52921662022-10-20 15:25:45 +0800141#endif
142static char *strdupReadString(Parcel* &p) {
ll04ae4142022-01-27 05:54:38 +0000143 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800144 const char16_t *s16;
q.huang52921662022-10-20 15:25:45 +0800145 s16 = p->readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000146 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800147}
148
149int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
150{
q.huang52921662022-10-20 15:25:45 +0800151 Parcel* p=NULL;
152 int ret=lynq_send_common_request(p,8,RIL_REQUEST_GET_CURRENT_CALLS,0,"");
153 if(ret!=0)
154 {
155 return ret;
156 }
157
158 int call_num = 0;
159 int temp = 0;
160 char *remote_phoneNum;
161 char *remote_name;
162 char uusData[128];
163
164 p->readInt32(&call_num);
165
166 if(call_num<=0)
167 {
168 s_module_call_state = CALL_OFF;
169 LYINFLOG("lynq_call_state:%d",s_module_call_state);
170 delete p;
171 return RESULT_OK;
172 }
173 s_module_call_state = CALL_ON;
174 LYINFLOG("lynq_call_state:%d, call num is %d ",s_module_call_state,call_num);
175 for(int i = 0;i < call_num;i++)
176 {
177 p->readInt32(&temp);
178 call_list[i].call_state = temp;
179 p->readInt32(&call_list[i].call_id);
180 p->readInt32(&call_list[i].toa);
181 p->readInt32(&temp);
182 p->readInt32(&temp);
183 call_list[i].direction = temp;
184 p->readInt32(&temp);
185 p->readInt32(&temp);
186 p->readInt32(&temp);
187 remote_phoneNum = strdupReadString(p);
188 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
189 if(remote_phoneNum !=NULL)
190 {
191 free(remote_phoneNum);
192 }
193 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
194 call_list[i].direction,call_list[i].addr,call_list[i].toa);
195 p->readInt32(&temp);
196 remote_name = strdupReadString(p);
197 if(remote_name !=NULL)
198 {
199 free(remote_name);
200 }
201 p->readInt32(&temp);
202 p->readInt32(&temp);
203 if(temp==0)
204 {
205 continue;
206 }
207 p->readInt32(&temp); /* UUS Information is present */
208 p->readInt32(&temp);
209 p->readInt32(&temp);
210 if(temp<=128)
211 {
212 p->read(uusData,temp);
213 }
214 else
215 {
216 LYERRLOG("%s len %d is too great",__func__,temp);
217 delete p;
218 return LYNQ_E_MALLOC_ERROR;
219 }
220 }
221
222 delete p;
223 return RESULT_OK;
224
225#if 0
lh7b0674a2022-01-10 00:34:35 -0800226 Parcel p;
227 lynq_client_t client;
228 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800229 int token;
lh7b0674a2022-01-10 00:34:35 -0800230 int request = -1;
231 int slot_id = -1;
232 int error = -1;
233 int call_num = 0;
234 int temp = 0;
235 char *remote_phoneNum = NULL;
236 char *remote_name= NULL;
237 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800238 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800239 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
240 client.paramLen = 0;
241 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang70b76492022-06-02 14:49:02 +0800242 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800243 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800244 {
245 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800246 return -1;
247 }
lh42c1e572022-01-25 18:47:39 -0800248 get_response(lynq_call_client_sockfd,p);
q.huang7de1d662022-09-13 14:19:24 +0800249 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh7b0674a2022-01-10 00:34:35 -0800250 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
251 if(error == 0)
252 {
253 p.readInt32(&call_num);
254 global_call_count = call_num;
255 if(call_num<=0)
256 {
257 lynq_call_state = CALL_OFF;
lhec17b0a2022-02-13 23:56:05 -0800258 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800259 return 0;
260 }
lhec17b0a2022-02-13 23:56:05 -0800261 lynq_call_state = CALL_ON;
q.huang70b76492022-06-02 14:49:02 +0800262 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh7b0674a2022-01-10 00:34:35 -0800263 for(int i = 0;i < call_num;i++)
264 {
265 p.readInt32(&temp);
266 call_list[i].call_state = temp;
267 p.readInt32(&call_list[i].call_id);
268 p.readInt32(&call_list[i].toa);
269 p.readInt32(&temp);
270 p.readInt32(&temp);
271 call_list[i].direction = temp;
272 p.readInt32(&temp);
273 p.readInt32(&temp);
274 p.readInt32(&temp);
275 remote_phoneNum = strdupReadString(p);
276 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
277 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
278 call_list[i].direction,call_list[i].addr,call_list[i].toa);
279 p.readInt32(&temp);
280 remote_name = strdupReadString(p);
281 p.readInt32(&temp);
282 p.readInt32(&temp);
283 if(temp==0)
284 {
285 continue;
286 }
287 p.readInt32(&temp); /* UUS Information is present */
288 p.readInt32(&temp);
289 p.readInt32(&temp);
290 p.read(uusData,temp);
291 }
292 }
293 return 0;
q.huang52921662022-10-20 15:25:45 +0800294#endif
lh7b0674a2022-01-10 00:34:35 -0800295}
296
297void cleanCallList(int lynq_call_id)
298{
q.huang52921662022-10-20 15:25:45 +0800299 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
300 s_call_lists[lynq_call_id].call_id = 0;
301 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
302 s_call_lists[lynq_call_id].toa = 0;
303 s_call_lists[lynq_call_id].direction = 0;
304 s_call_lists[lynq_call_id].used = 0;
305 memset(s_call_lists[lynq_call_id].addr,0,sizeof(s_call_lists[lynq_call_id].addr));
lh7b0674a2022-01-10 00:34:35 -0800306}
llb3921072023-01-10 14:47:46 +0800307
308
lh7b0674a2022-01-10 00:34:35 -0800309int getUnusedElement()
310{
311 for(int i=0;i < LYNQ_CALL_MAX; i++)
312 {
q.huang52921662022-10-20 15:25:45 +0800313 if(s_call_lists[i].used!=1)
lh7b0674a2022-01-10 00:34:35 -0800314 {
315 return i;
316 }
317 }
q.huang52921662022-10-20 15:25:45 +0800318 return INVALID_ID;
lh7b0674a2022-01-10 00:34:35 -0800319}
q.huang52921662022-10-20 15:25:45 +0800320int addAddr(char addr[], int call_id)
lh7b0674a2022-01-10 00:34:35 -0800321{
322 int ret = 0;
323 ret = getUnusedElement();
q.huang52921662022-10-20 15:25:45 +0800324 memcpy(s_call_lists[ret].addr,addr,strlen(addr)+1);
325 s_call_lists[ret].call_id=call_id;
326 s_call_lists[ret].used = 1;
q.huang70b76492022-06-02 14:49:02 +0800327 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh7b0674a2022-01-10 00:34:35 -0800328 return ret;
329}
330void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
331{
q.huang70b76492022-06-02 14:49:02 +0800332 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh7b0674a2022-01-10 00:34:35 -0800333 callList->call_id = call_id;
334 callList->call_state = call_state;
335 callList->toa = toa;
q.huang70b76492022-06-02 14:49:02 +0800336 callList->direction = direction;
lh7b0674a2022-01-10 00:34:35 -0800337 return;
338}
llb3921072023-01-10 14:47:46 +0800339
340void wait_call_state()
lh7b0674a2022-01-10 00:34:35 -0800341{
llb3921072023-01-10 14:47:46 +0800342 LYINFLOG("call state changed");
343 pthread_mutex_lock(&s_call_state_change_mutex);
344 pthread_cond_wait(&s_call_state_change_cond,&s_call_state_change_mutex);
345 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800346}
llb3921072023-01-10 14:47:46 +0800347
lh7b0674a2022-01-10 00:34:35 -0800348int checkHasCall(char addr[])
349{
350 for(int i = 0;i<LYNQ_CALL_MAX;i++)
351 {
q.huang52921662022-10-20 15:25:45 +0800352 if(strcmp(s_call_lists[i].addr,addr)==0)
lh7b0674a2022-01-10 00:34:35 -0800353 {
q.huang52921662022-10-20 15:25:45 +0800354 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,s_call_lists[i].call_id);
355 return true;
lh7b0674a2022-01-10 00:34:35 -0800356 }
357 }
q.huang70b76492022-06-02 14:49:02 +0800358 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
q.huang52921662022-10-20 15:25:45 +0800359 return false;
lh7b0674a2022-01-10 00:34:35 -0800360}
lhd1e457c2022-04-19 06:01:25 -0700361int find_call_id_with_addr(char *addr)
362{
lhd1e457c2022-04-19 06:01:25 -0700363 for(int id = 0; id < LYNQ_CALL_MAX; id++)
364 {
q.huang52921662022-10-20 15:25:45 +0800365 if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
lhd1e457c2022-04-19 06:01:25 -0700366 {
q.huang52921662022-10-20 15:25:45 +0800367 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 -0700368 return id;
369 }
370 }
q.huang70b76492022-06-02 14:49:02 +0800371 LYINFLOG("find addr %s in local list , not found",addr);
q.huang52921662022-10-20 15:25:45 +0800372 return INVALID_ID;
lhd1e457c2022-04-19 06:01:25 -0700373}
q.huang70b76492022-06-02 14:49:02 +0800374int find_call_id_with_call_id(int call_id)
375{
376 for(int id = 0; id < LYNQ_CALL_MAX; id++)
377 {
q.huang52921662022-10-20 15:25:45 +0800378 if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
q.huang70b76492022-06-02 14:49:02 +0800379 {
q.huang52921662022-10-20 15:25:45 +0800380 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 +0800381 return id;
382 }
383 }
384 LYINFLOG("find id %d in local list , not found",call_id);
385 return INVALID_ID;
386}
lh7b0674a2022-01-10 00:34:35 -0800387void sendSignalToWaitCallStateChange()
388{
lhd1e457c2022-04-19 06:01:25 -0700389 LYINFLOG("send Signal To Wait Call State Change");
lh7b0674a2022-01-10 00:34:35 -0800390 pthread_mutex_lock(&call_state_change_mutex);
391 pthread_cond_signal(&call_state_change_cond);
392 pthread_mutex_unlock(&call_state_change_mutex);
393}
you.chen79d8f932023-12-26 17:03:44 +0800394void send_call_state_change(int callid)
lh7b0674a2022-01-10 00:34:35 -0800395{
llb3921072023-01-10 14:47:46 +0800396 LYINFLOG("send call state change");
you.chen79d8f932023-12-26 17:03:44 +0800397 s_CallId = callid;
llb3921072023-01-10 14:47:46 +0800398 pthread_mutex_lock(&s_call_state_change_mutex);
399 pthread_cond_signal(&s_call_state_change_cond);
400 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800401}
402
q.huang52921662022-10-20 15:25:45 +0800403void cleanup_call_list_mutex(void *arg)
lh7b0674a2022-01-10 00:34:35 -0800404{
q.huang52921662022-10-20 15:25:45 +0800405 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
lh7b0674a2022-01-10 00:34:35 -0800406}
llb3921072023-01-10 14:47:46 +0800407
408void update_end_state(int lynq_call_id)
409{
410 LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
411 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
412}
413
lh7b0674a2022-01-10 00:34:35 -0800414void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000415{
416 int ret=0;
lhd1e457c2022-04-19 06:01:25 -0700417 bool call_end;
ll04ae4142022-01-27 05:54:38 +0000418 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang8b33ed52022-04-19 20:27:44 -0400419 int update=0;
q.huang70b76492022-06-02 14:49:02 +0800420 int cnt;
421 int i,n;
q.huange97cfcf2022-08-29 20:04:31 +0800422#ifdef ECALL_SUPPORT
423 int handupIncomingMT=0;
424#endif
q.huang52921662022-10-20 15:25:45 +0800425 pthread_mutex_lock(&s_notice_get_call_list_mutex);
426 pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
you.chen79d8f932023-12-26 17:03:44 +0800427 int tmp_call_id;
q.huang52921662022-10-20 15:25:45 +0800428 while(s_call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000429 {
q.huang52921662022-10-20 15:25:45 +0800430 update=0;
431 pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
you.chen79d8f932023-12-26 17:03:44 +0800432 LYINFLOG("triggerGetCallList event %p!!!", pthread_self());
ll04ae4142022-01-27 05:54:38 +0000433 memset(call_list,0,sizeof(call_list));
434 ret = lynq_get_current_call_list(call_list);
q.huang52921662022-10-20 15:25:45 +0800435 if(ret != RESULT_OK)
ll04ae4142022-01-27 05:54:38 +0000436 {
you.chen79d8f932023-12-26 17:03:44 +0800437 LYERRLOG("get current call list failure!!!");
llbc035332022-04-11 05:49:51 +0000438 continue;
ll04ae4142022-01-27 05:54:38 +0000439 }
lhd1e457c2022-04-19 06:01:25 -0700440 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huang70b76492022-06-02 14:49:02 +0800441 LYINFLOG("clear local index begin");
442 cnt=0;
443 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh7b0674a2022-01-10 00:34:35 -0800444 {
q.huang52921662022-10-20 15:25:45 +0800445 if(s_call_lists[i].used ==0)
q.huang70b76492022-06-02 14:49:02 +0800446 {
447 continue;
448 }
449 cnt++;
q.huang52921662022-10-20 15:25:45 +0800450 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 +0800451
q.huang52921662022-10-20 15:25:45 +0800452 if(s_call_lists[i].call_id > 0)
lhd1e457c2022-04-19 06:01:25 -0700453 {
454 call_end = 0;
q.huang70b76492022-06-02 14:49:02 +0800455 for(n = 0; n < LYNQ_CALL_MAX; n++)
lhd1e457c2022-04-19 06:01:25 -0700456 {
q.huang52921662022-10-20 15:25:45 +0800457 if(call_list[n].call_id == s_call_lists[i].call_id)
lhd1e457c2022-04-19 06:01:25 -0700458 {
459 call_end = 1;
q.huang52921662022-10-20 15:25:45 +0800460 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 +0800461 break;
lhd1e457c2022-04-19 06:01:25 -0700462 }
463 }
464 if(call_end == 0)
465 {
llb3921072023-01-10 14:47:46 +0800466 LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
467 //update_end_state(i);//lei modify for:update end state for this call
you.chen79d8f932023-12-26 17:03:44 +0800468 tmp_call_id = s_call_lists[i].call_id;
llb3921072023-01-10 14:47:46 +0800469 cleanCallList(i);
you.chen79d8f932023-12-26 17:03:44 +0800470 //Release the end handle
471 send_call_state_change(tmp_call_id);//means mt/mo call is end
llb3921072023-01-10 14:47:46 +0800472 //cleanCallList(i);
lhd1e457c2022-04-19 06:01:25 -0700473 }
474 } //fix bug API-54
q.huang70b76492022-06-02 14:49:02 +0800475 else
476 {
477 LYINFLOG("local id is 0");
478 }
479 }
480 LYINFLOG("clear local index end, local used cnt is %d", cnt);
481
482 LYINFLOG("add or update local index begin ");
483 for (i = 0;i < LYNQ_CALL_MAX;i++)
484 {
485 if(call_list[i].call_id==0)
486 {
487 break;
488 }
489
490 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,
491 call_list[i].direction,call_list[i].addr,call_list[i].toa);
492
lh7b0674a2022-01-10 00:34:35 -0800493 if(call_list[i].direction == 1)//MT call
494 {
q.huang70b76492022-06-02 14:49:02 +0800495 LYINFLOG("This is a MT CALL");
lh0fd3b012022-05-13 03:02:19 -0700496 /*MT CALL state code
497 **LYNQ_CALL_INCOMING = 4,
498 **LYNQ_CALL_WAITING = 5,
499 */
q.huange97cfcf2022-08-29 20:04:31 +0800500#ifdef ECALL_SUPPORT
lh0fd3b012022-05-13 03:02:19 -0700501 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh7b0674a2022-01-10 00:34:35 -0800502 {
q.huang52921662022-10-20 15:25:45 +0800503 handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
q.huange97cfcf2022-08-29 20:04:31 +0800504 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
505 if(handupIncomingMT)
lh7b0674a2022-01-10 00:34:35 -0800506 {
q.huang70b76492022-06-02 14:49:02 +0800507 lynq_call_hungup(&(call_list[i].call_id));
508 continue;
q.huange97cfcf2022-08-29 20:04:31 +0800509 }
q.huang70b76492022-06-02 14:49:02 +0800510 }
q.huange97cfcf2022-08-29 20:04:31 +0800511#endif
q.huang70b76492022-06-02 14:49:02 +0800512 /*you call me, and i call you,One party failed to dial*/
513 n = find_call_id_with_addr(call_list[i].addr);
514 if(n ==INVALID_ID)
515 {
q.huang52921662022-10-20 15:25:45 +0800516 n = addAddr(call_list[i].addr,call_list[i].call_id);
517 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 +0800518 send_call_state_change(call_list[i].call_id);
q.huang70b76492022-06-02 14:49:02 +0800519 }
q.huang52921662022-10-20 15:25:45 +0800520 else if(s_call_lists[n].call_state == call_list[i].call_state)
q.huang70b76492022-06-02 14:49:02 +0800521 {
522 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
523 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lhd1e457c2022-04-19 06:01:25 -0700524 {
lhd1e457c2022-04-19 06:01:25 -0700525 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
526 **an incoming call until the status changes.
527 **fix bug API-54
528 */
q.huang70b76492022-06-02 14:49:02 +0800529 LYINFLOG("resend incoming call signal");
you.chen79d8f932023-12-26 17:03:44 +0800530 send_call_state_change(call_list[i].call_id);
lhd1e457c2022-04-19 06:01:25 -0700531 }
lh7b0674a2022-01-10 00:34:35 -0800532 }
q.huang70b76492022-06-02 14:49:02 +0800533 else
ll72bf6c12022-03-24 10:22:25 +0800534 {
q.huang52921662022-10-20 15:25:45 +0800535 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 +0800536
llb3921072023-01-10 14:47:46 +0800537 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 +0800538 send_call_state_change(call_list[i].call_id);
llb3921072023-01-10 14:47:46 +0800539 }
lh7b0674a2022-01-10 00:34:35 -0800540 }
541 else
q.huang70b76492022-06-02 14:49:02 +0800542 {
543 LYINFLOG("This is a MO CALL");
544 call_end = 0;
545 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh7b0674a2022-01-10 00:34:35 -0800546 {
q.huang52921662022-10-20 15:25:45 +0800547 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 -0800548 {
q.huang52921662022-10-20 15:25:45 +0800549 if(s_call_lists[n].call_id==0)
q.huang70b76492022-06-02 14:49:02 +0800550 {
llb3921072023-01-10 14:47:46 +0800551 LYINFLOG("add a call id");
552 update=1;//for send sigal
q.huang70b76492022-06-02 14:49:02 +0800553 }
q.huang52921662022-10-20 15:25:45 +0800554 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);
555 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 +0800556 call_end = 1;
you.chen79d8f932023-12-26 17:03:44 +0800557 send_call_state_change(call_list[i].call_id);//means mo call is success
q.huang70b76492022-06-02 14:49:02 +0800558 break;
559 }
560 }
llb3921072023-01-10 14:47:46 +0800561 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 +0800562 {
563 LYINFLOG("need to hangup id %d", call_list[i].call_id);
564#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +0800565 if(IsECallDialing())
q.huang70b76492022-06-02 14:49:02 +0800566 {
567 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh7b0674a2022-01-10 00:34:35 -0800568 continue;
569 }
q.huang70b76492022-06-02 14:49:02 +0800570#endif
571 LYINFLOG("hang up service call id %d",call_list[i].call_id);
572 lynq_call_hungup(&(call_list[i].call_id));
lh7b0674a2022-01-10 00:34:35 -0800573 }
llb3921072023-01-10 14:47:46 +0800574
lh7b0674a2022-01-10 00:34:35 -0800575 }
q.huang70b76492022-06-02 14:49:02 +0800576 LYDBGLOG("servie idx %d end",i);
ll04ae4142022-01-27 05:54:38 +0000577 }
q.huang52921662022-10-20 15:25:45 +0800578 LYINFLOG("add or update local index end ");
579 if(s_module_isDial==1)
lh7b0674a2022-01-10 00:34:35 -0800580 {
q.huang70b76492022-06-02 14:49:02 +0800581 LYINFLOG("now is dialing");
582 if(update==1)
583 {
584 LYINFLOG("find added call");
585 sendSignalToWaitCallStateChange();
q.huang52921662022-10-20 15:25:45 +0800586 s_module_isDial = 0;
q.huang70b76492022-06-02 14:49:02 +0800587 }
588 else
589 {
590 LYINFLOG("not find added call");
591 }
592 }
593 else
594 {
595 LYINFLOG("now is not dialing");
q.huang52921662022-10-20 15:25:45 +0800596 }
ll04ae4142022-01-27 05:54:38 +0000597 }
q.huang52921662022-10-20 15:25:45 +0800598 pthread_cleanup_pop(0);
599 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
ll04ae4142022-01-27 05:54:38 +0000600 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800601}
602
q.huang52921662022-10-20 15:25:45 +0800603void lynqNoticeGetModuleCallList()
ll04ae4142022-01-27 05:54:38 +0000604{
you.chen79d8f932023-12-26 17:03:44 +0800605 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send start");
q.huang52921662022-10-20 15:25:45 +0800606 pthread_mutex_lock(&s_notice_get_call_list_mutex);
607 pthread_cond_signal(&s_notice_get_call_list_cond);
608 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
you.chen79d8f932023-12-26 17:03:44 +0800609 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send end");
lh7b0674a2022-01-10 00:34:35 -0800610}
611
q.huang52921662022-10-20 15:25:45 +0800612#if 0
lh7b0674a2022-01-10 00:34:35 -0800613/*Warren add for T800 platform 2021/11/19 start*/
614int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800615{
616 #if 0
lh7b0674a2022-01-10 00:34:35 -0800617 struct sockaddr_in lynq_socket_server_addr;
618 /* init lynq_socket_server_addr */
619 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
620 lynq_socket_server_addr.sin_family = AF_INET;
621 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
622 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800623
lh7b0674a2022-01-10 00:34:35 -0800624 /*
625 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
626 {
q.huang70b76492022-06-02 14:49:02 +0800627 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800628 exit(1);
629 }
630*/
lh42c1e572022-01-25 18:47:39 -0800631 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
632 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800633 {
q.huang70b76492022-06-02 14:49:02 +0800634 LYERRLOG("connect error");
lh7b0674a2022-01-10 00:34:35 -0800635 return -1;
636 }
rjw5d2a50e2022-02-28 15:01:49 +0800637 #endif
638 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
639 if (-1 == lynq_call_client_sockfd)
640 {
641 return lynq_call_client_sockfd;
642 }
ll630be412022-07-25 05:52:14 +0000643 struct timeval timeOut;
644 timeOut.tv_sec = 60;
645 timeOut.tv_usec = 0;
646 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
647 {
648 RLOGD("time out setting failed\n");
649 return -1;
650 }
rjw5d2a50e2022-02-28 15:01:49 +0800651 /* 设置address */
652 memset(&addr_serv, 0, sizeof(addr_serv));
653 addr_serv.sin_family = AF_INET;
654 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
655 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
656 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800657 return 0;
658}
lh7b0674a2022-01-10 00:34:35 -0800659
lh7b0674a2022-01-10 00:34:35 -0800660int lynq_socket_urc_start()
661{
662 int socket_fd=0;
663 int rt=0;
664 int len=0;
665 int on=1;
666 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800667 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000668 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000669 if(socket_fd < 0)
670 {
q.huang70b76492022-06-02 14:49:02 +0800671 LYERRLOG("creaet socket for udp fail");
ll04ae4142022-01-27 05:54:38 +0000672 return -1;
lh7b0674a2022-01-10 00:34:35 -0800673 }
674 urc_local_addr.sin_family = AF_INET;
675 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
676 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
677 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000678 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
679 if(rt<0)
680 {
q.huang70b76492022-06-02 14:49:02 +0800681 LYERRLOG("SO_REUSEADDR fail");
lh7b0674a2022-01-10 00:34:35 -0800682 return -1;
683 }
684 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000685 if (rt == -1)
686 {
lh21502f52022-01-27 00:27:12 -0800687 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000688 return -1;
lh7b0674a2022-01-10 00:34:35 -0800689 }
690 pthread_attr_init(&attr);
691 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800692 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800693 if(rt < 0)
694 {
q.huang70b76492022-06-02 14:49:02 +0800695 LYERRLOG("urc loop failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800696 return -1;
697 }
q.huang70b76492022-06-02 14:49:02 +0800698 LYDBGLOG("urc loop success!!!");
lh7b0674a2022-01-10 00:34:35 -0800699 return 0;
700}
q.huang52921662022-10-20 15:25:45 +0800701#endif
lh7b0674a2022-01-10 00:34:35 -0800702
703void lynq_call_state_change_test(int soc_id)
704{
q.huang70b76492022-06-02 14:49:02 +0800705 LYDBGLOG("call state change,sim:%d",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800706}
q.huangcb7b7292022-06-28 20:12:01 +0800707
q.huang52921662022-10-20 15:25:45 +0800708int lynq_start_call_list_loop()
709{
710#if 0
711 int ret = 0;
712 pthread_attr_t attr;
713 pthread_attr_init(&attr);
714 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
q.huangcb7b7292022-06-28 20:12:01 +0800715
q.huang52921662022-10-20 15:25:45 +0800716 s_notice_get_call_list_mutex = new pthread_mutex_t;
717 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
718 s_notice_get_call_list_cond = new pthread_cond_t;
719 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
720 pthread_cond_init(s_notice_get_call_list_cond, NULL);
721 LYINFLOG("liulei s_notice_get_call_list_cond\n");
722#endif
q.huangcb7b7292022-06-28 20:12:01 +0800723
q.huang52921662022-10-20 15:25:45 +0800724 s_call_list_loop = 1;
725 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
726 if(ret < 0)
q.huangcb7b7292022-06-28 20:12:01 +0800727 {
q.huang52921662022-10-20 15:25:45 +0800728 LYERRLOG("lynq_update_call_list_loop fail!!!");
lla8c25a82022-03-17 05:31:33 +0000729 return -1;
730 }
q.huang52921662022-10-20 15:25:45 +0800731 LYINFLOG("lynq_update_call_list_loop success!!!");
q.huangcb7b7292022-06-28 20:12:01 +0800732
q.huang52921662022-10-20 15:25:45 +0800733 memset(s_call_lists,0,sizeof(s_call_lists));
lh7b0674a2022-01-10 00:34:35 -0800734 return 0;
735}
q.huang52921662022-10-20 15:25:45 +0800736
737int lynq_stop_call_list_loop()
lh7b0674a2022-01-10 00:34:35 -0800738{
q.huang70b76492022-06-02 14:49:02 +0800739 int ret;
q.huang52921662022-10-20 15:25:45 +0800740 pthread_mutex_lock(&s_notice_get_call_list_mutex);
741 s_call_list_loop = 0;
742 ret = pthread_cancel(s_call_list_loop_tid);
743 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
744 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
745 ret = pthread_join(s_call_list_loop_tid,NULL);
746 LYINFLOG("pthread join w_c_list ret = %d",ret);
747 s_call_list_loop_tid=-1;
748#if 0
749 pthread_mutex_destroy(s_notice_get_call_list_mutex);
750 pthread_cond_destroy(s_notice_get_call_list_cond);
751 delete s_notice_get_call_list_mutex;
752 //s_notice_get_call_list_mutex = NULL;
753 delete s_notice_get_call_list_cond;
754 //s_notice_get_call_list_cond = NULL;
755#endif
756
757 return 0;
rita98e2e9c2022-04-07 06:08:13 -0400758}
q.huang714145d2022-04-18 00:09:50 -0400759
q.huang52921662022-10-20 15:25:45 +0800760int lynq_init_call(int utoken){
q.huangf6a9ddc2023-12-08 20:23:56 +0800761
762 LYLOGSET(LOG_INFO);
763 LYLOGEINIT(USER_LOG_TAG);
764 LYERRLOG("%s start, parameter is %d", __func__,utoken);
765
q.huang52921662022-10-20 15:25:45 +0800766 if(g_module_init_flag != MODULE_CLOSED)
767 {
768 LYERRLOG("module state is %d",g_module_init_flag);
769 return LYNQ_E_CONFLICT;
770 }
771 if(utoken <0){
772 LYERRLOG("utoken is less than 0",utoken);
773 return LYNQ_E_PARAMETER_ANONALY;
774 }
775 g_module_init_flag = MODULE_SWITCHING;
q.huangf6a9ddc2023-12-08 20:23:56 +0800776
q.huang52921662022-10-20 15:25:45 +0800777
778 g_module_Global_uToken = utoken;
779
q.huang036b6cf2023-01-10 14:29:20 +0800780 int ret = lynq_start_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800781 if(ret != RESULT_OK)
782 {
783 LYERRLOG("init socket urc fail!!!");
784 g_module_init_flag = MODULE_CLOSED;
785 return LYNQ_E_INNER_ERROR;
786 }
787
q.huang036b6cf2023-01-10 14:29:20 +0800788 ret = lynq_start_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800789 if(ret !=RESULT_OK)
790 {
791 LYERRLOG("init socket client fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800792 lynq_close_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800793 g_module_init_flag = MODULE_CLOSED;
794 return LYNQ_E_INNER_ERROR;
795 }
796
797
798 int result = lynq_start_call_list_loop();
799 if(ret != RESULT_OK)
800 {
801 LYERRLOG("lynq_start_call_list_loop fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800802 lynq_close_all_urc_socket_thread();
803 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800804 g_module_init_flag = MODULE_CLOSED;
805 return LYNQ_E_INNER_ERROR;
806 }
807
q.huang52921662022-10-20 15:25:45 +0800808 g_module_init_flag = MODULE_RUNNING;
q.huangf6a9ddc2023-12-08 20:23:56 +0800809
810 LYERRLOG("%s end suc", __func__);
q.huang52921662022-10-20 15:25:45 +0800811 return 0;
812}
813
814int lynq_deinit_call(void){
q.huangf6a9ddc2023-12-08 20:23:56 +0800815 LYERRLOG("%s start", __func__);
q.huang52921662022-10-20 15:25:45 +0800816
817 if (g_module_init_flag != MODULE_RUNNING)
818 {
819 LYERRLOG("module state is %d",g_module_init_flag);
820 return LYNQ_E_CONFLICT;
821 }
822 lynq_call_hungup_all();
q.huang52921662022-10-20 15:25:45 +0800823 g_module_init_flag = MODULE_SWITCHING;
q.huang036b6cf2023-01-10 14:29:20 +0800824 lynq_close_all_urc_socket_thread();
825 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800826 lynq_stop_call_list_loop();
827 g_module_init_flag = MODULE_CLOSED;
q.huangf6a9ddc2023-12-08 20:23:56 +0800828
829 LYERRLOG("%s end suc", __func__);
q.huang52921662022-10-20 15:25:45 +0800830 return 0;
831}
832
833#if 0
q.huang714145d2022-04-18 00:09:50 -0400834int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400835{
836 Parcel p;
837 lynq_client_t client;
838 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800839 int token;
rita089527e2022-04-07 01:55:39 -0400840 int request = -1;
841 int slot_id = -1;
842 int error = -1;
rita089527e2022-04-07 01:55:39 -0400843
q.huang52921662022-10-20 15:25:45 +0800844 Parcel* p=NULL;
845 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
846 if(ret==RESULT_OK)
847 {
848 delete p;
849 }
850 return ret;
851
rita089527e2022-04-07 01:55:39 -0400852 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400853 client.request = request_id;
854 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400855 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400856 if(argc!=0)
857 {
858 va_list args;
859 va_start(args, format);
860 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
861 va_end(args);
862 }
q.huang70b76492022-06-02 14:49:02 +0800863 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400864 if(send_request(lynq_call_client_sockfd,&client)==-1)
865 {
866 LYERRLOG("send request fail");
867 return -1;
868 }
q.huang714145d2022-04-18 00:09:50 -0400869 if(get_response(lynq_call_client_sockfd,p)==0)
870 {
q.huang7de1d662022-09-13 14:19:24 +0800871 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang714145d2022-04-18 00:09:50 -0400872 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
873 }
rita089527e2022-04-07 01:55:39 -0400874 return error;
q.huang52921662022-10-20 15:25:45 +0800875
876
rita089527e2022-04-07 01:55:39 -0400877}
q.huang52921662022-10-20 15:25:45 +0800878#endif
rita089527e2022-04-07 01:55:39 -0400879
q.huang714145d2022-04-18 00:09:50 -0400880int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400881{
q.huang714145d2022-04-18 00:09:50 -0400882 if(status==NULL)
883 {
884 LYERRLOG("status is null");
q.huang52921662022-10-20 15:25:45 +0800885 return LYNQ_E_PARAMETER_ANONALY;
q.huang714145d2022-04-18 00:09:50 -0400886 }
q.huang52921662022-10-20 15:25:45 +0800887
888 Parcel* p=NULL;
889 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
890 if(ret==RESULT_OK)
rita089527e2022-04-07 01:55:39 -0400891 {
q.huang52921662022-10-20 15:25:45 +0800892 p->readInt32(status);
893 delete p;
rita089527e2022-04-07 01:55:39 -0400894 }
q.huang52921662022-10-20 15:25:45 +0800895 return ret;
896}
897
898int waitCallstateChange(int mtime)
899{
900 LYINFLOG("wait Call state Change");
901 int ret = 0;
902 int sec = 0;
you.chen79d8f932023-12-26 17:03:44 +0800903 int ms = 0;
q.huang52921662022-10-20 15:25:45 +0800904 struct timeval now;
905 struct timespec timeout;
906 gettimeofday(&now,NULL);
907 sec = mtime/1000;
you.chen79d8f932023-12-26 17:03:44 +0800908 ms = mtime%1000;
q.huang52921662022-10-20 15:25:45 +0800909 timeout.tv_sec = now.tv_sec+sec;
you.chen79d8f932023-12-26 17:03:44 +0800910 unsigned long long ns;
911 ns = now.tv_usec*1000ull + ms*1000000ull;
912 timeout.tv_sec += ns/1000000000;
913 timeout.tv_nsec = ns % 1000000000;
q.huang52921662022-10-20 15:25:45 +0800914 pthread_mutex_lock(&call_state_change_mutex);
915 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
916 pthread_mutex_unlock(&call_state_change_mutex);
917 return ret;
918}
919
920int IsNormalCallDailing()
921{
922 return s_module_isDial;
rita089527e2022-04-07 01:55:39 -0400923}
924
llb3921072023-01-10 14:47:46 +0800925
lh3b6f7ea2023-11-08 01:16:42 -0800926int check_file_access(const char *fileName)
927{
928 if(0 == access(fileName,F_OK))
929 {
930 LYINFLOG("find file %s success",fileName);
931 return 0;
932 }
933 LYERRLOG("find file %s fail",fileName);
934 return 1;
935}
936int try_reset_audio_service()
937{
938 //check files:audio-ctrl-service,libmodem-afe-service,speech_daemon
939 int ap_speech = 0;
940 int audio_ctrl_ser = 0;
941 int md_afe = 0;
942 int tele_demo_lock = 0;
943 LYINFLOG("try_reset_audio_service start");
944 ap_speech = check_file_access(AP_SPEECH);
945 audio_ctrl_ser = check_file_access(AUDIO_CTRL_SER);
946 md_afe = check_file_access(LIBMODEM_AFE);
947 tele_demo_lock = check_file_access(TELE_DEMO_LOCK);
948 if((ap_speech + audio_ctrl_ser + md_afe) > 0)
949 {
950 system("systemctl stop audio-ctrl-service");
951 system("systemctl stop speech_daemon");
952 system("systemctl stop libmodem_afe_service");
953 usleep(200000);//200ms
954 system("rm /tmp/audio_ctrl_service -rf");
955 system("rm /tmp/ap_speech -rf");
956 system("rm /tmp/libmodem-afe-ctrl -rf");
957 usleep(100000);//100ms
958 system("systemctl start libmodem_afe_service");
959 usleep(200000);//200ms
960 system("systemctl start speech_daemon");
961 usleep(200000);//200ms
962 system("systemctl start audio-ctrl-service");
963 sleep(1);//1s
964 LYERRLOG("reset audio relation service");
965 }
966 if(tele_demo_lock)
967 {
968 LYERRLOG("%s lose,why?",TELE_DEMO_LOCK);
969 }
970 return 0;
971}
972
lh7b0674a2022-01-10 00:34:35 -0800973int lynq_call(int* handle,char addr[])
974{
q.huang52921662022-10-20 15:25:45 +0800975 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700976 {
q.huang52921662022-10-20 15:25:45 +0800977 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
978 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -0700979 }
lh3b6f7ea2023-11-08 01:16:42 -0800980 try_reset_audio_service();
lh7b0674a2022-01-10 00:34:35 -0800981 int lynq_call_id = -1;
q.huang70b76492022-06-02 14:49:02 +0800982
983 LYINFLOG("lynq_call begin addr %s",addr);
lh7b0674a2022-01-10 00:34:35 -0800984 if(addr==NULL)
985 {
986 LYERRLOG("Phone num is null!!!");
q.huang52921662022-10-20 15:25:45 +0800987 return LYNQ_E_PARAMETER_ANONALY;
lh7b0674a2022-01-10 00:34:35 -0800988 }
q.huang70b76492022-06-02 14:49:02 +0800989
990 if(find_call_id_with_addr(addr)!=INVALID_ID)
991 {
992 LYERRLOG("addr %s exists",addr);
993 return LYNQ_E_CONFLICT;
994 }
995
996#ifdef ECALL_SUPPORT
997 if(lynq_ecall_is_running())
998 {
999 LYERRLOG("lynq_fast_ecall ecall is running");
1000 return LYNQ_E_ECALL_BEING_RUNNING;
1001 }
1002#endif
q.huang52921662022-10-20 15:25:45 +08001003 Parcel* p=NULL;
1004 lynq_call_id = addAddr(addr,0);
1005 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
1006 if(ret!=0)
1007 {
llb3921072023-01-10 14:47:46 +08001008 cleanCallList(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001009 return ret;
llb3921072023-01-10 14:47:46 +08001010 }
1011 delete p;
q.huang52921662022-10-20 15:25:45 +08001012 s_module_isDial = 1;
1013 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -08001014 {
q.huang52921662022-10-20 15:25:45 +08001015 //if timeout,this call need destroy.
1016 s_module_isDial = 0;
1017 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
llb3921072023-01-10 14:47:46 +08001018 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001019 send_call_state_change(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001020 return LYNQ_E_TIME_OUT;
lh7b0674a2022-01-10 00:34:35 -08001021 }
q.huang52921662022-10-20 15:25:45 +08001022 s_module_isDial = 0;
1023 *handle = s_call_lists[lynq_call_id].call_id;
1024 if(*handle > 0)
lh7b0674a2022-01-10 00:34:35 -08001025 {
q.huang52921662022-10-20 15:25:45 +08001026 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
1027 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001028 }
q.huang52921662022-10-20 15:25:45 +08001029 else
1030 {
1031 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
lle3b9a232023-01-14 13:21:20 +08001032 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001033 send_call_state_change(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +08001034 return LYNQ_E_INVALID_ID_ANONALY;
llb3921072023-01-10 14:47:46 +08001035 }
lh7b0674a2022-01-10 00:34:35 -08001036}
llb3921072023-01-10 14:47:46 +08001037
lh7b0674a2022-01-10 00:34:35 -08001038int lynq_call_answer()
1039{
q.huang52921662022-10-20 15:25:45 +08001040 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001041 {
q.huang52921662022-10-20 15:25:45 +08001042 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1043 return LYNQ_E_CONFLICT;
1044 }
1045
1046 Parcel* p=NULL;
1047 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
1048 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001049 {
q.huang52921662022-10-20 15:25:45 +08001050 delete p;
1051 }
1052 return ret;
lh7b0674a2022-01-10 00:34:35 -08001053}
llb3921072023-01-10 14:47:46 +08001054
lh7b0674a2022-01-10 00:34:35 -08001055int lynq_call_hungup(int* handle)
1056{
q.huang52921662022-10-20 15:25:45 +08001057 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001058 {
q.huang52921662022-10-20 15:25:45 +08001059 return LYNQ_E_CONFLICT;
1060 }
1061
lh42c1e572022-01-25 18:47:39 -08001062 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1063 {
q.huang52921662022-10-20 15:25:45 +08001064 LYERRLOG("%s illegal input!!!!",__func__);
1065 return LYNQ_E_PARAMETER_ANONALY;
lh42c1e572022-01-25 18:47:39 -08001066 }
q.huang52921662022-10-20 15:25:45 +08001067
1068 int call_id = *handle;
1069 Parcel* p=NULL;
1070 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1071 if(ret!=0)
lh7b0674a2022-01-10 00:34:35 -08001072 {
q.huang52921662022-10-20 15:25:45 +08001073 return ret;
you.chen79d8f932023-12-26 17:03:44 +08001074 }
q.huang52921662022-10-20 15:25:45 +08001075 delete p;
1076
you.chen79d8f932023-12-26 17:03:44 +08001077 int lynq_call_id=find_call_id_with_call_id(call_id);
q.huang52921662022-10-20 15:25:45 +08001078 if(lynq_call_id!=INVALID_ID)
lh7b0674a2022-01-10 00:34:35 -08001079 {
you.chen79d8f932023-12-26 17:03:44 +08001080 //lei modify for API-857
q.huang52921662022-10-20 15:25:45 +08001081 cleanCallList(lynq_call_id);
you.chen79d8f932023-12-26 17:03:44 +08001082 send_call_state_change(call_id);
1083 }
1084 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001085}
1086int lynq_call_hungup_all()
1087{
q.huang52921662022-10-20 15:25:45 +08001088 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001089 {
q.huang52921662022-10-20 15:25:45 +08001090 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1091 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001092 }
q.huang52921662022-10-20 15:25:45 +08001093
1094 Parcel* p=NULL;
1095 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1096 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001097 {
q.huang52921662022-10-20 15:25:45 +08001098 delete p;
1099 }
1100 return ret;
lh7b0674a2022-01-10 00:34:35 -08001101}
llb3921072023-01-10 14:47:46 +08001102
1103int lynq_wait_call_state_change(int *handle)
lh7b0674a2022-01-10 00:34:35 -08001104{
q.huang52921662022-10-20 15:25:45 +08001105 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001106 {
q.huang52921662022-10-20 15:25:45 +08001107 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1108 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001109 }
llb3921072023-01-10 14:47:46 +08001110 wait_call_state();
1111 *handle = s_CallId;
1112 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1113 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001114}
1115
1116int lynq_set_auto_answercall(const int mode)
1117{
q.huang52921662022-10-20 15:25:45 +08001118 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001119 {
q.huang52921662022-10-20 15:25:45 +08001120 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1121 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001122 }
q.huang52921662022-10-20 15:25:45 +08001123 s_call_auto_answer = mode;
lh7b0674a2022-01-10 00:34:35 -08001124 LYINFLOG("auto answer call mode =%d",mode);
q.huang52921662022-10-20 15:25:45 +08001125 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001126}
llb3921072023-01-10 14:47:46 +08001127
1128int lynq_find_already_end()
1129{
1130 for(int i=0;i < LYNQ_CALL_MAX; i++)
1131 {
1132 if(s_call_lists[i].call_state == 6)
1133 {
1134 return 0;
1135 }
1136 }
1137 return INVALID_ID;
1138}
1139
q.huangec88da92022-03-29 04:17:32 -04001140int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1141{
q.huang52921662022-10-20 15:25:45 +08001142 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001143 {
q.huang52921662022-10-20 15:25:45 +08001144 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1145 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001146 }
q.huangec88da92022-03-29 04:17:32 -04001147 int lynq_call_id = 0;
q.huang70b76492022-06-02 14:49:02 +08001148 LYINFLOG("lynq_get_current_call_state begin ");
q.huangec88da92022-03-29 04:17:32 -04001149 if(handle==NULL)
1150 {
q.huang70b76492022-06-02 14:49:02 +08001151 LYERRLOG("handle is NULL");
q.huang52921662022-10-20 15:25:45 +08001152 return LYNQ_E_PARAMETER_ANONALY;
q.huangec88da92022-03-29 04:17:32 -04001153 }
you.chen79d8f932023-12-26 17:03:44 +08001154 if((*handle) <= 0)
1155 {
1156 LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);
1157 return LYNQ_E_INVALID_ID_ANONALY;
1158 }
llb3921072023-01-10 14:47:46 +08001159 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huang70b76492022-06-02 14:49:02 +08001160 lynq_call_id = find_call_id_with_call_id(*handle);
1161 if(lynq_call_id==INVALID_ID)
1162 {
llb3921072023-01-10 14:47:46 +08001163 //find end state
1164 if((*handle) >= 0)
1165 {
1166 *call_state = (int)LYNQ_CALL_END;
1167 return RESULT_OK;
1168 }
1169 else
1170 {
1171 return LYNQ_E_INVALID_ID_ANONALY;
1172 }
q.huang70b76492022-06-02 14:49:02 +08001173 }
q.huang52921662022-10-20 15:25:45 +08001174 *call_state = s_call_lists[lynq_call_id].call_state;
1175 *toa = s_call_lists[lynq_call_id].toa;
1176 *direction = s_call_lists[lynq_call_id].direction;
1177 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
llb3921072023-01-10 14:47:46 +08001178 return RESULT_OK;
q.huangec88da92022-03-29 04:17:32 -04001179}
1180
q.huange97cfcf2022-08-29 20:04:31 +08001181int lynq_get_current_call_number()
1182{
1183 int cnt=0;
1184 int i;
1185 for(i = 0;i < LYNQ_CALL_MAX;i++)
1186 {
q.huang52921662022-10-20 15:25:45 +08001187 if(s_call_lists[i].used !=0)
q.huange97cfcf2022-08-29 20:04:31 +08001188 {
1189 cnt++;
1190 }
1191 }
1192
1193 return cnt;
1194}
1195
q.huangec88da92022-03-29 04:17:32 -04001196/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001197static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001198 switch(enable){
1199 case 0:
q.huang52921662022-10-20 15:25:45 +08001200 return true;
llf512fa32022-02-14 08:58:16 +00001201 case 1:
q.huang52921662022-10-20 15:25:45 +08001202 return true;
llf512fa32022-02-14 08:58:16 +00001203 default:
q.huang52921662022-10-20 15:25:45 +08001204 return false;
lldc99c9b2022-01-24 12:16:22 +00001205 }
1206}
1207
lh7b0674a2022-01-10 00:34:35 -08001208int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001209{
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);
lldc99c9b2022-01-24 12:16:22 +00001213 return LYNQ_E_CONFLICT;
1214 }
q.huang52921662022-10-20 15:25:45 +08001215 if(!judge_mic(enable)){
1216 return LYNQ_E_PARAMETER_ANONALY;
1217 }
1218 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1219
1220 Parcel* p=NULL;
1221 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1222 if(ret==RESULT_OK)
1223 {
1224 delete p;
1225 }
1226 return ret;
q.huangec88da92022-03-29 04:17:32 -04001227}
1228int lynq_get_mute_mic(int *status)
1229{
q.huang52921662022-10-20 15:25:45 +08001230 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001231 {
q.huang52921662022-10-20 15:25:45 +08001232 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1233 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001234 }
q.huang52921662022-10-20 15:25:45 +08001235 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh7b0674a2022-01-10 00:34:35 -08001236}
ll72bf6c12022-03-24 10:22:25 +08001237
1238/**
1239 * @brief Check whether DTMF is valid
1240 *
1241 * @param callnum dtmf eg:0-9 * #
1242 * @return int
1243 */
1244static int judge_dtmf(const char callnum)
1245{
1246 if(callnum == '#')
1247 {
q.huang52921662022-10-20 15:25:45 +08001248 return true;
ll72bf6c12022-03-24 10:22:25 +08001249 }
1250 if(callnum == '*')
1251 {
q.huang52921662022-10-20 15:25:45 +08001252 return true;
ll72bf6c12022-03-24 10:22:25 +08001253 }
1254 if(callnum >= '0'&& callnum <= '9')
1255 {
q.huang52921662022-10-20 15:25:45 +08001256 return true;
ll72bf6c12022-03-24 10:22:25 +08001257 }
q.huang52921662022-10-20 15:25:45 +08001258 return false;
ll72bf6c12022-03-24 10:22:25 +08001259}
1260
ll209e6112022-07-20 09:30:19 +00001261int lynq_switch_waiting_or_holding_and_active(void)
1262{
q.huang52921662022-10-20 15:25:45 +08001263 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001264 {
q.huang52921662022-10-20 15:25:45 +08001265 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1266 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001267 }
q.huang52921662022-10-20 15:25:45 +08001268
1269 Parcel* p=NULL;
1270 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1271 if(ret==RESULT_OK)
1272 {
1273 delete p;
1274 }
1275 return ret;
1276
1277#if 0
ll209e6112022-07-20 09:30:19 +00001278 Parcel p;
1279 lynq_client_t client;
1280 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001281 int token;
ll209e6112022-07-20 09:30:19 +00001282 int request = -1;
1283 int slot_id = -1;
1284 int error = -1;
1285 client.uToken = Global_uToken_call;
1286 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1287 client.paramLen = 0;
1288 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1289 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001290 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001291 if(send_request(lynq_call_client_sockfd,&client)==-1)
1292 {
1293 LYERRLOG("send request fail");
1294 return -1;
1295 }
1296 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001297 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001298 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001299 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1300 return error;
q.huang52921662022-10-20 15:25:45 +08001301#endif
ll209e6112022-07-20 09:30:19 +00001302}
1303
1304int lynq_hangup_waiting_or_background(void)
1305{
q.huang52921662022-10-20 15:25:45 +08001306 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001307 {
q.huang52921662022-10-20 15:25:45 +08001308 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1309 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001310 }
q.huang52921662022-10-20 15:25:45 +08001311
1312 Parcel* p=NULL;
1313 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1314 if(ret==RESULT_OK)
1315 {
1316 delete p;
1317 }
1318 return ret;
1319#if 0
ll209e6112022-07-20 09:30:19 +00001320 Parcel p;
1321 lynq_client_t client;
1322 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001323 int token;
ll209e6112022-07-20 09:30:19 +00001324 int request = -1;
1325 int slot_id = -1;
1326 int error = -1;
1327 client.uToken = Global_uToken_call;
1328 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1329 client.paramLen = 0;
1330 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1331 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001332 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001333 if(send_request(lynq_call_client_sockfd,&client)==-1)
1334 {
1335 LYERRLOG("send request fail");
1336 return -1;
1337 }
1338 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001339 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001340 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001341 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1342 return error;
q.huang52921662022-10-20 15:25:45 +08001343#endif
ll209e6112022-07-20 09:30:19 +00001344}
1345
1346int lynq_hangup_foreground_resume_background(void)
1347{
q.huang52921662022-10-20 15:25:45 +08001348 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001349 {
q.huang52921662022-10-20 15:25:45 +08001350 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1351 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001352 }
q.huang52921662022-10-20 15:25:45 +08001353
1354 Parcel* p=NULL;
1355 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1356 if(ret==RESULT_OK)
1357 {
1358 delete p;
1359 }
1360 return ret;
1361#if 0
ll209e6112022-07-20 09:30:19 +00001362 Parcel p;
1363 lynq_client_t client;
1364 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001365 int token;
ll209e6112022-07-20 09:30:19 +00001366 int request = -1;
1367 int slot_id = -1;
1368 int error = -1;
1369 client.uToken = Global_uToken_call;
1370 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1371 client.paramLen = 0;
1372 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1373 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001374 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001375 if(send_request(lynq_call_client_sockfd,&client)==-1)
1376 {
1377 LYERRLOG("send request fail");
1378 return -1;
1379 }
1380 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001381 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001382 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001383 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1384 return error;
q.huang52921662022-10-20 15:25:45 +08001385#endif
ll209e6112022-07-20 09:30:19 +00001386}
1387
lh7b0674a2022-01-10 00:34:35 -08001388int lynq_set_DTMF(const char callnum)
1389{
q.huang52921662022-10-20 15:25:45 +08001390 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001391 {
q.huang52921662022-10-20 15:25:45 +08001392 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1393 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001394 }
ll72bf6c12022-03-24 10:22:25 +08001395 if(!judge_dtmf(callnum))
1396 {
1397 return LYNQ_E_CONFLICT;
1398 }
q.huang52921662022-10-20 15:25:45 +08001399 if(s_module_call_state!=CALL_ON)
lh7b0674a2022-01-10 00:34:35 -08001400 {
1401 LYERRLOG("LYNQ_E_CONFLICT");
1402 return LYNQ_E_CONFLICT;
1403 }
q.huang52921662022-10-20 15:25:45 +08001404
1405// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1406
1407 Parcel* p=NULL;
1408 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1409 if(ret==RESULT_OK)
1410 {
1411 delete p;
1412 }
1413 return ret;
lh7b0674a2022-01-10 00:34:35 -08001414}
q.huangec88da92022-03-29 04:17:32 -04001415static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1416 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1417 if(volume < 0 ||volume >36){
1418 return 0;
1419 }
1420 }
1421 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1422 {
1423 if(volume < 1 ||volume >7){
1424 return 0;
1425 }
lldc99c9b2022-01-24 12:16:22 +00001426 }
ll04ae4142022-01-27 05:54:38 +00001427 return 1;
lldc99c9b2022-01-24 12:16:22 +00001428}
lh7b0674a2022-01-10 00:34:35 -08001429int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001430{
q.huang52921662022-10-20 15:25:45 +08001431 if(g_module_init_flag != MODULE_RUNNING)
1432 {
1433 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001434 return LYNQ_E_CONFLICT;
1435 }
q.huang52921662022-10-20 15:25:45 +08001436 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1437 return LYNQ_E_PARAMETER_ANONALY;
1438 }
1439// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1440 Parcel* p=NULL;
1441 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1442 if(ret==RESULT_OK)
1443 {
1444 delete p;
1445 }
1446 return ret;
lh7b0674a2022-01-10 00:34:35 -08001447}
q.huangb212fde2022-04-05 23:11:02 -04001448int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001449{
q.huang52921662022-10-20 15:25:45 +08001450 if(g_module_init_flag != MODULE_RUNNING)
lh7b0674a2022-01-10 00:34:35 -08001451 {
q.huang52921662022-10-20 15:25:45 +08001452 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangec88da92022-03-29 04:17:32 -04001453 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001454 }
q.huang52921662022-10-20 15:25:45 +08001455 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1456 {
1457 return LYNQ_E_PARAMETER_ANONALY;
1458 }
1459// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1460 Parcel* p=NULL;
1461 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1462 if(ret==RESULT_OK)
1463 {
1464 delete p;
1465 }
1466 return ret;
lh7b0674a2022-01-10 00:34:35 -08001467}
q.huangec88da92022-03-29 04:17:32 -04001468int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1469{
q.huang52921662022-10-20 15:25:45 +08001470 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangec88da92022-03-29 04:17:32 -04001471}
q.huangb212fde2022-04-05 23:11:02 -04001472int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001473{
q.huang52921662022-10-20 15:25:45 +08001474// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1475 Parcel* p=NULL;
1476 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1477 if(ret==RESULT_OK)
1478 {
1479 delete p;
1480 }
1481 return ret;
q.huangec88da92022-03-29 04:17:32 -04001482}
1483int lynq_incall_record_stop()
1484{
q.huang52921662022-10-20 15:25:45 +08001485 if(g_module_init_flag != MODULE_RUNNING)
1486 {
1487 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1488 return LYNQ_E_CONFLICT;
1489 }
q.huangb212fde2022-04-05 23:11:02 -04001490 const char* unused_file="just_ocuupy_paramter_postion";
q.huang52921662022-10-20 15:25:45 +08001491// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1492 Parcel* p=NULL;
1493 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1494 if(ret==RESULT_OK)
1495 {
1496 delete p;
1497 }
1498 return ret;
q.huangec88da92022-03-29 04:17:32 -04001499}
1500/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001501
q.huang036b6cf2023-01-10 14:29:20 +08001502
1503
1504bool is_support_urc(int urc_id)
1505{
1506 switch(urc_id)
1507 {
1508 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1509 case RIL_UNSOL_CALL_RING:
1510 case RIL_UNSOL_RINGBACK_TONE:
1511 case RIL_UNSOL_CALL_INFO_INDICATION:
1512#ifdef ECALL_SUPPORT
1513 case RIL_UNSOL_ECALL_INDICATIONS://9502
1514#endif
1515 return true;
1516 default:
1517 return false;
1518 }
1519}
1520
q.huang52921662022-10-20 15:25:45 +08001521void urc_msg_process(Parcel *p)
1522{
1523 int resp_type;
1524 int urcid;
1525 int slot_id;
q.huang036b6cf2023-01-10 14:29:20 +08001526
1527 int size=p->dataSize();
q.huang52921662022-10-20 15:25:45 +08001528 p->readInt32(&resp_type);
1529 p->readInt32(&urcid);
1530 p->readInt32(&slot_id);
q.huang036b6cf2023-01-10 14:29:20 +08001531 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 +08001532 switch (urcid)
1533 {
1534 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1535 {
1536 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1537 lynqNoticeGetModuleCallList();
1538 break;
1539 }
1540 case RIL_UNSOL_CALL_RING: //1018
1541 {
1542 if(s_call_auto_answer==1)
1543 {
1544 lynq_call_answer();
1545 }
1546 break;
1547 }
1548 case RIL_UNSOL_RINGBACK_TONE: //1029
1549 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1550 {
1551 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1552 break;
1553 }
q.huang714145d2022-04-18 00:09:50 -04001554#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +08001555 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange97cfcf2022-08-29 20:04:31 +08001556 {
q.huang52921662022-10-20 15:25:45 +08001557 urc_ecall_msg_process(p);
q.huange97cfcf2022-08-29 20:04:31 +08001558 }
q.huange97cfcf2022-08-29 20:04:31 +08001559#endif
q.huang52921662022-10-20 15:25:45 +08001560 default:
1561 break;
q.huangcb7b7292022-06-28 20:12:01 +08001562 }
q.huang5ca6c072022-06-06 16:15:31 +08001563}
q.huang5ca6c072022-06-06 16:15:31 +08001564
lh7b0674a2022-01-10 00:34:35 -08001565#if 0
1566int main(int argc,char **argv)
1567{
1568 int n = 0;
1569 n = lynq_init_call(lynq_call_state_change_test,2222);
1570 if(n<0)
1571 {
q.huang70b76492022-06-02 14:49:02 +08001572 LYDBGLOG("lynq init call fail!!!");
lh7b0674a2022-01-10 00:34:35 -08001573 return -1;
1574 }
q.huang70b76492022-06-02 14:49:02 +08001575 LYDBGLOG("lynq call init success!!!");
lh7b0674a2022-01-10 00:34:35 -08001576 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1577 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1578 lynq_call(phoneNum);
1579 while(1)
1580 {
1581 sleep(1);
1582 }
1583 return 0;
1584}
1585#endif
1586/*Warren add for T800 platform 2021/11/19 end*/