blob: 70f6daad61099684cc59a8fbda5e0f67f3e23bdb [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();
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700785int check_apn_status();
786int radio_switch(int status);
lhf81a46f2022-02-13 23:57:37 -0800787int lynq_init_data(int uToken)
788{
rjw22947c22022-03-15 09:21:29 +0800789 if (g_lynq_data_init_flag == 1)
790 {
791 LYERRLOG("init twice is not allowed");
792 return -1;
793 }
794 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800795 int result = 0;
796 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800797 LYLOGSET(LOG_INFO);
798 LYLOGEINIT(USER_LOG_TAG);
799 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800800 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800801 if(result!=0)
802 {
803 LYERRLOG("init socket client fail!!!");
804 return -1;
805 }
rjw7ee7bb42023-01-18 11:34:28 +0800806 result = lynq_init_data_urc_thread();
807 if(result!=0)
808 {
809 LYERRLOG("init socket urc fail!!!");
810 return -1;
811 }
812
813 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800814 if(result!=0)
815 {
816 LYERRLOG("init socket urc fail!!!");
817 return -1;
818 }
819 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700820 LYINFLOG("[%s] radio on/off solution 20230724",__FUNCTION__);
Hong_Liu25edfe72023-06-16 01:13:42 -0700821 int count = 0;
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700822 while(count < 2)//try recover the network within 10s.
823 {
824 result = check_apn_status();
825 if(result==0)
826 {
827 break;
828 }
829 radio_switch(0);
830 sleep(1);
831 radio_switch(1);
832 sleep(3);
833 count++;
834 }
835 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
836 if(result!=0)
837 {
838 LYDBGLOG("lynq init call fail!!!");
839 return LYNQ_E_MD_NOT_READY;//
840 }
841 /* old
Hong_Liu25edfe72023-06-16 01:13:42 -0700842 while(count < 10)
843 {
844 result = get_imsi();
845 if(result==0)
846 {
847 break;
848 }
849 sleep(1);
850 count++;
851 }
852 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
853 if(result!=0)
854 {
855 LYDBGLOG("lynq init call fail!!!");
856 return LYNQ_E_MD_NOT_READY;//
857 }
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700858 */
lhf81a46f2022-02-13 23:57:37 -0800859 LYDBGLOG("lynq init call success!!!");
860 return 0;
861
862}
863int lynq_deinit_data()
864{
865 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800866 if (g_lynq_data_init_flag == 0)
867 {
868 LYERRLOG("deinit twice is not allowed");
869 return ret;
870 }
871 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800872 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
873 {
874 if(strlen(lynq_apn_table[i].apnType)!=0)
875 {
876 lynq_deactive_data_call(&i);
877 }
878 }
879 if(lynq_client_sockfd>0)
880 {
881 close(lynq_client_sockfd);
882 }
rjw7ee7bb42023-01-18 11:34:28 +0800883 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800884 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800885 {
rjw7ee7bb42023-01-18 11:34:28 +0800886 LYERRLOG("lynq_deinit_data_urc_thread fail");
887 return ret;
rjw22947c22022-03-15 09:21:29 +0800888 }
rjwc3d6e582023-03-28 17:19:11 +0800889 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
890 s_data_urc_wait_list.clear();
891 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800892 return 0;
893}
894int lynq_setup_data_call(int *handle)
895{
Hong_Liue54db8c2023-04-21 02:37:23 -0700896 int error = -1;
897 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
898 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
Hong_Liue9879152023-04-25 20:40:26 -0700899 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -0700900 #else
Hong_Liu25edfe72023-06-16 01:13:42 -0700901 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -0800902 lynq_client_t client;
903 int resp_type = -1;
904 int request = -1;
905 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -0800906 int lynq_data_call_id = 0;
907 if(handle==NULL)
908 {
909 LYERRLOG("handle is null!!!");
910 return LYNQ_E_NULL_ANONALY;
911 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700912 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -0800913 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
914 client.paramLen = 0;
915 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
916 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800917 lynq_data_call_id = updateApn("default");
918 if (lynq_data_call_id < 0)
919 {
920 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700921 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +0800922 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700923 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect.
924 //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate.
rjw733b9832023-04-03 10:20:08 +0800925 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800926 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800927 if(send_request(lynq_client_sockfd,&client)==-1)
928 {
929 LYERRLOG("send request fail");
930 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -0700931 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700932 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -0800933 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700934 //get_response(lynq_client_sockfd,p);
935 error = wait_response(lynq_client_sockfd,p,client.uToken);
936 if(error!=0)
937 {
938 LYERRLOG("wait_response fail,ret:%d",error);
939 printf_apn_table_debug(__FUNCTION__,__LINE__);
940 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
941 return error;
942 }
rjwed00d042022-05-25 09:18:16 +0800943 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liuaa7f4b32023-07-19 07:51:25 -0700944 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
Hong_Liu25edfe72023-06-16 01:13:42 -0700945 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -0800946 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800947 if(error==0)
948 {
rjwf9ec3832023-04-12 10:59:15 +0800949 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -0700950 if (waitDataCallstateChange(LYNQ_DATA_TIME_OUT) == ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -0800951 {
952 error = LYNQ_E_TIME_OUT;
953 LYERRLOG("timeout:wait data Call state fail!!!");
954 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -0700955 if (data_invaild_error == 1)
956 {
957 data_invaild_error = 0;
958 LYERRLOG("urc apn info error!!!");
959 return 8085;
960 }
961 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -0800962 return error;
963 }
lhf81a46f2022-02-13 23:57:37 -0800964 }
Hong_Liu6149f182023-05-12 02:15:14 -0700965 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liue54db8c2023-04-21 02:37:23 -0700966 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800967 return error;
968}
rjw7ee7bb42023-01-18 11:34:28 +0800969
lhf81a46f2022-02-13 23:57:37 -0800970int lynq_deactive_data_call(int *handle)
971{
Hong_Liu25edfe72023-06-16 01:13:42 -0700972 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -0800973 lynq_client_t client;
974 int resp_type = -1;
975 int request = -1;
976 int slot_id = -1;
977 int error = -1;
978 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800979 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800980 if(handle==NULL)
981 {
982 LYERRLOG("handle is null!!!");
983 return -1;
984 }
rjw1309e232022-07-22 09:54:06 +0800985 ret = handleCheck(*handle);
986 if (ret != 0)
987 {
988 LYERRLOG("incomming handle is invalid");
989 return -1;
990 }
991 lynq_data_call_id = *handle;
Hong_Liu25edfe72023-06-16 01:13:42 -0700992 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -0800993 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
Hong_Liue3d35262023-05-04 00:20:12 -0700994 client.paramLen = 0;
995 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
996 #ifdef GSW_RIL_CFG
997 client.paramLen = 1;
998 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
999 #else
1000 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -08001001 {
lhf81a46f2022-02-13 23:57:37 -08001002 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -08001003 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1004 }
Hong_Liue3d35262023-05-04 00:20:12 -07001005 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001006 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001007 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001008 if(send_request(lynq_client_sockfd,&client)==-1)
1009 {
1010 LYERRLOG("send request fail");
1011 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001012 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001013 return -1;
1014 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001015 //get_response(lynq_client_sockfd,p);
1016 error = wait_response(lynq_client_sockfd,p,client.uToken);
1017 if(error!=0)
1018 {
1019 LYERRLOG("wait_response fail,ret:%d",error);
1020 printf_apn_table_debug(__FUNCTION__,__LINE__);
1021 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1022 return error;
1023 }
rjwed00d042022-05-25 09:18:16 +08001024 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001025 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1026 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 -08001027 cleanOnceApnTable(lynq_data_call_id);
Hong_Liu6149f182023-05-12 02:15:14 -07001028 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liu25edfe72023-06-16 01:13:42 -07001029 if(error==0)
1030 {
1031 if(waitDeactived(20000)==ETIMEDOUT)
1032 {
1033 error = LYNQ_E_TIME_OUT;
1034 LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!");
1035 printf_apn_table_debug(__FUNCTION__,__LINE__);
1036 }
1037 }
1038 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001039 return error;
1040}
1041int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
1042{
Hong_Liu25edfe72023-06-16 01:13:42 -07001043 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001044 lynq_client_t client;
1045 int resp_type = -1;
1046 int request = -1;
1047 int slot_id = -1;
1048 int error = -1;
lhf81a46f2022-02-13 23:57:37 -08001049 int lynq_data_call_id = -1;
1050 char *argv[10] = {};
Hong_Liue54db8c2023-04-21 02:37:23 -07001051 #ifdef GSW_RIL_CFG
1052 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
1053 if(handle==NULL||apnType==NULL)
1054 {
1055 LYERRLOG("handle or apntype is null!!!");
1056 return -1;
1057 }
1058 #else
lhf81a46f2022-02-13 23:57:37 -08001059 if(handle==NULL||apn==NULL||apnType==NULL)
1060 {
1061 LYERRLOG("handle ,apn or apntype is null!!!");
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001062 return LYNQ_E_NULL_ANONALY;
lhf81a46f2022-02-13 23:57:37 -08001063 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001064 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001065 if(user==NULL)
1066 {
1067 argv[1] = "null";
1068 }
1069 else
1070 {
1071 argv[1] = user;
lh13586612022-01-11 21:58:58 -08001072 }
1073 if(password==NULL)
1074 {
lhf81a46f2022-02-13 23:57:37 -08001075 argv[2] = "null";
lh13586612022-01-11 21:58:58 -08001076 }
1077 else
1078 {
lhf81a46f2022-02-13 23:57:37 -08001079 argv[2] = password;
lh13586612022-01-11 21:58:58 -08001080 }
1081 if(authType==NULL)
1082 {
lhf81a46f2022-02-13 23:57:37 -08001083 argv[3] = "null";
lh13586612022-01-11 21:58:58 -08001084 }
1085 else
1086 {
lhf81a46f2022-02-13 23:57:37 -08001087 argv[3] = authType;
lh13586612022-01-11 21:58:58 -08001088 }
1089 if(normalProtocol==NULL)
1090 {
lhf81a46f2022-02-13 23:57:37 -08001091 argv[4] = "null";
lh13586612022-01-11 21:58:58 -08001092 }
1093 else
1094 {
lhf81a46f2022-02-13 23:57:37 -08001095 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -08001096 }
1097 if(roamingProtocol==NULL)
1098 {
lhf81a46f2022-02-13 23:57:37 -08001099 argv[5] = "null";
lh13586612022-01-11 21:58:58 -08001100 }
1101 else
1102 {
lhf81a46f2022-02-13 23:57:37 -08001103 argv[5] = roamingProtocol;
1104 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001105 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001106 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1107 client.paramLen = 7;
1108 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -07001109 #ifdef GSW_RIL_CFG
1110 if(NULL == apn)
1111 {
1112 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1113 }
1114 else
1115 {
1116 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1117 }
1118 #else
lhf81a46f2022-02-13 23:57:37 -08001119 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 -07001120 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001121 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +08001122 lynq_data_call_id = updateApn(apnType);
1123 if (lynq_data_call_id < 0)
1124 {
1125 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001126 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001127 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001128 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16)
rjw733b9832023-04-03 10:20:08 +08001129 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001130 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001131 if(send_request(lynq_client_sockfd,&client)==-1)
1132 {
1133 LYERRLOG("send request fail");
1134 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001135 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001136 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001137 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001138 //get_response(lynq_client_sockfd,p);
1139 error = wait_response(lynq_client_sockfd,p,client.uToken);
1140 if(error!=0)
1141 {
1142 LYERRLOG("wait_response fail,ret:%d",error);
1143 printf_apn_table_debug(__FUNCTION__,__LINE__);
1144 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1145 return error;
1146 }
rjwed00d042022-05-25 09:18:16 +08001147 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001148 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1149 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1150 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001151 if(error==0)
1152 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001153 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001154 if(waitDataCallstateChange(LYNQ_DATA_TIME_OUT)==ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001155 {
1156 error = LYNQ_E_TIME_OUT;
1157 LYERRLOG("timeout:wait data Call state fail!!!");
1158 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001159 if (data_invaild_error == 1)
1160 {
1161 data_invaild_error = 0;
1162 LYERRLOG("urc apn info error!!!");
1163 return 8085;
1164 }
1165 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001166 return error;
1167 }
lhf81a46f2022-02-13 23:57:37 -08001168 }
Hong_Liu6149f182023-05-12 02:15:14 -07001169 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001170 return error;
1171}
1172/*
1173int lynq_deactive_data_call_sp(int *handle,char *apnType)
1174{
1175 Parcel p;
1176 lynq_client_t client;
1177 int resp_type = -1;
1178 int request = -1;
1179 int slot_id = -1;
1180 int error = -1;
1181 if(handle==NULL||apnType==NULL)
1182 {
1183 LYERRLOG("handle is null!!!");
1184 return -1;
1185 }
1186 client.uToken = Global_uToken;
1187 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
1188 client.paramLen = 1;
1189 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1190 sprintf(client.param,"%s",apnType);
1191 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1192 if(send_request(lynq_client_sockfd,&client)==-1)
1193 {
1194 LYERRLOG("send request fail");
1195 perror("[LYNQ_DATA] send request fail:");
1196 return -1;
1197 }
1198 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +08001199 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -08001200 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1201 return error;
1202}
1203*/
1204int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
1205{
Hong_Liu25edfe72023-06-16 01:13:42 -07001206 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001207 lynq_client_t client;
1208 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001209 int token;
Hong_Liu25edfe72023-06-16 01:13:42 -07001210 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001211 int slot_id = -1;
1212 int error = -1;
1213 int version =0;
1214 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001215 char *temp_char = NULL;
1216 if(dataCallList==NULL)
1217 {
1218 LYERRLOG("dataCallList is null!!!");
1219 return -1;
1220 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001221 client.uToken = get_utoken();;
lhf81a46f2022-02-13 23:57:37 -08001222 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1223 client.paramLen = 0;
1224 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1225 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001226 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001227 if(send_request(lynq_client_sockfd,&client)==-1)
1228 {
1229 LYERRLOG("send request fail");
1230 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001231 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001232 return -1;
1233 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001234 //get_response(lynq_client_sockfd,p);
1235 error = wait_response(lynq_client_sockfd,p,client.uToken);
1236 if(error!=0)
1237 {
1238 LYERRLOG("wait_response fail,ret:%d",error);
1239 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1240 return error;
1241 }
rjwed00d042022-05-25 09:18:16 +08001242 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001243 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
rjwfa532972022-09-16 13:39:41 +08001244 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001245 LYERRLOG("JumpHeader fail");
rjwfa532972022-09-16 13:39:41 +08001246 return -1;
1247 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001248 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1249 p->readInt32(&version);
lhf81a46f2022-02-13 23:57:37 -08001250 if(version==11)
1251 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001252 p->readInt32(&num);
lhf81a46f2022-02-13 23:57:37 -08001253 *realNum = num;
1254 for (int i = 0; i < num; i++)
1255 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001256 p->readInt32(&dataCallList[i].status);
1257 p->readInt32(&dataCallList[i].suggestedRetryTime);
1258 p->readInt32(&dataCallList[i].cid);
1259 p->readInt32(&dataCallList[i].active);
1260 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001261 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1262 if(temp_char)
1263 {
1264 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1265 free(temp_char);
1266 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001267 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001268 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1269 if(temp_char)
1270 {
1271 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1272 free(temp_char);
1273 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001274 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001275 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1276 if(temp_char)
1277 {
1278 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1279 free(temp_char);
1280 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001281 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001282 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1283 if(temp_char)
1284 {
1285 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1286 free(temp_char);
1287 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001288 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001289 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1290 if(temp_char)
1291 {
1292 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1293 free(temp_char);
1294 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001295 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001296 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1297 if(temp_char)
1298 {
1299 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1300 free(temp_char);
1301 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001302 p->readInt32(&dataCallList[i].mtu);
lhf81a46f2022-02-13 23:57:37 -08001303 }
1304 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001305 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001306 return error;
1307}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001308
1309int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
1310{
1311 LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
1312 if((handle < 0) || (handle > 6) || (NULL == apn_msg))
1313 {
1314 LYERRLOG("handle value error,or apn_msg is null");
1315 return LYNQ_E_NULL_ANONALY;
1316 }
1317 apn_msg->handle = handle;
1318 if(apn_msg->apn!=NULL)
1319 {
1320 memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
1321 }
1322 if(apn_msg->apnType!=NULL)
1323 {
1324 memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
1325 }
1326 return 0;
1327}
1328
lhf81a46f2022-02-13 23:57:37 -08001329int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1330{
1331 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1332 int number = 0;
1333 int lynq_data_call_id = 0;
1334 int error = 0;
1335 lynq_data_call_id = *handle;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001336 if((handle==NULL) || (dataCallList==NULL))
lhf81a46f2022-02-13 23:57:37 -08001337 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001338 LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
lhf81a46f2022-02-13 23:57:37 -08001339 return LYNQ_E_NULL_ANONALY;
1340 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001341 if ((*handle < 0) || (*handle > 6))
rjw3938f262023-03-08 16:09:28 +08001342 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001343 LYERRLOG("[lynq_get_data_call_list] handle value error");
1344 return LYNQ_E_NULL_ANONALY;
rjw3938f262023-03-08 16:09:28 +08001345 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001346 LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001347 memset(interDataCallList,0,sizeof(interDataCallList));
1348 error = getDataCallLists(interDataCallList,&number);
1349 if(error == 0)
1350 {
1351 for(int i = 0;i < number;i++)
1352 {
1353 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1354 {
1355 dataCallList->active = interDataCallList[i].active;
1356 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1357 dataCallList->cid = interDataCallList[i].cid;
1358 dataCallList->status = interDataCallList[i].status;
1359 dataCallList->mtu = interDataCallList[i].mtu;
1360 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1361 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1362 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1363 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1364 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1365 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1366 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1367 }
1368 }
1369 }
1370 return error;
1371}
1372int lynq_wait_data_call_state_change(int *handle)
1373{
rjwc3d6e582023-03-28 17:19:11 +08001374 if (data_waiting_status == 1)
1375 {
1376 LYDBGLOG("some thread is waiting");
1377 return -3;
1378 }
1379 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1380 if (s_data_urc_wait_list.empty())
1381 {
1382 LYDBGLOG("start wait");
1383 data_waiting_status = 1;
1384 waitPdnChange();
1385 }
1386 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001387 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001388
1389 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1390 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001391 if (iter != s_data_urc_wait_list.end())
1392 {
1393 *handle = *iter;
1394 }
rjw7ee7bb42023-01-18 11:34:28 +08001395 s_data_urc_wait_list.erase(iter);
1396 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1397
Hong_Liudc46d412023-05-18 13:36:26 -07001398 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001399 return 0;
1400}
1401/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001402
1403/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001404
1405int 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 +08001406{
1407 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001408 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001409 {
rjw61fcae32022-08-18 14:03:39 +08001410 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001411 }
rjw61fcae32022-08-18 14:03:39 +08001412 else
rjw0cdacbc2022-06-22 10:51:07 +08001413 {
rjw61fcae32022-08-18 14:03:39 +08001414 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001415 }
rjw20006d12022-04-21 16:29:04 +08001416 if (mcc == NULL)
1417 {
1418 sprintf(strtmp[1], "mcc=;");
1419 }
1420 else
1421 {
1422 sprintf(strtmp[1], "mcc=%s;", mcc);
1423 }
1424 if (mnc == NULL)
1425 {
rjw61fcae32022-08-18 14:03:39 +08001426 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001427 }
1428 else
1429 {
1430 sprintf(strtmp[2], "mnc=%s;", mnc);
1431 }
1432 if (apn == NULL)
1433 {
1434 sprintf(strtmp[3], "apn=;");
1435 }
1436 else
1437 {
1438 sprintf(strtmp[3], "apn=%s;", apn);
1439 }
1440 if (apntype == NULL)
1441 {
1442 sprintf(strtmp[4], "apntype=;");
1443 }
1444 else
1445 {
1446 sprintf(strtmp[4], "apntype=%s;", apntype);
1447 }
1448 if (user == NULL)
1449 {
1450 sprintf(strtmp[5], "user=;");
1451 }
1452 else
1453 {
1454 sprintf(strtmp[5], "user=%s;", user);
1455 }
1456 if (password == NULL)
1457 {
1458 sprintf(strtmp[6], "password=;");
1459 }
1460 else
1461 {
1462 sprintf(strtmp[6], "password=%s;", password);
1463 }
1464 if (normalprotocol == NULL)
1465 {
1466 sprintf(strtmp[7], "normalprotocol=;");
1467 }
1468 else
1469 {
1470 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1471 }
1472 if (roamingprotocol == NULL)
1473 {
1474 sprintf(strtmp[8], "roamingprotocol=;");
1475 }
1476 else
1477 {
1478 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1479 }
1480 if (carrier == NULL)
1481 {
1482 sprintf(strtmp[9], "carrier=;");
1483 }
1484 else
1485 {
1486 sprintf(strtmp[9], "carrier=%s;", carrier);
1487 }
rjw61fcae32022-08-18 14:03:39 +08001488 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 +08001489
rjw20006d12022-04-21 16:29:04 +08001490 return 0;
1491}
1492
1493int 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)
1494{
1495 char strtmp[10][32];
1496 if (id == NULL)
1497 {
1498 sprintf(strtmp[0], "id=;");
1499 }
1500 else
1501 {
1502 sprintf(strtmp[0], "id=%s;", id);
1503 }
1504 if (mcc == NULL)
1505 {
1506 sprintf(strtmp[1], "mcc=;");
1507 }
1508 else
1509 {
1510 sprintf(strtmp[1], "mcc=%s;", mcc);
1511 }
1512 if (mnc == NULL)
1513 {
1514 sprintf(strtmp[2], "mnc=;");
1515 }
1516 else
1517 {
1518 sprintf(strtmp[2], "mnc=%s;", mnc);
1519 }
1520 if (apn == NULL)
1521 {
1522 sprintf(strtmp[3], "apn=;");
1523 }
1524 else
1525 {
1526 sprintf(strtmp[3], "apn=%s;", apn);
1527 }
1528 if (apntype == NULL)
1529 {
1530 sprintf(strtmp[4], "apntype=;");
1531 }
1532 else
1533 {
1534 sprintf(strtmp[4], "apntype=%s;", apntype);
1535 }
1536 if (user == NULL)
1537 {
1538 sprintf(strtmp[5], "user=;");
1539 }
1540 else
1541 {
1542 sprintf(strtmp[5], "user=%s;", user);
1543 }
1544 if (password == NULL)
1545 {
1546 sprintf(strtmp[6], "password=;");
1547 }
1548 else
1549 {
1550 sprintf(strtmp[6], "password=%s;", password);
1551 }
1552 if (normalprotocol == NULL)
1553 {
1554 sprintf(strtmp[7], "normalprotocol=;");
1555 }
1556 else
1557 {
1558 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1559 }
1560 if (roamingprotocol == NULL)
1561 {
1562 sprintf(strtmp[8], "roamingprotocol=;");
1563 }
1564 else
1565 {
1566 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1567 }
1568 if (carrier == NULL)
1569 {
1570 sprintf(strtmp[9], "carrier=;");
1571 }
1572 else
1573 {
1574 sprintf(strtmp[9], "carrier=%s;", carrier);
1575 }
1576 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]);
1577 return 0;
1578}
1579
rjwaf4b1612022-06-13 17:26:01 +08001580
1581int 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)
1582{
1583 char strtmp[10][32];
1584 if (id == NULL)
1585 {
1586 sprintf(strtmp[0], "");
1587 }
1588 else
1589 {
1590 sprintf(strtmp[0], "id=%s;", id);
1591 }
1592 if (mcc == NULL)
1593 {
1594 sprintf(strtmp[1], "");
1595 }
1596 else
1597 {
1598 sprintf(strtmp[1], "mcc=%s;", mcc);
1599 }
1600 if (mnc == NULL)
1601 {
1602 sprintf(strtmp[2], "");
1603 }
1604 else
1605 {
1606 sprintf(strtmp[2], "mnc=%s;", mnc);
1607 }
1608 if (apn == NULL)
1609 {
1610 sprintf(strtmp[3], "");
1611 }
1612 else
1613 {
1614 sprintf(strtmp[3], "apn=%s;", apn);
1615 }
1616 if (apntype == NULL)
1617 {
1618 sprintf(strtmp[4], "");
1619 }
1620 else
1621 {
1622 sprintf(strtmp[4], "apntype=%s;", apntype);
1623 }
1624 if (user == NULL)
1625 {
1626 sprintf(strtmp[5], "");
1627 }
1628 else
1629 {
1630 sprintf(strtmp[5], "user=%s;", user);
1631 }
1632 if (password == NULL)
1633 {
1634 sprintf(strtmp[6], "");
1635 }
1636 else
1637 {
1638 sprintf(strtmp[6], "password=%s;", password);
1639 }
1640 if (normalprotocol == NULL)
1641 {
1642 sprintf(strtmp[7], "");
1643 }
1644 else
1645 {
1646 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1647 }
1648 if (roamingprotocol == NULL)
1649 {
1650 sprintf(strtmp[8], "");
1651 }
1652 else
1653 {
1654 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1655 }
1656 if (carrier == NULL)
1657 {
1658 sprintf(strtmp[9], "");
1659 }
1660 else
1661 {
1662 sprintf(strtmp[9], "carrier=%s;", carrier);
1663 }
1664 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]);
1665 return 0;
1666}
1667
rjw20006d12022-04-21 16:29:04 +08001668static char *lynqStrdupReadString(Parcel &p)
1669{
1670 size_t stringlen;
1671 const char16_t *s16;
1672
1673 s16 = p.readString16Inplace(&stringlen);
1674 return strndup16to8(s16, stringlen);
1675}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001676int get_imsi()
1677{
Hong_Liu25edfe72023-06-16 01:13:42 -07001678 Parcel *p =NULL;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001679 lynq_client_t client;
1680 int resp_type = -1;
1681 int token;
1682 int request = -1;
1683 int slot_id = -1;
1684 int error = -1;
1685 int version =0;
1686 int num = 0;
1687 char *temp_char = NULL;
1688 char mccmnc[32] = {0};
1689 char mccmnckey[64] = {0};
Hong_Liu25edfe72023-06-16 01:13:42 -07001690 client.uToken = get_utoken();
Hong_Liu7163bbe2023-06-04 03:03:44 -07001691 client.request = 11;//RIL_REQUEST_GET_IMSI 11
1692 client.paramLen = 0;
1693 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1694 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1695 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1696 if(send_request(lynq_client_sockfd,&client)==-1)
1697 {
1698 LYERRLOG("send request fail");
1699 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001700 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001701 return -1;
1702 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001703 //get_response(lynq_client_sockfd,p);
1704 error = wait_response(lynq_client_sockfd,p,client.uToken);
1705 if(error!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001706 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001707 LYERRLOG("wait_response fail,ret:%d",error);
1708 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001709 return error;
1710 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001711 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1712 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001713 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001714 LYERRLOG("JumpHeader fail");
Hong_Liu7163bbe2023-06-04 03:03:44 -07001715 return -1;
1716 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001717 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1718 if(error == 0)
1719 {
1720 char * test = strdupReadString_p(p);
1721 memcpy(mccmnc, test,5);
1722 mccmnc[5]='\0';
1723 free(test);
1724 sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
1725 system(mccmnckey);
1726 system("uci commit");
1727 }
1728 free_parcel(p);
1729 return error;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001730}
rjw20006d12022-04-21 16:29:04 +08001731int 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)
1732{
1733 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1734 {
1735 LYERRLOG("There are no valid parameters");
1736 return -1;
1737 }
1738 lynq_client_t client;
1739 char argc[512];
Hong_Liu7163bbe2023-06-04 03:03:44 -07001740 int res = -1;
1741 int count = 0;
1742 while(count < 10)
1743 {
1744 res = get_imsi();
1745 if(res==0)
1746 {
1747 break;
1748 }
1749 sleep(1);
1750 count++;
1751 }
1752 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
rjw20006d12022-04-21 16:29:04 +08001753 if (cmd == 0) // insert apn db
1754 {
rjw61fcae32022-08-18 14:03:39 +08001755 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001756 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001757 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1758 client.paramLen = 2;
1759 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1760 sprintf(client.param, "%d %s", cmd, argc);
1761 }
rjw61fcae32022-08-18 14:03:39 +08001762 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001763 {
1764 if (NULL == id)
1765 {
1766 LYERRLOG("id is NULL!!!please input id: ");
1767 }
1768 sprintf(argc, "id=%s", id);
Hong_Liu25edfe72023-06-16 01:13:42 -07001769 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001770 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1771 client.paramLen = 2;
1772 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1773 sprintf(client.param, "%d %s", cmd, argc);
1774 }
rjw61fcae32022-08-18 14:03:39 +08001775 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001776 {
rjwaf4b1612022-06-13 17:26:01 +08001777 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001778 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001779 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1780 client.paramLen = 2;
1781 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1782 sprintf(client.param, "%d %s", cmd, argc);
1783 }
rjw61fcae32022-08-18 14:03:39 +08001784 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001785 {
1786 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001787 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001788 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1789 client.paramLen = 2;
1790 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1791 sprintf(client.param, "%d %s", cmd, argc);
1792 }
1793 else
1794 {
1795 LYERRLOG("incoming command is invalid");
1796 return -1;
1797 }
1798 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001799 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001800 if(send_request(lynq_client_sockfd,&client)==-1)
1801 {
1802 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001803 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001804 return -1;
1805 }
rjwed00d042022-05-25 09:18:16 +08001806 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001807 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001808 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001809 LYINFLOG(">>>>>output info:%s",out);
1810 return 0;
1811}
1812
1813int lynq_reset_apn(char *result)
1814{
rjw20006d12022-04-21 16:29:04 +08001815 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001816 if (NULL == result)
1817 {
1818 LYERRLOG("incoming paramters error");
1819 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001820 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001821 client.request = 2000 + 194;
1822 client.paramLen = 0;
1823 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1824 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001825 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001826 if (send_request(lynq_client_sockfd, &client) == -1)
1827 {
1828 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001829 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001830 return -1;
1831 }
rjwed00d042022-05-25 09:18:16 +08001832 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001833 waitApnResult();
1834 strcpy(result, g_lynq_apn_result);
1835 LYINFLOG(">>>>>result:%s",result);
1836 return 0;
1837}
1838
rjw3bcbbf12022-04-22 16:47:18 +08001839/*Typethree add for T800 platform 2022/04/21 end*/
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07001840static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) {
1841 FILE *fp;
1842 //printf("to exec cmd:%s\n", str_cmd);
1843 if((fp=popen(str_cmd,"r"))==NULL)
1844 {
1845 perror("popen error!");
1846 return -1;
1847 }
1848 if((fread(str_cmd_ret,max_len,1,fp))<0)
1849 {
1850 perror("fread fail!");
1851 fclose(fp);
1852 return -1;
1853 }
1854 fclose(fp);
1855 return 0;
1856}
1857int check_apn_status()
1858{
1859 LYINFLOG("check_apn_status enter");
1860 int ret = -1;
1861 char cmd_ret[8] ={0};//get mccmnc
1862 const char *cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc0";
1863 const char *empty_str = ":empty";
1864 ret = exec_cmd(cmd,cmd_ret,8);
1865 if(ret==0)
1866 {
1867 if(strlen(cmd_ret)==0)
1868 {
1869 LYERRLOG("not have mccmnc config in uci ram");
1870 return 1;
1871 }
1872 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
1873 {
1874 LYERRLOG("mccmnc is empty");
1875 return 2;
1876 }
1877 LYINFLOG("mccmnc is %s",cmd_ret);
1878 return 0;
1879 }
1880 else
1881 {
1882 LYERRLOG("exec cmd fail");
1883 return -1;
1884 }
1885 return 0;
1886}
1887int radio_switch(int status)
1888{
1889 Parcel *p =NULL;
1890 lynq_client_t client;
1891 int resp_type = -1;
1892 int token;
1893 int request = -1;
1894 int slot_id = -1;
1895 int error = -1;
1896 int version =0;
1897 int num = 0;
1898 char *temp_char = NULL;
1899 char mccmnc[32] = {0};
1900 char mccmnckey[64] = {0};
1901 client.uToken = get_utoken();
1902 client.request = 59;//RIL_REQUEST_OEM_HOOK_RAW 59
1903 client.paramLen = 1;
1904 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1905 sprintf(client.param,"AT+CFUN=%d",status);
1906 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1907 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1908 if(send_request(lynq_client_sockfd,&client)==-1)
1909 {
1910 LYERRLOG("send request fail");
1911 perror("[LYNQ_DATA] send request fail:");
1912 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1913 return -1;
1914 }
1915 //get_response(lynq_client_sockfd,p);
1916 error = wait_response(lynq_client_sockfd,p,client.uToken);
1917 if(error!=0)
1918 {
1919 LYERRLOG("wait_response fail,ret:%d",error);
1920 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1921 return error;
1922 }
1923 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1924 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
1925 {
1926 LYERRLOG("JumpHeader fail");
1927 return -1;
1928 }
1929 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1930 free_parcel(p);
1931 return error;
1932}