blob: 4a7c7cf43200f212f501fdc506b57e28037ceae0 [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.huange5595852023-05-30 19:39:42 +080024#include "service_lib_common.h"
q.huang5a738c02022-04-18 00:09:50 -040025
q.huang8878f362022-10-20 15:25:45 +080026#define CALL_OFF (0)
27#define CALL_ON (1)
lh25827952022-01-10 00:34:35 -080028#define USER_LOG_TAG "LYNQ_CALL"
29
30using ::android::Parcel;
q.huang8878f362022-10-20 15:25:45 +080031
32/**
33 * @brief mark call initialization state
34 * 0: deinit state
35 * 1: init state
36 */
37int g_module_init_flag = 0;
38
lh25827952022-01-10 00:34:35 -080039 typedef enum {
40 LYNQ_CALL_ACTIVE = 0,
41 LYNQ_CALL_HOLDING = 1,
42 LYNQ_CALL_DIALING = 2, /* MO call only */
43 LYNQ_CALL_ALERTING = 3, /* MO call only */
44 LYNQ_CALL_INCOMING = 4, /* MT call only */
lh745926c2022-04-26 00:45:44 -070045 LYNQ_CALL_WAITING = 5, /* MT call only */
46 /*warren add for T800 platform 2022/04/26 start*/
47 LYNQ_CALL_END = 6, /*CALL END*/
48 /*warren add for T800 platform 2022/04/26 end*/
lh25827952022-01-10 00:34:35 -080049}lynq_call_state_t;
50
lh25827952022-01-10 00:34:35 -080051typedef struct
52{
53 int used;
54 int call_id;
55 int call_state;
56 int toa;
57 int direction;/*0: MO call,1:MT call*/
58 char addr[LYNQ_PHONE_NUMBER_MAX];
lh25827952022-01-10 00:34:35 -080059}lynq_call_list_e_t;
60typedef struct
61{
62 int call_id;
63 int call_state;
64 int toa;
65 int direction;/*0: MO call,1:MT call*/
66 char addr[LYNQ_PHONE_NUMBER_MAX];
67}lynq_call_list_t;
68
q.huang8878f362022-10-20 15:25:45 +080069static lynq_call_list_e_t s_call_lists[LYNQ_CALL_MAX]={};
70static bool s_call_list_loop = 0;
71static pthread_t s_call_list_loop_tid = -1;
72static pthread_mutex_t s_notice_get_call_list_mutex = PTHREAD_MUTEX_INITIALIZER;
73static pthread_cond_t s_notice_get_call_list_cond = PTHREAD_COND_INITIALIZER;
74
75static int s_module_isDial = 0;
lh25827952022-01-10 00:34:35 -080076static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
77static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
rjw3d6a50e2023-02-20 13:35:42 +080078static int s_CallId = 0;
79static pthread_mutex_t s_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
80static pthread_cond_t s_call_state_change_cond = PTHREAD_COND_INITIALIZER;
lhcdf816a2022-02-13 23:56:05 -080081
q.huang8878f362022-10-20 15:25:45 +080082static int s_module_call_state =CALL_OFF;
83static int s_call_auto_answer = 0;
lh25827952022-01-10 00:34:35 -080084
q.huangb0eb7b02022-03-29 04:17:32 -040085typedef enum{
86 LYNQ_E_VOLUMN_SET_DTMF,
87 LYNQ_E_VOLUMN_SET_SPEECH
q.huang8878f362022-10-20 15:25:45 +080088}LYNQ_E_VOLUMN_SET;
lh25827952022-01-10 00:34:35 -080089
q.huang8878f362022-10-20 15:25:45 +080090#if 0
q.huang2befc3a2022-09-13 14:19:24 +080091int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
lh25827952022-01-10 00:34:35 -080092{
93 if(p.dataAvail() > 0)
94 {
95 p.readInt32(resp_type);
q.huang2befc3a2022-09-13 14:19:24 +080096 p.readInt32(token);
lh25827952022-01-10 00:34:35 -080097 p.readInt32(request);
98 p.readInt32(slot_id);
99 p.readInt32(error);
100 return 0;
101 }
102 else
103 {
104 return -1;
105 }
106}
107int send_request(int sockfd,lynq_client_t *client_tmp)
108{
109 int ret=0;
rjw8bdc56b2022-02-28 15:01:49 +0800110 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh25827952022-01-10 00:34:35 -0800111 if(ret==-1)
112 {
q.huangf8461432022-06-02 14:49:02 +0800113 LYERRLOG("sendto error");
lh25827952022-01-10 00:34:35 -0800114 return -1;
115 }
116 return 0;
117}
118
119int get_response(int sockfd,Parcel &p)
120{
121 int len = 0;
122 char recvline[LYNQ_REC_BUF];
123 bzero(recvline,LYNQ_REC_BUF);
124 /* receive data from server */
rjw8bdc56b2022-02-28 15:01:49 +0800125 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh25827952022-01-10 00:34:35 -0800126 if(len == -1)
127 {
q.huangf8461432022-06-02 14:49:02 +0800128 LYERRLOG("recvfrom error");
lh25827952022-01-10 00:34:35 -0800129 return -1;
130 }
lh25827952022-01-10 00:34:35 -0800131 if (recvline != NULL) {
132 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
133 p.setDataPosition(0);
134 }
135 return 0;
136}
q.huang8878f362022-10-20 15:25:45 +0800137#endif
138static char *strdupReadString(Parcel* &p) {
ll375c94d2022-01-27 05:54:38 +0000139 size_t stringlen;
lh25827952022-01-10 00:34:35 -0800140 const char16_t *s16;
q.huang8878f362022-10-20 15:25:45 +0800141 s16 = p->readString16Inplace(&stringlen);
ll375c94d2022-01-27 05:54:38 +0000142 return strndup16to8(s16, stringlen);
lh25827952022-01-10 00:34:35 -0800143}
144
145int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
146{
q.huang8878f362022-10-20 15:25:45 +0800147 Parcel* p=NULL;
148 int ret=lynq_send_common_request(p,8,RIL_REQUEST_GET_CURRENT_CALLS,0,"");
149 if(ret!=0)
150 {
151 return ret;
152 }
153
154 int call_num = 0;
155 int temp = 0;
156 char *remote_phoneNum;
157 char *remote_name;
158 char uusData[128];
159
160 p->readInt32(&call_num);
161
162 if(call_num<=0)
163 {
164 s_module_call_state = CALL_OFF;
165 LYINFLOG("lynq_call_state:%d",s_module_call_state);
166 delete p;
167 return RESULT_OK;
168 }
169 s_module_call_state = CALL_ON;
170 LYINFLOG("lynq_call_state:%d, call num is %d ",s_module_call_state,call_num);
171 for(int i = 0;i < call_num;i++)
172 {
173 p->readInt32(&temp);
174 call_list[i].call_state = temp;
175 p->readInt32(&call_list[i].call_id);
176 p->readInt32(&call_list[i].toa);
177 p->readInt32(&temp);
178 p->readInt32(&temp);
179 call_list[i].direction = temp;
180 p->readInt32(&temp);
181 p->readInt32(&temp);
182 p->readInt32(&temp);
183 remote_phoneNum = strdupReadString(p);
184 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
185 if(remote_phoneNum !=NULL)
186 {
187 free(remote_phoneNum);
188 }
189 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
190 call_list[i].direction,call_list[i].addr,call_list[i].toa);
191 p->readInt32(&temp);
192 remote_name = strdupReadString(p);
193 if(remote_name !=NULL)
194 {
195 free(remote_name);
196 }
197 p->readInt32(&temp);
198 p->readInt32(&temp);
199 if(temp==0)
200 {
201 continue;
202 }
203 p->readInt32(&temp); /* UUS Information is present */
204 p->readInt32(&temp);
205 p->readInt32(&temp);
206 if(temp<=128)
207 {
208 p->read(uusData,temp);
209 }
210 else
211 {
212 LYERRLOG("%s len %d is too great",__func__,temp);
213 delete p;
214 return LYNQ_E_MALLOC_ERROR;
215 }
216 }
217
218 delete p;
219 return RESULT_OK;
220
221#if 0
lh25827952022-01-10 00:34:35 -0800222 Parcel p;
223 lynq_client_t client;
224 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +0800225 int token;
lh25827952022-01-10 00:34:35 -0800226 int request = -1;
227 int slot_id = -1;
228 int error = -1;
229 int call_num = 0;
230 int temp = 0;
231 char *remote_phoneNum = NULL;
232 char *remote_name= NULL;
233 char *uusData = NULL;
lha35d4ee2022-01-25 18:47:39 -0800234 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -0800235 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
236 client.paramLen = 0;
237 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangf8461432022-06-02 14:49:02 +0800238 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800239 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800240 {
241 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800242 return -1;
243 }
lha35d4ee2022-01-25 18:47:39 -0800244 get_response(lynq_call_client_sockfd,p);
q.huang2befc3a2022-09-13 14:19:24 +0800245 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh25827952022-01-10 00:34:35 -0800246 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
247 if(error == 0)
248 {
249 p.readInt32(&call_num);
250 global_call_count = call_num;
251 if(call_num<=0)
252 {
253 lynq_call_state = CALL_OFF;
lhcdf816a2022-02-13 23:56:05 -0800254 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh25827952022-01-10 00:34:35 -0800255 return 0;
256 }
lhcdf816a2022-02-13 23:56:05 -0800257 lynq_call_state = CALL_ON;
q.huangf8461432022-06-02 14:49:02 +0800258 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh25827952022-01-10 00:34:35 -0800259 for(int i = 0;i < call_num;i++)
260 {
261 p.readInt32(&temp);
262 call_list[i].call_state = temp;
263 p.readInt32(&call_list[i].call_id);
264 p.readInt32(&call_list[i].toa);
265 p.readInt32(&temp);
266 p.readInt32(&temp);
267 call_list[i].direction = temp;
268 p.readInt32(&temp);
269 p.readInt32(&temp);
270 p.readInt32(&temp);
271 remote_phoneNum = strdupReadString(p);
272 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
273 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
274 call_list[i].direction,call_list[i].addr,call_list[i].toa);
275 p.readInt32(&temp);
276 remote_name = strdupReadString(p);
277 p.readInt32(&temp);
278 p.readInt32(&temp);
279 if(temp==0)
280 {
281 continue;
282 }
283 p.readInt32(&temp); /* UUS Information is present */
284 p.readInt32(&temp);
285 p.readInt32(&temp);
286 p.read(uusData,temp);
287 }
288 }
289 return 0;
q.huang8878f362022-10-20 15:25:45 +0800290#endif
lh25827952022-01-10 00:34:35 -0800291}
292
293void cleanCallList(int lynq_call_id)
294{
q.huang8878f362022-10-20 15:25:45 +0800295 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
296 s_call_lists[lynq_call_id].call_id = 0;
297 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
298 s_call_lists[lynq_call_id].toa = 0;
299 s_call_lists[lynq_call_id].direction = 0;
300 s_call_lists[lynq_call_id].used = 0;
301 memset(s_call_lists[lynq_call_id].addr,0,sizeof(s_call_lists[lynq_call_id].addr));
lh25827952022-01-10 00:34:35 -0800302}
rjw3d6a50e2023-02-20 13:35:42 +0800303
304
lh25827952022-01-10 00:34:35 -0800305int getUnusedElement()
306{
307 for(int i=0;i < LYNQ_CALL_MAX; i++)
308 {
q.huang8878f362022-10-20 15:25:45 +0800309 if(s_call_lists[i].used!=1)
lh25827952022-01-10 00:34:35 -0800310 {
311 return i;
312 }
313 }
q.huang8878f362022-10-20 15:25:45 +0800314 return INVALID_ID;
lh25827952022-01-10 00:34:35 -0800315}
q.huang8878f362022-10-20 15:25:45 +0800316int addAddr(char addr[], int call_id)
lh25827952022-01-10 00:34:35 -0800317{
318 int ret = 0;
319 ret = getUnusedElement();
q.huang8878f362022-10-20 15:25:45 +0800320 memcpy(s_call_lists[ret].addr,addr,strlen(addr)+1);
321 s_call_lists[ret].call_id=call_id;
322 s_call_lists[ret].used = 1;
q.huangf8461432022-06-02 14:49:02 +0800323 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh25827952022-01-10 00:34:35 -0800324 return ret;
325}
326void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
327{
q.huangf8461432022-06-02 14:49:02 +0800328 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh25827952022-01-10 00:34:35 -0800329 callList->call_id = call_id;
330 callList->call_state = call_state;
331 callList->toa = toa;
q.huangf8461432022-06-02 14:49:02 +0800332 callList->direction = direction;
lh25827952022-01-10 00:34:35 -0800333 return;
334}
rjw3d6a50e2023-02-20 13:35:42 +0800335
336void wait_call_state()
lh25827952022-01-10 00:34:35 -0800337{
rjw3d6a50e2023-02-20 13:35:42 +0800338 LYINFLOG("call state changed");
339 pthread_mutex_lock(&s_call_state_change_mutex);
340 pthread_cond_wait(&s_call_state_change_cond,&s_call_state_change_mutex);
341 pthread_mutex_unlock(&s_call_state_change_mutex);
lh25827952022-01-10 00:34:35 -0800342}
rjw3d6a50e2023-02-20 13:35:42 +0800343
lh25827952022-01-10 00:34:35 -0800344int checkHasCall(char addr[])
345{
346 for(int i = 0;i<LYNQ_CALL_MAX;i++)
347 {
q.huang8878f362022-10-20 15:25:45 +0800348 if(strcmp(s_call_lists[i].addr,addr)==0)
lh25827952022-01-10 00:34:35 -0800349 {
q.huang8878f362022-10-20 15:25:45 +0800350 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,s_call_lists[i].call_id);
351 return true;
lh25827952022-01-10 00:34:35 -0800352 }
353 }
q.huangf8461432022-06-02 14:49:02 +0800354 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
q.huang8878f362022-10-20 15:25:45 +0800355 return false;
lh25827952022-01-10 00:34:35 -0800356}
lh5095be72022-04-19 06:01:25 -0700357int find_call_id_with_addr(char *addr)
358{
lh5095be72022-04-19 06:01:25 -0700359 for(int id = 0; id < LYNQ_CALL_MAX; id++)
360 {
q.huang8878f362022-10-20 15:25:45 +0800361 if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
lh5095be72022-04-19 06:01:25 -0700362 {
q.huang8878f362022-10-20 15:25:45 +0800363 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 -0700364 return id;
365 }
366 }
q.huangf8461432022-06-02 14:49:02 +0800367 LYINFLOG("find addr %s in local list , not found",addr);
q.huang8878f362022-10-20 15:25:45 +0800368 return INVALID_ID;
lh5095be72022-04-19 06:01:25 -0700369}
q.huangf8461432022-06-02 14:49:02 +0800370int find_call_id_with_call_id(int call_id)
371{
372 for(int id = 0; id < LYNQ_CALL_MAX; id++)
373 {
q.huang8878f362022-10-20 15:25:45 +0800374 if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
q.huangf8461432022-06-02 14:49:02 +0800375 {
q.huang8878f362022-10-20 15:25:45 +0800376 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 +0800377 return id;
378 }
379 }
380 LYINFLOG("find id %d in local list , not found",call_id);
381 return INVALID_ID;
382}
lh25827952022-01-10 00:34:35 -0800383void sendSignalToWaitCallStateChange()
384{
lh5095be72022-04-19 06:01:25 -0700385 LYINFLOG("send Signal To Wait Call State Change");
lh25827952022-01-10 00:34:35 -0800386 pthread_mutex_lock(&call_state_change_mutex);
387 pthread_cond_signal(&call_state_change_cond);
388 pthread_mutex_unlock(&call_state_change_mutex);
389}
ll7b51c492023-04-07 11:41:15 +0800390void send_call_state_change(int callid)
lh25827952022-01-10 00:34:35 -0800391{
rjw3d6a50e2023-02-20 13:35:42 +0800392 LYINFLOG("send call state change");
ll7b51c492023-04-07 11:41:15 +0800393 s_CallId = callid;
rjw3d6a50e2023-02-20 13:35:42 +0800394 pthread_mutex_lock(&s_call_state_change_mutex);
395 pthread_cond_signal(&s_call_state_change_cond);
396 pthread_mutex_unlock(&s_call_state_change_mutex);
lh25827952022-01-10 00:34:35 -0800397}
398
q.huang8878f362022-10-20 15:25:45 +0800399void cleanup_call_list_mutex(void *arg)
lh25827952022-01-10 00:34:35 -0800400{
q.huang8878f362022-10-20 15:25:45 +0800401 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
lh25827952022-01-10 00:34:35 -0800402}
rjw3d6a50e2023-02-20 13:35:42 +0800403
404void update_end_state(int lynq_call_id)
405{
406 LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
407 s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
408}
409
lh25827952022-01-10 00:34:35 -0800410void *triggerGetCallList(void *parg)
ll375c94d2022-01-27 05:54:38 +0000411{
412 int ret=0;
lh5095be72022-04-19 06:01:25 -0700413 bool call_end;
ll375c94d2022-01-27 05:54:38 +0000414 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huangaa75aa62022-04-19 20:27:44 -0400415 int update=0;
q.huangf8461432022-06-02 14:49:02 +0800416 int cnt;
417 int i,n;
q.huange0024b02022-08-29 20:04:31 +0800418#ifdef ECALL_SUPPORT
419 int handupIncomingMT=0;
420#endif
q.huang8878f362022-10-20 15:25:45 +0800421 pthread_mutex_lock(&s_notice_get_call_list_mutex);
422 pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
ll7b51c492023-04-07 11:41:15 +0800423 int tmp_call_id;
q.huang8878f362022-10-20 15:25:45 +0800424 while(s_call_list_loop)
ll375c94d2022-01-27 05:54:38 +0000425 {
q.huang8878f362022-10-20 15:25:45 +0800426 update=0;
427 pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
rjw1f8a2ee42023-03-06 15:19:40 +0800428 LYINFLOG("triggerGetCallList event %p!!!", pthread_self());
ll375c94d2022-01-27 05:54:38 +0000429 memset(call_list,0,sizeof(call_list));
430 ret = lynq_get_current_call_list(call_list);
q.huang8878f362022-10-20 15:25:45 +0800431 if(ret != RESULT_OK)
ll375c94d2022-01-27 05:54:38 +0000432 {
rjw1f8a2ee42023-03-06 15:19:40 +0800433 LYERRLOG("get current call list failure!!!");
ll83081992022-04-11 05:49:51 +0000434 continue;
ll375c94d2022-01-27 05:54:38 +0000435 }
lh5095be72022-04-19 06:01:25 -0700436 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huangf8461432022-06-02 14:49:02 +0800437 LYINFLOG("clear local index begin");
438 cnt=0;
439 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh25827952022-01-10 00:34:35 -0800440 {
q.huang8878f362022-10-20 15:25:45 +0800441 if(s_call_lists[i].used ==0)
q.huangf8461432022-06-02 14:49:02 +0800442 {
443 continue;
444 }
445 cnt++;
q.huang8878f362022-10-20 15:25:45 +0800446 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 +0800447
q.huang8878f362022-10-20 15:25:45 +0800448 if(s_call_lists[i].call_id > 0)
lh5095be72022-04-19 06:01:25 -0700449 {
450 call_end = 0;
q.huangf8461432022-06-02 14:49:02 +0800451 for(n = 0; n < LYNQ_CALL_MAX; n++)
lh5095be72022-04-19 06:01:25 -0700452 {
q.huang8878f362022-10-20 15:25:45 +0800453 if(call_list[n].call_id == s_call_lists[i].call_id)
lh5095be72022-04-19 06:01:25 -0700454 {
455 call_end = 1;
q.huang8878f362022-10-20 15:25:45 +0800456 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 +0800457 break;
lh5095be72022-04-19 06:01:25 -0700458 }
459 }
460 if(call_end == 0)
461 {
rjw3d6a50e2023-02-20 13:35:42 +0800462 LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
463 //update_end_state(i);//lei modify for:update end state for this call
ll7b51c492023-04-07 11:41:15 +0800464 tmp_call_id = s_call_lists[i].call_id;
rjw3d6a50e2023-02-20 13:35:42 +0800465 cleanCallList(i);
lld4353242023-03-15 17:02:52 +0800466 //Release the end handle
ll7b51c492023-04-07 11:41:15 +0800467 send_call_state_change(tmp_call_id);//means mt/mo call is end
rjw3d6a50e2023-02-20 13:35:42 +0800468 //cleanCallList(i);
lh5095be72022-04-19 06:01:25 -0700469 }
470 } //fix bug API-54
q.huangf8461432022-06-02 14:49:02 +0800471 else
472 {
473 LYINFLOG("local id is 0");
474 }
475 }
476 LYINFLOG("clear local index end, local used cnt is %d", cnt);
477
478 LYINFLOG("add or update local index begin ");
479 for (i = 0;i < LYNQ_CALL_MAX;i++)
480 {
481 if(call_list[i].call_id==0)
482 {
483 break;
484 }
485
486 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,
487 call_list[i].direction,call_list[i].addr,call_list[i].toa);
488
lh25827952022-01-10 00:34:35 -0800489 if(call_list[i].direction == 1)//MT call
490 {
q.huangf8461432022-06-02 14:49:02 +0800491 LYINFLOG("This is a MT CALL");
lh36a140b2022-05-13 03:02:19 -0700492 /*MT CALL state code
493 **LYNQ_CALL_INCOMING = 4,
494 **LYNQ_CALL_WAITING = 5,
495 */
q.huange0024b02022-08-29 20:04:31 +0800496#ifdef ECALL_SUPPORT
lh36a140b2022-05-13 03:02:19 -0700497 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh25827952022-01-10 00:34:35 -0800498 {
q.huang8878f362022-10-20 15:25:45 +0800499 handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
q.huange0024b02022-08-29 20:04:31 +0800500 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
501 if(handupIncomingMT)
lh25827952022-01-10 00:34:35 -0800502 {
q.huangf8461432022-06-02 14:49:02 +0800503 lynq_call_hungup(&(call_list[i].call_id));
504 continue;
q.huange0024b02022-08-29 20:04:31 +0800505 }
q.huangf8461432022-06-02 14:49:02 +0800506 }
q.huange0024b02022-08-29 20:04:31 +0800507#endif
q.huangf8461432022-06-02 14:49:02 +0800508 /*you call me, and i call you,One party failed to dial*/
509 n = find_call_id_with_addr(call_list[i].addr);
510 if(n ==INVALID_ID)
511 {
q.huang8878f362022-10-20 15:25:45 +0800512 n = addAddr(call_list[i].addr,call_list[i].call_id);
513 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 +0800514 send_call_state_change(call_list[i].call_id);
q.huangf8461432022-06-02 14:49:02 +0800515 }
q.huang8878f362022-10-20 15:25:45 +0800516 else if(s_call_lists[n].call_state == call_list[i].call_state)
q.huangf8461432022-06-02 14:49:02 +0800517 {
518 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
519 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lh5095be72022-04-19 06:01:25 -0700520 {
lh5095be72022-04-19 06:01:25 -0700521 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
522 **an incoming call until the status changes.
523 **fix bug API-54
524 */
q.huangf8461432022-06-02 14:49:02 +0800525 LYINFLOG("resend incoming call signal");
ll7b51c492023-04-07 11:41:15 +0800526 send_call_state_change(call_list[i].call_id);
lh5095be72022-04-19 06:01:25 -0700527 }
lh25827952022-01-10 00:34:35 -0800528 }
q.huangf8461432022-06-02 14:49:02 +0800529 else
ll45d3ea92022-03-24 10:22:25 +0800530 {
q.huang8878f362022-10-20 15:25:45 +0800531 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 +0800532
rjw3d6a50e2023-02-20 13:35:42 +0800533 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 +0800534 send_call_state_change(call_list[i].call_id);
rjw3d6a50e2023-02-20 13:35:42 +0800535 }
lh25827952022-01-10 00:34:35 -0800536 }
537 else
q.huangf8461432022-06-02 14:49:02 +0800538 {
539 LYINFLOG("This is a MO CALL");
540 call_end = 0;
541 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh25827952022-01-10 00:34:35 -0800542 {
q.huang8878f362022-10-20 15:25:45 +0800543 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 -0800544 {
q.huang8878f362022-10-20 15:25:45 +0800545 if(s_call_lists[n].call_id==0)
q.huangf8461432022-06-02 14:49:02 +0800546 {
rjw3d6a50e2023-02-20 13:35:42 +0800547 LYINFLOG("add a call id");
548 update=1;//for send sigal
q.huangf8461432022-06-02 14:49:02 +0800549 }
q.huang8878f362022-10-20 15:25:45 +0800550 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);
551 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 +0800552 call_end = 1;
ll7b51c492023-04-07 11:41:15 +0800553 send_call_state_change(call_list[i].call_id);//means mo call is success
q.huangf8461432022-06-02 14:49:02 +0800554 break;
555 }
556 }
rjw3d6a50e2023-02-20 13:35:42 +0800557 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 +0800558 {
559 LYINFLOG("need to hangup id %d", call_list[i].call_id);
560#ifdef ECALL_SUPPORT
q.huang8878f362022-10-20 15:25:45 +0800561 if(IsECallDialing())
q.huangf8461432022-06-02 14:49:02 +0800562 {
563 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh25827952022-01-10 00:34:35 -0800564 continue;
565 }
q.huangf8461432022-06-02 14:49:02 +0800566#endif
567 LYINFLOG("hang up service call id %d",call_list[i].call_id);
568 lynq_call_hungup(&(call_list[i].call_id));
lh25827952022-01-10 00:34:35 -0800569 }
rjw3d6a50e2023-02-20 13:35:42 +0800570
lh25827952022-01-10 00:34:35 -0800571 }
q.huangf8461432022-06-02 14:49:02 +0800572 LYDBGLOG("servie idx %d end",i);
ll375c94d2022-01-27 05:54:38 +0000573 }
q.huang8878f362022-10-20 15:25:45 +0800574 LYINFLOG("add or update local index end ");
575 if(s_module_isDial==1)
lh25827952022-01-10 00:34:35 -0800576 {
q.huangf8461432022-06-02 14:49:02 +0800577 LYINFLOG("now is dialing");
578 if(update==1)
579 {
580 LYINFLOG("find added call");
581 sendSignalToWaitCallStateChange();
q.huang8878f362022-10-20 15:25:45 +0800582 s_module_isDial = 0;
q.huangf8461432022-06-02 14:49:02 +0800583 }
584 else
585 {
586 LYINFLOG("not find added call");
587 }
588 }
589 else
590 {
591 LYINFLOG("now is not dialing");
q.huang8878f362022-10-20 15:25:45 +0800592 }
ll375c94d2022-01-27 05:54:38 +0000593 }
q.huang8878f362022-10-20 15:25:45 +0800594 pthread_cleanup_pop(0);
595 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
ll375c94d2022-01-27 05:54:38 +0000596 return NULL;
lh25827952022-01-10 00:34:35 -0800597}
598
q.huang8878f362022-10-20 15:25:45 +0800599void lynqNoticeGetModuleCallList()
ll375c94d2022-01-27 05:54:38 +0000600{
rjw1f8a2ee42023-03-06 15:19:40 +0800601 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send start");
q.huang8878f362022-10-20 15:25:45 +0800602 pthread_mutex_lock(&s_notice_get_call_list_mutex);
603 pthread_cond_signal(&s_notice_get_call_list_cond);
604 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
rjw1f8a2ee42023-03-06 15:19:40 +0800605 LYINFLOG("RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED send end");
lh25827952022-01-10 00:34:35 -0800606}
607
q.huang8878f362022-10-20 15:25:45 +0800608#if 0
lh25827952022-01-10 00:34:35 -0800609/*Warren add for T800 platform 2021/11/19 start*/
610int lynq_socket_client_start()
rjw8bdc56b2022-02-28 15:01:49 +0800611{
612 #if 0
lh25827952022-01-10 00:34:35 -0800613 struct sockaddr_in lynq_socket_server_addr;
614 /* init lynq_socket_server_addr */
615 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
616 lynq_socket_server_addr.sin_family = AF_INET;
617 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
618 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw8bdc56b2022-02-28 15:01:49 +0800619
lh25827952022-01-10 00:34:35 -0800620 /*
621 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
622 {
q.huangf8461432022-06-02 14:49:02 +0800623 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh25827952022-01-10 00:34:35 -0800624 exit(1);
625 }
626*/
lha35d4ee2022-01-25 18:47:39 -0800627 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
628 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh25827952022-01-10 00:34:35 -0800629 {
q.huangf8461432022-06-02 14:49:02 +0800630 LYERRLOG("connect error");
lh25827952022-01-10 00:34:35 -0800631 return -1;
632 }
rjw8bdc56b2022-02-28 15:01:49 +0800633 #endif
634 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
635 if (-1 == lynq_call_client_sockfd)
636 {
637 return lynq_call_client_sockfd;
638 }
ll78948a22022-07-25 05:52:14 +0000639 struct timeval timeOut;
640 timeOut.tv_sec = 60;
641 timeOut.tv_usec = 0;
642 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
643 {
644 RLOGD("time out setting failed\n");
645 return -1;
646 }
rjw8bdc56b2022-02-28 15:01:49 +0800647 /* 设置address */
648 memset(&addr_serv, 0, sizeof(addr_serv));
649 addr_serv.sin_family = AF_INET;
650 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
651 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
652 len_addr_serv = sizeof(addr_serv);
lh25827952022-01-10 00:34:35 -0800653 return 0;
654}
lh25827952022-01-10 00:34:35 -0800655
lh25827952022-01-10 00:34:35 -0800656int lynq_socket_urc_start()
657{
658 int socket_fd=0;
659 int rt=0;
660 int len=0;
661 int on=1;
662 struct sockaddr_in urc_local_addr;
lh25827952022-01-10 00:34:35 -0800663 pthread_attr_t attr;
ll375c94d2022-01-27 05:54:38 +0000664 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll375c94d2022-01-27 05:54:38 +0000665 if(socket_fd < 0)
666 {
q.huangf8461432022-06-02 14:49:02 +0800667 LYERRLOG("creaet socket for udp fail");
ll375c94d2022-01-27 05:54:38 +0000668 return -1;
lh25827952022-01-10 00:34:35 -0800669 }
670 urc_local_addr.sin_family = AF_INET;
671 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
672 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
673 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll375c94d2022-01-27 05:54:38 +0000674 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
675 if(rt<0)
676 {
q.huangf8461432022-06-02 14:49:02 +0800677 LYERRLOG("SO_REUSEADDR fail");
lh25827952022-01-10 00:34:35 -0800678 return -1;
679 }
680 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll375c94d2022-01-27 05:54:38 +0000681 if (rt == -1)
682 {
lh59e0d002022-01-27 00:27:12 -0800683 LYERRLOG("bind failed");
ll375c94d2022-01-27 05:54:38 +0000684 return -1;
lh25827952022-01-10 00:34:35 -0800685 }
686 pthread_attr_init(&attr);
687 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -0800688 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh25827952022-01-10 00:34:35 -0800689 if(rt < 0)
690 {
q.huangf8461432022-06-02 14:49:02 +0800691 LYERRLOG("urc loop failure!!!");
lh25827952022-01-10 00:34:35 -0800692 return -1;
693 }
q.huangf8461432022-06-02 14:49:02 +0800694 LYDBGLOG("urc loop success!!!");
lh25827952022-01-10 00:34:35 -0800695 return 0;
696}
q.huang8878f362022-10-20 15:25:45 +0800697#endif
lh25827952022-01-10 00:34:35 -0800698
699void lynq_call_state_change_test(int soc_id)
700{
q.huangf8461432022-06-02 14:49:02 +0800701 LYDBGLOG("call state change,sim:%d",soc_id);
lh25827952022-01-10 00:34:35 -0800702}
q.huang68ee8a02022-06-28 20:12:01 +0800703
q.huang8878f362022-10-20 15:25:45 +0800704int lynq_start_call_list_loop()
705{
706#if 0
707 int ret = 0;
708 pthread_attr_t attr;
709 pthread_attr_init(&attr);
710 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
q.huang68ee8a02022-06-28 20:12:01 +0800711
q.huang8878f362022-10-20 15:25:45 +0800712 s_notice_get_call_list_mutex = new pthread_mutex_t;
713 pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
714 s_notice_get_call_list_cond = new pthread_cond_t;
715 LYINFLOG("liulei s_notice_get_call_list_mutex\n");
716 pthread_cond_init(s_notice_get_call_list_cond, NULL);
717 LYINFLOG("liulei s_notice_get_call_list_cond\n");
718#endif
q.huang68ee8a02022-06-28 20:12:01 +0800719
q.huang8878f362022-10-20 15:25:45 +0800720 s_call_list_loop = 1;
721 int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
722 if(ret < 0)
q.huang68ee8a02022-06-28 20:12:01 +0800723 {
q.huang8878f362022-10-20 15:25:45 +0800724 LYERRLOG("lynq_update_call_list_loop fail!!!");
ll1343a5b2022-03-17 05:31:33 +0000725 return -1;
726 }
q.huang8878f362022-10-20 15:25:45 +0800727 LYINFLOG("lynq_update_call_list_loop success!!!");
q.huang68ee8a02022-06-28 20:12:01 +0800728
q.huang8878f362022-10-20 15:25:45 +0800729 memset(s_call_lists,0,sizeof(s_call_lists));
lh25827952022-01-10 00:34:35 -0800730 return 0;
731}
q.huang8878f362022-10-20 15:25:45 +0800732
733int lynq_stop_call_list_loop()
lh25827952022-01-10 00:34:35 -0800734{
q.huangf8461432022-06-02 14:49:02 +0800735 int ret;
q.huang8878f362022-10-20 15:25:45 +0800736 pthread_mutex_lock(&s_notice_get_call_list_mutex);
737 s_call_list_loop = 0;
738 ret = pthread_cancel(s_call_list_loop_tid);
739 LYINFLOG("pthread cancel w_c_list ret = %d",ret);
740 pthread_mutex_unlock(&s_notice_get_call_list_mutex);
741 ret = pthread_join(s_call_list_loop_tid,NULL);
742 LYINFLOG("pthread join w_c_list ret = %d",ret);
743 s_call_list_loop_tid=-1;
744#if 0
745 pthread_mutex_destroy(s_notice_get_call_list_mutex);
746 pthread_cond_destroy(s_notice_get_call_list_cond);
747 delete s_notice_get_call_list_mutex;
748 //s_notice_get_call_list_mutex = NULL;
749 delete s_notice_get_call_list_cond;
750 //s_notice_get_call_list_cond = NULL;
751#endif
752
753 return 0;
ll83081992022-04-11 05:49:51 +0000754}
q.huang5a738c02022-04-18 00:09:50 -0400755
q.huang8878f362022-10-20 15:25:45 +0800756int lynq_init_call(int utoken){
757 if(g_module_init_flag != MODULE_CLOSED)
758 {
759 LYERRLOG("module state is %d",g_module_init_flag);
760 return LYNQ_E_CONFLICT;
761 }
762 if(utoken <0){
763 LYERRLOG("utoken is less than 0",utoken);
764 return LYNQ_E_PARAMETER_ANONALY;
765 }
766 g_module_init_flag = MODULE_SWITCHING;
767
768 LYLOGSET(LOG_INFO);
769 LYLOGEINIT(USER_LOG_TAG);
770
771 g_module_Global_uToken = utoken;
772
rjw3d6a50e2023-02-20 13:35:42 +0800773 int ret = lynq_start_all_urc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800774 if(ret != RESULT_OK)
775 {
776 LYERRLOG("init socket urc fail!!!");
777 g_module_init_flag = MODULE_CLOSED;
778 return LYNQ_E_INNER_ERROR;
779 }
780
rjw3d6a50e2023-02-20 13:35:42 +0800781 ret = lynq_start_all_rc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800782 if(ret !=RESULT_OK)
783 {
784 LYERRLOG("init socket client fail!!!");
rjw3d6a50e2023-02-20 13:35:42 +0800785 lynq_close_all_urc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800786 g_module_init_flag = MODULE_CLOSED;
787 return LYNQ_E_INNER_ERROR;
788 }
789
790
791 int result = lynq_start_call_list_loop();
792 if(ret != RESULT_OK)
793 {
794 LYERRLOG("lynq_start_call_list_loop fail!!!");
rjw3d6a50e2023-02-20 13:35:42 +0800795 lynq_close_all_urc_socket_thread();
796 lynq_close_all_rc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800797 g_module_init_flag = MODULE_CLOSED;
798 return LYNQ_E_INNER_ERROR;
799 }
800
q.huang8878f362022-10-20 15:25:45 +0800801 g_module_init_flag = MODULE_RUNNING;
802 return 0;
803}
804
805int lynq_deinit_call(void){
806
807 if (g_module_init_flag != MODULE_RUNNING)
808 {
809 LYERRLOG("module state is %d",g_module_init_flag);
810 return LYNQ_E_CONFLICT;
811 }
q.huangb07e29a2023-05-25 10:28:32 +0800812 lynq_call_hungup_all();
q.huang8878f362022-10-20 15:25:45 +0800813 g_module_init_flag = MODULE_SWITCHING;
rjw3d6a50e2023-02-20 13:35:42 +0800814 lynq_close_all_urc_socket_thread();
815 lynq_close_all_rc_socket_thread();
q.huang8878f362022-10-20 15:25:45 +0800816 lynq_stop_call_list_loop();
817 g_module_init_flag = MODULE_CLOSED;
818 return 0;
819}
820
821#if 0
q.huang5a738c02022-04-18 00:09:50 -0400822int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita9b436d82022-04-07 01:55:39 -0400823{
824 Parcel p;
825 lynq_client_t client;
826 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +0800827 int token;
rita9b436d82022-04-07 01:55:39 -0400828 int request = -1;
829 int slot_id = -1;
830 int error = -1;
rita9b436d82022-04-07 01:55:39 -0400831
q.huang8878f362022-10-20 15:25:45 +0800832 Parcel* p=NULL;
833 int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
834 if(ret==RESULT_OK)
835 {
836 delete p;
837 }
838 return ret;
839
rita9b436d82022-04-07 01:55:39 -0400840 client.uToken = Global_uToken_call;
q.huang5a738c02022-04-18 00:09:50 -0400841 client.request = request_id;
842 client.paramLen = argc;
rita9b436d82022-04-07 01:55:39 -0400843 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang5a738c02022-04-18 00:09:50 -0400844 if(argc!=0)
845 {
846 va_list args;
847 va_start(args, format);
848 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
849 va_end(args);
850 }
q.huangf8461432022-06-02 14:49:02 +0800851 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -0400852 if(send_request(lynq_call_client_sockfd,&client)==-1)
853 {
854 LYERRLOG("send request fail");
855 return -1;
856 }
q.huang5a738c02022-04-18 00:09:50 -0400857 if(get_response(lynq_call_client_sockfd,p)==0)
858 {
q.huang2befc3a2022-09-13 14:19:24 +0800859 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang5a738c02022-04-18 00:09:50 -0400860 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
861 }
rita9b436d82022-04-07 01:55:39 -0400862 return error;
q.huang8878f362022-10-20 15:25:45 +0800863
864
rita9b436d82022-04-07 01:55:39 -0400865}
q.huang8878f362022-10-20 15:25:45 +0800866#endif
rita9b436d82022-04-07 01:55:39 -0400867
q.huang5a738c02022-04-18 00:09:50 -0400868int lynq_get_common_request(int request_id, int* status)
rita9b436d82022-04-07 01:55:39 -0400869{
q.huang5a738c02022-04-18 00:09:50 -0400870 if(status==NULL)
871 {
872 LYERRLOG("status is null");
q.huang8878f362022-10-20 15:25:45 +0800873 return LYNQ_E_PARAMETER_ANONALY;
q.huang5a738c02022-04-18 00:09:50 -0400874 }
q.huang8878f362022-10-20 15:25:45 +0800875
876 Parcel* p=NULL;
877 int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
878 if(ret==RESULT_OK)
rita9b436d82022-04-07 01:55:39 -0400879 {
q.huang8878f362022-10-20 15:25:45 +0800880 p->readInt32(status);
881 delete p;
rita9b436d82022-04-07 01:55:39 -0400882 }
q.huang8878f362022-10-20 15:25:45 +0800883 return ret;
884}
885
886int waitCallstateChange(int mtime)
887{
888 LYINFLOG("wait Call state Change");
889 int ret = 0;
890 int sec = 0;
ll7b51c492023-04-07 11:41:15 +0800891 int ms = 0;
q.huang8878f362022-10-20 15:25:45 +0800892 struct timeval now;
893 struct timespec timeout;
894 gettimeofday(&now,NULL);
895 sec = mtime/1000;
ll7b51c492023-04-07 11:41:15 +0800896 ms = mtime%1000;
q.huang8878f362022-10-20 15:25:45 +0800897 timeout.tv_sec = now.tv_sec+sec;
ll7b51c492023-04-07 11:41:15 +0800898 unsigned long long ns;
899 ns = now.tv_usec*1000ull + ms*1000000ull;
900 timeout.tv_sec += ns/1000000000;
901 timeout.tv_nsec = ns % 1000000000;
q.huang8878f362022-10-20 15:25:45 +0800902 pthread_mutex_lock(&call_state_change_mutex);
903 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
904 pthread_mutex_unlock(&call_state_change_mutex);
905 return ret;
906}
907
908int IsNormalCallDailing()
909{
910 return s_module_isDial;
rita9b436d82022-04-07 01:55:39 -0400911}
912
rjw3d6a50e2023-02-20 13:35:42 +0800913
lh25827952022-01-10 00:34:35 -0800914int lynq_call(int* handle,char addr[])
915{
q.huang8878f362022-10-20 15:25:45 +0800916 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -0700917 {
q.huang8878f362022-10-20 15:25:45 +0800918 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
919 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -0700920 }
q.huang8878f362022-10-20 15:25:45 +0800921
lh25827952022-01-10 00:34:35 -0800922 int lynq_call_id = -1;
q.huangf8461432022-06-02 14:49:02 +0800923
924 LYINFLOG("lynq_call begin addr %s",addr);
lh25827952022-01-10 00:34:35 -0800925 if(addr==NULL)
926 {
927 LYERRLOG("Phone num is null!!!");
q.huang8878f362022-10-20 15:25:45 +0800928 return LYNQ_E_PARAMETER_ANONALY;
lh25827952022-01-10 00:34:35 -0800929 }
q.huangf8461432022-06-02 14:49:02 +0800930
931 if(find_call_id_with_addr(addr)!=INVALID_ID)
932 {
933 LYERRLOG("addr %s exists",addr);
934 return LYNQ_E_CONFLICT;
935 }
936
937#ifdef ECALL_SUPPORT
938 if(lynq_ecall_is_running())
939 {
940 LYERRLOG("lynq_fast_ecall ecall is running");
941 return LYNQ_E_ECALL_BEING_RUNNING;
942 }
943#endif
q.huang8878f362022-10-20 15:25:45 +0800944 Parcel* p=NULL;
945 lynq_call_id = addAddr(addr,0);
946 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
947 if(ret!=0)
948 {
rjw3d6a50e2023-02-20 13:35:42 +0800949 cleanCallList(lynq_call_id);
q.huang8878f362022-10-20 15:25:45 +0800950 return ret;
rjw3d6a50e2023-02-20 13:35:42 +0800951 }
952 delete p;
q.huang8878f362022-10-20 15:25:45 +0800953 s_module_isDial = 1;
954 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh25827952022-01-10 00:34:35 -0800955 {
q.huang8878f362022-10-20 15:25:45 +0800956 //if timeout,this call need destroy.
957 s_module_isDial = 0;
958 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
rjw3d6a50e2023-02-20 13:35:42 +0800959 cleanCallList(lynq_call_id);
q.huang8878f362022-10-20 15:25:45 +0800960 return LYNQ_E_TIME_OUT;
lh25827952022-01-10 00:34:35 -0800961 }
q.huang8878f362022-10-20 15:25:45 +0800962 s_module_isDial = 0;
963 *handle = s_call_lists[lynq_call_id].call_id;
964 if(*handle > 0)
lh25827952022-01-10 00:34:35 -0800965 {
q.huang8878f362022-10-20 15:25:45 +0800966 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
967 return RESULT_OK;
lh25827952022-01-10 00:34:35 -0800968 }
q.huang8878f362022-10-20 15:25:45 +0800969 else
970 {
971 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
rjw3d6a50e2023-02-20 13:35:42 +0800972 cleanCallList(lynq_call_id);
q.huang8878f362022-10-20 15:25:45 +0800973 return LYNQ_E_INVALID_ID_ANONALY;
rjw3d6a50e2023-02-20 13:35:42 +0800974 }
lh25827952022-01-10 00:34:35 -0800975}
rjw3d6a50e2023-02-20 13:35:42 +0800976
lh25827952022-01-10 00:34:35 -0800977int lynq_call_answer()
978{
q.huang8878f362022-10-20 15:25:45 +0800979 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -0700980 {
q.huang8878f362022-10-20 15:25:45 +0800981 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
982 return LYNQ_E_CONFLICT;
983 }
984
985 Parcel* p=NULL;
986 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
987 if(ret==RESULT_OK)
lh25827952022-01-10 00:34:35 -0800988 {
q.huang8878f362022-10-20 15:25:45 +0800989 delete p;
990 }
991 return ret;
lh25827952022-01-10 00:34:35 -0800992}
rjw3d6a50e2023-02-20 13:35:42 +0800993
lh25827952022-01-10 00:34:35 -0800994int lynq_call_hungup(int* handle)
995{
q.huang8878f362022-10-20 15:25:45 +0800996 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -0700997 {
q.huang8878f362022-10-20 15:25:45 +0800998 return LYNQ_E_CONFLICT;
999 }
1000
lha35d4ee2022-01-25 18:47:39 -08001001 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1002 {
q.huang8878f362022-10-20 15:25:45 +08001003 LYERRLOG("%s illegal input!!!!",__func__);
1004 return LYNQ_E_PARAMETER_ANONALY;
lha35d4ee2022-01-25 18:47:39 -08001005 }
q.huang8878f362022-10-20 15:25:45 +08001006
1007 int call_id = *handle;
1008 Parcel* p=NULL;
1009 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
1010 if(ret!=0)
lh25827952022-01-10 00:34:35 -08001011 {
q.huang8878f362022-10-20 15:25:45 +08001012 return ret;
ll7b51c492023-04-07 11:41:15 +08001013 }
q.huang8878f362022-10-20 15:25:45 +08001014 delete p;
1015
lld4353242023-03-15 17:02:52 +08001016 int lynq_call_id=find_call_id_with_call_id(call_id);
q.huang8878f362022-10-20 15:25:45 +08001017 if(lynq_call_id!=INVALID_ID)
lh25827952022-01-10 00:34:35 -08001018 {
ll7b51c492023-04-07 11:41:15 +08001019 //lei modify for API-857
q.huang8878f362022-10-20 15:25:45 +08001020 cleanCallList(lynq_call_id);
ll7b51c492023-04-07 11:41:15 +08001021 send_call_state_change(call_id);
lld4353242023-03-15 17:02:52 +08001022 }
lld4353242023-03-15 17:02:52 +08001023 return RESULT_OK;
lh25827952022-01-10 00:34:35 -08001024}
1025int lynq_call_hungup_all()
1026{
q.huang8878f362022-10-20 15:25:45 +08001027 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001028 {
q.huang8878f362022-10-20 15:25:45 +08001029 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1030 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001031 }
q.huang8878f362022-10-20 15:25:45 +08001032
1033 Parcel* p=NULL;
1034 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
1035 if(ret==RESULT_OK)
lh25827952022-01-10 00:34:35 -08001036 {
q.huang8878f362022-10-20 15:25:45 +08001037 delete p;
1038 }
1039 return ret;
lh25827952022-01-10 00:34:35 -08001040}
rjw3d6a50e2023-02-20 13:35:42 +08001041
1042int lynq_wait_call_state_change(int *handle)
lh25827952022-01-10 00:34:35 -08001043{
q.huang8878f362022-10-20 15:25:45 +08001044 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001045 {
q.huang8878f362022-10-20 15:25:45 +08001046 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1047 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001048 }
rjw3d6a50e2023-02-20 13:35:42 +08001049 wait_call_state();
1050 *handle = s_CallId;
1051 LYINFLOG("lynq mo/mt call id:%d",s_CallId);
1052 return RESULT_OK;
lh25827952022-01-10 00:34:35 -08001053}
1054
1055int lynq_set_auto_answercall(const int mode)
1056{
q.huang8878f362022-10-20 15:25:45 +08001057 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001058 {
q.huang8878f362022-10-20 15:25:45 +08001059 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1060 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001061 }
q.huang8878f362022-10-20 15:25:45 +08001062 s_call_auto_answer = mode;
lh25827952022-01-10 00:34:35 -08001063 LYINFLOG("auto answer call mode =%d",mode);
q.huang8878f362022-10-20 15:25:45 +08001064 return RESULT_OK;
lh25827952022-01-10 00:34:35 -08001065}
rjw3d6a50e2023-02-20 13:35:42 +08001066
1067int lynq_find_already_end()
1068{
1069 for(int i=0;i < LYNQ_CALL_MAX; i++)
1070 {
1071 if(s_call_lists[i].call_state == 6)
1072 {
1073 return 0;
1074 }
1075 }
1076 return INVALID_ID;
1077}
1078
q.huangb0eb7b02022-03-29 04:17:32 -04001079int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1080{
q.huang8878f362022-10-20 15:25:45 +08001081 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001082 {
q.huang8878f362022-10-20 15:25:45 +08001083 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1084 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001085 }
q.huangb0eb7b02022-03-29 04:17:32 -04001086 int lynq_call_id = 0;
q.huangf8461432022-06-02 14:49:02 +08001087 LYINFLOG("lynq_get_current_call_state begin ");
q.huangb0eb7b02022-03-29 04:17:32 -04001088 if(handle==NULL)
1089 {
q.huangf8461432022-06-02 14:49:02 +08001090 LYERRLOG("handle is NULL");
q.huang8878f362022-10-20 15:25:45 +08001091 return LYNQ_E_PARAMETER_ANONALY;
q.huangb0eb7b02022-03-29 04:17:32 -04001092 }
ll7b51c492023-04-07 11:41:15 +08001093 if((*handle) <= 0)
1094 {
1095 LYINFLOG("lynq_get_current_call_state input error %d\n ", *handle);
1096 return LYNQ_E_INVALID_ID_ANONALY;
1097 }
rjw3d6a50e2023-02-20 13:35:42 +08001098 LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
q.huangf8461432022-06-02 14:49:02 +08001099 lynq_call_id = find_call_id_with_call_id(*handle);
1100 if(lynq_call_id==INVALID_ID)
1101 {
ll7b51c492023-04-07 11:41:15 +08001102 *call_state = (int)LYNQ_CALL_END;
1103 return RESULT_OK;
q.huangf8461432022-06-02 14:49:02 +08001104 }
q.huang8878f362022-10-20 15:25:45 +08001105 *call_state = s_call_lists[lynq_call_id].call_state;
1106 *toa = s_call_lists[lynq_call_id].toa;
1107 *direction = s_call_lists[lynq_call_id].direction;
1108 memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
rjw3d6a50e2023-02-20 13:35:42 +08001109 return RESULT_OK;
q.huangb0eb7b02022-03-29 04:17:32 -04001110}
1111
q.huange0024b02022-08-29 20:04:31 +08001112int lynq_get_current_call_number()
1113{
1114 int cnt=0;
1115 int i;
1116 for(i = 0;i < LYNQ_CALL_MAX;i++)
1117 {
q.huang8878f362022-10-20 15:25:45 +08001118 if(s_call_lists[i].used !=0)
q.huange0024b02022-08-29 20:04:31 +08001119 {
1120 cnt++;
1121 }
1122 }
1123
1124 return cnt;
1125}
1126
q.huangb0eb7b02022-03-29 04:17:32 -04001127/*audio begin*/
ll7e055f22022-01-24 12:16:22 +00001128static int judge_mic(const int enable){
llc6030062022-02-14 08:58:16 +00001129 switch(enable){
1130 case 0:
q.huang8878f362022-10-20 15:25:45 +08001131 return true;
llc6030062022-02-14 08:58:16 +00001132 case 1:
q.huang8878f362022-10-20 15:25:45 +08001133 return true;
llc6030062022-02-14 08:58:16 +00001134 default:
q.huang8878f362022-10-20 15:25:45 +08001135 return false;
ll7e055f22022-01-24 12:16:22 +00001136 }
1137}
1138
lh25827952022-01-10 00:34:35 -08001139int lynq_set_mute_mic(const int enable)
ll7e055f22022-01-24 12:16:22 +00001140{
q.huang8878f362022-10-20 15:25:45 +08001141 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001142 {
q.huang8878f362022-10-20 15:25:45 +08001143 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
ll7e055f22022-01-24 12:16:22 +00001144 return LYNQ_E_CONFLICT;
1145 }
q.huang8878f362022-10-20 15:25:45 +08001146 if(!judge_mic(enable)){
1147 return LYNQ_E_PARAMETER_ANONALY;
1148 }
1149 // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1150
1151 Parcel* p=NULL;
1152 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
1153 if(ret==RESULT_OK)
1154 {
1155 delete p;
1156 }
1157 return ret;
q.huangb0eb7b02022-03-29 04:17:32 -04001158}
1159int lynq_get_mute_mic(int *status)
1160{
q.huang8878f362022-10-20 15:25:45 +08001161 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001162 {
q.huang8878f362022-10-20 15:25:45 +08001163 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1164 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001165 }
q.huang8878f362022-10-20 15:25:45 +08001166 return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
lh25827952022-01-10 00:34:35 -08001167}
ll45d3ea92022-03-24 10:22:25 +08001168
1169/**
1170 * @brief Check whether DTMF is valid
1171 *
1172 * @param callnum dtmf eg:0-9 * #
1173 * @return int
1174 */
1175static int judge_dtmf(const char callnum)
1176{
1177 if(callnum == '#')
1178 {
q.huang8878f362022-10-20 15:25:45 +08001179 return true;
ll45d3ea92022-03-24 10:22:25 +08001180 }
1181 if(callnum == '*')
1182 {
q.huang8878f362022-10-20 15:25:45 +08001183 return true;
ll45d3ea92022-03-24 10:22:25 +08001184 }
1185 if(callnum >= '0'&& callnum <= '9')
1186 {
q.huang8878f362022-10-20 15:25:45 +08001187 return true;
ll45d3ea92022-03-24 10:22:25 +08001188 }
q.huang8878f362022-10-20 15:25:45 +08001189 return false;
ll45d3ea92022-03-24 10:22:25 +08001190}
1191
llf79dc4d2022-07-20 09:30:19 +00001192int lynq_switch_waiting_or_holding_and_active(void)
1193{
q.huang8878f362022-10-20 15:25:45 +08001194 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001195 {
q.huang8878f362022-10-20 15:25:45 +08001196 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1197 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001198 }
q.huang8878f362022-10-20 15:25:45 +08001199
1200 Parcel* p=NULL;
1201 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
1202 if(ret==RESULT_OK)
1203 {
1204 delete p;
1205 }
1206 return ret;
1207
1208#if 0
llf79dc4d2022-07-20 09:30:19 +00001209 Parcel p;
1210 lynq_client_t client;
1211 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001212 int token;
llf79dc4d2022-07-20 09:30:19 +00001213 int request = -1;
1214 int slot_id = -1;
1215 int error = -1;
1216 client.uToken = Global_uToken_call;
1217 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1218 client.paramLen = 0;
1219 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1220 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001221 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-07-20 09:30:19 +00001222 if(send_request(lynq_call_client_sockfd,&client)==-1)
1223 {
1224 LYERRLOG("send request fail");
1225 return -1;
1226 }
1227 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001228 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001229 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-07-20 09:30:19 +00001230 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1231 return error;
q.huang8878f362022-10-20 15:25:45 +08001232#endif
llf79dc4d2022-07-20 09:30:19 +00001233}
1234
1235int lynq_hangup_waiting_or_background(void)
1236{
q.huang8878f362022-10-20 15:25:45 +08001237 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001238 {
q.huang8878f362022-10-20 15:25:45 +08001239 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1240 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001241 }
q.huang8878f362022-10-20 15:25:45 +08001242
1243 Parcel* p=NULL;
1244 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
1245 if(ret==RESULT_OK)
1246 {
1247 delete p;
1248 }
1249 return ret;
1250#if 0
llf79dc4d2022-07-20 09:30:19 +00001251 Parcel p;
1252 lynq_client_t client;
1253 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001254 int token;
llf79dc4d2022-07-20 09:30:19 +00001255 int request = -1;
1256 int slot_id = -1;
1257 int error = -1;
1258 client.uToken = Global_uToken_call;
1259 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1260 client.paramLen = 0;
1261 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1262 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001263 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-07-20 09:30:19 +00001264 if(send_request(lynq_call_client_sockfd,&client)==-1)
1265 {
1266 LYERRLOG("send request fail");
1267 return -1;
1268 }
1269 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001270 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001271 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-07-20 09:30:19 +00001272 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1273 return error;
q.huang8878f362022-10-20 15:25:45 +08001274#endif
llf79dc4d2022-07-20 09:30:19 +00001275}
1276
1277int lynq_hangup_foreground_resume_background(void)
1278{
q.huang8878f362022-10-20 15:25:45 +08001279 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001280 {
q.huang8878f362022-10-20 15:25:45 +08001281 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1282 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001283 }
q.huang8878f362022-10-20 15:25:45 +08001284
1285 Parcel* p=NULL;
1286 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
1287 if(ret==RESULT_OK)
1288 {
1289 delete p;
1290 }
1291 return ret;
1292#if 0
llf79dc4d2022-07-20 09:30:19 +00001293 Parcel p;
1294 lynq_client_t client;
1295 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001296 int token;
llf79dc4d2022-07-20 09:30:19 +00001297 int request = -1;
1298 int slot_id = -1;
1299 int error = -1;
1300 client.uToken = Global_uToken_call;
1301 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1302 client.paramLen = 0;
1303 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1304 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001305 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-07-20 09:30:19 +00001306 if(send_request(lynq_call_client_sockfd,&client)==-1)
1307 {
1308 LYERRLOG("send request fail");
1309 return -1;
1310 }
1311 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001312 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001313 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-07-20 09:30:19 +00001314 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1315 return error;
q.huang8878f362022-10-20 15:25:45 +08001316#endif
llf79dc4d2022-07-20 09:30:19 +00001317}
1318
lh25827952022-01-10 00:34:35 -08001319int lynq_set_DTMF(const char callnum)
1320{
q.huang8878f362022-10-20 15:25:45 +08001321 if(g_module_init_flag != MODULE_RUNNING)
ll3783e142022-08-10 00:33:52 -07001322 {
q.huang8878f362022-10-20 15:25:45 +08001323 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1324 return LYNQ_E_CONFLICT;
ll3783e142022-08-10 00:33:52 -07001325 }
ll45d3ea92022-03-24 10:22:25 +08001326 if(!judge_dtmf(callnum))
1327 {
1328 return LYNQ_E_CONFLICT;
1329 }
q.huang8878f362022-10-20 15:25:45 +08001330 if(s_module_call_state!=CALL_ON)
lh25827952022-01-10 00:34:35 -08001331 {
1332 LYERRLOG("LYNQ_E_CONFLICT");
1333 return LYNQ_E_CONFLICT;
1334 }
q.huang8878f362022-10-20 15:25:45 +08001335
1336// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
1337
1338 Parcel* p=NULL;
1339 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
1340 if(ret==RESULT_OK)
1341 {
1342 delete p;
1343 }
1344 return ret;
lh25827952022-01-10 00:34:35 -08001345}
q.huangb0eb7b02022-03-29 04:17:32 -04001346static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1347 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1348 if(volume < 0 ||volume >36){
1349 return 0;
1350 }
1351 }
1352 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1353 {
1354 if(volume < 1 ||volume >7){
1355 return 0;
1356 }
ll7e055f22022-01-24 12:16:22 +00001357 }
ll375c94d2022-01-27 05:54:38 +00001358 return 1;
ll7e055f22022-01-24 12:16:22 +00001359}
lh25827952022-01-10 00:34:35 -08001360int lynq_set_DTMF_volume(const int volume)
ll7e055f22022-01-24 12:16:22 +00001361{
q.huang8878f362022-10-20 15:25:45 +08001362 if(g_module_init_flag != MODULE_RUNNING)
1363 {
1364 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
ll7e055f22022-01-24 12:16:22 +00001365 return LYNQ_E_CONFLICT;
1366 }
q.huang8878f362022-10-20 15:25:45 +08001367 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
1368 return LYNQ_E_PARAMETER_ANONALY;
1369 }
1370// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
1371 Parcel* p=NULL;
1372 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
1373 if(ret==RESULT_OK)
1374 {
1375 delete p;
1376 }
1377 return ret;
lh25827952022-01-10 00:34:35 -08001378}
q.huang9ee6d5b2022-04-05 23:11:02 -04001379int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh25827952022-01-10 00:34:35 -08001380{
q.huang8878f362022-10-20 15:25:45 +08001381 if(g_module_init_flag != MODULE_RUNNING)
lh25827952022-01-10 00:34:35 -08001382 {
q.huang8878f362022-10-20 15:25:45 +08001383 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
q.huangb0eb7b02022-03-29 04:17:32 -04001384 return LYNQ_E_CONFLICT;
lh25827952022-01-10 00:34:35 -08001385 }
q.huang8878f362022-10-20 15:25:45 +08001386 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
1387 {
1388 return LYNQ_E_PARAMETER_ANONALY;
1389 }
1390// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
1391 Parcel* p=NULL;
1392 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
1393 if(ret==RESULT_OK)
1394 {
1395 delete p;
1396 }
1397 return ret;
lh25827952022-01-10 00:34:35 -08001398}
q.huangb0eb7b02022-03-29 04:17:32 -04001399int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1400{
q.huang8878f362022-10-20 15:25:45 +08001401 return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
q.huangb0eb7b02022-03-29 04:17:32 -04001402}
q.huang9ee6d5b2022-04-05 23:11:02 -04001403int lynq_incall_record_start(const char* file_path)
q.huangb0eb7b02022-03-29 04:17:32 -04001404{
q.huang8878f362022-10-20 15:25:45 +08001405// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
1406 Parcel* p=NULL;
1407 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
1408 if(ret==RESULT_OK)
1409 {
1410 delete p;
1411 }
1412 return ret;
q.huangb0eb7b02022-03-29 04:17:32 -04001413}
1414int lynq_incall_record_stop()
1415{
q.huang8878f362022-10-20 15:25:45 +08001416 if(g_module_init_flag != MODULE_RUNNING)
1417 {
1418 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
1419 return LYNQ_E_CONFLICT;
1420 }
q.huang9ee6d5b2022-04-05 23:11:02 -04001421 const char* unused_file="just_ocuupy_paramter_postion";
q.huang8878f362022-10-20 15:25:45 +08001422// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
1423 Parcel* p=NULL;
1424 int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
1425 if(ret==RESULT_OK)
1426 {
1427 delete p;
1428 }
1429 return ret;
q.huangb0eb7b02022-03-29 04:17:32 -04001430}
1431/*audio end*/
q.huang5a738c02022-04-18 00:09:50 -04001432
rjw3d6a50e2023-02-20 13:35:42 +08001433
1434
1435bool is_support_urc(int urc_id)
1436{
1437 switch(urc_id)
1438 {
1439 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
1440 case RIL_UNSOL_CALL_RING:
1441 case RIL_UNSOL_RINGBACK_TONE:
1442 case RIL_UNSOL_CALL_INFO_INDICATION:
1443#ifdef ECALL_SUPPORT
1444 case RIL_UNSOL_ECALL_INDICATIONS://9502
1445#endif
1446 return true;
1447 default:
1448 return false;
1449 }
1450}
1451
q.huang8878f362022-10-20 15:25:45 +08001452void urc_msg_process(Parcel *p)
1453{
1454 int resp_type;
1455 int urcid;
1456 int slot_id;
rjw3d6a50e2023-02-20 13:35:42 +08001457
1458 int size=p->dataSize();
q.huang8878f362022-10-20 15:25:45 +08001459 p->readInt32(&resp_type);
1460 p->readInt32(&urcid);
1461 p->readInt32(&slot_id);
q.huange5595852023-05-30 19:39:42 +08001462 LYINFLOG("%s urc id = %d, slot_id = %d, size is %d, msg is %s",__func__, urcid,slot_id,size,android::requestToString(urcid));
q.huang8878f362022-10-20 15:25:45 +08001463 switch (urcid)
1464 {
1465 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
1466 {
1467 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1468 lynqNoticeGetModuleCallList();
1469 break;
1470 }
1471 case RIL_UNSOL_CALL_RING: //1018
1472 {
1473 if(s_call_auto_answer==1)
1474 {
1475 lynq_call_answer();
1476 }
1477 break;
1478 }
1479 case RIL_UNSOL_RINGBACK_TONE: //1029
1480 case RIL_UNSOL_CALL_INFO_INDICATION://3049
1481 {
1482 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
1483 break;
1484 }
q.huang5a738c02022-04-18 00:09:50 -04001485#ifdef ECALL_SUPPORT
q.huang8878f362022-10-20 15:25:45 +08001486 case RIL_UNSOL_ECALL_INDICATIONS://9502
q.huange0024b02022-08-29 20:04:31 +08001487 {
q.huang8878f362022-10-20 15:25:45 +08001488 urc_ecall_msg_process(p);
q.huange0024b02022-08-29 20:04:31 +08001489 }
q.huange0024b02022-08-29 20:04:31 +08001490#endif
q.huang8878f362022-10-20 15:25:45 +08001491 default:
1492 break;
q.huang68ee8a02022-06-28 20:12:01 +08001493 }
q.huangdf857562022-06-06 16:15:31 +08001494}
q.huangdf857562022-06-06 16:15:31 +08001495
lh25827952022-01-10 00:34:35 -08001496#if 0
1497int main(int argc,char **argv)
1498{
1499 int n = 0;
1500 n = lynq_init_call(lynq_call_state_change_test,2222);
1501 if(n<0)
1502 {
q.huangf8461432022-06-02 14:49:02 +08001503 LYDBGLOG("lynq init call fail!!!");
lh25827952022-01-10 00:34:35 -08001504 return -1;
1505 }
q.huangf8461432022-06-02 14:49:02 +08001506 LYDBGLOG("lynq call init success!!!");
lh25827952022-01-10 00:34:35 -08001507 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
1508 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
1509 lynq_call(phoneNum);
1510 while(1)
1511 {
1512 sleep(1);
1513 }
1514 return 0;
1515}
1516#endif
1517/*Warren add for T800 platform 2021/11/19 end*/