blob: 677fb5f2a1f88d3aaef92af9713a5710f9a1cb9d [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
rjw61fcae32022-08-18 14:03:39 +080026
rjw0cdacbc2022-06-22 10:51:07 +080027
28
29
lhf81a46f2022-02-13 23:57:37 -080030using ::android::Parcel;
31typedef struct{
32 int uToken;
33 int request;
34 int paramLen;
35 char param[LYNQ_REQUEST_PARAM_BUF];
36}lynq_client_t;
lh13586612022-01-11 21:58:58 -080037typedef enum{
38 LYNQ_E_CARDSTATE_ERROR=8000,
39 /* The voice service state is out of service*/
40 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
41 /* The voice service state is EMERGENCY_ONLY*/
42 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
43 /* The radio power is power off*/
44 LYNQ_E_STATE_POWER_OFF=8003,
45 LYNQ_E_TIME_OUT=8004,
46 /*create or open sms DB fail */
47 LYNQ_E_SMS_DB_FAIL=8005,
48 /*Failed to execute sql statement*/
49 LYNQ_E_SMS_SQL_FAIL = 8006,
50 LYNQ_E_SMS_NOT_FIND = 8007,
51 /* The logic conflict*/
52 LYNQ_E_CONFLICT=9000,
53 /*Null anomaly*/
54 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080055}LYNQ_E;
56
57int lynq_client_sockfd = 0;
58int Global_uToken = 0;
59bool data_urc_recive_status = 1;
60int lynq_data_call_change_id = -1;
61pthread_t lynq_data_tid =-1;
62static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
63static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
64static pthread_mutex_t s_pdn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
65static pthread_cond_t s_pdn_change_cond = PTHREAD_COND_INITIALIZER;
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;
68
rjwed00d042022-05-25 09:18:16 +080069/**g_lynq_data_sendto_mutex
70* @brief mark data send request mutex
71*/
72static pthread_mutex_t g_lynq_data_sendto_mutex;
73
rjw22947c22022-03-15 09:21:29 +080074/**g_lynq_data_init_flag
75* @brief mark data initialization state
76* 0:deinit status
77* 1:init state
78*/
79static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080080/**g_lynq_apn_result
81* @brief temp of apn result info
82*/
83char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +080084
rjw20006d12022-04-21 16:29:04 +080085typedef struct
86{
lhf81a46f2022-02-13 23:57:37 -080087 char apn[LYNQ_APN_MAX_LEN];
88 char apnType[LYNQ_APN_TYPE_MAX_LEN];
89 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
90 int hasUsed;
91 int hasTimeout;
92}lynq_apn_t;
93lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
94lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
95int lynq_data_call = 0;
96int millli_sleep_with_restart(int millisecond)
lh13586612022-01-11 21:58:58 -080097{
lhf81a46f2022-02-13 23:57:37 -080098 int left = millisecond*1000;
99 while (left > 0)
100 {
101 left = usleep(left);
102 }
103
104 return 0;
105}
106int getLynqApnID(char apnType[])
107{
108 int ret = 0;
109 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
110 {
111 if(strcmp(lynq_apn_table[ret].apnType,apnType)==0)
lh13586612022-01-11 21:58:58 -0800112 {
lhf81a46f2022-02-13 23:57:37 -0800113 return ret;
114 }
115 }
116 return -1;
117}
118void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
119{
120 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
121 if(apn_table==NULL)
122 {
123 LYERRLOG("apn_table is null");
124 return;
125 }
126 memcpy(apn_table->apn,apn,strlen(apn)+1);
127 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
128 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
129 apn_table->hasTimeout = 0;
130 apn_table->hasUsed = 1;
131 return;
132}
133void cleanOnceApnTable(int apnId)
134{
135 LYDBGLOG("apn id:%d",apnId);
136 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
137 {
138 LYERRLOG("apn id is invalid!!!");
139 return;
140 }
141 lynq_apn_table[apnId].hasTimeout = 0;
142 lynq_apn_table[apnId].hasUsed = 0;
143 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
144 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
145 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
146 return;
147}
148int getUnusedElement()
149{
150 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
151 {
152 if(lynq_apn_table[i].hasUsed!=1)
153 {
154 return i;
155 }
156 }
157 return -1;
158}
159int updateApn(char apnType[])
160{
161 int ret = 0;
162 ret = getUnusedElement();
163 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
164 lynq_apn_table[ret].hasUsed = 1;
165 return ret;
166}
rjw1309e232022-07-22 09:54:06 +0800167
168int handleCheck(int handle)
169{
170 if (lynq_apn_table[handle].hasUsed == 1)
171 {
172 return 0;
173 }
174 else
175 {
176 return -1;
177 }
178}
rjw20006d12022-04-21 16:29:04 +0800179int waitApnResult()
180{
181 int ret = 0;
182 LYINFLOG("start wait apn result!!!");
183 int sec = 0;
184 int usec = 0;
185 struct timeval now;
186 struct timespec timeout;
187 gettimeofday(&now, NULL);
188 sec = 20000 / 1000;
189 usec = 20000 % 1000;
190 timeout.tv_sec = now.tv_sec + sec;
191 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
192 pthread_mutex_lock(&s_lynq_apn_change_mutex);
193 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
194 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
195 return ret;
196}
197
198void sendSignalApnChange()
199{
200 LYINFLOG("start send Signal Apn Change");
201 pthread_mutex_lock(&s_lynq_apn_change_mutex);
202 pthread_cond_signal(&s_lynq_apn_change_cond);
203 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
204 return;
205}
lhf81a46f2022-02-13 23:57:37 -0800206
207int waitPdnChange()
208{
209 int ret = 0;
210 pthread_mutex_lock(&s_pdn_change_mutex);
211 ret = pthread_cond_wait(&s_pdn_change_cond,&s_pdn_change_mutex);
212 pthread_mutex_unlock(&s_pdn_change_mutex);
213 return ret;
214}
215int waitDataCallstateChange(int mtime)
216{
217 int ret = 0;
218 int sec = 0;
219 int usec = 0;
220 struct timeval now;
221 struct timespec timeout;
222 gettimeofday(&now,NULL);
223 sec = mtime/1000;
224 usec = mtime%1000;
225 timeout.tv_sec = now.tv_sec+sec;
226 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
227 pthread_mutex_lock(&s_data_call_state_change_mutex);
228 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
229 pthread_mutex_unlock(&s_data_call_state_change_mutex);
230 return ret;
231}
232void sendSignalDataCallStateChange()
233{
234 pthread_mutex_lock(&s_data_call_state_change_mutex);
235 pthread_cond_signal(&s_data_call_state_change_cond);
236 pthread_mutex_unlock(&s_data_call_state_change_mutex);
237 return;
238}
239void sendSignalPdnChange()
240{
241 pthread_mutex_lock(&s_pdn_change_mutex);
242 pthread_cond_signal(&s_pdn_change_cond);
243 pthread_mutex_unlock(&s_pdn_change_mutex);
244 return;
245}
246
247int get_response(int sockfd,Parcel &p)
248{
249 int len = 0;
250 char recvline[LYNQ_REC_BUF];
251 bzero(recvline,LYNQ_REC_BUF);
252 /* receive data from server */
rjw08528682022-07-04 21:28:02 +0800253 len = read(sockfd, recvline, LYNQ_REC_BUF);
254 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800255 {
rjw747deea2022-07-01 18:25:30 +0800256 LYERRLOG("read error");
lhf81a46f2022-02-13 23:57:37 -0800257 return -1;
258 }
259 if (recvline != NULL) {
260 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
261 p.setDataPosition(0);
262 }
263 return 0;
264}
q.huang7de1d662022-09-13 14:19:24 +0800265int JumpHeader(Parcel &p,int *resp_type,int *token, int *request,int *slot_id,int *error)
lhf81a46f2022-02-13 23:57:37 -0800266{
267 if(p.dataAvail() > 0)
268 {
269 p.readInt32(resp_type);
q.huang7de1d662022-09-13 14:19:24 +0800270 p.readInt32(token);
lhf81a46f2022-02-13 23:57:37 -0800271 p.readInt32(request);
272 p.readInt32(slot_id);
273 p.readInt32(error);
274 return 0;
275 }
276 else
277 {
278 return -1;
279 }
280}
281int send_request(int sockfd,lynq_client_t *client_tmp)
282{
283 int ret=0;
284 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
285 if(ret==-1)
286 {
287 perror("write error");
288 return -1;
289 }
290 return 0;
291}
292static char *strdupReadString(Parcel &p) {
293 size_t stringlen;
294 const char16_t *s16;
295 s16 = p.readString16Inplace(&stringlen);
296 return strndup16to8(s16, stringlen);
297}
298static char *strdupReadString_p(Parcel *p) {
299 size_t stringlen;
300 const char16_t *s16;
301 s16 = p->readString16Inplace(&stringlen);
302 return strndup16to8(s16, stringlen);
303}
304
305
306/*Warren add for T800 platform 2021/11/19 start*/
307int lynq_socket_client_start()
308{
rjw08528682022-07-04 21:28:02 +0800309 struct sockaddr_in lynq_data_socket_server_addr;
lhf81a46f2022-02-13 23:57:37 -0800310 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800311 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
312 lynq_data_socket_server_addr.sin_family = AF_INET;
313 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
314 lynq_data_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
lhf81a46f2022-02-13 23:57:37 -0800315 /*
316 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
317 {
318 printf("[%s] is not a valid IPaddress\n", argv[1]);
319 exit(1);
320 }
321*/
322 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800323 struct timeval timeOut;
324
rjwa59bf312022-07-05 11:50:31 +0800325 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800326 timeOut.tv_usec = 0;
327
328 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
329 {
330 LYERRLOG("time out setting failed");
331 }
332 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 -0800333 {
334 perror("connect error");
335 return -1;
336 }
337 return 0;
338}
339void *thread_urc_recv(void *parg)
340{
341 int socket_fd = (int64_t)parg;
342 int len=0;
343 socklen_t addr_len=0;
344 uint8_t *dataLength = NULL;
345 char urc_data[LYNQ_REC_BUF];
346 char apn[LYNQ_APN_MAX_LEN];
347 char apnType[LYNQ_APN_TYPE_MAX_LEN];
348 int pdnState = 0;
349 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
350 int slot_id = -1;
351 int resp_type = -1;
352 int urcid = -1;
353 char *urc_msg = NULL;
354 Parcel *p = NULL;
355 struct sockaddr_in dest_addr;
356 LYINFLOG("thread_urc_recv in running....\n");
357 while(data_urc_recive_status)
358 {
359 bzero(urc_data,LYNQ_REC_BUF);
360 //get data msg
361 len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
362 if(len <= 0)
363 {
364 perror("thread_urc_recv step2 fail:");
365 millli_sleep_with_restart(1);
lh13586612022-01-11 21:58:58 -0800366 break;
lhf81a46f2022-02-13 23:57:37 -0800367 }
368 LYDBGLOG("=====>urc data len<=====:%d\n",len);
369 p = new Parcel();
370 if(p==NULL)
371 {
372 RLOGD("new parcel failure!!!");
373 break;
374 }
375 p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
376 p->setDataPosition(0);
377 if(p->dataAvail() > 0)
378 {
379 p->readInt32(&resp_type);
380 p->readInt32(&urcid);
381 p->readInt32(&slot_id);
382 //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
383 switch (urcid)
384 {
385 case 9003://LYNQ_URC_DATA_CALL_STATUS_IND
386 {
387 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
388 p->readInt32(&pdnState);
389 bzero(apn,LYNQ_APN_MAX_LEN);
390 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
391 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
392 if(pdnState!=4)//PDN_DISCONNECTED
393 {
394 urc_msg = strdupReadString_p(p);
395 int len = strlen(urc_msg);
396 if(len < LYNQ_APN_MAX_LEN-1)
397 {
398 memcpy(apn,urc_msg,len+1);
399 }
400 urc_msg = strdupReadString_p(p);
401 len = strlen(urc_msg);
402 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
403 {
404 memcpy(apnType,urc_msg,len+1);
405 }
406 urc_msg = strdupReadString_p(p);
407 len = strlen(urc_msg);
408 if(len < LYNQ_IFACE_NAME_MAX_LEN-1)
409 {
410 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
411 }
412 //sendSignalDataCallStateChange();
413 int apnId = getLynqApnID(apnType);
414 if(apnId >= 0)
415 {
416 if(lynq_apn_table[apnId].hasTimeout==1)
417 {
418 LYERRLOG("apn:%s has time out",lynq_apn_table[apnId].apn);
419 lynq_deactive_data_call(&apnId);
420 continue;
421 }
422 updateApnTable(&lynq_apn_table[apnId], apn,apnType,ifaceName);
423 }
424 lynq_data_call_change_id = apnId;
425 sendSignalPdnChange();
426 LYDBGLOG("data call state:%d",lynq_data_call);
427 if(lynq_data_call==1)
428 {
429 sendSignalDataCallStateChange();
430 lynq_data_call = 0;
431 }
432 }
433 else
434 {
435 urc_msg = strdupReadString_p(p);
436 len = strlen(urc_msg);
437 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
438 {
439 memcpy(apnType,urc_msg,len+1);
440 }
441 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
442 int apnId = getLynqApnID(apnType);
443 if(apnId >= 0)
444 {
445 lynq_data_call_change_id = apnId;
446 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
447 }
448 sendSignalPdnChange();
449 LYDBGLOG("data call state:%d",lynq_data_call);
450 if(lynq_data_call==1)
451 {
452 sendSignalDataCallStateChange();
453 lynq_data_call = 0;
454 }
455 }
456 break;
457 }
rjw20006d12022-04-21 16:29:04 +0800458 case 9004:
459 {
460 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
461 urc_msg = strdupReadString_p(p);
462 if (NULL == urc_msg)
463 {
464 LYERRLOG("error apn msg");
465 }
466 else
467 {
468 bzero(g_lynq_apn_result, 1024);
469 strcpy(g_lynq_apn_result, urc_msg);
470 sendSignalApnChange();
471 }
472 break;
473 }
474 case 9005:
475 {
476 LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
477 urc_msg = strdupReadString_p(p);
478 if (NULL == urc_msg)
479 {
480 LYERRLOG("error apn msg");
481 }
482 else
483 {
484 bzero(g_lynq_apn_result, 1024);
485 strcpy(g_lynq_apn_result, urc_msg);
486 sendSignalApnChange();
487 }
488 }
lhf81a46f2022-02-13 23:57:37 -0800489 default:
490 break;
491 }
492 }
493 delete p;
494 p = NULL;
495 }
496 close(socket_fd);
497}
498int lynq_socket_urc_start()
499{
500 int socket_fd=0;
501 int rt=0;
502 int len=0;
503 int on=1;
504 struct sockaddr_in urc_local_addr;
505 pthread_attr_t attr;
lh13586612022-01-11 21:58:58 -0800506 socket_fd = socket(AF_INET,SOCK_DGRAM,0);
lh13586612022-01-11 21:58:58 -0800507 if(socket_fd < 0)
508 {
lhf81a46f2022-02-13 23:57:37 -0800509 perror("creaet socket for udp fail");
lh13586612022-01-11 21:58:58 -0800510 return -1;
lhf81a46f2022-02-13 23:57:37 -0800511 }
512 urc_local_addr.sin_family = AF_INET;
513 urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
514 urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
515 /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
lh13586612022-01-11 21:58:58 -0800516 rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
517 if(rt<0)
518 {
lhf81a46f2022-02-13 23:57:37 -0800519 perror("SO_REUSEADDR fail\n");
520 return -1;
521 }
522 rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
lh13586612022-01-11 21:58:58 -0800523 if (rt == -1)
524 {
lhf81a46f2022-02-13 23:57:37 -0800525 perror("bind failed");
lh13586612022-01-11 21:58:58 -0800526 return -1;
lhf81a46f2022-02-13 23:57:37 -0800527 }
528 pthread_attr_init(&attr);
529 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
530 rt = pthread_create(&lynq_data_tid,&attr,thread_urc_recv,(void *)socket_fd);
531 if(rt < 0)
lh13586612022-01-11 21:58:58 -0800532 {
lhf81a46f2022-02-13 23:57:37 -0800533 LYERRLOG("urc loop failure!!!\n");
534 return -1;
535 }
536 LYDBGLOG("urc loop success!!!\n");
537 return 0;
538}
539int lynq_init_data(int uToken)
540{
rjw22947c22022-03-15 09:21:29 +0800541 if (g_lynq_data_init_flag == 1)
542 {
543 LYERRLOG("init twice is not allowed");
544 return -1;
545 }
546 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800547 int result = 0;
548 Global_uToken = uToken;
549 data_urc_recive_status = 1;
550 LYLOGSET(LOG_INFO);
551 LYLOGEINIT(USER_LOG_TAG);
552 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800553 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800554 if(result!=0)
555 {
556 LYERRLOG("init socket client fail!!!");
557 return -1;
558 }
559 result = lynq_socket_urc_start();
560 if(result!=0)
561 {
562 LYERRLOG("init socket urc fail!!!");
563 return -1;
564 }
565 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
566 LYDBGLOG("lynq init call success!!!");
567 return 0;
568
569}
570int lynq_deinit_data()
571{
572 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800573 if (g_lynq_data_init_flag == 0)
574 {
575 LYERRLOG("deinit twice is not allowed");
576 return ret;
577 }
578 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800579 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
580 {
581 if(strlen(lynq_apn_table[i].apnType)!=0)
582 {
583 lynq_deactive_data_call(&i);
584 }
585 }
586 if(lynq_client_sockfd>0)
587 {
588 close(lynq_client_sockfd);
589 }
590 data_urc_recive_status = 0;
rjw22947c22022-03-15 09:21:29 +0800591 if (lynq_data_tid > 0)
592 {
593 ret = pthread_cancel(lynq_data_tid);
594 LYDBGLOG("pthread cancel ret = %d",ret);
595 ret = pthread_join(lynq_data_tid,NULL);
596 LYDBGLOG("pthread join ret = %d",ret);
597 }
lhf81a46f2022-02-13 23:57:37 -0800598 return 0;
599}
600int lynq_setup_data_call(int *handle)
601{
602 Parcel p;
603 lynq_client_t client;
604 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800605 int token;
lhf81a46f2022-02-13 23:57:37 -0800606 int request = -1;
607 int slot_id = -1;
608 int error = -1;
609 char iface = NULL;
610 int lynq_data_call_id = 0;
611 if(handle==NULL)
612 {
613 LYERRLOG("handle is null!!!");
614 return LYNQ_E_NULL_ANONALY;
615 }
616 client.uToken = Global_uToken;
617 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
618 client.paramLen = 0;
619 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
620 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800621 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800622 if(send_request(lynq_client_sockfd,&client)==-1)
623 {
624 LYERRLOG("send request fail");
625 perror("[LYNQ_DATA] send request fail:");
626 return -1;
627 }
628 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800629 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +0800630 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800631 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
632 lynq_data_call_id = updateApn("default");
633 lynq_data_call = 1;
634 if(error==0)
635 {
rjw20006d12022-04-21 16:29:04 +0800636 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800637 {
638 error = LYNQ_E_TIME_OUT;
639 LYERRLOG("timeout:wait data Call state fail!!!");
640 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
641 return error;
642 }
643 *handle = lynq_data_call_id;
644 }
645 return error;
646}
647int lynq_deactive_data_call(int *handle)
648{
649 Parcel p;
650 lynq_client_t client;
651 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800652 int token;
lhf81a46f2022-02-13 23:57:37 -0800653 int request = -1;
654 int slot_id = -1;
655 int error = -1;
656 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800657 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800658 if(handle==NULL)
659 {
660 LYERRLOG("handle is null!!!");
661 return -1;
662 }
rjw1309e232022-07-22 09:54:06 +0800663 ret = handleCheck(*handle);
664 if (ret != 0)
665 {
666 LYERRLOG("incomming handle is invalid");
667 return -1;
668 }
669 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800670 client.uToken = Global_uToken;
671 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
672 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
673 {
674 client.paramLen = 0;
675 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800676 }
677 else
678 {
lhf81a46f2022-02-13 23:57:37 -0800679 client.paramLen = 1;
680 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
681 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
682 }
683 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800684 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800685 if(send_request(lynq_client_sockfd,&client)==-1)
686 {
687 LYERRLOG("send request fail");
688 perror("[LYNQ_DATA] send request fail:");
689 return -1;
690 }
691 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800692 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +0800693 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800694 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
695 cleanOnceApnTable(lynq_data_call_id);
696 return error;
697}
698int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
699{
700 Parcel p;
701 lynq_client_t client;
702 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800703 int token;
lhf81a46f2022-02-13 23:57:37 -0800704 int request = -1;
705 int slot_id = -1;
706 int error = -1;
707 char iface = NULL;
708 int lynq_data_call_id = -1;
709 char *argv[10] = {};
710 if(handle==NULL||apn==NULL||apnType==NULL)
711 {
712 LYERRLOG("handle ,apn or apntype is null!!!");
713 return -1;
714 }
715 if(user==NULL)
716 {
717 argv[1] = "null";
718 }
719 else
720 {
721 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800722 }
723 if(password==NULL)
724 {
lhf81a46f2022-02-13 23:57:37 -0800725 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800726 }
727 else
728 {
lhf81a46f2022-02-13 23:57:37 -0800729 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800730 }
731 if(authType==NULL)
732 {
lhf81a46f2022-02-13 23:57:37 -0800733 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800734 }
735 else
736 {
lhf81a46f2022-02-13 23:57:37 -0800737 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800738 }
739 if(normalProtocol==NULL)
740 {
lhf81a46f2022-02-13 23:57:37 -0800741 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800742 }
743 else
744 {
lhf81a46f2022-02-13 23:57:37 -0800745 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800746 }
747 if(roamingProtocol==NULL)
748 {
lhf81a46f2022-02-13 23:57:37 -0800749 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800750 }
751 else
752 {
lhf81a46f2022-02-13 23:57:37 -0800753 argv[5] = roamingProtocol;
754 }
755 client.uToken = Global_uToken;
756 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
757 client.paramLen = 7;
758 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
759 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
760 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800761 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800762 if(send_request(lynq_client_sockfd,&client)==-1)
763 {
764 LYERRLOG("send request fail");
765 perror("[LYNQ_DATA] send request fail:");
766 return -1;
767 }
768 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800769 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +0800770 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800771 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
772 lynq_data_call_id = updateApn(apnType);
773 lynq_data_call = 1;
774 if(error==0)
775 {
776 if(waitDataCallstateChange(20000)==ETIMEDOUT)//20s
777 {
778 error = LYNQ_E_TIME_OUT;
779 LYERRLOG("timeout:wait data Call state fail!!!");
780 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
781 return error;
782 }
783 *handle = lynq_data_call_id;
784 }
785 return error;
786}
787/*
788int lynq_deactive_data_call_sp(int *handle,char *apnType)
789{
790 Parcel p;
791 lynq_client_t client;
792 int resp_type = -1;
793 int request = -1;
794 int slot_id = -1;
795 int error = -1;
796 if(handle==NULL||apnType==NULL)
797 {
798 LYERRLOG("handle is null!!!");
799 return -1;
800 }
801 client.uToken = Global_uToken;
802 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
803 client.paramLen = 1;
804 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
805 sprintf(client.param,"%s",apnType);
806 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
807 if(send_request(lynq_client_sockfd,&client)==-1)
808 {
809 LYERRLOG("send request fail");
810 perror("[LYNQ_DATA] send request fail:");
811 return -1;
812 }
813 get_response(lynq_client_sockfd,p);
q.huang7de1d662022-09-13 14:19:24 +0800814 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800815 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
816 return error;
817}
818*/
819int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
820{
821 Parcel p;
822 lynq_client_t client;
823 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800824 int token;
825 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800826 int slot_id = -1;
827 int error = -1;
828 int version =0;
829 int num = 0;
830 int temp_int =0;
831 char *temp_char = NULL;
832 if(dataCallList==NULL)
833 {
834 LYERRLOG("dataCallList is null!!!");
835 return -1;
836 }
837 client.uToken = Global_uToken;
838 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
839 client.paramLen = 0;
840 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
841 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800842 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800843 if(send_request(lynq_client_sockfd,&client)==-1)
844 {
845 LYERRLOG("send request fail");
846 perror("[LYNQ_DATA] send request fail:");
847 return -1;
848 }
849 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800850 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
q.huang7de1d662022-09-13 14:19:24 +0800851 JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800852 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
853 p.readInt32(&version);
854 if(version==11)
855 {
856 p.readInt32(&num);
857 *realNum = num;
858 for (int i = 0; i < num; i++)
859 {
860 p.readInt32(&dataCallList[i].status);
861 p.readInt32(&dataCallList[i].suggestedRetryTime);
862 p.readInt32(&dataCallList[i].cid);
863 p.readInt32(&dataCallList[i].active);
864 temp_char = strdupReadString(p);
865 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
866 temp_char = strdupReadString(p);
867 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
868 temp_char = strdupReadString(p);
869 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
870 temp_char = strdupReadString(p);
871 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
872 temp_char = strdupReadString(p);
873 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
874 temp_char = strdupReadString(p);
875 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
876 p.readInt32(&dataCallList[i].mtu);
877 }
878 }
879 return error;
880}
881int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
882{
883 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
884 int number = 0;
885 int lynq_data_call_id = 0;
886 int error = 0;
887 lynq_data_call_id = *handle;
888 if(handle==NULL)
889 {
890 LYERRLOG("handle is NULL");
891 return LYNQ_E_NULL_ANONALY;
892 }
893 memset(interDataCallList,0,sizeof(interDataCallList));
894 error = getDataCallLists(interDataCallList,&number);
895 if(error == 0)
896 {
897 for(int i = 0;i < number;i++)
898 {
899 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
900 {
901 dataCallList->active = interDataCallList[i].active;
902 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
903 dataCallList->cid = interDataCallList[i].cid;
904 dataCallList->status = interDataCallList[i].status;
905 dataCallList->mtu = interDataCallList[i].mtu;
906 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
907 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
908 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
909 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
910 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
911 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
912 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
913 }
914 }
915 }
916 return error;
917}
918int lynq_wait_data_call_state_change(int *handle)
919{
920 waitPdnChange();
921 *handle = lynq_data_call_change_id;
922 LYINFLOG("lynq data call id:%d",lynq_data_call_change_id);
923 return 0;
924}
925/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +0800926
927/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +0800928
929int 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 +0800930{
931 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +0800932 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +0800933 {
rjw61fcae32022-08-18 14:03:39 +0800934 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +0800935 }
rjw61fcae32022-08-18 14:03:39 +0800936 else
rjw0cdacbc2022-06-22 10:51:07 +0800937 {
rjw61fcae32022-08-18 14:03:39 +0800938 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +0800939 }
rjw20006d12022-04-21 16:29:04 +0800940 if (mcc == NULL)
941 {
942 sprintf(strtmp[1], "mcc=;");
943 }
944 else
945 {
946 sprintf(strtmp[1], "mcc=%s;", mcc);
947 }
948 if (mnc == NULL)
949 {
rjw61fcae32022-08-18 14:03:39 +0800950 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +0800951 }
952 else
953 {
954 sprintf(strtmp[2], "mnc=%s;", mnc);
955 }
956 if (apn == NULL)
957 {
958 sprintf(strtmp[3], "apn=;");
959 }
960 else
961 {
962 sprintf(strtmp[3], "apn=%s;", apn);
963 }
964 if (apntype == NULL)
965 {
966 sprintf(strtmp[4], "apntype=;");
967 }
968 else
969 {
970 sprintf(strtmp[4], "apntype=%s;", apntype);
971 }
972 if (user == NULL)
973 {
974 sprintf(strtmp[5], "user=;");
975 }
976 else
977 {
978 sprintf(strtmp[5], "user=%s;", user);
979 }
980 if (password == NULL)
981 {
982 sprintf(strtmp[6], "password=;");
983 }
984 else
985 {
986 sprintf(strtmp[6], "password=%s;", password);
987 }
988 if (normalprotocol == NULL)
989 {
990 sprintf(strtmp[7], "normalprotocol=;");
991 }
992 else
993 {
994 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
995 }
996 if (roamingprotocol == NULL)
997 {
998 sprintf(strtmp[8], "roamingprotocol=;");
999 }
1000 else
1001 {
1002 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1003 }
1004 if (carrier == NULL)
1005 {
1006 sprintf(strtmp[9], "carrier=;");
1007 }
1008 else
1009 {
1010 sprintf(strtmp[9], "carrier=%s;", carrier);
1011 }
rjw61fcae32022-08-18 14:03:39 +08001012 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 +08001013
rjw20006d12022-04-21 16:29:04 +08001014 return 0;
1015}
1016
1017int 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)
1018{
1019 char strtmp[10][32];
1020 if (id == NULL)
1021 {
1022 sprintf(strtmp[0], "id=;");
1023 }
1024 else
1025 {
1026 sprintf(strtmp[0], "id=%s;", id);
1027 }
1028 if (mcc == NULL)
1029 {
1030 sprintf(strtmp[1], "mcc=;");
1031 }
1032 else
1033 {
1034 sprintf(strtmp[1], "mcc=%s;", mcc);
1035 }
1036 if (mnc == NULL)
1037 {
1038 sprintf(strtmp[2], "mnc=;");
1039 }
1040 else
1041 {
1042 sprintf(strtmp[2], "mnc=%s;", mnc);
1043 }
1044 if (apn == NULL)
1045 {
1046 sprintf(strtmp[3], "apn=;");
1047 }
1048 else
1049 {
1050 sprintf(strtmp[3], "apn=%s;", apn);
1051 }
1052 if (apntype == NULL)
1053 {
1054 sprintf(strtmp[4], "apntype=;");
1055 }
1056 else
1057 {
1058 sprintf(strtmp[4], "apntype=%s;", apntype);
1059 }
1060 if (user == NULL)
1061 {
1062 sprintf(strtmp[5], "user=;");
1063 }
1064 else
1065 {
1066 sprintf(strtmp[5], "user=%s;", user);
1067 }
1068 if (password == NULL)
1069 {
1070 sprintf(strtmp[6], "password=;");
1071 }
1072 else
1073 {
1074 sprintf(strtmp[6], "password=%s;", password);
1075 }
1076 if (normalprotocol == NULL)
1077 {
1078 sprintf(strtmp[7], "normalprotocol=;");
1079 }
1080 else
1081 {
1082 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1083 }
1084 if (roamingprotocol == NULL)
1085 {
1086 sprintf(strtmp[8], "roamingprotocol=;");
1087 }
1088 else
1089 {
1090 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1091 }
1092 if (carrier == NULL)
1093 {
1094 sprintf(strtmp[9], "carrier=;");
1095 }
1096 else
1097 {
1098 sprintf(strtmp[9], "carrier=%s;", carrier);
1099 }
1100 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]);
1101 return 0;
1102}
1103
rjwaf4b1612022-06-13 17:26:01 +08001104
1105int 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)
1106{
1107 char strtmp[10][32];
1108 if (id == NULL)
1109 {
1110 sprintf(strtmp[0], "");
1111 }
1112 else
1113 {
1114 sprintf(strtmp[0], "id=%s;", id);
1115 }
1116 if (mcc == NULL)
1117 {
1118 sprintf(strtmp[1], "");
1119 }
1120 else
1121 {
1122 sprintf(strtmp[1], "mcc=%s;", mcc);
1123 }
1124 if (mnc == NULL)
1125 {
1126 sprintf(strtmp[2], "");
1127 }
1128 else
1129 {
1130 sprintf(strtmp[2], "mnc=%s;", mnc);
1131 }
1132 if (apn == NULL)
1133 {
1134 sprintf(strtmp[3], "");
1135 }
1136 else
1137 {
1138 sprintf(strtmp[3], "apn=%s;", apn);
1139 }
1140 if (apntype == NULL)
1141 {
1142 sprintf(strtmp[4], "");
1143 }
1144 else
1145 {
1146 sprintf(strtmp[4], "apntype=%s;", apntype);
1147 }
1148 if (user == NULL)
1149 {
1150 sprintf(strtmp[5], "");
1151 }
1152 else
1153 {
1154 sprintf(strtmp[5], "user=%s;", user);
1155 }
1156 if (password == NULL)
1157 {
1158 sprintf(strtmp[6], "");
1159 }
1160 else
1161 {
1162 sprintf(strtmp[6], "password=%s;", password);
1163 }
1164 if (normalprotocol == NULL)
1165 {
1166 sprintf(strtmp[7], "");
1167 }
1168 else
1169 {
1170 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1171 }
1172 if (roamingprotocol == NULL)
1173 {
1174 sprintf(strtmp[8], "");
1175 }
1176 else
1177 {
1178 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1179 }
1180 if (carrier == NULL)
1181 {
1182 sprintf(strtmp[9], "");
1183 }
1184 else
1185 {
1186 sprintf(strtmp[9], "carrier=%s;", carrier);
1187 }
1188 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]);
1189 return 0;
1190}
1191
rjw20006d12022-04-21 16:29:04 +08001192static char *lynqStrdupReadString(Parcel &p)
1193{
1194 size_t stringlen;
1195 const char16_t *s16;
1196
1197 s16 = p.readString16Inplace(&stringlen);
1198 return strndup16to8(s16, stringlen);
1199}
1200
1201int 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)
1202{
1203 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1204 {
1205 LYERRLOG("There are no valid parameters");
1206 return -1;
1207 }
1208 lynq_client_t client;
1209 char argc[512];
1210 char recvline[LYNQ_REC_BUF];
rjw0cdacbc2022-06-22 10:51:07 +08001211 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001212 Parcel p;
1213 if (cmd == 0) // insert apn db
1214 {
rjw61fcae32022-08-18 14:03:39 +08001215 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1216
rjw20006d12022-04-21 16:29:04 +08001217 client.uToken = Global_uToken;
1218 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1219 client.paramLen = 2;
1220 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1221 sprintf(client.param, "%d %s", cmd, argc);
1222 }
rjw61fcae32022-08-18 14:03:39 +08001223 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001224 {
1225 if (NULL == id)
1226 {
1227 LYERRLOG("id is NULL!!!please input id: ");
1228 }
1229 sprintf(argc, "id=%s", id);
1230 client.uToken = Global_uToken;
1231 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1232 client.paramLen = 2;
1233 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1234 sprintf(client.param, "%d %s", cmd, argc);
1235 }
rjw61fcae32022-08-18 14:03:39 +08001236 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001237 {
rjwaf4b1612022-06-13 17:26:01 +08001238 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001239 client.uToken = Global_uToken;
1240 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1241 client.paramLen = 2;
1242 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1243 sprintf(client.param, "%d %s", cmd, argc);
1244 }
rjw61fcae32022-08-18 14:03:39 +08001245 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001246 {
1247 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1248 client.uToken = Global_uToken;
1249 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1250 client.paramLen = 2;
1251 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1252 sprintf(client.param, "%d %s", cmd, argc);
1253 }
1254 else
1255 {
1256 LYERRLOG("incoming command is invalid");
1257 return -1;
1258 }
1259 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001260 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001261 if(send_request(lynq_client_sockfd,&client)==-1)
1262 {
1263 LYERRLOG("send request fail");
1264 return -1;
1265 }
rjwed00d042022-05-25 09:18:16 +08001266 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001267 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001268 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001269 LYINFLOG(">>>>>output info:%s",out);
1270 return 0;
1271}
1272
1273int lynq_reset_apn(char *result)
1274{
1275 Parcel p;
1276 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001277 if (NULL == result)
1278 {
1279 LYERRLOG("incoming paramters error");
1280 }
rjw20006d12022-04-21 16:29:04 +08001281 client.uToken = Global_uToken;
1282 client.request = 2000 + 194;
1283 client.paramLen = 0;
1284 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1285 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001286 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001287 if (send_request(lynq_client_sockfd, &client) == -1)
1288 {
1289 LYERRLOG("send request fail");
1290 return -1;
1291 }
rjwed00d042022-05-25 09:18:16 +08001292 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001293 waitApnResult();
1294 strcpy(result, g_lynq_apn_result);
1295 LYINFLOG(">>>>>result:%s",result);
1296 return 0;
1297}
1298
rjw3bcbbf12022-04-22 16:47:18 +08001299/*Typethree add for T800 platform 2022/04/21 end*/