blob: 7fac4a6d84b7b6deb4a4b3eaf43f4e3503b54e85 [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
rjwc63abb42023-03-31 18:22:42 +080077static int data_invaild_error = 0;
78
rjw22947c22022-03-15 09:21:29 +080079/**g_lynq_data_init_flag
80* @brief mark data initialization state
81* 0:deinit status
82* 1:init state
83*/
84static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080085/**g_lynq_apn_result
86* @brief temp of apn result info
87*/
88char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +080089
rjw7ee7bb42023-01-18 11:34:28 +080090static std::vector<int> s_data_urc_wait_list;
91
rjw20006d12022-04-21 16:29:04 +080092typedef struct
93{
lhf81a46f2022-02-13 23:57:37 -080094 char apn[LYNQ_APN_MAX_LEN];
95 char apnType[LYNQ_APN_TYPE_MAX_LEN];
96 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
97 int hasUsed;
98 int hasTimeout;
99}lynq_apn_t;
100lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
101lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
102int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800103
lhf81a46f2022-02-13 23:57:37 -0800104int getLynqApnID(char apnType[])
105{
106 int ret = 0;
rjwc63abb42023-03-31 18:22:42 +0800107 int len = 0;
lhf81a46f2022-02-13 23:57:37 -0800108 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
109 {
rjwc63abb42023-03-31 18:22:42 +0800110 len = strlen(lynq_apn_table[ret].apnType)<strlen(apnType) ? strlen(lynq_apn_table[ret].apnType):strlen(apnType);
111 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
lh13586612022-01-11 21:58:58 -0800112 {
lhf81a46f2022-02-13 23:57:37 -0800113 return ret;
114 }
115 }
116 return -1;
117}
rjw7ee7bb42023-01-18 11:34:28 +0800118
lhf81a46f2022-02-13 23:57:37 -0800119void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
120{
121 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
122 if(apn_table==NULL)
123 {
124 LYERRLOG("apn_table is null");
125 return;
126 }
127 memcpy(apn_table->apn,apn,strlen(apn)+1);
128 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
129 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
130 apn_table->hasTimeout = 0;
131 apn_table->hasUsed = 1;
132 return;
133}
rjw7ee7bb42023-01-18 11:34:28 +0800134
lhf81a46f2022-02-13 23:57:37 -0800135void cleanOnceApnTable(int apnId)
136{
137 LYDBGLOG("apn id:%d",apnId);
138 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
139 {
140 LYERRLOG("apn id is invalid!!!");
141 return;
142 }
143 lynq_apn_table[apnId].hasTimeout = 0;
144 lynq_apn_table[apnId].hasUsed = 0;
145 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
146 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
147 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
148 return;
149}
150int getUnusedElement()
151{
rjwc63abb42023-03-31 18:22:42 +0800152 if (lynq_apn_table == NULL)
153 {
154 LYERRLOG("get UnusedElemnt apn_table is null");
155 return -1;
156 }
lhf81a46f2022-02-13 23:57:37 -0800157 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
158 {
159 if(lynq_apn_table[i].hasUsed!=1)
160 {
161 return i;
162 }
163 }
rjwc63abb42023-03-31 18:22:42 +0800164 LYERRLOG("None of get unused Element");
lhf81a46f2022-02-13 23:57:37 -0800165 return -1;
166}
167int updateApn(char apnType[])
168{
169 int ret = 0;
170 ret = getUnusedElement();
171 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
172 lynq_apn_table[ret].hasUsed = 1;
173 return ret;
174}
rjw1309e232022-07-22 09:54:06 +0800175
176int handleCheck(int handle)
177{
178 if (lynq_apn_table[handle].hasUsed == 1)
179 {
180 return 0;
181 }
182 else
183 {
184 return -1;
185 }
186}
rjw20006d12022-04-21 16:29:04 +0800187int waitApnResult()
188{
189 int ret = 0;
190 LYINFLOG("start wait apn result!!!");
191 int sec = 0;
192 int usec = 0;
193 struct timeval now;
194 struct timespec timeout;
195 gettimeofday(&now, NULL);
196 sec = 20000 / 1000;
197 usec = 20000 % 1000;
198 timeout.tv_sec = now.tv_sec + sec;
199 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
200 pthread_mutex_lock(&s_lynq_apn_change_mutex);
201 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
202 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
203 return ret;
204}
205
206void sendSignalApnChange()
207{
208 LYINFLOG("start send Signal Apn Change");
209 pthread_mutex_lock(&s_lynq_apn_change_mutex);
210 pthread_cond_signal(&s_lynq_apn_change_cond);
211 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
212 return;
213}
lhf81a46f2022-02-13 23:57:37 -0800214
215int waitPdnChange()
216{
217 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800218 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
219 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
220 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800221 return ret;
222}
223int waitDataCallstateChange(int mtime)
224{
225 int ret = 0;
226 int sec = 0;
227 int usec = 0;
228 struct timeval now;
229 struct timespec timeout;
230 gettimeofday(&now,NULL);
231 sec = mtime/1000;
232 usec = mtime%1000;
233 timeout.tv_sec = now.tv_sec+sec;
234 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
235 pthread_mutex_lock(&s_data_call_state_change_mutex);
236 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
237 pthread_mutex_unlock(&s_data_call_state_change_mutex);
238 return ret;
239}
240void sendSignalDataCallStateChange()
241{
242 pthread_mutex_lock(&s_data_call_state_change_mutex);
243 pthread_cond_signal(&s_data_call_state_change_cond);
244 pthread_mutex_unlock(&s_data_call_state_change_mutex);
245 return;
246}
247void sendSignalPdnChange()
248{
rjw7ee7bb42023-01-18 11:34:28 +0800249 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
250 pthread_cond_signal(&s_lynq_urc_vector_cond);
251 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800252 return;
253}
254
255int get_response(int sockfd,Parcel &p)
256{
257 int len = 0;
258 char recvline[LYNQ_REC_BUF];
259 bzero(recvline,LYNQ_REC_BUF);
260 /* receive data from server */
rjw08528682022-07-04 21:28:02 +0800261 len = read(sockfd, recvline, LYNQ_REC_BUF);
262 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800263 {
rjw747deea2022-07-01 18:25:30 +0800264 LYERRLOG("read error");
lhf81a46f2022-02-13 23:57:37 -0800265 return -1;
266 }
267 if (recvline != NULL) {
268 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
269 p.setDataPosition(0);
270 }
271 return 0;
272}
rjwfa532972022-09-16 13:39:41 +0800273int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
lhf81a46f2022-02-13 23:57:37 -0800274{
275 if(p.dataAvail() > 0)
276 {
277 p.readInt32(resp_type);
278 p.readInt32(request);
279 p.readInt32(slot_id);
280 p.readInt32(error);
281 return 0;
282 }
283 else
284 {
285 return -1;
286 }
287}
288int send_request(int sockfd,lynq_client_t *client_tmp)
289{
290 int ret=0;
291 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
292 if(ret==-1)
293 {
294 perror("write error");
295 return -1;
296 }
297 return 0;
298}
299static char *strdupReadString(Parcel &p) {
300 size_t stringlen;
301 const char16_t *s16;
302 s16 = p.readString16Inplace(&stringlen);
303 return strndup16to8(s16, stringlen);
304}
305static char *strdupReadString_p(Parcel *p) {
306 size_t stringlen;
307 const char16_t *s16;
308 s16 = p->readString16Inplace(&stringlen);
309 return strndup16to8(s16, stringlen);
310}
311
lhf81a46f2022-02-13 23:57:37 -0800312/*Warren add for T800 platform 2021/11/19 start*/
313int lynq_socket_client_start()
314{
rjw08528682022-07-04 21:28:02 +0800315 struct sockaddr_in lynq_data_socket_server_addr;
lhf81a46f2022-02-13 23:57:37 -0800316 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800317 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
318 lynq_data_socket_server_addr.sin_family = AF_INET;
319 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
jb.qid5852372023-03-29 10:29:12 +0800320 lynq_data_socket_server_addr.sin_addr.s_addr = inet_addr(LYNQ_ADDRESS);
lhf81a46f2022-02-13 23:57:37 -0800321 /*
322 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
323 {
324 printf("[%s] is not a valid IPaddress\n", argv[1]);
325 exit(1);
326 }
327*/
328 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800329 struct timeval timeOut;
330
rjwa59bf312022-07-05 11:50:31 +0800331 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800332 timeOut.tv_usec = 0;
333
334 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
335 {
336 LYERRLOG("time out setting failed");
337 }
338 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 -0800339 {
340 perror("connect error");
341 return -1;
342 }
343 return 0;
344}
rjw7ee7bb42023-01-18 11:34:28 +0800345
346bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800347{
rjw7ee7bb42023-01-18 11:34:28 +0800348 switch(urc_id)
349 {
350 case LYNQ_URC_DATA_CALL_STATUS_IND:
351
352 case LYNQ_URC_MODIFY_APNDB:
353 case LYNQ_URC_RESET_APNDB:
354 return true;
355 default:
356 return false;
357 }
358}
359
rjwc63abb42023-03-31 18:22:42 +0800360int printf_apn_table()
361{
362 int ret = 0;
363 if (lynq_apn_table == NULL)
364 {
365 LYERRLOG("apn table is null");
366 return -1;
367 }
368 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
369 {
370 LYINFLOG("[Typethree test info]apn=%s ;apntype=%s ;ifname=%s ;hasTimeout = %d ; hasUsed = %d", \
371 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
372 lynq_apn_table[ret].hasTimeout,lynq_apn_table[ret].hasUsed);
373 }
374 return 0;
375}
376
377
rjw7ee7bb42023-01-18 11:34:28 +0800378void urc_msg_process(Parcel *p)
379{
380 int len;
381 int resp_type;
382 int urcid;
383 int slot_id;
384
385 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800386 char apn[LYNQ_APN_MAX_LEN];
387 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800388 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800389 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800390
391 int size = p->dataSize();
392 p->readInt32(&resp_type);
393 p->readInt32(&urcid);
394 p->readInt32(&slot_id);
395 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
396 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800397 {
rjw7ee7bb42023-01-18 11:34:28 +0800398 case LYNQ_URC_DATA_CALL_STATUS_IND:
399 p->readInt32(&pdnState);
400 bzero(apn,LYNQ_APN_MAX_LEN);
401 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
402 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
403 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800404 {
rjw20006d12022-04-21 16:29:04 +0800405 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800406 int len = strlen(urc_msg);
407 if(len < LYNQ_APN_MAX_LEN-1)
rjw20006d12022-04-21 16:29:04 +0800408 {
rjw7ee7bb42023-01-18 11:34:28 +0800409 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800410 }
rjw7ee7bb42023-01-18 11:34:28 +0800411 urc_msg = strdupReadString_p(p);
412 len = strlen(urc_msg);
413 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
414 {
415 memcpy(apnType,urc_msg,len+1);
416 }
417 urc_msg = strdupReadString_p(p);
418 len = strlen(urc_msg);
419 if(len < LYNQ_IFACE_NAME_MAX_LEN-1)
420 {
421 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
422 }
423 //sendSignalDataCallStateChange();
424 int apnId = getLynqApnID(apnType);
rjwc63abb42023-03-31 18:22:42 +0800425 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d",apnType,ifaceName,apn,pdnState);
rjw7ee7bb42023-01-18 11:34:28 +0800426 if(apnId >= 0)
427 {
428 if(lynq_apn_table[apnId].hasTimeout==1)
429 {
rjwc63abb42023-03-31 18:22:42 +0800430 /*whether timeout?,real or not,*/
431 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800432 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800433 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 +0800434 {
435 LYERRLOG("deactive this time out APN");
436 lynq_deactive_data_call(&apnId);
437 }
rjwc63abb42023-03-31 18:22:42 +0800438 else
rjw7ee7bb42023-01-18 11:34:28 +0800439 {
rjwc63abb42023-03-31 18:22:42 +0800440 /*if apn lose,update apn and deactive all apn*/
441 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800442 }
443 break;
444 }
rjwacdb2152023-02-07 14:12:49 +0800445 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
rjw7ee7bb42023-01-18 11:34:28 +0800446 }
447 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800448 else
449 {
rjwc63abb42023-03-31 18:22:42 +0800450 data_invaild_error = 1;
451 printf_apn_table();
452 LYERRLOG("invalid apnId:%d",apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800453 break;
rjw20006d12022-04-21 16:29:04 +0800454 }
rjw7ee7bb42023-01-18 11:34:28 +0800455 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
456 s_data_urc_wait_list.push_back(apnId);
457 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
458 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800459 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800460 LYDBGLOG("data call state:%d",lynq_data_call);
461 if(lynq_data_call==1)
462 {
463 sendSignalDataCallStateChange();
464 lynq_data_call = 0;
465 }
rjw20006d12022-04-21 16:29:04 +0800466 }
rjw7ee7bb42023-01-18 11:34:28 +0800467 else
rjw20006d12022-04-21 16:29:04 +0800468 {
rjw7ee7bb42023-01-18 11:34:28 +0800469 urc_msg = strdupReadString_p(p);
470 len = strlen(urc_msg);
471 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
472 {
473 memcpy(apnType,urc_msg,len+1);
474 }
475 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
476 int apnId = getLynqApnID(apnType);
477 if(apnId >= 0)
478 {
479 lynq_data_call_change_id = apnId;
480 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800481 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
482 s_data_urc_wait_list.push_back(apnId);
483 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
rjwc3d6e582023-03-28 17:19:11 +0800484 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800485 }
rjw7ee7bb42023-01-18 11:34:28 +0800486 LYDBGLOG("data call state:%d",lynq_data_call);
487 if(lynq_data_call==1)
488 {
489 sendSignalDataCallStateChange();
490 lynq_data_call = 0;
491 }
492 }
493 break;
494 case LYNQ_URC_MODIFY_APNDB:
495 urc_msg = strdupReadString_p(p);
496 if (NULL == urc_msg)
497 {
498 LYERRLOG("error apn msg");
499 }
500 else
501 {
502 bzero(g_lynq_apn_result, 1024);
503 strcpy(g_lynq_apn_result, urc_msg);
504 sendSignalApnChange();
505 }
506 break;
507 case LYNQ_URC_RESET_APNDB:
508 {
rjw20006d12022-04-21 16:29:04 +0800509 urc_msg = strdupReadString_p(p);
510 if (NULL == urc_msg)
511 {
512 LYERRLOG("error apn msg");
513 }
514 else
515 {
516 bzero(g_lynq_apn_result, 1024);
517 strcpy(g_lynq_apn_result, urc_msg);
518 sendSignalApnChange();
519 }
520 }
rjw7ee7bb42023-01-18 11:34:28 +0800521 default:
522 break;
lhf81a46f2022-02-13 23:57:37 -0800523 }
rjw7ee7bb42023-01-18 11:34:28 +0800524
lhf81a46f2022-02-13 23:57:37 -0800525}
rjw7ee7bb42023-01-18 11:34:28 +0800526
rjw7ee7bb42023-01-18 11:34:28 +0800527int create_urc_vector_signal_thread()
528{
529 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800530 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800531 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
532 s_data_urc_wait_list.clear();
533 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800534 return 0;
535}
rjw7ee7bb42023-01-18 11:34:28 +0800536
lhf81a46f2022-02-13 23:57:37 -0800537int lynq_init_data(int uToken)
538{
rjw22947c22022-03-15 09:21:29 +0800539 if (g_lynq_data_init_flag == 1)
540 {
541 LYERRLOG("init twice is not allowed");
542 return -1;
543 }
544 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800545 int result = 0;
546 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800547 LYLOGSET(LOG_INFO);
548 LYLOGEINIT(USER_LOG_TAG);
549 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800550 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800551 if(result!=0)
552 {
553 LYERRLOG("init socket client fail!!!");
554 return -1;
555 }
rjw7ee7bb42023-01-18 11:34:28 +0800556 result = lynq_init_data_urc_thread();
557 if(result!=0)
558 {
559 LYERRLOG("init socket urc fail!!!");
560 return -1;
561 }
562
563 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800564 if(result!=0)
565 {
566 LYERRLOG("init socket urc fail!!!");
567 return -1;
568 }
569 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
570 LYDBGLOG("lynq init call success!!!");
571 return 0;
572
573}
574int lynq_deinit_data()
575{
576 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800577 if (g_lynq_data_init_flag == 0)
578 {
579 LYERRLOG("deinit twice is not allowed");
580 return ret;
581 }
582 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800583 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
584 {
585 if(strlen(lynq_apn_table[i].apnType)!=0)
586 {
587 lynq_deactive_data_call(&i);
588 }
589 }
590 if(lynq_client_sockfd>0)
591 {
592 close(lynq_client_sockfd);
593 }
rjw7ee7bb42023-01-18 11:34:28 +0800594 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800595 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800596 {
rjw7ee7bb42023-01-18 11:34:28 +0800597 LYERRLOG("lynq_deinit_data_urc_thread fail");
598 return ret;
rjw22947c22022-03-15 09:21:29 +0800599 }
rjwc3d6e582023-03-28 17:19:11 +0800600 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
601 s_data_urc_wait_list.clear();
602 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800603 return 0;
604}
605int lynq_setup_data_call(int *handle)
606{
607 Parcel p;
608 lynq_client_t client;
609 int resp_type = -1;
610 int request = -1;
611 int slot_id = -1;
612 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800613 int lynq_data_call_id = 0;
614 if(handle==NULL)
615 {
616 LYERRLOG("handle is null!!!");
617 return LYNQ_E_NULL_ANONALY;
618 }
619 client.uToken = Global_uToken;
620 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
621 client.paramLen = 0;
622 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
623 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800624 lynq_data_call_id = updateApn("default");
625 if (lynq_data_call_id < 0)
626 {
627 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
628 return -1;
629 }
rjwed00d042022-05-25 09:18:16 +0800630 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800631 if(send_request(lynq_client_sockfd,&client)==-1)
632 {
633 LYERRLOG("send request fail");
634 perror("[LYNQ_DATA] send request fail:");
635 return -1;
636 }
637 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800638 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800639 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800640 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800641 lynq_data_call = 1;
642 if(error==0)
643 {
rjw20006d12022-04-21 16:29:04 +0800644 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800645 {
646 error = LYNQ_E_TIME_OUT;
647 LYERRLOG("timeout:wait data Call state fail!!!");
648 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
rjwc63abb42023-03-31 18:22:42 +0800649 if (data_invaild_error == 1)
650 {
651 data_invaild_error = 0;
652 LYERRLOG("urc apn info error!!!");
653 return 8085;
654 }
lhf81a46f2022-02-13 23:57:37 -0800655 return error;
656 }
657 *handle = lynq_data_call_id;
658 }
659 return error;
660}
rjw7ee7bb42023-01-18 11:34:28 +0800661
lhf81a46f2022-02-13 23:57:37 -0800662int lynq_deactive_data_call(int *handle)
663{
664 Parcel p;
665 lynq_client_t client;
666 int resp_type = -1;
667 int request = -1;
668 int slot_id = -1;
669 int error = -1;
670 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800671 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800672 if(handle==NULL)
673 {
674 LYERRLOG("handle is null!!!");
675 return -1;
676 }
rjw1309e232022-07-22 09:54:06 +0800677 ret = handleCheck(*handle);
678 if (ret != 0)
679 {
680 LYERRLOG("incomming handle is invalid");
681 return -1;
682 }
683 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800684 client.uToken = Global_uToken;
685 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
686 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
687 {
688 client.paramLen = 0;
689 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800690 }
691 else
692 {
lhf81a46f2022-02-13 23:57:37 -0800693 client.paramLen = 1;
694 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
695 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
696 }
697 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800698 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800699 if(send_request(lynq_client_sockfd,&client)==-1)
700 {
701 LYERRLOG("send request fail");
702 perror("[LYNQ_DATA] send request fail:");
703 return -1;
704 }
705 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800706 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800707 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800708 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
709 cleanOnceApnTable(lynq_data_call_id);
710 return error;
711}
712int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
713{
714 Parcel p;
715 lynq_client_t client;
716 int resp_type = -1;
717 int request = -1;
718 int slot_id = -1;
719 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800720 int lynq_data_call_id = -1;
721 char *argv[10] = {};
722 if(handle==NULL||apn==NULL||apnType==NULL)
723 {
724 LYERRLOG("handle ,apn or apntype is null!!!");
725 return -1;
726 }
727 if(user==NULL)
728 {
729 argv[1] = "null";
730 }
731 else
732 {
733 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800734 }
735 if(password==NULL)
736 {
lhf81a46f2022-02-13 23:57:37 -0800737 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800738 }
739 else
740 {
lhf81a46f2022-02-13 23:57:37 -0800741 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800742 }
743 if(authType==NULL)
744 {
lhf81a46f2022-02-13 23:57:37 -0800745 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800746 }
747 else
748 {
lhf81a46f2022-02-13 23:57:37 -0800749 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800750 }
751 if(normalProtocol==NULL)
752 {
lhf81a46f2022-02-13 23:57:37 -0800753 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800754 }
755 else
756 {
lhf81a46f2022-02-13 23:57:37 -0800757 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800758 }
759 if(roamingProtocol==NULL)
760 {
lhf81a46f2022-02-13 23:57:37 -0800761 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800762 }
763 else
764 {
lhf81a46f2022-02-13 23:57:37 -0800765 argv[5] = roamingProtocol;
766 }
767 client.uToken = Global_uToken;
768 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
769 client.paramLen = 7;
770 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
771 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
772 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800773 lynq_data_call_id = updateApn(apnType);
774 if (lynq_data_call_id < 0)
775 {
776 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
777 return -1;
778 }
rjwed00d042022-05-25 09:18:16 +0800779 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800780 if(send_request(lynq_client_sockfd,&client)==-1)
781 {
782 LYERRLOG("send request fail");
783 perror("[LYNQ_DATA] send request fail:");
784 return -1;
785 }
786 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800787 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800788 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800789 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800790 lynq_data_call = 1;
791 if(error==0)
792 {
rjw7ee7bb42023-01-18 11:34:28 +0800793 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800794 {
795 error = LYNQ_E_TIME_OUT;
796 LYERRLOG("timeout:wait data Call state fail!!!");
797 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
rjwc63abb42023-03-31 18:22:42 +0800798 if (data_invaild_error == 1)
799 {
800 data_invaild_error = 0;
801 LYERRLOG("urc apn info error!!!");
802 return 8085;
803 }
lhf81a46f2022-02-13 23:57:37 -0800804 return error;
805 }
806 *handle = lynq_data_call_id;
807 }
808 return error;
809}
810/*
811int lynq_deactive_data_call_sp(int *handle,char *apnType)
812{
813 Parcel p;
814 lynq_client_t client;
815 int resp_type = -1;
816 int request = -1;
817 int slot_id = -1;
818 int error = -1;
819 if(handle==NULL||apnType==NULL)
820 {
821 LYERRLOG("handle is null!!!");
822 return -1;
823 }
824 client.uToken = Global_uToken;
825 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
826 client.paramLen = 1;
827 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
828 sprintf(client.param,"%s",apnType);
829 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
830 if(send_request(lynq_client_sockfd,&client)==-1)
831 {
832 LYERRLOG("send request fail");
833 perror("[LYNQ_DATA] send request fail:");
834 return -1;
835 }
836 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800837 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800838 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
839 return error;
840}
841*/
842int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
843{
844 Parcel p;
845 lynq_client_t client;
846 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800847 int token;
848 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800849 int slot_id = -1;
850 int error = -1;
851 int version =0;
852 int num = 0;
lhf81a46f2022-02-13 23:57:37 -0800853 char *temp_char = NULL;
854 if(dataCallList==NULL)
855 {
856 LYERRLOG("dataCallList is null!!!");
857 return -1;
858 }
859 client.uToken = Global_uToken;
860 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
861 client.paramLen = 0;
862 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
863 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800864 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800865 if(send_request(lynq_client_sockfd,&client)==-1)
866 {
867 LYERRLOG("send request fail");
868 perror("[LYNQ_DATA] send request fail:");
869 return -1;
870 }
871 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800872 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800873 if(p.dataAvail() > 0)
874 {
rjw0fb4ccb2022-09-16 19:12:35 +0800875 p.readInt32(&resp_type);
876 p.readInt32(&token);
877 p.readInt32(&request);
878 p.readInt32(&slot_id);
879 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +0800880 }
881 else
882 {
883 return -1;
884 }
lhf81a46f2022-02-13 23:57:37 -0800885 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
886 p.readInt32(&version);
887 if(version==11)
888 {
889 p.readInt32(&num);
890 *realNum = num;
891 for (int i = 0; i < num; i++)
892 {
893 p.readInt32(&dataCallList[i].status);
894 p.readInt32(&dataCallList[i].suggestedRetryTime);
895 p.readInt32(&dataCallList[i].cid);
896 p.readInt32(&dataCallList[i].active);
897 temp_char = strdupReadString(p);
898 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
899 temp_char = strdupReadString(p);
900 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
901 temp_char = strdupReadString(p);
902 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
903 temp_char = strdupReadString(p);
904 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
905 temp_char = strdupReadString(p);
906 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
907 temp_char = strdupReadString(p);
908 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
909 p.readInt32(&dataCallList[i].mtu);
910 }
911 }
912 return error;
913}
914int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
915{
916 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
917 int number = 0;
918 int lynq_data_call_id = 0;
919 int error = 0;
920 lynq_data_call_id = *handle;
921 if(handle==NULL)
922 {
923 LYERRLOG("handle is NULL");
924 return LYNQ_E_NULL_ANONALY;
925 }
rjw3938f262023-03-08 16:09:28 +0800926 if (*handle<0 && handle>8)
927 {
928 LYERRLOG("handle value error");
929 }
930 LYINFLOG("incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800931 memset(interDataCallList,0,sizeof(interDataCallList));
932 error = getDataCallLists(interDataCallList,&number);
933 if(error == 0)
934 {
935 for(int i = 0;i < number;i++)
936 {
937 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
938 {
939 dataCallList->active = interDataCallList[i].active;
940 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
941 dataCallList->cid = interDataCallList[i].cid;
942 dataCallList->status = interDataCallList[i].status;
943 dataCallList->mtu = interDataCallList[i].mtu;
944 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
945 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
946 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
947 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
948 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
949 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
950 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
951 }
952 }
953 }
954 return error;
955}
956int lynq_wait_data_call_state_change(int *handle)
957{
rjwc3d6e582023-03-28 17:19:11 +0800958 if (data_waiting_status == 1)
959 {
960 LYDBGLOG("some thread is waiting");
961 return -3;
962 }
963 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
964 if (s_data_urc_wait_list.empty())
965 {
966 LYDBGLOG("start wait");
967 data_waiting_status = 1;
968 waitPdnChange();
969 }
970 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800971 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +0800972
973 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
974 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +0800975 if (iter != s_data_urc_wait_list.end())
976 {
977 *handle = *iter;
978 }
rjw7ee7bb42023-01-18 11:34:28 +0800979 s_data_urc_wait_list.erase(iter);
980 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
981
rjw3938f262023-03-08 16:09:28 +0800982 LYINFLOG("lynq data call id:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800983 return 0;
984}
985/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +0800986
987/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +0800988
989int 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 +0800990{
991 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +0800992 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +0800993 {
rjw61fcae32022-08-18 14:03:39 +0800994 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +0800995 }
rjw61fcae32022-08-18 14:03:39 +0800996 else
rjw0cdacbc2022-06-22 10:51:07 +0800997 {
rjw61fcae32022-08-18 14:03:39 +0800998 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +0800999 }
rjw20006d12022-04-21 16:29:04 +08001000 if (mcc == NULL)
1001 {
1002 sprintf(strtmp[1], "mcc=;");
1003 }
1004 else
1005 {
1006 sprintf(strtmp[1], "mcc=%s;", mcc);
1007 }
1008 if (mnc == NULL)
1009 {
rjw61fcae32022-08-18 14:03:39 +08001010 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001011 }
1012 else
1013 {
1014 sprintf(strtmp[2], "mnc=%s;", mnc);
1015 }
1016 if (apn == NULL)
1017 {
1018 sprintf(strtmp[3], "apn=;");
1019 }
1020 else
1021 {
1022 sprintf(strtmp[3], "apn=%s;", apn);
1023 }
1024 if (apntype == NULL)
1025 {
1026 sprintf(strtmp[4], "apntype=;");
1027 }
1028 else
1029 {
1030 sprintf(strtmp[4], "apntype=%s;", apntype);
1031 }
1032 if (user == NULL)
1033 {
1034 sprintf(strtmp[5], "user=;");
1035 }
1036 else
1037 {
1038 sprintf(strtmp[5], "user=%s;", user);
1039 }
1040 if (password == NULL)
1041 {
1042 sprintf(strtmp[6], "password=;");
1043 }
1044 else
1045 {
1046 sprintf(strtmp[6], "password=%s;", password);
1047 }
1048 if (normalprotocol == NULL)
1049 {
1050 sprintf(strtmp[7], "normalprotocol=;");
1051 }
1052 else
1053 {
1054 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1055 }
1056 if (roamingprotocol == NULL)
1057 {
1058 sprintf(strtmp[8], "roamingprotocol=;");
1059 }
1060 else
1061 {
1062 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1063 }
1064 if (carrier == NULL)
1065 {
1066 sprintf(strtmp[9], "carrier=;");
1067 }
1068 else
1069 {
1070 sprintf(strtmp[9], "carrier=%s;", carrier);
1071 }
rjw61fcae32022-08-18 14:03:39 +08001072 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 +08001073
rjw20006d12022-04-21 16:29:04 +08001074 return 0;
1075}
1076
1077int 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)
1078{
1079 char strtmp[10][32];
1080 if (id == NULL)
1081 {
1082 sprintf(strtmp[0], "id=;");
1083 }
1084 else
1085 {
1086 sprintf(strtmp[0], "id=%s;", id);
1087 }
1088 if (mcc == NULL)
1089 {
1090 sprintf(strtmp[1], "mcc=;");
1091 }
1092 else
1093 {
1094 sprintf(strtmp[1], "mcc=%s;", mcc);
1095 }
1096 if (mnc == NULL)
1097 {
1098 sprintf(strtmp[2], "mnc=;");
1099 }
1100 else
1101 {
1102 sprintf(strtmp[2], "mnc=%s;", mnc);
1103 }
1104 if (apn == NULL)
1105 {
1106 sprintf(strtmp[3], "apn=;");
1107 }
1108 else
1109 {
1110 sprintf(strtmp[3], "apn=%s;", apn);
1111 }
1112 if (apntype == NULL)
1113 {
1114 sprintf(strtmp[4], "apntype=;");
1115 }
1116 else
1117 {
1118 sprintf(strtmp[4], "apntype=%s;", apntype);
1119 }
1120 if (user == NULL)
1121 {
1122 sprintf(strtmp[5], "user=;");
1123 }
1124 else
1125 {
1126 sprintf(strtmp[5], "user=%s;", user);
1127 }
1128 if (password == NULL)
1129 {
1130 sprintf(strtmp[6], "password=;");
1131 }
1132 else
1133 {
1134 sprintf(strtmp[6], "password=%s;", password);
1135 }
1136 if (normalprotocol == NULL)
1137 {
1138 sprintf(strtmp[7], "normalprotocol=;");
1139 }
1140 else
1141 {
1142 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1143 }
1144 if (roamingprotocol == NULL)
1145 {
1146 sprintf(strtmp[8], "roamingprotocol=;");
1147 }
1148 else
1149 {
1150 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1151 }
1152 if (carrier == NULL)
1153 {
1154 sprintf(strtmp[9], "carrier=;");
1155 }
1156 else
1157 {
1158 sprintf(strtmp[9], "carrier=%s;", carrier);
1159 }
1160 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]);
1161 return 0;
1162}
1163
rjwaf4b1612022-06-13 17:26:01 +08001164
1165int 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)
1166{
1167 char strtmp[10][32];
1168 if (id == NULL)
1169 {
1170 sprintf(strtmp[0], "");
1171 }
1172 else
1173 {
1174 sprintf(strtmp[0], "id=%s;", id);
1175 }
1176 if (mcc == NULL)
1177 {
1178 sprintf(strtmp[1], "");
1179 }
1180 else
1181 {
1182 sprintf(strtmp[1], "mcc=%s;", mcc);
1183 }
1184 if (mnc == NULL)
1185 {
1186 sprintf(strtmp[2], "");
1187 }
1188 else
1189 {
1190 sprintf(strtmp[2], "mnc=%s;", mnc);
1191 }
1192 if (apn == NULL)
1193 {
1194 sprintf(strtmp[3], "");
1195 }
1196 else
1197 {
1198 sprintf(strtmp[3], "apn=%s;", apn);
1199 }
1200 if (apntype == NULL)
1201 {
1202 sprintf(strtmp[4], "");
1203 }
1204 else
1205 {
1206 sprintf(strtmp[4], "apntype=%s;", apntype);
1207 }
1208 if (user == NULL)
1209 {
1210 sprintf(strtmp[5], "");
1211 }
1212 else
1213 {
1214 sprintf(strtmp[5], "user=%s;", user);
1215 }
1216 if (password == NULL)
1217 {
1218 sprintf(strtmp[6], "");
1219 }
1220 else
1221 {
1222 sprintf(strtmp[6], "password=%s;", password);
1223 }
1224 if (normalprotocol == NULL)
1225 {
1226 sprintf(strtmp[7], "");
1227 }
1228 else
1229 {
1230 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1231 }
1232 if (roamingprotocol == NULL)
1233 {
1234 sprintf(strtmp[8], "");
1235 }
1236 else
1237 {
1238 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1239 }
1240 if (carrier == NULL)
1241 {
1242 sprintf(strtmp[9], "");
1243 }
1244 else
1245 {
1246 sprintf(strtmp[9], "carrier=%s;", carrier);
1247 }
1248 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]);
1249 return 0;
1250}
1251
rjw20006d12022-04-21 16:29:04 +08001252static char *lynqStrdupReadString(Parcel &p)
1253{
1254 size_t stringlen;
1255 const char16_t *s16;
1256
1257 s16 = p.readString16Inplace(&stringlen);
1258 return strndup16to8(s16, stringlen);
1259}
1260
1261int 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)
1262{
1263 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1264 {
1265 LYERRLOG("There are no valid parameters");
1266 return -1;
1267 }
1268 lynq_client_t client;
1269 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001270 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001271 Parcel p;
1272 if (cmd == 0) // insert apn db
1273 {
rjw61fcae32022-08-18 14:03:39 +08001274 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1275
rjw20006d12022-04-21 16:29:04 +08001276 client.uToken = Global_uToken;
1277 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1278 client.paramLen = 2;
1279 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1280 sprintf(client.param, "%d %s", cmd, argc);
1281 }
rjw61fcae32022-08-18 14:03:39 +08001282 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001283 {
1284 if (NULL == id)
1285 {
1286 LYERRLOG("id is NULL!!!please input id: ");
1287 }
1288 sprintf(argc, "id=%s", id);
1289 client.uToken = Global_uToken;
1290 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1291 client.paramLen = 2;
1292 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1293 sprintf(client.param, "%d %s", cmd, argc);
1294 }
rjw61fcae32022-08-18 14:03:39 +08001295 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001296 {
rjwaf4b1612022-06-13 17:26:01 +08001297 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001298 client.uToken = Global_uToken;
1299 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1300 client.paramLen = 2;
1301 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1302 sprintf(client.param, "%d %s", cmd, argc);
1303 }
rjw61fcae32022-08-18 14:03:39 +08001304 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001305 {
1306 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1307 client.uToken = Global_uToken;
1308 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1309 client.paramLen = 2;
1310 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1311 sprintf(client.param, "%d %s", cmd, argc);
1312 }
1313 else
1314 {
1315 LYERRLOG("incoming command is invalid");
1316 return -1;
1317 }
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();
rjw3bcbbf12022-04-22 16:47:18 +08001327 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001328 LYINFLOG(">>>>>output info:%s",out);
1329 return 0;
1330}
1331
1332int lynq_reset_apn(char *result)
1333{
1334 Parcel p;
1335 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001336 if (NULL == result)
1337 {
1338 LYERRLOG("incoming paramters error");
1339 }
rjw20006d12022-04-21 16:29:04 +08001340 client.uToken = Global_uToken;
1341 client.request = 2000 + 194;
1342 client.paramLen = 0;
1343 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1344 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001345 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001346 if (send_request(lynq_client_sockfd, &client) == -1)
1347 {
1348 LYERRLOG("send request fail");
1349 return -1;
1350 }
rjwed00d042022-05-25 09:18:16 +08001351 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001352 waitApnResult();
1353 strcpy(result, g_lynq_apn_result);
1354 LYINFLOG(">>>>>result:%s",result);
1355 return 0;
1356}
1357
rjw3bcbbf12022-04-22 16:47:18 +08001358/*Typethree add for T800 platform 2022/04/21 end*/