blob: 67e112d5a19cd2d7596af156adecb2ea6765a1f9 [file] [log] [blame]
lhf81a46f2022-02-13 23:57:37 -08001#include <stdio.h>
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <arpa/inet.h>
5#include <fcntl.h>
6#include <string.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <binder/Parcel.h>
10#include <log/log.h>
11#include "lynq_data.h"
12#include <cutils/jstring.h>
13#include <pthread.h>
14#include "liblog/lynq_deflog.h"
15#include <sys/time.h>
rjw0cdacbc2022-06-22 10:51:07 +080016#include <include/lynq_uci.h>
rjw747deea2022-07-01 18:25:30 +080017#include <errno.h>
rjw7ee7bb42023-01-18 11:34:28 +080018#include <vector>
19#include "lynq_data_urc.h"
20
lhf81a46f2022-02-13 23:57:37 -080021#define LYNQ_SERVICE_PORT 8088
lhf81a46f2022-02-13 23:57:37 -080022#define LYNQ_REC_BUF 8192
23#define LYNQ_REQUEST_PARAM_BUF 8192
24#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
25#define USER_LOG_TAG "LYNQ_DATA"
26
rjw0cdacbc2022-06-22 10:51:07 +080027#define LYNQ_DATA_UCI_BUF 258
Hong_Liu25edfe72023-06-16 01:13:42 -070028#define LYNQ_DATA_TIME_OUT 1000*120
Hong_Liu7163bbe2023-06-04 03:03:44 -070029
rjw61fcae32022-08-18 14:03:39 +080030
lhf81a46f2022-02-13 23:57:37 -080031using ::android::Parcel;
32typedef struct{
33 int uToken;
34 int request;
35 int paramLen;
36 char param[LYNQ_REQUEST_PARAM_BUF];
37}lynq_client_t;
lh13586612022-01-11 21:58:58 -080038typedef enum{
39 LYNQ_E_CARDSTATE_ERROR=8000,
40 /* The voice service state is out of service*/
41 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
42 /* The voice service state is EMERGENCY_ONLY*/
43 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
44 /* The radio power is power off*/
45 LYNQ_E_STATE_POWER_OFF=8003,
46 LYNQ_E_TIME_OUT=8004,
47 /*create or open sms DB fail */
48 LYNQ_E_SMS_DB_FAIL=8005,
49 /*Failed to execute sql statement*/
50 LYNQ_E_SMS_SQL_FAIL = 8006,
51 LYNQ_E_SMS_NOT_FIND = 8007,
Hong_Liu25edfe72023-06-16 01:13:42 -070052 LYNQ_E_GET_RESP_FAIL = 8008,
53 LYNQ_E_NOT_THIS_APN = 8087,
54 LYNQ_E_NOT_ANY_APN = 8088,
55 LYNQ_E_MD_NOT_READY = 8089,
lh13586612022-01-11 21:58:58 -080056 /* The logic conflict*/
57 LYNQ_E_CONFLICT=9000,
58 /*Null anomaly*/
59 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080060}LYNQ_E;
61
62int lynq_client_sockfd = 0;
63int Global_uToken = 0;
Hong_Liu7e1b85e2023-05-16 05:51:57 -070064struct sockaddr_in lynq_data_socket_server_addr;
65int lynq_data_socket_server_addr_len;
rjw7ee7bb42023-01-18 11:34:28 +080066
lhf81a46f2022-02-13 23:57:37 -080067int lynq_data_call_change_id = -1;
68pthread_t lynq_data_tid =-1;
69static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
70static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080071
Hong_Liu25edfe72023-06-16 01:13:42 -070072static pthread_mutex_t s_data_call_deactived_mutex = PTHREAD_MUTEX_INITIALIZER;
73static pthread_cond_t s_data_call_deactived_cond = PTHREAD_COND_INITIALIZER;
74
75
rjw20006d12022-04-21 16:29:04 +080076static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
77static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080078static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
79static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER;
rjwed00d042022-05-25 09:18:16 +080080/**g_lynq_data_sendto_mutex
81* @brief mark data send request mutex
82*/
83static pthread_mutex_t g_lynq_data_sendto_mutex;
rjwf9ec3832023-04-12 10:59:15 +080084/*This value data the state of the wait*/
rjwc3d6e582023-03-28 17:19:11 +080085static int data_waiting_status = 0;
rjwf9ec3832023-04-12 10:59:15 +080086/*The value indicates that 8085 error occurs in data*/
rjwc63abb42023-03-31 18:22:42 +080087static int data_invaild_error = 0;
rjwf9ec3832023-04-12 10:59:15 +080088/*This value ensure the data call timing is correct*/
89static int data_timelimit = 0;
rjwc63abb42023-03-31 18:22:42 +080090
rjw22947c22022-03-15 09:21:29 +080091/**g_lynq_data_init_flag
92* @brief mark data initialization state
93* 0:deinit status
94* 1:init state
95*/
96static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080097/**g_lynq_apn_result
98* @brief temp of apn result info
99*/
100char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +0800101
rjw7ee7bb42023-01-18 11:34:28 +0800102static std::vector<int> s_data_urc_wait_list;
103
rjw20006d12022-04-21 16:29:04 +0800104typedef struct
105{
lhf81a46f2022-02-13 23:57:37 -0800106 char apn[LYNQ_APN_MAX_LEN];
107 char apnType[LYNQ_APN_TYPE_MAX_LEN];
108 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
109 int hasUsed;
110 int hasTimeout;
Hong_Liudc46d412023-05-18 13:36:26 -0700111 int status;
112 char statusApnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800113}lynq_apn_t;
114lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
115lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
116int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800117
lhf81a46f2022-02-13 23:57:37 -0800118int getLynqApnID(char apnType[])
119{
120 int ret = 0;
rjwc63abb42023-03-31 18:22:42 +0800121 int len = 0;
lhf81a46f2022-02-13 23:57:37 -0800122 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
123 {
Hong_Liudc46d412023-05-18 13:36:26 -0700124 len = strlen(apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700125 LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len);
rjwc63abb42023-03-31 18:22:42 +0800126 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
lh13586612022-01-11 21:58:58 -0800127 {
lhf81a46f2022-02-13 23:57:37 -0800128 return ret;
129 }
130 }
131 return -1;
132}
rjw7ee7bb42023-01-18 11:34:28 +0800133
Hong_Liudc46d412023-05-18 13:36:26 -0700134int getDeactApnID(char apnType[])
135{
136 int ret = 0;
137 int len = 0;
138 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
139 {
140 len = strlen(apnType);
141 LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len);
142 if(strncmp(lynq_apn_table[ret].statusApnType,apnType,len)==0)
143 {
144 return ret;
145 }
146 }
147 return -1;
148}
149
lhf81a46f2022-02-13 23:57:37 -0800150void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
151{
152 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
153 if(apn_table==NULL)
154 {
155 LYERRLOG("apn_table is null");
156 return;
157 }
158 memcpy(apn_table->apn,apn,strlen(apn)+1);
159 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
160 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
161 apn_table->hasTimeout = 0;
162 apn_table->hasUsed = 1;
163 return;
164}
rjw7ee7bb42023-01-18 11:34:28 +0800165
lhf81a46f2022-02-13 23:57:37 -0800166void cleanOnceApnTable(int apnId)
167{
Hong_Liudc46d412023-05-18 13:36:26 -0700168 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
lhf81a46f2022-02-13 23:57:37 -0800169 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
170 {
171 LYERRLOG("apn id is invalid!!!");
172 return;
173 }
174 lynq_apn_table[apnId].hasTimeout = 0;
175 lynq_apn_table[apnId].hasUsed = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700176 memcpy(lynq_apn_table[apnId].statusApnType,lynq_apn_table[apnId].apnType,strlen(lynq_apn_table[apnId].apnType));
lhf81a46f2022-02-13 23:57:37 -0800177 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700178 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
lhf81a46f2022-02-13 23:57:37 -0800179 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700180 lynq_apn_table[apnId].status = 32;
lhf81a46f2022-02-13 23:57:37 -0800181 return;
182}
Hong_Liudc46d412023-05-18 13:36:26 -0700183void cleanDeactApn(int apnId)
184{
185 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
186 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
187 {
188 LYERRLOG("apn id is invalid!!!");
189 return;
190 }
191 lynq_apn_table[apnId].status = 0;
192 bzero(lynq_apn_table[apnId].statusApnType,LYNQ_APN_TYPE_MAX_LEN);
193}
194
195void updateDeactApn(int apnId,int pdnState)
196{
197 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
198 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
199 {
200 LYERRLOG("apn id is invalid!!!");
201 return;
202 }
203 lynq_apn_table[apnId].status = pdnState;
204}
205
206
lhf81a46f2022-02-13 23:57:37 -0800207int getUnusedElement()
208{
Hong_Liudc46d412023-05-18 13:36:26 -0700209 if (lynq_apn_table == NULL)
210 {
211 LYERRLOG("get UnusedElemnt apn_table is null");
212 return -1;
213 }
lhf81a46f2022-02-13 23:57:37 -0800214 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
215 {
216 if(lynq_apn_table[i].hasUsed!=1)
217 {
218 return i;
219 }
220 }
rjwc63abb42023-03-31 18:22:42 +0800221 LYERRLOG("None of get unused Element");
lhf81a46f2022-02-13 23:57:37 -0800222 return -1;
223}
224int updateApn(char apnType[])
225{
226 int ret = 0;
227 ret = getUnusedElement();
Hong_Liu55668712023-05-16 21:49:17 -0700228 if(ret >= 0)
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700229 {
230 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
231 lynq_apn_table[ret].hasUsed = 1;
232 }
lhf81a46f2022-02-13 23:57:37 -0800233 return ret;
234}
rjw1309e232022-07-22 09:54:06 +0800235
236int handleCheck(int handle)
237{
Hong_Liu7163bbe2023-06-04 03:03:44 -0700238 if ((handle >= 0) && (handle <= 6))
rjw1309e232022-07-22 09:54:06 +0800239 {
Hong_Liu7163bbe2023-06-04 03:03:44 -0700240 if (lynq_apn_table[handle].hasUsed == 1)
241 {
242 return 0;
243 }
rjw1309e232022-07-22 09:54:06 +0800244 return -1;
245 }
Hong_Liu7163bbe2023-06-04 03:03:44 -0700246 return -1;
rjw1309e232022-07-22 09:54:06 +0800247}
rjw20006d12022-04-21 16:29:04 +0800248int waitApnResult()
249{
250 int ret = 0;
251 LYINFLOG("start wait apn result!!!");
252 int sec = 0;
253 int usec = 0;
254 struct timeval now;
255 struct timespec timeout;
256 gettimeofday(&now, NULL);
257 sec = 20000 / 1000;
258 usec = 20000 % 1000;
259 timeout.tv_sec = now.tv_sec + sec;
260 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
261 pthread_mutex_lock(&s_lynq_apn_change_mutex);
262 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
263 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
264 return ret;
265}
266
267void sendSignalApnChange()
268{
269 LYINFLOG("start send Signal Apn Change");
270 pthread_mutex_lock(&s_lynq_apn_change_mutex);
271 pthread_cond_signal(&s_lynq_apn_change_cond);
272 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
273 return;
274}
lhf81a46f2022-02-13 23:57:37 -0800275
276int waitPdnChange()
277{
278 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800279 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
280 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
281 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800282 return ret;
283}
284int waitDataCallstateChange(int mtime)
285{
286 int ret = 0;
287 int sec = 0;
288 int usec = 0;
289 struct timeval now;
290 struct timespec timeout;
291 gettimeofday(&now,NULL);
292 sec = mtime/1000;
293 usec = mtime%1000;
294 timeout.tv_sec = now.tv_sec+sec;
295 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
296 pthread_mutex_lock(&s_data_call_state_change_mutex);
297 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
298 pthread_mutex_unlock(&s_data_call_state_change_mutex);
299 return ret;
300}
301void sendSignalDataCallStateChange()
302{
303 pthread_mutex_lock(&s_data_call_state_change_mutex);
304 pthread_cond_signal(&s_data_call_state_change_cond);
305 pthread_mutex_unlock(&s_data_call_state_change_mutex);
306 return;
307}
Hong_Liu25edfe72023-06-16 01:13:42 -0700308int waitDeactived(int mtime)
309{
310 int ret = 0;
311 int sec = 0;
312 int usec = 0;
313 struct timeval now;
314 struct timespec timeout;
315 gettimeofday(&now,NULL);
316 sec = mtime/1000;
317 usec = mtime%1000;
318 timeout.tv_sec = now.tv_sec+sec;
319 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
320 pthread_mutex_lock(&s_data_call_deactived_mutex);
321 ret = pthread_cond_timedwait(&s_data_call_deactived_cond,&s_data_call_deactived_mutex,&timeout);
322 pthread_mutex_unlock(&s_data_call_deactived_mutex);
323 return ret;
324}
325void sendSignalDeactvied()
326{
327 pthread_mutex_lock(&s_data_call_deactived_mutex);
328 pthread_cond_signal(&s_data_call_deactived_cond);
329 pthread_mutex_unlock(&s_data_call_deactived_mutex);
330 return;
331}
332
lhf81a46f2022-02-13 23:57:37 -0800333void sendSignalPdnChange()
334{
rjw7ee7bb42023-01-18 11:34:28 +0800335 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
336 pthread_cond_signal(&s_lynq_urc_vector_cond);
337 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800338 return;
339}
340
341int get_response(int sockfd,Parcel &p)
342{
343 int len = 0;
344 char recvline[LYNQ_REC_BUF];
345 bzero(recvline,LYNQ_REC_BUF);
346 /* receive data from server */
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700347 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
348 //len = read(sockfd, recvline, LYNQ_REC_BUF);
rjw08528682022-07-04 21:28:02 +0800349 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800350 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700351 LYERRLOG("get_response fail,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800352 return -1;
353 }
354 if (recvline != NULL) {
355 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
356 p.setDataPosition(0);
357 }
358 return 0;
359}
Hong_Liu25edfe72023-06-16 01:13:42 -0700360/**@brief get utoken in range 0 to 10000
361* @return utoken
362*/
363int get_utoken()
lhf81a46f2022-02-13 23:57:37 -0800364{
Hong_Liu25edfe72023-06-16 01:13:42 -0700365 return (Global_uToken++)%10000;/*0-10000*/
366}
367/**@brief wait response with expected token and write msg to parcel in some time
368* @param fd [IN]: socket fd
369* @param p [OUT]: quote the parcel,if return success need delete p.
370* @param token [IN]: the expected token for the response msg
371* @return
372* 0:success
373* other:failure
374*/
375int wait_response(int sockfd,Parcel *& p,int utoken)
376{
377 int len = 0;
378 int flag = 1;
379 int count = 0;
380 int in_utoken = -1;
381 int resp_type = -1;
382 Parcel *temp = NULL;
383 char recvline[LYNQ_REC_BUF];
384 //Sometimes the socket is abnormal, causing the socket buffer to store the response of the last request.
385 //Here it does not return until the response corresponding to the request is read.
386 while(flag && (count < 20))//why?
lhf81a46f2022-02-13 23:57:37 -0800387 {
Hong_Liu25edfe72023-06-16 01:13:42 -0700388 bzero(recvline,LYNQ_REC_BUF);
389 count++;
390 LYINFLOG("wait_response,count:%d",count);
391 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
392 if(len == -1)
393 {
394 LYERRLOG("wait_response fail,errno:%d",errno);
395 return LYNQ_E_GET_RESP_FAIL;
396 }
397 if (len != 0)
398 {
399 temp = new Parcel;
400 int i = 0;
401 while((NULL == temp) && (i < 100))
402 {
403 usleep(1000);
404 temp = new Parcel;
405 i++;
406 }
407 if((i >= 100) || (NULL == temp))
408 {
409 LYERRLOG("wait_response i:%d",i);
410 return LYNQ_E_GET_RESP_FAIL;
411 }
412 temp->setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
413 temp->setDataPosition(0);
414 temp->readInt32(&resp_type);
415 temp->readInt32(&in_utoken);
416 LYINFLOG("[%s]in_utoken:%d,utoken:%d",__FUNCTION__,in_utoken,utoken);
417 if (in_utoken != utoken)
418 {
419 delete temp;
420 temp = NULL;
421 in_utoken = 0;
422 continue;
423 }
424 temp->setDataPosition(0);
425 p = temp;
426 flag = 0;
427 return 0;
428 }
429 else
430 {
431 LYERRLOG("recvline is null,errno:%d",errno);
432 return LYNQ_E_GET_RESP_FAIL;
433 }
434 }
435 return LYNQ_E_GET_RESP_FAIL;
436}
437
438int JumpHeader(Parcel *p,int *resp_type,int *utoken,int *request,int *slot_id,int *error)
439{
440 if(NULL == p)
441 {
442 LYERRLOG("JumpHeader is null");
443 return -1;
444 }
445 if(p->dataAvail() > 0)
446 {
447 p->readInt32(resp_type);
448 p->readInt32(utoken);
449 p->readInt32(request);
450 p->readInt32(slot_id);
451 p->readInt32(error);
lhf81a46f2022-02-13 23:57:37 -0800452 return 0;
453 }
454 else
455 {
456 return -1;
457 }
458}
Hong_Liu25edfe72023-06-16 01:13:42 -0700459void free_parcel(Parcel *p)
460{
461 if(p)
462 {
463 delete p;
464 p = NULL;
465 }
466}
lhf81a46f2022-02-13 23:57:37 -0800467int send_request(int sockfd,lynq_client_t *client_tmp)
468{
469 int ret=0;
470 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
471 if(ret==-1)
472 {
473 perror("write error");
474 return -1;
475 }
476 return 0;
477}
478static char *strdupReadString(Parcel &p) {
479 size_t stringlen;
480 const char16_t *s16;
481 s16 = p.readString16Inplace(&stringlen);
482 return strndup16to8(s16, stringlen);
483}
484static char *strdupReadString_p(Parcel *p) {
485 size_t stringlen;
486 const char16_t *s16;
487 s16 = p->readString16Inplace(&stringlen);
488 return strndup16to8(s16, stringlen);
489}
490
lhf81a46f2022-02-13 23:57:37 -0800491/*Warren add for T800 platform 2021/11/19 start*/
492int lynq_socket_client_start()
493{
lhf81a46f2022-02-13 23:57:37 -0800494 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800495 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
496 lynq_data_socket_server_addr.sin_family = AF_INET;
497 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
jb.qice04d002023-05-16 18:28:06 -0700498 lynq_data_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700499 lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr);
lhf81a46f2022-02-13 23:57:37 -0800500 /*
501 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
502 {
503 printf("[%s] is not a valid IPaddress\n", argv[1]);
504 exit(1);
505 }
506*/
507 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800508 struct timeval timeOut;
509
rjwa59bf312022-07-05 11:50:31 +0800510 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800511 timeOut.tv_usec = 0;
512
513 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
514 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700515 LYERRLOG("time out setting failed");
rjw747deea2022-07-01 18:25:30 +0800516 }
517 if(connect(lynq_client_sockfd, (struct sockaddr *)&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr)) == -1)
lhf81a46f2022-02-13 23:57:37 -0800518 {
519 perror("connect error");
520 return -1;
521 }
522 return 0;
523}
rjw7ee7bb42023-01-18 11:34:28 +0800524
525bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800526{
rjw7ee7bb42023-01-18 11:34:28 +0800527 switch(urc_id)
528 {
529 case LYNQ_URC_DATA_CALL_STATUS_IND:
530
531 case LYNQ_URC_MODIFY_APNDB:
532 case LYNQ_URC_RESET_APNDB:
533 return true;
534 default:
535 return false;
536 }
537}
538
rjwc63abb42023-03-31 18:22:42 +0800539int printf_apn_table()
540{
541 int ret = 0;
Hong_Liu6149f182023-05-12 02:15:14 -0700542 if (lynq_apn_table == NULL)
543 {
544 LYERRLOG("apn table is null");
545 return -1;
546 }
rjwc63abb42023-03-31 18:22:42 +0800547 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
548 {
Hong_Liudc46d412023-05-18 13:36:26 -0700549 LYINFLOG("[%s][%d] apn=%s ;apntype=%s ;ifname=%s ;hasTimeout = %d ; hasUsed = %d,status = %d,statusDeactApn = %s",__FUNCTION__,ret, \
rjwc63abb42023-03-31 18:22:42 +0800550 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
Hong_Liudc46d412023-05-18 13:36:26 -0700551 lynq_apn_table[ret].hasTimeout,lynq_apn_table[ret].hasUsed,lynq_apn_table[ret].status,lynq_apn_table[ret].statusApnType);
rjwc63abb42023-03-31 18:22:42 +0800552 }
553 return 0;
554}
555
Hong_Liu6149f182023-05-12 02:15:14 -0700556void printf_apn_table_debug(const char *fun,int line)
557{
558 LYINFLOG("[%s][%d]apn_table msg",fun,line);
559 printf_apn_table();
560}
rjwc63abb42023-03-31 18:22:42 +0800561
rjw7ee7bb42023-01-18 11:34:28 +0800562void urc_msg_process(Parcel *p)
563{
564 int len;
565 int resp_type;
566 int urcid;
567 int slot_id;
rjwf9ec3832023-04-12 10:59:15 +0800568 int check_count = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700569 static int apnId=-1;
rjw7ee7bb42023-01-18 11:34:28 +0800570
571 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800572 char apn[LYNQ_APN_MAX_LEN];
573 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800574 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800575 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800576
577 int size = p->dataSize();
578 p->readInt32(&resp_type);
579 p->readInt32(&urcid);
580 p->readInt32(&slot_id);
581 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
582 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800583 {
rjw7ee7bb42023-01-18 11:34:28 +0800584 case LYNQ_URC_DATA_CALL_STATUS_IND:
585 p->readInt32(&pdnState);
586 bzero(apn,LYNQ_APN_MAX_LEN);
587 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
588 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
589 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800590 {
rjw20006d12022-04-21 16:29:04 +0800591 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800592 int len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700593 if((len < LYNQ_APN_MAX_LEN-1) && (len > 0))
rjw20006d12022-04-21 16:29:04 +0800594 {
rjw7ee7bb42023-01-18 11:34:28 +0800595 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800596 }
Hong_Liu6149f182023-05-12 02:15:14 -0700597 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800598 urc_msg = strdupReadString_p(p);
599 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700600 if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800601 {
602 memcpy(apnType,urc_msg,len+1);
603 }
Hong_Liu6149f182023-05-12 02:15:14 -0700604 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800605 urc_msg = strdupReadString_p(p);
606 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700607 if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800608 {
609 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
610 }
Hong_Liu6149f182023-05-12 02:15:14 -0700611 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800612 //sendSignalDataCallStateChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700613 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800614 if(apnId >= 0)
615 {
Hong_Liudc46d412023-05-18 13:36:26 -0700616 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800617 if(lynq_apn_table[apnId].hasTimeout==1)
618 {
rjwc63abb42023-03-31 18:22:42 +0800619 /*whether timeout?,real or not,*/
620 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800621 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800622 if (NULL != lynq_apn_table[apnId].apn && NULL != lynq_apn_table[apnId].apnType && strlen(lynq_apn_table[apnId].apn)>0)
rjw7ee7bb42023-01-18 11:34:28 +0800623 {
624 LYERRLOG("deactive this time out APN");
625 lynq_deactive_data_call(&apnId);
626 }
rjwc63abb42023-03-31 18:22:42 +0800627 else
rjw7ee7bb42023-01-18 11:34:28 +0800628 {
rjwc63abb42023-03-31 18:22:42 +0800629 /*if apn lose,update apn and deactive all apn*/
630 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800631 }
632 break;
633 }
rjwacdb2152023-02-07 14:12:49 +0800634 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
Hong_Liu6149f182023-05-12 02:15:14 -0700635 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800636 }
637 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800638 else
639 {
Hong_Liu6149f182023-05-12 02:15:14 -0700640 data_invaild_error = 1;
Hong_Liudc46d412023-05-18 13:36:26 -0700641 printf_apn_table_debug(__FUNCTION__,__LINE__);
642 apnId = getDeactApnID(apnType);
643 if(apnId < 0)
644 {
645 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
646 break;
647 }
648 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
649 updateDeactApn(apnId,pdnState);
650 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800651 }
rjw7ee7bb42023-01-18 11:34:28 +0800652 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
653 s_data_urc_wait_list.push_back(apnId);
654 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
655 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800656 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800657 LYDBGLOG("data call state:%d",lynq_data_call);
658 if(lynq_data_call==1)
659 {
rjwf9ec3832023-04-12 10:59:15 +0800660 while (data_timelimit == 0)
661 {
662 LYINFLOG("client not ready to wait");
663 for (check_count = 0;check_count < 500;check_count++)
664 {
665 /*wait 10ms*/
666 usleep(10*1000);
667 }
668 LYERRLOG("client still without res");
669 break;
670 }
rjw7ee7bb42023-01-18 11:34:28 +0800671 sendSignalDataCallStateChange();
672 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800673 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800674 }
Hong_Liu6149f182023-05-12 02:15:14 -0700675 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800676 }
rjw7ee7bb42023-01-18 11:34:28 +0800677 else
rjw20006d12022-04-21 16:29:04 +0800678 {
rjw7ee7bb42023-01-18 11:34:28 +0800679 urc_msg = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -0700680 free(urc_msg);
681 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800682 len = strlen(urc_msg);
683 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
684 {
685 memcpy(apnType,urc_msg,len+1);
686 }
Hong_Liu6149f182023-05-12 02:15:14 -0700687 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800688 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
Hong_Liudc46d412023-05-18 13:36:26 -0700689 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800690 if(apnId >= 0)
691 {
Hong_Liudc46d412023-05-18 13:36:26 -0700692 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
693 lynq_data_call_change_id = apnId;
694 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
695 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
696 s_data_urc_wait_list.push_back(apnId);
697 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
698 sendSignalPdnChange();
699 }
700 else
701 {
702 apnId = getDeactApnID(apnType);
703 if(apnId < 0)
704 {
705 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
706 break;
707 }
708 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
709 cleanDeactApn(apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800710 lynq_data_call_change_id = apnId;
711 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800712 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
713 s_data_urc_wait_list.push_back(apnId);
714 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -0700715 sendSignalDeactvied();
rjwc3d6e582023-03-28 17:19:11 +0800716 sendSignalPdnChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700717 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800718 }
rjw7ee7bb42023-01-18 11:34:28 +0800719 LYDBGLOG("data call state:%d",lynq_data_call);
720 if(lynq_data_call==1)
721 {
rjwf9ec3832023-04-12 10:59:15 +0800722 while (data_timelimit == 0)
723 {
724 LYINFLOG("client not ready to wait");
725 for (check_count = 0;check_count < 500;check_count++)
726 {
727 /*wait 10ms*/
728 usleep(10*1000);
729 }
730 LYERRLOG("client still without res");
731 break;
732 }
rjw7ee7bb42023-01-18 11:34:28 +0800733 sendSignalDataCallStateChange();
734 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800735 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800736 }
Hong_Liu6149f182023-05-12 02:15:14 -0700737 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800738 }
739 break;
740 case LYNQ_URC_MODIFY_APNDB:
741 urc_msg = strdupReadString_p(p);
742 if (NULL == urc_msg)
743 {
744 LYERRLOG("error apn msg");
745 }
746 else
747 {
748 bzero(g_lynq_apn_result, 1024);
749 strcpy(g_lynq_apn_result, urc_msg);
750 sendSignalApnChange();
751 }
Hong_Liu6149f182023-05-12 02:15:14 -0700752 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800753 break;
754 case LYNQ_URC_RESET_APNDB:
755 {
rjw20006d12022-04-21 16:29:04 +0800756 urc_msg = strdupReadString_p(p);
757 if (NULL == urc_msg)
758 {
759 LYERRLOG("error apn msg");
760 }
761 else
762 {
763 bzero(g_lynq_apn_result, 1024);
764 strcpy(g_lynq_apn_result, urc_msg);
765 sendSignalApnChange();
766 }
Hong_Liu6149f182023-05-12 02:15:14 -0700767 free(urc_msg);
rjw20006d12022-04-21 16:29:04 +0800768 }
rjw7ee7bb42023-01-18 11:34:28 +0800769 default:
770 break;
lhf81a46f2022-02-13 23:57:37 -0800771 }
rjw7ee7bb42023-01-18 11:34:28 +0800772
lhf81a46f2022-02-13 23:57:37 -0800773}
rjw7ee7bb42023-01-18 11:34:28 +0800774
rjw7ee7bb42023-01-18 11:34:28 +0800775int create_urc_vector_signal_thread()
776{
777 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800778 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800779 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
780 s_data_urc_wait_list.clear();
781 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800782 return 0;
783}
Hong_Liu25edfe72023-06-16 01:13:42 -0700784int get_imsi();
lhf81a46f2022-02-13 23:57:37 -0800785int lynq_init_data(int uToken)
786{
rjw22947c22022-03-15 09:21:29 +0800787 if (g_lynq_data_init_flag == 1)
788 {
789 LYERRLOG("init twice is not allowed");
790 return -1;
791 }
792 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800793 int result = 0;
794 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800795 LYLOGSET(LOG_INFO);
796 LYLOGEINIT(USER_LOG_TAG);
797 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800798 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800799 if(result!=0)
800 {
801 LYERRLOG("init socket client fail!!!");
802 return -1;
803 }
rjw7ee7bb42023-01-18 11:34:28 +0800804 result = lynq_init_data_urc_thread();
805 if(result!=0)
806 {
807 LYERRLOG("init socket urc fail!!!");
808 return -1;
809 }
810
811 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800812 if(result!=0)
813 {
814 LYERRLOG("init socket urc fail!!!");
815 return -1;
816 }
817 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
Hong_Liu25edfe72023-06-16 01:13:42 -0700818 int count = 0;
819 while(count < 10)
820 {
821 result = get_imsi();
822 if(result==0)
823 {
824 break;
825 }
826 sleep(1);
827 count++;
828 }
829 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
830 if(result!=0)
831 {
832 LYDBGLOG("lynq init call fail!!!");
833 return LYNQ_E_MD_NOT_READY;//
834 }
lhf81a46f2022-02-13 23:57:37 -0800835 LYDBGLOG("lynq init call success!!!");
836 return 0;
837
838}
839int lynq_deinit_data()
840{
841 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800842 if (g_lynq_data_init_flag == 0)
843 {
844 LYERRLOG("deinit twice is not allowed");
845 return ret;
846 }
847 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800848 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
849 {
850 if(strlen(lynq_apn_table[i].apnType)!=0)
851 {
852 lynq_deactive_data_call(&i);
853 }
854 }
855 if(lynq_client_sockfd>0)
856 {
857 close(lynq_client_sockfd);
858 }
rjw7ee7bb42023-01-18 11:34:28 +0800859 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800860 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800861 {
rjw7ee7bb42023-01-18 11:34:28 +0800862 LYERRLOG("lynq_deinit_data_urc_thread fail");
863 return ret;
rjw22947c22022-03-15 09:21:29 +0800864 }
rjwc3d6e582023-03-28 17:19:11 +0800865 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
866 s_data_urc_wait_list.clear();
867 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800868 return 0;
869}
870int lynq_setup_data_call(int *handle)
871{
Hong_Liue54db8c2023-04-21 02:37:23 -0700872 int error = -1;
873 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
874 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
Hong_Liue9879152023-04-25 20:40:26 -0700875 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -0700876 #else
Hong_Liu25edfe72023-06-16 01:13:42 -0700877 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -0800878 lynq_client_t client;
879 int resp_type = -1;
880 int request = -1;
881 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -0800882 int lynq_data_call_id = 0;
883 if(handle==NULL)
884 {
885 LYERRLOG("handle is null!!!");
886 return LYNQ_E_NULL_ANONALY;
887 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700888 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -0800889 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
890 client.paramLen = 0;
891 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
892 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800893 lynq_data_call_id = updateApn("default");
894 if (lynq_data_call_id < 0)
895 {
896 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700897 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +0800898 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700899 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect.
900 //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate.
rjw733b9832023-04-03 10:20:08 +0800901 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800902 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800903 if(send_request(lynq_client_sockfd,&client)==-1)
904 {
905 LYERRLOG("send request fail");
906 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -0700907 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700908 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -0800909 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700910 //get_response(lynq_client_sockfd,p);
911 error = wait_response(lynq_client_sockfd,p,client.uToken);
912 if(error!=0)
913 {
914 LYERRLOG("wait_response fail,ret:%d",error);
915 printf_apn_table_debug(__FUNCTION__,__LINE__);
916 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
917 return error;
918 }
rjwed00d042022-05-25 09:18:16 +0800919 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liuaa7f4b32023-07-19 07:51:25 -0700920 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
Hong_Liu25edfe72023-06-16 01:13:42 -0700921 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -0800922 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800923 if(error==0)
924 {
rjwf9ec3832023-04-12 10:59:15 +0800925 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -0700926 if (waitDataCallstateChange(LYNQ_DATA_TIME_OUT) == ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -0800927 {
928 error = LYNQ_E_TIME_OUT;
929 LYERRLOG("timeout:wait data Call state fail!!!");
930 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -0700931 if (data_invaild_error == 1)
932 {
933 data_invaild_error = 0;
934 LYERRLOG("urc apn info error!!!");
935 return 8085;
936 }
937 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -0800938 return error;
939 }
lhf81a46f2022-02-13 23:57:37 -0800940 }
Hong_Liu6149f182023-05-12 02:15:14 -0700941 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liue54db8c2023-04-21 02:37:23 -0700942 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800943 return error;
944}
rjw7ee7bb42023-01-18 11:34:28 +0800945
lhf81a46f2022-02-13 23:57:37 -0800946int lynq_deactive_data_call(int *handle)
947{
Hong_Liu25edfe72023-06-16 01:13:42 -0700948 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -0800949 lynq_client_t client;
950 int resp_type = -1;
951 int request = -1;
952 int slot_id = -1;
953 int error = -1;
954 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800955 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800956 if(handle==NULL)
957 {
958 LYERRLOG("handle is null!!!");
959 return -1;
960 }
rjw1309e232022-07-22 09:54:06 +0800961 ret = handleCheck(*handle);
962 if (ret != 0)
963 {
964 LYERRLOG("incomming handle is invalid");
965 return -1;
966 }
967 lynq_data_call_id = *handle;
Hong_Liu25edfe72023-06-16 01:13:42 -0700968 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -0800969 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
Hong_Liue3d35262023-05-04 00:20:12 -0700970 client.paramLen = 0;
971 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
972 #ifdef GSW_RIL_CFG
973 client.paramLen = 1;
974 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
975 #else
976 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -0800977 {
lhf81a46f2022-02-13 23:57:37 -0800978 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -0800979 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
980 }
Hong_Liue3d35262023-05-04 00:20:12 -0700981 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800982 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800983 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800984 if(send_request(lynq_client_sockfd,&client)==-1)
985 {
986 LYERRLOG("send request fail");
987 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -0700988 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800989 return -1;
990 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700991 //get_response(lynq_client_sockfd,p);
992 error = wait_response(lynq_client_sockfd,p,client.uToken);
993 if(error!=0)
994 {
995 LYERRLOG("wait_response fail,ret:%d",error);
996 printf_apn_table_debug(__FUNCTION__,__LINE__);
997 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
998 return error;
999 }
rjwed00d042022-05-25 09:18:16 +08001000 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001001 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1002 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -08001003 cleanOnceApnTable(lynq_data_call_id);
Hong_Liu6149f182023-05-12 02:15:14 -07001004 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liu25edfe72023-06-16 01:13:42 -07001005 if(error==0)
1006 {
1007 if(waitDeactived(20000)==ETIMEDOUT)
1008 {
1009 error = LYNQ_E_TIME_OUT;
1010 LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!");
1011 printf_apn_table_debug(__FUNCTION__,__LINE__);
1012 }
1013 }
1014 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001015 return error;
1016}
1017int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
1018{
Hong_Liu25edfe72023-06-16 01:13:42 -07001019 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001020 lynq_client_t client;
1021 int resp_type = -1;
1022 int request = -1;
1023 int slot_id = -1;
1024 int error = -1;
lhf81a46f2022-02-13 23:57:37 -08001025 int lynq_data_call_id = -1;
1026 char *argv[10] = {};
Hong_Liue54db8c2023-04-21 02:37:23 -07001027 #ifdef GSW_RIL_CFG
1028 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
1029 if(handle==NULL||apnType==NULL)
1030 {
1031 LYERRLOG("handle or apntype is null!!!");
1032 return -1;
1033 }
1034 #else
lhf81a46f2022-02-13 23:57:37 -08001035 if(handle==NULL||apn==NULL||apnType==NULL)
1036 {
1037 LYERRLOG("handle ,apn or apntype is null!!!");
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001038 return LYNQ_E_NULL_ANONALY;
lhf81a46f2022-02-13 23:57:37 -08001039 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001040 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001041 if(user==NULL)
1042 {
1043 argv[1] = "null";
1044 }
1045 else
1046 {
1047 argv[1] = user;
lh13586612022-01-11 21:58:58 -08001048 }
1049 if(password==NULL)
1050 {
lhf81a46f2022-02-13 23:57:37 -08001051 argv[2] = "null";
lh13586612022-01-11 21:58:58 -08001052 }
1053 else
1054 {
lhf81a46f2022-02-13 23:57:37 -08001055 argv[2] = password;
lh13586612022-01-11 21:58:58 -08001056 }
1057 if(authType==NULL)
1058 {
lhf81a46f2022-02-13 23:57:37 -08001059 argv[3] = "null";
lh13586612022-01-11 21:58:58 -08001060 }
1061 else
1062 {
lhf81a46f2022-02-13 23:57:37 -08001063 argv[3] = authType;
lh13586612022-01-11 21:58:58 -08001064 }
1065 if(normalProtocol==NULL)
1066 {
lhf81a46f2022-02-13 23:57:37 -08001067 argv[4] = "null";
lh13586612022-01-11 21:58:58 -08001068 }
1069 else
1070 {
lhf81a46f2022-02-13 23:57:37 -08001071 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -08001072 }
1073 if(roamingProtocol==NULL)
1074 {
lhf81a46f2022-02-13 23:57:37 -08001075 argv[5] = "null";
lh13586612022-01-11 21:58:58 -08001076 }
1077 else
1078 {
lhf81a46f2022-02-13 23:57:37 -08001079 argv[5] = roamingProtocol;
1080 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001081 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001082 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1083 client.paramLen = 7;
1084 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -07001085 #ifdef GSW_RIL_CFG
1086 if(NULL == apn)
1087 {
1088 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1089 }
1090 else
1091 {
1092 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1093 }
1094 #else
lhf81a46f2022-02-13 23:57:37 -08001095 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
Hong_Liue54db8c2023-04-21 02:37:23 -07001096 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001097 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +08001098 lynq_data_call_id = updateApn(apnType);
1099 if (lynq_data_call_id < 0)
1100 {
1101 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001102 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001103 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001104 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16)
rjw733b9832023-04-03 10:20:08 +08001105 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001106 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001107 if(send_request(lynq_client_sockfd,&client)==-1)
1108 {
1109 LYERRLOG("send request fail");
1110 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001111 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001112 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001113 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001114 //get_response(lynq_client_sockfd,p);
1115 error = wait_response(lynq_client_sockfd,p,client.uToken);
1116 if(error!=0)
1117 {
1118 LYERRLOG("wait_response fail,ret:%d",error);
1119 printf_apn_table_debug(__FUNCTION__,__LINE__);
1120 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1121 return error;
1122 }
rjwed00d042022-05-25 09:18:16 +08001123 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001124 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1125 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1126 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001127 if(error==0)
1128 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001129 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001130 if(waitDataCallstateChange(LYNQ_DATA_TIME_OUT)==ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001131 {
1132 error = LYNQ_E_TIME_OUT;
1133 LYERRLOG("timeout:wait data Call state fail!!!");
1134 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001135 if (data_invaild_error == 1)
1136 {
1137 data_invaild_error = 0;
1138 LYERRLOG("urc apn info error!!!");
1139 return 8085;
1140 }
1141 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001142 return error;
1143 }
lhf81a46f2022-02-13 23:57:37 -08001144 }
Hong_Liu6149f182023-05-12 02:15:14 -07001145 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001146 return error;
1147}
1148/*
1149int lynq_deactive_data_call_sp(int *handle,char *apnType)
1150{
1151 Parcel p;
1152 lynq_client_t client;
1153 int resp_type = -1;
1154 int request = -1;
1155 int slot_id = -1;
1156 int error = -1;
1157 if(handle==NULL||apnType==NULL)
1158 {
1159 LYERRLOG("handle is null!!!");
1160 return -1;
1161 }
1162 client.uToken = Global_uToken;
1163 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
1164 client.paramLen = 1;
1165 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1166 sprintf(client.param,"%s",apnType);
1167 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1168 if(send_request(lynq_client_sockfd,&client)==-1)
1169 {
1170 LYERRLOG("send request fail");
1171 perror("[LYNQ_DATA] send request fail:");
1172 return -1;
1173 }
1174 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +08001175 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -08001176 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1177 return error;
1178}
1179*/
1180int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
1181{
Hong_Liu25edfe72023-06-16 01:13:42 -07001182 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001183 lynq_client_t client;
1184 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001185 int token;
Hong_Liu25edfe72023-06-16 01:13:42 -07001186 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001187 int slot_id = -1;
1188 int error = -1;
1189 int version =0;
1190 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001191 char *temp_char = NULL;
1192 if(dataCallList==NULL)
1193 {
1194 LYERRLOG("dataCallList is null!!!");
1195 return -1;
1196 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001197 client.uToken = get_utoken();;
lhf81a46f2022-02-13 23:57:37 -08001198 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1199 client.paramLen = 0;
1200 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1201 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001202 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001203 if(send_request(lynq_client_sockfd,&client)==-1)
1204 {
1205 LYERRLOG("send request fail");
1206 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001207 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001208 return -1;
1209 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001210 //get_response(lynq_client_sockfd,p);
1211 error = wait_response(lynq_client_sockfd,p,client.uToken);
1212 if(error!=0)
1213 {
1214 LYERRLOG("wait_response fail,ret:%d",error);
1215 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1216 return error;
1217 }
rjwed00d042022-05-25 09:18:16 +08001218 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001219 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
rjwfa532972022-09-16 13:39:41 +08001220 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001221 LYERRLOG("JumpHeader fail");
rjwfa532972022-09-16 13:39:41 +08001222 return -1;
1223 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001224 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1225 p->readInt32(&version);
lhf81a46f2022-02-13 23:57:37 -08001226 if(version==11)
1227 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001228 p->readInt32(&num);
lhf81a46f2022-02-13 23:57:37 -08001229 *realNum = num;
1230 for (int i = 0; i < num; i++)
1231 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001232 p->readInt32(&dataCallList[i].status);
1233 p->readInt32(&dataCallList[i].suggestedRetryTime);
1234 p->readInt32(&dataCallList[i].cid);
1235 p->readInt32(&dataCallList[i].active);
1236 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001237 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1238 if(temp_char)
1239 {
1240 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1241 free(temp_char);
1242 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001243 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001244 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1245 if(temp_char)
1246 {
1247 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1248 free(temp_char);
1249 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001250 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001251 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1252 if(temp_char)
1253 {
1254 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1255 free(temp_char);
1256 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001257 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001258 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1259 if(temp_char)
1260 {
1261 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1262 free(temp_char);
1263 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001264 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001265 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1266 if(temp_char)
1267 {
1268 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1269 free(temp_char);
1270 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001271 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001272 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1273 if(temp_char)
1274 {
1275 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1276 free(temp_char);
1277 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001278 p->readInt32(&dataCallList[i].mtu);
lhf81a46f2022-02-13 23:57:37 -08001279 }
1280 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001281 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001282 return error;
1283}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001284
1285int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
1286{
1287 LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
1288 if((handle < 0) || (handle > 6) || (NULL == apn_msg))
1289 {
1290 LYERRLOG("handle value error,or apn_msg is null");
1291 return LYNQ_E_NULL_ANONALY;
1292 }
1293 apn_msg->handle = handle;
1294 if(apn_msg->apn!=NULL)
1295 {
1296 memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
1297 }
1298 if(apn_msg->apnType!=NULL)
1299 {
1300 memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
1301 }
1302 return 0;
1303}
1304
lhf81a46f2022-02-13 23:57:37 -08001305int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1306{
1307 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1308 int number = 0;
1309 int lynq_data_call_id = 0;
1310 int error = 0;
1311 lynq_data_call_id = *handle;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001312 if((handle==NULL) || (dataCallList==NULL))
lhf81a46f2022-02-13 23:57:37 -08001313 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001314 LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
lhf81a46f2022-02-13 23:57:37 -08001315 return LYNQ_E_NULL_ANONALY;
1316 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001317 if ((*handle < 0) || (*handle > 6))
rjw3938f262023-03-08 16:09:28 +08001318 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001319 LYERRLOG("[lynq_get_data_call_list] handle value error");
1320 return LYNQ_E_NULL_ANONALY;
rjw3938f262023-03-08 16:09:28 +08001321 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001322 LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001323 memset(interDataCallList,0,sizeof(interDataCallList));
1324 error = getDataCallLists(interDataCallList,&number);
1325 if(error == 0)
1326 {
1327 for(int i = 0;i < number;i++)
1328 {
1329 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1330 {
1331 dataCallList->active = interDataCallList[i].active;
1332 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1333 dataCallList->cid = interDataCallList[i].cid;
1334 dataCallList->status = interDataCallList[i].status;
1335 dataCallList->mtu = interDataCallList[i].mtu;
1336 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1337 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1338 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1339 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1340 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1341 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1342 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1343 }
1344 }
1345 }
1346 return error;
1347}
1348int lynq_wait_data_call_state_change(int *handle)
1349{
rjwc3d6e582023-03-28 17:19:11 +08001350 if (data_waiting_status == 1)
1351 {
1352 LYDBGLOG("some thread is waiting");
1353 return -3;
1354 }
1355 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1356 if (s_data_urc_wait_list.empty())
1357 {
1358 LYDBGLOG("start wait");
1359 data_waiting_status = 1;
1360 waitPdnChange();
1361 }
1362 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001363 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001364
1365 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1366 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001367 if (iter != s_data_urc_wait_list.end())
1368 {
1369 *handle = *iter;
1370 }
rjw7ee7bb42023-01-18 11:34:28 +08001371 s_data_urc_wait_list.erase(iter);
1372 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1373
Hong_Liudc46d412023-05-18 13:36:26 -07001374 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001375 return 0;
1376}
1377/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001378
1379/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001380
1381int insert_apn_char(char *agc, char *id,char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier)
rjw20006d12022-04-21 16:29:04 +08001382{
1383 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001384 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001385 {
rjw61fcae32022-08-18 14:03:39 +08001386 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001387 }
rjw61fcae32022-08-18 14:03:39 +08001388 else
rjw0cdacbc2022-06-22 10:51:07 +08001389 {
rjw61fcae32022-08-18 14:03:39 +08001390 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001391 }
rjw20006d12022-04-21 16:29:04 +08001392 if (mcc == NULL)
1393 {
1394 sprintf(strtmp[1], "mcc=;");
1395 }
1396 else
1397 {
1398 sprintf(strtmp[1], "mcc=%s;", mcc);
1399 }
1400 if (mnc == NULL)
1401 {
rjw61fcae32022-08-18 14:03:39 +08001402 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001403 }
1404 else
1405 {
1406 sprintf(strtmp[2], "mnc=%s;", mnc);
1407 }
1408 if (apn == NULL)
1409 {
1410 sprintf(strtmp[3], "apn=;");
1411 }
1412 else
1413 {
1414 sprintf(strtmp[3], "apn=%s;", apn);
1415 }
1416 if (apntype == NULL)
1417 {
1418 sprintf(strtmp[4], "apntype=;");
1419 }
1420 else
1421 {
1422 sprintf(strtmp[4], "apntype=%s;", apntype);
1423 }
1424 if (user == NULL)
1425 {
1426 sprintf(strtmp[5], "user=;");
1427 }
1428 else
1429 {
1430 sprintf(strtmp[5], "user=%s;", user);
1431 }
1432 if (password == NULL)
1433 {
1434 sprintf(strtmp[6], "password=;");
1435 }
1436 else
1437 {
1438 sprintf(strtmp[6], "password=%s;", password);
1439 }
1440 if (normalprotocol == NULL)
1441 {
1442 sprintf(strtmp[7], "normalprotocol=;");
1443 }
1444 else
1445 {
1446 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1447 }
1448 if (roamingprotocol == NULL)
1449 {
1450 sprintf(strtmp[8], "roamingprotocol=;");
1451 }
1452 else
1453 {
1454 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1455 }
1456 if (carrier == NULL)
1457 {
1458 sprintf(strtmp[9], "carrier=;");
1459 }
1460 else
1461 {
1462 sprintf(strtmp[9], "carrier=%s;", carrier);
1463 }
rjw61fcae32022-08-18 14:03:39 +08001464 sprintf(agc, "%s%s%s%s%s%s%s%s%s%s",strtmp[0], strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]);
rjw0cdacbc2022-06-22 10:51:07 +08001465
rjw20006d12022-04-21 16:29:04 +08001466 return 0;
1467}
1468
1469int modify_apn_char(char *agc, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier)
1470{
1471 char strtmp[10][32];
1472 if (id == NULL)
1473 {
1474 sprintf(strtmp[0], "id=;");
1475 }
1476 else
1477 {
1478 sprintf(strtmp[0], "id=%s;", id);
1479 }
1480 if (mcc == NULL)
1481 {
1482 sprintf(strtmp[1], "mcc=;");
1483 }
1484 else
1485 {
1486 sprintf(strtmp[1], "mcc=%s;", mcc);
1487 }
1488 if (mnc == NULL)
1489 {
1490 sprintf(strtmp[2], "mnc=;");
1491 }
1492 else
1493 {
1494 sprintf(strtmp[2], "mnc=%s;", mnc);
1495 }
1496 if (apn == NULL)
1497 {
1498 sprintf(strtmp[3], "apn=;");
1499 }
1500 else
1501 {
1502 sprintf(strtmp[3], "apn=%s;", apn);
1503 }
1504 if (apntype == NULL)
1505 {
1506 sprintf(strtmp[4], "apntype=;");
1507 }
1508 else
1509 {
1510 sprintf(strtmp[4], "apntype=%s;", apntype);
1511 }
1512 if (user == NULL)
1513 {
1514 sprintf(strtmp[5], "user=;");
1515 }
1516 else
1517 {
1518 sprintf(strtmp[5], "user=%s;", user);
1519 }
1520 if (password == NULL)
1521 {
1522 sprintf(strtmp[6], "password=;");
1523 }
1524 else
1525 {
1526 sprintf(strtmp[6], "password=%s;", password);
1527 }
1528 if (normalprotocol == NULL)
1529 {
1530 sprintf(strtmp[7], "normalprotocol=;");
1531 }
1532 else
1533 {
1534 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1535 }
1536 if (roamingprotocol == NULL)
1537 {
1538 sprintf(strtmp[8], "roamingprotocol=;");
1539 }
1540 else
1541 {
1542 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1543 }
1544 if (carrier == NULL)
1545 {
1546 sprintf(strtmp[9], "carrier=;");
1547 }
1548 else
1549 {
1550 sprintf(strtmp[9], "carrier=%s;", carrier);
1551 }
1552 sprintf(agc, "%s%s%s%s%s%s%s%s%s%s", strtmp[0], strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]);
1553 return 0;
1554}
1555
rjwaf4b1612022-06-13 17:26:01 +08001556
1557int query_apn_char(char *agc, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier)
1558{
1559 char strtmp[10][32];
1560 if (id == NULL)
1561 {
1562 sprintf(strtmp[0], "");
1563 }
1564 else
1565 {
1566 sprintf(strtmp[0], "id=%s;", id);
1567 }
1568 if (mcc == NULL)
1569 {
1570 sprintf(strtmp[1], "");
1571 }
1572 else
1573 {
1574 sprintf(strtmp[1], "mcc=%s;", mcc);
1575 }
1576 if (mnc == NULL)
1577 {
1578 sprintf(strtmp[2], "");
1579 }
1580 else
1581 {
1582 sprintf(strtmp[2], "mnc=%s;", mnc);
1583 }
1584 if (apn == NULL)
1585 {
1586 sprintf(strtmp[3], "");
1587 }
1588 else
1589 {
1590 sprintf(strtmp[3], "apn=%s;", apn);
1591 }
1592 if (apntype == NULL)
1593 {
1594 sprintf(strtmp[4], "");
1595 }
1596 else
1597 {
1598 sprintf(strtmp[4], "apntype=%s;", apntype);
1599 }
1600 if (user == NULL)
1601 {
1602 sprintf(strtmp[5], "");
1603 }
1604 else
1605 {
1606 sprintf(strtmp[5], "user=%s;", user);
1607 }
1608 if (password == NULL)
1609 {
1610 sprintf(strtmp[6], "");
1611 }
1612 else
1613 {
1614 sprintf(strtmp[6], "password=%s;", password);
1615 }
1616 if (normalprotocol == NULL)
1617 {
1618 sprintf(strtmp[7], "");
1619 }
1620 else
1621 {
1622 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1623 }
1624 if (roamingprotocol == NULL)
1625 {
1626 sprintf(strtmp[8], "");
1627 }
1628 else
1629 {
1630 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1631 }
1632 if (carrier == NULL)
1633 {
1634 sprintf(strtmp[9], "");
1635 }
1636 else
1637 {
1638 sprintf(strtmp[9], "carrier=%s;", carrier);
1639 }
1640 sprintf(agc, "%s%s%s%s%s%s%s%s%s%s", strtmp[0], strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]);
1641 return 0;
1642}
1643
rjw20006d12022-04-21 16:29:04 +08001644static char *lynqStrdupReadString(Parcel &p)
1645{
1646 size_t stringlen;
1647 const char16_t *s16;
1648
1649 s16 = p.readString16Inplace(&stringlen);
1650 return strndup16to8(s16, stringlen);
1651}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001652int get_imsi()
1653{
Hong_Liu25edfe72023-06-16 01:13:42 -07001654 Parcel *p =NULL;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001655 lynq_client_t client;
1656 int resp_type = -1;
1657 int token;
1658 int request = -1;
1659 int slot_id = -1;
1660 int error = -1;
1661 int version =0;
1662 int num = 0;
1663 char *temp_char = NULL;
1664 char mccmnc[32] = {0};
1665 char mccmnckey[64] = {0};
Hong_Liu25edfe72023-06-16 01:13:42 -07001666 client.uToken = get_utoken();
Hong_Liu7163bbe2023-06-04 03:03:44 -07001667 client.request = 11;//RIL_REQUEST_GET_IMSI 11
1668 client.paramLen = 0;
1669 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1670 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1671 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1672 if(send_request(lynq_client_sockfd,&client)==-1)
1673 {
1674 LYERRLOG("send request fail");
1675 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001676 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001677 return -1;
1678 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001679 //get_response(lynq_client_sockfd,p);
1680 error = wait_response(lynq_client_sockfd,p,client.uToken);
1681 if(error!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001682 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001683 LYERRLOG("wait_response fail,ret:%d",error);
1684 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001685 return error;
1686 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001687 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1688 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001689 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001690 LYERRLOG("JumpHeader fail");
Hong_Liu7163bbe2023-06-04 03:03:44 -07001691 return -1;
1692 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001693 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1694 if(error == 0)
1695 {
1696 char * test = strdupReadString_p(p);
1697 memcpy(mccmnc, test,5);
1698 mccmnc[5]='\0';
1699 free(test);
1700 sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
1701 system(mccmnckey);
1702 system("uci commit");
1703 }
1704 free_parcel(p);
1705 return error;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001706}
rjw20006d12022-04-21 16:29:04 +08001707int lynq_modify_apn_db(const int cmd, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier, char *out)
1708{
1709 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1710 {
1711 LYERRLOG("There are no valid parameters");
1712 return -1;
1713 }
1714 lynq_client_t client;
1715 char argc[512];
Hong_Liu7163bbe2023-06-04 03:03:44 -07001716 int res = -1;
1717 int count = 0;
1718 while(count < 10)
1719 {
1720 res = get_imsi();
1721 if(res==0)
1722 {
1723 break;
1724 }
1725 sleep(1);
1726 count++;
1727 }
1728 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
rjw20006d12022-04-21 16:29:04 +08001729 if (cmd == 0) // insert apn db
1730 {
rjw61fcae32022-08-18 14:03:39 +08001731 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001732 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001733 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1734 client.paramLen = 2;
1735 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1736 sprintf(client.param, "%d %s", cmd, argc);
1737 }
rjw61fcae32022-08-18 14:03:39 +08001738 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001739 {
1740 if (NULL == id)
1741 {
1742 LYERRLOG("id is NULL!!!please input id: ");
1743 }
1744 sprintf(argc, "id=%s", id);
Hong_Liu25edfe72023-06-16 01:13:42 -07001745 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001746 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1747 client.paramLen = 2;
1748 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1749 sprintf(client.param, "%d %s", cmd, argc);
1750 }
rjw61fcae32022-08-18 14:03:39 +08001751 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001752 {
rjwaf4b1612022-06-13 17:26:01 +08001753 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001754 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001755 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1756 client.paramLen = 2;
1757 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1758 sprintf(client.param, "%d %s", cmd, argc);
1759 }
rjw61fcae32022-08-18 14:03:39 +08001760 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001761 {
1762 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001763 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001764 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1765 client.paramLen = 2;
1766 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1767 sprintf(client.param, "%d %s", cmd, argc);
1768 }
1769 else
1770 {
1771 LYERRLOG("incoming command is invalid");
1772 return -1;
1773 }
1774 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001775 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001776 if(send_request(lynq_client_sockfd,&client)==-1)
1777 {
1778 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001779 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001780 return -1;
1781 }
rjwed00d042022-05-25 09:18:16 +08001782 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001783 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001784 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001785 LYINFLOG(">>>>>output info:%s",out);
1786 return 0;
1787}
1788
1789int lynq_reset_apn(char *result)
1790{
rjw20006d12022-04-21 16:29:04 +08001791 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001792 if (NULL == result)
1793 {
1794 LYERRLOG("incoming paramters error");
1795 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001796 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001797 client.request = 2000 + 194;
1798 client.paramLen = 0;
1799 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1800 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001801 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001802 if (send_request(lynq_client_sockfd, &client) == -1)
1803 {
1804 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001805 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001806 return -1;
1807 }
rjwed00d042022-05-25 09:18:16 +08001808 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001809 waitApnResult();
1810 strcpy(result, g_lynq_apn_result);
1811 LYINFLOG(">>>>>result:%s",result);
1812 return 0;
1813}
1814
rjw3bcbbf12022-04-22 16:47:18 +08001815/*Typethree add for T800 platform 2022/04/21 end*/