blob: 10a4ea0fbf298909d5df1f2a91b578d1acbf536f [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
530 }
lh7b0674a2022-01-10 00:34:35 -0800531 }
532 else
q.huang70b76492022-06-02 14:49:02 +0800533 {
534 LYINFLOG("This is a MO CALL");
535 call_end = 0;
536 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh7b0674a2022-01-10 00:34:35 -0800537 {
q.huang52921662022-10-20 15:25:45 +0800538 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 -0800539 {
llb3921072023-01-10 14:47:46 +0800540 s_CallId = call_list[i].call_id;
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
q.huang70b76492022-06-02 14:49:02 +0800545 }
q.huang52921662022-10-20 15:25:45 +0800546 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);
547 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 +0800548 call_end = 1;
llb3921072023-01-10 14:47:46 +0800549 send_call_state_change();//means mo call is success
q.huang70b76492022-06-02 14:49:02 +0800550 break;
551 }
552 }
llb3921072023-01-10 14:47:46 +0800553 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 +0800554 {
555 LYINFLOG("need to hangup id %d", call_list[i].call_id);
556#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +0800557 if(IsECallDialing())
q.huang70b76492022-06-02 14:49:02 +0800558 {
559 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh7b0674a2022-01-10 00:34:35 -0800560 continue;
561 }
q.huang70b76492022-06-02 14:49:02 +0800562#endif
563 LYINFLOG("hang up service call id %d",call_list[i].call_id);
564 lynq_call_hungup(&(call_list[i].call_id));
lh7b0674a2022-01-10 00:34:35 -0800565 }
llb3921072023-01-10 14:47:46 +0800566
lh7b0674a2022-01-10 00:34:35 -0800567 }
q.huang70b76492022-06-02 14:49:02 +0800568 LYDBGLOG("servie idx %d end",i);
ll04ae4142022-01-27 05:54:38 +0000569 }
q.huang52921662022-10-20 15:25:45 +0800570 LYINFLOG("add or update local index end ");
571 if(s_module_isDial==1)
lh7b0674a2022-01-10 00:34:35 -0800572 {
q.huang70b76492022-06-02 14:49:02 +0800573 LYINFLOG("now is dialing");
574 if(update==1)
575 {
576 LYINFLOG("find added call");
577 sendSignalToWaitCallStateChange();
q.huang52921662022-10-20 15:25:45 +0800578 s_module_isDial = 0;
q.huang70b76492022-06-02 14:49:02 +0800579 }
580 else
581 {
582 LYINFLOG("not find added call");
583 }
584 }
585 else
586 {
587 LYINFLOG("now is not dialing");
q.huang52921662022-10-20 15:25:45 +0800588 }
ll04ae4142022-01-27 05:54:38 +0000589 }
q.huang52921662022-10-20 15:25:45 +0800590 pthread_cleanup_pop(0);
591 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
ll04ae4142022-01-27 05:54:38 +0000592 return NULL;
lh7b0674a2022-01-10 00:34:35 -0800593}
594
q.huang52921662022-10-20 15:25:45 +0800595void lynqNoticeGetModuleCallList()
ll04ae4142022-01-27 05:54:38 +0000596{
q.huang52921662022-10-20 15:25:45 +0800597 pthread_mutex_lock(&s_notice_get_call_list_mutex);
598 pthread_cond_signal(&s_notice_get_call_list_cond);
599 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
600
lh7b0674a2022-01-10 00:34:35 -0800601}
602
q.huang52921662022-10-20 15:25:45 +0800603#if 0
lh7b0674a2022-01-10 00:34:35 -0800604/*Warren add for T800 platform 2021/11/19 start*/
605int lynq_socket_client_start()
rjw5d2a50e2022-02-28 15:01:49 +0800606{
607 #if 0
lh7b0674a2022-01-10 00:34:35 -0800608 struct sockaddr_in lynq_socket_server_addr;
609 /* init lynq_socket_server_addr */
610 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
611 lynq_socket_server_addr.sin_family = AF_INET;
612 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
613 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw5d2a50e2022-02-28 15:01:49 +0800614
lh7b0674a2022-01-10 00:34:35 -0800615 /*
616 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
617 {
q.huang70b76492022-06-02 14:49:02 +0800618 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh7b0674a2022-01-10 00:34:35 -0800619 exit(1);
620 }
621*/
lh42c1e572022-01-25 18:47:39 -0800622 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
623 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh7b0674a2022-01-10 00:34:35 -0800624 {
q.huang70b76492022-06-02 14:49:02 +0800625 LYERRLOG("connect error");
lh7b0674a2022-01-10 00:34:35 -0800626 return -1;
627 }
rjw5d2a50e2022-02-28 15:01:49 +0800628 #endif
629 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
630 if (-1 == lynq_call_client_sockfd)
631 {
632 return lynq_call_client_sockfd;
633 }
ll630be412022-07-25 05:52:14 +0000634 struct timeval timeOut;
635 timeOut.tv_sec = 60;
636 timeOut.tv_usec = 0;
637 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
638 {
639 RLOGD("time out setting failed\n");
640 return -1;
641 }
rjw5d2a50e2022-02-28 15:01:49 +0800642 /* 设置address */
643 memset(&addr_serv, 0, sizeof(addr_serv));
644 addr_serv.sin_family = AF_INET;
645 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
646 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
647 len_addr_serv = sizeof(addr_serv);
lh7b0674a2022-01-10 00:34:35 -0800648 return 0;
649}
lh7b0674a2022-01-10 00:34:35 -0800650
lh7b0674a2022-01-10 00:34:35 -0800651int lynq_socket_urc_start()
652{
653 int socket_fd=0;
654 int rt=0;
655 int len=0;
656 int on=1;
657 struct sockaddr_in urc_local_addr;
lh7b0674a2022-01-10 00:34:35 -0800658 pthread_attr_t attr;
ll04ae4142022-01-27 05:54:38 +0000659 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll04ae4142022-01-27 05:54:38 +0000660 if(socket_fd < 0)
661 {
q.huang70b76492022-06-02 14:49:02 +0800662 LYERRLOG("creaet socket for udp fail");
ll04ae4142022-01-27 05:54:38 +0000663 return -1;
lh7b0674a2022-01-10 00:34:35 -0800664 }
665 urc_local_addr.sin_family = AF_INET;
666 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
667 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
668 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll04ae4142022-01-27 05:54:38 +0000669 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
670 if(rt<0)
671 {
q.huang70b76492022-06-02 14:49:02 +0800672 LYERRLOG("SO_REUSEADDR fail");
lh7b0674a2022-01-10 00:34:35 -0800673 return -1;
674 }
675 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll04ae4142022-01-27 05:54:38 +0000676 if (rt == -1)
677 {
lh21502f52022-01-27 00:27:12 -0800678 LYERRLOG("bind failed");
ll04ae4142022-01-27 05:54:38 +0000679 return -1;
lh7b0674a2022-01-10 00:34:35 -0800680 }
681 pthread_attr_init(&attr);
682 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhec17b0a2022-02-13 23:56:05 -0800683 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh7b0674a2022-01-10 00:34:35 -0800684 if(rt < 0)
685 {
q.huang70b76492022-06-02 14:49:02 +0800686 LYERRLOG("urc loop failure!!!");
lh7b0674a2022-01-10 00:34:35 -0800687 return -1;
688 }
q.huang70b76492022-06-02 14:49:02 +0800689 LYDBGLOG("urc loop success!!!");
lh7b0674a2022-01-10 00:34:35 -0800690 return 0;
691}
q.huang52921662022-10-20 15:25:45 +0800692#endif
lh7b0674a2022-01-10 00:34:35 -0800693
694void lynq_call_state_change_test(int soc_id)
695{
q.huang70b76492022-06-02 14:49:02 +0800696 LYDBGLOG("call state change,sim:%d",soc_id);
lh7b0674a2022-01-10 00:34:35 -0800697}
q.huangcb7b7292022-06-28 20:12:01 +0800698
q.huang52921662022-10-20 15:25:45 +0800699int lynq_start_call_list_loop()
700{
701#if 0
702 int ret = 0;
703 pthread_attr_t attr;
704 pthread_attr_init(&attr);
705 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
q.huangcb7b7292022-06-28 20:12:01 +0800706
q.huang52921662022-10-20 15:25:45 +0800707 s_notice_get_call_list_mutex = new pthread_mutex_t;
708 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
709 s_notice_get_call_list_cond = new pthread_cond_t;
710 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
711 pthread_cond_init(s_notice_get_call_list_cond, NULL);
712 LYINFLOG("liulei s_notice_get_call_list_cond\n");
713#endif
q.huangcb7b7292022-06-28 20:12:01 +0800714
q.huang52921662022-10-20 15:25:45 +0800715 s_call_list_loop = 1;
716 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
717 if(ret < 0)
q.huangcb7b7292022-06-28 20:12:01 +0800718 {
q.huang52921662022-10-20 15:25:45 +0800719 LYERRLOG("lynq_update_call_list_loop fail!!!");
lla8c25a82022-03-17 05:31:33 +0000720 return -1;
721 }
q.huang52921662022-10-20 15:25:45 +0800722 LYINFLOG("lynq_update_call_list_loop success!!!");
q.huangcb7b7292022-06-28 20:12:01 +0800723
q.huang52921662022-10-20 15:25:45 +0800724 memset(s_call_lists,0,sizeof(s_call_lists));
lh7b0674a2022-01-10 00:34:35 -0800725 return 0;
726}
q.huang52921662022-10-20 15:25:45 +0800727
728int lynq_stop_call_list_loop()
lh7b0674a2022-01-10 00:34:35 -0800729{
q.huang70b76492022-06-02 14:49:02 +0800730 int ret;
q.huang52921662022-10-20 15:25:45 +0800731 pthread_mutex_lock(&s_notice_get_call_list_mutex);
732 s_call_list_loop = 0;
733 ret = pthread_cancel(s_call_list_loop_tid);
734 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
735 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
736 ret = pthread_join(s_call_list_loop_tid,NULL);
737 LYINFLOG("pthread join w_c_list ret = %d",ret);
738 s_call_list_loop_tid=-1;
739#if 0
740 pthread_mutex_destroy(s_notice_get_call_list_mutex);
741 pthread_cond_destroy(s_notice_get_call_list_cond);
742 delete s_notice_get_call_list_mutex;
743 //s_notice_get_call_list_mutex = NULL;
744 delete s_notice_get_call_list_cond;
745 //s_notice_get_call_list_cond = NULL;
746#endif
747
748 return 0;
rita98e2e9c2022-04-07 06:08:13 -0400749}
q.huang714145d2022-04-18 00:09:50 -0400750
q.huang52921662022-10-20 15:25:45 +0800751int lynq_init_call(int utoken){
752 if(g_module_init_flag != MODULE_CLOSED)
753 {
754 LYERRLOG("module state is %d",g_module_init_flag);
755 return LYNQ_E_CONFLICT;
756 }
757 if(utoken <0){
758 LYERRLOG("utoken is less than 0",utoken);
759 return LYNQ_E_PARAMETER_ANONALY;
760 }
761 g_module_init_flag = MODULE_SWITCHING;
762
763 LYLOGSET(LOG_INFO);
764 LYLOGEINIT(USER_LOG_TAG);
765
766 g_module_Global_uToken = utoken;
767
q.huang036b6cf2023-01-10 14:29:20 +0800768 int ret = lynq_start_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800769 if(ret != RESULT_OK)
770 {
771 LYERRLOG("init socket urc fail!!!");
772 g_module_init_flag = MODULE_CLOSED;
773 return LYNQ_E_INNER_ERROR;
774 }
775
q.huang036b6cf2023-01-10 14:29:20 +0800776 ret = lynq_start_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800777 if(ret !=RESULT_OK)
778 {
779 LYERRLOG("init socket client fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800780 lynq_close_all_urc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800781 g_module_init_flag = MODULE_CLOSED;
782 return LYNQ_E_INNER_ERROR;
783 }
784
785
786 int result = lynq_start_call_list_loop();
787 if(ret != RESULT_OK)
788 {
789 LYERRLOG("lynq_start_call_list_loop fail!!!");
q.huang036b6cf2023-01-10 14:29:20 +0800790 lynq_close_all_urc_socket_thread();
791 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800792 g_module_init_flag = MODULE_CLOSED;
793 return LYNQ_E_INNER_ERROR;
794 }
795
796 lynq_init_rtp();
797
798 g_module_init_flag = MODULE_RUNNING;
799 return 0;
800}
801
802int lynq_deinit_call(void){
803
804 if (g_module_init_flag != MODULE_RUNNING)
805 {
806 LYERRLOG("module state is %d",g_module_init_flag);
807 return LYNQ_E_CONFLICT;
808 }
809 lynq_call_hungup_all();
810 lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
811 g_module_init_flag = MODULE_SWITCHING;
q.huang036b6cf2023-01-10 14:29:20 +0800812 lynq_close_all_urc_socket_thread();
813 lynq_close_all_rc_socket_thread();
q.huang52921662022-10-20 15:25:45 +0800814 lynq_stop_call_list_loop();
815 g_module_init_flag = MODULE_CLOSED;
816 return 0;
817}
818
819#if 0
q.huang714145d2022-04-18 00:09:50 -0400820int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita089527e2022-04-07 01:55:39 -0400821{
822 Parcel p;
823 lynq_client_t client;
824 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800825 int token;
rita089527e2022-04-07 01:55:39 -0400826 int request = -1;
827 int slot_id = -1;
828 int error = -1;
rita089527e2022-04-07 01:55:39 -0400829
q.huang52921662022-10-20 15:25:45 +0800830 Parcel* p=NULL;
831 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
832 if(ret==RESULT_OK)
833 {
834 delete p;
835 }
836 return ret;
837
rita089527e2022-04-07 01:55:39 -0400838 client.uToken = Global_uToken_call;
q.huang714145d2022-04-18 00:09:50 -0400839 client.request = request_id;
840 client.paramLen = argc;
rita089527e2022-04-07 01:55:39 -0400841 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang714145d2022-04-18 00:09:50 -0400842 if(argc!=0)
843 {
844 va_list args;
845 va_start(args, format);
846 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
847 va_end(args);
848 }
q.huang70b76492022-06-02 14:49:02 +0800849 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita089527e2022-04-07 01:55:39 -0400850 if(send_request(lynq_call_client_sockfd,&client)==-1)
851 {
852 LYERRLOG("send request fail");
853 return -1;
854 }
q.huang714145d2022-04-18 00:09:50 -0400855 if(get_response(lynq_call_client_sockfd,p)==0)
856 {
q.huang7de1d662022-09-13 14:19:24 +0800857 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang714145d2022-04-18 00:09:50 -0400858 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
859 }
rita089527e2022-04-07 01:55:39 -0400860 return error;
q.huang52921662022-10-20 15:25:45 +0800861
862
rita089527e2022-04-07 01:55:39 -0400863}
q.huang52921662022-10-20 15:25:45 +0800864#endif
rita089527e2022-04-07 01:55:39 -0400865
q.huang714145d2022-04-18 00:09:50 -0400866int lynq_get_common_request(int request_id, int* status)
rita089527e2022-04-07 01:55:39 -0400867{
q.huang714145d2022-04-18 00:09:50 -0400868 if(status==NULL)
869 {
870 LYERRLOG("status is null");
q.huang52921662022-10-20 15:25:45 +0800871 return LYNQ_E_PARAMETER_ANONALY;
q.huang714145d2022-04-18 00:09:50 -0400872 }
q.huang52921662022-10-20 15:25:45 +0800873
874 Parcel* p=NULL;
875 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
876 if(ret==RESULT_OK)
rita089527e2022-04-07 01:55:39 -0400877 {
q.huang52921662022-10-20 15:25:45 +0800878 p->readInt32(status);
879 delete p;
rita089527e2022-04-07 01:55:39 -0400880 }
q.huang52921662022-10-20 15:25:45 +0800881 return ret;
882}
883
884int waitCallstateChange(int mtime)
885{
886 LYINFLOG("wait Call state Change");
887 int ret = 0;
888 int sec = 0;
889 int usec = 0;
890 struct timeval now;
891 struct timespec timeout;
892 gettimeofday(&now,NULL);
893 sec = mtime/1000;
894 usec = mtime%1000;
895 timeout.tv_sec = now.tv_sec+sec;
896 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
897 pthread_mutex_lock(&call_state_change_mutex);
898 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
899 pthread_mutex_unlock(&call_state_change_mutex);
900 return ret;
901}
902
903int IsNormalCallDailing()
904{
905 return s_module_isDial;
rita089527e2022-04-07 01:55:39 -0400906}
907
llb3921072023-01-10 14:47:46 +0800908
lh7b0674a2022-01-10 00:34:35 -0800909int lynq_call(int* handle,char addr[])
910{
q.huang52921662022-10-20 15:25:45 +0800911 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700912 {
q.huang52921662022-10-20 15:25:45 +0800913 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
914 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -0700915 }
q.huang52921662022-10-20 15:25:45 +0800916
lh7b0674a2022-01-10 00:34:35 -0800917 int lynq_call_id = -1;
q.huang70b76492022-06-02 14:49:02 +0800918
919 LYINFLOG("lynq_call begin addr %s",addr);
lh7b0674a2022-01-10 00:34:35 -0800920 if(addr==NULL)
921 {
922 LYERRLOG("Phone num is null!!!");
q.huang52921662022-10-20 15:25:45 +0800923 return LYNQ_E_PARAMETER_ANONALY;
lh7b0674a2022-01-10 00:34:35 -0800924 }
q.huang70b76492022-06-02 14:49:02 +0800925
926 if(find_call_id_with_addr(addr)!=INVALID_ID)
927 {
928 LYERRLOG("addr %s exists",addr);
929 return LYNQ_E_CONFLICT;
930 }
931
932#ifdef ECALL_SUPPORT
933 if(lynq_ecall_is_running())
934 {
935 LYERRLOG("lynq_fast_ecall ecall is running");
936 return LYNQ_E_ECALL_BEING_RUNNING;
937 }
938#endif
q.huang52921662022-10-20 15:25:45 +0800939 Parcel* p=NULL;
940 lynq_call_id = addAddr(addr,0);
941 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
942 if(ret!=0)
943 {
llb3921072023-01-10 14:47:46 +0800944 cleanCallList(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +0800945 return ret;
llb3921072023-01-10 14:47:46 +0800946 }
947 delete p;
q.huang52921662022-10-20 15:25:45 +0800948 s_module_isDial = 1;
949 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh7b0674a2022-01-10 00:34:35 -0800950 {
q.huang52921662022-10-20 15:25:45 +0800951 //if timeout,this call need destroy.
952 s_module_isDial = 0;
953 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
llb3921072023-01-10 14:47:46 +0800954 cleanCallList(lynq_call_id);
q.huang52921662022-10-20 15:25:45 +0800955 return LYNQ_E_TIME_OUT;
lh7b0674a2022-01-10 00:34:35 -0800956 }
q.huang52921662022-10-20 15:25:45 +0800957 s_module_isDial = 0;
958 *handle = s_call_lists[lynq_call_id].call_id;
959 if(*handle > 0)
lh7b0674a2022-01-10 00:34:35 -0800960 {
q.huang52921662022-10-20 15:25:45 +0800961 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
962 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -0800963 }
q.huang52921662022-10-20 15:25:45 +0800964 else
965 {
966 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
967 cleanCallList(lynq_call_id);
968 return LYNQ_E_INVALID_ID_ANONALY;
llb3921072023-01-10 14:47:46 +0800969 }
lh7b0674a2022-01-10 00:34:35 -0800970}
llb3921072023-01-10 14:47:46 +0800971
lh7b0674a2022-01-10 00:34:35 -0800972int lynq_call_answer()
973{
q.huang52921662022-10-20 15:25:45 +0800974 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700975 {
q.huang52921662022-10-20 15:25:45 +0800976 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
977 return LYNQ_E_CONFLICT;
978 }
979
980 Parcel* p=NULL;
981 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
982 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -0800983 {
q.huang52921662022-10-20 15:25:45 +0800984 delete p;
985 }
986 return ret;
lh7b0674a2022-01-10 00:34:35 -0800987}
llb3921072023-01-10 14:47:46 +0800988
lh7b0674a2022-01-10 00:34:35 -0800989int lynq_call_hungup(int* handle)
990{
q.huang52921662022-10-20 15:25:45 +0800991 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700992 {
q.huang52921662022-10-20 15:25:45 +0800993 return LYNQ_E_CONFLICT;
994 }
995
lh42c1e572022-01-25 18:47:39 -0800996 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
997 {
q.huang52921662022-10-20 15:25:45 +0800998 LYERRLOG("%s illegal input!!!!",__func__);
999 return LYNQ_E_PARAMETER_ANONALY;
lh42c1e572022-01-25 18:47:39 -08001000 }
q.huang52921662022-10-20 15:25:45 +08001001
1002 int call_id = *handle;
1003 Parcel* p=NULL;
1004 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1005 if(ret!=0)
lh7b0674a2022-01-10 00:34:35 -08001006 {
q.huang52921662022-10-20 15:25:45 +08001007 return ret;
1008 }
1009 delete p;
1010
1011 int lynq_call_id=find_call_id_with_call_id(call_id);
1012 if(lynq_call_id!=INVALID_ID)
lh7b0674a2022-01-10 00:34:35 -08001013 {
q.huang52921662022-10-20 15:25:45 +08001014 cleanCallList(lynq_call_id);
1015 }
1016
1017 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001018}
1019int lynq_call_hungup_all()
1020{
q.huang52921662022-10-20 15:25:45 +08001021 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001022 {
q.huang52921662022-10-20 15:25:45 +08001023 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1024 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001025 }
q.huang52921662022-10-20 15:25:45 +08001026
1027 Parcel* p=NULL;
1028 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1029 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001030 {
q.huang52921662022-10-20 15:25:45 +08001031 delete p;
1032 }
1033 return ret;
lh7b0674a2022-01-10 00:34:35 -08001034}
llb3921072023-01-10 14:47:46 +08001035
1036int lynq_wait_call_state_change(int *handle)
lh7b0674a2022-01-10 00:34:35 -08001037{
q.huang52921662022-10-20 15:25:45 +08001038 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001039 {
q.huang52921662022-10-20 15:25:45 +08001040 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1041 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001042 }
llb3921072023-01-10 14:47:46 +08001043 wait_call_state();
1044 *handle = s_CallId;
1045 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1046 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001047}
1048
1049int lynq_set_auto_answercall(const int mode)
1050{
q.huang52921662022-10-20 15:25:45 +08001051 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001052 {
q.huang52921662022-10-20 15:25:45 +08001053 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1054 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001055 }
q.huang52921662022-10-20 15:25:45 +08001056 s_call_auto_answer = mode;
lh7b0674a2022-01-10 00:34:35 -08001057 LYINFLOG("auto answer call mode =%d",mode);
q.huang52921662022-10-20 15:25:45 +08001058 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001059}
llb3921072023-01-10 14:47:46 +08001060
1061int lynq_find_already_end()
1062{
1063 for(int i=0;i < LYNQ_CALL_MAX; i++)
1064 {
1065 if(s_call_lists[i].call_state == 6)
1066 {
1067 return 0;
1068 }
1069 }
1070 return INVALID_ID;
1071}
1072
q.huangec88da92022-03-29 04:17:32 -04001073int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1074{
q.huang52921662022-10-20 15:25:45 +08001075 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001076 {
q.huang52921662022-10-20 15:25:45 +08001077 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1078 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001079 }
q.huangec88da92022-03-29 04:17:32 -04001080 int lynq_call_id = 0;
q.huang70b76492022-06-02 14:49:02 +08001081 LYINFLOG("lynq_get_current_call_state begin ");
q.huangec88da92022-03-29 04:17:32 -04001082 if(handle==NULL)
1083 {
q.huang70b76492022-06-02 14:49:02 +08001084 LYERRLOG("handle is NULL");
q.huang52921662022-10-20 15:25:45 +08001085 return LYNQ_E_PARAMETER_ANONALY;
q.huangec88da92022-03-29 04:17:32 -04001086 }
llb3921072023-01-10 14:47:46 +08001087 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huang70b76492022-06-02 14:49:02 +08001088 lynq_call_id = find_call_id_with_call_id(*handle);
1089 if(lynq_call_id==INVALID_ID)
1090 {
llb3921072023-01-10 14:47:46 +08001091 if(lynq_find_already_end)
1092 {
1093 LYINFLOG("not end update\n ");
1094 return LYNQ_E_INVALID_ID_ANONALY;
1095 }
1096 //find end state
1097 if((*handle) >= 0)
1098 {
1099 *call_state = (int)LYNQ_CALL_END;
1100 return RESULT_OK;
1101 }
1102 else
1103 {
1104 return LYNQ_E_INVALID_ID_ANONALY;
1105 }
q.huang70b76492022-06-02 14:49:02 +08001106 }
q.huang52921662022-10-20 15:25:45 +08001107 *call_state = s_call_lists[lynq_call_id].call_state;
1108 *toa = s_call_lists[lynq_call_id].toa;
1109 *direction = s_call_lists[lynq_call_id].direction;
1110 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
llb3921072023-01-10 14:47:46 +08001111 return RESULT_OK;
q.huangec88da92022-03-29 04:17:32 -04001112}
1113
q.huange97cfcf2022-08-29 20:04:31 +08001114int lynq_get_current_call_number()
1115{
1116 int cnt=0;
1117 int i;
1118 for(i = 0;i < LYNQ_CALL_MAX;i++)
1119 {
q.huang52921662022-10-20 15:25:45 +08001120 if(s_call_lists[i].used !=0)
q.huange97cfcf2022-08-29 20:04:31 +08001121 {
1122 cnt++;
1123 }
1124 }
1125
1126 return cnt;
1127}
1128
q.huangec88da92022-03-29 04:17:32 -04001129/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001130static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001131 switch(enable){
1132 case 0:
q.huang52921662022-10-20 15:25:45 +08001133 return true;
llf512fa32022-02-14 08:58:16 +00001134 case 1:
q.huang52921662022-10-20 15:25:45 +08001135 return true;
llf512fa32022-02-14 08:58:16 +00001136 default:
q.huang52921662022-10-20 15:25:45 +08001137 return false;
lldc99c9b2022-01-24 12:16:22 +00001138 }
1139}
1140
lh7b0674a2022-01-10 00:34:35 -08001141int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001142{
q.huang52921662022-10-20 15:25:45 +08001143 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001144 {
q.huang52921662022-10-20 15:25:45 +08001145 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001146 return LYNQ_E_CONFLICT;
1147 }
q.huang52921662022-10-20 15:25:45 +08001148 if(!judge_mic(enable)){
1149 return LYNQ_E_PARAMETER_ANONALY;
1150 }
1151 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1152
1153 Parcel* p=NULL;
1154 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1155 if(ret==RESULT_OK)
1156 {
1157 delete p;
1158 }
1159 return ret;
q.huangec88da92022-03-29 04:17:32 -04001160}
1161int lynq_get_mute_mic(int *status)
1162{
q.huang52921662022-10-20 15:25:45 +08001163 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001164 {
q.huang52921662022-10-20 15:25:45 +08001165 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1166 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001167 }
q.huang52921662022-10-20 15:25:45 +08001168 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh7b0674a2022-01-10 00:34:35 -08001169}
ll72bf6c12022-03-24 10:22:25 +08001170
1171/**
1172 * @brief Check whether DTMF is valid
1173 *
1174 * @param callnum dtmf eg:0-9 * #
1175 * @return int
1176 */
1177static int judge_dtmf(const char callnum)
1178{
1179 if(callnum == '#')
1180 {
q.huang52921662022-10-20 15:25:45 +08001181 return true;
ll72bf6c12022-03-24 10:22:25 +08001182 }
1183 if(callnum == '*')
1184 {
q.huang52921662022-10-20 15:25:45 +08001185 return true;
ll72bf6c12022-03-24 10:22:25 +08001186 }
1187 if(callnum >= '0'&& callnum <= '9')
1188 {
q.huang52921662022-10-20 15:25:45 +08001189 return true;
ll72bf6c12022-03-24 10:22:25 +08001190 }
q.huang52921662022-10-20 15:25:45 +08001191 return false;
ll72bf6c12022-03-24 10:22:25 +08001192}
1193
ll209e6112022-07-20 09:30:19 +00001194int lynq_switch_waiting_or_holding_and_active(void)
1195{
q.huang52921662022-10-20 15:25:45 +08001196 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001197 {
q.huang52921662022-10-20 15:25:45 +08001198 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1199 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001200 }
q.huang52921662022-10-20 15:25:45 +08001201
1202 Parcel* p=NULL;
1203 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1204 if(ret==RESULT_OK)
1205 {
1206 delete p;
1207 }
1208 return ret;
1209
1210#if 0
ll209e6112022-07-20 09:30:19 +00001211 Parcel p;
1212 lynq_client_t client;
1213 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001214 int token;
ll209e6112022-07-20 09:30:19 +00001215 int request = -1;
1216 int slot_id = -1;
1217 int error = -1;
1218 client.uToken = Global_uToken_call;
1219 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1220 client.paramLen = 0;
1221 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1222 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001223 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001224 if(send_request(lynq_call_client_sockfd,&client)==-1)
1225 {
1226 LYERRLOG("send request fail");
1227 return -1;
1228 }
1229 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001230 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001231 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001232 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1233 return error;
q.huang52921662022-10-20 15:25:45 +08001234#endif
ll209e6112022-07-20 09:30:19 +00001235}
1236
1237int lynq_hangup_waiting_or_background(void)
1238{
q.huang52921662022-10-20 15:25:45 +08001239 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001240 {
q.huang52921662022-10-20 15:25:45 +08001241 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1242 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001243 }
q.huang52921662022-10-20 15:25:45 +08001244
1245 Parcel* p=NULL;
1246 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1247 if(ret==RESULT_OK)
1248 {
1249 delete p;
1250 }
1251 return ret;
1252#if 0
ll209e6112022-07-20 09:30:19 +00001253 Parcel p;
1254 lynq_client_t client;
1255 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001256 int token;
ll209e6112022-07-20 09:30:19 +00001257 int request = -1;
1258 int slot_id = -1;
1259 int error = -1;
1260 client.uToken = Global_uToken_call;
1261 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1262 client.paramLen = 0;
1263 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1264 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001265 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001266 if(send_request(lynq_call_client_sockfd,&client)==-1)
1267 {
1268 LYERRLOG("send request fail");
1269 return -1;
1270 }
1271 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001272 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001273 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001274 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1275 return error;
q.huang52921662022-10-20 15:25:45 +08001276#endif
ll209e6112022-07-20 09:30:19 +00001277}
1278
1279int lynq_hangup_foreground_resume_background(void)
1280{
q.huang52921662022-10-20 15:25:45 +08001281 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001282 {
q.huang52921662022-10-20 15:25:45 +08001283 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1284 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001285 }
q.huang52921662022-10-20 15:25:45 +08001286
1287 Parcel* p=NULL;
1288 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1289 if(ret==RESULT_OK)
1290 {
1291 delete p;
1292 }
1293 return ret;
1294#if 0
ll209e6112022-07-20 09:30:19 +00001295 Parcel p;
1296 lynq_client_t client;
1297 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001298 int token;
ll209e6112022-07-20 09:30:19 +00001299 int request = -1;
1300 int slot_id = -1;
1301 int error = -1;
1302 client.uToken = Global_uToken_call;
1303 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1304 client.paramLen = 0;
1305 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1306 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001307 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001308 if(send_request(lynq_call_client_sockfd,&client)==-1)
1309 {
1310 LYERRLOG("send request fail");
1311 return -1;
1312 }
1313 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001314 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001315 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001316 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1317 return error;
q.huang52921662022-10-20 15:25:45 +08001318#endif
ll209e6112022-07-20 09:30:19 +00001319}
1320
lh7b0674a2022-01-10 00:34:35 -08001321int lynq_set_DTMF(const char callnum)
1322{
q.huang52921662022-10-20 15:25:45 +08001323 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001324 {
q.huang52921662022-10-20 15:25:45 +08001325 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1326 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001327 }
ll72bf6c12022-03-24 10:22:25 +08001328 if(!judge_dtmf(callnum))
1329 {
1330 return LYNQ_E_CONFLICT;
1331 }
q.huang52921662022-10-20 15:25:45 +08001332 if(s_module_call_state!=CALL_ON)
lh7b0674a2022-01-10 00:34:35 -08001333 {
1334 LYERRLOG("LYNQ_E_CONFLICT");
1335 return LYNQ_E_CONFLICT;
1336 }
q.huang52921662022-10-20 15:25:45 +08001337
1338// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1339
1340 Parcel* p=NULL;
1341 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1342 if(ret==RESULT_OK)
1343 {
1344 delete p;
1345 }
1346 return ret;
lh7b0674a2022-01-10 00:34:35 -08001347}
q.huangec88da92022-03-29 04:17:32 -04001348static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1349 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1350 if(volume < 0 ||volume >36){
1351 return 0;
1352 }
1353 }
1354 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1355 {
1356 if(volume < 1 ||volume >7){
1357 return 0;
1358 }
lldc99c9b2022-01-24 12:16:22 +00001359 }
ll04ae4142022-01-27 05:54:38 +00001360 return 1;
lldc99c9b2022-01-24 12:16:22 +00001361}
lh7b0674a2022-01-10 00:34:35 -08001362int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001363{
q.huang52921662022-10-20 15:25:45 +08001364 if(g_module_init_flag != MODULE_RUNNING)
1365 {
1366 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001367 return LYNQ_E_CONFLICT;
1368 }
q.huang52921662022-10-20 15:25:45 +08001369 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1370 return LYNQ_E_PARAMETER_ANONALY;
1371 }
1372// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1373 Parcel* p=NULL;
1374 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1375 if(ret==RESULT_OK)
1376 {
1377 delete p;
1378 }
1379 return ret;
lh7b0674a2022-01-10 00:34:35 -08001380}
q.huangb212fde2022-04-05 23:11:02 -04001381int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001382{
q.huang52921662022-10-20 15:25:45 +08001383 if(g_module_init_flag != MODULE_RUNNING)
lh7b0674a2022-01-10 00:34:35 -08001384 {
q.huang52921662022-10-20 15:25:45 +08001385 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangec88da92022-03-29 04:17:32 -04001386 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001387 }
q.huang52921662022-10-20 15:25:45 +08001388 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1389 {
1390 return LYNQ_E_PARAMETER_ANONALY;
1391 }
1392// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1393 Parcel* p=NULL;
1394 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1395 if(ret==RESULT_OK)
1396 {
1397 delete p;
1398 }
1399 return ret;
lh7b0674a2022-01-10 00:34:35 -08001400}
q.huangec88da92022-03-29 04:17:32 -04001401int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1402{
q.huang52921662022-10-20 15:25:45 +08001403 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangec88da92022-03-29 04:17:32 -04001404}
q.huangb212fde2022-04-05 23:11:02 -04001405int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001406{
q.huang52921662022-10-20 15:25:45 +08001407// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1408 Parcel* p=NULL;
1409 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1410 if(ret==RESULT_OK)
1411 {
1412 delete p;
1413 }
1414 return ret;
q.huangec88da92022-03-29 04:17:32 -04001415}
1416int lynq_incall_record_stop()
1417{
q.huang52921662022-10-20 15:25:45 +08001418 if(g_module_init_flag != MODULE_RUNNING)
1419 {
1420 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1421 return LYNQ_E_CONFLICT;
1422 }
q.huangb212fde2022-04-05 23:11:02 -04001423 const char* unused_file="just_ocuupy_paramter_postion";
q.huang52921662022-10-20 15:25:45 +08001424// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1425 Parcel* p=NULL;
1426 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1427 if(ret==RESULT_OK)
1428 {
1429 delete p;
1430 }
1431 return ret;
q.huangec88da92022-03-29 04:17:32 -04001432}
1433/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001434
q.huang036b6cf2023-01-10 14:29:20 +08001435
1436
1437bool is_support_urc(int urc_id)
1438{
1439 switch(urc_id)
1440 {
1441 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1442 case RIL_UNSOL_CALL_RING:
1443 case RIL_UNSOL_RINGBACK_TONE:
1444 case RIL_UNSOL_CALL_INFO_INDICATION:
1445#ifdef ECALL_SUPPORT
1446 case RIL_UNSOL_ECALL_INDICATIONS://9502
1447#endif
1448 return true;
1449 default:
1450 return false;
1451 }
1452}
1453
q.huang52921662022-10-20 15:25:45 +08001454void urc_msg_process(Parcel *p)
1455{
1456 int resp_type;
1457 int urcid;
1458 int slot_id;
q.huang036b6cf2023-01-10 14:29:20 +08001459
1460 int size=p->dataSize();
q.huang52921662022-10-20 15:25:45 +08001461 p->readInt32(&resp_type);
1462 p->readInt32(&urcid);
1463 p->readInt32(&slot_id);
q.huang036b6cf2023-01-10 14:29:20 +08001464 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 +08001465 switch (urcid)
1466 {
1467 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1468 {
1469 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1470 lynqNoticeGetModuleCallList();
1471 break;
1472 }
1473 case RIL_UNSOL_CALL_RING: //1018
1474 {
1475 if(s_call_auto_answer==1)
1476 {
1477 lynq_call_answer();
1478 }
1479 break;
1480 }
1481 case RIL_UNSOL_RINGBACK_TONE: //1029
1482 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1483 {
1484 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1485 break;
1486 }
q.huang714145d2022-04-18 00:09:50 -04001487#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +08001488 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange97cfcf2022-08-29 20:04:31 +08001489 {
q.huang52921662022-10-20 15:25:45 +08001490 urc_ecall_msg_process(p);
q.huange97cfcf2022-08-29 20:04:31 +08001491 }
q.huange97cfcf2022-08-29 20:04:31 +08001492#endif
q.huang52921662022-10-20 15:25:45 +08001493 default:
1494 break;
q.huangcb7b7292022-06-28 20:12:01 +08001495 }
q.huang5ca6c072022-06-06 16:15:31 +08001496}
q.huang5ca6c072022-06-06 16:15:31 +08001497
lh7b0674a2022-01-10 00:34:35 -08001498#if 0
1499int main(int argc,char **argv)
1500{
1501 int n = 0;
1502 n = lynq_init_call(lynq_call_state_change_test,2222);
1503 if(n<0)
1504 {
q.huang70b76492022-06-02 14:49:02 +08001505 LYDBGLOG("lynq init call fail!!!");
lh7b0674a2022-01-10 00:34:35 -08001506 return -1;
1507 }
q.huang70b76492022-06-02 14:49:02 +08001508 LYDBGLOG("lynq call init success!!!");
lh7b0674a2022-01-10 00:34:35 -08001509 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1510 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1511 lynq_call(phoneNum);
1512 while(1)
1513 {
1514 sleep(1);
1515 }
1516 return 0;
1517}
1518#endif
1519/*Warren add for T800 platform 2021/11/19 end*/