blob: d973bc72f85457a66f516d0353bb32ab0981c559 [file] [log] [blame]
ll78948a22022-07-25 05:52:14 +00001
lh25827952022-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>
lh25827952022-01-10 00:34:35 -080012#include <cutils/jstring.h>
13#include <pthread.h>
14#include "liblog/lynq_deflog.h"
lh228a7b82022-01-10 02:24:31 -080015#include <sys/time.h>
lh59e0d002022-01-27 00:27:12 -080016#include <string.h>
q.huang5a738c02022-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.huang8878f362022-10-20 15:25:45 +080021#include "lynq_module_common.h"
22#include "lynq_module_socket.h"
23#include "lynq_call_common.h"
q.huang5a738c02022-04-18 00:09:50 -040024
q.huang8878f362022-10-20 15:25:45 +080025#define CALL_OFF (0)
26#define CALL_ON (1)
lh25827952022-01-10 00:34:35 -080027#define USER_LOG_TAG "LYNQ_CALL"
28
29using ::android::Parcel;
q.huang8878f362022-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
lh25827952022-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 */
lh745926c2022-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*/
lh25827952022-01-10 00:34:35 -080048}lynq_call_state_t;
49
lh25827952022-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];
lh25827952022-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.huang8878f362022-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;
lh25827952022-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;
rjw3d6a50e2023-02-20 13:35:42 +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;
lhcdf816a2022-02-13 23:56:05 -080080
q.huang8878f362022-10-20 15:25:45 +080081static int s_module_call_state =CALL_OFF;
82static int s_call_auto_answer = 0;
lh25827952022-01-10 00:34:35 -080083
q.huangb0eb7b02022-03-29 04:17:32 -040084typedef enum{
85 LYNQ_E_VOLUMN_SET_DTMF,
86 LYNQ_E_VOLUMN_SET_SPEECH
q.huang8878f362022-10-20 15:25:45 +080087}LYNQ_E_VOLUMN_SET;
lh25827952022-01-10 00:34:35 -080088
q.huang8878f362022-10-20 15:25:45 +080089#if 0
q.huang2befc3a2022-09-13 14:19:24 +080090int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
lh25827952022-01-10 00:34:35 -080091{
92 if(p.dataAvail() > 0)
93 {
94 p.readInt32(resp_type);
q.huang2befc3a2022-09-13 14:19:24 +080095 p.readInt32(token);
lh25827952022-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;
rjw8bdc56b2022-02-28 15:01:49 +0800109 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh25827952022-01-10 00:34:35 -0800110 if(ret==-1)
111 {
q.huangf8461432022-06-02 14:49:02 +0800112 LYERRLOG("sendto error");
lh25827952022-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 */
rjw8bdc56b2022-02-28 15:01:49 +0800124 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh25827952022-01-10 00:34:35 -0800125 if(len == -1)
126 {
q.huangf8461432022-06-02 14:49:02 +0800127 LYERRLOG("recvfrom error");
lh25827952022-01-10 00:34:35 -0800128 return -1;
129 }
lh25827952022-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.huang8878f362022-10-20 15:25:45 +0800136#endif
137static char *strdupReadString(Parcel* &p) {
ll375c94d2022-01-27 05:54:38 +0000138 size_t stringlen;
lh25827952022-01-10 00:34:35 -0800139 const char16_t *s16;
q.huang8878f362022-10-20 15:25:45 +0800140 s16 = p->readString16Inplace(&stringlen);
ll375c94d2022-01-27 05:54:38 +0000141 return strndup16to8(s16, stringlen);
lh25827952022-01-10 00:34:35 -0800142}
143
144int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
145{
q.huang8878f362022-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
lh25827952022-01-10 00:34:35 -0800221 Parcel p;
222 lynq_client_t client;
223 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +0800224 int token;
lh25827952022-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;
lha35d4ee2022-01-25 18:47:39 -0800233 client.uToken = Global_uToken_call;
lh25827952022-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.huangf8461432022-06-02 14:49:02 +0800237 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800238 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800239 {
240 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800241 return -1;
242 }
lha35d4ee2022-01-25 18:47:39 -0800243 get_response(lynq_call_client_sockfd,p);
q.huang2befc3a2022-09-13 14:19:24 +0800244 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh25827952022-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;
lhcdf816a2022-02-13 23:56:05 -0800253 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh25827952022-01-10 00:34:35 -0800254 return 0;
255 }
lhcdf816a2022-02-13 23:56:05 -0800256 lynq_call_state = CALL_ON;
q.huangf8461432022-06-02 14:49:02 +0800257 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh25827952022-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.huang8878f362022-10-20 15:25:45 +0800289#endif
lh25827952022-01-10 00:34:35 -0800290}
291
292void cleanCallList(int lynq_call_id)
293{
q.huang8878f362022-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));
lh25827952022-01-10 00:34:35 -0800301}
rjw3d6a50e2023-02-20 13:35:42 +0800302
303
lh25827952022-01-10 00:34:35 -0800304int getUnusedElement()
305{
306 for(int i=0;i < LYNQ_CALL_MAX; i++)
307 {
q.huang8878f362022-10-20 15:25:45 +0800308 if(s_call_lists[i].used!=1)
lh25827952022-01-10 00:34:35 -0800309 {
310 return i;
311 }
312 }
q.huang8878f362022-10-20 15:25:45 +0800313 return INVALID_ID;
lh25827952022-01-10 00:34:35 -0800314}
q.huang8878f362022-10-20 15:25:45 +0800315int addAddr(char addr[], int call_id)
lh25827952022-01-10 00:34:35 -0800316{
317 int ret = 0;
318 ret = getUnusedElement();
q.huang8878f362022-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.huangf8461432022-06-02 14:49:02 +0800322 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh25827952022-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.huangf8461432022-06-02 14:49:02 +0800327 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh25827952022-01-10 00:34:35 -0800328 callList->call_id = call_id;
329 callList->call_state = call_state;
330 callList->toa = toa;
q.huangf8461432022-06-02 14:49:02 +0800331 callList->direction = direction;
lh25827952022-01-10 00:34:35 -0800332 return;
333}
rjw3d6a50e2023-02-20 13:35:42 +0800334
335void wait_call_state()
lh25827952022-01-10 00:34:35 -0800336{
rjw3d6a50e2023-02-20 13:35:42 +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);
lh25827952022-01-10 00:34:35 -0800341}
rjw3d6a50e2023-02-20 13:35:42 +0800342
lh25827952022-01-10 00:34:35 -0800343int checkHasCall(char addr[])
344{
345 for(int i = 0;i<LYNQ_CALL_MAX;i++)
346 {
q.huang8878f362022-10-20 15:25:45 +0800347 if(strcmp(s_call_lists[i].addr,addr)==0)
lh25827952022-01-10 00:34:35 -0800348 {
q.huang8878f362022-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;
lh25827952022-01-10 00:34:35 -0800351 }
352 }
q.huangf8461432022-06-02 14:49:02 +0800353 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
q.huang8878f362022-10-20 15:25:45 +0800354 return false;
lh25827952022-01-10 00:34:35 -0800355}
lh5095be72022-04-19 06:01:25 -0700356int find_call_id_with_addr(char *addr)
357{
lh5095be72022-04-19 06:01:25 -0700358 for(int id = 0; id < LYNQ_CALL_MAX; id++)
359 {
q.huang8878f362022-10-20 15:25:45 +0800360 if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
lh5095be72022-04-19 06:01:25 -0700361 {
q.huang8878f362022-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);
lh5095be72022-04-19 06:01:25 -0700363 return id;
364 }
365 }
q.huangf8461432022-06-02 14:49:02 +0800366 LYINFLOG("find addr %s in local list , not found",addr);
q.huang8878f362022-10-20 15:25:45 +0800367 return INVALID_ID;
lh5095be72022-04-19 06:01:25 -0700368}
q.huangf8461432022-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.huang8878f362022-10-20 15:25:45 +0800373 if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
q.huangf8461432022-06-02 14:49:02 +0800374 {
q.huang8878f362022-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.huangf8461432022-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}
lh25827952022-01-10 00:34:35 -0800382void sendSignalToWaitCallStateChange()
383{
lh5095be72022-04-19 06:01:25 -0700384 LYINFLOG("send Signal To Wait Call State Change");
lh25827952022-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}
ll7b51c492023-04-07 11:41:15 +0800389void send_call_state_change(int callid)
lh25827952022-01-10 00:34:35 -0800390{
rjw3d6a50e2023-02-20 13:35:42 +0800391 LYINFLOG("send call state change");
ll7b51c492023-04-07 11:41:15 +0800392 s_CallId = callid;
rjw3d6a50e2023-02-20 13:35:42 +0800393 pthread_mutex_lock(&s_call_state_change_mutex);
394 pthread_cond_signal(&s_call_state_change_cond);
395 pthread_mutex_unlock(&s_call_state_change_mutex);
lh25827952022-01-10 00:34:35 -0800396}
397
q.huang8878f362022-10-20 15:25:45 +0800398void cleanup_call_list_mutex(void *arg)
lh25827952022-01-10 00:34:35 -0800399{
q.huang8878f362022-10-20 15:25:45 +0800400 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
lh25827952022-01-10 00:34:35 -0800401}
rjw3d6a50e2023-02-20 13:35:42 +0800402
403void update_end_state(int lynq_call_id)
404{
405 LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
406 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
407}
408
lh25827952022-01-10 00:34:35 -0800409void *triggerGetCallList(void *parg)
ll375c94d2022-01-27 05:54:38 +0000410{
411 int ret=0;
lh5095be72022-04-19 06:01:25 -0700412 bool call_end;
ll375c94d2022-01-27 05:54:38 +0000413 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huangaa75aa62022-04-19 20:27:44 -0400414 int update=0;
q.huangf8461432022-06-02 14:49:02 +0800415 int cnt;
416 int i,n;
q.huange0024b02022-08-29 20:04:31 +0800417#ifdef ECALL_SUPPORT
418 int handupIncomingMT=0;
419#endif
q.huang8878f362022-10-20 15:25:45 +0800420 pthread_mutex_lock(&s_notice_get_call_list_mutex);
421 pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
ll7b51c492023-04-07 11:41:15 +0800422 int tmp_call_id;
q.huang8878f362022-10-20 15:25:45 +0800423 while(s_call_list_loop)
ll375c94d2022-01-27 05:54:38 +0000424 {
q.huang8878f362022-10-20 15:25:45 +0800425 update=0;
426 pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
rjw1f8a2ee42023-03-06 15:19:40 +0800427 LYINFLOG("triggerGetCallList event %p!!!", pthread_self());
ll375c94d2022-01-27 05:54:38 +0000428 memset(call_list,0,sizeof(call_list));
429 ret = lynq_get_current_call_list(call_list);
q.huang8878f362022-10-20 15:25:45 +0800430 if(ret != RESULT_OK)
ll375c94d2022-01-27 05:54:38 +0000431 {
rjw1f8a2ee42023-03-06 15:19:40 +0800432 LYERRLOG("get current call list failure!!!");
ll83081992022-04-11 05:49:51 +0000433 continue;
ll375c94d2022-01-27 05:54:38 +0000434 }
lh5095be72022-04-19 06:01:25 -0700435 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huangf8461432022-06-02 14:49:02 +0800436 LYINFLOG("clear local index begin");
437 cnt=0;
438 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh25827952022-01-10 00:34:35 -0800439 {
q.huang8878f362022-10-20 15:25:45 +0800440 if(s_call_lists[i].used ==0)
q.huangf8461432022-06-02 14:49:02 +0800441 {
442 continue;
443 }
444 cnt++;
q.huang8878f362022-10-20 15:25:45 +0800445 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.huangf8461432022-06-02 14:49:02 +0800446
q.huang8878f362022-10-20 15:25:45 +0800447 if(s_call_lists[i].call_id > 0)
lh5095be72022-04-19 06:01:25 -0700448 {
449 call_end = 0;
q.huangf8461432022-06-02 14:49:02 +0800450 for(n = 0; n < LYNQ_CALL_MAX; n++)
lh5095be72022-04-19 06:01:25 -0700451 {
q.huang8878f362022-10-20 15:25:45 +0800452 if(call_list[n].call_id == s_call_lists[i].call_id)
lh5095be72022-04-19 06:01:25 -0700453 {
454 call_end = 1;
q.huang8878f362022-10-20 15:25:45 +0800455 LYINFLOG("find lynq call local idx %d, service idx %d id is %d!!!",i,n,s_call_lists[i].call_id);
q.huangf8461432022-06-02 14:49:02 +0800456 break;
lh5095be72022-04-19 06:01:25 -0700457 }
458 }
459 if(call_end == 0)
460 {
rjw3d6a50e2023-02-20 13:35:42 +0800461 LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
462 //update_end_state(i);//lei modify for:update end state for this call
ll7b51c492023-04-07 11:41:15 +0800463 tmp_call_id = s_call_lists[i].call_id;
rjw3d6a50e2023-02-20 13:35:42 +0800464 cleanCallList(i);
lld4353242023-03-15 17:02:52 +0800465 //Release the end handle
ll7b51c492023-04-07 11:41:15 +0800466 send_call_state_change(tmp_call_id);//means mt/mo call is end
rjw3d6a50e2023-02-20 13:35:42 +0800467 //cleanCallList(i);
lh5095be72022-04-19 06:01:25 -0700468 }
469 } //fix bug API-54
q.huangf8461432022-06-02 14:49:02 +0800470 else
471 {
472 LYINFLOG("local id is 0");
473 }
474 }
475 LYINFLOG("clear local index end, local used cnt is %d", cnt);
476
477 LYINFLOG("add or update local index begin ");
478 for (i = 0;i < LYNQ_CALL_MAX;i++)
479 {
480 if(call_list[i].call_id==0)
481 {
482 break;
483 }
484
485 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,
486 call_list[i].direction,call_list[i].addr,call_list[i].toa);
487
lh25827952022-01-10 00:34:35 -0800488 if(call_list[i].direction == 1)//MT call
489 {
q.huangf8461432022-06-02 14:49:02 +0800490 LYINFLOG("This is a MT CALL");
lh36a140b2022-05-13 03:02:19 -0700491 /*MT CALL state code
492 **LYNQ_CALL_INCOMING = 4,
493 **LYNQ_CALL_WAITING = 5,
494 */
q.huange0024b02022-08-29 20:04:31 +0800495#ifdef ECALL_SUPPORT
lh36a140b2022-05-13 03:02:19 -0700496 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh25827952022-01-10 00:34:35 -0800497 {
q.huang8878f362022-10-20 15:25:45 +0800498 handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
q.huange0024b02022-08-29 20:04:31 +0800499 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
500 if(handupIncomingMT)
lh25827952022-01-10 00:34:35 -0800501 {
q.huangf8461432022-06-02 14:49:02 +0800502 lynq_call_hungup(&(call_list[i].call_id));
503 continue;
q.huange0024b02022-08-29 20:04:31 +0800504 }
q.huangf8461432022-06-02 14:49:02 +0800505 }
q.huange0024b02022-08-29 20:04:31 +0800506#endif
q.huangf8461432022-06-02 14:49:02 +0800507 /*you call me, and i call you,One party failed to dial*/
508 n = find_call_id_with_addr(call_list[i].addr);
509 if(n ==INVALID_ID)
510 {
q.huang8878f362022-10-20 15:25:45 +0800511 n = addAddr(call_list[i].addr,call_list[i].call_id);
512 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
ll7b51c492023-04-07 11:41:15 +0800513 send_call_state_change(call_list[i].call_id);
q.huangf8461432022-06-02 14:49:02 +0800514 }
q.huang8878f362022-10-20 15:25:45 +0800515 else if(s_call_lists[n].call_state == call_list[i].call_state)
q.huangf8461432022-06-02 14:49:02 +0800516 {
517 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
518 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lh5095be72022-04-19 06:01:25 -0700519 {
lh5095be72022-04-19 06:01:25 -0700520 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
521 **an incoming call until the status changes.
522 **fix bug API-54
523 */
q.huangf8461432022-06-02 14:49:02 +0800524 LYINFLOG("resend incoming call signal");
ll7b51c492023-04-07 11:41:15 +0800525 send_call_state_change(call_list[i].call_id);
lh5095be72022-04-19 06:01:25 -0700526 }
lh25827952022-01-10 00:34:35 -0800527 }
q.huangf8461432022-06-02 14:49:02 +0800528 else
ll45d3ea92022-03-24 10:22:25 +0800529 {
q.huang8878f362022-10-20 15:25:45 +0800530 LYINFLOG("state changed from %d to %d",s_call_lists[n].call_state,call_list[i].call_state);
q.huangf8461432022-06-02 14:49:02 +0800531
rjw3d6a50e2023-02-20 13:35:42 +0800532 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
ll7b51c492023-04-07 11:41:15 +0800533 send_call_state_change(call_list[i].call_id);
rjw3d6a50e2023-02-20 13:35:42 +0800534 }
lh25827952022-01-10 00:34:35 -0800535 }
536 else
q.huangf8461432022-06-02 14:49:02 +0800537 {
538 LYINFLOG("This is a MO CALL");
539 call_end = 0;
540 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh25827952022-01-10 00:34:35 -0800541 {
q.huang8878f362022-10-20 15:25:45 +0800542 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)))
lh25827952022-01-10 00:34:35 -0800543 {
q.huang8878f362022-10-20 15:25:45 +0800544 if(s_call_lists[n].call_id==0)
q.huangf8461432022-06-02 14:49:02 +0800545 {
rjw3d6a50e2023-02-20 13:35:42 +0800546 LYINFLOG("add a call id");
547 update=1;//for send sigal
q.huangf8461432022-06-02 14:49:02 +0800548 }
q.huang8878f362022-10-20 15:25:45 +0800549 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);
550 updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
q.huangf8461432022-06-02 14:49:02 +0800551 call_end = 1;
ll7b51c492023-04-07 11:41:15 +0800552 send_call_state_change(call_list[i].call_id);//means mo call is success
q.huangf8461432022-06-02 14:49:02 +0800553 break;
554 }
555 }
rjw3d6a50e2023-02-20 13:35:42 +0800556 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.huangf8461432022-06-02 14:49:02 +0800557 {
558 LYINFLOG("need to hangup id %d", call_list[i].call_id);
559#ifdef ECALL_SUPPORT
q.huang8878f362022-10-20 15:25:45 +0800560 if(IsECallDialing())
q.huangf8461432022-06-02 14:49:02 +0800561 {
562 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh25827952022-01-10 00:34:35 -0800563 continue;
564 }
q.huangf8461432022-06-02 14:49:02 +0800565#endif
566 LYINFLOG("hang up service call id %d",call_list[i].call_id);
567 lynq_call_hungup(&(call_list[i].call_id));
lh25827952022-01-10 00:34:35 -0800568 }
rjw3d6a50e2023-02-20 13:35:42 +0800569
lh25827952022-01-10 00:34:35 -0800570 }
q.huangf8461432022-06-02 14:49:02 +0800571 LYDBGLOG("servie idx %d end",i);
ll375c94d2022-01-27 05:54:38 +0000572 }
q.huang8878f362022-10-20 15:25:45 +0800573 LYINFLOG("add or update local index end ");
574 if(s_module_isDial==1)
lh25827952022-01-10 00:34:35 -0800575 {
q.huangf8461432022-06-02 14:49:02 +0800576 LYINFLOG("now is dialing");
577 if(update==1)
578 {
579 LYINFLOG("find added call");
580 sendSignalToWaitCallStateChange();
q.huang8878f362022-10-20 15:25:45 +0800581 s_module_isDial = 0;
q.huangf8461432022-06-02 14:49:02 +0800582 }
583 else
584 {
585 LYINFLOG("not find added call");
586 }
587 }
588 else
589 {
590 LYINFLOG("now is not dialing");
q.huang8878f362022-10-20 15:25:45 +0800591 }
ll375c94d2022-01-27 05:54:38 +0000592 }
q.huang8878f362022-10-20 15:25:45 +0800593 pthread_cleanup_pop(0);
594 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
ll375c94d2022-01-27 05:54:38 +0000595 return NULL;
lh25827952022-01-10 00:34:35 -0800596}
597
q.huang8878f362022-10-20 15:25:45 +0800598void lynqNoticeGetModuleCallList()
ll375c94d2022-01-27 05:54:38 +0000599{
rjw1f8a2ee42023-03-06 15:19:40 +0800600 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send start");
q.huang8878f362022-10-20 15:25:45 +0800601 pthread_mutex_lock(&s_notice_get_call_list_mutex);
602 pthread_cond_signal(&s_notice_get_call_list_cond);
603 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
rjw1f8a2ee42023-03-06 15:19:40 +0800604 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send end");
lh25827952022-01-10 00:34:35 -0800605}
606
q.huang8878f362022-10-20 15:25:45 +0800607#if 0
lh25827952022-01-10 00:34:35 -0800608/*Warren add for T800 platform 2021/11/19 start*/
609int lynq_socket_client_start()
rjw8bdc56b2022-02-28 15:01:49 +0800610{
611 #if 0
lh25827952022-01-10 00:34:35 -0800612 struct sockaddr_in lynq_socket_server_addr;
613 /* init lynq_socket_server_addr */
614 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
615 lynq_socket_server_addr.sin_family = AF_INET;
616 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
617 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw8bdc56b2022-02-28 15:01:49 +0800618
lh25827952022-01-10 00:34:35 -0800619 /*
620 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
621 {
q.huangf8461432022-06-02 14:49:02 +0800622 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh25827952022-01-10 00:34:35 -0800623 exit(1);
624 }
625*/
lha35d4ee2022-01-25 18:47:39 -0800626 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
627 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh25827952022-01-10 00:34:35 -0800628 {
q.huangf8461432022-06-02 14:49:02 +0800629 LYERRLOG("connect error");
lh25827952022-01-10 00:34:35 -0800630 return -1;
631 }
rjw8bdc56b2022-02-28 15:01:49 +0800632 #endif
633 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
634 if (-1 == lynq_call_client_sockfd)
635 {
636 return lynq_call_client_sockfd;
637 }
ll78948a22022-07-25 05:52:14 +0000638 struct timeval timeOut;
639 timeOut.tv_sec = 60;
640 timeOut.tv_usec = 0;
641 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
642 {
643 RLOGD("time out setting failed\n");
644 return -1;
645 }
rjw8bdc56b2022-02-28 15:01:49 +0800646 /* 设置address */
647 memset(&addr_serv, 0, sizeof(addr_serv));
648 addr_serv.sin_family = AF_INET;
649 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
650 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
651 len_addr_serv = sizeof(addr_serv);
lh25827952022-01-10 00:34:35 -0800652 return 0;
653}
lh25827952022-01-10 00:34:35 -0800654
lh25827952022-01-10 00:34:35 -0800655int lynq_socket_urc_start()
656{
657 int socket_fd=0;
658 int rt=0;
659 int len=0;
660 int on=1;
661 struct sockaddr_in urc_local_addr;
lh25827952022-01-10 00:34:35 -0800662 pthread_attr_t attr;
ll375c94d2022-01-27 05:54:38 +0000663 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll375c94d2022-01-27 05:54:38 +0000664 if(socket_fd < 0)
665 {
q.huangf8461432022-06-02 14:49:02 +0800666 LYERRLOG("creaet socket for udp fail");
ll375c94d2022-01-27 05:54:38 +0000667 return -1;
lh25827952022-01-10 00:34:35 -0800668 }
669 urc_local_addr.sin_family = AF_INET;
670 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
671 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
672 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll375c94d2022-01-27 05:54:38 +0000673 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
674 if(rt<0)
675 {
q.huangf8461432022-06-02 14:49:02 +0800676 LYERRLOG("SO_REUSEADDR fail");
lh25827952022-01-10 00:34:35 -0800677 return -1;
678 }
679 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll375c94d2022-01-27 05:54:38 +0000680 if (rt == -1)
681 {
lh59e0d002022-01-27 00:27:12 -0800682 LYERRLOG("bind failed");
ll375c94d2022-01-27 05:54:38 +0000683 return -1;
lh25827952022-01-10 00:34:35 -0800684 }
685 pthread_attr_init(&attr);
686 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -0800687 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh25827952022-01-10 00:34:35 -0800688 if(rt < 0)
689 {
q.huangf8461432022-06-02 14:49:02 +0800690 LYERRLOG("urc loop failure!!!");
lh25827952022-01-10 00:34:35 -0800691 return -1;
692 }
q.huangf8461432022-06-02 14:49:02 +0800693 LYDBGLOG("urc loop success!!!");
lh25827952022-01-10 00:34:35 -0800694 return 0;
695}
q.huang8878f362022-10-20 15:25:45 +0800696#endif
lh25827952022-01-10 00:34:35 -0800697
698void lynq_call_state_change_test(int soc_id)
699{
q.huangf8461432022-06-02 14:49:02 +0800700 LYDBGLOG("call state change,sim:%d",soc_id);
lh25827952022-01-10 00:34:35 -0800701}
q.huang68ee8a02022-06-28 20:12:01 +0800702
q.huang8878f362022-10-20 15:25:45 +0800703int lynq_start_call_list_loop()
704{
705#if 0
706 int ret = 0;
707 pthread_attr_t attr;
708 pthread_attr_init(&attr);
709 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
q.huang68ee8a02022-06-28 20:12:01 +0800710
q.huang8878f362022-10-20 15:25:45 +0800711 s_notice_get_call_list_mutex = new pthread_mutex_t;
712 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
713 s_notice_get_call_list_cond = new pthread_cond_t;
714 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
715 pthread_cond_init(s_notice_get_call_list_cond, NULL);
716 LYINFLOG("liulei s_notice_get_call_list_cond\n");
717#endif
q.huang68ee8a02022-06-28 20:12:01 +0800718
q.huang8878f362022-10-20 15:25:45 +0800719 s_call_list_loop = 1;
720 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
721 if(ret < 0)
q.huang68ee8a02022-06-28 20:12:01 +0800722 {
q.huang8878f362022-10-20 15:25:45 +0800723 LYERRLOG("lynq_update_call_list_loop fail!!!");
ll1343a5b2022-03-17 05:31:33 +0000724 return -1;
725 }
q.huang8878f362022-10-20 15:25:45 +0800726 LYINFLOG("lynq_update_call_list_loop success!!!");
q.huang68ee8a02022-06-28 20:12:01 +0800727
q.huang8878f362022-10-20 15:25:45 +0800728 memset(s_call_lists,0,sizeof(s_call_lists));
lh25827952022-01-10 00:34:35 -0800729 return 0;
730}
q.huang8878f362022-10-20 15:25:45 +0800731
732int lynq_stop_call_list_loop()
lh25827952022-01-10 00:34:35 -0800733{
q.huangf8461432022-06-02 14:49:02 +0800734 int ret;
q.huang8878f362022-10-20 15:25:45 +0800735 pthread_mutex_lock(&s_notice_get_call_list_mutex);
736 s_call_list_loop = 0;
737 ret = pthread_cancel(s_call_list_loop_tid);
738 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
739 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
740 ret = pthread_join(s_call_list_loop_tid,NULL);
741 LYINFLOG("pthread join w_c_list ret = %d",ret);
742 s_call_list_loop_tid=-1;
743#if 0
744 pthread_mutex_destroy(s_notice_get_call_list_mutex);
745 pthread_cond_destroy(s_notice_get_call_list_cond);
746 delete s_notice_get_call_list_mutex;
747 //s_notice_get_call_list_mutex = NULL;
748 delete s_notice_get_call_list_cond;
749 //s_notice_get_call_list_cond = NULL;
750#endif
751
752 return 0;
ll83081992022-04-11 05:49:51 +0000753}
q.huang5a738c02022-04-18 00:09:50 -0400754
q.huang8878f362022-10-20 15:25:45 +0800755int lynq_init_call(int utoken){
756 if(g_module_init_flag != MODULE_CLOSED)
757 {
758 LYERRLOG("module state is %d",g_module_init_flag);
759 return LYNQ_E_CONFLICT;
760 }
761 if(utoken <0){
762 LYERRLOG("utoken is less than 0",utoken);
763 return LYNQ_E_PARAMETER_ANONALY;
764 }
765 g_module_init_flag = MODULE_SWITCHING;
766
767 LYLOGSET(LOG_INFO);
768 LYLOGEINIT(USER_LOG_TAG);
769
770 g_module_Global_uToken = utoken;
771
rjw3d6a50e2023-02-20 13:35:42 +0800772 int ret = lynq_start_all_urc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800773 if(ret != RESULT_OK)
774 {
775 LYERRLOG("init socket urc fail!!!");
776 g_module_init_flag = MODULE_CLOSED;
777 return LYNQ_E_INNER_ERROR;
778 }
779
rjw3d6a50e2023-02-20 13:35:42 +0800780 ret = lynq_start_all_rc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800781 if(ret !=RESULT_OK)
782 {
783 LYERRLOG("init socket client fail!!!");
rjw3d6a50e2023-02-20 13:35:42 +0800784 lynq_close_all_urc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800785 g_module_init_flag = MODULE_CLOSED;
786 return LYNQ_E_INNER_ERROR;
787 }
788
789
790 int result = lynq_start_call_list_loop();
791 if(ret != RESULT_OK)
792 {
793 LYERRLOG("lynq_start_call_list_loop fail!!!");
rjw3d6a50e2023-02-20 13:35:42 +0800794 lynq_close_all_urc_socket_thread();
795 lynq_close_all_rc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800796 g_module_init_flag = MODULE_CLOSED;
797 return LYNQ_E_INNER_ERROR;
798 }
799
800 lynq_init_rtp();
801
802 g_module_init_flag = MODULE_RUNNING;
803 return 0;
804}
805
806int lynq_deinit_call(void){
807
808 if (g_module_init_flag != MODULE_RUNNING)
809 {
810 LYERRLOG("module state is %d",g_module_init_flag);
811 return LYNQ_E_CONFLICT;
812 }
813 lynq_call_hungup_all();
814 lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
815 g_module_init_flag = MODULE_SWITCHING;
rjw3d6a50e2023-02-20 13:35:42 +0800816 lynq_close_all_urc_socket_thread();
817 lynq_close_all_rc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800818 lynq_stop_call_list_loop();
819 g_module_init_flag = MODULE_CLOSED;
820 return 0;
821}
822
823#if 0
q.huang5a738c02022-04-18 00:09:50 -0400824int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita9b436d82022-04-07 01:55:39 -0400825{
826 Parcel p;
827 lynq_client_t client;
828 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +0800829 int token;
rita9b436d82022-04-07 01:55:39 -0400830 int request = -1;
831 int slot_id = -1;
832 int error = -1;
rita9b436d82022-04-07 01:55:39 -0400833
q.huang8878f362022-10-20 15:25:45 +0800834 Parcel* p=NULL;
835 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
836 if(ret==RESULT_OK)
837 {
838 delete p;
839 }
840 return ret;
841
rita9b436d82022-04-07 01:55:39 -0400842 client.uToken = Global_uToken_call;
q.huang5a738c02022-04-18 00:09:50 -0400843 client.request = request_id;
844 client.paramLen = argc;
rita9b436d82022-04-07 01:55:39 -0400845 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang5a738c02022-04-18 00:09:50 -0400846 if(argc!=0)
847 {
848 va_list args;
849 va_start(args, format);
850 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
851 va_end(args);
852 }
q.huangf8461432022-06-02 14:49:02 +0800853 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -0400854 if(send_request(lynq_call_client_sockfd,&client)==-1)
855 {
856 LYERRLOG("send request fail");
857 return -1;
858 }
q.huang5a738c02022-04-18 00:09:50 -0400859 if(get_response(lynq_call_client_sockfd,p)==0)
860 {
q.huang2befc3a2022-09-13 14:19:24 +0800861 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang5a738c02022-04-18 00:09:50 -0400862 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
863 }
rita9b436d82022-04-07 01:55:39 -0400864 return error;
q.huang8878f362022-10-20 15:25:45 +0800865
866
rita9b436d82022-04-07 01:55:39 -0400867}
q.huang8878f362022-10-20 15:25:45 +0800868#endif
rita9b436d82022-04-07 01:55:39 -0400869
q.huang5a738c02022-04-18 00:09:50 -0400870int lynq_get_common_request(int request_id, int* status)
rita9b436d82022-04-07 01:55:39 -0400871{
q.huang5a738c02022-04-18 00:09:50 -0400872 if(status==NULL)
873 {
874 LYERRLOG("status is null");
q.huang8878f362022-10-20 15:25:45 +0800875 return LYNQ_E_PARAMETER_ANONALY;
q.huang5a738c02022-04-18 00:09:50 -0400876 }
q.huang8878f362022-10-20 15:25:45 +0800877
878 Parcel* p=NULL;
879 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
880 if(ret==RESULT_OK)
rita9b436d82022-04-07 01:55:39 -0400881 {
q.huang8878f362022-10-20 15:25:45 +0800882 p->readInt32(status);
883 delete p;
rita9b436d82022-04-07 01:55:39 -0400884 }
q.huang8878f362022-10-20 15:25:45 +0800885 return ret;
886}
887
888int waitCallstateChange(int mtime)
889{
890 LYINFLOG("wait Call state Change");
891 int ret = 0;
892 int sec = 0;
ll7b51c492023-04-07 11:41:15 +0800893 int ms = 0;
q.huang8878f362022-10-20 15:25:45 +0800894 struct timeval now;
895 struct timespec timeout;
896 gettimeofday(&now,NULL);
897 sec = mtime/1000;
ll7b51c492023-04-07 11:41:15 +0800898 ms = mtime%1000;
q.huang8878f362022-10-20 15:25:45 +0800899 timeout.tv_sec = now.tv_sec+sec;
ll7b51c492023-04-07 11:41:15 +0800900 unsigned long long ns;
901 ns = now.tv_usec*1000ull + ms*1000000ull;
902 timeout.tv_sec += ns/1000000000;
903 timeout.tv_nsec = ns % 1000000000;
q.huang8878f362022-10-20 15:25:45 +0800904 pthread_mutex_lock(&call_state_change_mutex);
905 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
906 pthread_mutex_unlock(&call_state_change_mutex);
907 return ret;
908}
909
910int IsNormalCallDailing()
911{
912 return s_module_isDial;
rita9b436d82022-04-07 01:55:39 -0400913}
914
rjw3d6a50e2023-02-20 13:35:42 +0800915
lh25827952022-01-10 00:34:35 -0800916int lynq_call(int* handle,char addr[])
917{
q.huang8878f362022-10-20 15:25:45 +0800918 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -0700919 {
q.huang8878f362022-10-20 15:25:45 +0800920 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
921 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -0700922 }
q.huang8878f362022-10-20 15:25:45 +0800923
lh25827952022-01-10 00:34:35 -0800924 int lynq_call_id = -1;
q.huangf8461432022-06-02 14:49:02 +0800925
926 LYINFLOG("lynq_call begin addr %s",addr);
lh25827952022-01-10 00:34:35 -0800927 if(addr==NULL)
928 {
929 LYERRLOG("Phone num is null!!!");
q.huang8878f362022-10-20 15:25:45 +0800930 return LYNQ_E_PARAMETER_ANONALY;
lh25827952022-01-10 00:34:35 -0800931 }
q.huangf8461432022-06-02 14:49:02 +0800932
933 if(find_call_id_with_addr(addr)!=INVALID_ID)
934 {
935 LYERRLOG("addr %s exists",addr);
936 return LYNQ_E_CONFLICT;
937 }
938
939#ifdef ECALL_SUPPORT
940 if(lynq_ecall_is_running())
941 {
942 LYERRLOG("lynq_fast_ecall ecall is running");
943 return LYNQ_E_ECALL_BEING_RUNNING;
944 }
945#endif
q.huang8878f362022-10-20 15:25:45 +0800946 Parcel* p=NULL;
947 lynq_call_id = addAddr(addr,0);
948 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
949 if(ret!=0)
950 {
rjw3d6a50e2023-02-20 13:35:42 +0800951 cleanCallList(lynq_call_id);
q.huang8878f362022-10-20 15:25:45 +0800952 return ret;
rjw3d6a50e2023-02-20 13:35:42 +0800953 }
954 delete p;
q.huang8878f362022-10-20 15:25:45 +0800955 s_module_isDial = 1;
956 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh25827952022-01-10 00:34:35 -0800957 {
q.huang8878f362022-10-20 15:25:45 +0800958 //if timeout,this call need destroy.
959 s_module_isDial = 0;
960 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
rjw3d6a50e2023-02-20 13:35:42 +0800961 cleanCallList(lynq_call_id);
q.huang8878f362022-10-20 15:25:45 +0800962 return LYNQ_E_TIME_OUT;
lh25827952022-01-10 00:34:35 -0800963 }
q.huang8878f362022-10-20 15:25:45 +0800964 s_module_isDial = 0;
965 *handle = s_call_lists[lynq_call_id].call_id;
966 if(*handle > 0)
lh25827952022-01-10 00:34:35 -0800967 {
q.huang8878f362022-10-20 15:25:45 +0800968 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
969 return RESULT_OK;
lh25827952022-01-10 00:34:35 -0800970 }
q.huang8878f362022-10-20 15:25:45 +0800971 else
972 {
973 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
rjw3d6a50e2023-02-20 13:35:42 +0800974 cleanCallList(lynq_call_id);
q.huang8878f362022-10-20 15:25:45 +0800975 return LYNQ_E_INVALID_ID_ANONALY;
rjw3d6a50e2023-02-20 13:35:42 +0800976 }
lh25827952022-01-10 00:34:35 -0800977}
rjw3d6a50e2023-02-20 13:35:42 +0800978
lh25827952022-01-10 00:34:35 -0800979int lynq_call_answer()
980{
q.huang8878f362022-10-20 15:25:45 +0800981 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -0700982 {
q.huang8878f362022-10-20 15:25:45 +0800983 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
984 return LYNQ_E_CONFLICT;
985 }
986
987 Parcel* p=NULL;
988 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
989 if(ret==RESULT_OK)
lh25827952022-01-10 00:34:35 -0800990 {
q.huang8878f362022-10-20 15:25:45 +0800991 delete p;
992 }
993 return ret;
lh25827952022-01-10 00:34:35 -0800994}
rjw3d6a50e2023-02-20 13:35:42 +0800995
lh25827952022-01-10 00:34:35 -0800996int lynq_call_hungup(int* handle)
997{
q.huang8878f362022-10-20 15:25:45 +0800998 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -0700999 {
q.huang8878f362022-10-20 15:25:45 +08001000 return LYNQ_E_CONFLICT;
1001 }
1002
lha35d4ee2022-01-25 18:47:39 -08001003 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1004 {
q.huang8878f362022-10-20 15:25:45 +08001005 LYERRLOG("%s illegal input!!!!",__func__);
1006 return LYNQ_E_PARAMETER_ANONALY;
lha35d4ee2022-01-25 18:47:39 -08001007 }
q.huang8878f362022-10-20 15:25:45 +08001008
1009 int call_id = *handle;
1010 Parcel* p=NULL;
1011 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1012 if(ret!=0)
lh25827952022-01-10 00:34:35 -08001013 {
q.huang8878f362022-10-20 15:25:45 +08001014 return ret;
ll7b51c492023-04-07 11:41:15 +08001015 }
q.huang8878f362022-10-20 15:25:45 +08001016 delete p;
1017
lld4353242023-03-15 17:02:52 +08001018 int lynq_call_id=find_call_id_with_call_id(call_id);
q.huang8878f362022-10-20 15:25:45 +08001019 if(lynq_call_id!=INVALID_ID)
lh25827952022-01-10 00:34:35 -08001020 {
ll7b51c492023-04-07 11:41:15 +08001021 //lei modify for API-857
q.huang8878f362022-10-20 15:25:45 +08001022 cleanCallList(lynq_call_id);
ll7b51c492023-04-07 11:41:15 +08001023 send_call_state_change(call_id);
lld4353242023-03-15 17:02:52 +08001024 }
lld4353242023-03-15 17:02:52 +08001025 return RESULT_OK;
lh25827952022-01-10 00:34:35 -08001026}
1027int lynq_call_hungup_all()
1028{
q.huang8878f362022-10-20 15:25:45 +08001029 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001030 {
q.huang8878f362022-10-20 15:25:45 +08001031 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1032 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001033 }
q.huang8878f362022-10-20 15:25:45 +08001034
1035 Parcel* p=NULL;
1036 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1037 if(ret==RESULT_OK)
lh25827952022-01-10 00:34:35 -08001038 {
q.huang8878f362022-10-20 15:25:45 +08001039 delete p;
1040 }
1041 return ret;
lh25827952022-01-10 00:34:35 -08001042}
rjw3d6a50e2023-02-20 13:35:42 +08001043
1044int lynq_wait_call_state_change(int *handle)
lh25827952022-01-10 00:34:35 -08001045{
q.huang8878f362022-10-20 15:25:45 +08001046 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001047 {
q.huang8878f362022-10-20 15:25:45 +08001048 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1049 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001050 }
rjw3d6a50e2023-02-20 13:35:42 +08001051 wait_call_state();
1052 *handle = s_CallId;
1053 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1054 return RESULT_OK;
lh25827952022-01-10 00:34:35 -08001055}
1056
1057int lynq_set_auto_answercall(const int mode)
1058{
q.huang8878f362022-10-20 15:25:45 +08001059 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001060 {
q.huang8878f362022-10-20 15:25:45 +08001061 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1062 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001063 }
q.huang8878f362022-10-20 15:25:45 +08001064 s_call_auto_answer = mode;
lh25827952022-01-10 00:34:35 -08001065 LYINFLOG("auto answer call mode =%d",mode);
q.huang8878f362022-10-20 15:25:45 +08001066 return RESULT_OK;
lh25827952022-01-10 00:34:35 -08001067}
rjw3d6a50e2023-02-20 13:35:42 +08001068
1069int lynq_find_already_end()
1070{
1071 for(int i=0;i < LYNQ_CALL_MAX; i++)
1072 {
1073 if(s_call_lists[i].call_state == 6)
1074 {
1075 return 0;
1076 }
1077 }
1078 return INVALID_ID;
1079}
1080
q.huangb0eb7b02022-03-29 04:17:32 -04001081int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1082{
q.huang8878f362022-10-20 15:25:45 +08001083 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001084 {
q.huang8878f362022-10-20 15:25:45 +08001085 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1086 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001087 }
q.huangb0eb7b02022-03-29 04:17:32 -04001088 int lynq_call_id = 0;
q.huangf8461432022-06-02 14:49:02 +08001089 LYINFLOG("lynq_get_current_call_state begin ");
q.huangb0eb7b02022-03-29 04:17:32 -04001090 if(handle==NULL)
1091 {
q.huangf8461432022-06-02 14:49:02 +08001092 LYERRLOG("handle is NULL");
q.huang8878f362022-10-20 15:25:45 +08001093 return LYNQ_E_PARAMETER_ANONALY;
q.huangb0eb7b02022-03-29 04:17:32 -04001094 }
ll7b51c492023-04-07 11:41:15 +08001095 if((*handle) <= 0)
1096 {
1097 LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);
1098 return LYNQ_E_INVALID_ID_ANONALY;
1099 }
rjw3d6a50e2023-02-20 13:35:42 +08001100 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huangf8461432022-06-02 14:49:02 +08001101 lynq_call_id = find_call_id_with_call_id(*handle);
1102 if(lynq_call_id==INVALID_ID)
1103 {
ll7b51c492023-04-07 11:41:15 +08001104 *call_state = (int)LYNQ_CALL_END;
1105 return RESULT_OK;
q.huangf8461432022-06-02 14:49:02 +08001106 }
q.huang8878f362022-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);
rjw3d6a50e2023-02-20 13:35:42 +08001111 return RESULT_OK;
q.huangb0eb7b02022-03-29 04:17:32 -04001112}
1113
q.huange0024b02022-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.huang8878f362022-10-20 15:25:45 +08001120 if(s_call_lists[i].used !=0)
q.huange0024b02022-08-29 20:04:31 +08001121 {
1122 cnt++;
1123 }
1124 }
1125
1126 return cnt;
1127}
1128
q.huangb0eb7b02022-03-29 04:17:32 -04001129/*audio begin*/
ll7e055f22022-01-24 12:16:22 +00001130static int judge_mic(const int enable){
llc6030062022-02-14 08:58:16 +00001131 switch(enable){
1132 case 0:
q.huang8878f362022-10-20 15:25:45 +08001133 return true;
llc6030062022-02-14 08:58:16 +00001134 case 1:
q.huang8878f362022-10-20 15:25:45 +08001135 return true;
llc6030062022-02-14 08:58:16 +00001136 default:
q.huang8878f362022-10-20 15:25:45 +08001137 return false;
ll7e055f22022-01-24 12:16:22 +00001138 }
1139}
1140
lh25827952022-01-10 00:34:35 -08001141int lynq_set_mute_mic(const int enable)
ll7e055f22022-01-24 12:16:22 +00001142{
q.huang8878f362022-10-20 15:25:45 +08001143 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001144 {
q.huang8878f362022-10-20 15:25:45 +08001145 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
ll7e055f22022-01-24 12:16:22 +00001146 return LYNQ_E_CONFLICT;
1147 }
q.huang8878f362022-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.huangb0eb7b02022-03-29 04:17:32 -04001160}
1161int lynq_get_mute_mic(int *status)
1162{
q.huang8878f362022-10-20 15:25:45 +08001163 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001164 {
q.huang8878f362022-10-20 15:25:45 +08001165 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1166 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001167 }
q.huang8878f362022-10-20 15:25:45 +08001168 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh25827952022-01-10 00:34:35 -08001169}
ll45d3ea92022-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.huang8878f362022-10-20 15:25:45 +08001181 return true;
ll45d3ea92022-03-24 10:22:25 +08001182 }
1183 if(callnum == '*')
1184 {
q.huang8878f362022-10-20 15:25:45 +08001185 return true;
ll45d3ea92022-03-24 10:22:25 +08001186 }
1187 if(callnum >= '0'&& callnum <= '9')
1188 {
q.huang8878f362022-10-20 15:25:45 +08001189 return true;
ll45d3ea92022-03-24 10:22:25 +08001190 }
q.huang8878f362022-10-20 15:25:45 +08001191 return false;
ll45d3ea92022-03-24 10:22:25 +08001192}
1193
llf79dc4d2022-07-20 09:30:19 +00001194int lynq_switch_waiting_or_holding_and_active(void)
1195{
q.huang8878f362022-10-20 15:25:45 +08001196 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001197 {
q.huang8878f362022-10-20 15:25:45 +08001198 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1199 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001200 }
q.huang8878f362022-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
llf79dc4d2022-07-20 09:30:19 +00001211 Parcel p;
1212 lynq_client_t client;
1213 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001214 int token;
llf79dc4d2022-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);
ll78948a22022-07-25 05:52:14 +00001223 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-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);
ll78948a22022-07-25 05:52:14 +00001230 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001231 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-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.huang8878f362022-10-20 15:25:45 +08001234#endif
llf79dc4d2022-07-20 09:30:19 +00001235}
1236
1237int lynq_hangup_waiting_or_background(void)
1238{
q.huang8878f362022-10-20 15:25:45 +08001239 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001240 {
q.huang8878f362022-10-20 15:25:45 +08001241 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1242 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001243 }
q.huang8878f362022-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
llf79dc4d2022-07-20 09:30:19 +00001253 Parcel p;
1254 lynq_client_t client;
1255 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001256 int token;
llf79dc4d2022-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);
ll78948a22022-07-25 05:52:14 +00001265 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-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);
ll78948a22022-07-25 05:52:14 +00001272 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001273 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-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.huang8878f362022-10-20 15:25:45 +08001276#endif
llf79dc4d2022-07-20 09:30:19 +00001277}
1278
1279int lynq_hangup_foreground_resume_background(void)
1280{
q.huang8878f362022-10-20 15:25:45 +08001281 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001282 {
q.huang8878f362022-10-20 15:25:45 +08001283 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1284 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001285 }
q.huang8878f362022-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
llf79dc4d2022-07-20 09:30:19 +00001295 Parcel p;
1296 lynq_client_t client;
1297 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001298 int token;
llf79dc4d2022-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);
ll78948a22022-07-25 05:52:14 +00001307 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-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);
ll78948a22022-07-25 05:52:14 +00001314 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001315 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-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.huang8878f362022-10-20 15:25:45 +08001318#endif
llf79dc4d2022-07-20 09:30:19 +00001319}
1320
lh25827952022-01-10 00:34:35 -08001321int lynq_set_DTMF(const char callnum)
1322{
q.huang8878f362022-10-20 15:25:45 +08001323 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001324 {
q.huang8878f362022-10-20 15:25:45 +08001325 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1326 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001327 }
ll45d3ea92022-03-24 10:22:25 +08001328 if(!judge_dtmf(callnum))
1329 {
1330 return LYNQ_E_CONFLICT;
1331 }
q.huang8878f362022-10-20 15:25:45 +08001332 if(s_module_call_state!=CALL_ON)
lh25827952022-01-10 00:34:35 -08001333 {
1334 LYERRLOG("LYNQ_E_CONFLICT");
1335 return LYNQ_E_CONFLICT;
1336 }
q.huang8878f362022-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;
lh25827952022-01-10 00:34:35 -08001347}
q.huangb0eb7b02022-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 }
ll7e055f22022-01-24 12:16:22 +00001359 }
ll375c94d2022-01-27 05:54:38 +00001360 return 1;
ll7e055f22022-01-24 12:16:22 +00001361}
lh25827952022-01-10 00:34:35 -08001362int lynq_set_DTMF_volume(const int volume)
ll7e055f22022-01-24 12:16:22 +00001363{
q.huang8878f362022-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);
ll7e055f22022-01-24 12:16:22 +00001367 return LYNQ_E_CONFLICT;
1368 }
q.huang8878f362022-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;
lh25827952022-01-10 00:34:35 -08001380}
q.huang9ee6d5b2022-04-05 23:11:02 -04001381int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh25827952022-01-10 00:34:35 -08001382{
q.huang8878f362022-10-20 15:25:45 +08001383 if(g_module_init_flag != MODULE_RUNNING)
lh25827952022-01-10 00:34:35 -08001384 {
q.huang8878f362022-10-20 15:25:45 +08001385 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangb0eb7b02022-03-29 04:17:32 -04001386 return LYNQ_E_CONFLICT;
lh25827952022-01-10 00:34:35 -08001387 }
q.huang8878f362022-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;
lh25827952022-01-10 00:34:35 -08001400}
q.huangb0eb7b02022-03-29 04:17:32 -04001401int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1402{
q.huang8878f362022-10-20 15:25:45 +08001403 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangb0eb7b02022-03-29 04:17:32 -04001404}
q.huang9ee6d5b2022-04-05 23:11:02 -04001405int lynq_incall_record_start(const char* file_path)
q.huangb0eb7b02022-03-29 04:17:32 -04001406{
q.huang8878f362022-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.huangb0eb7b02022-03-29 04:17:32 -04001415}
1416int lynq_incall_record_stop()
1417{
q.huang8878f362022-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.huang9ee6d5b2022-04-05 23:11:02 -04001423 const char* unused_file="just_ocuupy_paramter_postion";
q.huang8878f362022-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.huangb0eb7b02022-03-29 04:17:32 -04001432}
1433/*audio end*/
q.huang5a738c02022-04-18 00:09:50 -04001434
rjw3d6a50e2023-02-20 13:35:42 +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.huang8878f362022-10-20 15:25:45 +08001454void urc_msg_process(Parcel *p)
1455{
1456 int resp_type;
1457 int urcid;
1458 int slot_id;
rjw3d6a50e2023-02-20 13:35:42 +08001459
1460 int size=p->dataSize();
q.huang8878f362022-10-20 15:25:45 +08001461 p->readInt32(&resp_type);
1462 p->readInt32(&urcid);
1463 p->readInt32(&slot_id);
rjw3d6a50e2023-02-20 13:35:42 +08001464 LYINFLOG("%s urc id = %d, slot_id = %d, size is %d, msg is %s",__func__, urcid,slot_id,size,requestToString(urcid));
q.huang8878f362022-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.huang5a738c02022-04-18 00:09:50 -04001487#ifdef ECALL_SUPPORT
q.huang8878f362022-10-20 15:25:45 +08001488 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange0024b02022-08-29 20:04:31 +08001489 {
q.huang8878f362022-10-20 15:25:45 +08001490 urc_ecall_msg_process(p);
q.huange0024b02022-08-29 20:04:31 +08001491 }
q.huange0024b02022-08-29 20:04:31 +08001492#endif
q.huang8878f362022-10-20 15:25:45 +08001493 default:
1494 break;
q.huang68ee8a02022-06-28 20:12:01 +08001495 }
q.huangdf857562022-06-06 16:15:31 +08001496}
q.huangdf857562022-06-06 16:15:31 +08001497
lh25827952022-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.huangf8461432022-06-02 14:49:02 +08001505 LYDBGLOG("lynq init call fail!!!");
lh25827952022-01-10 00:34:35 -08001506 return -1;
1507 }
q.huangf8461432022-06-02 14:49:02 +08001508 LYDBGLOG("lynq call init success!!!");
lh25827952022-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*/