blob: 6772e2dd6741424f3f168bb7bb0648d6fea4fde0 [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
jb.qid5852372023-03-29 10:29:12 +080029#define LYNQ_ADDRESS "127.0.0.1"
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;
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;
74
rjwc3d6e582023-03-28 17:19:11 +080075static int data_waiting_status = 0;
76
rjw22947c22022-03-15 09:21:29 +080077/**g_lynq_data_init_flag
78* @brief mark data initialization state
79* 0:deinit status
80* 1:init state
81*/
82static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080083/**g_lynq_apn_result
84* @brief temp of apn result info
85*/
86char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +080087
rjw7ee7bb42023-01-18 11:34:28 +080088static std::vector<int> s_data_urc_wait_list;
89
rjw20006d12022-04-21 16:29:04 +080090typedef struct
91{
lhf81a46f2022-02-13 23:57:37 -080092 char apn[LYNQ_APN_MAX_LEN];
93 char apnType[LYNQ_APN_TYPE_MAX_LEN];
94 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
95 int hasUsed;
96 int hasTimeout;
97}lynq_apn_t;
98lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
99lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
100int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800101
lhf81a46f2022-02-13 23:57:37 -0800102int getLynqApnID(char apnType[])
103{
104 int ret = 0;
105 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
106 {
107 if(strcmp(lynq_apn_table[ret].apnType,apnType)==0)
lh13586612022-01-11 21:58:58 -0800108 {
lhf81a46f2022-02-13 23:57:37 -0800109 return ret;
110 }
111 }
112 return -1;
113}
rjw7ee7bb42023-01-18 11:34:28 +0800114
lhf81a46f2022-02-13 23:57:37 -0800115void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
116{
117 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
118 if(apn_table==NULL)
119 {
120 LYERRLOG("apn_table is null");
121 return;
122 }
123 memcpy(apn_table->apn,apn,strlen(apn)+1);
124 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
125 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
126 apn_table->hasTimeout = 0;
127 apn_table->hasUsed = 1;
128 return;
129}
rjw7ee7bb42023-01-18 11:34:28 +0800130
lhf81a46f2022-02-13 23:57:37 -0800131void cleanOnceApnTable(int apnId)
132{
133 LYDBGLOG("apn id:%d",apnId);
134 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
135 {
136 LYERRLOG("apn id is invalid!!!");
137 return;
138 }
139 lynq_apn_table[apnId].hasTimeout = 0;
140 lynq_apn_table[apnId].hasUsed = 0;
141 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
142 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
143 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
144 return;
145}
146int getUnusedElement()
147{
148 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
149 {
150 if(lynq_apn_table[i].hasUsed!=1)
151 {
152 return i;
153 }
154 }
155 return -1;
156}
157int updateApn(char apnType[])
158{
159 int ret = 0;
160 ret = getUnusedElement();
161 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
162 lynq_apn_table[ret].hasUsed = 1;
163 return ret;
164}
rjw1309e232022-07-22 09:54:06 +0800165
166int handleCheck(int handle)
167{
168 if (lynq_apn_table[handle].hasUsed == 1)
169 {
170 return 0;
171 }
172 else
173 {
174 return -1;
175 }
176}
rjw20006d12022-04-21 16:29:04 +0800177int waitApnResult()
178{
179 int ret = 0;
180 LYINFLOG("start wait apn result!!!");
181 int sec = 0;
182 int usec = 0;
183 struct timeval now;
184 struct timespec timeout;
185 gettimeofday(&now, NULL);
186 sec = 20000 / 1000;
187 usec = 20000 % 1000;
188 timeout.tv_sec = now.tv_sec + sec;
189 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
190 pthread_mutex_lock(&s_lynq_apn_change_mutex);
191 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
192 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
193 return ret;
194}
195
196void sendSignalApnChange()
197{
198 LYINFLOG("start send Signal Apn Change");
199 pthread_mutex_lock(&s_lynq_apn_change_mutex);
200 pthread_cond_signal(&s_lynq_apn_change_cond);
201 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
202 return;
203}
lhf81a46f2022-02-13 23:57:37 -0800204
205int waitPdnChange()
206{
207 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800208 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
209 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
210 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800211 return ret;
212}
213int waitDataCallstateChange(int mtime)
214{
215 int ret = 0;
216 int sec = 0;
217 int usec = 0;
218 struct timeval now;
219 struct timespec timeout;
220 gettimeofday(&now,NULL);
221 sec = mtime/1000;
222 usec = mtime%1000;
223 timeout.tv_sec = now.tv_sec+sec;
224 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
225 pthread_mutex_lock(&s_data_call_state_change_mutex);
226 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
227 pthread_mutex_unlock(&s_data_call_state_change_mutex);
228 return ret;
229}
230void sendSignalDataCallStateChange()
231{
232 pthread_mutex_lock(&s_data_call_state_change_mutex);
233 pthread_cond_signal(&s_data_call_state_change_cond);
234 pthread_mutex_unlock(&s_data_call_state_change_mutex);
235 return;
236}
237void sendSignalPdnChange()
238{
rjw7ee7bb42023-01-18 11:34:28 +0800239 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
240 pthread_cond_signal(&s_lynq_urc_vector_cond);
241 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800242 return;
243}
244
245int get_response(int sockfd,Parcel &p)
246{
247 int len = 0;
248 char recvline[LYNQ_REC_BUF];
249 bzero(recvline,LYNQ_REC_BUF);
250 /* receive data from server */
rjw08528682022-07-04 21:28:02 +0800251 len = read(sockfd, recvline, LYNQ_REC_BUF);
252 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800253 {
rjw747deea2022-07-01 18:25:30 +0800254 LYERRLOG("read error");
lhf81a46f2022-02-13 23:57:37 -0800255 return -1;
256 }
257 if (recvline != NULL) {
258 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
259 p.setDataPosition(0);
260 }
261 return 0;
262}
rjwfa532972022-09-16 13:39:41 +0800263int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
lhf81a46f2022-02-13 23:57:37 -0800264{
265 if(p.dataAvail() > 0)
266 {
267 p.readInt32(resp_type);
268 p.readInt32(request);
269 p.readInt32(slot_id);
270 p.readInt32(error);
271 return 0;
272 }
273 else
274 {
275 return -1;
276 }
277}
278int send_request(int sockfd,lynq_client_t *client_tmp)
279{
280 int ret=0;
281 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
282 if(ret==-1)
283 {
284 perror("write error");
285 return -1;
286 }
287 return 0;
288}
289static char *strdupReadString(Parcel &p) {
290 size_t stringlen;
291 const char16_t *s16;
292 s16 = p.readString16Inplace(&stringlen);
293 return strndup16to8(s16, stringlen);
294}
295static char *strdupReadString_p(Parcel *p) {
296 size_t stringlen;
297 const char16_t *s16;
298 s16 = p->readString16Inplace(&stringlen);
299 return strndup16to8(s16, stringlen);
300}
301
lhf81a46f2022-02-13 23:57:37 -0800302/*Warren add for T800 platform 2021/11/19 start*/
303int lynq_socket_client_start()
304{
rjw08528682022-07-04 21:28:02 +0800305 struct sockaddr_in lynq_data_socket_server_addr;
lhf81a46f2022-02-13 23:57:37 -0800306 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800307 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
308 lynq_data_socket_server_addr.sin_family = AF_INET;
309 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
jb.qid5852372023-03-29 10:29:12 +0800310 lynq_data_socket_server_addr.sin_addr.s_addr = inet_addr(LYNQ_ADDRESS);
lhf81a46f2022-02-13 23:57:37 -0800311 /*
312 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
313 {
314 printf("[%s] is not a valid IPaddress\n", argv[1]);
315 exit(1);
316 }
317*/
318 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800319 struct timeval timeOut;
320
rjwa59bf312022-07-05 11:50:31 +0800321 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800322 timeOut.tv_usec = 0;
323
324 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
325 {
326 LYERRLOG("time out setting failed");
327 }
328 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 -0800329 {
330 perror("connect error");
331 return -1;
332 }
333 return 0;
334}
rjw7ee7bb42023-01-18 11:34:28 +0800335
336bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800337{
rjw7ee7bb42023-01-18 11:34:28 +0800338 switch(urc_id)
339 {
340 case LYNQ_URC_DATA_CALL_STATUS_IND:
341
342 case LYNQ_URC_MODIFY_APNDB:
343 case LYNQ_URC_RESET_APNDB:
344 return true;
345 default:
346 return false;
347 }
348}
349
350void urc_msg_process(Parcel *p)
351{
352 int len;
353 int resp_type;
354 int urcid;
355 int slot_id;
356
357 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800358 char apn[LYNQ_APN_MAX_LEN];
359 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800360 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800361 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800362
363 int size = p->dataSize();
364 p->readInt32(&resp_type);
365 p->readInt32(&urcid);
366 p->readInt32(&slot_id);
367 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
368 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800369 {
rjw7ee7bb42023-01-18 11:34:28 +0800370 case LYNQ_URC_DATA_CALL_STATUS_IND:
371 p->readInt32(&pdnState);
372 bzero(apn,LYNQ_APN_MAX_LEN);
373 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
374 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
375 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800376 {
rjw20006d12022-04-21 16:29:04 +0800377 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800378 int len = strlen(urc_msg);
379 if(len < LYNQ_APN_MAX_LEN-1)
rjw20006d12022-04-21 16:29:04 +0800380 {
rjw7ee7bb42023-01-18 11:34:28 +0800381 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800382 }
rjw7ee7bb42023-01-18 11:34:28 +0800383 urc_msg = strdupReadString_p(p);
384 len = strlen(urc_msg);
385 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
386 {
387 memcpy(apnType,urc_msg,len+1);
388 }
389 urc_msg = strdupReadString_p(p);
390 len = strlen(urc_msg);
391 if(len < LYNQ_IFACE_NAME_MAX_LEN-1)
392 {
393 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
394 }
395 //sendSignalDataCallStateChange();
396 int apnId = getLynqApnID(apnType);
397 if(apnId >= 0)
398 {
399 if(lynq_apn_table[apnId].hasTimeout==1)
400 {
401 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800402 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 +0800403 {
404 LYERRLOG("deactive this time out APN");
405 lynq_deactive_data_call(&apnId);
406 }
407 else
408 {
409 LYERRLOG("this table is invalid");
410 }
411 break;
412 }
rjwacdb2152023-02-07 14:12:49 +0800413 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
rjw7ee7bb42023-01-18 11:34:28 +0800414 }
415 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800416 else
417 {
rjw7ee7bb42023-01-18 11:34:28 +0800418 LYERRLOG("invalid apnId");
419 break;
rjw20006d12022-04-21 16:29:04 +0800420 }
rjw7ee7bb42023-01-18 11:34:28 +0800421 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
422 s_data_urc_wait_list.push_back(apnId);
423 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
424 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800425 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800426 LYDBGLOG("data call state:%d",lynq_data_call);
427 if(lynq_data_call==1)
428 {
429 sendSignalDataCallStateChange();
430 lynq_data_call = 0;
431 }
rjw20006d12022-04-21 16:29:04 +0800432 }
rjw7ee7bb42023-01-18 11:34:28 +0800433 else
rjw20006d12022-04-21 16:29:04 +0800434 {
rjw7ee7bb42023-01-18 11:34:28 +0800435 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
rjw3938f262023-03-08 16:09:28 +0800447 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
448 s_data_urc_wait_list.push_back(apnId);
449 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
rjwc3d6e582023-03-28 17:19:11 +0800450 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800451 }
rjw7ee7bb42023-01-18 11:34:28 +0800452 LYDBGLOG("data call state:%d",lynq_data_call);
453 if(lynq_data_call==1)
454 {
455 sendSignalDataCallStateChange();
456 lynq_data_call = 0;
457 }
458 }
459 break;
460 case LYNQ_URC_MODIFY_APNDB:
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 case LYNQ_URC_RESET_APNDB:
474 {
rjw20006d12022-04-21 16:29:04 +0800475 urc_msg = strdupReadString_p(p);
476 if (NULL == urc_msg)
477 {
478 LYERRLOG("error apn msg");
479 }
480 else
481 {
482 bzero(g_lynq_apn_result, 1024);
483 strcpy(g_lynq_apn_result, urc_msg);
484 sendSignalApnChange();
485 }
486 }
rjw7ee7bb42023-01-18 11:34:28 +0800487 default:
488 break;
lhf81a46f2022-02-13 23:57:37 -0800489 }
rjw7ee7bb42023-01-18 11:34:28 +0800490
lhf81a46f2022-02-13 23:57:37 -0800491}
rjw7ee7bb42023-01-18 11:34:28 +0800492
rjw7ee7bb42023-01-18 11:34:28 +0800493int create_urc_vector_signal_thread()
494{
495 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800496 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800497 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
498 s_data_urc_wait_list.clear();
499 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800500 return 0;
501}
rjw7ee7bb42023-01-18 11:34:28 +0800502
lhf81a46f2022-02-13 23:57:37 -0800503int lynq_init_data(int uToken)
504{
rjw22947c22022-03-15 09:21:29 +0800505 if (g_lynq_data_init_flag == 1)
506 {
507 LYERRLOG("init twice is not allowed");
508 return -1;
509 }
510 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800511 int result = 0;
512 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800513 LYLOGSET(LOG_INFO);
514 LYLOGEINIT(USER_LOG_TAG);
515 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800516 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800517 if(result!=0)
518 {
519 LYERRLOG("init socket client fail!!!");
520 return -1;
521 }
rjw7ee7bb42023-01-18 11:34:28 +0800522 result = lynq_init_data_urc_thread();
523 if(result!=0)
524 {
525 LYERRLOG("init socket urc fail!!!");
526 return -1;
527 }
528
529 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800530 if(result!=0)
531 {
532 LYERRLOG("init socket urc fail!!!");
533 return -1;
534 }
535 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
536 LYDBGLOG("lynq init call success!!!");
537 return 0;
538
539}
540int lynq_deinit_data()
541{
542 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800543 if (g_lynq_data_init_flag == 0)
544 {
545 LYERRLOG("deinit twice is not allowed");
546 return ret;
547 }
548 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800549 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
550 {
551 if(strlen(lynq_apn_table[i].apnType)!=0)
552 {
553 lynq_deactive_data_call(&i);
554 }
555 }
556 if(lynq_client_sockfd>0)
557 {
558 close(lynq_client_sockfd);
559 }
rjw7ee7bb42023-01-18 11:34:28 +0800560 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800561 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800562 {
rjw7ee7bb42023-01-18 11:34:28 +0800563 LYERRLOG("lynq_deinit_data_urc_thread fail");
564 return ret;
rjw22947c22022-03-15 09:21:29 +0800565 }
rjwc3d6e582023-03-28 17:19:11 +0800566 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
567 s_data_urc_wait_list.clear();
568 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800569 return 0;
570}
571int lynq_setup_data_call(int *handle)
572{
573 Parcel p;
574 lynq_client_t client;
575 int resp_type = -1;
576 int request = -1;
577 int slot_id = -1;
578 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800579 int lynq_data_call_id = 0;
580 if(handle==NULL)
581 {
582 LYERRLOG("handle is null!!!");
583 return LYNQ_E_NULL_ANONALY;
584 }
585 client.uToken = Global_uToken;
586 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
587 client.paramLen = 0;
588 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
589 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800590 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800591 if(send_request(lynq_client_sockfd,&client)==-1)
592 {
593 LYERRLOG("send request fail");
594 perror("[LYNQ_DATA] send request fail:");
595 return -1;
596 }
597 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800598 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800599 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800600 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
601 lynq_data_call_id = updateApn("default");
602 lynq_data_call = 1;
603 if(error==0)
604 {
rjw20006d12022-04-21 16:29:04 +0800605 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800606 {
607 error = LYNQ_E_TIME_OUT;
608 LYERRLOG("timeout:wait data Call state fail!!!");
609 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
610 return error;
611 }
612 *handle = lynq_data_call_id;
613 }
614 return error;
615}
rjw7ee7bb42023-01-18 11:34:28 +0800616
lhf81a46f2022-02-13 23:57:37 -0800617int lynq_deactive_data_call(int *handle)
618{
619 Parcel p;
620 lynq_client_t client;
621 int resp_type = -1;
622 int request = -1;
623 int slot_id = -1;
624 int error = -1;
625 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800626 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800627 if(handle==NULL)
628 {
629 LYERRLOG("handle is null!!!");
630 return -1;
631 }
rjw1309e232022-07-22 09:54:06 +0800632 ret = handleCheck(*handle);
633 if (ret != 0)
634 {
635 LYERRLOG("incomming handle is invalid");
636 return -1;
637 }
638 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800639 client.uToken = Global_uToken;
640 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
641 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
642 {
643 client.paramLen = 0;
644 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800645 }
646 else
647 {
lhf81a46f2022-02-13 23:57:37 -0800648 client.paramLen = 1;
649 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
650 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
651 }
652 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800653 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800654 if(send_request(lynq_client_sockfd,&client)==-1)
655 {
656 LYERRLOG("send request fail");
657 perror("[LYNQ_DATA] send request fail:");
658 return -1;
659 }
660 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800661 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800662 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800663 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
664 cleanOnceApnTable(lynq_data_call_id);
665 return error;
666}
667int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
668{
669 Parcel p;
670 lynq_client_t client;
671 int resp_type = -1;
672 int request = -1;
673 int slot_id = -1;
674 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800675 int lynq_data_call_id = -1;
676 char *argv[10] = {};
677 if(handle==NULL||apn==NULL||apnType==NULL)
678 {
679 LYERRLOG("handle ,apn or apntype is null!!!");
680 return -1;
681 }
682 if(user==NULL)
683 {
684 argv[1] = "null";
685 }
686 else
687 {
688 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800689 }
690 if(password==NULL)
691 {
lhf81a46f2022-02-13 23:57:37 -0800692 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800693 }
694 else
695 {
lhf81a46f2022-02-13 23:57:37 -0800696 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800697 }
698 if(authType==NULL)
699 {
lhf81a46f2022-02-13 23:57:37 -0800700 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800701 }
702 else
703 {
lhf81a46f2022-02-13 23:57:37 -0800704 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800705 }
706 if(normalProtocol==NULL)
707 {
lhf81a46f2022-02-13 23:57:37 -0800708 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800709 }
710 else
711 {
lhf81a46f2022-02-13 23:57:37 -0800712 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800713 }
714 if(roamingProtocol==NULL)
715 {
lhf81a46f2022-02-13 23:57:37 -0800716 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800717 }
718 else
719 {
lhf81a46f2022-02-13 23:57:37 -0800720 argv[5] = roamingProtocol;
721 }
722 client.uToken = Global_uToken;
723 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
724 client.paramLen = 7;
725 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
726 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
727 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800728 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800729 if(send_request(lynq_client_sockfd,&client)==-1)
730 {
731 LYERRLOG("send request fail");
732 perror("[LYNQ_DATA] send request fail:");
733 return -1;
734 }
735 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800736 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800737 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800738 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
739 lynq_data_call_id = updateApn(apnType);
740 lynq_data_call = 1;
741 if(error==0)
742 {
rjw7ee7bb42023-01-18 11:34:28 +0800743 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800744 {
745 error = LYNQ_E_TIME_OUT;
746 LYERRLOG("timeout:wait data Call state fail!!!");
747 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
748 return error;
749 }
750 *handle = lynq_data_call_id;
751 }
752 return error;
753}
754/*
755int lynq_deactive_data_call_sp(int *handle,char *apnType)
756{
757 Parcel p;
758 lynq_client_t client;
759 int resp_type = -1;
760 int request = -1;
761 int slot_id = -1;
762 int error = -1;
763 if(handle==NULL||apnType==NULL)
764 {
765 LYERRLOG("handle is null!!!");
766 return -1;
767 }
768 client.uToken = Global_uToken;
769 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
770 client.paramLen = 1;
771 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
772 sprintf(client.param,"%s",apnType);
773 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
774 if(send_request(lynq_client_sockfd,&client)==-1)
775 {
776 LYERRLOG("send request fail");
777 perror("[LYNQ_DATA] send request fail:");
778 return -1;
779 }
780 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800781 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800782 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
783 return error;
784}
785*/
786int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
787{
788 Parcel p;
789 lynq_client_t client;
790 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800791 int token;
792 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800793 int slot_id = -1;
794 int error = -1;
795 int version =0;
796 int num = 0;
lhf81a46f2022-02-13 23:57:37 -0800797 char *temp_char = NULL;
798 if(dataCallList==NULL)
799 {
800 LYERRLOG("dataCallList is null!!!");
801 return -1;
802 }
803 client.uToken = Global_uToken;
804 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
805 client.paramLen = 0;
806 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
807 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800808 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800809 if(send_request(lynq_client_sockfd,&client)==-1)
810 {
811 LYERRLOG("send request fail");
812 perror("[LYNQ_DATA] send request fail:");
813 return -1;
814 }
815 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800816 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800817 if(p.dataAvail() > 0)
818 {
rjw0fb4ccb2022-09-16 19:12:35 +0800819 p.readInt32(&resp_type);
820 p.readInt32(&token);
821 p.readInt32(&request);
822 p.readInt32(&slot_id);
823 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +0800824 }
825 else
826 {
827 return -1;
828 }
lhf81a46f2022-02-13 23:57:37 -0800829 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 }
rjw3938f262023-03-08 16:09:28 +0800870 if (*handle<0 && handle>8)
871 {
872 LYERRLOG("handle value error");
873 }
874 LYINFLOG("incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800875 memset(interDataCallList,0,sizeof(interDataCallList));
876 error = getDataCallLists(interDataCallList,&number);
877 if(error == 0)
878 {
879 for(int i = 0;i < number;i++)
880 {
881 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
882 {
883 dataCallList->active = interDataCallList[i].active;
884 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
885 dataCallList->cid = interDataCallList[i].cid;
886 dataCallList->status = interDataCallList[i].status;
887 dataCallList->mtu = interDataCallList[i].mtu;
888 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
889 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
890 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
891 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
892 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
893 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
894 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
895 }
896 }
897 }
898 return error;
899}
900int lynq_wait_data_call_state_change(int *handle)
901{
rjwc3d6e582023-03-28 17:19:11 +0800902 if (data_waiting_status == 1)
903 {
904 LYDBGLOG("some thread is waiting");
905 return -3;
906 }
907 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
908 if (s_data_urc_wait_list.empty())
909 {
910 LYDBGLOG("start wait");
911 data_waiting_status = 1;
912 waitPdnChange();
913 }
914 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800915 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +0800916
917 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
918 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +0800919 if (iter != s_data_urc_wait_list.end())
920 {
921 *handle = *iter;
922 }
rjw7ee7bb42023-01-18 11:34:28 +0800923 s_data_urc_wait_list.erase(iter);
924 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
925
rjw3938f262023-03-08 16:09:28 +0800926 LYINFLOG("lynq data call id:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800927 return 0;
928}
929/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +0800930
931/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +0800932
933int 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 +0800934{
935 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +0800936 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +0800937 {
rjw61fcae32022-08-18 14:03:39 +0800938 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +0800939 }
rjw61fcae32022-08-18 14:03:39 +0800940 else
rjw0cdacbc2022-06-22 10:51:07 +0800941 {
rjw61fcae32022-08-18 14:03:39 +0800942 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +0800943 }
rjw20006d12022-04-21 16:29:04 +0800944 if (mcc == NULL)
945 {
946 sprintf(strtmp[1], "mcc=;");
947 }
948 else
949 {
950 sprintf(strtmp[1], "mcc=%s;", mcc);
951 }
952 if (mnc == NULL)
953 {
rjw61fcae32022-08-18 14:03:39 +0800954 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +0800955 }
956 else
957 {
958 sprintf(strtmp[2], "mnc=%s;", mnc);
959 }
960 if (apn == NULL)
961 {
962 sprintf(strtmp[3], "apn=;");
963 }
964 else
965 {
966 sprintf(strtmp[3], "apn=%s;", apn);
967 }
968 if (apntype == NULL)
969 {
970 sprintf(strtmp[4], "apntype=;");
971 }
972 else
973 {
974 sprintf(strtmp[4], "apntype=%s;", apntype);
975 }
976 if (user == NULL)
977 {
978 sprintf(strtmp[5], "user=;");
979 }
980 else
981 {
982 sprintf(strtmp[5], "user=%s;", user);
983 }
984 if (password == NULL)
985 {
986 sprintf(strtmp[6], "password=;");
987 }
988 else
989 {
990 sprintf(strtmp[6], "password=%s;", password);
991 }
992 if (normalprotocol == NULL)
993 {
994 sprintf(strtmp[7], "normalprotocol=;");
995 }
996 else
997 {
998 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
999 }
1000 if (roamingprotocol == NULL)
1001 {
1002 sprintf(strtmp[8], "roamingprotocol=;");
1003 }
1004 else
1005 {
1006 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1007 }
1008 if (carrier == NULL)
1009 {
1010 sprintf(strtmp[9], "carrier=;");
1011 }
1012 else
1013 {
1014 sprintf(strtmp[9], "carrier=%s;", carrier);
1015 }
rjw61fcae32022-08-18 14:03:39 +08001016 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 +08001017
rjw20006d12022-04-21 16:29:04 +08001018 return 0;
1019}
1020
1021int 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)
1022{
1023 char strtmp[10][32];
1024 if (id == NULL)
1025 {
1026 sprintf(strtmp[0], "id=;");
1027 }
1028 else
1029 {
1030 sprintf(strtmp[0], "id=%s;", id);
1031 }
1032 if (mcc == NULL)
1033 {
1034 sprintf(strtmp[1], "mcc=;");
1035 }
1036 else
1037 {
1038 sprintf(strtmp[1], "mcc=%s;", mcc);
1039 }
1040 if (mnc == NULL)
1041 {
1042 sprintf(strtmp[2], "mnc=;");
1043 }
1044 else
1045 {
1046 sprintf(strtmp[2], "mnc=%s;", mnc);
1047 }
1048 if (apn == NULL)
1049 {
1050 sprintf(strtmp[3], "apn=;");
1051 }
1052 else
1053 {
1054 sprintf(strtmp[3], "apn=%s;", apn);
1055 }
1056 if (apntype == NULL)
1057 {
1058 sprintf(strtmp[4], "apntype=;");
1059 }
1060 else
1061 {
1062 sprintf(strtmp[4], "apntype=%s;", apntype);
1063 }
1064 if (user == NULL)
1065 {
1066 sprintf(strtmp[5], "user=;");
1067 }
1068 else
1069 {
1070 sprintf(strtmp[5], "user=%s;", user);
1071 }
1072 if (password == NULL)
1073 {
1074 sprintf(strtmp[6], "password=;");
1075 }
1076 else
1077 {
1078 sprintf(strtmp[6], "password=%s;", password);
1079 }
1080 if (normalprotocol == NULL)
1081 {
1082 sprintf(strtmp[7], "normalprotocol=;");
1083 }
1084 else
1085 {
1086 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1087 }
1088 if (roamingprotocol == NULL)
1089 {
1090 sprintf(strtmp[8], "roamingprotocol=;");
1091 }
1092 else
1093 {
1094 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1095 }
1096 if (carrier == NULL)
1097 {
1098 sprintf(strtmp[9], "carrier=;");
1099 }
1100 else
1101 {
1102 sprintf(strtmp[9], "carrier=%s;", carrier);
1103 }
1104 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]);
1105 return 0;
1106}
1107
rjwaf4b1612022-06-13 17:26:01 +08001108
1109int 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)
1110{
1111 char strtmp[10][32];
1112 if (id == NULL)
1113 {
1114 sprintf(strtmp[0], "");
1115 }
1116 else
1117 {
1118 sprintf(strtmp[0], "id=%s;", id);
1119 }
1120 if (mcc == NULL)
1121 {
1122 sprintf(strtmp[1], "");
1123 }
1124 else
1125 {
1126 sprintf(strtmp[1], "mcc=%s;", mcc);
1127 }
1128 if (mnc == NULL)
1129 {
1130 sprintf(strtmp[2], "");
1131 }
1132 else
1133 {
1134 sprintf(strtmp[2], "mnc=%s;", mnc);
1135 }
1136 if (apn == NULL)
1137 {
1138 sprintf(strtmp[3], "");
1139 }
1140 else
1141 {
1142 sprintf(strtmp[3], "apn=%s;", apn);
1143 }
1144 if (apntype == NULL)
1145 {
1146 sprintf(strtmp[4], "");
1147 }
1148 else
1149 {
1150 sprintf(strtmp[4], "apntype=%s;", apntype);
1151 }
1152 if (user == NULL)
1153 {
1154 sprintf(strtmp[5], "");
1155 }
1156 else
1157 {
1158 sprintf(strtmp[5], "user=%s;", user);
1159 }
1160 if (password == NULL)
1161 {
1162 sprintf(strtmp[6], "");
1163 }
1164 else
1165 {
1166 sprintf(strtmp[6], "password=%s;", password);
1167 }
1168 if (normalprotocol == NULL)
1169 {
1170 sprintf(strtmp[7], "");
1171 }
1172 else
1173 {
1174 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1175 }
1176 if (roamingprotocol == NULL)
1177 {
1178 sprintf(strtmp[8], "");
1179 }
1180 else
1181 {
1182 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1183 }
1184 if (carrier == NULL)
1185 {
1186 sprintf(strtmp[9], "");
1187 }
1188 else
1189 {
1190 sprintf(strtmp[9], "carrier=%s;", carrier);
1191 }
1192 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]);
1193 return 0;
1194}
1195
rjw20006d12022-04-21 16:29:04 +08001196static char *lynqStrdupReadString(Parcel &p)
1197{
1198 size_t stringlen;
1199 const char16_t *s16;
1200
1201 s16 = p.readString16Inplace(&stringlen);
1202 return strndup16to8(s16, stringlen);
1203}
1204
1205int 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)
1206{
1207 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1208 {
1209 LYERRLOG("There are no valid parameters");
1210 return -1;
1211 }
1212 lynq_client_t client;
1213 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001214 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001215 Parcel p;
1216 if (cmd == 0) // insert apn db
1217 {
rjw61fcae32022-08-18 14:03:39 +08001218 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1219
rjw20006d12022-04-21 16:29:04 +08001220 client.uToken = Global_uToken;
1221 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1222 client.paramLen = 2;
1223 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1224 sprintf(client.param, "%d %s", cmd, argc);
1225 }
rjw61fcae32022-08-18 14:03:39 +08001226 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001227 {
1228 if (NULL == id)
1229 {
1230 LYERRLOG("id is NULL!!!please input id: ");
1231 }
1232 sprintf(argc, "id=%s", id);
1233 client.uToken = Global_uToken;
1234 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1235 client.paramLen = 2;
1236 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1237 sprintf(client.param, "%d %s", cmd, argc);
1238 }
rjw61fcae32022-08-18 14:03:39 +08001239 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001240 {
rjwaf4b1612022-06-13 17:26:01 +08001241 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001242 client.uToken = Global_uToken;
1243 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1244 client.paramLen = 2;
1245 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1246 sprintf(client.param, "%d %s", cmd, argc);
1247 }
rjw61fcae32022-08-18 14:03:39 +08001248 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001249 {
1250 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1251 client.uToken = Global_uToken;
1252 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1253 client.paramLen = 2;
1254 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1255 sprintf(client.param, "%d %s", cmd, argc);
1256 }
1257 else
1258 {
1259 LYERRLOG("incoming command is invalid");
1260 return -1;
1261 }
1262 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001263 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001264 if(send_request(lynq_client_sockfd,&client)==-1)
1265 {
1266 LYERRLOG("send request fail");
1267 return -1;
1268 }
rjwed00d042022-05-25 09:18:16 +08001269 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001270 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001271 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001272 LYINFLOG(">>>>>output info:%s",out);
1273 return 0;
1274}
1275
1276int lynq_reset_apn(char *result)
1277{
1278 Parcel p;
1279 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001280 if (NULL == result)
1281 {
1282 LYERRLOG("incoming paramters error");
1283 }
rjw20006d12022-04-21 16:29:04 +08001284 client.uToken = Global_uToken;
1285 client.request = 2000 + 194;
1286 client.paramLen = 0;
1287 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1288 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001289 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001290 if (send_request(lynq_client_sockfd, &client) == -1)
1291 {
1292 LYERRLOG("send request fail");
1293 return -1;
1294 }
rjwed00d042022-05-25 09:18:16 +08001295 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001296 waitApnResult();
1297 strcpy(result, g_lynq_apn_result);
1298 LYINFLOG(">>>>>result:%s",result);
1299 return 0;
1300}
1301
rjw3bcbbf12022-04-22 16:47:18 +08001302/*Typethree add for T800 platform 2022/04/21 end*/