blob: b7498a6568598378b122cc6867a0c534c21edf66 [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}
Hong_Liu55c62f52023-08-24 19:05:50 -0700235//@return
236//other:this apn has been used in apn table
237//-1:this apn not has been used in apn table
238int check_used_apn(char apnType[])
239{
240 LYINFLOG("check_used_apn.apnType:%s",apnType);
241 int ret = 0;
242 int len = 0;
243 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
244 {
245 len = strlen(apnType);
246 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
247 {
248 LYINFLOG("check_used_apn.apnType:%s in apn table",apnType);
249 return ret;
250 }
251 }
252 return -1;
253}
254int get_handle(char apnType[])
255{
256 int call_id = 0;
257 call_id = check_used_apn(apnType);
258 if(call_id == -1)
259 {
260 call_id = updateApn(apnType);
261 }
262 LYINFLOG("handle:%d",call_id);
263 return call_id;
264}
rjw1309e232022-07-22 09:54:06 +0800265
266int handleCheck(int handle)
267{
Hong_Liu7163bbe2023-06-04 03:03:44 -0700268 if ((handle >= 0) && (handle <= 6))
rjw1309e232022-07-22 09:54:06 +0800269 {
Hong_Liu7163bbe2023-06-04 03:03:44 -0700270 if (lynq_apn_table[handle].hasUsed == 1)
271 {
272 return 0;
273 }
rjw1309e232022-07-22 09:54:06 +0800274 return -1;
275 }
Hong_Liu7163bbe2023-06-04 03:03:44 -0700276 return -1;
rjw1309e232022-07-22 09:54:06 +0800277}
rjw20006d12022-04-21 16:29:04 +0800278int waitApnResult()
279{
280 int ret = 0;
281 LYINFLOG("start wait apn result!!!");
282 int sec = 0;
283 int usec = 0;
284 struct timeval now;
285 struct timespec timeout;
286 gettimeofday(&now, NULL);
287 sec = 20000 / 1000;
288 usec = 20000 % 1000;
289 timeout.tv_sec = now.tv_sec + sec;
290 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
291 pthread_mutex_lock(&s_lynq_apn_change_mutex);
292 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
293 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
294 return ret;
295}
296
297void sendSignalApnChange()
298{
299 LYINFLOG("start send Signal Apn Change");
300 pthread_mutex_lock(&s_lynq_apn_change_mutex);
301 pthread_cond_signal(&s_lynq_apn_change_cond);
302 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
303 return;
304}
lhf81a46f2022-02-13 23:57:37 -0800305
306int waitPdnChange()
307{
308 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800309 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
310 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
311 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800312 return ret;
313}
314int waitDataCallstateChange(int mtime)
315{
316 int ret = 0;
317 int sec = 0;
318 int usec = 0;
319 struct timeval now;
320 struct timespec timeout;
321 gettimeofday(&now,NULL);
322 sec = mtime/1000;
323 usec = mtime%1000;
324 timeout.tv_sec = now.tv_sec+sec;
325 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
326 pthread_mutex_lock(&s_data_call_state_change_mutex);
327 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
328 pthread_mutex_unlock(&s_data_call_state_change_mutex);
329 return ret;
330}
331void sendSignalDataCallStateChange()
332{
333 pthread_mutex_lock(&s_data_call_state_change_mutex);
334 pthread_cond_signal(&s_data_call_state_change_cond);
335 pthread_mutex_unlock(&s_data_call_state_change_mutex);
336 return;
337}
Hong_Liu25edfe72023-06-16 01:13:42 -0700338int waitDeactived(int mtime)
339{
340 int ret = 0;
341 int sec = 0;
342 int usec = 0;
343 struct timeval now;
344 struct timespec timeout;
345 gettimeofday(&now,NULL);
346 sec = mtime/1000;
347 usec = mtime%1000;
348 timeout.tv_sec = now.tv_sec+sec;
349 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
350 pthread_mutex_lock(&s_data_call_deactived_mutex);
351 ret = pthread_cond_timedwait(&s_data_call_deactived_cond,&s_data_call_deactived_mutex,&timeout);
352 pthread_mutex_unlock(&s_data_call_deactived_mutex);
353 return ret;
354}
355void sendSignalDeactvied()
356{
357 pthread_mutex_lock(&s_data_call_deactived_mutex);
358 pthread_cond_signal(&s_data_call_deactived_cond);
359 pthread_mutex_unlock(&s_data_call_deactived_mutex);
360 return;
361}
362
lhf81a46f2022-02-13 23:57:37 -0800363void sendSignalPdnChange()
364{
rjw7ee7bb42023-01-18 11:34:28 +0800365 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
366 pthread_cond_signal(&s_lynq_urc_vector_cond);
367 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800368 return;
369}
370
371int get_response(int sockfd,Parcel &p)
372{
373 int len = 0;
374 char recvline[LYNQ_REC_BUF];
375 bzero(recvline,LYNQ_REC_BUF);
376 /* receive data from server */
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700377 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
378 //len = read(sockfd, recvline, LYNQ_REC_BUF);
rjw08528682022-07-04 21:28:02 +0800379 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800380 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700381 LYERRLOG("get_response fail,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800382 return -1;
383 }
384 if (recvline != NULL) {
385 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
386 p.setDataPosition(0);
387 }
388 return 0;
389}
Hong_Liu25edfe72023-06-16 01:13:42 -0700390/**@brief get utoken in range 0 to 10000
391* @return utoken
392*/
393int get_utoken()
lhf81a46f2022-02-13 23:57:37 -0800394{
Hong_Liu25edfe72023-06-16 01:13:42 -0700395 return (Global_uToken++)%10000;/*0-10000*/
396}
397/**@brief wait response with expected token and write msg to parcel in some time
398* @param fd [IN]: socket fd
399* @param p [OUT]: quote the parcel,if return success need delete p.
400* @param token [IN]: the expected token for the response msg
401* @return
402* 0:success
403* other:failure
404*/
405int wait_response(int sockfd,Parcel *& p,int utoken)
406{
407 int len = 0;
408 int flag = 1;
409 int count = 0;
410 int in_utoken = -1;
411 int resp_type = -1;
412 Parcel *temp = NULL;
413 char recvline[LYNQ_REC_BUF];
414 //Sometimes the socket is abnormal, causing the socket buffer to store the response of the last request.
415 //Here it does not return until the response corresponding to the request is read.
416 while(flag && (count < 20))//why?
lhf81a46f2022-02-13 23:57:37 -0800417 {
Hong_Liu25edfe72023-06-16 01:13:42 -0700418 bzero(recvline,LYNQ_REC_BUF);
419 count++;
420 LYINFLOG("wait_response,count:%d",count);
421 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
422 if(len == -1)
423 {
424 LYERRLOG("wait_response fail,errno:%d",errno);
425 return LYNQ_E_GET_RESP_FAIL;
426 }
427 if (len != 0)
428 {
429 temp = new Parcel;
430 int i = 0;
431 while((NULL == temp) && (i < 100))
432 {
433 usleep(1000);
434 temp = new Parcel;
435 i++;
436 }
437 if((i >= 100) || (NULL == temp))
438 {
439 LYERRLOG("wait_response i:%d",i);
440 return LYNQ_E_GET_RESP_FAIL;
441 }
442 temp->setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
443 temp->setDataPosition(0);
444 temp->readInt32(&resp_type);
445 temp->readInt32(&in_utoken);
446 LYINFLOG("[%s]in_utoken:%d,utoken:%d",__FUNCTION__,in_utoken,utoken);
447 if (in_utoken != utoken)
448 {
449 delete temp;
450 temp = NULL;
451 in_utoken = 0;
452 continue;
453 }
454 temp->setDataPosition(0);
455 p = temp;
456 flag = 0;
457 return 0;
458 }
459 else
460 {
461 LYERRLOG("recvline is null,errno:%d",errno);
462 return LYNQ_E_GET_RESP_FAIL;
463 }
464 }
465 return LYNQ_E_GET_RESP_FAIL;
466}
467
468int JumpHeader(Parcel *p,int *resp_type,int *utoken,int *request,int *slot_id,int *error)
469{
470 if(NULL == p)
471 {
472 LYERRLOG("JumpHeader is null");
473 return -1;
474 }
475 if(p->dataAvail() > 0)
476 {
477 p->readInt32(resp_type);
478 p->readInt32(utoken);
479 p->readInt32(request);
480 p->readInt32(slot_id);
481 p->readInt32(error);
lhf81a46f2022-02-13 23:57:37 -0800482 return 0;
483 }
484 else
485 {
486 return -1;
487 }
488}
Hong_Liu25edfe72023-06-16 01:13:42 -0700489void free_parcel(Parcel *p)
490{
491 if(p)
492 {
493 delete p;
494 p = NULL;
495 }
496}
lhf81a46f2022-02-13 23:57:37 -0800497int send_request(int sockfd,lynq_client_t *client_tmp)
498{
499 int ret=0;
500 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
501 if(ret==-1)
502 {
503 perror("write error");
504 return -1;
505 }
506 return 0;
507}
508static char *strdupReadString(Parcel &p) {
509 size_t stringlen;
510 const char16_t *s16;
511 s16 = p.readString16Inplace(&stringlen);
512 return strndup16to8(s16, stringlen);
513}
514static char *strdupReadString_p(Parcel *p) {
515 size_t stringlen;
516 const char16_t *s16;
517 s16 = p->readString16Inplace(&stringlen);
518 return strndup16to8(s16, stringlen);
519}
520
lhf81a46f2022-02-13 23:57:37 -0800521/*Warren add for T800 platform 2021/11/19 start*/
522int lynq_socket_client_start()
523{
lhf81a46f2022-02-13 23:57:37 -0800524 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800525 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
526 lynq_data_socket_server_addr.sin_family = AF_INET;
527 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
jb.qice04d002023-05-16 18:28:06 -0700528 lynq_data_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700529 lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr);
lhf81a46f2022-02-13 23:57:37 -0800530 /*
531 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
532 {
533 printf("[%s] is not a valid IPaddress\n", argv[1]);
534 exit(1);
535 }
536*/
537 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800538 struct timeval timeOut;
539
rjwa59bf312022-07-05 11:50:31 +0800540 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800541 timeOut.tv_usec = 0;
542
543 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
544 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700545 LYERRLOG("time out setting failed");
rjw747deea2022-07-01 18:25:30 +0800546 }
547 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 -0800548 {
549 perror("connect error");
550 return -1;
551 }
552 return 0;
553}
rjw7ee7bb42023-01-18 11:34:28 +0800554
555bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800556{
rjw7ee7bb42023-01-18 11:34:28 +0800557 switch(urc_id)
558 {
559 case LYNQ_URC_DATA_CALL_STATUS_IND:
560
561 case LYNQ_URC_MODIFY_APNDB:
562 case LYNQ_URC_RESET_APNDB:
563 return true;
564 default:
565 return false;
566 }
567}
568
rjwc63abb42023-03-31 18:22:42 +0800569int printf_apn_table()
570{
571 int ret = 0;
Hong_Liu6149f182023-05-12 02:15:14 -0700572 if (lynq_apn_table == NULL)
573 {
574 LYERRLOG("apn table is null");
575 return -1;
576 }
rjwc63abb42023-03-31 18:22:42 +0800577 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
578 {
Hong_Liudc46d412023-05-18 13:36:26 -0700579 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 +0800580 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
Hong_Liudc46d412023-05-18 13:36:26 -0700581 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 +0800582 }
583 return 0;
584}
585
Hong_Liu6149f182023-05-12 02:15:14 -0700586void printf_apn_table_debug(const char *fun,int line)
587{
588 LYINFLOG("[%s][%d]apn_table msg",fun,line);
589 printf_apn_table();
590}
rjwc63abb42023-03-31 18:22:42 +0800591
rjw7ee7bb42023-01-18 11:34:28 +0800592void urc_msg_process(Parcel *p)
593{
594 int len;
595 int resp_type;
596 int urcid;
597 int slot_id;
rjwf9ec3832023-04-12 10:59:15 +0800598 int check_count = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700599 static int apnId=-1;
rjw7ee7bb42023-01-18 11:34:28 +0800600
601 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800602 char apn[LYNQ_APN_MAX_LEN];
603 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800604 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800605 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800606
607 int size = p->dataSize();
608 p->readInt32(&resp_type);
609 p->readInt32(&urcid);
610 p->readInt32(&slot_id);
611 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
612 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800613 {
rjw7ee7bb42023-01-18 11:34:28 +0800614 case LYNQ_URC_DATA_CALL_STATUS_IND:
615 p->readInt32(&pdnState);
616 bzero(apn,LYNQ_APN_MAX_LEN);
617 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
618 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
619 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800620 {
rjw20006d12022-04-21 16:29:04 +0800621 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800622 int len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700623 if((len < LYNQ_APN_MAX_LEN-1) && (len > 0))
rjw20006d12022-04-21 16:29:04 +0800624 {
rjw7ee7bb42023-01-18 11:34:28 +0800625 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800626 }
Hong_Liu6149f182023-05-12 02:15:14 -0700627 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800628 urc_msg = strdupReadString_p(p);
629 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700630 if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800631 {
632 memcpy(apnType,urc_msg,len+1);
633 }
Hong_Liu6149f182023-05-12 02:15:14 -0700634 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800635 urc_msg = strdupReadString_p(p);
636 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700637 if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800638 {
639 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
640 }
Hong_Liu6149f182023-05-12 02:15:14 -0700641 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800642 //sendSignalDataCallStateChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700643 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800644 if(apnId >= 0)
645 {
Hong_Liudc46d412023-05-18 13:36:26 -0700646 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800647 if(lynq_apn_table[apnId].hasTimeout==1)
648 {
rjwc63abb42023-03-31 18:22:42 +0800649 /*whether timeout?,real or not,*/
650 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800651 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800652 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 +0800653 {
654 LYERRLOG("deactive this time out APN");
655 lynq_deactive_data_call(&apnId);
656 }
rjwc63abb42023-03-31 18:22:42 +0800657 else
rjw7ee7bb42023-01-18 11:34:28 +0800658 {
rjwc63abb42023-03-31 18:22:42 +0800659 /*if apn lose,update apn and deactive all apn*/
660 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800661 }
662 break;
663 }
rjwacdb2152023-02-07 14:12:49 +0800664 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
Hong_Liu6149f182023-05-12 02:15:14 -0700665 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800666 }
667 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800668 else
669 {
Hong_Liu6149f182023-05-12 02:15:14 -0700670 data_invaild_error = 1;
Hong_Liudc46d412023-05-18 13:36:26 -0700671 printf_apn_table_debug(__FUNCTION__,__LINE__);
672 apnId = getDeactApnID(apnType);
673 if(apnId < 0)
674 {
675 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
676 break;
677 }
678 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
679 updateDeactApn(apnId,pdnState);
680 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800681 }
rjw7ee7bb42023-01-18 11:34:28 +0800682 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
683 s_data_urc_wait_list.push_back(apnId);
684 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
685 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800686 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800687 LYDBGLOG("data call state:%d",lynq_data_call);
688 if(lynq_data_call==1)
689 {
rjwf9ec3832023-04-12 10:59:15 +0800690 while (data_timelimit == 0)
691 {
692 LYINFLOG("client not ready to wait");
693 for (check_count = 0;check_count < 500;check_count++)
694 {
695 /*wait 10ms*/
696 usleep(10*1000);
697 }
698 LYERRLOG("client still without res");
699 break;
700 }
rjw7ee7bb42023-01-18 11:34:28 +0800701 sendSignalDataCallStateChange();
702 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800703 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800704 }
Hong_Liu6149f182023-05-12 02:15:14 -0700705 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800706 }
rjw7ee7bb42023-01-18 11:34:28 +0800707 else
rjw20006d12022-04-21 16:29:04 +0800708 {
rjw7ee7bb42023-01-18 11:34:28 +0800709 urc_msg = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -0700710 free(urc_msg);
711 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800712 len = strlen(urc_msg);
713 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
714 {
715 memcpy(apnType,urc_msg,len+1);
716 }
Hong_Liu6149f182023-05-12 02:15:14 -0700717 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800718 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
Hong_Liudc46d412023-05-18 13:36:26 -0700719 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800720 if(apnId >= 0)
721 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700722 LYINFLOG("[%d]URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",__LINE__,apnType,ifaceName,apn,pdnState,apnId);
Hong_Liudc46d412023-05-18 13:36:26 -0700723 lynq_data_call_change_id = apnId;
724 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
725 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
726 s_data_urc_wait_list.push_back(apnId);
727 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
728 sendSignalPdnChange();
729 }
730 else
731 {
732 apnId = getDeactApnID(apnType);
733 if(apnId < 0)
734 {
735 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
736 break;
737 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700738 LYINFLOG("[%d]URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",__LINE__,apnType,ifaceName,apn,pdnState,apnId);
Hong_Liudc46d412023-05-18 13:36:26 -0700739 cleanDeactApn(apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800740 lynq_data_call_change_id = apnId;
741 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800742 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
743 s_data_urc_wait_list.push_back(apnId);
744 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -0700745 sendSignalDeactvied();
rjwc3d6e582023-03-28 17:19:11 +0800746 sendSignalPdnChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700747 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800748 }
rjw7ee7bb42023-01-18 11:34:28 +0800749 LYDBGLOG("data call state:%d",lynq_data_call);
750 if(lynq_data_call==1)
751 {
rjwf9ec3832023-04-12 10:59:15 +0800752 while (data_timelimit == 0)
753 {
754 LYINFLOG("client not ready to wait");
755 for (check_count = 0;check_count < 500;check_count++)
756 {
757 /*wait 10ms*/
758 usleep(10*1000);
759 }
760 LYERRLOG("client still without res");
761 break;
762 }
rjw7ee7bb42023-01-18 11:34:28 +0800763 sendSignalDataCallStateChange();
764 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800765 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800766 }
Hong_Liu6149f182023-05-12 02:15:14 -0700767 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800768 }
769 break;
770 case LYNQ_URC_MODIFY_APNDB:
771 urc_msg = strdupReadString_p(p);
772 if (NULL == urc_msg)
773 {
774 LYERRLOG("error apn msg");
775 }
776 else
777 {
778 bzero(g_lynq_apn_result, 1024);
779 strcpy(g_lynq_apn_result, urc_msg);
780 sendSignalApnChange();
781 }
Hong_Liu6149f182023-05-12 02:15:14 -0700782 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800783 break;
784 case LYNQ_URC_RESET_APNDB:
785 {
rjw20006d12022-04-21 16:29:04 +0800786 urc_msg = strdupReadString_p(p);
787 if (NULL == urc_msg)
788 {
789 LYERRLOG("error apn msg");
790 }
791 else
792 {
793 bzero(g_lynq_apn_result, 1024);
794 strcpy(g_lynq_apn_result, urc_msg);
795 sendSignalApnChange();
796 }
Hong_Liu6149f182023-05-12 02:15:14 -0700797 free(urc_msg);
rjw20006d12022-04-21 16:29:04 +0800798 }
rjw7ee7bb42023-01-18 11:34:28 +0800799 default:
800 break;
lhf81a46f2022-02-13 23:57:37 -0800801 }
rjw7ee7bb42023-01-18 11:34:28 +0800802
lhf81a46f2022-02-13 23:57:37 -0800803}
rjw7ee7bb42023-01-18 11:34:28 +0800804
rjw7ee7bb42023-01-18 11:34:28 +0800805int create_urc_vector_signal_thread()
806{
807 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800808 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800809 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
810 s_data_urc_wait_list.clear();
811 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800812 return 0;
813}
Hong_Liu25edfe72023-06-16 01:13:42 -0700814int get_imsi();
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700815int check_apn_status();
816int radio_switch(int status);
lhf81a46f2022-02-13 23:57:37 -0800817int lynq_init_data(int uToken)
818{
rjw22947c22022-03-15 09:21:29 +0800819 if (g_lynq_data_init_flag == 1)
820 {
821 LYERRLOG("init twice is not allowed");
822 return -1;
823 }
824 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800825 int result = 0;
826 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800827 LYLOGSET(LOG_INFO);
828 LYLOGEINIT(USER_LOG_TAG);
829 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800830 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800831 if(result!=0)
832 {
833 LYERRLOG("init socket client fail!!!");
834 return -1;
835 }
rjw7ee7bb42023-01-18 11:34:28 +0800836 result = lynq_init_data_urc_thread();
837 if(result!=0)
838 {
839 LYERRLOG("init socket urc fail!!!");
840 return -1;
841 }
842
843 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800844 if(result!=0)
845 {
846 LYERRLOG("init socket urc fail!!!");
847 return -1;
848 }
849 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700850 LYINFLOG("[%s] radio on/off solution 20230724",__FUNCTION__);
Hong_Liu25edfe72023-06-16 01:13:42 -0700851 int count = 0;
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700852 while(count < 2)//try recover the network within 10s.
853 {
854 result = check_apn_status();
855 if(result==0)
856 {
857 break;
858 }
859 radio_switch(0);
860 sleep(1);
861 radio_switch(1);
862 sleep(3);
863 count++;
864 }
865 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
866 if(result!=0)
867 {
868 LYDBGLOG("lynq init call fail!!!");
869 return LYNQ_E_MD_NOT_READY;//
870 }
871 /* old
Hong_Liu25edfe72023-06-16 01:13:42 -0700872 while(count < 10)
873 {
874 result = get_imsi();
875 if(result==0)
876 {
877 break;
878 }
879 sleep(1);
880 count++;
881 }
882 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
883 if(result!=0)
884 {
885 LYDBGLOG("lynq init call fail!!!");
886 return LYNQ_E_MD_NOT_READY;//
887 }
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700888 */
lhf81a46f2022-02-13 23:57:37 -0800889 LYDBGLOG("lynq init call success!!!");
890 return 0;
891
892}
893int lynq_deinit_data()
894{
895 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800896 if (g_lynq_data_init_flag == 0)
897 {
898 LYERRLOG("deinit twice is not allowed");
899 return ret;
900 }
901 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800902 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
903 {
904 if(strlen(lynq_apn_table[i].apnType)!=0)
905 {
906 lynq_deactive_data_call(&i);
907 }
908 }
909 if(lynq_client_sockfd>0)
910 {
911 close(lynq_client_sockfd);
912 }
rjw7ee7bb42023-01-18 11:34:28 +0800913 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800914 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800915 {
rjw7ee7bb42023-01-18 11:34:28 +0800916 LYERRLOG("lynq_deinit_data_urc_thread fail");
917 return ret;
rjw22947c22022-03-15 09:21:29 +0800918 }
rjwc3d6e582023-03-28 17:19:11 +0800919 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
920 s_data_urc_wait_list.clear();
921 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800922 return 0;
923}
924int lynq_setup_data_call(int *handle)
925{
Hong_Liue54db8c2023-04-21 02:37:23 -0700926 int error = -1;
927 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
928 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
Hong_Liue9879152023-04-25 20:40:26 -0700929 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -0700930 #else
Hong_Liu25edfe72023-06-16 01:13:42 -0700931 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -0800932 lynq_client_t client;
933 int resp_type = -1;
934 int request = -1;
935 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -0800936 int lynq_data_call_id = 0;
937 if(handle==NULL)
938 {
939 LYERRLOG("handle is null!!!");
940 return LYNQ_E_NULL_ANONALY;
941 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700942 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -0800943 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
944 client.paramLen = 0;
945 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
946 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -0700947 lynq_data_call_id = get_handle("default");
rjwc63abb42023-03-31 18:22:42 +0800948 if (lynq_data_call_id < 0)
949 {
950 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700951 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +0800952 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700953 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect.
954 //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate.
rjw733b9832023-04-03 10:20:08 +0800955 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800956 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800957 if(send_request(lynq_client_sockfd,&client)==-1)
958 {
959 LYERRLOG("send request fail");
960 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -0700961 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700962 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -0800963 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700964 //get_response(lynq_client_sockfd,p);
965 error = wait_response(lynq_client_sockfd,p,client.uToken);
966 if(error!=0)
967 {
968 LYERRLOG("wait_response fail,ret:%d",error);
969 printf_apn_table_debug(__FUNCTION__,__LINE__);
970 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
971 return error;
972 }
rjwed00d042022-05-25 09:18:16 +0800973 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liuaa7f4b32023-07-19 07:51:25 -0700974 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
Hong_Liu25edfe72023-06-16 01:13:42 -0700975 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -0800976 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800977 if(error==0)
978 {
rjwf9ec3832023-04-12 10:59:15 +0800979 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -0700980 if (waitDataCallstateChange(LYNQ_DATA_TIME_OUT) == ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -0800981 {
982 error = LYNQ_E_TIME_OUT;
983 LYERRLOG("timeout:wait data Call state fail!!!");
984 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -0700985 if (data_invaild_error == 1)
986 {
987 data_invaild_error = 0;
988 LYERRLOG("urc apn info error!!!");
989 return 8085;
990 }
991 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -0800992 return error;
993 }
lhf81a46f2022-02-13 23:57:37 -0800994 }
Hong_Liu6149f182023-05-12 02:15:14 -0700995 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liue54db8c2023-04-21 02:37:23 -0700996 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800997 return error;
998}
rjw7ee7bb42023-01-18 11:34:28 +0800999
lhf81a46f2022-02-13 23:57:37 -08001000int lynq_deactive_data_call(int *handle)
1001{
Hong_Liu25edfe72023-06-16 01:13:42 -07001002 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001003 lynq_client_t client;
1004 int resp_type = -1;
1005 int request = -1;
1006 int slot_id = -1;
1007 int error = -1;
1008 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +08001009 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -08001010 if(handle==NULL)
1011 {
1012 LYERRLOG("handle is null!!!");
1013 return -1;
1014 }
rjw1309e232022-07-22 09:54:06 +08001015 ret = handleCheck(*handle);
1016 if (ret != 0)
1017 {
1018 LYERRLOG("incomming handle is invalid");
1019 return -1;
1020 }
1021 lynq_data_call_id = *handle;
Hong_Liu25edfe72023-06-16 01:13:42 -07001022 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001023 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
Hong_Liue3d35262023-05-04 00:20:12 -07001024 client.paramLen = 0;
1025 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1026 #ifdef GSW_RIL_CFG
1027 client.paramLen = 1;
1028 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1029 #else
1030 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -08001031 {
lhf81a46f2022-02-13 23:57:37 -08001032 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -08001033 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1034 }
Hong_Liue3d35262023-05-04 00:20:12 -07001035 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001036 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001037 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001038 if(send_request(lynq_client_sockfd,&client)==-1)
1039 {
1040 LYERRLOG("send request fail");
1041 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001042 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001043 return -1;
1044 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001045 //get_response(lynq_client_sockfd,p);
1046 error = wait_response(lynq_client_sockfd,p,client.uToken);
1047 if(error!=0)
1048 {
1049 LYERRLOG("wait_response fail,ret:%d",error);
1050 printf_apn_table_debug(__FUNCTION__,__LINE__);
1051 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1052 return error;
1053 }
rjwed00d042022-05-25 09:18:16 +08001054 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001055 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1056 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 -08001057 cleanOnceApnTable(lynq_data_call_id);
Hong_Liu6149f182023-05-12 02:15:14 -07001058 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liu25edfe72023-06-16 01:13:42 -07001059 if(error==0)
1060 {
1061 if(waitDeactived(20000)==ETIMEDOUT)
1062 {
1063 error = LYNQ_E_TIME_OUT;
1064 LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!");
1065 printf_apn_table_debug(__FUNCTION__,__LINE__);
1066 }
1067 }
1068 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001069 return error;
1070}
1071int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
1072{
Hong_Liu25edfe72023-06-16 01:13:42 -07001073 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001074 lynq_client_t client;
1075 int resp_type = -1;
1076 int request = -1;
1077 int slot_id = -1;
1078 int error = -1;
lhf81a46f2022-02-13 23:57:37 -08001079 int lynq_data_call_id = -1;
1080 char *argv[10] = {};
Hong_Liue54db8c2023-04-21 02:37:23 -07001081 #ifdef GSW_RIL_CFG
1082 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
1083 if(handle==NULL||apnType==NULL)
1084 {
1085 LYERRLOG("handle or apntype is null!!!");
1086 return -1;
1087 }
1088 #else
lhf81a46f2022-02-13 23:57:37 -08001089 if(handle==NULL||apn==NULL||apnType==NULL)
1090 {
1091 LYERRLOG("handle ,apn or apntype is null!!!");
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001092 return LYNQ_E_NULL_ANONALY;
lhf81a46f2022-02-13 23:57:37 -08001093 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001094 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001095 if(user==NULL)
1096 {
1097 argv[1] = "null";
1098 }
1099 else
1100 {
1101 argv[1] = user;
lh13586612022-01-11 21:58:58 -08001102 }
1103 if(password==NULL)
1104 {
lhf81a46f2022-02-13 23:57:37 -08001105 argv[2] = "null";
lh13586612022-01-11 21:58:58 -08001106 }
1107 else
1108 {
lhf81a46f2022-02-13 23:57:37 -08001109 argv[2] = password;
lh13586612022-01-11 21:58:58 -08001110 }
1111 if(authType==NULL)
1112 {
lhf81a46f2022-02-13 23:57:37 -08001113 argv[3] = "null";
lh13586612022-01-11 21:58:58 -08001114 }
1115 else
1116 {
lhf81a46f2022-02-13 23:57:37 -08001117 argv[3] = authType;
lh13586612022-01-11 21:58:58 -08001118 }
1119 if(normalProtocol==NULL)
1120 {
lhf81a46f2022-02-13 23:57:37 -08001121 argv[4] = "null";
lh13586612022-01-11 21:58:58 -08001122 }
1123 else
1124 {
lhf81a46f2022-02-13 23:57:37 -08001125 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -08001126 }
1127 if(roamingProtocol==NULL)
1128 {
lhf81a46f2022-02-13 23:57:37 -08001129 argv[5] = "null";
lh13586612022-01-11 21:58:58 -08001130 }
1131 else
1132 {
lhf81a46f2022-02-13 23:57:37 -08001133 argv[5] = roamingProtocol;
1134 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001135 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001136 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1137 client.paramLen = 7;
1138 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -07001139 #ifdef GSW_RIL_CFG
1140 if(NULL == apn)
1141 {
1142 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1143 }
1144 else
1145 {
1146 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1147 }
1148 #else
lhf81a46f2022-02-13 23:57:37 -08001149 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 -07001150 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001151 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -07001152 lynq_data_call_id = get_handle(apnType);
rjwc63abb42023-03-31 18:22:42 +08001153 if (lynq_data_call_id < 0)
1154 {
1155 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001156 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001157 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001158 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16)
rjw733b9832023-04-03 10:20:08 +08001159 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001160 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001161 if(send_request(lynq_client_sockfd,&client)==-1)
1162 {
1163 LYERRLOG("send request fail");
1164 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001165 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001166 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001167 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001168 //get_response(lynq_client_sockfd,p);
1169 error = wait_response(lynq_client_sockfd,p,client.uToken);
1170 if(error!=0)
1171 {
1172 LYERRLOG("wait_response fail,ret:%d",error);
1173 printf_apn_table_debug(__FUNCTION__,__LINE__);
1174 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1175 return error;
1176 }
rjwed00d042022-05-25 09:18:16 +08001177 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001178 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1179 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1180 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001181 if(error==0)
1182 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001183 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001184 if(waitDataCallstateChange(LYNQ_DATA_TIME_OUT)==ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001185 {
1186 error = LYNQ_E_TIME_OUT;
1187 LYERRLOG("timeout:wait data Call state fail!!!");
1188 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001189 if (data_invaild_error == 1)
1190 {
1191 data_invaild_error = 0;
1192 LYERRLOG("urc apn info error!!!");
1193 return 8085;
1194 }
1195 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001196 return error;
1197 }
lhf81a46f2022-02-13 23:57:37 -08001198 }
Hong_Liu6149f182023-05-12 02:15:14 -07001199 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001200 return error;
1201}
1202/*
1203int lynq_deactive_data_call_sp(int *handle,char *apnType)
1204{
1205 Parcel p;
1206 lynq_client_t client;
1207 int resp_type = -1;
1208 int request = -1;
1209 int slot_id = -1;
1210 int error = -1;
1211 if(handle==NULL||apnType==NULL)
1212 {
1213 LYERRLOG("handle is null!!!");
1214 return -1;
1215 }
1216 client.uToken = Global_uToken;
1217 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
1218 client.paramLen = 1;
1219 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1220 sprintf(client.param,"%s",apnType);
1221 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1222 if(send_request(lynq_client_sockfd,&client)==-1)
1223 {
1224 LYERRLOG("send request fail");
1225 perror("[LYNQ_DATA] send request fail:");
1226 return -1;
1227 }
1228 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +08001229 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -08001230 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1231 return error;
1232}
1233*/
1234int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
1235{
Hong_Liu25edfe72023-06-16 01:13:42 -07001236 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001237 lynq_client_t client;
1238 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001239 int token;
Hong_Liu25edfe72023-06-16 01:13:42 -07001240 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001241 int slot_id = -1;
1242 int error = -1;
1243 int version =0;
1244 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001245 char *temp_char = NULL;
1246 if(dataCallList==NULL)
1247 {
1248 LYERRLOG("dataCallList is null!!!");
1249 return -1;
1250 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001251 client.uToken = get_utoken();;
lhf81a46f2022-02-13 23:57:37 -08001252 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1253 client.paramLen = 0;
1254 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1255 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001256 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001257 if(send_request(lynq_client_sockfd,&client)==-1)
1258 {
1259 LYERRLOG("send request fail");
1260 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001261 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001262 return -1;
1263 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001264 //get_response(lynq_client_sockfd,p);
1265 error = wait_response(lynq_client_sockfd,p,client.uToken);
1266 if(error!=0)
1267 {
1268 LYERRLOG("wait_response fail,ret:%d",error);
1269 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1270 return error;
1271 }
rjwed00d042022-05-25 09:18:16 +08001272 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001273 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
rjwfa532972022-09-16 13:39:41 +08001274 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001275 LYERRLOG("JumpHeader fail");
rjwfa532972022-09-16 13:39:41 +08001276 return -1;
1277 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001278 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1279 p->readInt32(&version);
lhf81a46f2022-02-13 23:57:37 -08001280 if(version==11)
1281 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001282 p->readInt32(&num);
lhf81a46f2022-02-13 23:57:37 -08001283 *realNum = num;
1284 for (int i = 0; i < num; i++)
1285 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001286 p->readInt32(&dataCallList[i].status);
1287 p->readInt32(&dataCallList[i].suggestedRetryTime);
1288 p->readInt32(&dataCallList[i].cid);
1289 p->readInt32(&dataCallList[i].active);
1290 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001291 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1292 if(temp_char)
1293 {
1294 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1295 free(temp_char);
1296 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001297 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001298 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1299 if(temp_char)
1300 {
1301 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1302 free(temp_char);
1303 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001304 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001305 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1306 if(temp_char)
1307 {
1308 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1309 free(temp_char);
1310 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001311 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001312 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1313 if(temp_char)
1314 {
1315 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1316 free(temp_char);
1317 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001318 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001319 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1320 if(temp_char)
1321 {
1322 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1323 free(temp_char);
1324 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001325 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001326 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1327 if(temp_char)
1328 {
1329 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1330 free(temp_char);
1331 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001332 p->readInt32(&dataCallList[i].mtu);
lhf81a46f2022-02-13 23:57:37 -08001333 }
1334 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001335 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001336 return error;
1337}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001338
1339int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
1340{
1341 LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
1342 if((handle < 0) || (handle > 6) || (NULL == apn_msg))
1343 {
1344 LYERRLOG("handle value error,or apn_msg is null");
1345 return LYNQ_E_NULL_ANONALY;
1346 }
1347 apn_msg->handle = handle;
1348 if(apn_msg->apn!=NULL)
1349 {
1350 memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
1351 }
1352 if(apn_msg->apnType!=NULL)
1353 {
1354 memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
1355 }
1356 return 0;
1357}
1358
lhf81a46f2022-02-13 23:57:37 -08001359int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1360{
1361 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1362 int number = 0;
1363 int lynq_data_call_id = 0;
1364 int error = 0;
1365 lynq_data_call_id = *handle;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001366 if((handle==NULL) || (dataCallList==NULL))
lhf81a46f2022-02-13 23:57:37 -08001367 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001368 LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
lhf81a46f2022-02-13 23:57:37 -08001369 return LYNQ_E_NULL_ANONALY;
1370 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001371 if ((*handle < 0) || (*handle > 6))
rjw3938f262023-03-08 16:09:28 +08001372 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001373 LYERRLOG("[lynq_get_data_call_list] handle value error");
1374 return LYNQ_E_NULL_ANONALY;
rjw3938f262023-03-08 16:09:28 +08001375 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001376 LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001377 memset(interDataCallList,0,sizeof(interDataCallList));
1378 error = getDataCallLists(interDataCallList,&number);
1379 if(error == 0)
1380 {
1381 for(int i = 0;i < number;i++)
1382 {
1383 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1384 {
1385 dataCallList->active = interDataCallList[i].active;
1386 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1387 dataCallList->cid = interDataCallList[i].cid;
1388 dataCallList->status = interDataCallList[i].status;
1389 dataCallList->mtu = interDataCallList[i].mtu;
1390 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1391 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1392 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1393 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1394 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1395 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1396 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1397 }
1398 }
1399 }
1400 return error;
1401}
1402int lynq_wait_data_call_state_change(int *handle)
1403{
rjwc3d6e582023-03-28 17:19:11 +08001404 if (data_waiting_status == 1)
1405 {
1406 LYDBGLOG("some thread is waiting");
1407 return -3;
1408 }
1409 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1410 if (s_data_urc_wait_list.empty())
1411 {
1412 LYDBGLOG("start wait");
1413 data_waiting_status = 1;
1414 waitPdnChange();
1415 }
1416 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001417 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001418
1419 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1420 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001421 if (iter != s_data_urc_wait_list.end())
1422 {
1423 *handle = *iter;
1424 }
rjw7ee7bb42023-01-18 11:34:28 +08001425 s_data_urc_wait_list.erase(iter);
1426 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1427
Hong_Liudc46d412023-05-18 13:36:26 -07001428 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001429 return 0;
1430}
1431/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001432
1433/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001434
1435int 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 +08001436{
1437 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001438 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001439 {
rjw61fcae32022-08-18 14:03:39 +08001440 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001441 }
rjw61fcae32022-08-18 14:03:39 +08001442 else
rjw0cdacbc2022-06-22 10:51:07 +08001443 {
rjw61fcae32022-08-18 14:03:39 +08001444 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001445 }
rjw20006d12022-04-21 16:29:04 +08001446 if (mcc == NULL)
1447 {
1448 sprintf(strtmp[1], "mcc=;");
1449 }
1450 else
1451 {
1452 sprintf(strtmp[1], "mcc=%s;", mcc);
1453 }
1454 if (mnc == NULL)
1455 {
rjw61fcae32022-08-18 14:03:39 +08001456 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001457 }
1458 else
1459 {
1460 sprintf(strtmp[2], "mnc=%s;", mnc);
1461 }
1462 if (apn == NULL)
1463 {
1464 sprintf(strtmp[3], "apn=;");
1465 }
1466 else
1467 {
1468 sprintf(strtmp[3], "apn=%s;", apn);
1469 }
1470 if (apntype == NULL)
1471 {
1472 sprintf(strtmp[4], "apntype=;");
1473 }
1474 else
1475 {
1476 sprintf(strtmp[4], "apntype=%s;", apntype);
1477 }
1478 if (user == NULL)
1479 {
1480 sprintf(strtmp[5], "user=;");
1481 }
1482 else
1483 {
1484 sprintf(strtmp[5], "user=%s;", user);
1485 }
1486 if (password == NULL)
1487 {
1488 sprintf(strtmp[6], "password=;");
1489 }
1490 else
1491 {
1492 sprintf(strtmp[6], "password=%s;", password);
1493 }
1494 if (normalprotocol == NULL)
1495 {
1496 sprintf(strtmp[7], "normalprotocol=;");
1497 }
1498 else
1499 {
1500 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1501 }
1502 if (roamingprotocol == NULL)
1503 {
1504 sprintf(strtmp[8], "roamingprotocol=;");
1505 }
1506 else
1507 {
1508 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1509 }
1510 if (carrier == NULL)
1511 {
1512 sprintf(strtmp[9], "carrier=;");
1513 }
1514 else
1515 {
1516 sprintf(strtmp[9], "carrier=%s;", carrier);
1517 }
rjw61fcae32022-08-18 14:03:39 +08001518 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 +08001519
rjw20006d12022-04-21 16:29:04 +08001520 return 0;
1521}
1522
1523int 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)
1524{
1525 char strtmp[10][32];
1526 if (id == NULL)
1527 {
1528 sprintf(strtmp[0], "id=;");
1529 }
1530 else
1531 {
1532 sprintf(strtmp[0], "id=%s;", id);
1533 }
1534 if (mcc == NULL)
1535 {
1536 sprintf(strtmp[1], "mcc=;");
1537 }
1538 else
1539 {
1540 sprintf(strtmp[1], "mcc=%s;", mcc);
1541 }
1542 if (mnc == NULL)
1543 {
1544 sprintf(strtmp[2], "mnc=;");
1545 }
1546 else
1547 {
1548 sprintf(strtmp[2], "mnc=%s;", mnc);
1549 }
1550 if (apn == NULL)
1551 {
1552 sprintf(strtmp[3], "apn=;");
1553 }
1554 else
1555 {
1556 sprintf(strtmp[3], "apn=%s;", apn);
1557 }
1558 if (apntype == NULL)
1559 {
1560 sprintf(strtmp[4], "apntype=;");
1561 }
1562 else
1563 {
1564 sprintf(strtmp[4], "apntype=%s;", apntype);
1565 }
1566 if (user == NULL)
1567 {
1568 sprintf(strtmp[5], "user=;");
1569 }
1570 else
1571 {
1572 sprintf(strtmp[5], "user=%s;", user);
1573 }
1574 if (password == NULL)
1575 {
1576 sprintf(strtmp[6], "password=;");
1577 }
1578 else
1579 {
1580 sprintf(strtmp[6], "password=%s;", password);
1581 }
1582 if (normalprotocol == NULL)
1583 {
1584 sprintf(strtmp[7], "normalprotocol=;");
1585 }
1586 else
1587 {
1588 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1589 }
1590 if (roamingprotocol == NULL)
1591 {
1592 sprintf(strtmp[8], "roamingprotocol=;");
1593 }
1594 else
1595 {
1596 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1597 }
1598 if (carrier == NULL)
1599 {
1600 sprintf(strtmp[9], "carrier=;");
1601 }
1602 else
1603 {
1604 sprintf(strtmp[9], "carrier=%s;", carrier);
1605 }
1606 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]);
1607 return 0;
1608}
1609
rjwaf4b1612022-06-13 17:26:01 +08001610
1611int 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)
1612{
1613 char strtmp[10][32];
1614 if (id == NULL)
1615 {
1616 sprintf(strtmp[0], "");
1617 }
1618 else
1619 {
1620 sprintf(strtmp[0], "id=%s;", id);
1621 }
1622 if (mcc == NULL)
1623 {
1624 sprintf(strtmp[1], "");
1625 }
1626 else
1627 {
1628 sprintf(strtmp[1], "mcc=%s;", mcc);
1629 }
1630 if (mnc == NULL)
1631 {
1632 sprintf(strtmp[2], "");
1633 }
1634 else
1635 {
1636 sprintf(strtmp[2], "mnc=%s;", mnc);
1637 }
1638 if (apn == NULL)
1639 {
1640 sprintf(strtmp[3], "");
1641 }
1642 else
1643 {
1644 sprintf(strtmp[3], "apn=%s;", apn);
1645 }
1646 if (apntype == NULL)
1647 {
1648 sprintf(strtmp[4], "");
1649 }
1650 else
1651 {
1652 sprintf(strtmp[4], "apntype=%s;", apntype);
1653 }
1654 if (user == NULL)
1655 {
1656 sprintf(strtmp[5], "");
1657 }
1658 else
1659 {
1660 sprintf(strtmp[5], "user=%s;", user);
1661 }
1662 if (password == NULL)
1663 {
1664 sprintf(strtmp[6], "");
1665 }
1666 else
1667 {
1668 sprintf(strtmp[6], "password=%s;", password);
1669 }
1670 if (normalprotocol == NULL)
1671 {
1672 sprintf(strtmp[7], "");
1673 }
1674 else
1675 {
1676 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1677 }
1678 if (roamingprotocol == NULL)
1679 {
1680 sprintf(strtmp[8], "");
1681 }
1682 else
1683 {
1684 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1685 }
1686 if (carrier == NULL)
1687 {
1688 sprintf(strtmp[9], "");
1689 }
1690 else
1691 {
1692 sprintf(strtmp[9], "carrier=%s;", carrier);
1693 }
1694 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]);
1695 return 0;
1696}
1697
rjw20006d12022-04-21 16:29:04 +08001698static char *lynqStrdupReadString(Parcel &p)
1699{
1700 size_t stringlen;
1701 const char16_t *s16;
1702
1703 s16 = p.readString16Inplace(&stringlen);
1704 return strndup16to8(s16, stringlen);
1705}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001706int get_imsi()
1707{
Hong_Liu25edfe72023-06-16 01:13:42 -07001708 Parcel *p =NULL;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001709 lynq_client_t client;
1710 int resp_type = -1;
1711 int token;
1712 int request = -1;
1713 int slot_id = -1;
1714 int error = -1;
1715 int version =0;
1716 int num = 0;
1717 char *temp_char = NULL;
1718 char mccmnc[32] = {0};
1719 char mccmnckey[64] = {0};
Hong_Liu25edfe72023-06-16 01:13:42 -07001720 client.uToken = get_utoken();
Hong_Liu7163bbe2023-06-04 03:03:44 -07001721 client.request = 11;//RIL_REQUEST_GET_IMSI 11
1722 client.paramLen = 0;
1723 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1724 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1725 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1726 if(send_request(lynq_client_sockfd,&client)==-1)
1727 {
1728 LYERRLOG("send request fail");
1729 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001730 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001731 return -1;
1732 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001733 //get_response(lynq_client_sockfd,p);
1734 error = wait_response(lynq_client_sockfd,p,client.uToken);
1735 if(error!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001736 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001737 LYERRLOG("wait_response fail,ret:%d",error);
1738 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001739 return error;
1740 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001741 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1742 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001743 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001744 LYERRLOG("JumpHeader fail");
Hong_Liu7163bbe2023-06-04 03:03:44 -07001745 return -1;
1746 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001747 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1748 if(error == 0)
1749 {
1750 char * test = strdupReadString_p(p);
1751 memcpy(mccmnc, test,5);
1752 mccmnc[5]='\0';
1753 free(test);
1754 sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
1755 system(mccmnckey);
1756 system("uci commit");
1757 }
1758 free_parcel(p);
1759 return error;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001760}
rjw20006d12022-04-21 16:29:04 +08001761int 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)
1762{
1763 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1764 {
1765 LYERRLOG("There are no valid parameters");
1766 return -1;
1767 }
1768 lynq_client_t client;
1769 char argc[512];
Hong_Liu7163bbe2023-06-04 03:03:44 -07001770 int res = -1;
rjw20006d12022-04-21 16:29:04 +08001771 if (cmd == 0) // insert apn db
1772 {
rjw61fcae32022-08-18 14:03:39 +08001773 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001774 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001775 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1776 client.paramLen = 2;
1777 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1778 sprintf(client.param, "%d %s", cmd, argc);
1779 }
rjw61fcae32022-08-18 14:03:39 +08001780 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001781 {
1782 if (NULL == id)
1783 {
1784 LYERRLOG("id is NULL!!!please input id: ");
1785 }
1786 sprintf(argc, "id=%s", id);
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 }
rjw61fcae32022-08-18 14:03:39 +08001793 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001794 {
rjwaf4b1612022-06-13 17:26:01 +08001795 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001796 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001797 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1798 client.paramLen = 2;
1799 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1800 sprintf(client.param, "%d %s", cmd, argc);
1801 }
rjw61fcae32022-08-18 14:03:39 +08001802 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001803 {
1804 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001805 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001806 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1807 client.paramLen = 2;
1808 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1809 sprintf(client.param, "%d %s", cmd, argc);
1810 }
1811 else
1812 {
1813 LYERRLOG("incoming command is invalid");
1814 return -1;
1815 }
1816 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001817 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001818 if(send_request(lynq_client_sockfd,&client)==-1)
1819 {
1820 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001821 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001822 return -1;
1823 }
rjwed00d042022-05-25 09:18:16 +08001824 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001825 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001826 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001827 LYINFLOG(">>>>>output info:%s",out);
1828 return 0;
1829}
1830
1831int lynq_reset_apn(char *result)
1832{
rjw20006d12022-04-21 16:29:04 +08001833 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001834 if (NULL == result)
1835 {
1836 LYERRLOG("incoming paramters error");
1837 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001838 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001839 client.request = 2000 + 194;
1840 client.paramLen = 0;
1841 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1842 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001843 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001844 if (send_request(lynq_client_sockfd, &client) == -1)
1845 {
1846 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001847 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001848 return -1;
1849 }
rjwed00d042022-05-25 09:18:16 +08001850 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001851 waitApnResult();
1852 strcpy(result, g_lynq_apn_result);
1853 LYINFLOG(">>>>>result:%s",result);
1854 return 0;
1855}
1856
rjw3bcbbf12022-04-22 16:47:18 +08001857/*Typethree add for T800 platform 2022/04/21 end*/
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07001858static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) {
1859 FILE *fp;
1860 //printf("to exec cmd:%s\n", str_cmd);
1861 if((fp=popen(str_cmd,"r"))==NULL)
1862 {
1863 perror("popen error!");
1864 return -1;
1865 }
1866 if((fread(str_cmd_ret,max_len,1,fp))<0)
1867 {
1868 perror("fread fail!");
1869 fclose(fp);
1870 return -1;
1871 }
1872 fclose(fp);
1873 return 0;
1874}
1875int check_apn_status()
1876{
1877 LYINFLOG("check_apn_status enter");
1878 int ret = -1;
1879 char cmd_ret[8] ={0};//get mccmnc
1880 const char *cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc0";
1881 const char *empty_str = ":empty";
1882 ret = exec_cmd(cmd,cmd_ret,8);
1883 if(ret==0)
1884 {
1885 if(strlen(cmd_ret)==0)
1886 {
1887 LYERRLOG("not have mccmnc config in uci ram");
1888 return 1;
1889 }
1890 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
1891 {
1892 LYERRLOG("mccmnc is empty");
1893 return 2;
1894 }
1895 LYINFLOG("mccmnc is %s",cmd_ret);
1896 return 0;
1897 }
1898 else
1899 {
1900 LYERRLOG("exec cmd fail");
1901 return -1;
1902 }
1903 return 0;
1904}
1905int radio_switch(int status)
1906{
1907 Parcel *p =NULL;
1908 lynq_client_t client;
1909 int resp_type = -1;
1910 int token;
1911 int request = -1;
1912 int slot_id = -1;
1913 int error = -1;
1914 int version =0;
1915 int num = 0;
1916 char *temp_char = NULL;
1917 char mccmnc[32] = {0};
1918 char mccmnckey[64] = {0};
1919 client.uToken = get_utoken();
1920 client.request = 59;//RIL_REQUEST_OEM_HOOK_RAW 59
1921 client.paramLen = 1;
1922 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1923 sprintf(client.param,"AT+CFUN=%d",status);
1924 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1925 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1926 if(send_request(lynq_client_sockfd,&client)==-1)
1927 {
1928 LYERRLOG("send request fail");
1929 perror("[LYNQ_DATA] send request fail:");
1930 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1931 return -1;
1932 }
1933 //get_response(lynq_client_sockfd,p);
1934 error = wait_response(lynq_client_sockfd,p,client.uToken);
1935 if(error!=0)
1936 {
1937 LYERRLOG("wait_response fail,ret:%d",error);
1938 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1939 return error;
1940 }
1941 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1942 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
1943 {
1944 LYERRLOG("JumpHeader fail");
1945 return -1;
1946 }
1947 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1948 free_parcel(p);
1949 return error;
1950}