blob: d1e2293c21455d57a51240ad83764afd1c8ea9a6 [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
29using ::android::Parcel;
q.huang52921662022-10-20 15:25:45 +080030
31/**
32 * @brief mark call initialization state
33 * 0: deinit state
34 * 1: init state
35 */
36int g_module_init_flag = 0;
37
lh7b0674a2022-01-10 00:34:35 -080038 typedef enum {
39 LYNQ_CALL_ACTIVE = 0,
40 LYNQ_CALL_HOLDING = 1,
41 LYNQ_CALL_DIALING = 2, /* MO call only */
42 LYNQ_CALL_ALERTING = 3, /* MO call only */
43 LYNQ_CALL_INCOMING = 4, /* MT call only */
lhe45b7002022-04-26 00:45:44 -070044 LYNQ_CALL_WAITING = 5, /* MT call only */
45 /*warren add for T800 platform 2022/04/26 start*/
46 LYNQ_CALL_END = 6, /*CALL END*/
47 /*warren add for T800 platform 2022/04/26 end*/
lh7b0674a2022-01-10 00:34:35 -080048}lynq_call_state_t;
49
lh7b0674a2022-01-10 00:34:35 -080050typedef struct
51{
52 int used;
53 int call_id;
54 int call_state;
55 int toa;
56 int direction;/*0: MO call,1:MT call*/
57 char addr[LYNQ_PHONE_NUMBER_MAX];
lh7b0674a2022-01-10 00:34:35 -080058}lynq_call_list_e_t;
59typedef struct
60{
61 int call_id;
62 int call_state;
63 int toa;
64 int direction;/*0: MO call,1:MT call*/
65 char addr[LYNQ_PHONE_NUMBER_MAX];
66}lynq_call_list_t;
67
q.huang52921662022-10-20 15:25:45 +080068static lynq_call_list_e_t s_call_lists[LYNQ_CALL_MAX]={};
69static bool s_call_list_loop = 0;
70static pthread_t s_call_list_loop_tid = -1;
71static pthread_mutex_t s_notice_get_call_list_mutex = PTHREAD_MUTEX_INITIALIZER;
72static pthread_cond_t s_notice_get_call_list_cond = PTHREAD_COND_INITIALIZER;
73
74static int s_module_isDial = 0;
lh7b0674a2022-01-10 00:34:35 -080075static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
76static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
llb3921072023-01-10 14:47:46 +080077static int s_CallId = 0;
78static pthread_mutex_t s_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
79static pthread_cond_t s_call_state_change_cond = PTHREAD_COND_INITIALIZER;
lhec17b0a2022-02-13 23:56:05 -080080
q.huang52921662022-10-20 15:25:45 +080081static int s_module_call_state =CALL_OFF;
82static int s_call_auto_answer = 0;
lh7b0674a2022-01-10 00:34:35 -080083
q.huangec88da92022-03-29 04:17:32 -040084typedef enum{
85 LYNQ_E_VOLUMN_SET_DTMF,
86 LYNQ_E_VOLUMN_SET_SPEECH
q.huang52921662022-10-20 15:25:45 +080087}LYNQ_E_VOLUMN_SET;
lh7b0674a2022-01-10 00:34:35 -080088
q.huang52921662022-10-20 15:25:45 +080089#if 0
q.huang7de1d662022-09-13 14:19:24 +080090int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
lh7b0674a2022-01-10 00:34:35 -080091{
92 if(p.dataAvail() > 0)
93 {
94 p.readInt32(resp_type);
q.huang7de1d662022-09-13 14:19:24 +080095 p.readInt32(token);
lh7b0674a2022-01-10 00:34:35 -080096 p.readInt32(request);
97 p.readInt32(slot_id);
98 p.readInt32(error);
99 return 0;
100 }
101 else
102 {
103 return -1;
104 }
105}
106int send_request(int sockfd,lynq_client_t *client_tmp)
107{
108 int ret=0;
rjw5d2a50e2022-02-28 15:01:49 +0800109 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800110 if(ret==-1)
111 {
q.huang70b76492022-06-02 14:49:02 +0800112 LYERRLOG("sendto error");
lh7b0674a2022-01-10 00:34:35 -0800113 return -1;
114 }
115 return 0;
116}
117
118int get_response(int sockfd,Parcel &p)
119{
120 int len = 0;
121 char recvline[LYNQ_REC_BUF];
122 bzero(recvline,LYNQ_REC_BUF);
123 /* receive data from server */
rjw5d2a50e2022-02-28 15:01:49 +0800124 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800125 if(len == -1)
126 {
q.huang70b76492022-06-02 14:49:02 +0800127 LYERRLOG("recvfrom error");
lh7b0674a2022-01-10 00:34:35 -0800128 return -1;
129 }
lh7b0674a2022-01-10 00:34:35 -0800130 if (recvline != NULL) {
131 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
132 p.setDataPosition(0);
133 }
134 return 0;
135}
q.huang52921662022-10-20 15:25:45 +0800136#endif
137static char *strdupReadString(Parcel* &p) {
ll04ae4142022-01-27 05:54:38 +0000138 size_t stringlen;
lh7b0674a2022-01-10 00:34:35 -0800139 const char16_t *s16;
q.huang52921662022-10-20 15:25:45 +0800140 s16 = p->readString16Inplace(&stringlen);
ll04ae4142022-01-27 05:54:38 +0000141 return strndup16to8(s16, stringlen);
lh7b0674a2022-01-10 00:34:35 -0800142}
143
144int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
145{
q.huang52921662022-10-20 15:25:45 +0800146 Parcel* p=NULL;
147 int ret=lynq_send_common_request(p,8,RIL_REQUEST_GET_CURRENT_CALLS,0,"");
148 if(ret!=0)
149 {
150 return ret;
151 }
152
153 int call_num = 0;
154 int temp = 0;
155 char *remote_phoneNum;
156 char *remote_name;
157 char uusData[128];
158
159 p->readInt32(&call_num);
160
161 if(call_num<=0)
162 {
163 s_module_call_state = CALL_OFF;
164 LYINFLOG("lynq_call_state:%d",s_module_call_state);
165 delete p;
166 return RESULT_OK;
167 }
168 s_module_call_state = CALL_ON;
169 LYINFLOG("lynq_call_state:%d, call num is %d ",s_module_call_state,call_num);
170 for(int i = 0;i < call_num;i++)
171 {
172 p->readInt32(&temp);
173 call_list[i].call_state = temp;
174 p->readInt32(&call_list[i].call_id);
175 p->readInt32(&call_list[i].toa);
176 p->readInt32(&temp);
177 p->readInt32(&temp);
178 call_list[i].direction = temp;
179 p->readInt32(&temp);
180 p->readInt32(&temp);
181 p->readInt32(&temp);
182 remote_phoneNum = strdupReadString(p);
183 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
184 if(remote_phoneNum !=NULL)
185 {
186 free(remote_phoneNum);
187 }
188 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
189 call_list[i].direction,call_list[i].addr,call_list[i].toa);
190 p->readInt32(&temp);
191 remote_name = strdupReadString(p);
192 if(remote_name !=NULL)
193 {
194 free(remote_name);
195 }
196 p->readInt32(&temp);
197 p->readInt32(&temp);
198 if(temp==0)
199 {
200 continue;
201 }
202 p->readInt32(&temp); /* UUS Information is present */
203 p->readInt32(&temp);
204 p->readInt32(&temp);
205 if(temp<=128)
206 {
207 p->read(uusData,temp);
208 }
209 else
210 {
211 LYERRLOG("%s len %d is too great",__func__,temp);
212 delete p;
213 return LYNQ_E_MALLOC_ERROR;
214 }
215 }
216
217 delete p;
218 return RESULT_OK;
219
220#if 0
lh7b0674a2022-01-10 00:34:35 -0800221 Parcel p;
222 lynq_client_t client;
223 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800224 int token;
lh7b0674a2022-01-10 00:34:35 -0800225 int request = -1;
226 int slot_id = -1;
227 int error = -1;
228 int call_num = 0;
229 int temp = 0;
230 char *remote_phoneNum = NULL;
231 char *remote_name= NULL;
232 char *uusData = NULL;
lh42c1e572022-01-25 18:47:39 -0800233 client.uToken = Global_uToken_call;
lh7b0674a2022-01-10 00:34:35 -0800234 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
235 client.paramLen = 0;
236 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang70b76492022-06-02 14:49:02 +0800237 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lh42c1e572022-01-25 18:47:39 -0800238 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh7b0674a2022-01-10 00:34:35 -0800239 {
240 LYERRLOG("send request fail");
lh7b0674a2022-01-10 00:34:35 -0800241 return -1;
242 }
lh42c1e572022-01-25 18:47:39 -0800243 get_response(lynq_call_client_sockfd,p);
q.huang7de1d662022-09-13 14:19:24 +0800244 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh7b0674a2022-01-10 00:34:35 -0800245 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
246 if(error == 0)
247 {
248 p.readInt32(&call_num);
249 global_call_count = call_num;
250 if(call_num<=0)
251 {
252 lynq_call_state = CALL_OFF;
lhec17b0a2022-02-13 23:56:05 -0800253 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh7b0674a2022-01-10 00:34:35 -0800254 return 0;
255 }
lhec17b0a2022-02-13 23:56:05 -0800256 lynq_call_state = CALL_ON;
q.huang70b76492022-06-02 14:49:02 +0800257 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh7b0674a2022-01-10 00:34:35 -0800258 for(int i = 0;i < call_num;i++)
259 {
260 p.readInt32(&temp);
261 call_list[i].call_state = temp;
262 p.readInt32(&call_list[i].call_id);
263 p.readInt32(&call_list[i].toa);
264 p.readInt32(&temp);
265 p.readInt32(&temp);
266 call_list[i].direction = temp;
267 p.readInt32(&temp);
268 p.readInt32(&temp);
269 p.readInt32(&temp);
270 remote_phoneNum = strdupReadString(p);
271 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
272 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
273 call_list[i].direction,call_list[i].addr,call_list[i].toa);
274 p.readInt32(&temp);
275 remote_name = strdupReadString(p);
276 p.readInt32(&temp);
277 p.readInt32(&temp);
278 if(temp==0)
279 {
280 continue;
281 }
282 p.readInt32(&temp); /* UUS Information is present */
283 p.readInt32(&temp);
284 p.readInt32(&temp);
285 p.read(uusData,temp);
286 }
287 }
288 return 0;
q.huang52921662022-10-20 15:25:45 +0800289#endif
lh7b0674a2022-01-10 00:34:35 -0800290}
291
292void cleanCallList(int lynq_call_id)
293{
q.huang52921662022-10-20 15:25:45 +0800294 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
295 s_call_lists[lynq_call_id].call_id = 0;
296 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
297 s_call_lists[lynq_call_id].toa = 0;
298 s_call_lists[lynq_call_id].direction = 0;
299 s_call_lists[lynq_call_id].used = 0;
300 memset(s_call_lists[lynq_call_id].addr,0,sizeof(s_call_lists[lynq_call_id].addr));
lh7b0674a2022-01-10 00:34:35 -0800301}
llb3921072023-01-10 14:47:46 +0800302
303
lh7b0674a2022-01-10 00:34:35 -0800304int getUnusedElement()
305{
306 for(int i=0;i < LYNQ_CALL_MAX; i++)
307 {
q.huang52921662022-10-20 15:25:45 +0800308 if(s_call_lists[i].used!=1)
lh7b0674a2022-01-10 00:34:35 -0800309 {
310 return i;
311 }
312 }
q.huang52921662022-10-20 15:25:45 +0800313 return INVALID_ID;
lh7b0674a2022-01-10 00:34:35 -0800314}
q.huang52921662022-10-20 15:25:45 +0800315int addAddr(char addr[], int call_id)
lh7b0674a2022-01-10 00:34:35 -0800316{
317 int ret = 0;
318 ret = getUnusedElement();
q.huang52921662022-10-20 15:25:45 +0800319 memcpy(s_call_lists[ret].addr,addr,strlen(addr)+1);
320 s_call_lists[ret].call_id=call_id;
321 s_call_lists[ret].used = 1;
q.huang70b76492022-06-02 14:49:02 +0800322 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh7b0674a2022-01-10 00:34:35 -0800323 return ret;
324}
325void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
326{
q.huang70b76492022-06-02 14:49:02 +0800327 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh7b0674a2022-01-10 00:34:35 -0800328 callList->call_id = call_id;
329 callList->call_state = call_state;
330 callList->toa = toa;
q.huang70b76492022-06-02 14:49:02 +0800331 callList->direction = direction;
lh7b0674a2022-01-10 00:34:35 -0800332 return;
333}
llb3921072023-01-10 14:47:46 +0800334
335void wait_call_state()
lh7b0674a2022-01-10 00:34:35 -0800336{
llb3921072023-01-10 14:47:46 +0800337 LYINFLOG("call state changed");
338 pthread_mutex_lock(&s_call_state_change_mutex);
339 pthread_cond_wait(&s_call_state_change_cond,&s_call_state_change_mutex);
340 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800341}
llb3921072023-01-10 14:47:46 +0800342
lh7b0674a2022-01-10 00:34:35 -0800343int checkHasCall(char addr[])
344{
345 for(int i = 0;i<LYNQ_CALL_MAX;i++)
346 {
q.huang52921662022-10-20 15:25:45 +0800347 if(strcmp(s_call_lists[i].addr,addr)==0)
lh7b0674a2022-01-10 00:34:35 -0800348 {
q.huang52921662022-10-20 15:25:45 +0800349 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,s_call_lists[i].call_id);
350 return true;
lh7b0674a2022-01-10 00:34:35 -0800351 }
352 }
q.huang70b76492022-06-02 14:49:02 +0800353 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
q.huang52921662022-10-20 15:25:45 +0800354 return false;
lh7b0674a2022-01-10 00:34:35 -0800355}
lhd1e457c2022-04-19 06:01:25 -0700356int find_call_id_with_addr(char *addr)
357{
lhd1e457c2022-04-19 06:01:25 -0700358 for(int id = 0; id < LYNQ_CALL_MAX; id++)
359 {
q.huang52921662022-10-20 15:25:45 +0800360 if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
lhd1e457c2022-04-19 06:01:25 -0700361 {
q.huang52921662022-10-20 15:25:45 +0800362 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 -0700363 return id;
364 }
365 }
q.huang70b76492022-06-02 14:49:02 +0800366 LYINFLOG("find addr %s in local list , not found",addr);
q.huang52921662022-10-20 15:25:45 +0800367 return INVALID_ID;
lhd1e457c2022-04-19 06:01:25 -0700368}
q.huang70b76492022-06-02 14:49:02 +0800369int find_call_id_with_call_id(int call_id)
370{
371 for(int id = 0; id < LYNQ_CALL_MAX; id++)
372 {
q.huang52921662022-10-20 15:25:45 +0800373 if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
q.huang70b76492022-06-02 14:49:02 +0800374 {
q.huang52921662022-10-20 15:25:45 +0800375 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 +0800376 return id;
377 }
378 }
379 LYINFLOG("find id %d in local list , not found",call_id);
380 return INVALID_ID;
381}
lh7b0674a2022-01-10 00:34:35 -0800382void sendSignalToWaitCallStateChange()
383{
lhd1e457c2022-04-19 06:01:25 -0700384 LYINFLOG("send Signal To Wait Call State Change");
lh7b0674a2022-01-10 00:34:35 -0800385 pthread_mutex_lock(&call_state_change_mutex);
386 pthread_cond_signal(&call_state_change_cond);
387 pthread_mutex_unlock(&call_state_change_mutex);
388}
llb3921072023-01-10 14:47:46 +0800389void send_call_state_change()
lh7b0674a2022-01-10 00:34:35 -0800390{
llb3921072023-01-10 14:47:46 +0800391 LYINFLOG("send call state change");
392 pthread_mutex_lock(&s_call_state_change_mutex);
393 pthread_cond_signal(&s_call_state_change_cond);
394 pthread_mutex_unlock(&s_call_state_change_mutex);
lh7b0674a2022-01-10 00:34:35 -0800395}
396
q.huang52921662022-10-20 15:25:45 +0800397void cleanup_call_list_mutex(void *arg)
lh7b0674a2022-01-10 00:34:35 -0800398{
q.huang52921662022-10-20 15:25:45 +0800399 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
lh7b0674a2022-01-10 00:34:35 -0800400}
llb3921072023-01-10 14:47:46 +0800401
402void update_end_state(int lynq_call_id)
403{
404 LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
405 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
406}
407
lh7b0674a2022-01-10 00:34:35 -0800408void *triggerGetCallList(void *parg)
ll04ae4142022-01-27 05:54:38 +0000409{
410 int ret=0;
lhd1e457c2022-04-19 06:01:25 -0700411 bool call_end;
ll04ae4142022-01-27 05:54:38 +0000412 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huang8b33ed52022-04-19 20:27:44 -0400413 int update=0;
q.huang70b76492022-06-02 14:49:02 +0800414 int cnt;
415 int i,n;
q.huange97cfcf2022-08-29 20:04:31 +0800416#ifdef ECALL_SUPPORT
417 int handupIncomingMT=0;
418#endif
q.huang52921662022-10-20 15:25:45 +0800419 pthread_mutex_lock(&s_notice_get_call_list_mutex);
420 pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
421 while(s_call_list_loop)
ll04ae4142022-01-27 05:54:38 +0000422 {
q.huang52921662022-10-20 15:25:45 +0800423 update=0;
424 pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
q.huang70b76492022-06-02 14:49:02 +0800425 LYDBGLOG("triggerGetCallList event!!!");
ll04ae4142022-01-27 05:54:38 +0000426 memset(call_list,0,sizeof(call_list));
427 ret = lynq_get_current_call_list(call_list);
q.huang52921662022-10-20 15:25:45 +0800428 if(ret != RESULT_OK)
ll04ae4142022-01-27 05:54:38 +0000429 {
q.huang52921662022-10-20 15:25:45 +0800430 LYDBGLOG("get current call list failure!!!");
llbc035332022-04-11 05:49:51 +0000431 continue;
ll04ae4142022-01-27 05:54:38 +0000432 }
lhd1e457c2022-04-19 06:01:25 -0700433 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huang70b76492022-06-02 14:49:02 +0800434 LYINFLOG("clear local index begin");
435 cnt=0;
436 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh7b0674a2022-01-10 00:34:35 -0800437 {
q.huang52921662022-10-20 15:25:45 +0800438 if(s_call_lists[i].used ==0)
q.huang70b76492022-06-02 14:49:02 +0800439 {
440 continue;
441 }
442 cnt++;
q.huang52921662022-10-20 15:25:45 +0800443 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 +0800444
q.huang52921662022-10-20 15:25:45 +0800445 if(s_call_lists[i].call_id > 0)
lhd1e457c2022-04-19 06:01:25 -0700446 {
447 call_end = 0;
q.huang70b76492022-06-02 14:49:02 +0800448 for(n = 0; n < LYNQ_CALL_MAX; n++)
lhd1e457c2022-04-19 06:01:25 -0700449 {
q.huang52921662022-10-20 15:25:45 +0800450 if(call_list[n].call_id == s_call_lists[i].call_id)
lhd1e457c2022-04-19 06:01:25 -0700451 {
452 call_end = 1;
q.huang52921662022-10-20 15:25:45 +0800453 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 +0800454 break;
lhd1e457c2022-04-19 06:01:25 -0700455 }
456 }
457 if(call_end == 0)
458 {
llb3921072023-01-10 14:47:46 +0800459 LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
460 //update_end_state(i);//lei modify for:update end state for this call
461 cleanCallList(i);
462 send_call_state_change();//means mt/mo call is end
463 //cleanCallList(i);
lhd1e457c2022-04-19 06:01:25 -0700464 }
465 } //fix bug API-54
q.huang70b76492022-06-02 14:49:02 +0800466 else
467 {
468 LYINFLOG("local id is 0");
469 }
470 }
471 LYINFLOG("clear local index end, local used cnt is %d", cnt);
472
473 LYINFLOG("add or update local index begin ");
474 for (i = 0;i < LYNQ_CALL_MAX;i++)
475 {
476 if(call_list[i].call_id==0)
477 {
478 break;
479 }
480
481 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,
482 call_list[i].direction,call_list[i].addr,call_list[i].toa);
483
lh7b0674a2022-01-10 00:34:35 -0800484 if(call_list[i].direction == 1)//MT call
485 {
q.huang70b76492022-06-02 14:49:02 +0800486 LYINFLOG("This is a MT CALL");
lh0fd3b012022-05-13 03:02:19 -0700487 /*MT CALL state code
488 **LYNQ_CALL_INCOMING = 4,
489 **LYNQ_CALL_WAITING = 5,
490 */
q.huange97cfcf2022-08-29 20:04:31 +0800491#ifdef ECALL_SUPPORT
lh0fd3b012022-05-13 03:02:19 -0700492 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh7b0674a2022-01-10 00:34:35 -0800493 {
q.huang52921662022-10-20 15:25:45 +0800494 handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
q.huange97cfcf2022-08-29 20:04:31 +0800495 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
496 if(handupIncomingMT)
lh7b0674a2022-01-10 00:34:35 -0800497 {
q.huang70b76492022-06-02 14:49:02 +0800498 lynq_call_hungup(&(call_list[i].call_id));
499 continue;
q.huange97cfcf2022-08-29 20:04:31 +0800500 }
q.huang70b76492022-06-02 14:49:02 +0800501 }
q.huange97cfcf2022-08-29 20:04:31 +0800502#endif
q.huang70b76492022-06-02 14:49:02 +0800503 /*you call me, and i call you,One party failed to dial*/
504 n = find_call_id_with_addr(call_list[i].addr);
505 if(n ==INVALID_ID)
506 {
q.huang52921662022-10-20 15:25:45 +0800507 n = addAddr(call_list[i].addr,call_list[i].call_id);
508 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
llb3921072023-01-10 14:47:46 +0800509 s_CallId = call_list[i].call_id;
510 send_call_state_change();
q.huang70b76492022-06-02 14:49:02 +0800511 }
q.huang52921662022-10-20 15:25:45 +0800512 else if(s_call_lists[n].call_state == call_list[i].call_state)
q.huang70b76492022-06-02 14:49:02 +0800513 {
514 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
515 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lhd1e457c2022-04-19 06:01:25 -0700516 {
lhd1e457c2022-04-19 06:01:25 -0700517 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
518 **an incoming call until the status changes.
519 **fix bug API-54
520 */
q.huang70b76492022-06-02 14:49:02 +0800521 LYINFLOG("resend incoming call signal");
llb3921072023-01-10 14:47:46 +0800522 send_call_state_change();
lhd1e457c2022-04-19 06:01:25 -0700523 }
lh7b0674a2022-01-10 00:34:35 -0800524 }
q.huang70b76492022-06-02 14:49:02 +0800525 else
ll72bf6c12022-03-24 10:22:25 +0800526 {
q.huang52921662022-10-20 15:25:45 +0800527 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 +0800528
llb3921072023-01-10 14:47:46 +0800529 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
lle3b9a232023-01-14 13:21:20 +0800530 send_call_state_change();
llb3921072023-01-10 14:47:46 +0800531 }
lh7b0674a2022-01-10 00:34:35 -0800532 }
533 else
q.huang70b76492022-06-02 14:49:02 +0800534 {
535 LYINFLOG("This is a MO CALL");
536 call_end = 0;
537 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh7b0674a2022-01-10 00:34:35 -0800538 {
q.huang52921662022-10-20 15:25:45 +0800539 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 -0800540 {
q.huang52921662022-10-20 15:25:45 +0800541 if(s_call_lists[n].call_id==0)
q.huang70b76492022-06-02 14:49:02 +0800542 {
llb3921072023-01-10 14:47:46 +0800543 LYINFLOG("add a call id");
544 update=1;//for send sigal
lle3b9a232023-01-14 13:21:20 +0800545 s_CallId = call_list[i].call_id;
q.huang70b76492022-06-02 14:49:02 +0800546 }
q.huang52921662022-10-20 15:25:45 +0800547 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);
548 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 +0800549 call_end = 1;
llb3921072023-01-10 14:47:46 +0800550 send_call_state_change();//means mo call is success
q.huang70b76492022-06-02 14:49:02 +0800551 break;
552 }
553 }
llb3921072023-01-10 14:47:46 +0800554 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 +0800555 {
556 LYINFLOG("need to hangup id %d", call_list[i].call_id);
557#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +0800558 if(IsECallDialing())
q.huang70b76492022-06-02 14:49:02 +0800559 {
560 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh7b0674a2022-01-10 00:34:35 -0800561 continue;
562 }
q.huang70b76492022-06-02 14:49:02 +0800563#endif
564 LYINFLOG("hang up service call id %d",call_list[i].call_id);
565 lynq_call_hungup(&(call_list[i].call_id));
lh7b0674a2022-01-10 00:34:35 -0800566 }
llb3921072023-01-10 14:47:46 +0800567
lh7b0674a2022-01-10 00:34:35 -0800568 }
q.huang70b76492022-06-02 14:49:02 +0800569 LYDBGLOG("servie idx %d end",i);
ll04ae4142022-01-27 05:54:38 +0000570 }
q.huang52921662022-10-20 15:25:45 +0800571 LYINFLOG("add or update local index end ");
572 if(s_module_isDial==1)
lh7b0674a2022-01-10 00:34:35 -0800573 {
q.huang70b76492022-06-02 14:49:02 +0800574 LYINFLOG("now is dialing");
575 if(update==1)
576 {
577 LYINFLOG("find added call");
578 sendSignalToWaitCallStateChange();
q.huang52921662022-10-20 15:25:45 +0800579 s_module_isDial = 0;
q.huang70b76492022-06-02 14:49:02 +0800580 }
581 else
582 {
583 LYINFLOG("not find added call");
584 }
585 }
586 else
587 {
588 LYINFLOG("now is not dialing");
q.huang52921662022-10-20 15:25:45 +0800589 }
ll04ae4142022-01-27 05:54:38 +0000590 }
q.huang52921662022-10-20 15:25:45 +0800591 pthread_cleanup_pop(0);
592 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
ll04ae4142022-01-27 05:54:38 +0000593 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800594}
595
q.huang52921662022-10-20 15:25:45 +0800596void lynqNoticeGetModuleCallList()
ll04ae4142022-01-27 05:54:38 +0000597{
q.huang52921662022-10-20 15:25:45 +0800598 pthread_mutex_lock(&s_notice_get_call_list_mutex);
599 pthread_cond_signal(&s_notice_get_call_list_cond);
600 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
601
lh7b0674a2022-01-10 00:34:35 -0800602}
603
q.huang52921662022-10-20 15:25:45 +0800604#if 0
lh7b0674a2022-01-10 00:34:35 -0800605/*Warren add for T800 platform 2021/11/19 start*/
606int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800607{
608 #if 0
lh7b0674a2022-01-10 00:34:35 -0800609 struct sockaddr_in lynq_socket_server_addr;
610 /* init lynq_socket_server_addr */
611 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
612 lynq_socket_server_addr.sin_family = AF_INET;
613 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
614 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800615
lh7b0674a2022-01-10 00:34:35 -0800616 /*
617 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
618 {
q.huang70b76492022-06-02 14:49:02 +0800619 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800620 exit(1);
621 }
622*/
lh42c1e572022-01-25 18:47:39 -0800623 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
624 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800625 {
q.huang70b76492022-06-02 14:49:02 +0800626 LYERRLOG("connect error");
lh7b0674a2022-01-10 00:34:35 -0800627 return -1;
628 }
rjw5d2a50e2022-02-28 15:01:49 +0800629 #endif
630 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
631 if (-1 == lynq_call_client_sockfd)
632 {
633 return lynq_call_client_sockfd;
634 }
ll630be412022-07-25 05:52:14 +0000635 struct timeval timeOut;
636 timeOut.tv_sec = 60;
637 timeOut.tv_usec = 0;
638 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
639 {
640 RLOGD("time out setting failed\n");
641 return -1;
642 }
rjw5d2a50e2022-02-28 15:01:49 +0800643 /* 设置address */
644 memset(&addr_serv, 0, sizeof(addr_serv));
645 addr_serv.sin_family = AF_INET;
646 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
647 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
648 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800649 return 0;
650}
lh7b0674a2022-01-10 00:34:35 -0800651
lh7b0674a2022-01-10 00:34:35 -0800652int lynq_socket_urc_start()
653{
654 int socket_fd=0;
655 int rt=0;
656 int len=0;
657 int on=1;
658 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800659 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000660 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000661 if(socket_fd < 0)
662 {
q.huang70b76492022-06-02 14:49:02 +0800663 LYERRLOG("creaet socket for udp fail");
ll04ae4142022-01-27 05:54:38 +0000664 return -1;
lh7b0674a2022-01-10 00:34:35 -0800665 }
666 urc_local_addr.sin_family = AF_INET;
667 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
668 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
669 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000670 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
671 if(rt<0)
672 {
q.huang70b76492022-06-02 14:49:02 +0800673 LYERRLOG("SO_REUSEADDR fail");
lh7b0674a2022-01-10 00:34:35 -0800674 return -1;
675 }
676 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000677 if (rt == -1)
678 {
lh21502f52022-01-27 00:27:12 -0800679 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000680 return -1;
lh7b0674a2022-01-10 00:34:35 -0800681 }
682 pthread_attr_init(&attr);
683 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800684 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800685 if(rt < 0)
686 {
q.huang70b76492022-06-02 14:49:02 +0800687 LYERRLOG("urc loop failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800688 return -1;
689 }
q.huang70b76492022-06-02 14:49:02 +0800690 LYDBGLOG("urc loop success!!!");
lh7b0674a2022-01-10 00:34:35 -0800691 return 0;
692}
q.huang52921662022-10-20 15:25:45 +0800693#endif
lh7b0674a2022-01-10 00:34:35 -0800694
695void lynq_call_state_change_test(int soc_id)
696{
q.huang70b76492022-06-02 14:49:02 +0800697 LYDBGLOG("call state change,sim:%d",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800698}
q.huangcb7b7292022-06-28 20:12:01 +0800699
q.huang52921662022-10-20 15:25:45 +0800700int lynq_start_call_list_loop()
701{
702#if 0
703 int ret = 0;
704 pthread_attr_t attr;
705 pthread_attr_init(&attr);
706 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
q.huangcb7b7292022-06-28 20:12:01 +0800707
q.huang52921662022-10-20 15:25:45 +0800708 s_notice_get_call_list_mutex = new pthread_mutex_t;
709 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
710 s_notice_get_call_list_cond = new pthread_cond_t;
711 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
712 pthread_cond_init(s_notice_get_call_list_cond, NULL);
713 LYINFLOG("liulei s_notice_get_call_list_cond\n");
714#endif
q.huangcb7b7292022-06-28 20:12:01 +0800715
q.huang52921662022-10-20 15:25:45 +0800716 s_call_list_loop = 1;
717 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
718 if(ret < 0)
q.huangcb7b7292022-06-28 20:12:01 +0800719 {
q.huang52921662022-10-20 15:25:45 +0800720 LYERRLOG("lynq_update_call_list_loop fail!!!");
lla8c25a82022-03-17 05:31:33 +0000721 return -1;
722 }
q.huang52921662022-10-20 15:25:45 +0800723 LYINFLOG("lynq_update_call_list_loop success!!!");
q.huangcb7b7292022-06-28 20:12:01 +0800724
q.huang52921662022-10-20 15:25:45 +0800725 memset(s_call_lists,0,sizeof(s_call_lists));
lh7b0674a2022-01-10 00:34:35 -0800726 return 0;
727}
q.huang52921662022-10-20 15:25:45 +0800728
729int lynq_stop_call_list_loop()
lh7b0674a2022-01-10 00:34:35 -0800730{
q.huang70b76492022-06-02 14:49:02 +0800731 int ret;
q.huang52921662022-10-20 15:25:45 +0800732 pthread_mutex_lock(&s_notice_get_call_list_mutex);
733 s_call_list_loop = 0;
734 ret = pthread_cancel(s_call_list_loop_tid);
735 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
736 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
737 ret = pthread_join(s_call_list_loop_tid,NULL);
738 LYINFLOG("pthread join w_c_list ret = %d",ret);
739 s_call_list_loop_tid=-1;
740#if 0
741 pthread_mutex_destroy(s_notice_get_call_list_mutex);
742 pthread_cond_destroy(s_notice_get_call_list_cond);
743 delete s_notice_get_call_list_mutex;
744 //s_notice_get_call_list_mutex = NULL;
745 delete s_notice_get_call_list_cond;
746 //s_notice_get_call_list_cond = NULL;
747#endif
748
749 return 0;
rita98e2e9c2022-04-07 06:08:13 -0400750}
q.huang714145d2022-04-18 00:09:50 -0400751
q.huang52921662022-10-20 15:25:45 +0800752int lynq_init_call(int utoken){
753 if(g_module_init_flag != MODULE_CLOSED)
754 {
755 LYERRLOG("module state is %d",g_module_init_flag);
756 return LYNQ_E_CONFLICT;
757 }
758 if(utoken <0){
759 LYERRLOG("utoken is less than 0",utoken);
760 return LYNQ_E_PARAMETER_ANONALY;
761 }
762 g_module_init_flag = MODULE_SWITCHING;
763
764 LYLOGSET(LOG_INFO);
765 LYLOGEINIT(USER_LOG_TAG);
766
767 g_module_Global_uToken = utoken;
768
q.huang036b6cf2023-01-10 14:29:20 +0800769 int ret = lynq_start_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800770 if(ret != RESULT_OK)
771 {
772 LYERRLOG("init socket urc fail!!!");
773 g_module_init_flag = MODULE_CLOSED;
774 return LYNQ_E_INNER_ERROR;
775 }
776
q.huang036b6cf2023-01-10 14:29:20 +0800777 ret = lynq_start_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800778 if(ret !=RESULT_OK)
779 {
780 LYERRLOG("init socket client fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800781 lynq_close_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800782 g_module_init_flag = MODULE_CLOSED;
783 return LYNQ_E_INNER_ERROR;
784 }
785
786
787 int result = lynq_start_call_list_loop();
788 if(ret != RESULT_OK)
789 {
790 LYERRLOG("lynq_start_call_list_loop fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800791 lynq_close_all_urc_socket_thread();
792 lynq_close_all_rc_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 lynq_init_rtp();
798
799 g_module_init_flag = MODULE_RUNNING;
800 return 0;
801}
802
803int lynq_deinit_call(void){
804
805 if (g_module_init_flag != MODULE_RUNNING)
806 {
807 LYERRLOG("module state is %d",g_module_init_flag);
808 return LYNQ_E_CONFLICT;
809 }
810 lynq_call_hungup_all();
811 lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
812 g_module_init_flag = MODULE_SWITCHING;
q.huang036b6cf2023-01-10 14:29:20 +0800813 lynq_close_all_urc_socket_thread();
814 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800815 lynq_stop_call_list_loop();
816 g_module_init_flag = MODULE_CLOSED;
817 return 0;
818}
819
820#if 0
q.huang714145d2022-04-18 00:09:50 -0400821int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400822{
823 Parcel p;
824 lynq_client_t client;
825 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800826 int token;
rita089527e2022-04-07 01:55:39 -0400827 int request = -1;
828 int slot_id = -1;
829 int error = -1;
rita089527e2022-04-07 01:55:39 -0400830
q.huang52921662022-10-20 15:25:45 +0800831 Parcel* p=NULL;
832 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
833 if(ret==RESULT_OK)
834 {
835 delete p;
836 }
837 return ret;
838
rita089527e2022-04-07 01:55:39 -0400839 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400840 client.request = request_id;
841 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400842 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400843 if(argc!=0)
844 {
845 va_list args;
846 va_start(args, format);
847 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
848 va_end(args);
849 }
q.huang70b76492022-06-02 14:49:02 +0800850 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400851 if(send_request(lynq_call_client_sockfd,&client)==-1)
852 {
853 LYERRLOG("send request fail");
854 return -1;
855 }
q.huang714145d2022-04-18 00:09:50 -0400856 if(get_response(lynq_call_client_sockfd,p)==0)
857 {
q.huang7de1d662022-09-13 14:19:24 +0800858 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang714145d2022-04-18 00:09:50 -0400859 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
860 }
rita089527e2022-04-07 01:55:39 -0400861 return error;
q.huang52921662022-10-20 15:25:45 +0800862
863
rita089527e2022-04-07 01:55:39 -0400864}
q.huang52921662022-10-20 15:25:45 +0800865#endif
rita089527e2022-04-07 01:55:39 -0400866
q.huang714145d2022-04-18 00:09:50 -0400867int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400868{
q.huang714145d2022-04-18 00:09:50 -0400869 if(status==NULL)
870 {
871 LYERRLOG("status is null");
q.huang52921662022-10-20 15:25:45 +0800872 return LYNQ_E_PARAMETER_ANONALY;
q.huang714145d2022-04-18 00:09:50 -0400873 }
q.huang52921662022-10-20 15:25:45 +0800874
875 Parcel* p=NULL;
876 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
877 if(ret==RESULT_OK)
rita089527e2022-04-07 01:55:39 -0400878 {
q.huang52921662022-10-20 15:25:45 +0800879 p->readInt32(status);
880 delete p;
rita089527e2022-04-07 01:55:39 -0400881 }
q.huang52921662022-10-20 15:25:45 +0800882 return ret;
883}
884
885int waitCallstateChange(int mtime)
886{
887 LYINFLOG("wait Call state Change");
888 int ret = 0;
889 int sec = 0;
890 int usec = 0;
891 struct timeval now;
892 struct timespec timeout;
893 gettimeofday(&now,NULL);
894 sec = mtime/1000;
895 usec = mtime%1000;
896 timeout.tv_sec = now.tv_sec+sec;
897 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
898 pthread_mutex_lock(&call_state_change_mutex);
899 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
900 pthread_mutex_unlock(&call_state_change_mutex);
901 return ret;
902}
903
904int IsNormalCallDailing()
905{
906 return s_module_isDial;
rita089527e2022-04-07 01:55:39 -0400907}
908
llb3921072023-01-10 14:47:46 +0800909
lh7b0674a2022-01-10 00:34:35 -0800910int lynq_call(int* handle,char addr[])
911{
q.huang52921662022-10-20 15:25:45 +0800912 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700913 {
q.huang52921662022-10-20 15:25:45 +0800914 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
915 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -0700916 }
q.huang52921662022-10-20 15:25:45 +0800917
lh7b0674a2022-01-10 00:34:35 -0800918 int lynq_call_id = -1;
q.huang70b76492022-06-02 14:49:02 +0800919
920 LYINFLOG("lynq_call begin addr %s",addr);
lh7b0674a2022-01-10 00:34:35 -0800921 if(addr==NULL)
922 {
923 LYERRLOG("Phone num is null!!!");
q.huang52921662022-10-20 15:25:45 +0800924 return LYNQ_E_PARAMETER_ANONALY;
lh7b0674a2022-01-10 00:34:35 -0800925 }
q.huang70b76492022-06-02 14:49:02 +0800926
927 if(find_call_id_with_addr(addr)!=INVALID_ID)
928 {
929 LYERRLOG("addr %s exists",addr);
930 return LYNQ_E_CONFLICT;
931 }
932
933#ifdef ECALL_SUPPORT
934 if(lynq_ecall_is_running())
935 {
936 LYERRLOG("lynq_fast_ecall ecall is running");
937 return LYNQ_E_ECALL_BEING_RUNNING;
938 }
939#endif
q.huang52921662022-10-20 15:25:45 +0800940 Parcel* p=NULL;
941 lynq_call_id = addAddr(addr,0);
942 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
943 if(ret!=0)
944 {
llb3921072023-01-10 14:47:46 +0800945 cleanCallList(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +0800946 return ret;
llb3921072023-01-10 14:47:46 +0800947 }
948 delete p;
q.huang52921662022-10-20 15:25:45 +0800949 s_module_isDial = 1;
950 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -0800951 {
q.huang52921662022-10-20 15:25:45 +0800952 //if timeout,this call need destroy.
953 s_module_isDial = 0;
954 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
llb3921072023-01-10 14:47:46 +0800955 cleanCallList(lynq_call_id);
lle3b9a232023-01-14 13:21:20 +0800956 send_call_state_change();
q.huang52921662022-10-20 15:25:45 +0800957 return LYNQ_E_TIME_OUT;
lh7b0674a2022-01-10 00:34:35 -0800958 }
q.huang52921662022-10-20 15:25:45 +0800959 s_module_isDial = 0;
960 *handle = s_call_lists[lynq_call_id].call_id;
961 if(*handle > 0)
lh7b0674a2022-01-10 00:34:35 -0800962 {
q.huang52921662022-10-20 15:25:45 +0800963 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
964 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -0800965 }
q.huang52921662022-10-20 15:25:45 +0800966 else
967 {
968 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
lle3b9a232023-01-14 13:21:20 +0800969 cleanCallList(lynq_call_id);
970 send_call_state_change();
q.huang52921662022-10-20 15:25:45 +0800971 return LYNQ_E_INVALID_ID_ANONALY;
llb3921072023-01-10 14:47:46 +0800972 }
lh7b0674a2022-01-10 00:34:35 -0800973}
llb3921072023-01-10 14:47:46 +0800974
lh7b0674a2022-01-10 00:34:35 -0800975int lynq_call_answer()
976{
q.huang52921662022-10-20 15:25:45 +0800977 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700978 {
q.huang52921662022-10-20 15:25:45 +0800979 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
980 return LYNQ_E_CONFLICT;
981 }
982
983 Parcel* p=NULL;
984 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
985 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -0800986 {
q.huang52921662022-10-20 15:25:45 +0800987 delete p;
988 }
989 return ret;
lh7b0674a2022-01-10 00:34:35 -0800990}
llb3921072023-01-10 14:47:46 +0800991
lh7b0674a2022-01-10 00:34:35 -0800992int lynq_call_hungup(int* handle)
993{
q.huang52921662022-10-20 15:25:45 +0800994 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700995 {
q.huang52921662022-10-20 15:25:45 +0800996 return LYNQ_E_CONFLICT;
997 }
998
lh42c1e572022-01-25 18:47:39 -0800999 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1000 {
q.huang52921662022-10-20 15:25:45 +08001001 LYERRLOG("%s illegal input!!!!",__func__);
1002 return LYNQ_E_PARAMETER_ANONALY;
lh42c1e572022-01-25 18:47:39 -08001003 }
q.huang52921662022-10-20 15:25:45 +08001004
1005 int call_id = *handle;
1006 Parcel* p=NULL;
1007 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1008 if(ret!=0)
lh7b0674a2022-01-10 00:34:35 -08001009 {
q.huang52921662022-10-20 15:25:45 +08001010 return ret;
1011 }
1012 delete p;
1013
1014 int lynq_call_id=find_call_id_with_call_id(call_id);
1015 if(lynq_call_id!=INVALID_ID)
lh7b0674a2022-01-10 00:34:35 -08001016 {
q.huang52921662022-10-20 15:25:45 +08001017 cleanCallList(lynq_call_id);
1018 }
1019
1020 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001021}
1022int lynq_call_hungup_all()
1023{
q.huang52921662022-10-20 15:25:45 +08001024 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001025 {
q.huang52921662022-10-20 15:25:45 +08001026 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1027 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001028 }
q.huang52921662022-10-20 15:25:45 +08001029
1030 Parcel* p=NULL;
1031 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1032 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001033 {
q.huang52921662022-10-20 15:25:45 +08001034 delete p;
1035 }
1036 return ret;
lh7b0674a2022-01-10 00:34:35 -08001037}
llb3921072023-01-10 14:47:46 +08001038
1039int lynq_wait_call_state_change(int *handle)
lh7b0674a2022-01-10 00:34:35 -08001040{
q.huang52921662022-10-20 15:25:45 +08001041 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001042 {
q.huang52921662022-10-20 15:25:45 +08001043 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1044 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001045 }
llb3921072023-01-10 14:47:46 +08001046 wait_call_state();
1047 *handle = s_CallId;
1048 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1049 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001050}
1051
1052int lynq_set_auto_answercall(const int mode)
1053{
q.huang52921662022-10-20 15:25:45 +08001054 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001055 {
q.huang52921662022-10-20 15:25:45 +08001056 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1057 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001058 }
q.huang52921662022-10-20 15:25:45 +08001059 s_call_auto_answer = mode;
lh7b0674a2022-01-10 00:34:35 -08001060 LYINFLOG("auto answer call mode =%d",mode);
q.huang52921662022-10-20 15:25:45 +08001061 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001062}
llb3921072023-01-10 14:47:46 +08001063
1064int lynq_find_already_end()
1065{
1066 for(int i=0;i < LYNQ_CALL_MAX; i++)
1067 {
1068 if(s_call_lists[i].call_state == 6)
1069 {
1070 return 0;
1071 }
1072 }
1073 return INVALID_ID;
1074}
1075
q.huangec88da92022-03-29 04:17:32 -04001076int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1077{
q.huang52921662022-10-20 15:25:45 +08001078 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001079 {
q.huang52921662022-10-20 15:25:45 +08001080 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1081 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001082 }
q.huangec88da92022-03-29 04:17:32 -04001083 int lynq_call_id = 0;
q.huang70b76492022-06-02 14:49:02 +08001084 LYINFLOG("lynq_get_current_call_state begin ");
q.huangec88da92022-03-29 04:17:32 -04001085 if(handle==NULL)
1086 {
q.huang70b76492022-06-02 14:49:02 +08001087 LYERRLOG("handle is NULL");
q.huang52921662022-10-20 15:25:45 +08001088 return LYNQ_E_PARAMETER_ANONALY;
q.huangec88da92022-03-29 04:17:32 -04001089 }
llb3921072023-01-10 14:47:46 +08001090 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huang70b76492022-06-02 14:49:02 +08001091 lynq_call_id = find_call_id_with_call_id(*handle);
1092 if(lynq_call_id==INVALID_ID)
1093 {
llb3921072023-01-10 14:47:46 +08001094 //find end state
1095 if((*handle) >= 0)
1096 {
1097 *call_state = (int)LYNQ_CALL_END;
1098 return RESULT_OK;
1099 }
1100 else
1101 {
1102 return LYNQ_E_INVALID_ID_ANONALY;
1103 }
q.huang70b76492022-06-02 14:49:02 +08001104 }
q.huang52921662022-10-20 15:25:45 +08001105 *call_state = s_call_lists[lynq_call_id].call_state;
1106 *toa = s_call_lists[lynq_call_id].toa;
1107 *direction = s_call_lists[lynq_call_id].direction;
1108 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
llb3921072023-01-10 14:47:46 +08001109 return RESULT_OK;
q.huangec88da92022-03-29 04:17:32 -04001110}
1111
q.huange97cfcf2022-08-29 20:04:31 +08001112int lynq_get_current_call_number()
1113{
1114 int cnt=0;
1115 int i;
1116 for(i = 0;i < LYNQ_CALL_MAX;i++)
1117 {
q.huang52921662022-10-20 15:25:45 +08001118 if(s_call_lists[i].used !=0)
q.huange97cfcf2022-08-29 20:04:31 +08001119 {
1120 cnt++;
1121 }
1122 }
1123
1124 return cnt;
1125}
1126
q.huangec88da92022-03-29 04:17:32 -04001127/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001128static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001129 switch(enable){
1130 case 0:
q.huang52921662022-10-20 15:25:45 +08001131 return true;
llf512fa32022-02-14 08:58:16 +00001132 case 1:
q.huang52921662022-10-20 15:25:45 +08001133 return true;
llf512fa32022-02-14 08:58:16 +00001134 default:
q.huang52921662022-10-20 15:25:45 +08001135 return false;
lldc99c9b2022-01-24 12:16:22 +00001136 }
1137}
1138
lh7b0674a2022-01-10 00:34:35 -08001139int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001140{
q.huang52921662022-10-20 15:25:45 +08001141 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001142 {
q.huang52921662022-10-20 15:25:45 +08001143 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001144 return LYNQ_E_CONFLICT;
1145 }
q.huang52921662022-10-20 15:25:45 +08001146 if(!judge_mic(enable)){
1147 return LYNQ_E_PARAMETER_ANONALY;
1148 }
1149 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1150
1151 Parcel* p=NULL;
1152 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1153 if(ret==RESULT_OK)
1154 {
1155 delete p;
1156 }
1157 return ret;
q.huangec88da92022-03-29 04:17:32 -04001158}
1159int lynq_get_mute_mic(int *status)
1160{
q.huang52921662022-10-20 15:25:45 +08001161 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001162 {
q.huang52921662022-10-20 15:25:45 +08001163 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1164 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001165 }
q.huang52921662022-10-20 15:25:45 +08001166 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh7b0674a2022-01-10 00:34:35 -08001167}
ll72bf6c12022-03-24 10:22:25 +08001168
1169/**
1170 * @brief Check whether DTMF is valid
1171 *
1172 * @param callnum dtmf eg:0-9 * #
1173 * @return int
1174 */
1175static int judge_dtmf(const char callnum)
1176{
1177 if(callnum == '#')
1178 {
q.huang52921662022-10-20 15:25:45 +08001179 return true;
ll72bf6c12022-03-24 10:22:25 +08001180 }
1181 if(callnum == '*')
1182 {
q.huang52921662022-10-20 15:25:45 +08001183 return true;
ll72bf6c12022-03-24 10:22:25 +08001184 }
1185 if(callnum >= '0'&& callnum <= '9')
1186 {
q.huang52921662022-10-20 15:25:45 +08001187 return true;
ll72bf6c12022-03-24 10:22:25 +08001188 }
q.huang52921662022-10-20 15:25:45 +08001189 return false;
ll72bf6c12022-03-24 10:22:25 +08001190}
1191
ll209e6112022-07-20 09:30:19 +00001192int lynq_switch_waiting_or_holding_and_active(void)
1193{
q.huang52921662022-10-20 15:25:45 +08001194 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001195 {
q.huang52921662022-10-20 15:25:45 +08001196 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1197 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001198 }
q.huang52921662022-10-20 15:25:45 +08001199
1200 Parcel* p=NULL;
1201 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1202 if(ret==RESULT_OK)
1203 {
1204 delete p;
1205 }
1206 return ret;
1207
1208#if 0
ll209e6112022-07-20 09:30:19 +00001209 Parcel p;
1210 lynq_client_t client;
1211 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001212 int token;
ll209e6112022-07-20 09:30:19 +00001213 int request = -1;
1214 int slot_id = -1;
1215 int error = -1;
1216 client.uToken = Global_uToken_call;
1217 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1218 client.paramLen = 0;
1219 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1220 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001221 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001222 if(send_request(lynq_call_client_sockfd,&client)==-1)
1223 {
1224 LYERRLOG("send request fail");
1225 return -1;
1226 }
1227 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001228 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001229 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001230 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1231 return error;
q.huang52921662022-10-20 15:25:45 +08001232#endif
ll209e6112022-07-20 09:30:19 +00001233}
1234
1235int lynq_hangup_waiting_or_background(void)
1236{
q.huang52921662022-10-20 15:25:45 +08001237 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001238 {
q.huang52921662022-10-20 15:25:45 +08001239 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1240 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001241 }
q.huang52921662022-10-20 15:25:45 +08001242
1243 Parcel* p=NULL;
1244 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1245 if(ret==RESULT_OK)
1246 {
1247 delete p;
1248 }
1249 return ret;
1250#if 0
ll209e6112022-07-20 09:30:19 +00001251 Parcel p;
1252 lynq_client_t client;
1253 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001254 int token;
ll209e6112022-07-20 09:30:19 +00001255 int request = -1;
1256 int slot_id = -1;
1257 int error = -1;
1258 client.uToken = Global_uToken_call;
1259 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1260 client.paramLen = 0;
1261 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1262 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001263 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001264 if(send_request(lynq_call_client_sockfd,&client)==-1)
1265 {
1266 LYERRLOG("send request fail");
1267 return -1;
1268 }
1269 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001270 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001271 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001272 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1273 return error;
q.huang52921662022-10-20 15:25:45 +08001274#endif
ll209e6112022-07-20 09:30:19 +00001275}
1276
1277int lynq_hangup_foreground_resume_background(void)
1278{
q.huang52921662022-10-20 15:25:45 +08001279 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001280 {
q.huang52921662022-10-20 15:25:45 +08001281 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1282 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001283 }
q.huang52921662022-10-20 15:25:45 +08001284
1285 Parcel* p=NULL;
1286 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1287 if(ret==RESULT_OK)
1288 {
1289 delete p;
1290 }
1291 return ret;
1292#if 0
ll209e6112022-07-20 09:30:19 +00001293 Parcel p;
1294 lynq_client_t client;
1295 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001296 int token;
ll209e6112022-07-20 09:30:19 +00001297 int request = -1;
1298 int slot_id = -1;
1299 int error = -1;
1300 client.uToken = Global_uToken_call;
1301 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1302 client.paramLen = 0;
1303 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1304 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001305 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001306 if(send_request(lynq_call_client_sockfd,&client)==-1)
1307 {
1308 LYERRLOG("send request fail");
1309 return -1;
1310 }
1311 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001312 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001313 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001314 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1315 return error;
q.huang52921662022-10-20 15:25:45 +08001316#endif
ll209e6112022-07-20 09:30:19 +00001317}
1318
lh7b0674a2022-01-10 00:34:35 -08001319int lynq_set_DTMF(const char callnum)
1320{
q.huang52921662022-10-20 15:25:45 +08001321 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001322 {
q.huang52921662022-10-20 15:25:45 +08001323 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1324 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001325 }
ll72bf6c12022-03-24 10:22:25 +08001326 if(!judge_dtmf(callnum))
1327 {
1328 return LYNQ_E_CONFLICT;
1329 }
q.huang52921662022-10-20 15:25:45 +08001330 if(s_module_call_state!=CALL_ON)
lh7b0674a2022-01-10 00:34:35 -08001331 {
1332 LYERRLOG("LYNQ_E_CONFLICT");
1333 return LYNQ_E_CONFLICT;
1334 }
q.huang52921662022-10-20 15:25:45 +08001335
1336// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1337
1338 Parcel* p=NULL;
1339 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1340 if(ret==RESULT_OK)
1341 {
1342 delete p;
1343 }
1344 return ret;
lh7b0674a2022-01-10 00:34:35 -08001345}
q.huangec88da92022-03-29 04:17:32 -04001346static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1347 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1348 if(volume < 0 ||volume >36){
1349 return 0;
1350 }
1351 }
1352 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1353 {
1354 if(volume < 1 ||volume >7){
1355 return 0;
1356 }
lldc99c9b2022-01-24 12:16:22 +00001357 }
ll04ae4142022-01-27 05:54:38 +00001358 return 1;
lldc99c9b2022-01-24 12:16:22 +00001359}
lh7b0674a2022-01-10 00:34:35 -08001360int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001361{
q.huang52921662022-10-20 15:25:45 +08001362 if(g_module_init_flag != MODULE_RUNNING)
1363 {
1364 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001365 return LYNQ_E_CONFLICT;
1366 }
q.huang52921662022-10-20 15:25:45 +08001367 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1368 return LYNQ_E_PARAMETER_ANONALY;
1369 }
1370// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1371 Parcel* p=NULL;
1372 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1373 if(ret==RESULT_OK)
1374 {
1375 delete p;
1376 }
1377 return ret;
lh7b0674a2022-01-10 00:34:35 -08001378}
q.huangb212fde2022-04-05 23:11:02 -04001379int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001380{
q.huang52921662022-10-20 15:25:45 +08001381 if(g_module_init_flag != MODULE_RUNNING)
lh7b0674a2022-01-10 00:34:35 -08001382 {
q.huang52921662022-10-20 15:25:45 +08001383 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangec88da92022-03-29 04:17:32 -04001384 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001385 }
q.huang52921662022-10-20 15:25:45 +08001386 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1387 {
1388 return LYNQ_E_PARAMETER_ANONALY;
1389 }
1390// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1391 Parcel* p=NULL;
1392 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1393 if(ret==RESULT_OK)
1394 {
1395 delete p;
1396 }
1397 return ret;
lh7b0674a2022-01-10 00:34:35 -08001398}
q.huangec88da92022-03-29 04:17:32 -04001399int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1400{
q.huang52921662022-10-20 15:25:45 +08001401 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangec88da92022-03-29 04:17:32 -04001402}
q.huangb212fde2022-04-05 23:11:02 -04001403int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001404{
q.huang52921662022-10-20 15:25:45 +08001405// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1406 Parcel* p=NULL;
1407 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1408 if(ret==RESULT_OK)
1409 {
1410 delete p;
1411 }
1412 return ret;
q.huangec88da92022-03-29 04:17:32 -04001413}
1414int lynq_incall_record_stop()
1415{
q.huang52921662022-10-20 15:25:45 +08001416 if(g_module_init_flag != MODULE_RUNNING)
1417 {
1418 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1419 return LYNQ_E_CONFLICT;
1420 }
q.huangb212fde2022-04-05 23:11:02 -04001421 const char* unused_file="just_ocuupy_paramter_postion";
q.huang52921662022-10-20 15:25:45 +08001422// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1423 Parcel* p=NULL;
1424 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1425 if(ret==RESULT_OK)
1426 {
1427 delete p;
1428 }
1429 return ret;
q.huangec88da92022-03-29 04:17:32 -04001430}
1431/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001432
q.huang036b6cf2023-01-10 14:29:20 +08001433
1434
1435bool is_support_urc(int urc_id)
1436{
1437 switch(urc_id)
1438 {
1439 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1440 case RIL_UNSOL_CALL_RING:
1441 case RIL_UNSOL_RINGBACK_TONE:
1442 case RIL_UNSOL_CALL_INFO_INDICATION:
1443#ifdef ECALL_SUPPORT
1444 case RIL_UNSOL_ECALL_INDICATIONS://9502
1445#endif
1446 return true;
1447 default:
1448 return false;
1449 }
1450}
1451
q.huang52921662022-10-20 15:25:45 +08001452void urc_msg_process(Parcel *p)
1453{
1454 int resp_type;
1455 int urcid;
1456 int slot_id;
q.huang036b6cf2023-01-10 14:29:20 +08001457
1458 int size=p->dataSize();
q.huang52921662022-10-20 15:25:45 +08001459 p->readInt32(&resp_type);
1460 p->readInt32(&urcid);
1461 p->readInt32(&slot_id);
q.huang036b6cf2023-01-10 14:29:20 +08001462 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 +08001463 switch (urcid)
1464 {
1465 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1466 {
1467 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1468 lynqNoticeGetModuleCallList();
1469 break;
1470 }
1471 case RIL_UNSOL_CALL_RING: //1018
1472 {
1473 if(s_call_auto_answer==1)
1474 {
1475 lynq_call_answer();
1476 }
1477 break;
1478 }
1479 case RIL_UNSOL_RINGBACK_TONE: //1029
1480 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1481 {
1482 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1483 break;
1484 }
q.huang714145d2022-04-18 00:09:50 -04001485#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +08001486 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange97cfcf2022-08-29 20:04:31 +08001487 {
q.huang52921662022-10-20 15:25:45 +08001488 urc_ecall_msg_process(p);
q.huange97cfcf2022-08-29 20:04:31 +08001489 }
q.huange97cfcf2022-08-29 20:04:31 +08001490#endif
q.huang52921662022-10-20 15:25:45 +08001491 default:
1492 break;
q.huangcb7b7292022-06-28 20:12:01 +08001493 }
q.huang5ca6c072022-06-06 16:15:31 +08001494}
q.huang5ca6c072022-06-06 16:15:31 +08001495
lh7b0674a2022-01-10 00:34:35 -08001496#if 0
1497int main(int argc,char **argv)
1498{
1499 int n = 0;
1500 n = lynq_init_call(lynq_call_state_change_test,2222);
1501 if(n<0)
1502 {
q.huang70b76492022-06-02 14:49:02 +08001503 LYDBGLOG("lynq init call fail!!!");
lh7b0674a2022-01-10 00:34:35 -08001504 return -1;
1505 }
q.huang70b76492022-06-02 14:49:02 +08001506 LYDBGLOG("lynq call init success!!!");
lh7b0674a2022-01-10 00:34:35 -08001507 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1508 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1509 lynq_call(phoneNum);
1510 while(1)
1511 {
1512 sleep(1);
1513 }
1514 return 0;
1515}
1516#endif
1517/*Warren add for T800 platform 2021/11/19 end*/