blob: dfee4e0359c37aa23315db497c6e5960935dc549 [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
rjw61fcae32022-08-18 14:03:39 +080028
lhf81a46f2022-02-13 23:57:37 -080029using ::android::Parcel;
30typedef struct{
31 int uToken;
32 int request;
33 int paramLen;
34 char param[LYNQ_REQUEST_PARAM_BUF];
35}lynq_client_t;
lh13586612022-01-11 21:58:58 -080036typedef enum{
37 LYNQ_E_CARDSTATE_ERROR=8000,
38 /* The voice service state is out of service*/
39 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
40 /* The voice service state is EMERGENCY_ONLY*/
41 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
42 /* The radio power is power off*/
43 LYNQ_E_STATE_POWER_OFF=8003,
44 LYNQ_E_TIME_OUT=8004,
45 /*create or open sms DB fail */
46 LYNQ_E_SMS_DB_FAIL=8005,
47 /*Failed to execute sql statement*/
48 LYNQ_E_SMS_SQL_FAIL = 8006,
49 LYNQ_E_SMS_NOT_FIND = 8007,
50 /* The logic conflict*/
51 LYNQ_E_CONFLICT=9000,
52 /*Null anomaly*/
53 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080054}LYNQ_E;
55
56int lynq_client_sockfd = 0;
57int Global_uToken = 0;
Hong_Liu7e1b85e2023-05-16 05:51:57 -070058struct sockaddr_in lynq_data_socket_server_addr;
59int lynq_data_socket_server_addr_len;
rjw7ee7bb42023-01-18 11:34:28 +080060
lhf81a46f2022-02-13 23:57:37 -080061int lynq_data_call_change_id = -1;
62pthread_t lynq_data_tid =-1;
63static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
64static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080065
rjw20006d12022-04-21 16:29:04 +080066static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
67static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080068static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
69static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER;
rjwed00d042022-05-25 09:18:16 +080070/**g_lynq_data_sendto_mutex
71* @brief mark data send request mutex
72*/
73static pthread_mutex_t g_lynq_data_sendto_mutex;
rjwf9ec3832023-04-12 10:59:15 +080074/*This value data the state of the wait*/
rjwc3d6e582023-03-28 17:19:11 +080075static int data_waiting_status = 0;
rjwf9ec3832023-04-12 10:59:15 +080076/*The value indicates that 8085 error occurs in data*/
rjwc63abb42023-03-31 18:22:42 +080077static int data_invaild_error = 0;
rjwf9ec3832023-04-12 10:59:15 +080078/*This value ensure the data call timing is correct*/
79static int data_timelimit = 0;
rjwc63abb42023-03-31 18:22:42 +080080
rjw22947c22022-03-15 09:21:29 +080081/**g_lynq_data_init_flag
82* @brief mark data initialization state
83* 0:deinit status
84* 1:init state
85*/
86static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080087/**g_lynq_apn_result
88* @brief temp of apn result info
89*/
90char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +080091
rjw7ee7bb42023-01-18 11:34:28 +080092static std::vector<int> s_data_urc_wait_list;
93
rjw20006d12022-04-21 16:29:04 +080094typedef struct
95{
lhf81a46f2022-02-13 23:57:37 -080096 char apn[LYNQ_APN_MAX_LEN];
97 char apnType[LYNQ_APN_TYPE_MAX_LEN];
98 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
99 int hasUsed;
100 int hasTimeout;
Hong_Liudc46d412023-05-18 13:36:26 -0700101 int status;
102 char statusApnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800103}lynq_apn_t;
104lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
105lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
106int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800107
lhf81a46f2022-02-13 23:57:37 -0800108int getLynqApnID(char apnType[])
109{
110 int ret = 0;
rjwc63abb42023-03-31 18:22:42 +0800111 int len = 0;
lhf81a46f2022-02-13 23:57:37 -0800112 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
113 {
Hong_Liudc46d412023-05-18 13:36:26 -0700114 len = strlen(apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700115 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 +0800116 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
lh13586612022-01-11 21:58:58 -0800117 {
lhf81a46f2022-02-13 23:57:37 -0800118 return ret;
119 }
120 }
121 return -1;
122}
rjw7ee7bb42023-01-18 11:34:28 +0800123
Hong_Liudc46d412023-05-18 13:36:26 -0700124int getDeactApnID(char apnType[])
125{
126 int ret = 0;
127 int len = 0;
128 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
129 {
130 len = strlen(apnType);
131 LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len);
132 if(strncmp(lynq_apn_table[ret].statusApnType,apnType,len)==0)
133 {
134 return ret;
135 }
136 }
137 return -1;
138}
139
lhf81a46f2022-02-13 23:57:37 -0800140void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
141{
142 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
143 if(apn_table==NULL)
144 {
145 LYERRLOG("apn_table is null");
146 return;
147 }
148 memcpy(apn_table->apn,apn,strlen(apn)+1);
149 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
150 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
151 apn_table->hasTimeout = 0;
152 apn_table->hasUsed = 1;
153 return;
154}
rjw7ee7bb42023-01-18 11:34:28 +0800155
lhf81a46f2022-02-13 23:57:37 -0800156void cleanOnceApnTable(int apnId)
157{
Hong_Liudc46d412023-05-18 13:36:26 -0700158 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
lhf81a46f2022-02-13 23:57:37 -0800159 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
160 {
161 LYERRLOG("apn id is invalid!!!");
162 return;
163 }
164 lynq_apn_table[apnId].hasTimeout = 0;
165 lynq_apn_table[apnId].hasUsed = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700166 memcpy(lynq_apn_table[apnId].statusApnType,lynq_apn_table[apnId].apnType,strlen(lynq_apn_table[apnId].apnType));
lhf81a46f2022-02-13 23:57:37 -0800167 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700168 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
lhf81a46f2022-02-13 23:57:37 -0800169 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700170 lynq_apn_table[apnId].status = 32;
lhf81a46f2022-02-13 23:57:37 -0800171 return;
172}
Hong_Liudc46d412023-05-18 13:36:26 -0700173void cleanDeactApn(int apnId)
174{
175 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
176 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
177 {
178 LYERRLOG("apn id is invalid!!!");
179 return;
180 }
181 lynq_apn_table[apnId].status = 0;
182 bzero(lynq_apn_table[apnId].statusApnType,LYNQ_APN_TYPE_MAX_LEN);
183}
184
185void updateDeactApn(int apnId,int pdnState)
186{
187 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
188 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
189 {
190 LYERRLOG("apn id is invalid!!!");
191 return;
192 }
193 lynq_apn_table[apnId].status = pdnState;
194}
195
196
lhf81a46f2022-02-13 23:57:37 -0800197int getUnusedElement()
198{
Hong_Liudc46d412023-05-18 13:36:26 -0700199 if (lynq_apn_table == NULL)
200 {
201 LYERRLOG("get UnusedElemnt apn_table is null");
202 return -1;
203 }
lhf81a46f2022-02-13 23:57:37 -0800204 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
205 {
206 if(lynq_apn_table[i].hasUsed!=1)
207 {
208 return i;
209 }
210 }
rjwc63abb42023-03-31 18:22:42 +0800211 LYERRLOG("None of get unused Element");
lhf81a46f2022-02-13 23:57:37 -0800212 return -1;
213}
214int updateApn(char apnType[])
215{
216 int ret = 0;
217 ret = getUnusedElement();
Hong_Liu55668712023-05-16 21:49:17 -0700218 if(ret >= 0)
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700219 {
220 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
221 lynq_apn_table[ret].hasUsed = 1;
222 }
lhf81a46f2022-02-13 23:57:37 -0800223 return ret;
224}
rjw1309e232022-07-22 09:54:06 +0800225
226int handleCheck(int handle)
227{
228 if (lynq_apn_table[handle].hasUsed == 1)
229 {
230 return 0;
231 }
232 else
233 {
234 return -1;
235 }
236}
rjw20006d12022-04-21 16:29:04 +0800237int waitApnResult()
238{
239 int ret = 0;
240 LYINFLOG("start wait apn result!!!");
241 int sec = 0;
242 int usec = 0;
243 struct timeval now;
244 struct timespec timeout;
245 gettimeofday(&now, NULL);
246 sec = 20000 / 1000;
247 usec = 20000 % 1000;
248 timeout.tv_sec = now.tv_sec + sec;
249 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
250 pthread_mutex_lock(&s_lynq_apn_change_mutex);
251 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
252 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
253 return ret;
254}
255
256void sendSignalApnChange()
257{
258 LYINFLOG("start send Signal Apn Change");
259 pthread_mutex_lock(&s_lynq_apn_change_mutex);
260 pthread_cond_signal(&s_lynq_apn_change_cond);
261 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
262 return;
263}
lhf81a46f2022-02-13 23:57:37 -0800264
265int waitPdnChange()
266{
267 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800268 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
269 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
270 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800271 return ret;
272}
273int waitDataCallstateChange(int mtime)
274{
275 int ret = 0;
276 int sec = 0;
277 int usec = 0;
278 struct timeval now;
279 struct timespec timeout;
280 gettimeofday(&now,NULL);
281 sec = mtime/1000;
282 usec = mtime%1000;
283 timeout.tv_sec = now.tv_sec+sec;
284 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
285 pthread_mutex_lock(&s_data_call_state_change_mutex);
286 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
287 pthread_mutex_unlock(&s_data_call_state_change_mutex);
288 return ret;
289}
290void sendSignalDataCallStateChange()
291{
292 pthread_mutex_lock(&s_data_call_state_change_mutex);
293 pthread_cond_signal(&s_data_call_state_change_cond);
294 pthread_mutex_unlock(&s_data_call_state_change_mutex);
295 return;
296}
297void sendSignalPdnChange()
298{
rjw7ee7bb42023-01-18 11:34:28 +0800299 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
300 pthread_cond_signal(&s_lynq_urc_vector_cond);
301 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800302 return;
303}
304
305int get_response(int sockfd,Parcel &p)
306{
307 int len = 0;
308 char recvline[LYNQ_REC_BUF];
309 bzero(recvline,LYNQ_REC_BUF);
310 /* receive data from server */
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700311 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
312 //len = read(sockfd, recvline, LYNQ_REC_BUF);
rjw08528682022-07-04 21:28:02 +0800313 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800314 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700315 LYERRLOG("get_response fail,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800316 return -1;
317 }
318 if (recvline != NULL) {
319 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
320 p.setDataPosition(0);
321 }
322 return 0;
323}
rjwfa532972022-09-16 13:39:41 +0800324int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
lhf81a46f2022-02-13 23:57:37 -0800325{
326 if(p.dataAvail() > 0)
327 {
328 p.readInt32(resp_type);
329 p.readInt32(request);
330 p.readInt32(slot_id);
331 p.readInt32(error);
332 return 0;
333 }
334 else
335 {
336 return -1;
337 }
338}
339int send_request(int sockfd,lynq_client_t *client_tmp)
340{
341 int ret=0;
342 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
343 if(ret==-1)
344 {
345 perror("write error");
346 return -1;
347 }
348 return 0;
349}
350static char *strdupReadString(Parcel &p) {
351 size_t stringlen;
352 const char16_t *s16;
353 s16 = p.readString16Inplace(&stringlen);
354 return strndup16to8(s16, stringlen);
355}
356static char *strdupReadString_p(Parcel *p) {
357 size_t stringlen;
358 const char16_t *s16;
359 s16 = p->readString16Inplace(&stringlen);
360 return strndup16to8(s16, stringlen);
361}
362
lhf81a46f2022-02-13 23:57:37 -0800363/*Warren add for T800 platform 2021/11/19 start*/
364int lynq_socket_client_start()
365{
lhf81a46f2022-02-13 23:57:37 -0800366 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800367 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
368 lynq_data_socket_server_addr.sin_family = AF_INET;
369 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
jb.qice04d002023-05-16 18:28:06 -0700370 lynq_data_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700371 lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr);
lhf81a46f2022-02-13 23:57:37 -0800372 /*
373 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
374 {
375 printf("[%s] is not a valid IPaddress\n", argv[1]);
376 exit(1);
377 }
378*/
379 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800380 struct timeval timeOut;
381
rjwa59bf312022-07-05 11:50:31 +0800382 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800383 timeOut.tv_usec = 0;
384
385 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
386 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700387 LYERRLOG("time out setting failed");
rjw747deea2022-07-01 18:25:30 +0800388 }
389 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 -0800390 {
391 perror("connect error");
392 return -1;
393 }
394 return 0;
395}
rjw7ee7bb42023-01-18 11:34:28 +0800396
397bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800398{
rjw7ee7bb42023-01-18 11:34:28 +0800399 switch(urc_id)
400 {
401 case LYNQ_URC_DATA_CALL_STATUS_IND:
402
403 case LYNQ_URC_MODIFY_APNDB:
404 case LYNQ_URC_RESET_APNDB:
405 return true;
406 default:
407 return false;
408 }
409}
410
rjwc63abb42023-03-31 18:22:42 +0800411int printf_apn_table()
412{
413 int ret = 0;
Hong_Liu6149f182023-05-12 02:15:14 -0700414 if (lynq_apn_table == NULL)
415 {
416 LYERRLOG("apn table is null");
417 return -1;
418 }
rjwc63abb42023-03-31 18:22:42 +0800419 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
420 {
Hong_Liudc46d412023-05-18 13:36:26 -0700421 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 +0800422 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
Hong_Liudc46d412023-05-18 13:36:26 -0700423 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 +0800424 }
425 return 0;
426}
427
Hong_Liu6149f182023-05-12 02:15:14 -0700428void printf_apn_table_debug(const char *fun,int line)
429{
430 LYINFLOG("[%s][%d]apn_table msg",fun,line);
431 printf_apn_table();
432}
rjwc63abb42023-03-31 18:22:42 +0800433
rjw7ee7bb42023-01-18 11:34:28 +0800434void urc_msg_process(Parcel *p)
435{
436 int len;
437 int resp_type;
438 int urcid;
439 int slot_id;
rjwf9ec3832023-04-12 10:59:15 +0800440 int check_count = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700441 static int apnId=-1;
rjw7ee7bb42023-01-18 11:34:28 +0800442
443 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800444 char apn[LYNQ_APN_MAX_LEN];
445 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800446 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800447 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800448
449 int size = p->dataSize();
450 p->readInt32(&resp_type);
451 p->readInt32(&urcid);
452 p->readInt32(&slot_id);
453 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
454 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800455 {
rjw7ee7bb42023-01-18 11:34:28 +0800456 case LYNQ_URC_DATA_CALL_STATUS_IND:
457 p->readInt32(&pdnState);
458 bzero(apn,LYNQ_APN_MAX_LEN);
459 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
460 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
461 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800462 {
rjw20006d12022-04-21 16:29:04 +0800463 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800464 int len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700465 if((len < LYNQ_APN_MAX_LEN-1) && (len > 0))
rjw20006d12022-04-21 16:29:04 +0800466 {
rjw7ee7bb42023-01-18 11:34:28 +0800467 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800468 }
Hong_Liu6149f182023-05-12 02:15:14 -0700469 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800470 urc_msg = strdupReadString_p(p);
471 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700472 if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800473 {
474 memcpy(apnType,urc_msg,len+1);
475 }
Hong_Liu6149f182023-05-12 02:15:14 -0700476 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800477 urc_msg = strdupReadString_p(p);
478 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700479 if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800480 {
481 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
482 }
Hong_Liu6149f182023-05-12 02:15:14 -0700483 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800484 //sendSignalDataCallStateChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700485 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800486 if(apnId >= 0)
487 {
Hong_Liudc46d412023-05-18 13:36:26 -0700488 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800489 if(lynq_apn_table[apnId].hasTimeout==1)
490 {
rjwc63abb42023-03-31 18:22:42 +0800491 /*whether timeout?,real or not,*/
492 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800493 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800494 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 +0800495 {
496 LYERRLOG("deactive this time out APN");
497 lynq_deactive_data_call(&apnId);
498 }
rjwc63abb42023-03-31 18:22:42 +0800499 else
rjw7ee7bb42023-01-18 11:34:28 +0800500 {
rjwc63abb42023-03-31 18:22:42 +0800501 /*if apn lose,update apn and deactive all apn*/
502 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800503 }
504 break;
505 }
rjwacdb2152023-02-07 14:12:49 +0800506 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
Hong_Liu6149f182023-05-12 02:15:14 -0700507 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800508 }
509 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800510 else
511 {
Hong_Liu6149f182023-05-12 02:15:14 -0700512 data_invaild_error = 1;
Hong_Liudc46d412023-05-18 13:36:26 -0700513 printf_apn_table_debug(__FUNCTION__,__LINE__);
514 apnId = getDeactApnID(apnType);
515 if(apnId < 0)
516 {
517 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
518 break;
519 }
520 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
521 updateDeactApn(apnId,pdnState);
522 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800523 }
rjw7ee7bb42023-01-18 11:34:28 +0800524 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
525 s_data_urc_wait_list.push_back(apnId);
526 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
527 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800528 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800529 LYDBGLOG("data call state:%d",lynq_data_call);
530 if(lynq_data_call==1)
531 {
rjwf9ec3832023-04-12 10:59:15 +0800532 while (data_timelimit == 0)
533 {
534 LYINFLOG("client not ready to wait");
535 for (check_count = 0;check_count < 500;check_count++)
536 {
537 /*wait 10ms*/
538 usleep(10*1000);
539 }
540 LYERRLOG("client still without res");
541 break;
542 }
rjw7ee7bb42023-01-18 11:34:28 +0800543 sendSignalDataCallStateChange();
544 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800545 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800546 }
Hong_Liu6149f182023-05-12 02:15:14 -0700547 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800548 }
rjw7ee7bb42023-01-18 11:34:28 +0800549 else
rjw20006d12022-04-21 16:29:04 +0800550 {
rjw7ee7bb42023-01-18 11:34:28 +0800551 urc_msg = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -0700552 free(urc_msg);
553 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800554 len = strlen(urc_msg);
555 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
556 {
557 memcpy(apnType,urc_msg,len+1);
558 }
Hong_Liu6149f182023-05-12 02:15:14 -0700559 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800560 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
Hong_Liudc46d412023-05-18 13:36:26 -0700561 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800562 if(apnId >= 0)
563 {
Hong_Liudc46d412023-05-18 13:36:26 -0700564 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
565 lynq_data_call_change_id = apnId;
566 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
567 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
568 s_data_urc_wait_list.push_back(apnId);
569 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
570 sendSignalPdnChange();
571 }
572 else
573 {
574 apnId = getDeactApnID(apnType);
575 if(apnId < 0)
576 {
577 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
578 break;
579 }
580 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
581 cleanDeactApn(apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800582 lynq_data_call_change_id = apnId;
583 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800584 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
585 s_data_urc_wait_list.push_back(apnId);
586 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
rjwc3d6e582023-03-28 17:19:11 +0800587 sendSignalPdnChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700588 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800589 }
rjw7ee7bb42023-01-18 11:34:28 +0800590 LYDBGLOG("data call state:%d",lynq_data_call);
591 if(lynq_data_call==1)
592 {
rjwf9ec3832023-04-12 10:59:15 +0800593 while (data_timelimit == 0)
594 {
595 LYINFLOG("client not ready to wait");
596 for (check_count = 0;check_count < 500;check_count++)
597 {
598 /*wait 10ms*/
599 usleep(10*1000);
600 }
601 LYERRLOG("client still without res");
602 break;
603 }
rjw7ee7bb42023-01-18 11:34:28 +0800604 sendSignalDataCallStateChange();
605 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800606 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800607 }
Hong_Liu6149f182023-05-12 02:15:14 -0700608 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800609 }
610 break;
611 case LYNQ_URC_MODIFY_APNDB:
612 urc_msg = strdupReadString_p(p);
613 if (NULL == urc_msg)
614 {
615 LYERRLOG("error apn msg");
616 }
617 else
618 {
619 bzero(g_lynq_apn_result, 1024);
620 strcpy(g_lynq_apn_result, urc_msg);
621 sendSignalApnChange();
622 }
Hong_Liu6149f182023-05-12 02:15:14 -0700623 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800624 break;
625 case LYNQ_URC_RESET_APNDB:
626 {
rjw20006d12022-04-21 16:29:04 +0800627 urc_msg = strdupReadString_p(p);
628 if (NULL == urc_msg)
629 {
630 LYERRLOG("error apn msg");
631 }
632 else
633 {
634 bzero(g_lynq_apn_result, 1024);
635 strcpy(g_lynq_apn_result, urc_msg);
636 sendSignalApnChange();
637 }
Hong_Liu6149f182023-05-12 02:15:14 -0700638 free(urc_msg);
rjw20006d12022-04-21 16:29:04 +0800639 }
rjw7ee7bb42023-01-18 11:34:28 +0800640 default:
641 break;
lhf81a46f2022-02-13 23:57:37 -0800642 }
rjw7ee7bb42023-01-18 11:34:28 +0800643
lhf81a46f2022-02-13 23:57:37 -0800644}
rjw7ee7bb42023-01-18 11:34:28 +0800645
rjw7ee7bb42023-01-18 11:34:28 +0800646int create_urc_vector_signal_thread()
647{
648 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800649 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800650 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
651 s_data_urc_wait_list.clear();
652 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800653 return 0;
654}
rjw7ee7bb42023-01-18 11:34:28 +0800655
lhf81a46f2022-02-13 23:57:37 -0800656int lynq_init_data(int uToken)
657{
rjw22947c22022-03-15 09:21:29 +0800658 if (g_lynq_data_init_flag == 1)
659 {
660 LYERRLOG("init twice is not allowed");
661 return -1;
662 }
663 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800664 int result = 0;
665 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800666 LYLOGSET(LOG_INFO);
667 LYLOGEINIT(USER_LOG_TAG);
668 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800669 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800670 if(result!=0)
671 {
672 LYERRLOG("init socket client fail!!!");
673 return -1;
674 }
rjw7ee7bb42023-01-18 11:34:28 +0800675 result = lynq_init_data_urc_thread();
676 if(result!=0)
677 {
678 LYERRLOG("init socket urc fail!!!");
679 return -1;
680 }
681
682 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800683 if(result!=0)
684 {
685 LYERRLOG("init socket urc fail!!!");
686 return -1;
687 }
688 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
689 LYDBGLOG("lynq init call success!!!");
690 return 0;
691
692}
693int lynq_deinit_data()
694{
695 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800696 if (g_lynq_data_init_flag == 0)
697 {
698 LYERRLOG("deinit twice is not allowed");
699 return ret;
700 }
701 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800702 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
703 {
704 if(strlen(lynq_apn_table[i].apnType)!=0)
705 {
706 lynq_deactive_data_call(&i);
707 }
708 }
709 if(lynq_client_sockfd>0)
710 {
711 close(lynq_client_sockfd);
712 }
rjw7ee7bb42023-01-18 11:34:28 +0800713 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800714 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800715 {
rjw7ee7bb42023-01-18 11:34:28 +0800716 LYERRLOG("lynq_deinit_data_urc_thread fail");
717 return ret;
rjw22947c22022-03-15 09:21:29 +0800718 }
rjwc3d6e582023-03-28 17:19:11 +0800719 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
720 s_data_urc_wait_list.clear();
721 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800722 return 0;
723}
724int lynq_setup_data_call(int *handle)
725{
Hong_Liue54db8c2023-04-21 02:37:23 -0700726 int error = -1;
727 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
728 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
Hong_Liue9879152023-04-25 20:40:26 -0700729 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -0700730 #else
lhf81a46f2022-02-13 23:57:37 -0800731 Parcel p;
732 lynq_client_t client;
733 int resp_type = -1;
734 int request = -1;
735 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -0800736 int lynq_data_call_id = 0;
737 if(handle==NULL)
738 {
739 LYERRLOG("handle is null!!!");
740 return LYNQ_E_NULL_ANONALY;
741 }
742 client.uToken = Global_uToken;
743 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
744 client.paramLen = 0;
745 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
746 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800747 lynq_data_call_id = updateApn("default");
748 if (lynq_data_call_id < 0)
749 {
750 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700751 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +0800752 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700753 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect.
754 //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate.
rjw733b9832023-04-03 10:20:08 +0800755 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800756 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800757 if(send_request(lynq_client_sockfd,&client)==-1)
758 {
759 LYERRLOG("send request fail");
760 perror("[LYNQ_DATA] send request fail:");
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700761 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -0800762 }
763 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800764 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800765 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800766 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800767 if(error==0)
768 {
rjwf9ec3832023-04-12 10:59:15 +0800769 data_timelimit = 1;
rjw20006d12022-04-21 16:29:04 +0800770 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800771 {
772 error = LYNQ_E_TIME_OUT;
773 LYERRLOG("timeout:wait data Call state fail!!!");
774 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -0700775 if (data_invaild_error == 1)
776 {
777 data_invaild_error = 0;
778 LYERRLOG("urc apn info error!!!");
779 return 8085;
780 }
781 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -0800782 return error;
783 }
lhf81a46f2022-02-13 23:57:37 -0800784 }
Hong_Liu6149f182023-05-12 02:15:14 -0700785 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liue54db8c2023-04-21 02:37:23 -0700786 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800787 return error;
788}
rjw7ee7bb42023-01-18 11:34:28 +0800789
lhf81a46f2022-02-13 23:57:37 -0800790int lynq_deactive_data_call(int *handle)
791{
792 Parcel p;
793 lynq_client_t client;
794 int resp_type = -1;
795 int request = -1;
796 int slot_id = -1;
797 int error = -1;
798 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800799 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800800 if(handle==NULL)
801 {
802 LYERRLOG("handle is null!!!");
803 return -1;
804 }
rjw1309e232022-07-22 09:54:06 +0800805 ret = handleCheck(*handle);
806 if (ret != 0)
807 {
808 LYERRLOG("incomming handle is invalid");
809 return -1;
810 }
811 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800812 client.uToken = Global_uToken;
813 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
Hong_Liue3d35262023-05-04 00:20:12 -0700814 client.paramLen = 0;
815 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
816 #ifdef GSW_RIL_CFG
817 client.paramLen = 1;
818 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
819 #else
820 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -0800821 {
lhf81a46f2022-02-13 23:57:37 -0800822 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -0800823 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
824 }
Hong_Liue3d35262023-05-04 00:20:12 -0700825 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800826 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800827 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800828 if(send_request(lynq_client_sockfd,&client)==-1)
829 {
830 LYERRLOG("send request fail");
831 perror("[LYNQ_DATA] send request fail:");
832 return -1;
833 }
834 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800835 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800836 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800837 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
838 cleanOnceApnTable(lynq_data_call_id);
Hong_Liu6149f182023-05-12 02:15:14 -0700839 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -0800840 return error;
841}
842int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
843{
844 Parcel p;
845 lynq_client_t client;
846 int resp_type = -1;
847 int request = -1;
848 int slot_id = -1;
849 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800850 int lynq_data_call_id = -1;
851 char *argv[10] = {};
Hong_Liue54db8c2023-04-21 02:37:23 -0700852 #ifdef GSW_RIL_CFG
853 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
854 if(handle==NULL||apnType==NULL)
855 {
856 LYERRLOG("handle or apntype is null!!!");
857 return -1;
858 }
859 #else
lhf81a46f2022-02-13 23:57:37 -0800860 if(handle==NULL||apn==NULL||apnType==NULL)
861 {
862 LYERRLOG("handle ,apn or apntype is null!!!");
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700863 return LYNQ_E_NULL_ANONALY;
lhf81a46f2022-02-13 23:57:37 -0800864 }
Hong_Liue54db8c2023-04-21 02:37:23 -0700865 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800866 if(user==NULL)
867 {
868 argv[1] = "null";
869 }
870 else
871 {
872 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800873 }
874 if(password==NULL)
875 {
lhf81a46f2022-02-13 23:57:37 -0800876 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800877 }
878 else
879 {
lhf81a46f2022-02-13 23:57:37 -0800880 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800881 }
882 if(authType==NULL)
883 {
lhf81a46f2022-02-13 23:57:37 -0800884 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800885 }
886 else
887 {
lhf81a46f2022-02-13 23:57:37 -0800888 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800889 }
890 if(normalProtocol==NULL)
891 {
lhf81a46f2022-02-13 23:57:37 -0800892 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800893 }
894 else
895 {
lhf81a46f2022-02-13 23:57:37 -0800896 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800897 }
898 if(roamingProtocol==NULL)
899 {
lhf81a46f2022-02-13 23:57:37 -0800900 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800901 }
902 else
903 {
lhf81a46f2022-02-13 23:57:37 -0800904 argv[5] = roamingProtocol;
905 }
906 client.uToken = Global_uToken;
907 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
908 client.paramLen = 7;
909 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -0700910 #ifdef GSW_RIL_CFG
911 if(NULL == apn)
912 {
913 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
914 }
915 else
916 {
917 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
918 }
919 #else
lhf81a46f2022-02-13 23:57:37 -0800920 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 -0700921 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800922 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800923 lynq_data_call_id = updateApn(apnType);
924 if (lynq_data_call_id < 0)
925 {
926 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700927 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +0800928 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700929 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16)
rjw733b9832023-04-03 10:20:08 +0800930 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800931 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800932 if(send_request(lynq_client_sockfd,&client)==-1)
933 {
934 LYERRLOG("send request fail");
935 perror("[LYNQ_DATA] send request fail:");
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700936 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -0800937 }
938 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800939 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800940 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800941 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800942 if(error==0)
943 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700944 data_timelimit = 1;
rjw7ee7bb42023-01-18 11:34:28 +0800945 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800946 {
947 error = LYNQ_E_TIME_OUT;
948 LYERRLOG("timeout:wait data Call state fail!!!");
949 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -0700950 if (data_invaild_error == 1)
951 {
952 data_invaild_error = 0;
953 LYERRLOG("urc apn info error!!!");
954 return 8085;
955 }
956 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -0800957 return error;
958 }
lhf81a46f2022-02-13 23:57:37 -0800959 }
Hong_Liu6149f182023-05-12 02:15:14 -0700960 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -0800961 return error;
962}
963/*
964int lynq_deactive_data_call_sp(int *handle,char *apnType)
965{
966 Parcel p;
967 lynq_client_t client;
968 int resp_type = -1;
969 int request = -1;
970 int slot_id = -1;
971 int error = -1;
972 if(handle==NULL||apnType==NULL)
973 {
974 LYERRLOG("handle is null!!!");
975 return -1;
976 }
977 client.uToken = Global_uToken;
978 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
979 client.paramLen = 1;
980 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
981 sprintf(client.param,"%s",apnType);
982 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
983 if(send_request(lynq_client_sockfd,&client)==-1)
984 {
985 LYERRLOG("send request fail");
986 perror("[LYNQ_DATA] send request fail:");
987 return -1;
988 }
989 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800990 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800991 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
992 return error;
993}
994*/
995int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
996{
997 Parcel p;
998 lynq_client_t client;
999 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001000 int token;
1001 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001002 int slot_id = -1;
1003 int error = -1;
1004 int version =0;
1005 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001006 char *temp_char = NULL;
1007 if(dataCallList==NULL)
1008 {
1009 LYERRLOG("dataCallList is null!!!");
1010 return -1;
1011 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001012 Global_uToken++;
lhf81a46f2022-02-13 23:57:37 -08001013 client.uToken = Global_uToken;
1014 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1015 client.paramLen = 0;
1016 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1017 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001018 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001019 if(send_request(lynq_client_sockfd,&client)==-1)
1020 {
1021 LYERRLOG("send request fail");
1022 perror("[LYNQ_DATA] send request fail:");
1023 return -1;
1024 }
1025 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +08001026 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +08001027 if(p.dataAvail() > 0)
1028 {
rjw0fb4ccb2022-09-16 19:12:35 +08001029 p.readInt32(&resp_type);
1030 p.readInt32(&token);
1031 p.readInt32(&request);
1032 p.readInt32(&slot_id);
1033 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +08001034 }
1035 else
1036 {
1037 return -1;
1038 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001039 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,token,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -08001040 p.readInt32(&version);
1041 if(version==11)
1042 {
1043 p.readInt32(&num);
1044 *realNum = num;
1045 for (int i = 0; i < num; i++)
1046 {
1047 p.readInt32(&dataCallList[i].status);
1048 p.readInt32(&dataCallList[i].suggestedRetryTime);
1049 p.readInt32(&dataCallList[i].cid);
1050 p.readInt32(&dataCallList[i].active);
1051 temp_char = strdupReadString(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001052 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1053 if(temp_char)
1054 {
1055 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1056 free(temp_char);
1057 }
lhf81a46f2022-02-13 23:57:37 -08001058 temp_char = strdupReadString(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001059 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1060 if(temp_char)
1061 {
1062 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1063 free(temp_char);
1064 }
lhf81a46f2022-02-13 23:57:37 -08001065 temp_char = strdupReadString(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001066 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1067 if(temp_char)
1068 {
1069 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1070 free(temp_char);
1071 }
lhf81a46f2022-02-13 23:57:37 -08001072 temp_char = strdupReadString(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001073 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1074 if(temp_char)
1075 {
1076 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1077 free(temp_char);
1078 }
lhf81a46f2022-02-13 23:57:37 -08001079 temp_char = strdupReadString(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001080 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1081 if(temp_char)
1082 {
1083 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1084 free(temp_char);
1085 }
lhf81a46f2022-02-13 23:57:37 -08001086 temp_char = strdupReadString(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001087 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1088 if(temp_char)
1089 {
1090 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1091 free(temp_char);
1092 }
lhf81a46f2022-02-13 23:57:37 -08001093 p.readInt32(&dataCallList[i].mtu);
1094 }
1095 }
1096 return error;
1097}
1098int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1099{
1100 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1101 int number = 0;
1102 int lynq_data_call_id = 0;
1103 int error = 0;
1104 lynq_data_call_id = *handle;
1105 if(handle==NULL)
1106 {
1107 LYERRLOG("handle is NULL");
1108 return LYNQ_E_NULL_ANONALY;
1109 }
rjw3938f262023-03-08 16:09:28 +08001110 if (*handle<0 && handle>8)
1111 {
1112 LYERRLOG("handle value error");
1113 }
1114 LYINFLOG("incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001115 memset(interDataCallList,0,sizeof(interDataCallList));
1116 error = getDataCallLists(interDataCallList,&number);
1117 if(error == 0)
1118 {
1119 for(int i = 0;i < number;i++)
1120 {
1121 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1122 {
1123 dataCallList->active = interDataCallList[i].active;
1124 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1125 dataCallList->cid = interDataCallList[i].cid;
1126 dataCallList->status = interDataCallList[i].status;
1127 dataCallList->mtu = interDataCallList[i].mtu;
1128 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1129 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1130 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1131 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1132 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1133 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1134 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1135 }
1136 }
1137 }
1138 return error;
1139}
1140int lynq_wait_data_call_state_change(int *handle)
1141{
rjwc3d6e582023-03-28 17:19:11 +08001142 if (data_waiting_status == 1)
1143 {
1144 LYDBGLOG("some thread is waiting");
1145 return -3;
1146 }
1147 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1148 if (s_data_urc_wait_list.empty())
1149 {
1150 LYDBGLOG("start wait");
1151 data_waiting_status = 1;
1152 waitPdnChange();
1153 }
1154 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001155 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001156
1157 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1158 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001159 if (iter != s_data_urc_wait_list.end())
1160 {
1161 *handle = *iter;
1162 }
rjw7ee7bb42023-01-18 11:34:28 +08001163 s_data_urc_wait_list.erase(iter);
1164 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1165
Hong_Liudc46d412023-05-18 13:36:26 -07001166 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001167 return 0;
1168}
1169/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001170
1171/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001172
1173int 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 +08001174{
1175 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001176 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001177 {
rjw61fcae32022-08-18 14:03:39 +08001178 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001179 }
rjw61fcae32022-08-18 14:03:39 +08001180 else
rjw0cdacbc2022-06-22 10:51:07 +08001181 {
rjw61fcae32022-08-18 14:03:39 +08001182 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001183 }
rjw20006d12022-04-21 16:29:04 +08001184 if (mcc == NULL)
1185 {
1186 sprintf(strtmp[1], "mcc=;");
1187 }
1188 else
1189 {
1190 sprintf(strtmp[1], "mcc=%s;", mcc);
1191 }
1192 if (mnc == NULL)
1193 {
rjw61fcae32022-08-18 14:03:39 +08001194 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001195 }
1196 else
1197 {
1198 sprintf(strtmp[2], "mnc=%s;", mnc);
1199 }
1200 if (apn == NULL)
1201 {
1202 sprintf(strtmp[3], "apn=;");
1203 }
1204 else
1205 {
1206 sprintf(strtmp[3], "apn=%s;", apn);
1207 }
1208 if (apntype == NULL)
1209 {
1210 sprintf(strtmp[4], "apntype=;");
1211 }
1212 else
1213 {
1214 sprintf(strtmp[4], "apntype=%s;", apntype);
1215 }
1216 if (user == NULL)
1217 {
1218 sprintf(strtmp[5], "user=;");
1219 }
1220 else
1221 {
1222 sprintf(strtmp[5], "user=%s;", user);
1223 }
1224 if (password == NULL)
1225 {
1226 sprintf(strtmp[6], "password=;");
1227 }
1228 else
1229 {
1230 sprintf(strtmp[6], "password=%s;", password);
1231 }
1232 if (normalprotocol == NULL)
1233 {
1234 sprintf(strtmp[7], "normalprotocol=;");
1235 }
1236 else
1237 {
1238 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1239 }
1240 if (roamingprotocol == NULL)
1241 {
1242 sprintf(strtmp[8], "roamingprotocol=;");
1243 }
1244 else
1245 {
1246 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1247 }
1248 if (carrier == NULL)
1249 {
1250 sprintf(strtmp[9], "carrier=;");
1251 }
1252 else
1253 {
1254 sprintf(strtmp[9], "carrier=%s;", carrier);
1255 }
rjw61fcae32022-08-18 14:03:39 +08001256 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 +08001257
rjw20006d12022-04-21 16:29:04 +08001258 return 0;
1259}
1260
1261int 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)
1262{
1263 char strtmp[10][32];
1264 if (id == NULL)
1265 {
1266 sprintf(strtmp[0], "id=;");
1267 }
1268 else
1269 {
1270 sprintf(strtmp[0], "id=%s;", id);
1271 }
1272 if (mcc == NULL)
1273 {
1274 sprintf(strtmp[1], "mcc=;");
1275 }
1276 else
1277 {
1278 sprintf(strtmp[1], "mcc=%s;", mcc);
1279 }
1280 if (mnc == NULL)
1281 {
1282 sprintf(strtmp[2], "mnc=;");
1283 }
1284 else
1285 {
1286 sprintf(strtmp[2], "mnc=%s;", mnc);
1287 }
1288 if (apn == NULL)
1289 {
1290 sprintf(strtmp[3], "apn=;");
1291 }
1292 else
1293 {
1294 sprintf(strtmp[3], "apn=%s;", apn);
1295 }
1296 if (apntype == NULL)
1297 {
1298 sprintf(strtmp[4], "apntype=;");
1299 }
1300 else
1301 {
1302 sprintf(strtmp[4], "apntype=%s;", apntype);
1303 }
1304 if (user == NULL)
1305 {
1306 sprintf(strtmp[5], "user=;");
1307 }
1308 else
1309 {
1310 sprintf(strtmp[5], "user=%s;", user);
1311 }
1312 if (password == NULL)
1313 {
1314 sprintf(strtmp[6], "password=;");
1315 }
1316 else
1317 {
1318 sprintf(strtmp[6], "password=%s;", password);
1319 }
1320 if (normalprotocol == NULL)
1321 {
1322 sprintf(strtmp[7], "normalprotocol=;");
1323 }
1324 else
1325 {
1326 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1327 }
1328 if (roamingprotocol == NULL)
1329 {
1330 sprintf(strtmp[8], "roamingprotocol=;");
1331 }
1332 else
1333 {
1334 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1335 }
1336 if (carrier == NULL)
1337 {
1338 sprintf(strtmp[9], "carrier=;");
1339 }
1340 else
1341 {
1342 sprintf(strtmp[9], "carrier=%s;", carrier);
1343 }
1344 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]);
1345 return 0;
1346}
1347
rjwaf4b1612022-06-13 17:26:01 +08001348
1349int 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)
1350{
1351 char strtmp[10][32];
1352 if (id == NULL)
1353 {
1354 sprintf(strtmp[0], "");
1355 }
1356 else
1357 {
1358 sprintf(strtmp[0], "id=%s;", id);
1359 }
1360 if (mcc == NULL)
1361 {
1362 sprintf(strtmp[1], "");
1363 }
1364 else
1365 {
1366 sprintf(strtmp[1], "mcc=%s;", mcc);
1367 }
1368 if (mnc == NULL)
1369 {
1370 sprintf(strtmp[2], "");
1371 }
1372 else
1373 {
1374 sprintf(strtmp[2], "mnc=%s;", mnc);
1375 }
1376 if (apn == NULL)
1377 {
1378 sprintf(strtmp[3], "");
1379 }
1380 else
1381 {
1382 sprintf(strtmp[3], "apn=%s;", apn);
1383 }
1384 if (apntype == NULL)
1385 {
1386 sprintf(strtmp[4], "");
1387 }
1388 else
1389 {
1390 sprintf(strtmp[4], "apntype=%s;", apntype);
1391 }
1392 if (user == NULL)
1393 {
1394 sprintf(strtmp[5], "");
1395 }
1396 else
1397 {
1398 sprintf(strtmp[5], "user=%s;", user);
1399 }
1400 if (password == NULL)
1401 {
1402 sprintf(strtmp[6], "");
1403 }
1404 else
1405 {
1406 sprintf(strtmp[6], "password=%s;", password);
1407 }
1408 if (normalprotocol == NULL)
1409 {
1410 sprintf(strtmp[7], "");
1411 }
1412 else
1413 {
1414 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1415 }
1416 if (roamingprotocol == NULL)
1417 {
1418 sprintf(strtmp[8], "");
1419 }
1420 else
1421 {
1422 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1423 }
1424 if (carrier == NULL)
1425 {
1426 sprintf(strtmp[9], "");
1427 }
1428 else
1429 {
1430 sprintf(strtmp[9], "carrier=%s;", carrier);
1431 }
1432 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]);
1433 return 0;
1434}
1435
rjw20006d12022-04-21 16:29:04 +08001436static char *lynqStrdupReadString(Parcel &p)
1437{
1438 size_t stringlen;
1439 const char16_t *s16;
1440
1441 s16 = p.readString16Inplace(&stringlen);
1442 return strndup16to8(s16, stringlen);
1443}
1444
1445int 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)
1446{
1447 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1448 {
1449 LYERRLOG("There are no valid parameters");
1450 return -1;
1451 }
1452 lynq_client_t client;
1453 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001454 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001455 Parcel p;
1456 if (cmd == 0) // insert apn db
1457 {
rjw61fcae32022-08-18 14:03:39 +08001458 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1459
rjw20006d12022-04-21 16:29:04 +08001460 client.uToken = Global_uToken;
1461 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1462 client.paramLen = 2;
1463 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1464 sprintf(client.param, "%d %s", cmd, argc);
1465 }
rjw61fcae32022-08-18 14:03:39 +08001466 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001467 {
1468 if (NULL == id)
1469 {
1470 LYERRLOG("id is NULL!!!please input id: ");
1471 }
1472 sprintf(argc, "id=%s", id);
1473 client.uToken = Global_uToken;
1474 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1475 client.paramLen = 2;
1476 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1477 sprintf(client.param, "%d %s", cmd, argc);
1478 }
rjw61fcae32022-08-18 14:03:39 +08001479 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001480 {
rjwaf4b1612022-06-13 17:26:01 +08001481 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001482 client.uToken = Global_uToken;
1483 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1484 client.paramLen = 2;
1485 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1486 sprintf(client.param, "%d %s", cmd, argc);
1487 }
rjw61fcae32022-08-18 14:03:39 +08001488 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001489 {
1490 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1491 client.uToken = Global_uToken;
1492 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1493 client.paramLen = 2;
1494 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1495 sprintf(client.param, "%d %s", cmd, argc);
1496 }
1497 else
1498 {
1499 LYERRLOG("incoming command is invalid");
1500 return -1;
1501 }
1502 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001503 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001504 if(send_request(lynq_client_sockfd,&client)==-1)
1505 {
1506 LYERRLOG("send request fail");
1507 return -1;
1508 }
rjwed00d042022-05-25 09:18:16 +08001509 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001510 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001511 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001512 LYINFLOG(">>>>>output info:%s",out);
1513 return 0;
1514}
1515
1516int lynq_reset_apn(char *result)
1517{
1518 Parcel p;
1519 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001520 if (NULL == result)
1521 {
1522 LYERRLOG("incoming paramters error");
1523 }
rjw20006d12022-04-21 16:29:04 +08001524 client.uToken = Global_uToken;
1525 client.request = 2000 + 194;
1526 client.paramLen = 0;
1527 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1528 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001529 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001530 if (send_request(lynq_client_sockfd, &client) == -1)
1531 {
1532 LYERRLOG("send request fail");
1533 return -1;
1534 }
rjwed00d042022-05-25 09:18:16 +08001535 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001536 waitApnResult();
1537 strcpy(result, g_lynq_apn_result);
1538 LYINFLOG(">>>>>result:%s",result);
1539 return 0;
1540}
1541
rjw3bcbbf12022-04-22 16:47:18 +08001542/*Typethree add for T800 platform 2022/04/21 end*/