blob: c04a373ec8b85cb48afc701da76a88b2e71c78b1 [file] [log] [blame]
lhf81a46f2022-02-13 23:57:37 -08001#include <stdio.h>
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <arpa/inet.h>
5#include <fcntl.h>
6#include <string.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <binder/Parcel.h>
10#include <log/log.h>
11#include "lynq_data.h"
12#include <cutils/jstring.h>
13#include <pthread.h>
14#include "liblog/lynq_deflog.h"
15#include <sys/time.h>
rjw0cdacbc2022-06-22 10:51:07 +080016#include <include/lynq_uci.h>
rjw747deea2022-07-01 18:25:30 +080017#include <errno.h>
rjw7ee7bb42023-01-18 11:34:28 +080018#include <vector>
19#include "lynq_data_urc.h"
20
lhf81a46f2022-02-13 23:57:37 -080021#define LYNQ_SERVICE_PORT 8088
lhf81a46f2022-02-13 23:57:37 -080022#define LYNQ_REC_BUF 8192
23#define LYNQ_REQUEST_PARAM_BUF 8192
24#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
25#define USER_LOG_TAG "LYNQ_DATA"
26
rjw0cdacbc2022-06-22 10:51:07 +080027#define LYNQ_DATA_UCI_BUF 258
rjw61fcae32022-08-18 14:03:39 +080028
lhf81a46f2022-02-13 23:57:37 -080029using ::android::Parcel;
30typedef struct{
31 int uToken;
32 int request;
33 int paramLen;
34 char param[LYNQ_REQUEST_PARAM_BUF];
35}lynq_client_t;
lh13586612022-01-11 21:58:58 -080036typedef enum{
37 LYNQ_E_CARDSTATE_ERROR=8000,
38 /* The voice service state is out of service*/
39 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
40 /* The voice service state is EMERGENCY_ONLY*/
41 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
42 /* The radio power is power off*/
43 LYNQ_E_STATE_POWER_OFF=8003,
44 LYNQ_E_TIME_OUT=8004,
45 /*create or open sms DB fail */
46 LYNQ_E_SMS_DB_FAIL=8005,
47 /*Failed to execute sql statement*/
48 LYNQ_E_SMS_SQL_FAIL = 8006,
49 LYNQ_E_SMS_NOT_FIND = 8007,
50 /* The logic conflict*/
51 LYNQ_E_CONFLICT=9000,
52 /*Null anomaly*/
53 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080054}LYNQ_E;
55
56int lynq_client_sockfd = 0;
57int Global_uToken = 0;
rjw7ee7bb42023-01-18 11:34:28 +080058
lhf81a46f2022-02-13 23:57:37 -080059int lynq_data_call_change_id = -1;
60pthread_t lynq_data_tid =-1;
61static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
62static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080063
rjw20006d12022-04-21 16:29:04 +080064static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
65static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
66
rjw7ee7bb42023-01-18 11:34:28 +080067pthread_t data_list_urc_vector_tid = -1;
68int data_urc_vector_status = 0;
69static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
70static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER;
rjwed00d042022-05-25 09:18:16 +080071/**g_lynq_data_sendto_mutex
72* @brief mark data send request mutex
73*/
74static pthread_mutex_t g_lynq_data_sendto_mutex;
75
rjw22947c22022-03-15 09:21:29 +080076/**g_lynq_data_init_flag
77* @brief mark data initialization state
78* 0:deinit status
79* 1:init state
80*/
81static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080082/**g_lynq_apn_result
83* @brief temp of apn result info
84*/
85char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +080086
rjw7ee7bb42023-01-18 11:34:28 +080087static std::vector<int> s_data_urc_wait_list;
88
rjw20006d12022-04-21 16:29:04 +080089typedef struct
90{
lhf81a46f2022-02-13 23:57:37 -080091 char apn[LYNQ_APN_MAX_LEN];
92 char apnType[LYNQ_APN_TYPE_MAX_LEN];
93 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
94 int hasUsed;
95 int hasTimeout;
96}lynq_apn_t;
97lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
98lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
99int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800100
lhf81a46f2022-02-13 23:57:37 -0800101int getLynqApnID(char apnType[])
102{
103 int ret = 0;
104 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
105 {
106 if(strcmp(lynq_apn_table[ret].apnType,apnType)==0)
lh13586612022-01-11 21:58:58 -0800107 {
lhf81a46f2022-02-13 23:57:37 -0800108 return ret;
109 }
110 }
111 return -1;
112}
rjw7ee7bb42023-01-18 11:34:28 +0800113
lhf81a46f2022-02-13 23:57:37 -0800114void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
115{
116 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
117 if(apn_table==NULL)
118 {
119 LYERRLOG("apn_table is null");
120 return;
121 }
122 memcpy(apn_table->apn,apn,strlen(apn)+1);
123 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
124 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
125 apn_table->hasTimeout = 0;
126 apn_table->hasUsed = 1;
127 return;
128}
rjw7ee7bb42023-01-18 11:34:28 +0800129
lhf81a46f2022-02-13 23:57:37 -0800130void cleanOnceApnTable(int apnId)
131{
132 LYDBGLOG("apn id:%d",apnId);
133 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
134 {
135 LYERRLOG("apn id is invalid!!!");
136 return;
137 }
138 lynq_apn_table[apnId].hasTimeout = 0;
139 lynq_apn_table[apnId].hasUsed = 0;
140 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
141 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
142 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
143 return;
144}
145int getUnusedElement()
146{
147 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
148 {
149 if(lynq_apn_table[i].hasUsed!=1)
150 {
151 return i;
152 }
153 }
154 return -1;
155}
156int updateApn(char apnType[])
157{
158 int ret = 0;
159 ret = getUnusedElement();
160 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
161 lynq_apn_table[ret].hasUsed = 1;
162 return ret;
163}
rjw1309e232022-07-22 09:54:06 +0800164
165int handleCheck(int handle)
166{
167 if (lynq_apn_table[handle].hasUsed == 1)
168 {
169 return 0;
170 }
171 else
172 {
173 return -1;
174 }
175}
rjw20006d12022-04-21 16:29:04 +0800176int waitApnResult()
177{
178 int ret = 0;
179 LYINFLOG("start wait apn result!!!");
180 int sec = 0;
181 int usec = 0;
182 struct timeval now;
183 struct timespec timeout;
184 gettimeofday(&now, NULL);
185 sec = 20000 / 1000;
186 usec = 20000 % 1000;
187 timeout.tv_sec = now.tv_sec + sec;
188 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
189 pthread_mutex_lock(&s_lynq_apn_change_mutex);
190 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
191 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
192 return ret;
193}
194
195void sendSignalApnChange()
196{
197 LYINFLOG("start send Signal Apn Change");
198 pthread_mutex_lock(&s_lynq_apn_change_mutex);
199 pthread_cond_signal(&s_lynq_apn_change_cond);
200 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
201 return;
202}
lhf81a46f2022-02-13 23:57:37 -0800203
204int waitPdnChange()
205{
206 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800207 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
208 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
209 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800210 return ret;
211}
212int waitDataCallstateChange(int mtime)
213{
214 int ret = 0;
215 int sec = 0;
216 int usec = 0;
217 struct timeval now;
218 struct timespec timeout;
219 gettimeofday(&now,NULL);
220 sec = mtime/1000;
221 usec = mtime%1000;
222 timeout.tv_sec = now.tv_sec+sec;
223 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
224 pthread_mutex_lock(&s_data_call_state_change_mutex);
225 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
226 pthread_mutex_unlock(&s_data_call_state_change_mutex);
227 return ret;
228}
229void sendSignalDataCallStateChange()
230{
231 pthread_mutex_lock(&s_data_call_state_change_mutex);
232 pthread_cond_signal(&s_data_call_state_change_cond);
233 pthread_mutex_unlock(&s_data_call_state_change_mutex);
234 return;
235}
236void sendSignalPdnChange()
237{
rjw7ee7bb42023-01-18 11:34:28 +0800238 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
239 pthread_cond_signal(&s_lynq_urc_vector_cond);
240 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800241 return;
242}
243
244int get_response(int sockfd,Parcel &p)
245{
246 int len = 0;
247 char recvline[LYNQ_REC_BUF];
248 bzero(recvline,LYNQ_REC_BUF);
249 /* receive data from server */
rjw08528682022-07-04 21:28:02 +0800250 len = read(sockfd, recvline, LYNQ_REC_BUF);
251 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800252 {
rjw747deea2022-07-01 18:25:30 +0800253 LYERRLOG("read error");
lhf81a46f2022-02-13 23:57:37 -0800254 return -1;
255 }
256 if (recvline != NULL) {
257 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
258 p.setDataPosition(0);
259 }
260 return 0;
261}
rjwfa532972022-09-16 13:39:41 +0800262int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
lhf81a46f2022-02-13 23:57:37 -0800263{
264 if(p.dataAvail() > 0)
265 {
266 p.readInt32(resp_type);
267 p.readInt32(request);
268 p.readInt32(slot_id);
269 p.readInt32(error);
270 return 0;
271 }
272 else
273 {
274 return -1;
275 }
276}
277int send_request(int sockfd,lynq_client_t *client_tmp)
278{
279 int ret=0;
280 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
281 if(ret==-1)
282 {
283 perror("write error");
284 return -1;
285 }
286 return 0;
287}
288static char *strdupReadString(Parcel &p) {
289 size_t stringlen;
290 const char16_t *s16;
291 s16 = p.readString16Inplace(&stringlen);
292 return strndup16to8(s16, stringlen);
293}
294static char *strdupReadString_p(Parcel *p) {
295 size_t stringlen;
296 const char16_t *s16;
297 s16 = p->readString16Inplace(&stringlen);
298 return strndup16to8(s16, stringlen);
299}
300
lhf81a46f2022-02-13 23:57:37 -0800301/*Warren add for T800 platform 2021/11/19 start*/
302int lynq_socket_client_start()
303{
rjw08528682022-07-04 21:28:02 +0800304 struct sockaddr_in lynq_data_socket_server_addr;
lhf81a46f2022-02-13 23:57:37 -0800305 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800306 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
307 lynq_data_socket_server_addr.sin_family = AF_INET;
308 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
309 lynq_data_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
lhf81a46f2022-02-13 23:57:37 -0800310 /*
311 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
312 {
313 printf("[%s] is not a valid IPaddress\n", argv[1]);
314 exit(1);
315 }
316*/
317 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800318 struct timeval timeOut;
319
rjwa59bf312022-07-05 11:50:31 +0800320 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800321 timeOut.tv_usec = 0;
322
323 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
324 {
325 LYERRLOG("time out setting failed");
326 }
327 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 -0800328 {
329 perror("connect error");
330 return -1;
331 }
332 return 0;
333}
rjw7ee7bb42023-01-18 11:34:28 +0800334
335bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800336{
rjw7ee7bb42023-01-18 11:34:28 +0800337 switch(urc_id)
338 {
339 case LYNQ_URC_DATA_CALL_STATUS_IND:
340
341 case LYNQ_URC_MODIFY_APNDB:
342 case LYNQ_URC_RESET_APNDB:
343 return true;
344 default:
345 return false;
346 }
347}
348
349void urc_msg_process(Parcel *p)
350{
351 int len;
352 int resp_type;
353 int urcid;
354 int slot_id;
355
356 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800357 char apn[LYNQ_APN_MAX_LEN];
358 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800359 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800360 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800361
362 int size = p->dataSize();
363 p->readInt32(&resp_type);
364 p->readInt32(&urcid);
365 p->readInt32(&slot_id);
366 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
367 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800368 {
rjw7ee7bb42023-01-18 11:34:28 +0800369 case LYNQ_URC_DATA_CALL_STATUS_IND:
370 p->readInt32(&pdnState);
371 bzero(apn,LYNQ_APN_MAX_LEN);
372 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
373 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
374 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800375 {
rjw20006d12022-04-21 16:29:04 +0800376 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800377 int len = strlen(urc_msg);
378 if(len < LYNQ_APN_MAX_LEN-1)
rjw20006d12022-04-21 16:29:04 +0800379 {
rjw7ee7bb42023-01-18 11:34:28 +0800380 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800381 }
rjw7ee7bb42023-01-18 11:34:28 +0800382 urc_msg = strdupReadString_p(p);
383 len = strlen(urc_msg);
384 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
385 {
386 memcpy(apnType,urc_msg,len+1);
387 }
388 urc_msg = strdupReadString_p(p);
389 len = strlen(urc_msg);
390 if(len < LYNQ_IFACE_NAME_MAX_LEN-1)
391 {
392 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
393 }
394 //sendSignalDataCallStateChange();
395 int apnId = getLynqApnID(apnType);
396 if(apnId >= 0)
397 {
398 if(lynq_apn_table[apnId].hasTimeout==1)
399 {
400 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
401 if (NULL != lynq_apn_table[apnId].apn && NULL != NULL != lynq_apn_table[apnId].apnType)
402 {
403 LYERRLOG("deactive this time out APN");
404 lynq_deactive_data_call(&apnId);
405 }
406 else
407 {
408 LYERRLOG("this table is invalid");
409 }
410 break;
411 }
412 //updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
413 }
414 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800415 else
416 {
rjw7ee7bb42023-01-18 11:34:28 +0800417 LYERRLOG("invalid apnId");
418 break;
rjw20006d12022-04-21 16:29:04 +0800419 }
rjw7ee7bb42023-01-18 11:34:28 +0800420 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
421 s_data_urc_wait_list.push_back(apnId);
422 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
423 lynq_data_call_change_id = apnId;
424 //sendSignalPdnChange();
425 LYDBGLOG("data call state:%d",lynq_data_call);
426 if(lynq_data_call==1)
427 {
428 sendSignalDataCallStateChange();
429 lynq_data_call = 0;
430 }
rjw20006d12022-04-21 16:29:04 +0800431 }
rjw7ee7bb42023-01-18 11:34:28 +0800432 else
rjw20006d12022-04-21 16:29:04 +0800433 {
rjw7ee7bb42023-01-18 11:34:28 +0800434 urc_msg = strdupReadString_p(p);
435 len = strlen(urc_msg);
436 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
437 {
438 memcpy(apnType,urc_msg,len+1);
439 }
440 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
441 int apnId = getLynqApnID(apnType);
442 if(apnId >= 0)
443 {
444 lynq_data_call_change_id = apnId;
445 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
446 }
447 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);
450 //sendSignalPdnChange();
451 LYDBGLOG("data call state:%d",lynq_data_call);
452 if(lynq_data_call==1)
453 {
454 sendSignalDataCallStateChange();
455 lynq_data_call = 0;
456 }
457 }
458 break;
459 case LYNQ_URC_MODIFY_APNDB:
460 urc_msg = strdupReadString_p(p);
461 if (NULL == urc_msg)
462 {
463 LYERRLOG("error apn msg");
464 }
465 else
466 {
467 bzero(g_lynq_apn_result, 1024);
468 strcpy(g_lynq_apn_result, urc_msg);
469 sendSignalApnChange();
470 }
471 break;
472 case LYNQ_URC_RESET_APNDB:
473 {
rjw20006d12022-04-21 16:29:04 +0800474 urc_msg = strdupReadString_p(p);
475 if (NULL == urc_msg)
476 {
477 LYERRLOG("error apn msg");
478 }
479 else
480 {
481 bzero(g_lynq_apn_result, 1024);
482 strcpy(g_lynq_apn_result, urc_msg);
483 sendSignalApnChange();
484 }
485 }
rjw7ee7bb42023-01-18 11:34:28 +0800486 default:
487 break;
lhf81a46f2022-02-13 23:57:37 -0800488 }
rjw7ee7bb42023-01-18 11:34:28 +0800489
lhf81a46f2022-02-13 23:57:37 -0800490}
rjw7ee7bb42023-01-18 11:34:28 +0800491
492void cleanup_urc_vector_mutex(void *arg)
lhf81a46f2022-02-13 23:57:37 -0800493{
rjw7ee7bb42023-01-18 11:34:28 +0800494 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
495}
496
497void *thread_urc_vector()
498{
499 pthread_cleanup_push(cleanup_urc_vector_mutex, NULL);
500 while (data_urc_vector_status)
lh13586612022-01-11 21:58:58 -0800501 {
rjw7ee7bb42023-01-18 11:34:28 +0800502 while (!s_data_urc_wait_list.empty())
503 {
504 sendSignalPdnChange();
505 usleep(10);
506 }
507 }
508 pthread_cleanup_pop(0);
509}
510
511void cancel_urc_vector_signal_thread()
512{
513 int ret;
514
515 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
516 if (data_list_urc_vector_tid != -1)
517 {
518 ret = pthread_cancel(data_list_urc_vector_tid);
519 LYDBGLOG("pthread cancel ret = %d",ret);
520 }
521 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
522
523 if (data_list_urc_vector_tid != -1)
524 {
525 ret = pthread_join(data_list_urc_vector_tid,NULL);
526 LYDBGLOG("pthread join ret = %d",ret);
527 data_list_urc_vector_tid = -1;
528 }
529 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
530 s_data_urc_wait_list.clear();
531 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
532 data_urc_vector_status = 0;
533}
534
535int create_urc_vector_signal_thread()
536{
537 int ret;
538
539 data_urc_vector_status = 1;
540 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
541 ret = pthread_create(&data_list_urc_vector_tid,NULL,thread_urc_vector,NULL);
542 if (ret < 0)
543 {
544 LYERRLOG("urc vector signal pthread create error");
545 lynq_deinit_data_urc_thread();
546 data_urc_vector_status = 0;
lh13586612022-01-11 21:58:58 -0800547 return -1;
lhf81a46f2022-02-13 23:57:37 -0800548 }
rjw7ee7bb42023-01-18 11:34:28 +0800549 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
550 s_data_urc_wait_list.clear();
551 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800552 return 0;
553}
rjw7ee7bb42023-01-18 11:34:28 +0800554
lhf81a46f2022-02-13 23:57:37 -0800555int lynq_init_data(int uToken)
556{
rjw22947c22022-03-15 09:21:29 +0800557 if (g_lynq_data_init_flag == 1)
558 {
559 LYERRLOG("init twice is not allowed");
560 return -1;
561 }
562 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800563 int result = 0;
564 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800565 LYLOGSET(LOG_INFO);
566 LYLOGEINIT(USER_LOG_TAG);
567 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800568 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800569 if(result!=0)
570 {
571 LYERRLOG("init socket client fail!!!");
572 return -1;
573 }
rjw7ee7bb42023-01-18 11:34:28 +0800574 result = lynq_init_data_urc_thread();
575 if(result!=0)
576 {
577 LYERRLOG("init socket urc fail!!!");
578 return -1;
579 }
580
581 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800582 if(result!=0)
583 {
584 LYERRLOG("init socket urc fail!!!");
585 return -1;
586 }
587 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
588 LYDBGLOG("lynq init call success!!!");
589 return 0;
590
591}
592int lynq_deinit_data()
593{
594 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800595 if (g_lynq_data_init_flag == 0)
596 {
597 LYERRLOG("deinit twice is not allowed");
598 return ret;
599 }
600 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800601 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
602 {
603 if(strlen(lynq_apn_table[i].apnType)!=0)
604 {
605 lynq_deactive_data_call(&i);
606 }
607 }
608 if(lynq_client_sockfd>0)
609 {
610 close(lynq_client_sockfd);
611 }
rjw7ee7bb42023-01-18 11:34:28 +0800612 ret = lynq_deinit_data_urc_thread();
rjw22947c22022-03-15 09:21:29 +0800613 {
rjw7ee7bb42023-01-18 11:34:28 +0800614 LYERRLOG("lynq_deinit_data_urc_thread fail");
615 return ret;
rjw22947c22022-03-15 09:21:29 +0800616 }
rjw7ee7bb42023-01-18 11:34:28 +0800617 cancel_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800618 return 0;
619}
620int lynq_setup_data_call(int *handle)
621{
622 Parcel p;
623 lynq_client_t client;
624 int resp_type = -1;
625 int request = -1;
626 int slot_id = -1;
627 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800628 int lynq_data_call_id = 0;
629 if(handle==NULL)
630 {
631 LYERRLOG("handle is null!!!");
632 return LYNQ_E_NULL_ANONALY;
633 }
634 client.uToken = Global_uToken;
635 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
636 client.paramLen = 0;
637 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
638 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800639 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800640 if(send_request(lynq_client_sockfd,&client)==-1)
641 {
642 LYERRLOG("send request fail");
643 perror("[LYNQ_DATA] send request fail:");
644 return -1;
645 }
646 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800647 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800648 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800649 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
650 lynq_data_call_id = updateApn("default");
651 lynq_data_call = 1;
652 if(error==0)
653 {
rjw20006d12022-04-21 16:29:04 +0800654 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800655 {
656 error = LYNQ_E_TIME_OUT;
657 LYERRLOG("timeout:wait data Call state fail!!!");
658 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
659 return error;
660 }
661 *handle = lynq_data_call_id;
662 }
663 return error;
664}
rjw7ee7bb42023-01-18 11:34:28 +0800665
lhf81a46f2022-02-13 23:57:37 -0800666int lynq_deactive_data_call(int *handle)
667{
668 Parcel p;
669 lynq_client_t client;
670 int resp_type = -1;
671 int request = -1;
672 int slot_id = -1;
673 int error = -1;
674 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800675 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800676 if(handle==NULL)
677 {
678 LYERRLOG("handle is null!!!");
679 return -1;
680 }
rjw1309e232022-07-22 09:54:06 +0800681 ret = handleCheck(*handle);
682 if (ret != 0)
683 {
684 LYERRLOG("incomming handle is invalid");
685 return -1;
686 }
687 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800688 client.uToken = Global_uToken;
689 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
690 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
691 {
692 client.paramLen = 0;
693 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800694 }
695 else
696 {
lhf81a46f2022-02-13 23:57:37 -0800697 client.paramLen = 1;
698 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
699 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
700 }
701 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800702 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800703 if(send_request(lynq_client_sockfd,&client)==-1)
704 {
705 LYERRLOG("send request fail");
706 perror("[LYNQ_DATA] send request fail:");
707 return -1;
708 }
709 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800710 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800711 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800712 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
713 cleanOnceApnTable(lynq_data_call_id);
714 return error;
715}
716int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
717{
718 Parcel p;
719 lynq_client_t client;
720 int resp_type = -1;
721 int request = -1;
722 int slot_id = -1;
723 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800724 int lynq_data_call_id = -1;
725 char *argv[10] = {};
726 if(handle==NULL||apn==NULL||apnType==NULL)
727 {
728 LYERRLOG("handle ,apn or apntype is null!!!");
729 return -1;
730 }
731 if(user==NULL)
732 {
733 argv[1] = "null";
734 }
735 else
736 {
737 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800738 }
739 if(password==NULL)
740 {
lhf81a46f2022-02-13 23:57:37 -0800741 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800742 }
743 else
744 {
lhf81a46f2022-02-13 23:57:37 -0800745 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800746 }
747 if(authType==NULL)
748 {
lhf81a46f2022-02-13 23:57:37 -0800749 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800750 }
751 else
752 {
lhf81a46f2022-02-13 23:57:37 -0800753 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800754 }
755 if(normalProtocol==NULL)
756 {
lhf81a46f2022-02-13 23:57:37 -0800757 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800758 }
759 else
760 {
lhf81a46f2022-02-13 23:57:37 -0800761 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800762 }
763 if(roamingProtocol==NULL)
764 {
lhf81a46f2022-02-13 23:57:37 -0800765 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800766 }
767 else
768 {
lhf81a46f2022-02-13 23:57:37 -0800769 argv[5] = roamingProtocol;
770 }
771 client.uToken = Global_uToken;
772 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
773 client.paramLen = 7;
774 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
775 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
776 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800777 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800778 if(send_request(lynq_client_sockfd,&client)==-1)
779 {
780 LYERRLOG("send request fail");
781 perror("[LYNQ_DATA] send request fail:");
782 return -1;
783 }
784 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800785 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800786 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800787 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
788 lynq_data_call_id = updateApn(apnType);
789 lynq_data_call = 1;
790 if(error==0)
791 {
rjw7ee7bb42023-01-18 11:34:28 +0800792 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800793 {
794 error = LYNQ_E_TIME_OUT;
795 LYERRLOG("timeout:wait data Call state fail!!!");
796 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
797 return error;
798 }
799 *handle = lynq_data_call_id;
800 }
801 return error;
802}
803/*
804int lynq_deactive_data_call_sp(int *handle,char *apnType)
805{
806 Parcel p;
807 lynq_client_t client;
808 int resp_type = -1;
809 int request = -1;
810 int slot_id = -1;
811 int error = -1;
812 if(handle==NULL||apnType==NULL)
813 {
814 LYERRLOG("handle is null!!!");
815 return -1;
816 }
817 client.uToken = Global_uToken;
818 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
819 client.paramLen = 1;
820 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
821 sprintf(client.param,"%s",apnType);
822 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
823 if(send_request(lynq_client_sockfd,&client)==-1)
824 {
825 LYERRLOG("send request fail");
826 perror("[LYNQ_DATA] send request fail:");
827 return -1;
828 }
829 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800830 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800831 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
832 return error;
833}
834*/
835int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
836{
837 Parcel p;
838 lynq_client_t client;
839 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800840 int token;
841 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800842 int slot_id = -1;
843 int error = -1;
844 int version =0;
845 int num = 0;
lhf81a46f2022-02-13 23:57:37 -0800846 char *temp_char = NULL;
847 if(dataCallList==NULL)
848 {
849 LYERRLOG("dataCallList is null!!!");
850 return -1;
851 }
852 client.uToken = Global_uToken;
853 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
854 client.paramLen = 0;
855 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
856 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800857 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800858 if(send_request(lynq_client_sockfd,&client)==-1)
859 {
860 LYERRLOG("send request fail");
861 perror("[LYNQ_DATA] send request fail:");
862 return -1;
863 }
864 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800865 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800866 if(p.dataAvail() > 0)
867 {
rjw0fb4ccb2022-09-16 19:12:35 +0800868 p.readInt32(&resp_type);
869 p.readInt32(&token);
870 p.readInt32(&request);
871 p.readInt32(&slot_id);
872 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +0800873 }
874 else
875 {
876 return -1;
877 }
lhf81a46f2022-02-13 23:57:37 -0800878 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
879 p.readInt32(&version);
880 if(version==11)
881 {
882 p.readInt32(&num);
883 *realNum = num;
884 for (int i = 0; i < num; i++)
885 {
886 p.readInt32(&dataCallList[i].status);
887 p.readInt32(&dataCallList[i].suggestedRetryTime);
888 p.readInt32(&dataCallList[i].cid);
889 p.readInt32(&dataCallList[i].active);
890 temp_char = strdupReadString(p);
891 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
892 temp_char = strdupReadString(p);
893 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
894 temp_char = strdupReadString(p);
895 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
896 temp_char = strdupReadString(p);
897 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
898 temp_char = strdupReadString(p);
899 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
900 temp_char = strdupReadString(p);
901 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
902 p.readInt32(&dataCallList[i].mtu);
903 }
904 }
905 return error;
906}
907int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
908{
909 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
910 int number = 0;
911 int lynq_data_call_id = 0;
912 int error = 0;
913 lynq_data_call_id = *handle;
914 if(handle==NULL)
915 {
916 LYERRLOG("handle is NULL");
917 return LYNQ_E_NULL_ANONALY;
918 }
919 memset(interDataCallList,0,sizeof(interDataCallList));
920 error = getDataCallLists(interDataCallList,&number);
921 if(error == 0)
922 {
923 for(int i = 0;i < number;i++)
924 {
925 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
926 {
927 dataCallList->active = interDataCallList[i].active;
928 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
929 dataCallList->cid = interDataCallList[i].cid;
930 dataCallList->status = interDataCallList[i].status;
931 dataCallList->mtu = interDataCallList[i].mtu;
932 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
933 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
934 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
935 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
936 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
937 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
938 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
939 }
940 }
941 }
942 return error;
943}
944int lynq_wait_data_call_state_change(int *handle)
945{
rjw7ee7bb42023-01-18 11:34:28 +0800946
947 std::vector<int>::iterator iter;
lhf81a46f2022-02-13 23:57:37 -0800948 waitPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800949
950 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
951 iter = s_data_urc_wait_list.begin();
952 handle = (*iter);
953 s_data_urc_wait_list.erase(iter);
954 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
955
lhf81a46f2022-02-13 23:57:37 -0800956 LYINFLOG("lynq data call id:%d",lynq_data_call_change_id);
957 return 0;
958}
959/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +0800960
961/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +0800962
963int 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 +0800964{
965 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +0800966 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +0800967 {
rjw61fcae32022-08-18 14:03:39 +0800968 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +0800969 }
rjw61fcae32022-08-18 14:03:39 +0800970 else
rjw0cdacbc2022-06-22 10:51:07 +0800971 {
rjw61fcae32022-08-18 14:03:39 +0800972 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +0800973 }
rjw20006d12022-04-21 16:29:04 +0800974 if (mcc == NULL)
975 {
976 sprintf(strtmp[1], "mcc=;");
977 }
978 else
979 {
980 sprintf(strtmp[1], "mcc=%s;", mcc);
981 }
982 if (mnc == NULL)
983 {
rjw61fcae32022-08-18 14:03:39 +0800984 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +0800985 }
986 else
987 {
988 sprintf(strtmp[2], "mnc=%s;", mnc);
989 }
990 if (apn == NULL)
991 {
992 sprintf(strtmp[3], "apn=;");
993 }
994 else
995 {
996 sprintf(strtmp[3], "apn=%s;", apn);
997 }
998 if (apntype == NULL)
999 {
1000 sprintf(strtmp[4], "apntype=;");
1001 }
1002 else
1003 {
1004 sprintf(strtmp[4], "apntype=%s;", apntype);
1005 }
1006 if (user == NULL)
1007 {
1008 sprintf(strtmp[5], "user=;");
1009 }
1010 else
1011 {
1012 sprintf(strtmp[5], "user=%s;", user);
1013 }
1014 if (password == NULL)
1015 {
1016 sprintf(strtmp[6], "password=;");
1017 }
1018 else
1019 {
1020 sprintf(strtmp[6], "password=%s;", password);
1021 }
1022 if (normalprotocol == NULL)
1023 {
1024 sprintf(strtmp[7], "normalprotocol=;");
1025 }
1026 else
1027 {
1028 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1029 }
1030 if (roamingprotocol == NULL)
1031 {
1032 sprintf(strtmp[8], "roamingprotocol=;");
1033 }
1034 else
1035 {
1036 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1037 }
1038 if (carrier == NULL)
1039 {
1040 sprintf(strtmp[9], "carrier=;");
1041 }
1042 else
1043 {
1044 sprintf(strtmp[9], "carrier=%s;", carrier);
1045 }
rjw61fcae32022-08-18 14:03:39 +08001046 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 +08001047
rjw20006d12022-04-21 16:29:04 +08001048 return 0;
1049}
1050
1051int 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)
1052{
1053 char strtmp[10][32];
1054 if (id == NULL)
1055 {
1056 sprintf(strtmp[0], "id=;");
1057 }
1058 else
1059 {
1060 sprintf(strtmp[0], "id=%s;", id);
1061 }
1062 if (mcc == NULL)
1063 {
1064 sprintf(strtmp[1], "mcc=;");
1065 }
1066 else
1067 {
1068 sprintf(strtmp[1], "mcc=%s;", mcc);
1069 }
1070 if (mnc == NULL)
1071 {
1072 sprintf(strtmp[2], "mnc=;");
1073 }
1074 else
1075 {
1076 sprintf(strtmp[2], "mnc=%s;", mnc);
1077 }
1078 if (apn == NULL)
1079 {
1080 sprintf(strtmp[3], "apn=;");
1081 }
1082 else
1083 {
1084 sprintf(strtmp[3], "apn=%s;", apn);
1085 }
1086 if (apntype == NULL)
1087 {
1088 sprintf(strtmp[4], "apntype=;");
1089 }
1090 else
1091 {
1092 sprintf(strtmp[4], "apntype=%s;", apntype);
1093 }
1094 if (user == NULL)
1095 {
1096 sprintf(strtmp[5], "user=;");
1097 }
1098 else
1099 {
1100 sprintf(strtmp[5], "user=%s;", user);
1101 }
1102 if (password == NULL)
1103 {
1104 sprintf(strtmp[6], "password=;");
1105 }
1106 else
1107 {
1108 sprintf(strtmp[6], "password=%s;", password);
1109 }
1110 if (normalprotocol == NULL)
1111 {
1112 sprintf(strtmp[7], "normalprotocol=;");
1113 }
1114 else
1115 {
1116 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1117 }
1118 if (roamingprotocol == NULL)
1119 {
1120 sprintf(strtmp[8], "roamingprotocol=;");
1121 }
1122 else
1123 {
1124 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1125 }
1126 if (carrier == NULL)
1127 {
1128 sprintf(strtmp[9], "carrier=;");
1129 }
1130 else
1131 {
1132 sprintf(strtmp[9], "carrier=%s;", carrier);
1133 }
1134 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]);
1135 return 0;
1136}
1137
rjwaf4b1612022-06-13 17:26:01 +08001138
1139int 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)
1140{
1141 char strtmp[10][32];
1142 if (id == NULL)
1143 {
1144 sprintf(strtmp[0], "");
1145 }
1146 else
1147 {
1148 sprintf(strtmp[0], "id=%s;", id);
1149 }
1150 if (mcc == NULL)
1151 {
1152 sprintf(strtmp[1], "");
1153 }
1154 else
1155 {
1156 sprintf(strtmp[1], "mcc=%s;", mcc);
1157 }
1158 if (mnc == NULL)
1159 {
1160 sprintf(strtmp[2], "");
1161 }
1162 else
1163 {
1164 sprintf(strtmp[2], "mnc=%s;", mnc);
1165 }
1166 if (apn == NULL)
1167 {
1168 sprintf(strtmp[3], "");
1169 }
1170 else
1171 {
1172 sprintf(strtmp[3], "apn=%s;", apn);
1173 }
1174 if (apntype == NULL)
1175 {
1176 sprintf(strtmp[4], "");
1177 }
1178 else
1179 {
1180 sprintf(strtmp[4], "apntype=%s;", apntype);
1181 }
1182 if (user == NULL)
1183 {
1184 sprintf(strtmp[5], "");
1185 }
1186 else
1187 {
1188 sprintf(strtmp[5], "user=%s;", user);
1189 }
1190 if (password == NULL)
1191 {
1192 sprintf(strtmp[6], "");
1193 }
1194 else
1195 {
1196 sprintf(strtmp[6], "password=%s;", password);
1197 }
1198 if (normalprotocol == NULL)
1199 {
1200 sprintf(strtmp[7], "");
1201 }
1202 else
1203 {
1204 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1205 }
1206 if (roamingprotocol == NULL)
1207 {
1208 sprintf(strtmp[8], "");
1209 }
1210 else
1211 {
1212 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1213 }
1214 if (carrier == NULL)
1215 {
1216 sprintf(strtmp[9], "");
1217 }
1218 else
1219 {
1220 sprintf(strtmp[9], "carrier=%s;", carrier);
1221 }
1222 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]);
1223 return 0;
1224}
1225
rjw20006d12022-04-21 16:29:04 +08001226static char *lynqStrdupReadString(Parcel &p)
1227{
1228 size_t stringlen;
1229 const char16_t *s16;
1230
1231 s16 = p.readString16Inplace(&stringlen);
1232 return strndup16to8(s16, stringlen);
1233}
1234
1235int 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)
1236{
1237 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1238 {
1239 LYERRLOG("There are no valid parameters");
1240 return -1;
1241 }
1242 lynq_client_t client;
1243 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001244 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001245 Parcel p;
1246 if (cmd == 0) // insert apn db
1247 {
rjw61fcae32022-08-18 14:03:39 +08001248 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1249
rjw20006d12022-04-21 16:29:04 +08001250 client.uToken = Global_uToken;
1251 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1252 client.paramLen = 2;
1253 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1254 sprintf(client.param, "%d %s", cmd, argc);
1255 }
rjw61fcae32022-08-18 14:03:39 +08001256 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001257 {
1258 if (NULL == id)
1259 {
1260 LYERRLOG("id is NULL!!!please input id: ");
1261 }
1262 sprintf(argc, "id=%s", id);
1263 client.uToken = Global_uToken;
1264 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1265 client.paramLen = 2;
1266 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1267 sprintf(client.param, "%d %s", cmd, argc);
1268 }
rjw61fcae32022-08-18 14:03:39 +08001269 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001270 {
rjwaf4b1612022-06-13 17:26:01 +08001271 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001272 client.uToken = Global_uToken;
1273 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1274 client.paramLen = 2;
1275 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1276 sprintf(client.param, "%d %s", cmd, argc);
1277 }
rjw61fcae32022-08-18 14:03:39 +08001278 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001279 {
1280 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1281 client.uToken = Global_uToken;
1282 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1283 client.paramLen = 2;
1284 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1285 sprintf(client.param, "%d %s", cmd, argc);
1286 }
1287 else
1288 {
1289 LYERRLOG("incoming command is invalid");
1290 return -1;
1291 }
1292 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001293 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001294 if(send_request(lynq_client_sockfd,&client)==-1)
1295 {
1296 LYERRLOG("send request fail");
1297 return -1;
1298 }
rjwed00d042022-05-25 09:18:16 +08001299 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001300 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001301 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001302 LYINFLOG(">>>>>output info:%s",out);
1303 return 0;
1304}
1305
1306int lynq_reset_apn(char *result)
1307{
1308 Parcel p;
1309 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001310 if (NULL == result)
1311 {
1312 LYERRLOG("incoming paramters error");
1313 }
rjw20006d12022-04-21 16:29:04 +08001314 client.uToken = Global_uToken;
1315 client.request = 2000 + 194;
1316 client.paramLen = 0;
1317 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1318 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001319 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001320 if (send_request(lynq_client_sockfd, &client) == -1)
1321 {
1322 LYERRLOG("send request fail");
1323 return -1;
1324 }
rjwed00d042022-05-25 09:18:16 +08001325 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001326 waitApnResult();
1327 strcpy(result, g_lynq_apn_result);
1328 LYINFLOG(">>>>>result:%s",result);
1329 return 0;
1330}
1331
rjw3bcbbf12022-04-22 16:47:18 +08001332/*Typethree add for T800 platform 2022/04/21 end*/