blob: ce6007474d2fee679a82018c9423c653c04e5f04 [file] [log] [blame]
q.huang52921662022-10-20 15:25:45 +08001#include <stdio.h>
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <arpa/inet.h>
5#include <fcntl.h>
6#include <string.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <binder/Parcel.h>
10#include <log/log.h>
11#include <cutils/jstring.h>
12#include <pthread.h>
13#include "liblog/lynq_deflog.h"
14#include <sys/time.h>
15#include <string.h>
16#include <vendor-ril/telephony/ril.h>
17#include <vendor-ril/telephony/mtk_ril_sp.h>
18#include <vendor-ril/telephony/mtk_ril_ivt.h>
19#include "lynq_call.h"
20#include "lynq_module_common.h"
21#include "lynq_module_socket.h"
22#include "lynq_call_common.h"
23
24#define USER_LOG_TAG "LYNQ_CALL"
25
26using ::android::Parcel;
27
28#ifdef ECALL_SUPPORT
29typedef enum{
30 LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
31 LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
32 LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
33 LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */
34}LYNQ_ECall_Type;
35typedef enum{
36 LYNQ_ECALL_DAILING_STATE_NONE =0,
37 LYNQ_ECALL_DAILING_STATE_STARTED = 1,
38 LYNQ_ECALL_DAILING_STATE_ANSWERED = 2,
39}LYNQ_ECall_Dailing_State;
40static LYNQ_ECall_Dailing_State s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
41int IsECallDialing()
42{
43 return s_module_is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE;
44}
45static int s_ecallId = INVALID_ID;
46char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"test_ecall","emergency_ecall","reconf_ecall"};
47
48static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
49static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
50static pthread_mutex_t s_ecall_variable_mutex = PTHREAD_MUTEX_INITIALIZER;
51
52static LYNQ_ECall_Indication s_IncomingEcallIndication;
53int s_IncomingEcallId=INVALID_ID;
54LYNQ_ECall_Variant s_EcallVariant=LYNQ_ECALL_VAR_NONE;
q.huangdf0723c2023-04-28 16:03:01 +080055int s_ecall_whether_preempt=0x02;
q.huang52921662022-10-20 15:25:45 +080056
57void sendSignalIncomingECallEvent()
58{
59 LYINFLOG("send incoming ecall event signal");
60 pthread_mutex_lock(&s_incoming_e_call_mutex);
61 pthread_cond_signal(&s_incoming_e_call_cond);
62 pthread_mutex_unlock(&s_incoming_e_call_mutex);
63}
64
65int lynq_is_msd_suc(LYNQ_ECall_Indication lynqIncomingEcallIndication)
66{
67 if(LYNQ_ECALL_LLACK_RECEIVED == lynqIncomingEcallIndication ||
68 LYNQ_ECALL_ALACK_POSITIVE_RECEIVED == lynqIncomingEcallIndication ||
69 LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED == lynqIncomingEcallIndication ||
70 //LYNQ_ECALL_T5_TIMER_OUT == lynqIncomingEcallIndication ||
71 LYNQ_ECALL_T6_TIMER_OUT == lynqIncomingEcallIndication ||
72 LYNQ_ECALL_T7_TIMER_OUT == lynqIncomingEcallIndication)
73 {
74 return 1;
75 }
76
77 return 0;
78}
79
80int lynq_ecall_is_running()
81{
82 return (s_module_is_ecall_dial!=LYNQ_ECALL_DAILING_STATE_NONE) || (s_ecallId !=INVALID_ID || s_EcallVariant == LYNQ_ECALL_CALLBACK);
83}
84
85void print_ecall_info()
86{
87 LYERRLOG("%s is ecall dial is %d, ecall id is %d, ecall vairant is %d, incoming ecall ind is %d, incoming ecall id is %d, whether preempt is %d",__func__,s_module_is_ecall_dial,s_ecallId,s_EcallVariant,s_IncomingEcallIndication,s_IncomingEcallId,s_ecall_whether_preempt);
88}
89
90int lynq_ecall_is_permit_in_call(int ecall_id)
91{
92 return s_EcallVariant == LYNQ_ECALL_CALLBACK && (s_ecallId ==INVALID_ID || s_ecallId ==ecall_id);
93}
94
95int Is_handup_IncomingMT(int ecall_id)
96{
97 pthread_mutex_lock(&s_ecall_variable_mutex);
98 int handupIncomingMT=lynq_ecall_is_running() && (lynq_ecall_is_permit_in_call(ecall_id)==false);
99 pthread_mutex_unlock(&s_ecall_variable_mutex);
100 return handupIncomingMT;
101}
102
103int lynq_ecall_is_in_voice()
104{
105 return (s_module_is_ecall_dial==LYNQ_ECALL_DAILING_STATE_NONE) && (s_ecallId !=INVALID_ID);
106}
107
108LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
109{
110 switch(type)
111 {
112 case LYNQ_ECALL_TYPE_TEST:
113 return LYNQ_ECALL_TEST;
114 case LYNQ_ECALL_TYPE_RECONFIG:
115 return LYNQ_ECALL_RECONFIG;
116 default:
117 return LYNQ_ECALL_EMERGENCY;
118 }
119}
120
121RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
122{
123 switch(type)
124 {
125 case LYNQ_ECALL_TEST:
126 return ECALL_TEST;
127 case LYNQ_ECALL_RECONFIG:
128 return ECALL_RECONFIG;
129 default:
130 return ECALL_EMERGENCY;
131 }
132}
133
134RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
135{
136 switch(cat)
137 {
138 case LYNQ_EMER_CAT_MANUAL_ECALL:
139 return EMER_CAT_MANUAL_ECALL;
140 default:
141 return EMER_CAT_AUTO_ECALL;
142 }
143}
144
145
146int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
147{
148 if(g_module_init_flag != MODULE_RUNNING)
149 {
150 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
151 return LYNQ_E_CONFLICT;
152 }
153 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
154 {
155 LYERRLOG("test_num is null or test_num_length %d s greater than %d ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
156 return LYNQ_E_PARAMETER_ANONALY;
157 }
158
159// error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
160
161 Parcel* p=NULL;
162 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
163 if(ret==RESULT_OK)
164 {
165 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
166 delete p;
167 }
168 return ret;
169}
170
171int lynq_ecall_can_be_preempted(LYNQ_ECall_Variant old_variant,LYNQ_ECall_Variant new_variant)
172{
173 int ret;
174
175 if(old_variant == LYNQ_ECALL_EMERGENCY)
176 {
177 return false;
178 }
179 else if(new_variant == LYNQ_ECALL_EMERGENCY)
180 {
181 return true;
182 }
183 else if(old_variant==LYNQ_ECALL_DAILING_STATE_NONE)
184 {
185 return true;
186 }
187 else
188 {
189 ret = (s_ecall_whether_preempt & 0x01);
190 }
191 LYINFLOG("ecall clear conflict call, lynq_ecall_can_be_preempted is true");
192 return ret;
193}
194
195int lynq_clear_current_call()
196{
197 int cnt;
198 int ret=lynq_call_hungup_all();
199
200 if(ret!=RESULT_OK)
201 {
202 LYERRLOG("ecall clear conflict call, hangup all failure");
203 return ret;
204 }
205 cnt=0;
206 while(lynq_get_current_call_number()!=0 && cnt<80)
207 {
208 lynqNoticeGetModuleCallList();
209 usleep(200 * 1000);//200ms
210 cnt++;
211 }
212 if(lynq_get_current_call_number()!=0)
213 {
214 LYERRLOG("ecall clear conflict call, current call list can't cleared after 15s");
215 return LYNQ_E_INNER_ERROR;
216 }
217
218 LYINFLOG("ecall clear conflict call, after %d 0.2s, call list is cleared", cnt);
219 return RESULT_OK;
220}
221
222int lynq_clear_current_conflict_call(LYNQ_ECall_Variant old_variant,LYNQ_ECall_Variant new_variant)
223{
224 int cnt;
225 int ret;
226
227 if(lynq_ecall_is_running()==false)
228 {
229 if(lynq_get_current_call_number()==0)
230 {
231 LYINFLOG("ecall clear conflict call, no conflict ecall and normal call");
232 }
233 else if(s_ecall_whether_preempt & 0x02)
234 {
235 ret=lynq_clear_current_call();
236 LYERRLOG("ecall clear conflict call, relase current normal call ret is %d",ret);
237 }
q.huangdf0723c2023-04-28 16:03:01 +0800238 else
239 {
240 LYINFLOG("ecall clear conflict call, exits conflict normal call, let mtk release them");
241 }
q.huang52921662022-10-20 15:25:45 +0800242 return RESULT_OK;
243 }
244
245 LYINFLOG("ecall clear conflict call, two ecall occure at the same time, new is %d, old is %d, g_preempt is %d",new_variant,old_variant,s_ecall_whether_preempt);
246
247 if(lynq_ecall_can_be_preempted(old_variant,new_variant)==false)
248 {
249 LYERRLOG("ecall clear conflict call, new ecall %d can't preempt old ecall %d",new_variant,old_variant);
250 return LYNQ_E_CONFLICT;
251 }
252
253 ret=lynq_clear_current_call();
254 LYINFLOG("ecall clear conflict call, relase current call(including ecall) ret is %d",ret);
255
256 if(s_module_is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
257 {
258 sendSignalToWaitCallStateChange();
259 LYINFLOG("ecall clear conflict call, stop ecall in dailing status");
260 }
261
262 cnt=0;
263 while(lynq_ecall_is_running() && cnt<80)
264 {
265 usleep(200 * 1000);//200ms
266 cnt++;
267 }
268
269 if(lynq_ecall_is_running())
270 {
271 LYERRLOG("ecall clear conflict call, after 16s, lynq ecall is still running");
272 }
273 else
274 {
275 LYINFLOG("ecall clear conflict call, after %d 0.2s, ecall info is cleared", cnt);
276 }
277
278 sleep(3);// for ecall disconnect
279 print_ecall_info();
280 return RESULT_OK;
281}
282
283int lynq_fast_ecall(int* handle, LYNQ_ECall_Category lynq_ecall_cat, LYNQ_ECall_Variant lynq_ecall_variant, const char *addr, int addr_length, const unsigned char *msd_data,int msd_length)
284{
285 if(g_module_init_flag != MODULE_RUNNING)
286 {
287 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
288 return LYNQ_E_CONFLICT;
289 }
290 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
291 RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
292 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
293 unsigned int i;
q.huang7cca73c2024-10-30 12:05:22 +0800294
295 (void) lynq_call_pre_confirm(call_type_mo);
q.huang52921662022-10-20 15:25:45 +0800296
297 if(msd_length > MSD_MAX_LENGTH || msd_length <=0 || lynq_ecall_variant >=LYNQ_ECALL_MO_MAX)
298 {
299 LYERRLOG("lynq_fast_ecall msd_length %d or ecall variant %d parameter error",msd_length,lynq_ecall_variant);
300 return LYNQ_E_PARAMETER_ANONALY;
301 }
302
303 if(lynq_clear_current_conflict_call(s_EcallVariant,lynq_ecall_variant)!=0)
304 {
305 LYERRLOG("%s call lynq_clear_current_conflict_call false, old is %d, new is %d",__func__,s_EcallVariant,lynq_ecall_variant);
306 return LYNQ_E_CONFLICT;
307 }
308
309 pthread_mutex_lock(&s_ecall_variable_mutex);
310 s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_STARTED;
311 s_EcallVariant = lynq_ecall_variant;
312 s_ecallId = INVALID_ID;
313 pthread_mutex_unlock(&s_ecall_variable_mutex);
314
315 for(i =0; i<msd_length;i++)
316 {
317 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
318 }
319
320
321 LYINFLOG("lynq_fast_ecall addr is %s",e_call_addr[lynq_ecall_variant]);
322
323// error=lynq_set_common_request(RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", lynq_msd_data);
324
325 Parcel* p=NULL;
326 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", lynq_msd_data);
327 if(ret!=RESULT_OK)
328 {
329 pthread_mutex_lock(&s_ecall_variable_mutex);
330 s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
331 s_EcallVariant = LYNQ_ECALL_VAR_NONE;
332 s_ecallId = INVALID_ID;
333 pthread_mutex_unlock(&s_ecall_variable_mutex);
334 return ret;
335 }
336
337 delete p;
338 if(waitCallstateChange(270000)==ETIMEDOUT)//4.5 min, dailing 1 min, alerting 1 min, sending msd 30s, redial 2min
339 {
340 pthread_mutex_lock(&s_ecall_variable_mutex);
341 LYERRLOG("lynq_fast_ecall timeout:wait Call state time out!!!");
342 s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
343 lynqNoticeGetModuleCallList();
344 pthread_mutex_unlock(&s_ecall_variable_mutex);
345 return LYNQ_E_TIME_OUT;
346 }
347 pthread_mutex_lock(&s_ecall_variable_mutex);
348 if(s_module_is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)
349 {
350 /*just dail, no recv answer*/
351 LYERRLOG("lynq_fast_ecall, no answer!");
352 s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
353 lynqNoticeGetModuleCallList();
354 pthread_mutex_unlock(&s_ecall_variable_mutex);
355 return LYNQ_E_ECALL_DAILING_NO_ANSWER;
356 }
357
358 s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
359 lynqNoticeGetModuleCallList();
360
361 if(s_ecallId != INVALID_ID)
362 {
363 *handle=s_ecallId;
364 LYINFLOG("lynq_fast_ecall id is %d",s_ecallId);
365 pthread_mutex_unlock(&s_ecall_variable_mutex);
366 return RESULT_OK;
367 }
368
369 LYERRLOG("lynq_fast_ecall service return fail");
370 pthread_mutex_unlock(&s_ecall_variable_mutex);
371 return LYNQ_E_INVALID_ID_ANONALY;
372
373}
374
375int lynq_set_psap(int enable)
376{
377 if(g_module_init_flag != MODULE_RUNNING)
378 {
379 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
380 return LYNQ_E_CONFLICT;
381 }
382// return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
383 Parcel* p=NULL;
384 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
385 if(ret==RESULT_OK)
386 {
387 delete p;
388 }
389 return ret;
390}
391
392int lynq_psap_pull_msd()
393{
394 if(g_module_init_flag != MODULE_RUNNING)
395 {
396 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
397 return LYNQ_E_CONFLICT;
398 }
399// return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
400 Parcel* p=NULL;
401 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
402 if(ret==RESULT_OK)
403 {
404 delete p;
405 }
406 return ret;
407}
408
409int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
410{
411 return RESULT_OK;
412#if 0
413 LYNQ_ECall_Variant lynq_ecall_variant;
414 int error = -1;
415 int lynq_call_id = -1;
416
417 if(handle==NULL)
418 {
419 LYERRLOG("handle is NULL, parameter error ");
420 return -1;
421 }
422
423 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
424
425 if(error==0)
426 {
427 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
428
429 lynq_call_id = addAddr(e_call_addr[lynq_ecall_variant]);
430 s_module_isDial = 1;
431 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
432 {
433 error = LYNQ_E_TIME_OUT;
434 LYERRLOG("timeout:wait Call state fail!!!");
435 return error;
436 }
437
438 *handle = lynq_call_id;
439 }
440
441 return error;
442#endif
443}
444
445
446int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length)
447{
448 if(g_module_init_flag != MODULE_RUNNING)
449 {
450 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
451 return LYNQ_E_CONFLICT;
452 }
453 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
454 unsigned int i;
455
456 if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX) || msd_length > MSD_MAX_LENGTH || msd_length <= 0 || msd_data ==NULL)
457 {
458 LYERRLOG("lynq_set_msd handle is NULL or *handle %d is greater or equeal to %d or msd_length %d is greater than %d or msd_data %s is NULL, parameter error",*handle,LYNQ_CALL_MAX,msd_length,MSD_MAX_LENGTH, msd_data);
459 return LYNQ_E_PARAMETER_ANONALY;
460 }
461
462 for(i=0; i<msd_length;i++)
463 {
464 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
465 }
466
467 LYINFLOG("lynq_set_msd ");
468
469// return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",*handle,lynq_msd_data);
470 Parcel* p=NULL;
471 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",*handle,lynq_msd_data);
472 if(ret==RESULT_OK)
473 {
474 delete p;
475 }
476 return ret;
477}
478
479int lynq_set_ivs(int enable)
480{
481 if(g_module_init_flag != MODULE_RUNNING)
482 {
483 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
484 return LYNQ_E_CONFLICT;
485 }
486 if(enable<0)
487 {
q.huang1c03f752023-12-14 14:11:58 +0800488 if(enable >-300)
q.huang52921662022-10-20 15:25:45 +0800489 {
490 goto set_ivs_end;
491// lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
492 }
493 else if(enable== -1000)
494 {
495 print_ecall_info();
496 }
497 else
498 {
q.huang1c03f752023-12-14 14:11:58 +0800499 s_ecall_whether_preempt= ((-300-enable) & 0x11);
q.huang52921662022-10-20 15:25:45 +0800500 }
501 return RESULT_OK;
502 }
503
504// return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
505set_ivs_end:
506 Parcel* p=NULL;
507 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
508 if(ret==RESULT_OK)
509 {
510 delete p;
511 }
512 return ret;
513}
514
515int lynq_reset_ivs()
516{
517 if(g_module_init_flag != MODULE_RUNNING)
518 {
519 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
520 return LYNQ_E_CONFLICT;
521 }
522// return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
523 Parcel* p=NULL;
524 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_RESET_IVS,0,"");
525 if(ret==RESULT_OK)
526 {
527 delete p;
528 }
529 return ret;
530}
531
532int lynq_ivs_push_msd()
533{
534 if(g_module_init_flag != MODULE_RUNNING)
535 {
536 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
537 return LYNQ_E_CONFLICT;
538 }
539// return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
540 Parcel* p=NULL;
541 int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
542 if(ret==RESULT_OK)
543 {
544 delete p;
545 }
546 return ret;
547}
548
549int wait_ecall_event()
550{
551 int ret = 0;
552 pthread_mutex_lock(&s_incoming_e_call_mutex);
553 ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
554 pthread_mutex_unlock(&s_incoming_e_call_mutex);
555 return ret;
556}
557
558int lynq_wait_ecall_indication(int* handle, LYNQ_ECall_Indication *eCall_Indication)
559{
560 if(g_module_init_flag != MODULE_RUNNING)
561 {
562 LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
563 return LYNQ_E_CONFLICT;
564 }
565 wait_ecall_event();
566 *handle = s_IncomingEcallId;
567 *eCall_Indication = s_IncomingEcallIndication;
568 LYINFLOG("lynq_wait_ecall_indication handle %d, Ind id: %d", *handle, *eCall_Indication);
569 return RESULT_OK;
570}
571void urc_ecall_msg_process(Parcel *p)
572{
573 int ecall_ind;
574 int ecallId;
575 int send_signal_to_wait_call_state;
576 int handup_ecall_id;
577
578 pthread_mutex_lock(&s_ecall_variable_mutex);
579 send_signal_to_wait_call_state = false;
580 handup_ecall_id=false;
581 p->readInt32(&ecall_ind);
582 s_IncomingEcallIndication = ecall_ind;
583 p->readInt32(&ecallId);
584 s_IncomingEcallId = ecallId;
585 LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS ,Id %d, ind %d, ecall dialing is %d, normal dialing is %d, local ecall id is %d",ecallId,ecall_ind,s_module_is_ecall_dial,IsNormalCallDailing(),s_ecallId);
586 switch (s_IncomingEcallIndication)
587 {
588 case LYNQ_ECALL_ACTIVE:
589 if(s_module_is_ecall_dial)
590 {
591 s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_ANSWERED;
592 }
593 break;
594 case LYNQ_ECALL_SENDING_START:
595 if(lynq_ecall_is_in_voice())
596 {
597 LYINFLOG("recv msd in voice, ind is changed to %d",LYNQ_ECALL_SENDING_START_IN_VOICE);
598 s_IncomingEcallIndication = LYNQ_ECALL_SENDING_START_IN_VOICE;
599 }
600 break;
601 case LYNQ_ECALL_LLACK_RECEIVED:
602 case LYNQ_ECALL_ALACK_POSITIVE_RECEIVED:
603 case LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED:
604 //case LYNQ_ECALL_T5_TIMER_OUT: /*when Certificate CP 1.1.10.2, no msd start (ind 1), so T5 timeout is not regard as success*/
605 case LYNQ_ECALL_T6_TIMER_OUT:
606 case LYNQ_ECALL_T7_TIMER_OUT:
607 if(s_module_is_ecall_dial)
608 {
609 LYINFLOG("ecall is dialing, recv suc indication");
610 s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
q.huangdf0723c2023-04-28 16:03:01 +0800611 if(ecallId >0)
q.huang52921662022-10-20 15:25:45 +0800612 {
q.huangdf0723c2023-04-28 16:03:01 +0800613 if(find_call_id_with_call_id(ecallId)==INVALID_ID)
614 {
615 LYINFLOG("add ecall in loacl list");
616 addAddr("ecall",ecallId);
617 }
618 s_ecallId = ecallId; //API-871 ecall id maybe exists in local list as noraml call to be replaced
619 }
q.huang52921662022-10-20 15:25:45 +0800620 send_signal_to_wait_call_state=true;
621 }
622 else if(ecallId >0 && (find_call_id_with_call_id(ecallId)==INVALID_ID) && (s_EcallVariant != LYNQ_ECALL_CALLBACK))
623 {
624 LYERRLOG("ecall is not in dialing and first recv suc indication, hangup");
625 handup_ecall_id=true;
626 }
627 else
628 {
629 LYERRLOG("ecall is not in dialing and not first recv suc indication");
630 }
631 break;
632 case LYNQ_ECALL_PSAP_CALLBACK_START:
633 if(lynq_ecall_is_running()==0)
634 {
635 if(ecallId>0)
636 {
637 LYINFLOG("ecall is not running, recv psap call back msd start, set ecall running");
638 s_EcallVariant = LYNQ_ECALL_CALLBACK;
639 s_ecallId = ecallId;
640 if(IsNormalCallDailing())
641 {
642 LYINFLOG("stop normal dial");
643 send_signal_to_wait_call_state=true;
644 }
645 else
646 {
647 LYINFLOG("no normal dial");
648 }
649 }
650 else
651 {
652 LYERRLOG("ecallId is abnormal in psap callback");
653 }
654 }
655 else
656 {
657 LYERRLOG("ecall is running, recv psap call back msd start");
658 }
659 break;
660 case LYNQ_ECALL_ABNORMAL_HANGUP:
661 if(s_module_is_ecall_dial == LYNQ_ECALL_DAILING_STATE_NONE)
662 {
663 LYERRLOG("ecall is not in dialing , recv abnormal hangup");
664 s_ecallId = INVALID_ID;
665 }
666 else if (s_module_is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)
667 {
668 LYERRLOG("ecall is in dialing state, recv no answer, recv abnormal hangup, dont' redial");
669 s_ecallId = INVALID_ID;
670 send_signal_to_wait_call_state=true;
671 }
672 else {
673 LYINFLOG("ecall is in dialing and recv answer, recv abnormal hangup");
674 }
675 break;
676 case LYNQ_ECALL_DISCONNECTED:
677 case LYNQ_ECALL_REDIAL_TIMER_OUT:
678 case LYNQ_ECALL_T2_TIMER_OUT :
679 case LYNQ_ECALL_IMS_DISCONNECTED:
680 s_ecallId = INVALID_ID;
681 if(s_EcallVariant == LYNQ_ECALL_CALLBACK)
682 {
683 s_EcallVariant = LYNQ_ECALL_VAR_NONE; /*other type, needn't re-initialize*/
684 }
685 if(s_module_is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
686 {
687 LYERRLOG("ecall is in dialing, recv like disconnect indication");
688 s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
689 send_signal_to_wait_call_state=true;
690 }
691 else
692 {
693 LYINFLOG("ecall is not in dialing, recv like disconnect indication");
694 }
695 break;
696 default:
697 LYINFLOG("not special indication");
698 }
699 pthread_mutex_unlock(&s_ecall_variable_mutex);
700 if(send_signal_to_wait_call_state)
701 {
702 sendSignalToWaitCallStateChange();
703 }
704 sendSignalIncomingECallEvent();
705 if(handup_ecall_id)
706 {
707 lynq_call_hungup(&ecallId);
708 }
709 LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS, local ecall id is %d", s_ecallId);
710 return;
711}
712#endif