blob: 1f2b28b495e1ef9c3b986931b004842af441f261 [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();
q.huang52921662022-10-20 15:25:45 +0800811 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);
lle3b9a232023-01-14 13:21:20 +0800955 send_call_state_change();
q.huang52921662022-10-20 15:25:45 +0800956 return LYNQ_E_TIME_OUT;
lh7b0674a2022-01-10 00:34:35 -0800957 }
q.huang52921662022-10-20 15:25:45 +0800958 s_module_isDial = 0;
959 *handle = s_call_lists[lynq_call_id].call_id;
960 if(*handle > 0)
lh7b0674a2022-01-10 00:34:35 -0800961 {
q.huang52921662022-10-20 15:25:45 +0800962 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
963 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -0800964 }
q.huang52921662022-10-20 15:25:45 +0800965 else
966 {
967 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
lle3b9a232023-01-14 13:21:20 +0800968 cleanCallList(lynq_call_id);
969 send_call_state_change();
q.huang52921662022-10-20 15:25:45 +0800970 return LYNQ_E_INVALID_ID_ANONALY;
llb3921072023-01-10 14:47:46 +0800971 }
lh7b0674a2022-01-10 00:34:35 -0800972}
llb3921072023-01-10 14:47:46 +0800973
lh7b0674a2022-01-10 00:34:35 -0800974int lynq_call_answer()
975{
q.huang52921662022-10-20 15:25:45 +0800976 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700977 {
q.huang52921662022-10-20 15:25:45 +0800978 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
979 return LYNQ_E_CONFLICT;
980 }
981
982 Parcel* p=NULL;
983 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
984 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -0800985 {
q.huang52921662022-10-20 15:25:45 +0800986 delete p;
987 }
988 return ret;
lh7b0674a2022-01-10 00:34:35 -0800989}
llb3921072023-01-10 14:47:46 +0800990
lh7b0674a2022-01-10 00:34:35 -0800991int lynq_call_hungup(int* handle)
992{
q.huang52921662022-10-20 15:25:45 +0800993 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -0700994 {
q.huang52921662022-10-20 15:25:45 +0800995 return LYNQ_E_CONFLICT;
996 }
997
lh42c1e572022-01-25 18:47:39 -0800998 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
999 {
q.huang52921662022-10-20 15:25:45 +08001000 LYERRLOG("%s illegal input!!!!",__func__);
1001 return LYNQ_E_PARAMETER_ANONALY;
lh42c1e572022-01-25 18:47:39 -08001002 }
q.huang52921662022-10-20 15:25:45 +08001003
1004 int call_id = *handle;
1005 Parcel* p=NULL;
1006 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1007 if(ret!=0)
lh7b0674a2022-01-10 00:34:35 -08001008 {
q.huang52921662022-10-20 15:25:45 +08001009 return ret;
1010 }
1011 delete p;
1012
1013 int lynq_call_id=find_call_id_with_call_id(call_id);
1014 if(lynq_call_id!=INVALID_ID)
lh7b0674a2022-01-10 00:34:35 -08001015 {
q.huang52921662022-10-20 15:25:45 +08001016 cleanCallList(lynq_call_id);
1017 }
1018
1019 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001020}
1021int lynq_call_hungup_all()
1022{
q.huang52921662022-10-20 15:25:45 +08001023 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001024 {
q.huang52921662022-10-20 15:25:45 +08001025 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1026 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001027 }
q.huang52921662022-10-20 15:25:45 +08001028
1029 Parcel* p=NULL;
1030 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1031 if(ret==RESULT_OK)
lh7b0674a2022-01-10 00:34:35 -08001032 {
q.huang52921662022-10-20 15:25:45 +08001033 delete p;
1034 }
1035 return ret;
lh7b0674a2022-01-10 00:34:35 -08001036}
llb3921072023-01-10 14:47:46 +08001037
1038int lynq_wait_call_state_change(int *handle)
lh7b0674a2022-01-10 00:34:35 -08001039{
q.huang52921662022-10-20 15:25:45 +08001040 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001041 {
q.huang52921662022-10-20 15:25:45 +08001042 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1043 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001044 }
llb3921072023-01-10 14:47:46 +08001045 wait_call_state();
1046 *handle = s_CallId;
1047 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1048 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001049}
1050
1051int lynq_set_auto_answercall(const int mode)
1052{
q.huang52921662022-10-20 15:25:45 +08001053 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001054 {
q.huang52921662022-10-20 15:25:45 +08001055 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1056 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001057 }
q.huang52921662022-10-20 15:25:45 +08001058 s_call_auto_answer = mode;
lh7b0674a2022-01-10 00:34:35 -08001059 LYINFLOG("auto answer call mode =%d",mode);
q.huang52921662022-10-20 15:25:45 +08001060 return RESULT_OK;
lh7b0674a2022-01-10 00:34:35 -08001061}
llb3921072023-01-10 14:47:46 +08001062
1063int lynq_find_already_end()
1064{
1065 for(int i=0;i < LYNQ_CALL_MAX; i++)
1066 {
1067 if(s_call_lists[i].call_state == 6)
1068 {
1069 return 0;
1070 }
1071 }
1072 return INVALID_ID;
1073}
1074
q.huangec88da92022-03-29 04:17:32 -04001075int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1076{
q.huang52921662022-10-20 15:25:45 +08001077 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001078 {
q.huang52921662022-10-20 15:25:45 +08001079 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1080 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001081 }
q.huangec88da92022-03-29 04:17:32 -04001082 int lynq_call_id = 0;
q.huang70b76492022-06-02 14:49:02 +08001083 LYINFLOG("lynq_get_current_call_state begin ");
q.huangec88da92022-03-29 04:17:32 -04001084 if(handle==NULL)
1085 {
q.huang70b76492022-06-02 14:49:02 +08001086 LYERRLOG("handle is NULL");
q.huang52921662022-10-20 15:25:45 +08001087 return LYNQ_E_PARAMETER_ANONALY;
q.huangec88da92022-03-29 04:17:32 -04001088 }
llb3921072023-01-10 14:47:46 +08001089 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huang70b76492022-06-02 14:49:02 +08001090 lynq_call_id = find_call_id_with_call_id(*handle);
1091 if(lynq_call_id==INVALID_ID)
1092 {
llb3921072023-01-10 14:47:46 +08001093 //find end state
1094 if((*handle) >= 0)
1095 {
1096 *call_state = (int)LYNQ_CALL_END;
1097 return RESULT_OK;
1098 }
1099 else
1100 {
1101 return LYNQ_E_INVALID_ID_ANONALY;
1102 }
q.huang70b76492022-06-02 14:49:02 +08001103 }
q.huang52921662022-10-20 15:25:45 +08001104 *call_state = s_call_lists[lynq_call_id].call_state;
1105 *toa = s_call_lists[lynq_call_id].toa;
1106 *direction = s_call_lists[lynq_call_id].direction;
1107 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
llb3921072023-01-10 14:47:46 +08001108 return RESULT_OK;
q.huangec88da92022-03-29 04:17:32 -04001109}
1110
q.huange97cfcf2022-08-29 20:04:31 +08001111int lynq_get_current_call_number()
1112{
1113 int cnt=0;
1114 int i;
1115 for(i = 0;i < LYNQ_CALL_MAX;i++)
1116 {
q.huang52921662022-10-20 15:25:45 +08001117 if(s_call_lists[i].used !=0)
q.huange97cfcf2022-08-29 20:04:31 +08001118 {
1119 cnt++;
1120 }
1121 }
1122
1123 return cnt;
1124}
1125
q.huangec88da92022-03-29 04:17:32 -04001126/*audio begin*/
lldc99c9b2022-01-24 12:16:22 +00001127static int judge_mic(const int enable){
llf512fa32022-02-14 08:58:16 +00001128 switch(enable){
1129 case 0:
q.huang52921662022-10-20 15:25:45 +08001130 return true;
llf512fa32022-02-14 08:58:16 +00001131 case 1:
q.huang52921662022-10-20 15:25:45 +08001132 return true;
llf512fa32022-02-14 08:58:16 +00001133 default:
q.huang52921662022-10-20 15:25:45 +08001134 return false;
lldc99c9b2022-01-24 12:16:22 +00001135 }
1136}
1137
lh7b0674a2022-01-10 00:34:35 -08001138int lynq_set_mute_mic(const int enable)
lldc99c9b2022-01-24 12:16:22 +00001139{
q.huang52921662022-10-20 15:25:45 +08001140 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001141 {
q.huang52921662022-10-20 15:25:45 +08001142 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001143 return LYNQ_E_CONFLICT;
1144 }
q.huang52921662022-10-20 15:25:45 +08001145 if(!judge_mic(enable)){
1146 return LYNQ_E_PARAMETER_ANONALY;
1147 }
1148 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1149
1150 Parcel* p=NULL;
1151 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1152 if(ret==RESULT_OK)
1153 {
1154 delete p;
1155 }
1156 return ret;
q.huangec88da92022-03-29 04:17:32 -04001157}
1158int lynq_get_mute_mic(int *status)
1159{
q.huang52921662022-10-20 15:25:45 +08001160 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001161 {
q.huang52921662022-10-20 15:25:45 +08001162 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1163 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001164 }
q.huang52921662022-10-20 15:25:45 +08001165 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh7b0674a2022-01-10 00:34:35 -08001166}
ll72bf6c12022-03-24 10:22:25 +08001167
1168/**
1169 * @brief Check whether DTMF is valid
1170 *
1171 * @param callnum dtmf eg:0-9 * #
1172 * @return int
1173 */
1174static int judge_dtmf(const char callnum)
1175{
1176 if(callnum == '#')
1177 {
q.huang52921662022-10-20 15:25:45 +08001178 return true;
ll72bf6c12022-03-24 10:22:25 +08001179 }
1180 if(callnum == '*')
1181 {
q.huang52921662022-10-20 15:25:45 +08001182 return true;
ll72bf6c12022-03-24 10:22:25 +08001183 }
1184 if(callnum >= '0'&& callnum <= '9')
1185 {
q.huang52921662022-10-20 15:25:45 +08001186 return true;
ll72bf6c12022-03-24 10:22:25 +08001187 }
q.huang52921662022-10-20 15:25:45 +08001188 return false;
ll72bf6c12022-03-24 10:22:25 +08001189}
1190
ll209e6112022-07-20 09:30:19 +00001191int lynq_switch_waiting_or_holding_and_active(void)
1192{
q.huang52921662022-10-20 15:25:45 +08001193 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001194 {
q.huang52921662022-10-20 15:25:45 +08001195 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1196 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001197 }
q.huang52921662022-10-20 15:25:45 +08001198
1199 Parcel* p=NULL;
1200 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1201 if(ret==RESULT_OK)
1202 {
1203 delete p;
1204 }
1205 return ret;
1206
1207#if 0
ll209e6112022-07-20 09:30:19 +00001208 Parcel p;
1209 lynq_client_t client;
1210 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001211 int token;
ll209e6112022-07-20 09:30:19 +00001212 int request = -1;
1213 int slot_id = -1;
1214 int error = -1;
1215 client.uToken = Global_uToken_call;
1216 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1217 client.paramLen = 0;
1218 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1219 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001220 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001221 if(send_request(lynq_call_client_sockfd,&client)==-1)
1222 {
1223 LYERRLOG("send request fail");
1224 return -1;
1225 }
1226 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001227 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001228 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001229 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1230 return error;
q.huang52921662022-10-20 15:25:45 +08001231#endif
ll209e6112022-07-20 09:30:19 +00001232}
1233
1234int lynq_hangup_waiting_or_background(void)
1235{
q.huang52921662022-10-20 15:25:45 +08001236 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001237 {
q.huang52921662022-10-20 15:25:45 +08001238 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1239 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001240 }
q.huang52921662022-10-20 15:25:45 +08001241
1242 Parcel* p=NULL;
1243 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1244 if(ret==RESULT_OK)
1245 {
1246 delete p;
1247 }
1248 return ret;
1249#if 0
ll209e6112022-07-20 09:30:19 +00001250 Parcel p;
1251 lynq_client_t client;
1252 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001253 int token;
ll209e6112022-07-20 09:30:19 +00001254 int request = -1;
1255 int slot_id = -1;
1256 int error = -1;
1257 client.uToken = Global_uToken_call;
1258 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1259 client.paramLen = 0;
1260 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1261 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001262 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001263 if(send_request(lynq_call_client_sockfd,&client)==-1)
1264 {
1265 LYERRLOG("send request fail");
1266 return -1;
1267 }
1268 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001269 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001270 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001271 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1272 return error;
q.huang52921662022-10-20 15:25:45 +08001273#endif
ll209e6112022-07-20 09:30:19 +00001274}
1275
1276int lynq_hangup_foreground_resume_background(void)
1277{
q.huang52921662022-10-20 15:25:45 +08001278 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001279 {
q.huang52921662022-10-20 15:25:45 +08001280 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1281 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001282 }
q.huang52921662022-10-20 15:25:45 +08001283
1284 Parcel* p=NULL;
1285 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1286 if(ret==RESULT_OK)
1287 {
1288 delete p;
1289 }
1290 return ret;
1291#if 0
ll209e6112022-07-20 09:30:19 +00001292 Parcel p;
1293 lynq_client_t client;
1294 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001295 int token;
ll209e6112022-07-20 09:30:19 +00001296 int request = -1;
1297 int slot_id = -1;
1298 int error = -1;
1299 client.uToken = Global_uToken_call;
1300 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1301 client.paramLen = 0;
1302 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1303 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll630be412022-07-25 05:52:14 +00001304 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
ll209e6112022-07-20 09:30:19 +00001305 if(send_request(lynq_call_client_sockfd,&client)==-1)
1306 {
1307 LYERRLOG("send request fail");
1308 return -1;
1309 }
1310 get_response(lynq_call_client_sockfd,p);
ll630be412022-07-25 05:52:14 +00001311 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +08001312 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
ll209e6112022-07-20 09:30:19 +00001313 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1314 return error;
q.huang52921662022-10-20 15:25:45 +08001315#endif
ll209e6112022-07-20 09:30:19 +00001316}
1317
lh7b0674a2022-01-10 00:34:35 -08001318int lynq_set_DTMF(const char callnum)
1319{
q.huang52921662022-10-20 15:25:45 +08001320 if(g_module_init_flag != MODULE_RUNNING)
ll27dbe752022-08-10 00:33:52 -07001321 {
q.huang52921662022-10-20 15:25:45 +08001322 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1323 return LYNQ_E_CONFLICT;
ll27dbe752022-08-10 00:33:52 -07001324 }
ll72bf6c12022-03-24 10:22:25 +08001325 if(!judge_dtmf(callnum))
1326 {
1327 return LYNQ_E_CONFLICT;
1328 }
q.huang52921662022-10-20 15:25:45 +08001329 if(s_module_call_state!=CALL_ON)
lh7b0674a2022-01-10 00:34:35 -08001330 {
1331 LYERRLOG("LYNQ_E_CONFLICT");
1332 return LYNQ_E_CONFLICT;
1333 }
q.huang52921662022-10-20 15:25:45 +08001334
1335// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1336
1337 Parcel* p=NULL;
1338 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1339 if(ret==RESULT_OK)
1340 {
1341 delete p;
1342 }
1343 return ret;
lh7b0674a2022-01-10 00:34:35 -08001344}
q.huangec88da92022-03-29 04:17:32 -04001345static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1346 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1347 if(volume < 0 ||volume >36){
1348 return 0;
1349 }
1350 }
1351 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1352 {
1353 if(volume < 1 ||volume >7){
1354 return 0;
1355 }
lldc99c9b2022-01-24 12:16:22 +00001356 }
ll04ae4142022-01-27 05:54:38 +00001357 return 1;
lldc99c9b2022-01-24 12:16:22 +00001358}
lh7b0674a2022-01-10 00:34:35 -08001359int lynq_set_DTMF_volume(const int volume)
lldc99c9b2022-01-24 12:16:22 +00001360{
q.huang52921662022-10-20 15:25:45 +08001361 if(g_module_init_flag != MODULE_RUNNING)
1362 {
1363 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
lldc99c9b2022-01-24 12:16:22 +00001364 return LYNQ_E_CONFLICT;
1365 }
q.huang52921662022-10-20 15:25:45 +08001366 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1367 return LYNQ_E_PARAMETER_ANONALY;
1368 }
1369// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1370 Parcel* p=NULL;
1371 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1372 if(ret==RESULT_OK)
1373 {
1374 delete p;
1375 }
1376 return ret;
lh7b0674a2022-01-10 00:34:35 -08001377}
q.huangb212fde2022-04-05 23:11:02 -04001378int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh7b0674a2022-01-10 00:34:35 -08001379{
q.huang52921662022-10-20 15:25:45 +08001380 if(g_module_init_flag != MODULE_RUNNING)
lh7b0674a2022-01-10 00:34:35 -08001381 {
q.huang52921662022-10-20 15:25:45 +08001382 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangec88da92022-03-29 04:17:32 -04001383 return LYNQ_E_CONFLICT;
lh7b0674a2022-01-10 00:34:35 -08001384 }
q.huang52921662022-10-20 15:25:45 +08001385 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1386 {
1387 return LYNQ_E_PARAMETER_ANONALY;
1388 }
1389// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1390 Parcel* p=NULL;
1391 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1392 if(ret==RESULT_OK)
1393 {
1394 delete p;
1395 }
1396 return ret;
lh7b0674a2022-01-10 00:34:35 -08001397}
q.huangec88da92022-03-29 04:17:32 -04001398int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1399{
q.huang52921662022-10-20 15:25:45 +08001400 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangec88da92022-03-29 04:17:32 -04001401}
q.huangb212fde2022-04-05 23:11:02 -04001402int lynq_incall_record_start(const char* file_path)
q.huangec88da92022-03-29 04:17:32 -04001403{
q.huang52921662022-10-20 15:25:45 +08001404// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1405 Parcel* p=NULL;
1406 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1407 if(ret==RESULT_OK)
1408 {
1409 delete p;
1410 }
1411 return ret;
q.huangec88da92022-03-29 04:17:32 -04001412}
1413int lynq_incall_record_stop()
1414{
q.huang52921662022-10-20 15:25:45 +08001415 if(g_module_init_flag != MODULE_RUNNING)
1416 {
1417 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1418 return LYNQ_E_CONFLICT;
1419 }
q.huangb212fde2022-04-05 23:11:02 -04001420 const char* unused_file="just_ocuupy_paramter_postion";
q.huang52921662022-10-20 15:25:45 +08001421// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1422 Parcel* p=NULL;
1423 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1424 if(ret==RESULT_OK)
1425 {
1426 delete p;
1427 }
1428 return ret;
q.huangec88da92022-03-29 04:17:32 -04001429}
1430/*audio end*/
q.huang714145d2022-04-18 00:09:50 -04001431
q.huang036b6cf2023-01-10 14:29:20 +08001432
1433
1434bool is_support_urc(int urc_id)
1435{
1436 switch(urc_id)
1437 {
1438 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1439 case RIL_UNSOL_CALL_RING:
1440 case RIL_UNSOL_RINGBACK_TONE:
1441 case RIL_UNSOL_CALL_INFO_INDICATION:
1442#ifdef ECALL_SUPPORT
1443 case RIL_UNSOL_ECALL_INDICATIONS://9502
1444#endif
1445 return true;
1446 default:
1447 return false;
1448 }
1449}
1450
q.huang52921662022-10-20 15:25:45 +08001451void urc_msg_process(Parcel *p)
1452{
1453 int resp_type;
1454 int urcid;
1455 int slot_id;
q.huang036b6cf2023-01-10 14:29:20 +08001456
1457 int size=p->dataSize();
q.huang52921662022-10-20 15:25:45 +08001458 p->readInt32(&resp_type);
1459 p->readInt32(&urcid);
1460 p->readInt32(&slot_id);
q.huang036b6cf2023-01-10 14:29:20 +08001461 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 +08001462 switch (urcid)
1463 {
1464 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1465 {
1466 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1467 lynqNoticeGetModuleCallList();
1468 break;
1469 }
1470 case RIL_UNSOL_CALL_RING: //1018
1471 {
1472 if(s_call_auto_answer==1)
1473 {
1474 lynq_call_answer();
1475 }
1476 break;
1477 }
1478 case RIL_UNSOL_RINGBACK_TONE: //1029
1479 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1480 {
1481 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1482 break;
1483 }
q.huang714145d2022-04-18 00:09:50 -04001484#ifdef ECALL_SUPPORT
q.huang52921662022-10-20 15:25:45 +08001485 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange97cfcf2022-08-29 20:04:31 +08001486 {
q.huang52921662022-10-20 15:25:45 +08001487 urc_ecall_msg_process(p);
q.huange97cfcf2022-08-29 20:04:31 +08001488 }
q.huange97cfcf2022-08-29 20:04:31 +08001489#endif
q.huang52921662022-10-20 15:25:45 +08001490 default:
1491 break;
q.huangcb7b7292022-06-28 20:12:01 +08001492 }
q.huang5ca6c072022-06-06 16:15:31 +08001493}
q.huang5ca6c072022-06-06 16:15:31 +08001494
lh7b0674a2022-01-10 00:34:35 -08001495#if 0
1496int main(int argc,char **argv)
1497{
1498 int n = 0;
1499 n = lynq_init_call(lynq_call_state_change_test,2222);
1500 if(n<0)
1501 {
q.huang70b76492022-06-02 14:49:02 +08001502 LYDBGLOG("lynq init call fail!!!");
lh7b0674a2022-01-10 00:34:35 -08001503 return -1;
1504 }
q.huang70b76492022-06-02 14:49:02 +08001505 LYDBGLOG("lynq call init success!!!");
lh7b0674a2022-01-10 00:34:35 -08001506 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1507 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1508 lynq_call(phoneNum);
1509 while(1)
1510 {
1511 sleep(1);
1512 }
1513 return 0;
1514}
1515#endif
1516/*Warren add for T800 platform 2021/11/19 end*/