blob: ed8a9c7473f66ad24a49a32ed510c50f85b610a3 [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;
68
rjw7ee7bb42023-01-18 11:34:28 +080069pthread_t data_list_urc_vector_tid = -1;
70int data_urc_vector_status = 0;
71static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
72static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER;
rjwed00d042022-05-25 09:18:16 +080073/**g_lynq_data_sendto_mutex
74* @brief mark data send request mutex
75*/
76static pthread_mutex_t g_lynq_data_sendto_mutex;
77
rjw22947c22022-03-15 09:21:29 +080078/**g_lynq_data_init_flag
79* @brief mark data initialization state
80* 0:deinit status
81* 1:init state
82*/
83static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080084/**g_lynq_apn_result
85* @brief temp of apn result info
86*/
87char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +080088
rjw7ee7bb42023-01-18 11:34:28 +080089static std::vector<int> s_data_urc_wait_list;
90
rjw20006d12022-04-21 16:29:04 +080091typedef struct
92{
lhf81a46f2022-02-13 23:57:37 -080093 char apn[LYNQ_APN_MAX_LEN];
94 char apnType[LYNQ_APN_TYPE_MAX_LEN];
95 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
96 int hasUsed;
97 int hasTimeout;
98}lynq_apn_t;
99lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
100lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
101int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800102
lhf81a46f2022-02-13 23:57:37 -0800103int getLynqApnID(char apnType[])
104{
105 int ret = 0;
106 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
107 {
108 if(strcmp(lynq_apn_table[ret].apnType,apnType)==0)
lh13586612022-01-11 21:58:58 -0800109 {
lhf81a46f2022-02-13 23:57:37 -0800110 return ret;
111 }
112 }
113 return -1;
114}
rjw7ee7bb42023-01-18 11:34:28 +0800115
lhf81a46f2022-02-13 23:57:37 -0800116void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
117{
118 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
119 if(apn_table==NULL)
120 {
121 LYERRLOG("apn_table is null");
122 return;
123 }
124 memcpy(apn_table->apn,apn,strlen(apn)+1);
125 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
126 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
127 apn_table->hasTimeout = 0;
128 apn_table->hasUsed = 1;
129 return;
130}
rjw7ee7bb42023-01-18 11:34:28 +0800131
lhf81a46f2022-02-13 23:57:37 -0800132void cleanOnceApnTable(int apnId)
133{
134 LYDBGLOG("apn id:%d",apnId);
135 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
136 {
137 LYERRLOG("apn id is invalid!!!");
138 return;
139 }
140 lynq_apn_table[apnId].hasTimeout = 0;
141 lynq_apn_table[apnId].hasUsed = 0;
142 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
143 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
144 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
145 return;
146}
147int getUnusedElement()
148{
149 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
150 {
151 if(lynq_apn_table[i].hasUsed!=1)
152 {
153 return i;
154 }
155 }
156 return -1;
157}
158int updateApn(char apnType[])
159{
160 int ret = 0;
161 ret = getUnusedElement();
162 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
163 lynq_apn_table[ret].hasUsed = 1;
164 return ret;
165}
rjw1309e232022-07-22 09:54:06 +0800166
167int handleCheck(int handle)
168{
169 if (lynq_apn_table[handle].hasUsed == 1)
170 {
171 return 0;
172 }
173 else
174 {
175 return -1;
176 }
177}
rjw20006d12022-04-21 16:29:04 +0800178int waitApnResult()
179{
180 int ret = 0;
181 LYINFLOG("start wait apn result!!!");
182 int sec = 0;
183 int usec = 0;
184 struct timeval now;
185 struct timespec timeout;
186 gettimeofday(&now, NULL);
187 sec = 20000 / 1000;
188 usec = 20000 % 1000;
189 timeout.tv_sec = now.tv_sec + sec;
190 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
191 pthread_mutex_lock(&s_lynq_apn_change_mutex);
192 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
193 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
194 return ret;
195}
196
197void sendSignalApnChange()
198{
199 LYINFLOG("start send Signal Apn Change");
200 pthread_mutex_lock(&s_lynq_apn_change_mutex);
201 pthread_cond_signal(&s_lynq_apn_change_cond);
202 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
203 return;
204}
lhf81a46f2022-02-13 23:57:37 -0800205
206int waitPdnChange()
207{
208 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800209 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
210 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
211 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800212 return ret;
213}
214int waitDataCallstateChange(int mtime)
215{
216 int ret = 0;
217 int sec = 0;
218 int usec = 0;
219 struct timeval now;
220 struct timespec timeout;
221 gettimeofday(&now,NULL);
222 sec = mtime/1000;
223 usec = mtime%1000;
224 timeout.tv_sec = now.tv_sec+sec;
225 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
226 pthread_mutex_lock(&s_data_call_state_change_mutex);
227 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
228 pthread_mutex_unlock(&s_data_call_state_change_mutex);
229 return ret;
230}
231void sendSignalDataCallStateChange()
232{
233 pthread_mutex_lock(&s_data_call_state_change_mutex);
234 pthread_cond_signal(&s_data_call_state_change_cond);
235 pthread_mutex_unlock(&s_data_call_state_change_mutex);
236 return;
237}
238void sendSignalPdnChange()
239{
rjw7ee7bb42023-01-18 11:34:28 +0800240 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
241 pthread_cond_signal(&s_lynq_urc_vector_cond);
242 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800243 return;
244}
245
246int get_response(int sockfd,Parcel &p)
247{
248 int len = 0;
249 char recvline[LYNQ_REC_BUF];
250 bzero(recvline,LYNQ_REC_BUF);
251 /* receive data from server */
rjw08528682022-07-04 21:28:02 +0800252 len = read(sockfd, recvline, LYNQ_REC_BUF);
253 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800254 {
rjw747deea2022-07-01 18:25:30 +0800255 LYERRLOG("read error");
lhf81a46f2022-02-13 23:57:37 -0800256 return -1;
257 }
258 if (recvline != NULL) {
259 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
260 p.setDataPosition(0);
261 }
262 return 0;
263}
rjwfa532972022-09-16 13:39:41 +0800264int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
lhf81a46f2022-02-13 23:57:37 -0800265{
266 if(p.dataAvail() > 0)
267 {
268 p.readInt32(resp_type);
269 p.readInt32(request);
270 p.readInt32(slot_id);
271 p.readInt32(error);
272 return 0;
273 }
274 else
275 {
276 return -1;
277 }
278}
279int send_request(int sockfd,lynq_client_t *client_tmp)
280{
281 int ret=0;
282 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
283 if(ret==-1)
284 {
285 perror("write error");
286 return -1;
287 }
288 return 0;
289}
290static char *strdupReadString(Parcel &p) {
291 size_t stringlen;
292 const char16_t *s16;
293 s16 = p.readString16Inplace(&stringlen);
294 return strndup16to8(s16, stringlen);
295}
296static char *strdupReadString_p(Parcel *p) {
297 size_t stringlen;
298 const char16_t *s16;
299 s16 = p->readString16Inplace(&stringlen);
300 return strndup16to8(s16, stringlen);
301}
302
lhf81a46f2022-02-13 23:57:37 -0800303/*Warren add for T800 platform 2021/11/19 start*/
304int lynq_socket_client_start()
305{
rjw08528682022-07-04 21:28:02 +0800306 struct sockaddr_in lynq_data_socket_server_addr;
lhf81a46f2022-02-13 23:57:37 -0800307 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800308 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
309 lynq_data_socket_server_addr.sin_family = AF_INET;
310 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
jb.qid5852372023-03-29 10:29:12 +0800311 lynq_data_socket_server_addr.sin_addr.s_addr = inet_addr(LYNQ_ADDRESS);
lhf81a46f2022-02-13 23:57:37 -0800312 /*
313 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
314 {
315 printf("[%s] is not a valid IPaddress\n", argv[1]);
316 exit(1);
317 }
318*/
319 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800320 struct timeval timeOut;
321
rjwa59bf312022-07-05 11:50:31 +0800322 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800323 timeOut.tv_usec = 0;
324
325 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
326 {
327 LYERRLOG("time out setting failed");
328 }
329 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 -0800330 {
331 perror("connect error");
332 return -1;
333 }
334 return 0;
335}
rjw7ee7bb42023-01-18 11:34:28 +0800336
337bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800338{
rjw7ee7bb42023-01-18 11:34:28 +0800339 switch(urc_id)
340 {
341 case LYNQ_URC_DATA_CALL_STATUS_IND:
342
343 case LYNQ_URC_MODIFY_APNDB:
344 case LYNQ_URC_RESET_APNDB:
345 return true;
346 default:
347 return false;
348 }
349}
350
351void urc_msg_process(Parcel *p)
352{
353 int len;
354 int resp_type;
355 int urcid;
356 int slot_id;
357
358 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800359 char apn[LYNQ_APN_MAX_LEN];
360 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800361 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800362 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800363
364 int size = p->dataSize();
365 p->readInt32(&resp_type);
366 p->readInt32(&urcid);
367 p->readInt32(&slot_id);
368 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
369 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800370 {
rjw7ee7bb42023-01-18 11:34:28 +0800371 case LYNQ_URC_DATA_CALL_STATUS_IND:
372 p->readInt32(&pdnState);
373 bzero(apn,LYNQ_APN_MAX_LEN);
374 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
375 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
376 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800377 {
rjw20006d12022-04-21 16:29:04 +0800378 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800379 int len = strlen(urc_msg);
380 if(len < LYNQ_APN_MAX_LEN-1)
rjw20006d12022-04-21 16:29:04 +0800381 {
rjw7ee7bb42023-01-18 11:34:28 +0800382 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800383 }
rjw7ee7bb42023-01-18 11:34:28 +0800384 urc_msg = strdupReadString_p(p);
385 len = strlen(urc_msg);
386 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
387 {
388 memcpy(apnType,urc_msg,len+1);
389 }
390 urc_msg = strdupReadString_p(p);
391 len = strlen(urc_msg);
392 if(len < LYNQ_IFACE_NAME_MAX_LEN-1)
393 {
394 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
395 }
396 //sendSignalDataCallStateChange();
397 int apnId = getLynqApnID(apnType);
398 if(apnId >= 0)
399 {
400 if(lynq_apn_table[apnId].hasTimeout==1)
401 {
402 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800403 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 +0800404 {
405 LYERRLOG("deactive this time out APN");
406 lynq_deactive_data_call(&apnId);
407 }
408 else
409 {
410 LYERRLOG("this table is invalid");
411 }
412 break;
413 }
rjwacdb2152023-02-07 14:12:49 +0800414 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
rjw7ee7bb42023-01-18 11:34:28 +0800415 }
416 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800417 else
418 {
rjw7ee7bb42023-01-18 11:34:28 +0800419 LYERRLOG("invalid apnId");
420 break;
rjw20006d12022-04-21 16:29:04 +0800421 }
rjw7ee7bb42023-01-18 11:34:28 +0800422 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
423 s_data_urc_wait_list.push_back(apnId);
424 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
425 lynq_data_call_change_id = apnId;
426 //sendSignalPdnChange();
427 LYDBGLOG("data call state:%d",lynq_data_call);
428 if(lynq_data_call==1)
429 {
430 sendSignalDataCallStateChange();
431 lynq_data_call = 0;
432 }
rjw20006d12022-04-21 16:29:04 +0800433 }
rjw7ee7bb42023-01-18 11:34:28 +0800434 else
rjw20006d12022-04-21 16:29:04 +0800435 {
rjw7ee7bb42023-01-18 11:34:28 +0800436 urc_msg = strdupReadString_p(p);
437 len = strlen(urc_msg);
438 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
439 {
440 memcpy(apnType,urc_msg,len+1);
441 }
442 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
443 int apnId = getLynqApnID(apnType);
444 if(apnId >= 0)
445 {
446 lynq_data_call_change_id = apnId;
447 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800448 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
449 s_data_urc_wait_list.push_back(apnId);
450 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
rjw7ee7bb42023-01-18 11:34:28 +0800451 }
rjw7ee7bb42023-01-18 11:34:28 +0800452 //sendSignalPdnChange();
453 LYDBGLOG("data call state:%d",lynq_data_call);
454 if(lynq_data_call==1)
455 {
456 sendSignalDataCallStateChange();
457 lynq_data_call = 0;
458 }
459 }
460 break;
461 case LYNQ_URC_MODIFY_APNDB:
462 urc_msg = strdupReadString_p(p);
463 if (NULL == urc_msg)
464 {
465 LYERRLOG("error apn msg");
466 }
467 else
468 {
469 bzero(g_lynq_apn_result, 1024);
470 strcpy(g_lynq_apn_result, urc_msg);
471 sendSignalApnChange();
472 }
473 break;
474 case LYNQ_URC_RESET_APNDB:
475 {
rjw20006d12022-04-21 16:29:04 +0800476 urc_msg = strdupReadString_p(p);
477 if (NULL == urc_msg)
478 {
479 LYERRLOG("error apn msg");
480 }
481 else
482 {
483 bzero(g_lynq_apn_result, 1024);
484 strcpy(g_lynq_apn_result, urc_msg);
485 sendSignalApnChange();
486 }
487 }
rjw7ee7bb42023-01-18 11:34:28 +0800488 default:
489 break;
lhf81a46f2022-02-13 23:57:37 -0800490 }
rjw7ee7bb42023-01-18 11:34:28 +0800491
lhf81a46f2022-02-13 23:57:37 -0800492}
rjw7ee7bb42023-01-18 11:34:28 +0800493
494void cleanup_urc_vector_mutex(void *arg)
lhf81a46f2022-02-13 23:57:37 -0800495{
rjw7ee7bb42023-01-18 11:34:28 +0800496 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
497}
498
499void *thread_urc_vector()
500{
501 pthread_cleanup_push(cleanup_urc_vector_mutex, NULL);
502 while (data_urc_vector_status)
lh13586612022-01-11 21:58:58 -0800503 {
rjw7ee7bb42023-01-18 11:34:28 +0800504 while (!s_data_urc_wait_list.empty())
505 {
506 sendSignalPdnChange();
507 usleep(10);
508 }
rjw430a59e2023-02-09 16:01:25 +0800509 usleep(1);
rjw7ee7bb42023-01-18 11:34:28 +0800510 }
511 pthread_cleanup_pop(0);
512}
513
514void cancel_urc_vector_signal_thread()
515{
516 int ret;
rjw430a59e2023-02-09 16:01:25 +0800517
518 data_urc_vector_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800519 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
520 if (data_list_urc_vector_tid != -1)
521 {
522 ret = pthread_cancel(data_list_urc_vector_tid);
523 LYDBGLOG("pthread cancel ret = %d",ret);
524 }
525 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
526
527 if (data_list_urc_vector_tid != -1)
528 {
529 ret = pthread_join(data_list_urc_vector_tid,NULL);
530 LYDBGLOG("pthread join ret = %d",ret);
531 data_list_urc_vector_tid = -1;
532 }
533 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
534 s_data_urc_wait_list.clear();
535 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
rjw7ee7bb42023-01-18 11:34:28 +0800536}
537
538int create_urc_vector_signal_thread()
539{
540 int ret;
541
542 data_urc_vector_status = 1;
543 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
544 ret = pthread_create(&data_list_urc_vector_tid,NULL,thread_urc_vector,NULL);
545 if (ret < 0)
546 {
547 LYERRLOG("urc vector signal pthread create error");
548 lynq_deinit_data_urc_thread();
549 data_urc_vector_status = 0;
lh13586612022-01-11 21:58:58 -0800550 return -1;
lhf81a46f2022-02-13 23:57:37 -0800551 }
rjw7ee7bb42023-01-18 11:34:28 +0800552 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
553 s_data_urc_wait_list.clear();
554 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800555 return 0;
556}
rjw7ee7bb42023-01-18 11:34:28 +0800557
lhf81a46f2022-02-13 23:57:37 -0800558int lynq_init_data(int uToken)
559{
rjw22947c22022-03-15 09:21:29 +0800560 if (g_lynq_data_init_flag == 1)
561 {
562 LYERRLOG("init twice is not allowed");
563 return -1;
564 }
565 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800566 int result = 0;
567 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800568 LYLOGSET(LOG_INFO);
569 LYLOGEINIT(USER_LOG_TAG);
570 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800571 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800572 if(result!=0)
573 {
574 LYERRLOG("init socket client fail!!!");
575 return -1;
576 }
rjw7ee7bb42023-01-18 11:34:28 +0800577 result = lynq_init_data_urc_thread();
578 if(result!=0)
579 {
580 LYERRLOG("init socket urc fail!!!");
581 return -1;
582 }
583
584 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800585 if(result!=0)
586 {
587 LYERRLOG("init socket urc fail!!!");
588 return -1;
589 }
590 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
591 LYDBGLOG("lynq init call success!!!");
592 return 0;
593
594}
595int lynq_deinit_data()
596{
597 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800598 if (g_lynq_data_init_flag == 0)
599 {
600 LYERRLOG("deinit twice is not allowed");
601 return ret;
602 }
603 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800604 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
605 {
606 if(strlen(lynq_apn_table[i].apnType)!=0)
607 {
608 lynq_deactive_data_call(&i);
609 }
610 }
611 if(lynq_client_sockfd>0)
612 {
613 close(lynq_client_sockfd);
614 }
rjw7ee7bb42023-01-18 11:34:28 +0800615 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800616 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800617 {
rjw7ee7bb42023-01-18 11:34:28 +0800618 LYERRLOG("lynq_deinit_data_urc_thread fail");
619 return ret;
rjw22947c22022-03-15 09:21:29 +0800620 }
rjw7ee7bb42023-01-18 11:34:28 +0800621 cancel_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800622 return 0;
623}
624int lynq_setup_data_call(int *handle)
625{
626 Parcel p;
627 lynq_client_t client;
628 int resp_type = -1;
629 int request = -1;
630 int slot_id = -1;
631 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800632 int lynq_data_call_id = 0;
633 if(handle==NULL)
634 {
635 LYERRLOG("handle is null!!!");
636 return LYNQ_E_NULL_ANONALY;
637 }
638 client.uToken = Global_uToken;
639 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
640 client.paramLen = 0;
641 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
642 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800643 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800644 if(send_request(lynq_client_sockfd,&client)==-1)
645 {
646 LYERRLOG("send request fail");
647 perror("[LYNQ_DATA] send request fail:");
648 return -1;
649 }
650 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800651 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800652 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800653 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
654 lynq_data_call_id = updateApn("default");
655 lynq_data_call = 1;
656 if(error==0)
657 {
rjw20006d12022-04-21 16:29:04 +0800658 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800659 {
660 error = LYNQ_E_TIME_OUT;
661 LYERRLOG("timeout:wait data Call state fail!!!");
662 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
663 return error;
664 }
665 *handle = lynq_data_call_id;
666 }
667 return error;
668}
rjw7ee7bb42023-01-18 11:34:28 +0800669
lhf81a46f2022-02-13 23:57:37 -0800670int lynq_deactive_data_call(int *handle)
671{
672 Parcel p;
673 lynq_client_t client;
674 int resp_type = -1;
675 int request = -1;
676 int slot_id = -1;
677 int error = -1;
678 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800679 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800680 if(handle==NULL)
681 {
682 LYERRLOG("handle is null!!!");
683 return -1;
684 }
rjw1309e232022-07-22 09:54:06 +0800685 ret = handleCheck(*handle);
686 if (ret != 0)
687 {
688 LYERRLOG("incomming handle is invalid");
689 return -1;
690 }
691 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800692 client.uToken = Global_uToken;
693 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
694 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
695 {
696 client.paramLen = 0;
697 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800698 }
699 else
700 {
lhf81a46f2022-02-13 23:57:37 -0800701 client.paramLen = 1;
702 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
703 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
704 }
705 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800706 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800707 if(send_request(lynq_client_sockfd,&client)==-1)
708 {
709 LYERRLOG("send request fail");
710 perror("[LYNQ_DATA] send request fail:");
711 return -1;
712 }
713 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800714 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800715 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800716 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
717 cleanOnceApnTable(lynq_data_call_id);
718 return error;
719}
720int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
721{
722 Parcel p;
723 lynq_client_t client;
724 int resp_type = -1;
725 int request = -1;
726 int slot_id = -1;
727 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800728 int lynq_data_call_id = -1;
729 char *argv[10] = {};
730 if(handle==NULL||apn==NULL||apnType==NULL)
731 {
732 LYERRLOG("handle ,apn or apntype is null!!!");
733 return -1;
734 }
735 if(user==NULL)
736 {
737 argv[1] = "null";
738 }
739 else
740 {
741 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800742 }
743 if(password==NULL)
744 {
lhf81a46f2022-02-13 23:57:37 -0800745 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800746 }
747 else
748 {
lhf81a46f2022-02-13 23:57:37 -0800749 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800750 }
751 if(authType==NULL)
752 {
lhf81a46f2022-02-13 23:57:37 -0800753 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800754 }
755 else
756 {
lhf81a46f2022-02-13 23:57:37 -0800757 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800758 }
759 if(normalProtocol==NULL)
760 {
lhf81a46f2022-02-13 23:57:37 -0800761 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800762 }
763 else
764 {
lhf81a46f2022-02-13 23:57:37 -0800765 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800766 }
767 if(roamingProtocol==NULL)
768 {
lhf81a46f2022-02-13 23:57:37 -0800769 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800770 }
771 else
772 {
lhf81a46f2022-02-13 23:57:37 -0800773 argv[5] = roamingProtocol;
774 }
775 client.uToken = Global_uToken;
776 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
777 client.paramLen = 7;
778 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
779 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
780 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800781 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800782 if(send_request(lynq_client_sockfd,&client)==-1)
783 {
784 LYERRLOG("send request fail");
785 perror("[LYNQ_DATA] send request fail:");
786 return -1;
787 }
788 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800789 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800790 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800791 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
792 lynq_data_call_id = updateApn(apnType);
793 lynq_data_call = 1;
794 if(error==0)
795 {
rjw7ee7bb42023-01-18 11:34:28 +0800796 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800797 {
798 error = LYNQ_E_TIME_OUT;
799 LYERRLOG("timeout:wait data Call state fail!!!");
800 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
801 return error;
802 }
803 *handle = lynq_data_call_id;
804 }
805 return error;
806}
807/*
808int lynq_deactive_data_call_sp(int *handle,char *apnType)
809{
810 Parcel p;
811 lynq_client_t client;
812 int resp_type = -1;
813 int request = -1;
814 int slot_id = -1;
815 int error = -1;
816 if(handle==NULL||apnType==NULL)
817 {
818 LYERRLOG("handle is null!!!");
819 return -1;
820 }
821 client.uToken = Global_uToken;
822 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
823 client.paramLen = 1;
824 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
825 sprintf(client.param,"%s",apnType);
826 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
827 if(send_request(lynq_client_sockfd,&client)==-1)
828 {
829 LYERRLOG("send request fail");
830 perror("[LYNQ_DATA] send request fail:");
831 return -1;
832 }
833 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800834 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800835 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
836 return error;
837}
838*/
839int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
840{
841 Parcel p;
842 lynq_client_t client;
843 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800844 int token;
845 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800846 int slot_id = -1;
847 int error = -1;
848 int version =0;
849 int num = 0;
lhf81a46f2022-02-13 23:57:37 -0800850 char *temp_char = NULL;
851 if(dataCallList==NULL)
852 {
853 LYERRLOG("dataCallList is null!!!");
854 return -1;
855 }
856 client.uToken = Global_uToken;
857 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
858 client.paramLen = 0;
859 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
860 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800861 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800862 if(send_request(lynq_client_sockfd,&client)==-1)
863 {
864 LYERRLOG("send request fail");
865 perror("[LYNQ_DATA] send request fail:");
866 return -1;
867 }
868 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800869 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800870 if(p.dataAvail() > 0)
871 {
rjw0fb4ccb2022-09-16 19:12:35 +0800872 p.readInt32(&resp_type);
873 p.readInt32(&token);
874 p.readInt32(&request);
875 p.readInt32(&slot_id);
876 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +0800877 }
878 else
879 {
880 return -1;
881 }
lhf81a46f2022-02-13 23:57:37 -0800882 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
883 p.readInt32(&version);
884 if(version==11)
885 {
886 p.readInt32(&num);
887 *realNum = num;
888 for (int i = 0; i < num; i++)
889 {
890 p.readInt32(&dataCallList[i].status);
891 p.readInt32(&dataCallList[i].suggestedRetryTime);
892 p.readInt32(&dataCallList[i].cid);
893 p.readInt32(&dataCallList[i].active);
894 temp_char = strdupReadString(p);
895 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
896 temp_char = strdupReadString(p);
897 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
898 temp_char = strdupReadString(p);
899 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
900 temp_char = strdupReadString(p);
901 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
902 temp_char = strdupReadString(p);
903 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
904 temp_char = strdupReadString(p);
905 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
906 p.readInt32(&dataCallList[i].mtu);
907 }
908 }
909 return error;
910}
911int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
912{
913 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
914 int number = 0;
915 int lynq_data_call_id = 0;
916 int error = 0;
917 lynq_data_call_id = *handle;
918 if(handle==NULL)
919 {
920 LYERRLOG("handle is NULL");
921 return LYNQ_E_NULL_ANONALY;
922 }
rjw3938f262023-03-08 16:09:28 +0800923 if (*handle<0 && handle>8)
924 {
925 LYERRLOG("handle value error");
926 }
927 LYINFLOG("incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800928 memset(interDataCallList,0,sizeof(interDataCallList));
929 error = getDataCallLists(interDataCallList,&number);
930 if(error == 0)
931 {
932 for(int i = 0;i < number;i++)
933 {
934 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
935 {
936 dataCallList->active = interDataCallList[i].active;
937 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
938 dataCallList->cid = interDataCallList[i].cid;
939 dataCallList->status = interDataCallList[i].status;
940 dataCallList->mtu = interDataCallList[i].mtu;
941 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
942 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
943 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
944 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
945 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
946 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
947 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
948 }
949 }
950 }
951 return error;
952}
953int lynq_wait_data_call_state_change(int *handle)
954{
rjw7ee7bb42023-01-18 11:34:28 +0800955
956 std::vector<int>::iterator iter;
lhf81a46f2022-02-13 23:57:37 -0800957 waitPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800958
959 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
960 iter = s_data_urc_wait_list.begin();
rjw3938f262023-03-08 16:09:28 +0800961 *handle = s_data_urc_wait_list.front();
962
rjw7ee7bb42023-01-18 11:34:28 +0800963 s_data_urc_wait_list.erase(iter);
964 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
965
rjw3938f262023-03-08 16:09:28 +0800966 LYINFLOG("lynq data call id:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800967 return 0;
968}
969/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +0800970
971/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +0800972
973int 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 +0800974{
975 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +0800976 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +0800977 {
rjw61fcae32022-08-18 14:03:39 +0800978 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +0800979 }
rjw61fcae32022-08-18 14:03:39 +0800980 else
rjw0cdacbc2022-06-22 10:51:07 +0800981 {
rjw61fcae32022-08-18 14:03:39 +0800982 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +0800983 }
rjw20006d12022-04-21 16:29:04 +0800984 if (mcc == NULL)
985 {
986 sprintf(strtmp[1], "mcc=;");
987 }
988 else
989 {
990 sprintf(strtmp[1], "mcc=%s;", mcc);
991 }
992 if (mnc == NULL)
993 {
rjw61fcae32022-08-18 14:03:39 +0800994 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +0800995 }
996 else
997 {
998 sprintf(strtmp[2], "mnc=%s;", mnc);
999 }
1000 if (apn == NULL)
1001 {
1002 sprintf(strtmp[3], "apn=;");
1003 }
1004 else
1005 {
1006 sprintf(strtmp[3], "apn=%s;", apn);
1007 }
1008 if (apntype == NULL)
1009 {
1010 sprintf(strtmp[4], "apntype=;");
1011 }
1012 else
1013 {
1014 sprintf(strtmp[4], "apntype=%s;", apntype);
1015 }
1016 if (user == NULL)
1017 {
1018 sprintf(strtmp[5], "user=;");
1019 }
1020 else
1021 {
1022 sprintf(strtmp[5], "user=%s;", user);
1023 }
1024 if (password == NULL)
1025 {
1026 sprintf(strtmp[6], "password=;");
1027 }
1028 else
1029 {
1030 sprintf(strtmp[6], "password=%s;", password);
1031 }
1032 if (normalprotocol == NULL)
1033 {
1034 sprintf(strtmp[7], "normalprotocol=;");
1035 }
1036 else
1037 {
1038 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1039 }
1040 if (roamingprotocol == NULL)
1041 {
1042 sprintf(strtmp[8], "roamingprotocol=;");
1043 }
1044 else
1045 {
1046 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1047 }
1048 if (carrier == NULL)
1049 {
1050 sprintf(strtmp[9], "carrier=;");
1051 }
1052 else
1053 {
1054 sprintf(strtmp[9], "carrier=%s;", carrier);
1055 }
rjw61fcae32022-08-18 14:03:39 +08001056 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 +08001057
rjw20006d12022-04-21 16:29:04 +08001058 return 0;
1059}
1060
1061int 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)
1062{
1063 char strtmp[10][32];
1064 if (id == NULL)
1065 {
1066 sprintf(strtmp[0], "id=;");
1067 }
1068 else
1069 {
1070 sprintf(strtmp[0], "id=%s;", id);
1071 }
1072 if (mcc == NULL)
1073 {
1074 sprintf(strtmp[1], "mcc=;");
1075 }
1076 else
1077 {
1078 sprintf(strtmp[1], "mcc=%s;", mcc);
1079 }
1080 if (mnc == NULL)
1081 {
1082 sprintf(strtmp[2], "mnc=;");
1083 }
1084 else
1085 {
1086 sprintf(strtmp[2], "mnc=%s;", mnc);
1087 }
1088 if (apn == NULL)
1089 {
1090 sprintf(strtmp[3], "apn=;");
1091 }
1092 else
1093 {
1094 sprintf(strtmp[3], "apn=%s;", apn);
1095 }
1096 if (apntype == NULL)
1097 {
1098 sprintf(strtmp[4], "apntype=;");
1099 }
1100 else
1101 {
1102 sprintf(strtmp[4], "apntype=%s;", apntype);
1103 }
1104 if (user == NULL)
1105 {
1106 sprintf(strtmp[5], "user=;");
1107 }
1108 else
1109 {
1110 sprintf(strtmp[5], "user=%s;", user);
1111 }
1112 if (password == NULL)
1113 {
1114 sprintf(strtmp[6], "password=;");
1115 }
1116 else
1117 {
1118 sprintf(strtmp[6], "password=%s;", password);
1119 }
1120 if (normalprotocol == NULL)
1121 {
1122 sprintf(strtmp[7], "normalprotocol=;");
1123 }
1124 else
1125 {
1126 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1127 }
1128 if (roamingprotocol == NULL)
1129 {
1130 sprintf(strtmp[8], "roamingprotocol=;");
1131 }
1132 else
1133 {
1134 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1135 }
1136 if (carrier == NULL)
1137 {
1138 sprintf(strtmp[9], "carrier=;");
1139 }
1140 else
1141 {
1142 sprintf(strtmp[9], "carrier=%s;", carrier);
1143 }
1144 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]);
1145 return 0;
1146}
1147
rjwaf4b1612022-06-13 17:26:01 +08001148
1149int 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)
1150{
1151 char strtmp[10][32];
1152 if (id == NULL)
1153 {
1154 sprintf(strtmp[0], "");
1155 }
1156 else
1157 {
1158 sprintf(strtmp[0], "id=%s;", id);
1159 }
1160 if (mcc == NULL)
1161 {
1162 sprintf(strtmp[1], "");
1163 }
1164 else
1165 {
1166 sprintf(strtmp[1], "mcc=%s;", mcc);
1167 }
1168 if (mnc == NULL)
1169 {
1170 sprintf(strtmp[2], "");
1171 }
1172 else
1173 {
1174 sprintf(strtmp[2], "mnc=%s;", mnc);
1175 }
1176 if (apn == NULL)
1177 {
1178 sprintf(strtmp[3], "");
1179 }
1180 else
1181 {
1182 sprintf(strtmp[3], "apn=%s;", apn);
1183 }
1184 if (apntype == NULL)
1185 {
1186 sprintf(strtmp[4], "");
1187 }
1188 else
1189 {
1190 sprintf(strtmp[4], "apntype=%s;", apntype);
1191 }
1192 if (user == NULL)
1193 {
1194 sprintf(strtmp[5], "");
1195 }
1196 else
1197 {
1198 sprintf(strtmp[5], "user=%s;", user);
1199 }
1200 if (password == NULL)
1201 {
1202 sprintf(strtmp[6], "");
1203 }
1204 else
1205 {
1206 sprintf(strtmp[6], "password=%s;", password);
1207 }
1208 if (normalprotocol == NULL)
1209 {
1210 sprintf(strtmp[7], "");
1211 }
1212 else
1213 {
1214 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1215 }
1216 if (roamingprotocol == NULL)
1217 {
1218 sprintf(strtmp[8], "");
1219 }
1220 else
1221 {
1222 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1223 }
1224 if (carrier == NULL)
1225 {
1226 sprintf(strtmp[9], "");
1227 }
1228 else
1229 {
1230 sprintf(strtmp[9], "carrier=%s;", carrier);
1231 }
1232 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]);
1233 return 0;
1234}
1235
rjw20006d12022-04-21 16:29:04 +08001236static char *lynqStrdupReadString(Parcel &p)
1237{
1238 size_t stringlen;
1239 const char16_t *s16;
1240
1241 s16 = p.readString16Inplace(&stringlen);
1242 return strndup16to8(s16, stringlen);
1243}
1244
1245int 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)
1246{
1247 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1248 {
1249 LYERRLOG("There are no valid parameters");
1250 return -1;
1251 }
1252 lynq_client_t client;
1253 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001254 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001255 Parcel p;
1256 if (cmd == 0) // insert apn db
1257 {
rjw61fcae32022-08-18 14:03:39 +08001258 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1259
rjw20006d12022-04-21 16:29:04 +08001260 client.uToken = Global_uToken;
1261 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1262 client.paramLen = 2;
1263 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1264 sprintf(client.param, "%d %s", cmd, argc);
1265 }
rjw61fcae32022-08-18 14:03:39 +08001266 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001267 {
1268 if (NULL == id)
1269 {
1270 LYERRLOG("id is NULL!!!please input id: ");
1271 }
1272 sprintf(argc, "id=%s", id);
1273 client.uToken = Global_uToken;
1274 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1275 client.paramLen = 2;
1276 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1277 sprintf(client.param, "%d %s", cmd, argc);
1278 }
rjw61fcae32022-08-18 14:03:39 +08001279 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001280 {
rjwaf4b1612022-06-13 17:26:01 +08001281 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001282 client.uToken = Global_uToken;
1283 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1284 client.paramLen = 2;
1285 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1286 sprintf(client.param, "%d %s", cmd, argc);
1287 }
rjw61fcae32022-08-18 14:03:39 +08001288 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001289 {
1290 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1291 client.uToken = Global_uToken;
1292 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1293 client.paramLen = 2;
1294 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1295 sprintf(client.param, "%d %s", cmd, argc);
1296 }
1297 else
1298 {
1299 LYERRLOG("incoming command is invalid");
1300 return -1;
1301 }
1302 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001303 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001304 if(send_request(lynq_client_sockfd,&client)==-1)
1305 {
1306 LYERRLOG("send request fail");
1307 return -1;
1308 }
rjwed00d042022-05-25 09:18:16 +08001309 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001310 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001311 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001312 LYINFLOG(">>>>>output info:%s",out);
1313 return 0;
1314}
1315
1316int lynq_reset_apn(char *result)
1317{
1318 Parcel p;
1319 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001320 if (NULL == result)
1321 {
1322 LYERRLOG("incoming paramters error");
1323 }
rjw20006d12022-04-21 16:29:04 +08001324 client.uToken = Global_uToken;
1325 client.request = 2000 + 194;
1326 client.paramLen = 0;
1327 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1328 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001329 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001330 if (send_request(lynq_client_sockfd, &client) == -1)
1331 {
1332 LYERRLOG("send request fail");
1333 return -1;
1334 }
rjwed00d042022-05-25 09:18:16 +08001335 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001336 waitApnResult();
1337 strcpy(result, g_lynq_apn_result);
1338 LYINFLOG(">>>>>result:%s",result);
1339 return 0;
1340}
1341
rjw3bcbbf12022-04-22 16:47:18 +08001342/*Typethree add for T800 platform 2022/04/21 end*/