blob: 81a5270daabe69eda48b9ff1407a0db75e3ee9df [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>
lhf81a46f2022-02-13 23:57:37 -080018#define LYNQ_SERVICE_PORT 8088
19#define LYNQ_URC_SERVICE_PORT 8086
20#define LYNQ_REC_BUF 8192
21#define LYNQ_REQUEST_PARAM_BUF 8192
22#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
23#define USER_LOG_TAG "LYNQ_DATA"
24
rjw0cdacbc2022-06-22 10:51:07 +080025#define LYNQ_DATA_UCI_BUF 258
26#define LYNQ_DATA_UCI_APN_SECTION "lynq_apn_info"
27#define LYNQ_DATA_UCI_APN_KEY "insertId"
28
29
30
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,
52 /* The logic conflict*/
53 LYNQ_E_CONFLICT=9000,
54 /*Null anomaly*/
55 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080056}LYNQ_E;
57
58int lynq_client_sockfd = 0;
59int Global_uToken = 0;
60bool data_urc_recive_status = 1;
61int 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;
65static pthread_mutex_t s_pdn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
66static pthread_cond_t s_pdn_change_cond = PTHREAD_COND_INITIALIZER;
rjw20006d12022-04-21 16:29:04 +080067static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
68static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
69
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;
74
rjw22947c22022-03-15 09:21:29 +080075/**g_lynq_data_init_flag
76* @brief mark data initialization state
77* 0:deinit status
78* 1:init state
79*/
80static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080081/**g_lynq_apn_result
82* @brief temp of apn result info
83*/
84char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +080085
rjw20006d12022-04-21 16:29:04 +080086typedef struct
87{
lhf81a46f2022-02-13 23:57:37 -080088 char apn[LYNQ_APN_MAX_LEN];
89 char apnType[LYNQ_APN_TYPE_MAX_LEN];
90 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
91 int hasUsed;
92 int hasTimeout;
93}lynq_apn_t;
94lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
95lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
96int lynq_data_call = 0;
97int millli_sleep_with_restart(int millisecond)
lh13586612022-01-11 21:58:58 -080098{
lhf81a46f2022-02-13 23:57:37 -080099 int left = millisecond*1000;
100 while (left > 0)
101 {
102 left = usleep(left);
103 }
104
105 return 0;
106}
107int getLynqApnID(char apnType[])
108{
109 int ret = 0;
110 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
111 {
112 if(strcmp(lynq_apn_table[ret].apnType,apnType)==0)
lh13586612022-01-11 21:58:58 -0800113 {
lhf81a46f2022-02-13 23:57:37 -0800114 return ret;
115 }
116 }
117 return -1;
118}
119void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
120{
121 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
122 if(apn_table==NULL)
123 {
124 LYERRLOG("apn_table is null");
125 return;
126 }
127 memcpy(apn_table->apn,apn,strlen(apn)+1);
128 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
129 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
130 apn_table->hasTimeout = 0;
131 apn_table->hasUsed = 1;
132 return;
133}
134void cleanOnceApnTable(int apnId)
135{
136 LYDBGLOG("apn id:%d",apnId);
137 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
138 {
139 LYERRLOG("apn id is invalid!!!");
140 return;
141 }
142 lynq_apn_table[apnId].hasTimeout = 0;
143 lynq_apn_table[apnId].hasUsed = 0;
144 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
145 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
146 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
147 return;
148}
149int getUnusedElement()
150{
151 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
152 {
153 if(lynq_apn_table[i].hasUsed!=1)
154 {
155 return i;
156 }
157 }
158 return -1;
159}
160int updateApn(char apnType[])
161{
162 int ret = 0;
163 ret = getUnusedElement();
164 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
165 lynq_apn_table[ret].hasUsed = 1;
166 return ret;
167}
rjw20006d12022-04-21 16:29:04 +0800168int waitApnResult()
169{
170 int ret = 0;
171 LYINFLOG("start wait apn result!!!");
172 int sec = 0;
173 int usec = 0;
174 struct timeval now;
175 struct timespec timeout;
176 gettimeofday(&now, NULL);
177 sec = 20000 / 1000;
178 usec = 20000 % 1000;
179 timeout.tv_sec = now.tv_sec + sec;
180 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
181 pthread_mutex_lock(&s_lynq_apn_change_mutex);
182 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
183 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
184 return ret;
185}
186
187void sendSignalApnChange()
188{
189 LYINFLOG("start send Signal Apn Change");
190 pthread_mutex_lock(&s_lynq_apn_change_mutex);
191 pthread_cond_signal(&s_lynq_apn_change_cond);
192 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
193 return;
194}
lhf81a46f2022-02-13 23:57:37 -0800195
196int waitPdnChange()
197{
198 int ret = 0;
199 pthread_mutex_lock(&s_pdn_change_mutex);
200 ret = pthread_cond_wait(&s_pdn_change_cond,&s_pdn_change_mutex);
201 pthread_mutex_unlock(&s_pdn_change_mutex);
202 return ret;
203}
204int waitDataCallstateChange(int mtime)
205{
206 int ret = 0;
207 int sec = 0;
208 int usec = 0;
209 struct timeval now;
210 struct timespec timeout;
211 gettimeofday(&now,NULL);
212 sec = mtime/1000;
213 usec = mtime%1000;
214 timeout.tv_sec = now.tv_sec+sec;
215 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
216 pthread_mutex_lock(&s_data_call_state_change_mutex);
217 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
218 pthread_mutex_unlock(&s_data_call_state_change_mutex);
219 return ret;
220}
221void sendSignalDataCallStateChange()
222{
223 pthread_mutex_lock(&s_data_call_state_change_mutex);
224 pthread_cond_signal(&s_data_call_state_change_cond);
225 pthread_mutex_unlock(&s_data_call_state_change_mutex);
226 return;
227}
228void sendSignalPdnChange()
229{
230 pthread_mutex_lock(&s_pdn_change_mutex);
231 pthread_cond_signal(&s_pdn_change_cond);
232 pthread_mutex_unlock(&s_pdn_change_mutex);
233 return;
234}
235
236int get_response(int sockfd,Parcel &p)
237{
238 int len = 0;
239 char recvline[LYNQ_REC_BUF];
240 bzero(recvline,LYNQ_REC_BUF);
241 /* receive data from server */
rjw08528682022-07-04 21:28:02 +0800242 len = read(sockfd, recvline, LYNQ_REC_BUF);
243 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800244 {
rjw747deea2022-07-01 18:25:30 +0800245 LYERRLOG("read error");
lhf81a46f2022-02-13 23:57:37 -0800246 return -1;
247 }
248 if (recvline != NULL) {
249 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
250 p.setDataPosition(0);
251 }
252 return 0;
253}
254int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
255{
256 if(p.dataAvail() > 0)
257 {
258 p.readInt32(resp_type);
259 p.readInt32(request);
260 p.readInt32(slot_id);
261 p.readInt32(error);
262 return 0;
263 }
264 else
265 {
266 return -1;
267 }
268}
269int send_request(int sockfd,lynq_client_t *client_tmp)
270{
271 int ret=0;
272 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
273 if(ret==-1)
274 {
275 perror("write error");
276 return -1;
277 }
278 return 0;
279}
280static char *strdupReadString(Parcel &p) {
281 size_t stringlen;
282 const char16_t *s16;
283 s16 = p.readString16Inplace(&stringlen);
284 return strndup16to8(s16, stringlen);
285}
286static char *strdupReadString_p(Parcel *p) {
287 size_t stringlen;
288 const char16_t *s16;
289 s16 = p->readString16Inplace(&stringlen);
290 return strndup16to8(s16, stringlen);
291}
292
293
294/*Warren add for T800 platform 2021/11/19 start*/
295int lynq_socket_client_start()
296{
rjw08528682022-07-04 21:28:02 +0800297 struct sockaddr_in lynq_data_socket_server_addr;
lhf81a46f2022-02-13 23:57:37 -0800298 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800299 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
300 lynq_data_socket_server_addr.sin_family = AF_INET;
301 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
302 lynq_data_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
lhf81a46f2022-02-13 23:57:37 -0800303 /*
304 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
305 {
306 printf("[%s] is not a valid IPaddress\n", argv[1]);
307 exit(1);
308 }
309*/
310 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800311 struct timeval timeOut;
312
rjwa59bf312022-07-05 11:50:31 +0800313 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800314 timeOut.tv_usec = 0;
315
316 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
317 {
318 LYERRLOG("time out setting failed");
319 }
320 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 -0800321 {
322 perror("connect error");
323 return -1;
324 }
325 return 0;
326}
327void *thread_urc_recv(void *parg)
328{
329 int socket_fd = (int64_t)parg;
330 int len=0;
331 socklen_t addr_len=0;
332 uint8_t *dataLength = NULL;
333 char urc_data[LYNQ_REC_BUF];
334 char apn[LYNQ_APN_MAX_LEN];
335 char apnType[LYNQ_APN_TYPE_MAX_LEN];
336 int pdnState = 0;
337 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
338 int slot_id = -1;
339 int resp_type = -1;
340 int urcid = -1;
341 char *urc_msg = NULL;
342 Parcel *p = NULL;
343 struct sockaddr_in dest_addr;
344 LYINFLOG("thread_urc_recv in running....\n");
345 while(data_urc_recive_status)
346 {
347 bzero(urc_data,LYNQ_REC_BUF);
348 //get data msg
349 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
350 if(len <= 0)
351 {
352 perror("thread_urc_recv step2 fail:");
353 millli_sleep_with_restart(1);
lh13586612022-01-11 21:58:58 -0800354 break;
lhf81a46f2022-02-13 23:57:37 -0800355 }
356 LYDBGLOG("=====>urc data len<=====:%d\n",len);
357 p = new Parcel();
358 if(p==NULL)
359 {
360 RLOGD("new parcel failure!!!");
361 break;
362 }
363 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
364 p->setDataPosition(0);
365 if(p->dataAvail() > 0)
366 {
367 p->readInt32(&resp_type);
368 p->readInt32(&urcid);
369 p->readInt32(&slot_id);
370 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
371 switch (urcid)
372 {
373 case 9003://LYNQ_URC_DATA_CALL_STATUS_IND
374 {
375 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
376 p->readInt32(&pdnState);
377 bzero(apn,LYNQ_APN_MAX_LEN);
378 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
379 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
380 if(pdnState!=4)//PDN_DISCONNECTED
381 {
382 urc_msg = strdupReadString_p(p);
383 int len = strlen(urc_msg);
384 if(len < LYNQ_APN_MAX_LEN-1)
385 {
386 memcpy(apn,urc_msg,len+1);
387 }
388 urc_msg = strdupReadString_p(p);
389 len = strlen(urc_msg);
390 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
391 {
392 memcpy(apnType,urc_msg,len+1);
393 }
394 urc_msg = strdupReadString_p(p);
395 len = strlen(urc_msg);
396 if(len < LYNQ_IFACE_NAME_MAX_LEN-1)
397 {
398 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
399 }
400 //sendSignalDataCallStateChange();
401 int apnId = getLynqApnID(apnType);
402 if(apnId >= 0)
403 {
404 if(lynq_apn_table[apnId].hasTimeout==1)
405 {
406 LYERRLOG("apn:%s has time out",lynq_apn_table[apnId].apn);
407 lynq_deactive_data_call(&apnId);
408 continue;
409 }
410 updateApnTable(&lynq_apn_table[apnId], apn,apnType,ifaceName);
411 }
412 lynq_data_call_change_id = apnId;
413 sendSignalPdnChange();
414 LYDBGLOG("data call state:%d",lynq_data_call);
415 if(lynq_data_call==1)
416 {
417 sendSignalDataCallStateChange();
418 lynq_data_call = 0;
419 }
420 }
421 else
422 {
423 urc_msg = strdupReadString_p(p);
424 len = strlen(urc_msg);
425 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
426 {
427 memcpy(apnType,urc_msg,len+1);
428 }
429 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
430 int apnId = getLynqApnID(apnType);
431 if(apnId >= 0)
432 {
433 lynq_data_call_change_id = apnId;
434 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
435 }
436 sendSignalPdnChange();
437 LYDBGLOG("data call state:%d",lynq_data_call);
438 if(lynq_data_call==1)
439 {
440 sendSignalDataCallStateChange();
441 lynq_data_call = 0;
442 }
443 }
444 break;
445 }
rjw20006d12022-04-21 16:29:04 +0800446 case 9004:
447 {
448 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
449 urc_msg = strdupReadString_p(p);
450 if (NULL == urc_msg)
451 {
452 LYERRLOG("error apn msg");
453 }
454 else
455 {
456 bzero(g_lynq_apn_result, 1024);
457 strcpy(g_lynq_apn_result, urc_msg);
458 sendSignalApnChange();
459 }
460 break;
461 }
462 case 9005:
463 {
464 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
465 urc_msg = strdupReadString_p(p);
466 if (NULL == urc_msg)
467 {
468 LYERRLOG("error apn msg");
469 }
470 else
471 {
472 bzero(g_lynq_apn_result, 1024);
473 strcpy(g_lynq_apn_result, urc_msg);
474 sendSignalApnChange();
475 }
476 }
lhf81a46f2022-02-13 23:57:37 -0800477 default:
478 break;
479 }
480 }
481 delete p;
482 p = NULL;
483 }
484 close(socket_fd);
485}
486int lynq_socket_urc_start()
487{
488 int socket_fd=0;
489 int rt=0;
490 int len=0;
491 int on=1;
492 struct sockaddr_in urc_local_addr;
493 pthread_attr_t attr;
lh13586612022-01-11 21:58:58 -0800494 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
lh13586612022-01-11 21:58:58 -0800495 if(socket_fd < 0)
496 {
lhf81a46f2022-02-13 23:57:37 -0800497 perror("creaet socket for udp fail");
lh13586612022-01-11 21:58:58 -0800498 return -1;
lhf81a46f2022-02-13 23:57:37 -0800499 }
500 urc_local_addr.sin_family = AF_INET;
501 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
502 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
503 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
lh13586612022-01-11 21:58:58 -0800504 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
505 if(rt<0)
506 {
lhf81a46f2022-02-13 23:57:37 -0800507 perror("SO_REUSEADDR fail\n");
508 return -1;
509 }
510 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
lh13586612022-01-11 21:58:58 -0800511 if (rt == -1)
512 {
lhf81a46f2022-02-13 23:57:37 -0800513 perror("bind failed");
lh13586612022-01-11 21:58:58 -0800514 return -1;
lhf81a46f2022-02-13 23:57:37 -0800515 }
516 pthread_attr_init(&attr);
517 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
518 rt = pthread_create(&lynq_data_tid,&attr,thread_urc_recv,(void *)socket_fd);
519 if(rt < 0)
lh13586612022-01-11 21:58:58 -0800520 {
lhf81a46f2022-02-13 23:57:37 -0800521 LYERRLOG("urc loop failure!!!\n");
522 return -1;
523 }
524 LYDBGLOG("urc loop success!!!\n");
525 return 0;
526}
527int lynq_init_data(int uToken)
528{
rjw22947c22022-03-15 09:21:29 +0800529 if (g_lynq_data_init_flag == 1)
530 {
531 LYERRLOG("init twice is not allowed");
532 return -1;
533 }
534 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800535 int result = 0;
536 Global_uToken = uToken;
537 data_urc_recive_status = 1;
538 LYLOGSET(LOG_INFO);
539 LYLOGEINIT(USER_LOG_TAG);
540 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800541 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800542 if(result!=0)
543 {
544 LYERRLOG("init socket client fail!!!");
545 return -1;
546 }
547 result = lynq_socket_urc_start();
548 if(result!=0)
549 {
550 LYERRLOG("init socket urc fail!!!");
551 return -1;
552 }
553 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
554 LYDBGLOG("lynq init call success!!!");
555 return 0;
556
557}
558int lynq_deinit_data()
559{
560 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800561 if (g_lynq_data_init_flag == 0)
562 {
563 LYERRLOG("deinit twice is not allowed");
564 return ret;
565 }
566 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800567 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
568 {
569 if(strlen(lynq_apn_table[i].apnType)!=0)
570 {
571 lynq_deactive_data_call(&i);
572 }
573 }
574 if(lynq_client_sockfd>0)
575 {
576 close(lynq_client_sockfd);
577 }
578 data_urc_recive_status = 0;
rjw22947c22022-03-15 09:21:29 +0800579 if (lynq_data_tid > 0)
580 {
581 ret = pthread_cancel(lynq_data_tid);
582 LYDBGLOG("pthread cancel ret = %d",ret);
583 ret = pthread_join(lynq_data_tid,NULL);
584 LYDBGLOG("pthread join ret = %d",ret);
585 }
lhf81a46f2022-02-13 23:57:37 -0800586 return 0;
587}
588int lynq_setup_data_call(int *handle)
589{
590 Parcel p;
591 lynq_client_t client;
592 int resp_type = -1;
593 int request = -1;
594 int slot_id = -1;
595 int error = -1;
596 char iface = NULL;
597 int lynq_data_call_id = 0;
598 if(handle==NULL)
599 {
600 LYERRLOG("handle is null!!!");
601 return LYNQ_E_NULL_ANONALY;
602 }
603 client.uToken = Global_uToken;
604 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
605 client.paramLen = 0;
606 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
607 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800608 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800609 if(send_request(lynq_client_sockfd,&client)==-1)
610 {
611 LYERRLOG("send request fail");
612 perror("[LYNQ_DATA] send request fail:");
613 return -1;
614 }
615 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800616 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800617 JumpHeader(p,&resp_type,&request,&slot_id,&error);
618 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
619 lynq_data_call_id = updateApn("default");
620 lynq_data_call = 1;
621 if(error==0)
622 {
rjw20006d12022-04-21 16:29:04 +0800623 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800624 {
625 error = LYNQ_E_TIME_OUT;
626 LYERRLOG("timeout:wait data Call state fail!!!");
627 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
628 return error;
629 }
630 *handle = lynq_data_call_id;
631 }
632 return error;
633}
634int lynq_deactive_data_call(int *handle)
635{
636 Parcel p;
637 lynq_client_t client;
638 int resp_type = -1;
639 int request = -1;
640 int slot_id = -1;
641 int error = -1;
642 int lynq_data_call_id = -1;
643 lynq_data_call_id = *handle;
644 if(handle==NULL)
645 {
646 LYERRLOG("handle is null!!!");
647 return -1;
648 }
649 client.uToken = Global_uToken;
650 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
651 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
652 {
653 client.paramLen = 0;
654 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800655 }
656 else
657 {
lhf81a46f2022-02-13 23:57:37 -0800658 client.paramLen = 1;
659 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
660 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
661 }
662 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800663 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800664 if(send_request(lynq_client_sockfd,&client)==-1)
665 {
666 LYERRLOG("send request fail");
667 perror("[LYNQ_DATA] send request fail:");
668 return -1;
669 }
670 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800671 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800672 JumpHeader(p,&resp_type,&request,&slot_id,&error);
673 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
674 cleanOnceApnTable(lynq_data_call_id);
675 return error;
676}
677int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
678{
679 Parcel p;
680 lynq_client_t client;
681 int resp_type = -1;
682 int request = -1;
683 int slot_id = -1;
684 int error = -1;
685 char iface = NULL;
686 int lynq_data_call_id = -1;
687 char *argv[10] = {};
688 if(handle==NULL||apn==NULL||apnType==NULL)
689 {
690 LYERRLOG("handle ,apn or apntype is null!!!");
691 return -1;
692 }
693 if(user==NULL)
694 {
695 argv[1] = "null";
696 }
697 else
698 {
699 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800700 }
701 if(password==NULL)
702 {
lhf81a46f2022-02-13 23:57:37 -0800703 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800704 }
705 else
706 {
lhf81a46f2022-02-13 23:57:37 -0800707 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800708 }
709 if(authType==NULL)
710 {
lhf81a46f2022-02-13 23:57:37 -0800711 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800712 }
713 else
714 {
lhf81a46f2022-02-13 23:57:37 -0800715 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800716 }
717 if(normalProtocol==NULL)
718 {
lhf81a46f2022-02-13 23:57:37 -0800719 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800720 }
721 else
722 {
lhf81a46f2022-02-13 23:57:37 -0800723 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800724 }
725 if(roamingProtocol==NULL)
726 {
lhf81a46f2022-02-13 23:57:37 -0800727 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800728 }
729 else
730 {
lhf81a46f2022-02-13 23:57:37 -0800731 argv[5] = roamingProtocol;
732 }
733 client.uToken = Global_uToken;
734 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
735 client.paramLen = 7;
736 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
737 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
738 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800739 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800740 if(send_request(lynq_client_sockfd,&client)==-1)
741 {
742 LYERRLOG("send request fail");
743 perror("[LYNQ_DATA] send request fail:");
744 return -1;
745 }
746 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800747 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800748 JumpHeader(p,&resp_type,&request,&slot_id,&error);
749 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
750 lynq_data_call_id = updateApn(apnType);
751 lynq_data_call = 1;
752 if(error==0)
753 {
754 if(waitDataCallstateChange(20000)==ETIMEDOUT)//20s
755 {
756 error = LYNQ_E_TIME_OUT;
757 LYERRLOG("timeout:wait data Call state fail!!!");
758 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
759 return error;
760 }
761 *handle = lynq_data_call_id;
762 }
763 return error;
764}
765/*
766int lynq_deactive_data_call_sp(int *handle,char *apnType)
767{
768 Parcel p;
769 lynq_client_t client;
770 int resp_type = -1;
771 int request = -1;
772 int slot_id = -1;
773 int error = -1;
774 if(handle==NULL||apnType==NULL)
775 {
776 LYERRLOG("handle is null!!!");
777 return -1;
778 }
779 client.uToken = Global_uToken;
780 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
781 client.paramLen = 1;
782 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
783 sprintf(client.param,"%s",apnType);
784 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
785 if(send_request(lynq_client_sockfd,&client)==-1)
786 {
787 LYERRLOG("send request fail");
788 perror("[LYNQ_DATA] send request fail:");
789 return -1;
790 }
791 get_response(lynq_client_sockfd,p);
792 JumpHeader(p,&resp_type,&request,&slot_id,&error);
793 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
794 return error;
795}
796*/
797int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
798{
799 Parcel p;
800 lynq_client_t client;
801 int resp_type = -1;
802 int request = -1;
803 int slot_id = -1;
804 int error = -1;
805 int version =0;
806 int num = 0;
807 int temp_int =0;
808 char *temp_char = NULL;
809 if(dataCallList==NULL)
810 {
811 LYERRLOG("dataCallList is null!!!");
812 return -1;
813 }
814 client.uToken = Global_uToken;
815 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
816 client.paramLen = 0;
817 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
818 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800819 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800820 if(send_request(lynq_client_sockfd,&client)==-1)
821 {
822 LYERRLOG("send request fail");
823 perror("[LYNQ_DATA] send request fail:");
824 return -1;
825 }
826 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800827 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800828 JumpHeader(p,&resp_type,&request,&slot_id,&error);
829 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
830 p.readInt32(&version);
831 if(version==11)
832 {
833 p.readInt32(&num);
834 *realNum = num;
835 for (int i = 0; i < num; i++)
836 {
837 p.readInt32(&dataCallList[i].status);
838 p.readInt32(&dataCallList[i].suggestedRetryTime);
839 p.readInt32(&dataCallList[i].cid);
840 p.readInt32(&dataCallList[i].active);
841 temp_char = strdupReadString(p);
842 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
843 temp_char = strdupReadString(p);
844 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
845 temp_char = strdupReadString(p);
846 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
847 temp_char = strdupReadString(p);
848 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
849 temp_char = strdupReadString(p);
850 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
851 temp_char = strdupReadString(p);
852 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
853 p.readInt32(&dataCallList[i].mtu);
854 }
855 }
856 return error;
857}
858int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
859{
860 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
861 int number = 0;
862 int lynq_data_call_id = 0;
863 int error = 0;
864 lynq_data_call_id = *handle;
865 if(handle==NULL)
866 {
867 LYERRLOG("handle is NULL");
868 return LYNQ_E_NULL_ANONALY;
869 }
870 memset(interDataCallList,0,sizeof(interDataCallList));
871 error = getDataCallLists(interDataCallList,&number);
872 if(error == 0)
873 {
874 for(int i = 0;i < number;i++)
875 {
876 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
877 {
878 dataCallList->active = interDataCallList[i].active;
879 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
880 dataCallList->cid = interDataCallList[i].cid;
881 dataCallList->status = interDataCallList[i].status;
882 dataCallList->mtu = interDataCallList[i].mtu;
883 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
884 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
885 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
886 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
887 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
888 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
889 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
890 }
891 }
892 }
893 return error;
894}
895int lynq_wait_data_call_state_change(int *handle)
896{
897 waitPdnChange();
898 *handle = lynq_data_call_change_id;
899 LYINFLOG("lynq data call id:%d",lynq_data_call_change_id);
900 return 0;
901}
902/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +0800903
904/*Typethree add for T800 platform 2022/04/21 start*/
905int insert_apn_char(char *agc, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier)
906{
rjw0cdacbc2022-06-22 10:51:07 +0800907 int ret = 0;
908 int fact_apn_id=0;
909 int tmp_id_num = 0;
910 char tmp_ID[16]="";
911 char apn_info_buf[LYNQ_DATA_UCI_BUF]="";
912 char apn_info_outbuf[LYNQ_DATA_UCI_BUF];
rjw20006d12022-04-21 16:29:04 +0800913 char strtmp[10][32];
rjw0cdacbc2022-06-22 10:51:07 +0800914
915 sprintf(apn_info_buf,"%s.%s.%s",LYNQ_UCI_FILE,LYNQ_DATA_UCI_APN_SECTION,LYNQ_DATA_UCI_APN_KEY);
916 ret = lynq_uci_get(apn_info_buf,apn_info_outbuf);
917 if (ret != UCI_OK)
918 {
919 LYERRLOG("Description APN failed to allocate an ID :ret = -1");
920 return -1;
921 }
922 tmp_id_num = atoi(apn_info_outbuf);
923 fact_apn_id = -tmp_id_num;
924 tmp_id_num = tmp_id_num + 1;
925
926 apn_info_buf[LYNQ_DATA_UCI_BUF]="";
927 sprintf(apn_info_buf,"%s.%s.%s=%d",LYNQ_UCI_FILE,LYNQ_DATA_UCI_APN_SECTION,LYNQ_DATA_UCI_APN_KEY,tmp_id_num);
928
929 ret = lynq_uci_set(apn_info_buf);
930 if (ret != UCI_OK)
931 {
932 LYERRLOG("Description APN failed to allocate an ID :ret = -2");
933 return -1;
934 }
rjw20006d12022-04-21 16:29:04 +0800935 if (mcc == NULL)
936 {
937 sprintf(strtmp[1], "mcc=;");
938 }
939 else
940 {
941 sprintf(strtmp[1], "mcc=%s;", mcc);
942 }
943 if (mnc == NULL)
944 {
945 sprintf(strtmp[12], "mnc=;");
946 }
947 else
948 {
949 sprintf(strtmp[2], "mnc=%s;", mnc);
950 }
951 if (apn == NULL)
952 {
953 sprintf(strtmp[3], "apn=;");
954 }
955 else
956 {
957 sprintf(strtmp[3], "apn=%s;", apn);
958 }
959 if (apntype == NULL)
960 {
961 sprintf(strtmp[4], "apntype=;");
962 }
963 else
964 {
965 sprintf(strtmp[4], "apntype=%s;", apntype);
966 }
967 if (user == NULL)
968 {
969 sprintf(strtmp[5], "user=;");
970 }
971 else
972 {
973 sprintf(strtmp[5], "user=%s;", user);
974 }
975 if (password == NULL)
976 {
977 sprintf(strtmp[6], "password=;");
978 }
979 else
980 {
981 sprintf(strtmp[6], "password=%s;", password);
982 }
983 if (normalprotocol == NULL)
984 {
985 sprintf(strtmp[7], "normalprotocol=;");
986 }
987 else
988 {
989 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
990 }
991 if (roamingprotocol == NULL)
992 {
993 sprintf(strtmp[8], "roamingprotocol=;");
994 }
995 else
996 {
997 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
998 }
999 if (carrier == NULL)
1000 {
1001 sprintf(strtmp[9], "carrier=;");
1002 }
1003 else
1004 {
1005 sprintf(strtmp[9], "carrier=%s;", carrier);
1006 }
rjw0cdacbc2022-06-22 10:51:07 +08001007 sprintf(agc, "id=%d;%s%s%s%s%s%s%s%s%s",fact_apn_id, strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]);
1008
rjw20006d12022-04-21 16:29:04 +08001009 return 0;
1010}
1011
1012int 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)
1013{
1014 char strtmp[10][32];
1015 if (id == NULL)
1016 {
1017 sprintf(strtmp[0], "id=;");
1018 }
1019 else
1020 {
1021 sprintf(strtmp[0], "id=%s;", id);
1022 }
1023 if (mcc == NULL)
1024 {
1025 sprintf(strtmp[1], "mcc=;");
1026 }
1027 else
1028 {
1029 sprintf(strtmp[1], "mcc=%s;", mcc);
1030 }
1031 if (mnc == NULL)
1032 {
1033 sprintf(strtmp[2], "mnc=;");
1034 }
1035 else
1036 {
1037 sprintf(strtmp[2], "mnc=%s;", mnc);
1038 }
1039 if (apn == NULL)
1040 {
1041 sprintf(strtmp[3], "apn=;");
1042 }
1043 else
1044 {
1045 sprintf(strtmp[3], "apn=%s;", apn);
1046 }
1047 if (apntype == NULL)
1048 {
1049 sprintf(strtmp[4], "apntype=;");
1050 }
1051 else
1052 {
1053 sprintf(strtmp[4], "apntype=%s;", apntype);
1054 }
1055 if (user == NULL)
1056 {
1057 sprintf(strtmp[5], "user=;");
1058 }
1059 else
1060 {
1061 sprintf(strtmp[5], "user=%s;", user);
1062 }
1063 if (password == NULL)
1064 {
1065 sprintf(strtmp[6], "password=;");
1066 }
1067 else
1068 {
1069 sprintf(strtmp[6], "password=%s;", password);
1070 }
1071 if (normalprotocol == NULL)
1072 {
1073 sprintf(strtmp[7], "normalprotocol=;");
1074 }
1075 else
1076 {
1077 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1078 }
1079 if (roamingprotocol == NULL)
1080 {
1081 sprintf(strtmp[8], "roamingprotocol=;");
1082 }
1083 else
1084 {
1085 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1086 }
1087 if (carrier == NULL)
1088 {
1089 sprintf(strtmp[9], "carrier=;");
1090 }
1091 else
1092 {
1093 sprintf(strtmp[9], "carrier=%s;", carrier);
1094 }
1095 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]);
1096 return 0;
1097}
1098
rjwaf4b1612022-06-13 17:26:01 +08001099
1100int 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)
1101{
1102 char strtmp[10][32];
1103 if (id == NULL)
1104 {
1105 sprintf(strtmp[0], "");
1106 }
1107 else
1108 {
1109 sprintf(strtmp[0], "id=%s;", id);
1110 }
1111 if (mcc == NULL)
1112 {
1113 sprintf(strtmp[1], "");
1114 }
1115 else
1116 {
1117 sprintf(strtmp[1], "mcc=%s;", mcc);
1118 }
1119 if (mnc == NULL)
1120 {
1121 sprintf(strtmp[2], "");
1122 }
1123 else
1124 {
1125 sprintf(strtmp[2], "mnc=%s;", mnc);
1126 }
1127 if (apn == NULL)
1128 {
1129 sprintf(strtmp[3], "");
1130 }
1131 else
1132 {
1133 sprintf(strtmp[3], "apn=%s;", apn);
1134 }
1135 if (apntype == NULL)
1136 {
1137 sprintf(strtmp[4], "");
1138 }
1139 else
1140 {
1141 sprintf(strtmp[4], "apntype=%s;", apntype);
1142 }
1143 if (user == NULL)
1144 {
1145 sprintf(strtmp[5], "");
1146 }
1147 else
1148 {
1149 sprintf(strtmp[5], "user=%s;", user);
1150 }
1151 if (password == NULL)
1152 {
1153 sprintf(strtmp[6], "");
1154 }
1155 else
1156 {
1157 sprintf(strtmp[6], "password=%s;", password);
1158 }
1159 if (normalprotocol == NULL)
1160 {
1161 sprintf(strtmp[7], "");
1162 }
1163 else
1164 {
1165 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1166 }
1167 if (roamingprotocol == NULL)
1168 {
1169 sprintf(strtmp[8], "");
1170 }
1171 else
1172 {
1173 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1174 }
1175 if (carrier == NULL)
1176 {
1177 sprintf(strtmp[9], "");
1178 }
1179 else
1180 {
1181 sprintf(strtmp[9], "carrier=%s;", carrier);
1182 }
1183 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]);
1184 return 0;
1185}
1186
rjw20006d12022-04-21 16:29:04 +08001187static char *lynqStrdupReadString(Parcel &p)
1188{
1189 size_t stringlen;
1190 const char16_t *s16;
1191
1192 s16 = p.readString16Inplace(&stringlen);
1193 return strndup16to8(s16, stringlen);
1194}
1195
1196int 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)
1197{
1198 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1199 {
1200 LYERRLOG("There are no valid parameters");
1201 return -1;
1202 }
1203 lynq_client_t client;
1204 char argc[512];
1205 char recvline[LYNQ_REC_BUF];
rjw0cdacbc2022-06-22 10:51:07 +08001206 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001207 Parcel p;
1208 if (cmd == 0) // insert apn db
1209 {
rjw0cdacbc2022-06-22 10:51:07 +08001210 res = insert_apn_char(argc, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1211 if (res != UCI_OK)
1212 {
1213 LYERRLOG("Description APN failed to allocate an ID");
1214 return -1;
1215 }
rjw20006d12022-04-21 16:29:04 +08001216 client.uToken = Global_uToken;
1217 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1218 client.paramLen = 2;
1219 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1220 sprintf(client.param, "%d %s", cmd, argc);
1221 }
1222 else if (cmd == 1)
1223 {
1224 if (NULL == id)
1225 {
1226 LYERRLOG("id is NULL!!!please input id: ");
1227 }
1228 sprintf(argc, "id=%s", id);
1229 client.uToken = Global_uToken;
1230 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1231 client.paramLen = 2;
1232 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1233 sprintf(client.param, "%d %s", cmd, argc);
1234 }
1235 else if (cmd == 2)
1236 {
rjwaf4b1612022-06-13 17:26:01 +08001237 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001238 client.uToken = Global_uToken;
1239 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1240 client.paramLen = 2;
1241 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1242 sprintf(client.param, "%d %s", cmd, argc);
1243 }
1244 else if (cmd == 3)
1245 {
1246 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1247 client.uToken = Global_uToken;
1248 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1249 client.paramLen = 2;
1250 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1251 sprintf(client.param, "%d %s", cmd, argc);
1252 }
1253 else
1254 {
1255 LYERRLOG("incoming command is invalid");
1256 return -1;
1257 }
1258 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001259 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001260 if(send_request(lynq_client_sockfd,&client)==-1)
1261 {
1262 LYERRLOG("send request fail");
1263 return -1;
1264 }
rjwed00d042022-05-25 09:18:16 +08001265 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001266 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001267 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001268 LYINFLOG(">>>>>output info:%s",out);
1269 return 0;
1270}
1271
1272int lynq_reset_apn(char *result)
1273{
1274 Parcel p;
1275 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001276 if (NULL == result)
1277 {
1278 LYERRLOG("incoming paramters error");
1279 }
rjw20006d12022-04-21 16:29:04 +08001280 client.uToken = Global_uToken;
1281 client.request = 2000 + 194;
1282 client.paramLen = 0;
1283 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1284 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001285 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001286 if (send_request(lynq_client_sockfd, &client) == -1)
1287 {
1288 LYERRLOG("send request fail");
1289 return -1;
1290 }
rjwed00d042022-05-25 09:18:16 +08001291 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001292 waitApnResult();
1293 strcpy(result, g_lynq_apn_result);
1294 LYINFLOG(">>>>>result:%s",result);
1295 return 0;
1296}
1297
rjw3bcbbf12022-04-22 16:47:18 +08001298/*Typethree add for T800 platform 2022/04/21 end*/