blob: 0e46e6e33468f6aed54e34323563d75b05362f55 [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"
21
22
lh25827952022-01-10 00:34:35 -080023#define LYNQ_SERVICE_PORT 8088
rjw8bdc56b2022-02-28 15:01:49 +080024#define DSET_IP_ADDRESS "127.0.0.1"
lh25827952022-01-10 00:34:35 -080025#define LYNQ_URC_SERVICE_PORT 8086
26#define LYNQ_REC_BUF 8192
27#define LYNQ_REQUEST_PARAM_BUF 8192
28#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
q.huangf8461432022-06-02 14:49:02 +080029#define INVALID_ID (-1)
q.huang68ee8a02022-06-28 20:12:01 +080030#define RTP_FROM_CMD "gst-launch-1.0 -v udpsrc port=%d caps=\'application/x-rtp, media=(string)audio, clock-rate=(int)%d, channels=(int)%d\' ! rtpjitterbuffer latency=%d ! rtppcmadepay ! alawdec ! audioresample ! audioconvert ! alsasink device=\'hw:0,2\'"
q.huangb84348a2022-09-30 17:33:20 +080031#define RTP_TO_CMD "gst-launch-1.0 -v alsasrc device=\'hw:0,6\' ! audioconvert ! audioresample ! alawenc ! rtppcmapay ! udpsink host=%s %s auto-multicast=true port=%d"
32#define RTP_VLAN_INFO_FORMAT "multicast-iface=\"%s\""
q.huang68ee8a02022-06-28 20:12:01 +080033#define MAX_IP_LENGTH 128
q.huangb84348a2022-09-30 17:33:20 +080034#define MAX_VLAN_INFO_LENGTH 128
lh25827952022-01-10 00:34:35 -080035#define USER_LOG_TAG "LYNQ_CALL"
36
37using ::android::Parcel;
38 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
50typedef struct{
51 int uToken;
52 int request;
53 int paramLen;
54 char param[LYNQ_REQUEST_PARAM_BUF];
55}lynq_client_t;
56typedef struct
57{
58 int used;
59 int call_id;
60 int call_state;
61 int toa;
62 int direction;/*0: MO call,1:MT call*/
63 char addr[LYNQ_PHONE_NUMBER_MAX];
lh25827952022-01-10 00:34:35 -080064}lynq_call_list_e_t;
65typedef struct
66{
67 int call_id;
68 int call_state;
69 int toa;
70 int direction;/*0: MO call,1:MT call*/
71 char addr[LYNQ_PHONE_NUMBER_MAX];
72}lynq_call_list_t;
73
74lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
75static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
76static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
ll00a10dd2022-07-13 09:39:44 +000077static pthread_mutex_t *s_urc_call_state_change_mutex = NULL;
78static pthread_cond_t *s_urc_call_state_change_cond = NULL;
lh25827952022-01-10 00:34:35 -080079static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
80static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
ll78948a22022-07-25 05:52:14 +000081static pthread_mutex_t g_lynq_call_sendto_mutex;
ll1343a5b2022-03-17 05:31:33 +000082pthread_t lynq_call_urc_tid = -1;
83pthread_t lynq_call_list_loop_tid = -1;
lhcdf816a2022-02-13 23:56:05 -080084
rjw8bdc56b2022-02-28 15:01:49 +080085/*lei add*/
86/* socket文件描述符 */
87int len_addr_serv;
88struct sockaddr_in addr_serv;
89lynq_client_t client_t;
90int client_size = 0;
91/*lei add*/
lh25827952022-01-10 00:34:35 -080092
ll00a10dd2022-07-13 09:39:44 +000093int s_call_urc_event_complete = 0;
lh25827952022-01-10 00:34:35 -080094
95enum{
96 CALL_OFF=0,
97 CALL_ON=1
98}call_state;
ll375c94d2022-01-27 05:54:38 +000099typedef enum{
100 LYNQ_E_CARDSTATE_ERROR=8000,
101 /* The voice service state is out of service*/
102 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
103 /* The voice service state is EMERGENCY_ONLY*/
104 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
105 /* The radio power is power off*/
106 LYNQ_E_STATE_POWER_OFF=8003,
107 LYNQ_E_TIME_OUT=8004,
108 /*create or open sms DB fail */
109 LYNQ_E_SMS_DB_FAIL=8005,
110 /*Failed to execute sql statement*/
111 LYNQ_E_SMS_SQL_FAIL = 8006,
112 LYNQ_E_SMS_NOT_FIND = 8007,
113 /* The logic conflict*/
114 LYNQ_E_CONFLICT=9000,
115 /*Null anomaly*/
q.huangf8461432022-06-02 14:49:02 +0800116 LYNQ_E_NULL_ANONALY=9001,
117 /*Invalid id anomaly*/
118 LYNQ_E_INVALID_ID_ANONALY=9002,
119#ifdef ECALL_SUPPORT
120 LYNQ_E_ECALL_BEING_RUNNING =9003,
121 LYNQ_E_ECALL_MSD_LENGTH_ERROR =9004,
q.huang4bb7b0a2022-06-21 14:57:02 +0800122 LYNQ_E_ECALL_DAILING_NO_ANSWER =9005,
q.huangf8461432022-06-02 14:49:02 +0800123#endif
lh25827952022-01-10 00:34:35 -0800124}LYNQ_E;
q.huangb0eb7b02022-03-29 04:17:32 -0400125typedef enum{
126 LYNQ_E_VOLUMN_SET_DTMF,
127 LYNQ_E_VOLUMN_SET_SPEECH
128}LYNQ_E_VOLUMN_SET;
lh25827952022-01-10 00:34:35 -0800129
130int lynq_call_state =CALL_OFF;
lha35d4ee2022-01-25 18:47:39 -0800131int lynq_call_client_sockfd = 0;
132int Global_uToken_call = 0;
lh25827952022-01-10 00:34:35 -0800133int global_call_count =0;
134int global_call_auto_answer = 0;
lha35d4ee2022-01-25 18:47:39 -0800135bool urc_call_recive_status = 1;
ll00a10dd2022-07-13 09:39:44 +0000136bool call_list_loop = 0;
lh25827952022-01-10 00:34:35 -0800137int isDial = 0;
138int lynqIncomingCallId = 0;
q.huangaa75aa62022-04-19 20:27:44 -0400139
q.huang68ee8a02022-06-28 20:12:01 +0800140/*rtp begin*/
141typedef struct
142{
143 char ip[MAX_IP_LENGTH];
144 int port;
q.huang60494a52022-10-11 17:48:06 +0800145 char vlan_info[MAX_VLAN_INFO_LENGTH];
q.huang68ee8a02022-06-28 20:12:01 +0800146}lynq_rtp_server_info;
147
148typedef struct
149{
150 int port;
151 int clockrate;
152 int latency;
153 int channels;
154}lynq_rtp_client_info;
155
156static lynq_rtp_client_info g_rtp_client_info;
157static lynq_rtp_server_info g_rtp_server_info;
158
159static pthread_t g_rtp_thread[RTP_MODE_MAX];
160static bool g_rtp_thread_valid[RTP_MODE_MAX];
161
162/*rtp end*/
163
q.huangaa75aa62022-04-19 20:27:44 -0400164#ifdef ECALL_SUPPORT
q.huangf8461432022-06-02 14:49:02 +0800165int lynq_set_common_request(int request_id, int argc, const char* format,...);
q.huangf8461432022-06-02 14:49:02 +0800166int g_ecallId = INVALID_ID;
q.huangaa75aa62022-04-19 20:27:44 -0400167typedef enum{
168 LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
169 LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
q.huang5a738c02022-04-18 00:09:50 -0400170 LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
q.huang4bb7b0a2022-06-21 14:57:02 +0800171 LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */
q.huang5a738c02022-04-18 00:09:50 -0400172}LYNQ_ECall_Type;
173
q.huang4bb7b0a2022-06-21 14:57:02 +0800174typedef enum{
175 LYNQ_ECALL_DAILING_STATE_NONE =0,
176 LYNQ_ECALL_DAILING_STATE_STARTED = 1,
177 LYNQ_ECALL_DAILING_STATE_ANSWERED = 2,
178}LYNQ_ECall_Dailing_State;
179
180LYNQ_ECall_Dailing_State is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
q.huangf8461432022-06-02 14:49:02 +0800181char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"test_ecall","emergency_ecall","reconf_ecall"};
q.huangaa75aa62022-04-19 20:27:44 -0400182
183static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
184static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
q.huange0024b02022-08-29 20:04:31 +0800185static pthread_mutex_t s_ecall_variable_mutex = PTHREAD_MUTEX_INITIALIZER;
q.huangaa75aa62022-04-19 20:27:44 -0400186
q.huangf8461432022-06-02 14:49:02 +0800187LYNQ_ECall_Indication g_lynqIncomingEcallIndication;
q.huange0024b02022-08-29 20:04:31 +0800188int g_lynqIncomingEcallId=INVALID_ID;
189LYNQ_ECall_Variant g_lynqEcallVariant=LYNQ_ECALL_VAR_NONE;
190int g_ecall_whether_preempt=0;
q.huangaa75aa62022-04-19 20:27:44 -0400191
192void sendSignalIncomingECallEvent()
193{
q.huang68ee8a02022-06-28 20:12:01 +0800194 LYINFLOG("send incoming ecall event signal");
q.huangaa75aa62022-04-19 20:27:44 -0400195 pthread_mutex_lock(&s_incoming_e_call_mutex);
196 pthread_cond_signal(&s_incoming_e_call_cond);
197 pthread_mutex_unlock(&s_incoming_e_call_mutex);
198}
q.huangf8461432022-06-02 14:49:02 +0800199
200int lynq_is_msd_suc(LYNQ_ECall_Indication lynqIncomingEcallIndication)
201{
202 if(LYNQ_ECALL_LLACK_RECEIVED == lynqIncomingEcallIndication ||
203 LYNQ_ECALL_ALACK_POSITIVE_RECEIVED == lynqIncomingEcallIndication ||
204 LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED == lynqIncomingEcallIndication ||
q.huange0024b02022-08-29 20:04:31 +0800205 //LYNQ_ECALL_T5_TIMER_OUT == lynqIncomingEcallIndication ||
q.huangf8461432022-06-02 14:49:02 +0800206 LYNQ_ECALL_T6_TIMER_OUT == lynqIncomingEcallIndication ||
207 LYNQ_ECALL_T7_TIMER_OUT == lynqIncomingEcallIndication)
208 {
209 return 1;
210 }
211
212 return 0;
213}
214
215int lynq_ecall_is_running()
216{
q.huange0024b02022-08-29 20:04:31 +0800217 return (is_ecall_dial!=LYNQ_ECALL_DAILING_STATE_NONE) || (g_ecallId !=INVALID_ID || g_lynqEcallVariant == LYNQ_ECALL_CALLBACK);
218}
219
220void print_ecall_info()
221{
222 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__,is_ecall_dial,g_ecallId,g_lynqEcallVariant,g_lynqIncomingEcallIndication,g_lynqIncomingEcallId,g_ecall_whether_preempt);
223}
224
225int lynq_ecall_is_permit_in_call(int ecall_id)
226{
227 return g_lynqEcallVariant == LYNQ_ECALL_CALLBACK && (g_ecallId ==INVALID_ID || g_ecallId ==ecall_id);
228}
229
230int lynq_ecall_is_in_voice()
231{
232 return (is_ecall_dial==LYNQ_ECALL_DAILING_STATE_NONE) && (g_ecallId !=INVALID_ID);
q.huangf8461432022-06-02 14:49:02 +0800233}
q.huangaa75aa62022-04-19 20:27:44 -0400234#endif
q.huang5a738c02022-04-18 00:09:50 -0400235
ll1343a5b2022-03-17 05:31:33 +0000236/**
237 * @brief mark call initialization state
238 * 0: deinit state
239 * 1: init state
240 */
241int g_lynq_call_init_flag = 0;
lh25827952022-01-10 00:34:35 -0800242
q.huang2befc3a2022-09-13 14:19:24 +0800243int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
lh25827952022-01-10 00:34:35 -0800244{
245 if(p.dataAvail() > 0)
246 {
247 p.readInt32(resp_type);
q.huang2befc3a2022-09-13 14:19:24 +0800248 p.readInt32(token);
lh25827952022-01-10 00:34:35 -0800249 p.readInt32(request);
250 p.readInt32(slot_id);
251 p.readInt32(error);
252 return 0;
253 }
254 else
255 {
256 return -1;
257 }
258}
259int send_request(int sockfd,lynq_client_t *client_tmp)
260{
261 int ret=0;
rjw8bdc56b2022-02-28 15:01:49 +0800262 ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
lh25827952022-01-10 00:34:35 -0800263 if(ret==-1)
264 {
q.huangf8461432022-06-02 14:49:02 +0800265 LYERRLOG("sendto error");
lh25827952022-01-10 00:34:35 -0800266 return -1;
267 }
268 return 0;
269}
270
271int get_response(int sockfd,Parcel &p)
272{
273 int len = 0;
274 char recvline[LYNQ_REC_BUF];
275 bzero(recvline,LYNQ_REC_BUF);
276 /* receive data from server */
rjw8bdc56b2022-02-28 15:01:49 +0800277 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
lh25827952022-01-10 00:34:35 -0800278 if(len == -1)
279 {
q.huangf8461432022-06-02 14:49:02 +0800280 LYERRLOG("recvfrom error");
lh25827952022-01-10 00:34:35 -0800281 return -1;
282 }
lh25827952022-01-10 00:34:35 -0800283 if (recvline != NULL) {
284 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
285 p.setDataPosition(0);
286 }
287 return 0;
288}
289static char *strdupReadString(Parcel &p) {
ll375c94d2022-01-27 05:54:38 +0000290 size_t stringlen;
lh25827952022-01-10 00:34:35 -0800291 const char16_t *s16;
292 s16 = p.readString16Inplace(&stringlen);
ll375c94d2022-01-27 05:54:38 +0000293 return strndup16to8(s16, stringlen);
lh25827952022-01-10 00:34:35 -0800294}
295
296int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
297{
298 Parcel p;
299 lynq_client_t client;
300 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +0800301 int token;
lh25827952022-01-10 00:34:35 -0800302 int request = -1;
303 int slot_id = -1;
304 int error = -1;
305 int call_num = 0;
306 int temp = 0;
307 char *remote_phoneNum = NULL;
308 char *remote_name= NULL;
309 char *uusData = NULL;
lha35d4ee2022-01-25 18:47:39 -0800310 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -0800311 client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
312 client.paramLen = 0;
313 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangf8461432022-06-02 14:49:02 +0800314 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
lha35d4ee2022-01-25 18:47:39 -0800315 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -0800316 {
317 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -0800318 return -1;
319 }
lha35d4ee2022-01-25 18:47:39 -0800320 get_response(lynq_call_client_sockfd,p);
q.huang2befc3a2022-09-13 14:19:24 +0800321 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh25827952022-01-10 00:34:35 -0800322 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
323 if(error == 0)
324 {
325 p.readInt32(&call_num);
326 global_call_count = call_num;
327 if(call_num<=0)
328 {
329 lynq_call_state = CALL_OFF;
lhcdf816a2022-02-13 23:56:05 -0800330 LYINFLOG("lynq_call_state:%d",lynq_call_state);
lh25827952022-01-10 00:34:35 -0800331 return 0;
332 }
lhcdf816a2022-02-13 23:56:05 -0800333 lynq_call_state = CALL_ON;
q.huangf8461432022-06-02 14:49:02 +0800334 LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
lh25827952022-01-10 00:34:35 -0800335 for(int i = 0;i < call_num;i++)
336 {
337 p.readInt32(&temp);
338 call_list[i].call_state = temp;
339 p.readInt32(&call_list[i].call_id);
340 p.readInt32(&call_list[i].toa);
341 p.readInt32(&temp);
342 p.readInt32(&temp);
343 call_list[i].direction = temp;
344 p.readInt32(&temp);
345 p.readInt32(&temp);
346 p.readInt32(&temp);
347 remote_phoneNum = strdupReadString(p);
348 memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
349 LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
350 call_list[i].direction,call_list[i].addr,call_list[i].toa);
351 p.readInt32(&temp);
352 remote_name = strdupReadString(p);
353 p.readInt32(&temp);
354 p.readInt32(&temp);
355 if(temp==0)
356 {
357 continue;
358 }
359 p.readInt32(&temp); /* UUS Information is present */
360 p.readInt32(&temp);
361 p.readInt32(&temp);
362 p.read(uusData,temp);
ll532a91d2022-10-12 17:57:17 +0800363 free(remote_phoneNum);
364 free(remote_name);
lh25827952022-01-10 00:34:35 -0800365 }
366 }
367 return 0;
368}
369
370void cleanCallList(int lynq_call_id)
371{
q.huangf8461432022-06-02 14:49:02 +0800372 LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
lh25827952022-01-10 00:34:35 -0800373 lynq_call_lists[lynq_call_id].call_id = 0;
lh745926c2022-04-26 00:45:44 -0700374 lynq_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
lh25827952022-01-10 00:34:35 -0800375 lynq_call_lists[lynq_call_id].toa = 0;
376 lynq_call_lists[lynq_call_id].direction = 0;
377 lynq_call_lists[lynq_call_id].used = 0;
lh25827952022-01-10 00:34:35 -0800378 memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
379}
380int getUnusedElement()
381{
382 for(int i=0;i < LYNQ_CALL_MAX; i++)
383 {
384 if(lynq_call_lists[i].used!=1)
385 {
386 return i;
387 }
388 }
389 return -1;
390}
q.huangf8461432022-06-02 14:49:02 +0800391int addAddr(char addr[])
lh25827952022-01-10 00:34:35 -0800392{
393 int ret = 0;
394 ret = getUnusedElement();
395 memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
396 lynq_call_lists[ret].used = 1;
q.huangf8461432022-06-02 14:49:02 +0800397 LYINFLOG("add local idx is %d addr is %s",ret,addr);
lh25827952022-01-10 00:34:35 -0800398 return ret;
399}
400void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
401{
q.huangf8461432022-06-02 14:49:02 +0800402 LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
lh25827952022-01-10 00:34:35 -0800403 callList->call_id = call_id;
404 callList->call_state = call_state;
405 callList->toa = toa;
q.huangf8461432022-06-02 14:49:02 +0800406 callList->direction = direction;
lh25827952022-01-10 00:34:35 -0800407 return;
408}
409int waitCallstateChange(int mtime)
410{
lh5095be72022-04-19 06:01:25 -0700411 LYINFLOG("wait Call state Change");
lh25827952022-01-10 00:34:35 -0800412 int ret = 0;
413 int sec = 0;
414 int usec = 0;
lh228a7b82022-01-10 02:24:31 -0800415 struct timeval now;
416 struct timespec timeout;
417 gettimeofday(&now,NULL);
lh25827952022-01-10 00:34:35 -0800418 sec = mtime/1000;
419 usec = mtime%1000;
lh228a7b82022-01-10 02:24:31 -0800420 timeout.tv_sec = now.tv_sec+sec;
421 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
lh25827952022-01-10 00:34:35 -0800422 pthread_mutex_lock(&call_state_change_mutex);
lh228a7b82022-01-10 02:24:31 -0800423 ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
lh25827952022-01-10 00:34:35 -0800424 pthread_mutex_unlock(&call_state_change_mutex);
425 return ret;
426}
427int waitIncomingCall()
428{
lh5095be72022-04-19 06:01:25 -0700429 LYINFLOG("wait incming call");
lh25827952022-01-10 00:34:35 -0800430 int ret = 0;
431 pthread_mutex_lock(&s_incoming_call_mutex);
432 ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
433 pthread_mutex_unlock(&s_incoming_call_mutex);
434 return ret;
435}
436int checkHasCall(char addr[])
437{
438 for(int i = 0;i<LYNQ_CALL_MAX;i++)
439 {
440 if(strcmp(lynq_call_lists[i].addr,addr)==0)
441 {
q.huangf8461432022-06-02 14:49:02 +0800442 LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,lynq_call_lists[i].call_id);
lh25827952022-01-10 00:34:35 -0800443 return 1;
444 }
445 }
q.huangf8461432022-06-02 14:49:02 +0800446 LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
lh25827952022-01-10 00:34:35 -0800447 return 0;
448}
lh5095be72022-04-19 06:01:25 -0700449int find_call_id_with_addr(char *addr)
450{
lh5095be72022-04-19 06:01:25 -0700451 for(int id = 0; id < LYNQ_CALL_MAX; id++)
452 {
q.huangf8461432022-06-02 14:49:02 +0800453 if(lynq_call_lists[id].used && (strcmp(lynq_call_lists[id].addr,addr) == 0))
lh5095be72022-04-19 06:01:25 -0700454 {
q.huangf8461432022-06-02 14:49:02 +0800455 LYINFLOG("find addr %s in local list, local idx is %d id is %d",addr,id,lynq_call_lists[id].call_id);
lh5095be72022-04-19 06:01:25 -0700456 return id;
457 }
458 }
q.huangf8461432022-06-02 14:49:02 +0800459 LYINFLOG("find addr %s in local list , not found",addr);
lh5095be72022-04-19 06:01:25 -0700460 return -1;
461}
q.huangf8461432022-06-02 14:49:02 +0800462int find_call_id_with_call_id(int call_id)
463{
464 for(int id = 0; id < LYNQ_CALL_MAX; id++)
465 {
466 if(lynq_call_lists[id].used && (lynq_call_lists[id].call_id == call_id))
467 {
468 LYINFLOG("find id %d in local list, local idx is %d, addr is %s",call_id,id,lynq_call_lists[id].addr);
469 return id;
470 }
471 }
472 LYINFLOG("find id %d in local list , not found",call_id);
473 return INVALID_ID;
474}
lh25827952022-01-10 00:34:35 -0800475void sendSignalToWaitCallStateChange()
476{
lh5095be72022-04-19 06:01:25 -0700477 LYINFLOG("send Signal To Wait Call State Change");
lh25827952022-01-10 00:34:35 -0800478 pthread_mutex_lock(&call_state_change_mutex);
479 pthread_cond_signal(&call_state_change_cond);
480 pthread_mutex_unlock(&call_state_change_mutex);
481}
482void sendSignalIncomingCall()
483{
lh5095be72022-04-19 06:01:25 -0700484 LYINFLOG("send incoming call signal");
lh25827952022-01-10 00:34:35 -0800485 pthread_mutex_lock(&s_incoming_call_mutex);
486 pthread_cond_signal(&s_incoming_call_cond);
487 pthread_mutex_unlock(&s_incoming_call_mutex);
488}
489
490void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
491{
492 callList->call_id = call_id;
493 callList->call_state = call_state;
494 callList->toa = toa;
495 callList->direction = direction;
496 memcpy(callList->addr,addr,strlen(addr)+1);
497 callList->used = 1;
lh25827952022-01-10 00:34:35 -0800498 return;
499}
500
501void *triggerGetCallList(void *parg)
ll375c94d2022-01-27 05:54:38 +0000502{
503 int ret=0;
lh5095be72022-04-19 06:01:25 -0700504 bool call_end;
ll375c94d2022-01-27 05:54:38 +0000505 lynq_call_list_t call_list[LYNQ_CALL_MAX];
q.huangaa75aa62022-04-19 20:27:44 -0400506 int update=0;
q.huangf8461432022-06-02 14:49:02 +0800507 int cnt;
508 int i,n;
q.huange0024b02022-08-29 20:04:31 +0800509#ifdef ECALL_SUPPORT
510 int handupIncomingMT=0;
511#endif
q.huangf8461432022-06-02 14:49:02 +0800512
lh25827952022-01-10 00:34:35 -0800513 while(call_list_loop)
ll375c94d2022-01-27 05:54:38 +0000514 {
q.huangaa75aa62022-04-19 20:27:44 -0400515 update=0;
ll00a10dd2022-07-13 09:39:44 +0000516 pthread_mutex_lock(s_urc_call_state_change_mutex);
517 pthread_cond_wait(s_urc_call_state_change_cond, s_urc_call_state_change_mutex);
q.huangf8461432022-06-02 14:49:02 +0800518 LYDBGLOG("triggerGetCallList event!!!");
ll375c94d2022-01-27 05:54:38 +0000519 memset(call_list,0,sizeof(call_list));
520 ret = lynq_get_current_call_list(call_list);
521 if(ret != 0)
522 {
q.huangf8461432022-06-02 14:49:02 +0800523 LYDBGLOG("get current call list failure!!!");
ll83081992022-04-11 05:49:51 +0000524 continue;
ll375c94d2022-01-27 05:54:38 +0000525 }
lh5095be72022-04-19 06:01:25 -0700526 LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
q.huangf8461432022-06-02 14:49:02 +0800527 LYINFLOG("clear local index begin");
528 cnt=0;
529 for(i = 0;i < LYNQ_CALL_MAX;i++)
lh25827952022-01-10 00:34:35 -0800530 {
q.huangf8461432022-06-02 14:49:02 +0800531 if(lynq_call_lists[i].used ==0)
532 {
533 continue;
534 }
535 cnt++;
536 LYINFLOG("local idx is %d id is %d addr is %s state is %d direction is %d",i,lynq_call_lists[i].call_id,lynq_call_lists[i].addr,lynq_call_lists[i].call_state,lynq_call_lists[i].direction);
537
538 if(lynq_call_lists[i].call_id > 0)
lh5095be72022-04-19 06:01:25 -0700539 {
540 call_end = 0;
q.huangf8461432022-06-02 14:49:02 +0800541 for(n = 0; n < LYNQ_CALL_MAX; n++)
lh5095be72022-04-19 06:01:25 -0700542 {
q.huangf8461432022-06-02 14:49:02 +0800543 if(call_list[n].call_id == lynq_call_lists[i].call_id)
lh5095be72022-04-19 06:01:25 -0700544 {
545 call_end = 1;
q.huangf8461432022-06-02 14:49:02 +0800546 LYINFLOG("find lynq call local idx %d, service idx %d id is %d!!!",i,n,lynq_call_lists[i].call_id);
547 break;
lh5095be72022-04-19 06:01:25 -0700548 }
549 }
550 if(call_end == 0)
551 {
q.huangf8461432022-06-02 14:49:02 +0800552 LYINFLOG("MT hungup,then clean call info local idx is %d id is %d",i, lynq_call_lists[i].call_id);
553 cleanCallList(i);
lh5095be72022-04-19 06:01:25 -0700554 }
555 } //fix bug API-54
q.huangf8461432022-06-02 14:49:02 +0800556 else
557 {
558 LYINFLOG("local id is 0");
559 }
560 }
561 LYINFLOG("clear local index end, local used cnt is %d", cnt);
562
563 LYINFLOG("add or update local index begin ");
564 for (i = 0;i < LYNQ_CALL_MAX;i++)
565 {
566 if(call_list[i].call_id==0)
567 {
568 break;
569 }
570
571 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,
572 call_list[i].direction,call_list[i].addr,call_list[i].toa);
573
lh25827952022-01-10 00:34:35 -0800574 if(call_list[i].direction == 1)//MT call
575 {
q.huangf8461432022-06-02 14:49:02 +0800576 LYINFLOG("This is a MT CALL");
lh36a140b2022-05-13 03:02:19 -0700577 /*MT CALL state code
578 **LYNQ_CALL_INCOMING = 4,
579 **LYNQ_CALL_WAITING = 5,
580 */
q.huange0024b02022-08-29 20:04:31 +0800581#ifdef ECALL_SUPPORT
lh36a140b2022-05-13 03:02:19 -0700582 if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
lh25827952022-01-10 00:34:35 -0800583 {
q.huange0024b02022-08-29 20:04:31 +0800584
585 pthread_mutex_lock(&s_ecall_variable_mutex);
586 handupIncomingMT=lynq_ecall_is_running() && (lynq_ecall_is_permit_in_call(call_list[i].call_id)==false);
587 pthread_mutex_unlock(&s_ecall_variable_mutex);
588 LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
589 if(handupIncomingMT)
lh25827952022-01-10 00:34:35 -0800590 {
q.huangf8461432022-06-02 14:49:02 +0800591 lynq_call_hungup(&(call_list[i].call_id));
592 continue;
q.huange0024b02022-08-29 20:04:31 +0800593 }
q.huangf8461432022-06-02 14:49:02 +0800594 }
q.huange0024b02022-08-29 20:04:31 +0800595#endif
q.huangf8461432022-06-02 14:49:02 +0800596 /*you call me, and i call you,One party failed to dial*/
597 n = find_call_id_with_addr(call_list[i].addr);
598 if(n ==INVALID_ID)
599 {
600 n = addAddr(call_list[i].addr);
601 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
602 lynqIncomingCallId = call_list[i].call_id;
603 sendSignalIncomingCall();
604 }
605 else if(lynq_call_lists[n].call_state == call_list[i].call_state)
606 {
607 LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
608 if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
lh5095be72022-04-19 06:01:25 -0700609 {
lh5095be72022-04-19 06:01:25 -0700610 /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
611 **an incoming call until the status changes.
612 **fix bug API-54
613 */
q.huangf8461432022-06-02 14:49:02 +0800614 LYINFLOG("resend incoming call signal");
615 sendSignalIncomingCall();
lh5095be72022-04-19 06:01:25 -0700616 }
lh25827952022-01-10 00:34:35 -0800617 }
q.huangf8461432022-06-02 14:49:02 +0800618 else
ll45d3ea92022-03-24 10:22:25 +0800619 {
q.huangf8461432022-06-02 14:49:02 +0800620 LYINFLOG("state changed from %d to %d",lynq_call_lists[n].call_state,call_list[i].call_state);
621
622 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
623 }
lh25827952022-01-10 00:34:35 -0800624 }
625 else
q.huangf8461432022-06-02 14:49:02 +0800626 {
627 LYINFLOG("This is a MO CALL");
628 call_end = 0;
629 for(n = 0 ; n < LYNQ_CALL_MAX; n++)
lh25827952022-01-10 00:34:35 -0800630 {
q.huangf8461432022-06-02 14:49:02 +0800631 if(lynq_call_lists[n].used && ((strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)||(call_list[i].call_id==lynq_call_lists[n].call_id)))
lh25827952022-01-10 00:34:35 -0800632 {
q.huangf8461432022-06-02 14:49:02 +0800633 if(lynq_call_lists[n].call_id==0)
634 {
635 LYINFLOG("add a call id");
636 update=1;
637 }
638 LYINFLOG("local idx %d updated, original call id is %d origial addr is %s original state is %d",n,lynq_call_lists[n].call_id,lynq_call_lists[n].addr,lynq_call_lists[n].call_state);
639 updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
640 call_end = 1;
641 break;
642 }
643 }
644
645 if(call_end == 0)
646 {
647 LYINFLOG("need to hangup id %d", call_list[i].call_id);
648#ifdef ECALL_SUPPORT
q.huang4bb7b0a2022-06-21 14:57:02 +0800649 if(is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
q.huangf8461432022-06-02 14:49:02 +0800650 {
651 LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
lh25827952022-01-10 00:34:35 -0800652 continue;
653 }
q.huangf8461432022-06-02 14:49:02 +0800654#endif
655 LYINFLOG("hang up service call id %d",call_list[i].call_id);
656 lynq_call_hungup(&(call_list[i].call_id));
lh25827952022-01-10 00:34:35 -0800657 }
lh25827952022-01-10 00:34:35 -0800658 }
q.huangf8461432022-06-02 14:49:02 +0800659 LYDBGLOG("servie idx %d end",i);
ll375c94d2022-01-27 05:54:38 +0000660 }
q.huangf8461432022-06-02 14:49:02 +0800661 LYINFLOG("add or update local index end ");
lha35d4ee2022-01-25 18:47:39 -0800662 s_call_urc_event_complete = 1;
q.huangf8461432022-06-02 14:49:02 +0800663 if(isDial==1)
lh25827952022-01-10 00:34:35 -0800664 {
q.huangf8461432022-06-02 14:49:02 +0800665 LYINFLOG("now is dialing");
666 if(update==1)
667 {
668 LYINFLOG("find added call");
669 sendSignalToWaitCallStateChange();
670 isDial = 0;
671 }
672 else
673 {
674 LYINFLOG("not find added call");
675 }
676 }
677 else
678 {
679 LYINFLOG("now is not dialing");
lh25827952022-01-10 00:34:35 -0800680 }
ll00a10dd2022-07-13 09:39:44 +0000681 pthread_mutex_unlock(s_urc_call_state_change_mutex);
ll375c94d2022-01-27 05:54:38 +0000682 }
683 return NULL;
lh25827952022-01-10 00:34:35 -0800684}
685
686void lynqRespWatingEvent()
ll375c94d2022-01-27 05:54:38 +0000687{
688 if(s_call_urc_event_complete==1)
689 {
ll00a10dd2022-07-13 09:39:44 +0000690 pthread_mutex_lock(s_urc_call_state_change_mutex);
691 pthread_cond_signal(s_urc_call_state_change_cond);
ll375c94d2022-01-27 05:54:38 +0000692 s_call_urc_event_complete = 0;
ll00a10dd2022-07-13 09:39:44 +0000693 pthread_mutex_unlock(s_urc_call_state_change_mutex);
lh25827952022-01-10 00:34:35 -0800694 }
ll375c94d2022-01-27 05:54:38 +0000695 return;
lh25827952022-01-10 00:34:35 -0800696}
697
698/*Warren add for T800 platform 2021/11/19 start*/
699int lynq_socket_client_start()
rjw8bdc56b2022-02-28 15:01:49 +0800700{
701 #if 0
lh25827952022-01-10 00:34:35 -0800702 struct sockaddr_in lynq_socket_server_addr;
703 /* init lynq_socket_server_addr */
704 bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
705 lynq_socket_server_addr.sin_family = AF_INET;
706 lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
707 lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
rjw8bdc56b2022-02-28 15:01:49 +0800708
lh25827952022-01-10 00:34:35 -0800709 /*
710 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
711 {
q.huangf8461432022-06-02 14:49:02 +0800712 LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
lh25827952022-01-10 00:34:35 -0800713 exit(1);
714 }
715*/
lha35d4ee2022-01-25 18:47:39 -0800716 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
717 if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
lh25827952022-01-10 00:34:35 -0800718 {
q.huangf8461432022-06-02 14:49:02 +0800719 LYERRLOG("connect error");
lh25827952022-01-10 00:34:35 -0800720 return -1;
721 }
rjw8bdc56b2022-02-28 15:01:49 +0800722 #endif
723 lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
724 if (-1 == lynq_call_client_sockfd)
725 {
726 return lynq_call_client_sockfd;
727 }
ll78948a22022-07-25 05:52:14 +0000728 struct timeval timeOut;
729 timeOut.tv_sec = 60;
730 timeOut.tv_usec = 0;
731 if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
732 {
733 RLOGD("time out setting failed\n");
734 return -1;
735 }
rjw8bdc56b2022-02-28 15:01:49 +0800736 /* 设置address */
737 memset(&addr_serv, 0, sizeof(addr_serv));
738 addr_serv.sin_family = AF_INET;
739 addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
740 addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
741 len_addr_serv = sizeof(addr_serv);
lh25827952022-01-10 00:34:35 -0800742 return 0;
743}
744int lynq_update_call_list_loop()
745{
746 int ret = 0;
lh25827952022-01-10 00:34:35 -0800747 pthread_attr_t attr;
748 pthread_attr_init(&attr);
749 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -0800750 ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
lh25827952022-01-10 00:34:35 -0800751 if(ret < 0)
752 {
753 LYERRLOG("lynq_update_call_list_loop fail!!!");
754 return -1;
755 }
q.huangf8461432022-06-02 14:49:02 +0800756 LYDBGLOG("lynq_update_call_list_loop success!!!");
lh25827952022-01-10 00:34:35 -0800757 return 0;
758
759}
q.huangf8461432022-06-02 14:49:02 +0800760
lh25827952022-01-10 00:34:35 -0800761void *thread_urc_recv(void *parg)
ll375c94d2022-01-27 05:54:38 +0000762{
lh25827952022-01-10 00:34:35 -0800763 int socket_fd = (int64_t)parg;
764 int len=0;
765 socklen_t addr_len=0;
766 uint8_t *dataLength = NULL;
767 char urc_data[LYNQ_REC_BUF];
768 int slot_id = -1;
769 int resp_type = -1;
770 int urcid = -1;
771 Parcel *p = NULL;
772 struct sockaddr_in dest_addr;
q.huangaa75aa62022-04-19 20:27:44 -0400773#ifdef ECALL_SUPPORT
q.huangf8461432022-06-02 14:49:02 +0800774 int ecall_ind;
775 int ecallId;
776 int unused_callid;
q.huange0024b02022-08-29 20:04:31 +0800777 int send_signal_to_wait_call_state;
778 int handup_ecall_id;
q.huangaa75aa62022-04-19 20:27:44 -0400779#endif
780
q.huangf8461432022-06-02 14:49:02 +0800781 LYINFLOG("thread_urc_recv in running....");
lha35d4ee2022-01-25 18:47:39 -0800782 while(urc_call_recive_status)
lh25827952022-01-10 00:34:35 -0800783 {
784 bzero(urc_data,LYNQ_REC_BUF);
785 //get data msg
786 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
787 if(len <= 0)
ll375c94d2022-01-27 05:54:38 +0000788 {
q.huangf8461432022-06-02 14:49:02 +0800789 LYERRLOG("thread_urc_recv step2 fail");
ll375c94d2022-01-27 05:54:38 +0000790 break;
lh25827952022-01-10 00:34:35 -0800791 }
q.huangf8461432022-06-02 14:49:02 +0800792 LYDBGLOG("=====>urc data len<=====:%d",len);
lh25827952022-01-10 00:34:35 -0800793 p = new Parcel();
794 if(p==NULL)
795 {
lh59e0d002022-01-27 00:27:12 -0800796 LYERRLOG("new parcel failure!!!");
lh25827952022-01-10 00:34:35 -0800797 break;
798 }
799 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
800 p->setDataPosition(0);
801 if(p->dataAvail() > 0)
802 {
803 p->readInt32(&resp_type);
804 p->readInt32(&urcid);
805 p->readInt32(&slot_id);
q.huangf8461432022-06-02 14:49:02 +0800806 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
lh25827952022-01-10 00:34:35 -0800807 switch (urcid)
808 {
809 case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
810 {
q.huangf8461432022-06-02 14:49:02 +0800811 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
lh25827952022-01-10 00:34:35 -0800812 lynqRespWatingEvent();
813 break;
814 }
815 case 1018://RIL_UNSOL_CALL_RING
816 {
817 if(global_call_auto_answer==1)
818 {
819 lynq_call_answer();
820 }
821 break;
822 }
823 case 1029://RIL_UNSOL_RINGBACK_TONE
824 case 3049://RIL_UNSOL_CALL_INFO_INDICATION
825 {
q.huangf8461432022-06-02 14:49:02 +0800826 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
lh25827952022-01-10 00:34:35 -0800827 break;
828 }
q.huangaa75aa62022-04-19 20:27:44 -0400829#ifdef ECALL_SUPPORT
830 case RIL_UNSOL_ECALL_INDICATIONS:
831 {
q.huange0024b02022-08-29 20:04:31 +0800832 pthread_mutex_lock(&s_ecall_variable_mutex);
833 send_signal_to_wait_call_state = false;
834 handup_ecall_id=false;
q.huangf8461432022-06-02 14:49:02 +0800835 p->readInt32(&ecall_ind);
836 g_lynqIncomingEcallIndication = ecall_ind;
837 p->readInt32(&ecallId);
q.huang4bb7b0a2022-06-21 14:57:02 +0800838 g_lynqIncomingEcallId = ecallId;
q.huangf8461432022-06-02 14:49:02 +0800839 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,is_ecall_dial,isDial,g_ecallId);
q.huang4bb7b0a2022-06-21 14:57:02 +0800840 switch (g_lynqIncomingEcallIndication)
q.huangf8461432022-06-02 14:49:02 +0800841 {
q.huang4bb7b0a2022-06-21 14:57:02 +0800842 case LYNQ_ECALL_ACTIVE:
843 if(is_ecall_dial)
q.huangf8461432022-06-02 14:49:02 +0800844 {
q.huang4bb7b0a2022-06-21 14:57:02 +0800845 is_ecall_dial = LYNQ_ECALL_DAILING_STATE_ANSWERED;
q.huangf8461432022-06-02 14:49:02 +0800846 }
q.huang4bb7b0a2022-06-21 14:57:02 +0800847 break;
q.huange0024b02022-08-29 20:04:31 +0800848 case LYNQ_ECALL_SENDING_START:
849 if(lynq_ecall_is_in_voice())
850 {
851 LYINFLOG("recv msd in voice, ind is changed to %d",LYNQ_ECALL_SENDING_START_IN_VOICE);
852 g_lynqIncomingEcallIndication = LYNQ_ECALL_SENDING_START_IN_VOICE;
853 }
854 break;
q.huang4bb7b0a2022-06-21 14:57:02 +0800855 case LYNQ_ECALL_LLACK_RECEIVED:
856 case LYNQ_ECALL_ALACK_POSITIVE_RECEIVED:
857 case LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED:
q.huange0024b02022-08-29 20:04:31 +0800858 //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*/
q.huang4bb7b0a2022-06-21 14:57:02 +0800859 case LYNQ_ECALL_T6_TIMER_OUT:
860 case LYNQ_ECALL_T7_TIMER_OUT:
861 if(is_ecall_dial)
862 {
863 LYINFLOG("ecall is dialing, recv suc indication");
864 is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
865 if(ecallId >0 && find_call_id_with_call_id(ecallId)==INVALID_ID)
866 {
867 LYINFLOG("add ecall in loacl list");
868 g_ecallId = ecallId;
869 unused_callid=addAddr("ecall");
870 lynq_call_lists[unused_callid].call_id=g_ecallId;
q.huange0024b02022-08-29 20:04:31 +0800871 }
872 send_signal_to_wait_call_state=true;
q.huang4bb7b0a2022-06-21 14:57:02 +0800873 }
q.huange0024b02022-08-29 20:04:31 +0800874 else if(ecallId >0 && (find_call_id_with_call_id(ecallId)==INVALID_ID) && (g_lynqEcallVariant != LYNQ_ECALL_CALLBACK))
q.huang4bb7b0a2022-06-21 14:57:02 +0800875 {
876 LYERRLOG("ecall is not in dialing and first recv suc indication, hangup");
q.huange0024b02022-08-29 20:04:31 +0800877 handup_ecall_id=true;
q.huang4bb7b0a2022-06-21 14:57:02 +0800878 }
879 else
880 {
881 LYERRLOG("ecall is not in dialing and not first recv suc indication");
882 }
883 break;
884 case LYNQ_ECALL_PSAP_CALLBACK_START:
885 if(lynq_ecall_is_running()==0)
886 {
q.huange0024b02022-08-29 20:04:31 +0800887 if(ecallId>0)
888 {
889 LYINFLOG("ecall is not running, recv psap call back msd start, set ecall running");
890 g_lynqEcallVariant = LYNQ_ECALL_CALLBACK;
q.huang4bb7b0a2022-06-21 14:57:02 +0800891 g_ecallId = ecallId;
892 if(isDial)
893 {
894 LYINFLOG("stop normal dial");
q.huange0024b02022-08-29 20:04:31 +0800895 send_signal_to_wait_call_state=true;
q.huang4bb7b0a2022-06-21 14:57:02 +0800896 }
897 else
898 {
899 LYINFLOG("no normal dial");
q.huange0024b02022-08-29 20:04:31 +0800900 }
q.huang4bb7b0a2022-06-21 14:57:02 +0800901 }
902 else
903 {
q.huange0024b02022-08-29 20:04:31 +0800904 LYERRLOG("ecallId is abnormal in psap callback");
905 }
906 }
q.huang4bb7b0a2022-06-21 14:57:02 +0800907 else
908 {
909 LYERRLOG("ecall is running, recv psap call back msd start");
910 }
911 break;
912 case LYNQ_ECALL_ABNORMAL_HANGUP:
913 if(is_ecall_dial == LYNQ_ECALL_DAILING_STATE_NONE)
914 {
915 LYERRLOG("ecall is not in dialing , recv abnormal hangup");
916 g_ecallId = INVALID_ID;
917 }
918 else if (is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)
919 {
920 LYERRLOG("ecall is in dialing state, recv no answer, recv abnormal hangup, dont' redial");
921 g_ecallId = INVALID_ID;
q.huange0024b02022-08-29 20:04:31 +0800922 send_signal_to_wait_call_state=true;
q.huang4bb7b0a2022-06-21 14:57:02 +0800923 }
924 else {
925 LYINFLOG("ecall is in dialing and recv answer, recv abnormal hangup");
926 }
927 break;
928 case LYNQ_ECALL_DISCONNECTED:
929 case LYNQ_ECALL_REDIAL_TIMER_OUT:
930 case LYNQ_ECALL_T2_TIMER_OUT :
q.huange0024b02022-08-29 20:04:31 +0800931 case LYNQ_ECALL_IMS_DISCONNECTED:
q.huang4bb7b0a2022-06-21 14:57:02 +0800932 g_ecallId = INVALID_ID;
q.huange0024b02022-08-29 20:04:31 +0800933 if(g_lynqEcallVariant == LYNQ_ECALL_CALLBACK)
934 {
935 g_lynqEcallVariant = LYNQ_ECALL_VAR_NONE; /*other type, needn't re-initialize*/
936 }
q.huang4bb7b0a2022-06-21 14:57:02 +0800937 if(is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
938 {
939 LYERRLOG("ecall is in dialing, recv like disconnect indication");
q.huange0024b02022-08-29 20:04:31 +0800940 is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
941 send_signal_to_wait_call_state=true;
q.huang4bb7b0a2022-06-21 14:57:02 +0800942 }
943 else
944 {
945 LYINFLOG("ecall is not in dialing, recv like disconnect indication");
946 }
947 break;
948 default:
949 LYINFLOG("not special indication");
q.huange0024b02022-08-29 20:04:31 +0800950 }
951 pthread_mutex_unlock(&s_ecall_variable_mutex);
952 if(send_signal_to_wait_call_state)
953 {
954 sendSignalToWaitCallStateChange();
q.huangf8461432022-06-02 14:49:02 +0800955 }
q.huangaa75aa62022-04-19 20:27:44 -0400956 sendSignalIncomingECallEvent();
q.huange0024b02022-08-29 20:04:31 +0800957 if(handup_ecall_id)
958 {
959 lynq_call_hungup(&ecallId);
960 }
q.huangf8461432022-06-02 14:49:02 +0800961 LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS, local ecall id is %d", g_ecallId);
q.huangaa75aa62022-04-19 20:27:44 -0400962 break;
963 }
964#endif
lh25827952022-01-10 00:34:35 -0800965 default:
966 break;
967 }
968 }
969 delete p;
970 p = NULL;
971 }
972 close(socket_fd);
973}
974int lynq_socket_urc_start()
975{
976 int socket_fd=0;
977 int rt=0;
978 int len=0;
979 int on=1;
980 struct sockaddr_in urc_local_addr;
lh25827952022-01-10 00:34:35 -0800981 pthread_attr_t attr;
ll375c94d2022-01-27 05:54:38 +0000982 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
ll375c94d2022-01-27 05:54:38 +0000983 if(socket_fd < 0)
984 {
q.huangf8461432022-06-02 14:49:02 +0800985 LYERRLOG("creaet socket for udp fail");
ll375c94d2022-01-27 05:54:38 +0000986 return -1;
lh25827952022-01-10 00:34:35 -0800987 }
988 urc_local_addr.sin_family = AF_INET;
989 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
990 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
991 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ll375c94d2022-01-27 05:54:38 +0000992 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
993 if(rt<0)
994 {
q.huangf8461432022-06-02 14:49:02 +0800995 LYERRLOG("SO_REUSEADDR fail");
lh25827952022-01-10 00:34:35 -0800996 return -1;
997 }
998 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
ll375c94d2022-01-27 05:54:38 +0000999 if (rt == -1)
1000 {
lh59e0d002022-01-27 00:27:12 -08001001 LYERRLOG("bind failed");
ll375c94d2022-01-27 05:54:38 +00001002 return -1;
lh25827952022-01-10 00:34:35 -08001003 }
1004 pthread_attr_init(&attr);
1005 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
lhcdf816a2022-02-13 23:56:05 -08001006 rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
lh25827952022-01-10 00:34:35 -08001007 if(rt < 0)
1008 {
q.huangf8461432022-06-02 14:49:02 +08001009 LYERRLOG("urc loop failure!!!");
lh25827952022-01-10 00:34:35 -08001010 return -1;
1011 }
q.huangf8461432022-06-02 14:49:02 +08001012 LYDBGLOG("urc loop success!!!");
lh25827952022-01-10 00:34:35 -08001013 return 0;
1014}
1015int getSelfElement(char addr[])
1016{
1017 for(int i=0;i < LYNQ_CALL_MAX; i++)
1018 {
1019 if(lynq_call_lists[i].used==1)
1020 {
1021 if(strcmp(lynq_call_lists[i].addr,addr)==0)
1022 {
1023 return i;
1024 }
1025
1026 }
1027 }
1028 return -1;
1029}
1030
1031void lynq_call_state_change_test(int soc_id)
1032{
q.huangf8461432022-06-02 14:49:02 +08001033 LYDBGLOG("call state change,sim:%d",soc_id);
lh25827952022-01-10 00:34:35 -08001034}
q.huang68ee8a02022-06-28 20:12:01 +08001035
1036void lynq_init_rtp()
1037{
1038 memset(&g_rtp_client_info,0,sizeof(g_rtp_client_info));
1039 memset(&g_rtp_server_info,0,sizeof(g_rtp_server_info));
1040
1041
1042 lynq_set_rtp_param(8000,1,400);
1043
1044 for(int i=0;i<RTP_MODE_MAX;i++)
1045 {
q.huange6109d92022-06-30 09:55:45 +08001046 lynq_set_rtp_port(i,6666);
q.huang68ee8a02022-06-28 20:12:01 +08001047 g_rtp_thread_valid[i] = 0;
1048 }
1049
1050 LYDBGLOG("lynq init rtp success!!!");
1051 return;
1052}
1053
lh25827952022-01-10 00:34:35 -08001054int lynq_init_call(int uToken)
ll1343a5b2022-03-17 05:31:33 +00001055{
1056 if(g_lynq_call_init_flag == 1){
1057 LYDBGLOG("lynq init call failed!!!");
1058 return -1;
1059 }
1060 g_lynq_call_init_flag = 1;
ll00a10dd2022-07-13 09:39:44 +00001061 s_call_urc_event_complete = 1;
1062 call_list_loop = 1;
1063 LYINFLOG("liulei call_list_loop %d\n", call_list_loop);
1064 s_urc_call_state_change_mutex = new pthread_mutex_t;
1065 pthread_mutex_init(s_urc_call_state_change_mutex, NULL);
1066 s_urc_call_state_change_cond = new pthread_cond_t;
1067 LYINFLOG("liulei s_urc_call_state_change_mutex\n");
1068 pthread_cond_init(s_urc_call_state_change_cond, NULL);
1069 LYINFLOG("liulei s_urc_call_state_change_cond\n");
lh25827952022-01-10 00:34:35 -08001070 int result = 0;
lha35d4ee2022-01-25 18:47:39 -08001071 Global_uToken_call = uToken;
lh59e0d002022-01-27 00:27:12 -08001072 urc_call_recive_status = 1;
rjw8bdc56b2022-02-28 15:01:49 +08001073 client_size = sizeof(client_t);
lh25827952022-01-10 00:34:35 -08001074 LYLOGSET(LOG_INFO);
1075 LYLOGEINIT(USER_LOG_TAG);
1076 result = lynq_socket_client_start();
1077 if(result!=0)
1078 {
1079 return -1;
1080 }
1081 result = lynq_socket_urc_start();
1082 if(result!=0)
1083 {
1084 return -1;
1085 }
1086 result = lynq_update_call_list_loop();
1087 if(result!=0)
1088 {
1089 return -1;
1090 }
1091 memset(lynq_call_lists,0,sizeof(lynq_call_lists));
q.huang68ee8a02022-06-28 20:12:01 +08001092
1093 lynq_init_rtp();
1094
lh25827952022-01-10 00:34:35 -08001095 LYDBGLOG("lynq init call success!!!");
1096 return 0;
1097}
1098int lynq_deinit_call()
1099{
q.huangf8461432022-06-02 14:49:02 +08001100 int ret;
ll1343a5b2022-03-17 05:31:33 +00001101 if(g_lynq_call_init_flag == 0)
lhcdf816a2022-02-13 23:56:05 -08001102 {
ll1343a5b2022-03-17 05:31:33 +00001103 LYDBGLOG("lynq_deinit_call failed!!!");
1104 return -1;
lhcdf816a2022-02-13 23:56:05 -08001105 }
ll1343a5b2022-03-17 05:31:33 +00001106 else
ll00a10dd2022-07-13 09:39:44 +00001107 {
ll1343a5b2022-03-17 05:31:33 +00001108 g_lynq_call_init_flag = 0;
q.huangf8461432022-06-02 14:49:02 +08001109 lynq_call_hungup_all();
ll1343a5b2022-03-17 05:31:33 +00001110 if(lynq_call_client_sockfd>0)
1111 {
1112 close(lynq_call_client_sockfd);
1113 }
1114 urc_call_recive_status = 0;
1115 call_list_loop = 0;
q.huang68ee8a02022-06-28 20:12:01 +08001116 lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
ll1343a5b2022-03-17 05:31:33 +00001117 if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
1118 {
1119 return -1;
1120 }
1121 ret = pthread_cancel(lynq_call_urc_tid);
1122 LYDBGLOG("pthread cancel ret = %d",ret);
1123 ret = pthread_cancel(lynq_call_list_loop_tid);
1124 LYDBGLOG("pthread cancel ret = %d",ret);
1125 ret = pthread_join(lynq_call_urc_tid,NULL);
1126 LYDBGLOG("pthread join ret = %d",ret);
1127 ret = pthread_join(lynq_call_list_loop_tid,NULL);
1128 LYDBGLOG("pthread join ret = %d",ret);
ll00a10dd2022-07-13 09:39:44 +00001129 pthread_mutex_destroy(s_urc_call_state_change_mutex);
1130 pthread_cond_destroy(s_urc_call_state_change_cond);
1131 delete s_urc_call_state_change_mutex;
1132 //s_urc_call_state_change_mutex = NULL;
1133 delete s_urc_call_state_change_cond;
1134 //s_urc_call_state_change_cond = NULL;
1135
ll1343a5b2022-03-17 05:31:33 +00001136 return 0;
1137 }
ll83081992022-04-11 05:49:51 +00001138}
q.huang5a738c02022-04-18 00:09:50 -04001139
1140int lynq_set_common_request(int request_id, int argc, const char* format,...)
rita9b436d82022-04-07 01:55:39 -04001141{
1142 Parcel p;
1143 lynq_client_t client;
1144 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001145 int token;
rita9b436d82022-04-07 01:55:39 -04001146 int request = -1;
1147 int slot_id = -1;
1148 int error = -1;
rita9b436d82022-04-07 01:55:39 -04001149
1150 client.uToken = Global_uToken_call;
q.huang5a738c02022-04-18 00:09:50 -04001151 client.request = request_id;
1152 client.paramLen = argc;
rita9b436d82022-04-07 01:55:39 -04001153 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huang5a738c02022-04-18 00:09:50 -04001154 if(argc!=0)
1155 {
1156 va_list args;
1157 va_start(args, format);
1158 vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
1159 va_end(args);
1160 }
q.huangf8461432022-06-02 14:49:02 +08001161 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -04001162 if(send_request(lynq_call_client_sockfd,&client)==-1)
1163 {
1164 LYERRLOG("send request fail");
1165 return -1;
1166 }
q.huang5a738c02022-04-18 00:09:50 -04001167 if(get_response(lynq_call_client_sockfd,p)==0)
1168 {
q.huang2befc3a2022-09-13 14:19:24 +08001169 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang5a738c02022-04-18 00:09:50 -04001170 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1171 }
rita9b436d82022-04-07 01:55:39 -04001172 return error;
1173}
1174
q.huang5a738c02022-04-18 00:09:50 -04001175int lynq_get_common_request(int request_id, int* status)
rita9b436d82022-04-07 01:55:39 -04001176{
1177 Parcel p;
1178 lynq_client_t client;
1179 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001180 int token;
rita9b436d82022-04-07 01:55:39 -04001181 int request = -1;
1182 int slot_id = -1;
1183 int error = -1;
q.huang5a738c02022-04-18 00:09:50 -04001184 if(status==NULL)
1185 {
1186 LYERRLOG("status is null");
1187 return -1;
1188 }
rita9b436d82022-04-07 01:55:39 -04001189 client.uToken = Global_uToken_call;
q.huang5a738c02022-04-18 00:09:50 -04001190 client.request = request_id;
1191 client.paramLen = 0;
rita9b436d82022-04-07 01:55:39 -04001192 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangf8461432022-06-02 14:49:02 +08001193 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rita9b436d82022-04-07 01:55:39 -04001194 if(send_request(lynq_call_client_sockfd,&client)==-1)
1195 {
1196 LYERRLOG("send request fail");
1197 return -1;
1198 }
q.huang5a738c02022-04-18 00:09:50 -04001199 if(get_response(lynq_call_client_sockfd,p)==0)
rita9b436d82022-04-07 01:55:39 -04001200 {
q.huang2befc3a2022-09-13 14:19:24 +08001201 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
q.huang5a738c02022-04-18 00:09:50 -04001202 p.readInt32(status);
1203 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
rita9b436d82022-04-07 01:55:39 -04001204 }
rita9b436d82022-04-07 01:55:39 -04001205 return error;
1206}
1207
lh25827952022-01-10 00:34:35 -08001208int lynq_call(int* handle,char addr[])
1209{
ll3783e142022-08-10 00:33:52 -07001210 if(g_lynq_call_init_flag == 0)
1211 {
1212 return -1;
1213 }
lh25827952022-01-10 00:34:35 -08001214 Parcel p;
1215 lynq_client_t client;
1216 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001217 int token;
lh25827952022-01-10 00:34:35 -08001218 int request = -1;
1219 int slot_id = -1;
1220 int error = -1;
1221 int lynq_call_id = -1;
q.huangf8461432022-06-02 14:49:02 +08001222
1223 LYINFLOG("lynq_call begin addr %s",addr);
lh25827952022-01-10 00:34:35 -08001224 if(addr==NULL)
1225 {
1226 LYERRLOG("Phone num is null!!!");
1227 return -1;
1228 }
q.huangf8461432022-06-02 14:49:02 +08001229
1230 if(find_call_id_with_addr(addr)!=INVALID_ID)
1231 {
1232 LYERRLOG("addr %s exists",addr);
1233 return LYNQ_E_CONFLICT;
1234 }
1235
1236#ifdef ECALL_SUPPORT
1237 if(lynq_ecall_is_running())
1238 {
1239 LYERRLOG("lynq_fast_ecall ecall is running");
1240 return LYNQ_E_ECALL_BEING_RUNNING;
1241 }
1242#endif
1243
lha35d4ee2022-01-25 18:47:39 -08001244 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001245 client.request = 10;//RIL_REQUEST_DIAL
1246 client.paramLen = 2;
1247 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1248 memcpy(client.param,addr,strlen(addr)+1);
1249 strcat(client.param," 0");
q.huangf8461432022-06-02 14:49:02 +08001250 lynq_call_id = addAddr(addr);
1251 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001252 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
lha35d4ee2022-01-25 18:47:39 -08001253 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001254 {
1255 LYERRLOG("send request fail");
q.huangf8461432022-06-02 14:49:02 +08001256 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001257 return -1;
1258 }
lha35d4ee2022-01-25 18:47:39 -08001259 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001260 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001261 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh25827952022-01-10 00:34:35 -08001262 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lh25827952022-01-10 00:34:35 -08001263 if(error==0)
1264 {
1265 isDial = 1;
ll45d3ea92022-03-24 10:22:25 +08001266 if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
lh25827952022-01-10 00:34:35 -08001267 {
lh5095be72022-04-19 06:01:25 -07001268 //if timeout,this call need destroy.
1269 isDial = 0;
lh25827952022-01-10 00:34:35 -08001270 error = LYNQ_E_TIME_OUT;
q.huangf8461432022-06-02 14:49:02 +08001271 LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
1272 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001273 return error;
1274 }
q.huangf8461432022-06-02 14:49:02 +08001275 isDial = 0;
1276 *handle = lynq_call_lists[lynq_call_id].call_id;
1277 if(*handle > 0)
1278 {
1279 LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
1280 return 0;
1281 }
1282 else
1283 {
1284 LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
1285 cleanCallList(lynq_call_id);
1286 return LYNQ_E_INVALID_ID_ANONALY;
1287 }
1288
lh25827952022-01-10 00:34:35 -08001289 }
q.huangf8461432022-06-02 14:49:02 +08001290 LYERRLOG("lynq_call dial addr %s fail, service error %d",addr, error);
1291 cleanCallList(lynq_call_id);
lh25827952022-01-10 00:34:35 -08001292 return error;
1293}
1294int lynq_call_answer()
1295{
ll3783e142022-08-10 00:33:52 -07001296 if(g_lynq_call_init_flag == 0)
1297 {
1298 return -1;
1299 }
lh25827952022-01-10 00:34:35 -08001300 Parcel p;
1301 lynq_client_t client;
1302 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001303 int token;
1304 int request = -1;
1305 int slot_id = -1;
lh25827952022-01-10 00:34:35 -08001306 int error = -1;
lha35d4ee2022-01-25 18:47:39 -08001307 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001308 client.request = 40;//RIL_REQUEST_DIAL
1309 client.paramLen = 0;
1310 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangf8461432022-06-02 14:49:02 +08001311 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001312 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
lha35d4ee2022-01-25 18:47:39 -08001313 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001314 {
1315 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001316 return -1;
1317 }
lha35d4ee2022-01-25 18:47:39 -08001318 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001319 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001320 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh25827952022-01-10 00:34:35 -08001321 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1322 return error;
1323}
1324int lynq_call_hungup(int* handle)
1325{
ll3783e142022-08-10 00:33:52 -07001326 if(g_lynq_call_init_flag == 0)
1327 {
1328 return -1;
1329 }
lh25827952022-01-10 00:34:35 -08001330 Parcel p;
1331 lynq_client_t client;
1332 int resp_type = -1;
1333 int request = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001334 int token;
lh25827952022-01-10 00:34:35 -08001335 int slot_id = -1;
1336 int error = -1;
1337 int call_id = 0;
q.huangf8461432022-06-02 14:49:02 +08001338 int lynq_call_id;
lha35d4ee2022-01-25 18:47:39 -08001339 if(handle==NULL||!((*handle>=0)&&(*handle<10)))
1340 {
1341 LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
1342 return LYNQ_E_CONFLICT;
1343 }
1344 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001345 client.request = 12;//RIL_REQUEST_HUNGUP
1346 client.paramLen = 1;
1347 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangf8461432022-06-02 14:49:02 +08001348 call_id = *handle;
lh25827952022-01-10 00:34:35 -08001349 sprintf(client.param,"%d",call_id);
q.huangf8461432022-06-02 14:49:02 +08001350 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001351 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
lha35d4ee2022-01-25 18:47:39 -08001352 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001353 {
1354 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001355 return -1;
1356 }
lha35d4ee2022-01-25 18:47:39 -08001357 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001358 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001359 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh25827952022-01-10 00:34:35 -08001360 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1361 if(error==0)
1362 {
q.huangf8461432022-06-02 14:49:02 +08001363 lynq_call_id=find_call_id_with_call_id(call_id);
1364 if(lynq_call_id!=INVALID_ID)
1365 {
1366 cleanCallList(lynq_call_id);
1367 }
lh25827952022-01-10 00:34:35 -08001368 }
1369 return error;
1370}
1371int lynq_call_hungup_all()
1372{
ll3783e142022-08-10 00:33:52 -07001373 if(g_lynq_call_init_flag == 0)
1374 {
1375 return -1;
1376 }
lh25827952022-01-10 00:34:35 -08001377 Parcel p;
1378 lynq_client_t client;
1379 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001380 int token=-1;
lh25827952022-01-10 00:34:35 -08001381 int request = -1;
1382 int slot_id = -1;
1383 int error = -1;
lha35d4ee2022-01-25 18:47:39 -08001384 client.uToken = Global_uToken_call;
lh25827952022-01-10 00:34:35 -08001385 client.request = 17;//RIL_REQUEST_UDUB
1386 client.paramLen = 0;
1387 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
q.huangf8461432022-06-02 14:49:02 +08001388 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001389 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
lha35d4ee2022-01-25 18:47:39 -08001390 if(send_request(lynq_call_client_sockfd,&client)==-1)
lh25827952022-01-10 00:34:35 -08001391 {
1392 LYERRLOG("send request fail");
lh25827952022-01-10 00:34:35 -08001393 return -1;
1394 }
lha35d4ee2022-01-25 18:47:39 -08001395 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001396 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001397 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lh25827952022-01-10 00:34:35 -08001398 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1399 return error;
1400}
1401int lynq_wait_incoming_call(int *handle)
1402{
ll3783e142022-08-10 00:33:52 -07001403 if(g_lynq_call_init_flag == 0)
1404 {
1405 return -1;
1406 }
lh25827952022-01-10 00:34:35 -08001407 waitIncomingCall();
1408 *handle = lynqIncomingCallId;
1409 LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
1410 return 0;
1411}
1412
1413int lynq_set_auto_answercall(const int mode)
1414{
ll3783e142022-08-10 00:33:52 -07001415 if(g_lynq_call_init_flag == 0)
1416 {
1417 return -1;
1418 }
lh25827952022-01-10 00:34:35 -08001419 global_call_auto_answer = mode;
1420 LYINFLOG("auto answer call mode =%d",mode);
1421 return 0;
1422}
q.huangb0eb7b02022-03-29 04:17:32 -04001423int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
1424{
ll3783e142022-08-10 00:33:52 -07001425 if(g_lynq_call_init_flag == 0)
1426 {
1427 return -1;
1428 }
q.huangb0eb7b02022-03-29 04:17:32 -04001429 int lynq_call_id = 0;
q.huangf8461432022-06-02 14:49:02 +08001430 LYINFLOG("lynq_get_current_call_state begin ");
q.huangb0eb7b02022-03-29 04:17:32 -04001431 if(handle==NULL)
1432 {
q.huangf8461432022-06-02 14:49:02 +08001433 LYERRLOG("handle is NULL");
q.huangb0eb7b02022-03-29 04:17:32 -04001434 return LYNQ_E_NULL_ANONALY;
1435 }
q.huangf8461432022-06-02 14:49:02 +08001436 lynq_call_id = find_call_id_with_call_id(*handle);
1437 if(lynq_call_id==INVALID_ID)
1438 {
1439 return LYNQ_E_INVALID_ID_ANONALY;
1440 }
q.huangb0eb7b02022-03-29 04:17:32 -04001441 *call_state = lynq_call_lists[lynq_call_id].call_state;
1442 *toa = lynq_call_lists[lynq_call_id].toa;
1443 *direction = lynq_call_lists[lynq_call_id].direction;
1444 memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
1445 return 0;
1446}
1447
q.huange0024b02022-08-29 20:04:31 +08001448int lynq_get_current_call_number()
1449{
1450 int cnt=0;
1451 int i;
1452 for(i = 0;i < LYNQ_CALL_MAX;i++)
1453 {
1454 if(lynq_call_lists[i].used !=0)
1455 {
1456 cnt++;
1457 }
1458 }
1459
1460 return cnt;
1461}
1462
q.huangb0eb7b02022-03-29 04:17:32 -04001463/*audio begin*/
ll7e055f22022-01-24 12:16:22 +00001464static int judge_mic(const int enable){
llc6030062022-02-14 08:58:16 +00001465 switch(enable){
1466 case 0:
1467 return 1;
1468 case 1:
1469 return 1;
1470 default:
1471 return 0;
ll7e055f22022-01-24 12:16:22 +00001472 }
1473}
1474
lh25827952022-01-10 00:34:35 -08001475int lynq_set_mute_mic(const int enable)
ll7e055f22022-01-24 12:16:22 +00001476{
ll3783e142022-08-10 00:33:52 -07001477 if(g_lynq_call_init_flag == 0)
1478 {
1479 return -1;
1480 }
ll7e055f22022-01-24 12:16:22 +00001481 if(!judge_mic(enable)){
1482 return LYNQ_E_CONFLICT;
1483 }
q.huangb0eb7b02022-03-29 04:17:32 -04001484 return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
1485}
1486int lynq_get_mute_mic(int *status)
1487{
ll3783e142022-08-10 00:33:52 -07001488 if(g_lynq_call_init_flag == 0)
1489 {
1490 return -1;
1491 }
q.huangb0eb7b02022-03-29 04:17:32 -04001492 return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
lh25827952022-01-10 00:34:35 -08001493}
ll45d3ea92022-03-24 10:22:25 +08001494
1495/**
1496 * @brief Check whether DTMF is valid
1497 *
1498 * @param callnum dtmf eg:0-9 * #
1499 * @return int
1500 */
1501static int judge_dtmf(const char callnum)
1502{
1503 if(callnum == '#')
1504 {
1505 return 1;
1506 }
1507 if(callnum == '*')
1508 {
1509 return 1;
1510 }
1511 if(callnum >= '0'&& callnum <= '9')
1512 {
1513 return 1;
1514 }
1515 return 0;
1516}
1517
llf79dc4d2022-07-20 09:30:19 +00001518int lynq_switch_waiting_or_holding_and_active(void)
1519{
ll3783e142022-08-10 00:33:52 -07001520 if(g_lynq_call_init_flag == 0)
1521 {
1522 return -1;
1523 }
llf79dc4d2022-07-20 09:30:19 +00001524 Parcel p;
1525 lynq_client_t client;
1526 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001527 int token;
llf79dc4d2022-07-20 09:30:19 +00001528 int request = -1;
1529 int slot_id = -1;
1530 int error = -1;
1531 client.uToken = Global_uToken_call;
1532 client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
1533 client.paramLen = 0;
1534 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1535 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001536 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-07-20 09:30:19 +00001537 if(send_request(lynq_call_client_sockfd,&client)==-1)
1538 {
1539 LYERRLOG("send request fail");
1540 return -1;
1541 }
1542 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001543 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001544 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-07-20 09:30:19 +00001545 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1546 return error;
1547}
1548
1549int lynq_hangup_waiting_or_background(void)
1550{
ll3783e142022-08-10 00:33:52 -07001551 if(g_lynq_call_init_flag == 0)
1552 {
1553 return -1;
1554 }
llf79dc4d2022-07-20 09:30:19 +00001555 Parcel p;
1556 lynq_client_t client;
1557 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001558 int token;
llf79dc4d2022-07-20 09:30:19 +00001559 int request = -1;
1560 int slot_id = -1;
1561 int error = -1;
1562 client.uToken = Global_uToken_call;
1563 client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
1564 client.paramLen = 0;
1565 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1566 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001567 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-07-20 09:30:19 +00001568 if(send_request(lynq_call_client_sockfd,&client)==-1)
1569 {
1570 LYERRLOG("send request fail");
1571 return -1;
1572 }
1573 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001574 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001575 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-07-20 09:30:19 +00001576 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1577 return error;
1578}
1579
1580int lynq_hangup_foreground_resume_background(void)
1581{
ll3783e142022-08-10 00:33:52 -07001582 if(g_lynq_call_init_flag == 0)
1583 {
1584 return -1;
1585 }
llf79dc4d2022-07-20 09:30:19 +00001586 Parcel p;
1587 lynq_client_t client;
1588 int resp_type = -1;
q.huang2befc3a2022-09-13 14:19:24 +08001589 int token;
llf79dc4d2022-07-20 09:30:19 +00001590 int request = -1;
1591 int slot_id = -1;
1592 int error = -1;
1593 client.uToken = Global_uToken_call;
1594 client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
1595 client.paramLen = 0;
1596 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1597 LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
ll78948a22022-07-25 05:52:14 +00001598 pthread_mutex_lock(&g_lynq_call_sendto_mutex);
llf79dc4d2022-07-20 09:30:19 +00001599 if(send_request(lynq_call_client_sockfd,&client)==-1)
1600 {
1601 LYERRLOG("send request fail");
1602 return -1;
1603 }
1604 get_response(lynq_call_client_sockfd,p);
ll78948a22022-07-25 05:52:14 +00001605 pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
q.huang2befc3a2022-09-13 14:19:24 +08001606 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
llf79dc4d2022-07-20 09:30:19 +00001607 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1608 return error;
1609}
1610
lh25827952022-01-10 00:34:35 -08001611int lynq_set_DTMF(const char callnum)
1612{
ll3783e142022-08-10 00:33:52 -07001613 if(g_lynq_call_init_flag == 0)
1614 {
1615 return -1;
1616 }
ll45d3ea92022-03-24 10:22:25 +08001617 if(!judge_dtmf(callnum))
1618 {
1619 return LYNQ_E_CONFLICT;
1620 }
lh25827952022-01-10 00:34:35 -08001621 if(!lynq_call_state)
1622 {
1623 LYERRLOG("LYNQ_E_CONFLICT");
1624 return LYNQ_E_CONFLICT;
1625 }
q.huangb0eb7b02022-03-29 04:17:32 -04001626 return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
lh25827952022-01-10 00:34:35 -08001627}
q.huangb0eb7b02022-03-29 04:17:32 -04001628static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
1629 if(set==LYNQ_E_VOLUMN_SET_DTMF){
1630 if(volume < 0 ||volume >36){
1631 return 0;
1632 }
1633 }
1634 else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
1635 {
1636 if(volume < 1 ||volume >7){
1637 return 0;
1638 }
ll7e055f22022-01-24 12:16:22 +00001639 }
ll375c94d2022-01-27 05:54:38 +00001640 return 1;
ll7e055f22022-01-24 12:16:22 +00001641}
lh25827952022-01-10 00:34:35 -08001642int lynq_set_DTMF_volume(const int volume)
ll7e055f22022-01-24 12:16:22 +00001643{
q.huangb0eb7b02022-03-29 04:17:32 -04001644 if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
ll7e055f22022-01-24 12:16:22 +00001645 return LYNQ_E_CONFLICT;
1646 }
q.huangb0eb7b02022-03-29 04:17:32 -04001647 return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
lh25827952022-01-10 00:34:35 -08001648}
q.huang9ee6d5b2022-04-05 23:11:02 -04001649int lynq_set_speech_volume(const int volume)//mixer_set_volume
lh25827952022-01-10 00:34:35 -08001650{
q.huangb0eb7b02022-03-29 04:17:32 -04001651 if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
lh25827952022-01-10 00:34:35 -08001652 {
q.huangb0eb7b02022-03-29 04:17:32 -04001653 return LYNQ_E_CONFLICT;
lh25827952022-01-10 00:34:35 -08001654 }
q.huangb0eb7b02022-03-29 04:17:32 -04001655 return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
lh25827952022-01-10 00:34:35 -08001656}
q.huangb0eb7b02022-03-29 04:17:32 -04001657int lynq_get_speech_volume(int* volumn)//mixer_get_volume
1658{
1659 return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
1660}
q.huang9ee6d5b2022-04-05 23:11:02 -04001661int lynq_incall_record_start(const char* file_path)
q.huangb0eb7b02022-03-29 04:17:32 -04001662{
q.huangf8461432022-06-02 14:49:02 +08001663 return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
q.huangb0eb7b02022-03-29 04:17:32 -04001664}
1665int lynq_incall_record_stop()
1666{
q.huang9ee6d5b2022-04-05 23:11:02 -04001667 const char* unused_file="just_ocuupy_paramter_postion";
1668 return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
q.huangb0eb7b02022-03-29 04:17:32 -04001669}
1670/*audio end*/
q.huang5a738c02022-04-18 00:09:50 -04001671
1672#ifdef ECALL_SUPPORT
1673LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
1674{
1675 switch(type)
1676 {
1677 case LYNQ_ECALL_TYPE_TEST:
1678 return LYNQ_ECALL_TEST;
1679 case LYNQ_ECALL_TYPE_RECONFIG:
1680 return LYNQ_ECALL_RECONFIG;
1681 default:
1682 return LYNQ_ECALL_EMERGENCY;
1683 }
1684}
1685
1686RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
1687{
1688 switch(type)
1689 {
1690 case LYNQ_ECALL_TEST:
1691 return ECALL_TEST;
1692 case LYNQ_ECALL_RECONFIG:
1693 return ECALL_RECONFIG;
1694 default:
1695 return ECALL_EMERGENCY;
1696 }
1697}
1698
1699RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
1700{
1701 switch(cat)
1702 {
1703 case LYNQ_EMER_CAT_MANUAL_ECALL:
1704 return EMER_CAT_MANUAL_ECALL;
1705 default:
1706 return EMER_CAT_AUTO_ECALL;
1707 }
1708}
1709
1710
1711int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
1712{
1713 int error;
1714
1715 if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
1716 {
q.huangf8461432022-06-02 14:49:02 +08001717 LYERRLOG("test_num is null or test_num_length %d s greater than %d ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
q.huang5a738c02022-04-18 00:09:50 -04001718 return -1;
1719 }
1720
1721 error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
1722
1723 if(error==0)
1724 {
1725 snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
1726 }
1727
1728 return error;
1729}
1730
q.huange0024b02022-08-29 20:04:31 +08001731int lynq_ecall_can_be_preempted(LYNQ_ECall_Variant old_variant,LYNQ_ECall_Variant new_variant)
1732{
1733 int ret;
1734
1735 if(old_variant == LYNQ_ECALL_EMERGENCY)
1736 {
1737 return false;
1738 }
1739 else if(new_variant == LYNQ_ECALL_EMERGENCY)
1740 {
1741 return true;
1742 }
1743 else if(old_variant==LYNQ_ECALL_DAILING_STATE_NONE)
1744 {
1745 return true;
1746 }
1747 else
1748 {
1749 ret = (g_ecall_whether_preempt & 0x01);
1750 }
1751 LYINFLOG("ecall clear conflict call, lynq_ecall_can_be_preempted is true");
1752 return ret;
1753}
1754
1755int lynq_clear_current_call()
1756{
1757 int cnt;
1758 if(lynq_call_hungup_all()!=0)
1759 {
1760 LYERRLOG("ecall clear conflict call, hangup all failure");
1761 return -1;
1762 }
1763 cnt=0;
1764 while(lynq_get_current_call_number()!=0 && cnt<80)
1765 {
1766 lynqRespWatingEvent();
1767 usleep(200 * 1000);//200ms
1768 cnt++;
1769 }
1770 if(lynq_get_current_call_number()!=0)
1771 {
1772 LYERRLOG("ecall clear conflict call, current call list can't cleared after 15s");
1773 return -2;
1774 }
1775
1776 LYINFLOG("ecall clear conflict call, after %d 0.2s, call list is cleared", cnt);
1777 return 0;
1778}
1779
1780int lynq_clear_current_conflict_call(LYNQ_ECall_Variant old_variant,LYNQ_ECall_Variant new_variant)
1781{
1782 int cnt;
1783 int ret;
1784
1785 if(lynq_ecall_is_running()==false)
1786 {
1787 if(lynq_get_current_call_number()==0)
1788 {
1789 LYINFLOG("ecall clear conflict call, no conflict ecall and normal call");
1790 }
1791 else if(g_ecall_whether_preempt & 0x02)
1792 {
1793 ret=lynq_clear_current_call();
1794 LYERRLOG("ecall clear conflict call, relase current normal call ret is %d",ret);
1795 }
1796 return 0;
1797 }
1798
1799 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,g_ecall_whether_preempt);
1800
1801 if(lynq_ecall_can_be_preempted(old_variant,new_variant)==false)
1802 {
1803 LYERRLOG("ecall clear conflict call, new ecall %d can't preempt old ecall %d",new_variant,old_variant);
1804 return -1;
1805 }
1806
1807 ret=lynq_clear_current_call();
1808 LYINFLOG("ecall clear conflict call, relase current call(including ecall) ret is %d",ret);
1809
1810 if(is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
1811 {
1812 sendSignalToWaitCallStateChange();
1813 LYINFLOG("ecall clear conflict call, stop ecall in dailing status");
1814 }
1815
1816 cnt=0;
1817 while(lynq_ecall_is_running() && cnt<80)
1818 {
1819 usleep(200 * 1000);//200ms
1820 cnt++;
1821 }
1822
1823 if(lynq_ecall_is_running())
1824 {
1825 LYERRLOG("ecall clear conflict call, after 16s, lynq ecall is still running");
1826 }
1827 else
1828 {
1829 LYINFLOG("ecall clear conflict call, after %d 0.2s, ecall info is cleared", cnt);
1830 }
1831
1832 sleep(3);// for ecall disconnect
1833 print_ecall_info();
1834 return 0;
1835}
1836
q.huangb3037c12022-05-10 20:37:21 +08001837int 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)
q.huang5a738c02022-04-18 00:09:50 -04001838{
q.huangf8461432022-06-02 14:49:02 +08001839 int error;
q.huang5a738c02022-04-18 00:09:50 -04001840 RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
q.huang36fb9a02022-04-19 05:20:12 -04001841 RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
q.huang1dd31c52022-05-11 20:10:38 +08001842 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
q.huange0024b02022-08-29 20:04:31 +08001843 unsigned int i;
1844
1845 if(msd_length > MSD_MAX_LENGTH || msd_length <=0 || lynq_ecall_variant >=LYNQ_ECALL_MO_MAX)
q.huangb3037c12022-05-10 20:37:21 +08001846 {
q.huange0024b02022-08-29 20:04:31 +08001847 LYERRLOG("lynq_fast_ecall msd_length %d or ecall variant %d parameter error",msd_length,lynq_ecall_variant);
q.huangf8461432022-06-02 14:49:02 +08001848 return LYNQ_E_ECALL_MSD_LENGTH_ERROR;
q.huange0024b02022-08-29 20:04:31 +08001849 }
1850
1851 if(lynq_clear_current_conflict_call(g_lynqEcallVariant,lynq_ecall_variant)!=0)
1852 {
1853 LYERRLOG("%s call lynq_clear_current_conflict_call false, old is %d, new is %d",__func__,g_lynqEcallVariant,lynq_ecall_variant);
1854 return LYNQ_E_ECALL_BEING_RUNNING;
1855 }
1856
1857 pthread_mutex_lock(&s_ecall_variable_mutex);
1858 is_ecall_dial = LYNQ_ECALL_DAILING_STATE_STARTED;
1859 g_lynqEcallVariant = lynq_ecall_variant;
1860 g_ecallId = INVALID_ID;
1861 pthread_mutex_unlock(&s_ecall_variable_mutex);
q.huangb3037c12022-05-10 20:37:21 +08001862
q.huang1dd31c52022-05-11 20:10:38 +08001863 for(i =0; i<msd_length;i++)
q.huangb3037c12022-05-10 20:37:21 +08001864 {
q.huang1dd31c52022-05-11 20:10:38 +08001865 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
q.huangb3037c12022-05-10 20:37:21 +08001866 }
1867
q.huangaa75aa62022-04-19 20:27:44 -04001868
q.huangf8461432022-06-02 14:49:02 +08001869 LYINFLOG("lynq_fast_ecall addr is %s",e_call_addr[lynq_ecall_variant]);
q.huangaa75aa62022-04-19 20:27:44 -04001870
q.huangb3037c12022-05-10 20:37:21 +08001871 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);
q.huang5a738c02022-04-18 00:09:50 -04001872
1873 if(error==0)
q.huangf8461432022-06-02 14:49:02 +08001874 {
q.huangc046fcd2022-07-01 11:38:26 +08001875 if(waitCallstateChange(270000)==ETIMEDOUT)//4.5 min, dailing 1 min, alerting 1 min, sending msd 30s, redial 2min
q.huang5a738c02022-04-18 00:09:50 -04001876 {
q.huange0024b02022-08-29 20:04:31 +08001877 pthread_mutex_lock(&s_ecall_variable_mutex);
1878 LYERRLOG("lynq_fast_ecall timeout:wait Call state time out!!!");
1879 is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
1880 lynqRespWatingEvent();
1881 pthread_mutex_unlock(&s_ecall_variable_mutex);
q.huangf8461432022-06-02 14:49:02 +08001882 return LYNQ_E_TIME_OUT;
q.huang5a738c02022-04-18 00:09:50 -04001883 }
q.huange0024b02022-08-29 20:04:31 +08001884 pthread_mutex_lock(&s_ecall_variable_mutex);
q.huang4bb7b0a2022-06-21 14:57:02 +08001885 if(is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)
1886 {
1887 /*just dail, no recv answer*/
1888 LYERRLOG("lynq_fast_ecall, no answer!");
1889 is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
q.huange0024b02022-08-29 20:04:31 +08001890 lynqRespWatingEvent();
1891 pthread_mutex_unlock(&s_ecall_variable_mutex);
q.huang4bb7b0a2022-06-21 14:57:02 +08001892 return LYNQ_E_ECALL_DAILING_NO_ANSWER;
1893 }
1894
1895 is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
q.huangf8461432022-06-02 14:49:02 +08001896 lynqRespWatingEvent();
q.huangaa75aa62022-04-19 20:27:44 -04001897
q.huangf8461432022-06-02 14:49:02 +08001898 if(g_ecallId != INVALID_ID)
1899 {
1900 *handle=g_ecallId;
1901 LYINFLOG("lynq_fast_ecall id is %d",g_ecallId);
q.huange0024b02022-08-29 20:04:31 +08001902 pthread_mutex_unlock(&s_ecall_variable_mutex);
q.huangf8461432022-06-02 14:49:02 +08001903 return 0;
1904 }
q.huange0024b02022-08-29 20:04:31 +08001905
1906 LYERRLOG("lynq_fast_ecall service return fail");
1907 pthread_mutex_unlock(&s_ecall_variable_mutex);
1908 return LYNQ_E_INVALID_ID_ANONALY;
q.huang5a738c02022-04-18 00:09:50 -04001909 }
1910
q.huange0024b02022-08-29 20:04:31 +08001911 pthread_mutex_lock(&s_ecall_variable_mutex);
1912 is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
1913 g_lynqEcallVariant = LYNQ_ECALL_VAR_NONE;
1914 g_ecallId = INVALID_ID;
1915 pthread_mutex_unlock(&s_ecall_variable_mutex);
1916
q.huang5a738c02022-04-18 00:09:50 -04001917 return error;
1918}
1919
1920int lynq_set_psap(int enable)
1921{
1922 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
1923}
1924
1925int lynq_psap_pull_msd()
1926{
1927 return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
1928}
1929
1930int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
1931{
1932 LYNQ_ECall_Variant lynq_ecall_variant;
1933 int error = -1;
1934 int lynq_call_id = -1;
1935
1936 if(handle==NULL)
1937 {
q.huangf8461432022-06-02 14:49:02 +08001938 LYERRLOG("handle is NULL, parameter error ");
q.huang5a738c02022-04-18 00:09:50 -04001939 return -1;
1940 }
1941
1942 error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
1943
1944 if(error==0)
1945 {
1946 lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
1947
q.huangf8461432022-06-02 14:49:02 +08001948 lynq_call_id = addAddr(e_call_addr[lynq_ecall_variant]);
q.huang5a738c02022-04-18 00:09:50 -04001949 isDial = 1;
1950 if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
1951 {
1952 error = LYNQ_E_TIME_OUT;
1953 LYERRLOG("timeout:wait Call state fail!!!");
q.huang5a738c02022-04-18 00:09:50 -04001954 return error;
1955 }
1956
1957 *handle = lynq_call_id;
1958 }
1959
1960 return error;
1961}
1962
1963
q.huang6254d382022-05-10 20:49:46 +08001964int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length)
q.huang5a738c02022-04-18 00:09:50 -04001965{
q.huang1dd31c52022-05-11 20:10:38 +08001966 char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
1967 unsigned int i;
1968
q.huange0024b02022-08-29 20:04:31 +08001969 if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX) || msd_length > MSD_MAX_LENGTH || msd_length <= 0 || msd_data ==NULL)
q.huang5a738c02022-04-18 00:09:50 -04001970 {
q.huangf8461432022-06-02 14:49:02 +08001971 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);
q.huang6254d382022-05-10 20:49:46 +08001972 return -1;
1973 }
q.huang6254d382022-05-10 20:49:46 +08001974
q.huang1dd31c52022-05-11 20:10:38 +08001975 for(i=0; i<msd_length;i++)
q.huang6254d382022-05-10 20:49:46 +08001976 {
q.huang1dd31c52022-05-11 20:10:38 +08001977 sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
q.huangf8461432022-06-02 14:49:02 +08001978 }
1979
1980 LYINFLOG("lynq_set_msd ");
q.huang5a738c02022-04-18 00:09:50 -04001981
q.huange0024b02022-08-29 20:04:31 +08001982 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",*handle,lynq_msd_data);
q.huang5a738c02022-04-18 00:09:50 -04001983}
1984
1985int lynq_set_ivs(int enable)
1986{
q.huange0024b02022-08-29 20:04:31 +08001987#ifdef ECALL_SUPPORT
q.huangf8461432022-06-02 14:49:02 +08001988 if(enable<0)
1989 {
q.huange0024b02022-08-29 20:04:31 +08001990 if(enable >-100)
1991 {
1992 lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
1993 }
1994 else if(enable== -1000)
1995 {
1996 print_ecall_info();
1997 }
1998 else
1999 {
2000 g_ecall_whether_preempt= ((-100-enable) & 0x11);
2001 }
q.huangf8461432022-06-02 14:49:02 +08002002 return 0;
2003 }
q.huange0024b02022-08-29 20:04:31 +08002004#endif
q.huangf8461432022-06-02 14:49:02 +08002005
2006 return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
q.huang5a738c02022-04-18 00:09:50 -04002007}
2008
2009int lynq_reset_ivs()
2010{
2011 return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
2012}
2013
2014int lynq_ivs_push_msd()
2015{
2016 return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
2017}
q.huangaa75aa62022-04-19 20:27:44 -04002018
2019int wait_ecall_event()
2020{
2021 int ret = 0;
2022 pthread_mutex_lock(&s_incoming_e_call_mutex);
2023 ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
q.huangf8461432022-06-02 14:49:02 +08002024 pthread_mutex_unlock(&s_incoming_e_call_mutex);
q.huangaa75aa62022-04-19 20:27:44 -04002025 return ret;
2026}
2027
q.huang64bcb3c2022-06-30 19:39:20 +08002028int lynq_wait_ecall_indication(int* handle, LYNQ_ECall_Indication *eCall_Indication)
q.huangaa75aa62022-04-19 20:27:44 -04002029{
2030 wait_ecall_event();
q.huang64bcb3c2022-06-30 19:39:20 +08002031 *handle = g_lynqIncomingEcallId;
q.huang4bb7b0a2022-06-21 14:57:02 +08002032 *eCall_Indication = g_lynqIncomingEcallIndication;
q.huang64bcb3c2022-06-30 19:39:20 +08002033 LYINFLOG("lynq_wait_ecall_indication handle %d, Ind id: %d", *handle, *eCall_Indication);
q.huangaa75aa62022-04-19 20:27:44 -04002034 return 0;
2035}
2036
q.huang5a738c02022-04-18 00:09:50 -04002037#endif
2038
q.huangdf857562022-06-06 16:15:31 +08002039/*Audio Path setting begin*/
q.huang68ee8a02022-06-28 20:12:01 +08002040/*sub function*/
2041void lynq_set_rtp_mixer_ctrl(int enable_rtp)
2042{
2043 char cmd[256];
2044 LYINFLOG("set_rtp_mixer_ctrl %d", enable_rtp);
2045 if(enable_rtp)
2046 {
2047 sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 0);
2048 system(cmd);
2049 sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 1);
2050 system(cmd);
2051 sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 1);
2052 system(cmd);
2053 sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 1);
2054 system(cmd);
2055 sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 1);
2056 system(cmd);
2057 sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 1);
2058 system(cmd);
2059 }
2060 else
2061 {
2062 sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 1);
2063 system(cmd);
2064 sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 0);
2065 system(cmd);
2066 sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 0);
2067 system(cmd);
2068 sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 0);
2069 system(cmd);
2070 sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 0);
2071 system(cmd);
2072 sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 0);
2073 system(cmd);
2074 }
2075}
2076
2077void* lynq_start_rtp_cmd(void *arg)
2078{
ll3783e142022-08-10 00:33:52 -07002079 if(g_lynq_call_init_flag == 0)
2080 {
2081 return -1;
2082 }
q.huang68ee8a02022-06-28 20:12:01 +08002083 int* rtp_mode= (int*) arg;
2084 char cmd[384];
q.huangb84348a2022-09-30 17:33:20 +08002085 char vlan_para_string[sizeof(RTP_VLAN_INFO_FORMAT)+MAX_VLAN_INFO_LENGTH-2/*sizeof "%s"*/]={0};
q.huang68ee8a02022-06-28 20:12:01 +08002086 LYINFLOG("lynq_start_rtp_cmd: rtp_mode is %d",(*rtp_mode));
2087 if ((*rtp_mode) == RTP_CLIENT)
2088 {
2089 sprintf(cmd,RTP_FROM_CMD, \
2090 g_rtp_client_info.port,g_rtp_client_info.clockrate,g_rtp_client_info.channels, \
2091 g_rtp_client_info.latency);
q.huange0024b02022-08-29 20:04:31 +08002092 // LYINFLOG("start from rtp play: cmd is %s",cmd);
q.huang68ee8a02022-06-28 20:12:01 +08002093 system(cmd);
2094 }
2095 else if ((*rtp_mode) == RTP_SERVER)
2096 {
q.huangb84348a2022-09-30 17:33:20 +08002097 if(strlen(g_rtp_server_info.vlan_info)>0)
2098 {
2099 sprintf(vlan_para_string,RTP_VLAN_INFO_FORMAT,g_rtp_server_info.vlan_info);
2100 }
q.huang68ee8a02022-06-28 20:12:01 +08002101 sprintf(cmd,RTP_TO_CMD, \
q.huangb84348a2022-09-30 17:33:20 +08002102 g_rtp_server_info.ip,vlan_para_string,g_rtp_server_info.port);
q.huange0024b02022-08-29 20:04:31 +08002103 // LYINFLOG("start to rtp play: cmd is %s",cmd);
q.huang68ee8a02022-06-28 20:12:01 +08002104 system(cmd);
2105 }
2106 return NULL;
2107}
2108
2109int lynq_start_rtp_thread(int rtp_mode)
2110{
2111 int ret;
2112 pthread_attr_t attr;
2113 static int start_mode[RTP_MODE_MAX]={0,1};
2114
2115 pthread_attr_init(&attr);
2116 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
2117 ret = pthread_create(&(g_rtp_thread[rtp_mode]),&attr,lynq_start_rtp_cmd,&(start_mode[rtp_mode]));
2118 if(ret != 0)
2119 {
2120 g_rtp_thread_valid[rtp_mode]=0;
2121 LYERRLOG("rtp create %d pthread error, ret is %d",rtp_mode, ret);
2122 return ret;
2123 }
2124 g_rtp_thread_valid[rtp_mode]=1;
2125 return 0;
2126}
2127
q.huangdf857562022-06-06 16:15:31 +08002128/*set*/
2129int lynq_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode)
2130{
ll3783e142022-08-10 00:33:52 -07002131 if(g_lynq_call_init_flag == 0)
2132 {
2133 return -1;
2134 }
q.huang68ee8a02022-06-28 20:12:01 +08002135 int ret;
2136 int i;
2137
2138 if(audio_mode==AUDIO_MODE_RTP)
2139 {
2140 lynq_set_rtp_mixer_ctrl(1);
2141 for(i=0;i<RTP_MODE_MAX;i++)
2142 {
2143 if(!g_rtp_thread_valid[i])
2144 {
2145 if(lynq_start_rtp_thread(i)!= 0)
2146 {
2147 LYERRLOG("start rtp %d fail",i);
2148 break;
2149 }
2150 else
2151 {
2152 LYINFLOG("start rtp %d suc",i);
2153 }
2154 }
2155 else
2156 {
2157 LYERRLOG("rtp %d needn't start",i);
2158 }
2159 }
2160 if(i!= RTP_MODE_MAX)
2161 {
2162 LYERRLOG("start rtp whole fail");
2163 lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
2164 return 1;
2165 }
2166 LYINFLOG("start rtp whole suc");
2167 return 0;
2168 }
2169 else if(audio_mode==AUDIO_MODE_CODEC)
2170 {
2171 for(i=0;i<RTP_MODE_MAX;i++)
2172 {
2173 if(g_rtp_thread_valid[i])
2174 {
2175 ret = pthread_cancel(g_rtp_thread[i]);
2176 LYINFLOG("pthread cancel rtp %d ret = %d",i,ret);
2177 ret = pthread_join(g_rtp_thread[i],NULL);
2178 LYINFLOG("pthread join rtp %d ret = %d",i,ret);
2179 g_rtp_thread_valid[i] = 0;
2180 }
2181 else
2182 {
2183 LYINFLOG("rtp %d needn't stop",i);
2184 }
2185 }
2186 lynq_set_rtp_mixer_ctrl(0);
2187 LYINFLOG("stop rtp suc");
2188 }
2189 return 0;
q.huangdf857562022-06-06 16:15:31 +08002190}
q.huang68ee8a02022-06-28 20:12:01 +08002191int lynq_set_remote_rtp_ip(const char* ip, const int ip_length)
q.huangdf857562022-06-06 16:15:31 +08002192{
q.huang68ee8a02022-06-28 20:12:01 +08002193 if (NULL == ip)
2194 {
2195 LYERRLOG("ip is NULL!!!");
2196 return -1;
2197 }
2198 if ((ip_length < strlen(ip)+1) || (ip_length > MAX_IP_LENGTH))
2199 {
2200 LYERRLOG("incoming ip length error %d", ip_length);
2201 return -1;
2202 }
2203
2204 bzero(g_rtp_server_info.ip,MAX_IP_LENGTH);
2205 strcpy(g_rtp_server_info.ip,ip);
2206
2207 LYINFLOG("lynq_set_remote_rtp_ip suc: ip is %s, length is %d", ip,ip_length);
2208
q.huangdf857562022-06-06 16:15:31 +08002209 return 0;
2210}
q.huangb84348a2022-09-30 17:33:20 +08002211int lynq_set_vlan_info(const char* vlan_info, const int vlan_info_length)
2212{
2213 if (NULL == vlan_info)
2214 {
2215 LYERRLOG("vlan_info is NULL!!!");
2216 return -1;
2217 }
2218
2219 if ((vlan_info_length < strlen(vlan_info)+1) || (vlan_info_length > MAX_VLAN_INFO_LENGTH))
2220 {
2221 LYERRLOG("incoming vlan_info error, vlan info length %d", vlan_info_length);
2222 return -1;
2223 }
2224
2225
2226 bzero(g_rtp_server_info.vlan_info,MAX_VLAN_INFO_LENGTH);
2227 strcpy(g_rtp_server_info.vlan_info,vlan_info);
2228
2229 LYINFLOG("lynq_set_vlan_info suc: vlan is %s, length is %d", vlan_info,vlan_info_length);
2230
2231 return 0;
2232}
q.huang0b6154c2022-06-06 20:23:15 +08002233int lynq_set_rtp_port(const LYNQ_Rtp_Mode rtp_mode, const int port)
q.huangdf857562022-06-06 16:15:31 +08002234{
q.huang68ee8a02022-06-28 20:12:01 +08002235 if (port < 0)
2236 {
2237 LYERRLOG("invalid port number %d", port);
2238 return -1;
2239 }
2240 if (rtp_mode == 0)
2241 {
2242 g_rtp_client_info.port = port;
2243 }
2244 else if (rtp_mode == 1)
2245 {
2246 g_rtp_server_info.port = port;
2247 }
2248 LYINFLOG("lynq_set_rtp_port suc: LYNQ_Rtp_Mode is %d, port is %d", rtp_mode, port);
q.huangdf857562022-06-06 16:15:31 +08002249 return 0;
2250}
2251int lynq_set_rtp_param(const int clock_rate,const int channels,const int latency) //only for client mode
2252{
q.huang68ee8a02022-06-28 20:12:01 +08002253 g_rtp_client_info.clockrate = clock_rate;
2254 g_rtp_client_info.channels = channels;
2255 g_rtp_client_info.latency = latency;
2256 LYINFLOG("lynq_set_rtp_param suc: clockrate is %d, channels is %d, latency is %d", clock_rate, channels, latency);
q.huangdf857562022-06-06 16:15:31 +08002257 return 0;
2258}
2259/*get*/
2260LYNQ_Audio_Mode lynq_get_voice_audio_mode()
2261{
ll3783e142022-08-10 00:33:52 -07002262 if(g_lynq_call_init_flag == 0)
2263 {
2264 return -1;
2265 }
q.huang68ee8a02022-06-28 20:12:01 +08002266 if(g_rtp_thread_valid[0])
2267 {
2268 return AUDIO_MODE_RTP;
2269 }
2270 else
2271 {
2272 return AUDIO_MODE_CODEC;
2273 }
q.huangdf857562022-06-06 16:15:31 +08002274}
q.huang68ee8a02022-06-28 20:12:01 +08002275int lynq_get_remote_rtp_ip(char* ip, const int ip_length)
q.huangdf857562022-06-06 16:15:31 +08002276{
ll3783e142022-08-10 00:33:52 -07002277 if(g_lynq_call_init_flag == 0)
2278 {
2279 return -1;
2280 }
q.huangdf857562022-06-06 16:15:31 +08002281 if(ip==NULL)
2282 {
q.huang68ee8a02022-06-28 20:12:01 +08002283 LYERRLOG("ip is NULL");
q.huangdf857562022-06-06 16:15:31 +08002284 return 1;
2285 }
q.huang68ee8a02022-06-28 20:12:01 +08002286
2287 if(ip_length < strlen(g_rtp_server_info.ip)+1)
2288 {
2289 LYERRLOG("ip lenght %d is shorter than saved ip length %d",ip_length,strlen(g_rtp_server_info.ip)+1);
2290 return 1;
2291 }
2292 bzero(ip,ip_length);
2293 strcpy(ip,g_rtp_server_info.ip);
q.huangdf857562022-06-06 16:15:31 +08002294 return 0;
2295}
q.huangb84348a2022-09-30 17:33:20 +08002296int lynq_get_vlan_info(char* vlan_info, const int vlan_info_length)
2297{
2298 if(vlan_info==NULL)
2299 {
2300 LYERRLOG("vlan info is NULL");
2301 return -1;
2302 }
2303
2304 if(vlan_info_length < strlen(g_rtp_server_info.vlan_info)+1)
2305 {
2306 LYERRLOG("vlan info length %d is shorter than saved vlan info length %d",vlan_info_length,strlen(g_rtp_server_info.vlan_info)+1);
2307 return -1;
2308 }
2309
2310 bzero(vlan_info,vlan_info_length);
2311 strcpy(vlan_info,g_rtp_server_info.vlan_info);
2312
2313 return 0;
2314}
q.huangdf857562022-06-06 16:15:31 +08002315int lynq_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port)
2316{
ll3783e142022-08-10 00:33:52 -07002317 if(g_lynq_call_init_flag == 0)
2318 {
2319 return -1;
2320 }
q.huangdf857562022-06-06 16:15:31 +08002321 if(port==NULL)
2322 {
2323 return 1;
q.huang68ee8a02022-06-28 20:12:01 +08002324 }
2325 if (rtp_mode == 0)
2326 {
2327 *port = g_rtp_client_info.port;
2328 }
2329 else if (rtp_mode == 1)
2330 {
2331 *port = g_rtp_server_info.port;
2332 }
q.huangdf857562022-06-06 16:15:31 +08002333 return 0;
2334}
2335int lynq_get_rtp_param(int* clock_rate, int* channels, int* latency)//only for client mode
2336{
ll3783e142022-08-10 00:33:52 -07002337 if(g_lynq_call_init_flag == 0)
2338 {
2339 return -1;
2340 }
q.huangdf857562022-06-06 16:15:31 +08002341 if(clock_rate == NULL || channels ==NULL || latency ==NULL)
2342 {
q.huang68ee8a02022-06-28 20:12:01 +08002343 LYERRLOG("input parameter is NULL");
q.huangdf857562022-06-06 16:15:31 +08002344 return 1;
2345 }
2346
q.huang68ee8a02022-06-28 20:12:01 +08002347 *clock_rate = g_rtp_client_info.clockrate;
2348 *channels = g_rtp_client_info.channels ;
2349 *latency = g_rtp_client_info.latency;
2350
q.huangdf857562022-06-06 16:15:31 +08002351 return 0;
2352}
2353/*Audio Path setting end*/
2354
lh25827952022-01-10 00:34:35 -08002355#if 0
2356int main(int argc,char **argv)
2357{
2358 int n = 0;
2359 n = lynq_init_call(lynq_call_state_change_test,2222);
2360 if(n<0)
2361 {
q.huangf8461432022-06-02 14:49:02 +08002362 LYDBGLOG("lynq init call fail!!!");
lh25827952022-01-10 00:34:35 -08002363 return -1;
2364 }
q.huangf8461432022-06-02 14:49:02 +08002365 LYDBGLOG("lynq call init success!!!");
lh25827952022-01-10 00:34:35 -08002366 char phoneNum[LYNQ_PHONE_NUMBER_MAX];
2367 sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
2368 lynq_call(phoneNum);
2369 while(1)
2370 {
2371 sleep(1);
2372 }
2373 return 0;
2374}
2375#endif
2376/*Warren add for T800 platform 2021/11/19 end*/