blob: 710a16e852c66b915326cba27d151eb04c75f25b [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);
rjw3938f262023-03-08 16:09:28 +0800401 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 +0800402 {
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 }
rjwacdb2152023-02-07 14:12:49 +0800412 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
rjw7ee7bb42023-01-18 11:34:28 +0800413 }
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
rjw3938f262023-03-08 16:09:28 +0800446 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
447 s_data_urc_wait_list.push_back(apnId);
448 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
rjw7ee7bb42023-01-18 11:34:28 +0800449 }
rjw7ee7bb42023-01-18 11:34:28 +0800450 //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 }
rjw430a59e2023-02-09 16:01:25 +0800507 usleep(1);
rjw7ee7bb42023-01-18 11:34:28 +0800508 }
509 pthread_cleanup_pop(0);
510}
511
512void cancel_urc_vector_signal_thread()
513{
514 int ret;
rjw430a59e2023-02-09 16:01:25 +0800515
516 data_urc_vector_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800517 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
518 if (data_list_urc_vector_tid != -1)
519 {
520 ret = pthread_cancel(data_list_urc_vector_tid);
521 LYDBGLOG("pthread cancel ret = %d",ret);
522 }
523 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
524
525 if (data_list_urc_vector_tid != -1)
526 {
527 ret = pthread_join(data_list_urc_vector_tid,NULL);
528 LYDBGLOG("pthread join ret = %d",ret);
529 data_list_urc_vector_tid = -1;
530 }
531 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
532 s_data_urc_wait_list.clear();
533 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
rjw7ee7bb42023-01-18 11:34:28 +0800534}
535
536int create_urc_vector_signal_thread()
537{
538 int ret;
539
540 data_urc_vector_status = 1;
541 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
542 ret = pthread_create(&data_list_urc_vector_tid,NULL,thread_urc_vector,NULL);
543 if (ret < 0)
544 {
545 LYERRLOG("urc vector signal pthread create error");
546 lynq_deinit_data_urc_thread();
547 data_urc_vector_status = 0;
lh13586612022-01-11 21:58:58 -0800548 return -1;
lhf81a46f2022-02-13 23:57:37 -0800549 }
rjw7ee7bb42023-01-18 11:34:28 +0800550 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
551 s_data_urc_wait_list.clear();
552 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800553 return 0;
554}
rjw7ee7bb42023-01-18 11:34:28 +0800555
lhf81a46f2022-02-13 23:57:37 -0800556int lynq_init_data(int uToken)
557{
rjw22947c22022-03-15 09:21:29 +0800558 if (g_lynq_data_init_flag == 1)
559 {
560 LYERRLOG("init twice is not allowed");
561 return -1;
562 }
563 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800564 int result = 0;
565 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800566 LYLOGSET(LOG_INFO);
567 LYLOGEINIT(USER_LOG_TAG);
568 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800569 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800570 if(result!=0)
571 {
572 LYERRLOG("init socket client fail!!!");
573 return -1;
574 }
rjw7ee7bb42023-01-18 11:34:28 +0800575 result = lynq_init_data_urc_thread();
576 if(result!=0)
577 {
578 LYERRLOG("init socket urc fail!!!");
579 return -1;
580 }
581
582 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800583 if(result!=0)
584 {
585 LYERRLOG("init socket urc fail!!!");
586 return -1;
587 }
588 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
589 LYDBGLOG("lynq init call success!!!");
590 return 0;
591
592}
593int lynq_deinit_data()
594{
595 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800596 if (g_lynq_data_init_flag == 0)
597 {
598 LYERRLOG("deinit twice is not allowed");
599 return ret;
600 }
601 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800602 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
603 {
604 if(strlen(lynq_apn_table[i].apnType)!=0)
605 {
606 lynq_deactive_data_call(&i);
607 }
608 }
609 if(lynq_client_sockfd>0)
610 {
611 close(lynq_client_sockfd);
612 }
rjw7ee7bb42023-01-18 11:34:28 +0800613 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800614 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800615 {
rjw7ee7bb42023-01-18 11:34:28 +0800616 LYERRLOG("lynq_deinit_data_urc_thread fail");
617 return ret;
rjw22947c22022-03-15 09:21:29 +0800618 }
rjw7ee7bb42023-01-18 11:34:28 +0800619 cancel_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800620 return 0;
621}
622int lynq_setup_data_call(int *handle)
623{
624 Parcel p;
625 lynq_client_t client;
626 int resp_type = -1;
627 int request = -1;
628 int slot_id = -1;
629 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800630 int lynq_data_call_id = 0;
631 if(handle==NULL)
632 {
633 LYERRLOG("handle is null!!!");
634 return LYNQ_E_NULL_ANONALY;
635 }
636 client.uToken = Global_uToken;
637 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
638 client.paramLen = 0;
639 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
640 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800641 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800642 if(send_request(lynq_client_sockfd,&client)==-1)
643 {
644 LYERRLOG("send request fail");
645 perror("[LYNQ_DATA] send request fail:");
646 return -1;
647 }
648 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800649 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800650 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800651 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
652 lynq_data_call_id = updateApn("default");
653 lynq_data_call = 1;
654 if(error==0)
655 {
rjw20006d12022-04-21 16:29:04 +0800656 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800657 {
658 error = LYNQ_E_TIME_OUT;
659 LYERRLOG("timeout:wait data Call state fail!!!");
660 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
661 return error;
662 }
663 *handle = lynq_data_call_id;
664 }
665 return error;
666}
rjw7ee7bb42023-01-18 11:34:28 +0800667
lhf81a46f2022-02-13 23:57:37 -0800668int lynq_deactive_data_call(int *handle)
669{
670 Parcel p;
671 lynq_client_t client;
672 int resp_type = -1;
673 int request = -1;
674 int slot_id = -1;
675 int error = -1;
676 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800677 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800678 if(handle==NULL)
679 {
680 LYERRLOG("handle is null!!!");
681 return -1;
682 }
rjw1309e232022-07-22 09:54:06 +0800683 ret = handleCheck(*handle);
684 if (ret != 0)
685 {
686 LYERRLOG("incomming handle is invalid");
687 return -1;
688 }
689 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800690 client.uToken = Global_uToken;
691 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
692 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
693 {
694 client.paramLen = 0;
695 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800696 }
697 else
698 {
lhf81a46f2022-02-13 23:57:37 -0800699 client.paramLen = 1;
700 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
701 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
702 }
703 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800704 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800705 if(send_request(lynq_client_sockfd,&client)==-1)
706 {
707 LYERRLOG("send request fail");
708 perror("[LYNQ_DATA] send request fail:");
709 return -1;
710 }
711 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800712 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800713 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800714 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
715 cleanOnceApnTable(lynq_data_call_id);
716 return error;
717}
718int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
719{
720 Parcel p;
721 lynq_client_t client;
722 int resp_type = -1;
723 int request = -1;
724 int slot_id = -1;
725 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800726 int lynq_data_call_id = -1;
727 char *argv[10] = {};
728 if(handle==NULL||apn==NULL||apnType==NULL)
729 {
730 LYERRLOG("handle ,apn or apntype is null!!!");
731 return -1;
732 }
733 if(user==NULL)
734 {
735 argv[1] = "null";
736 }
737 else
738 {
739 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800740 }
741 if(password==NULL)
742 {
lhf81a46f2022-02-13 23:57:37 -0800743 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800744 }
745 else
746 {
lhf81a46f2022-02-13 23:57:37 -0800747 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800748 }
749 if(authType==NULL)
750 {
lhf81a46f2022-02-13 23:57:37 -0800751 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800752 }
753 else
754 {
lhf81a46f2022-02-13 23:57:37 -0800755 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800756 }
757 if(normalProtocol==NULL)
758 {
lhf81a46f2022-02-13 23:57:37 -0800759 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800760 }
761 else
762 {
lhf81a46f2022-02-13 23:57:37 -0800763 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800764 }
765 if(roamingProtocol==NULL)
766 {
lhf81a46f2022-02-13 23:57:37 -0800767 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800768 }
769 else
770 {
lhf81a46f2022-02-13 23:57:37 -0800771 argv[5] = roamingProtocol;
772 }
773 client.uToken = Global_uToken;
774 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
775 client.paramLen = 7;
776 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
777 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
778 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
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);
790 lynq_data_call_id = updateApn(apnType);
791 lynq_data_call = 1;
792 if(error==0)
793 {
rjw7ee7bb42023-01-18 11:34:28 +0800794 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800795 {
796 error = LYNQ_E_TIME_OUT;
797 LYERRLOG("timeout:wait data Call state fail!!!");
798 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
799 return error;
800 }
801 *handle = lynq_data_call_id;
802 }
803 return error;
804}
805/*
806int lynq_deactive_data_call_sp(int *handle,char *apnType)
807{
808 Parcel p;
809 lynq_client_t client;
810 int resp_type = -1;
811 int request = -1;
812 int slot_id = -1;
813 int error = -1;
814 if(handle==NULL||apnType==NULL)
815 {
816 LYERRLOG("handle is null!!!");
817 return -1;
818 }
819 client.uToken = Global_uToken;
820 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
821 client.paramLen = 1;
822 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
823 sprintf(client.param,"%s",apnType);
824 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
825 if(send_request(lynq_client_sockfd,&client)==-1)
826 {
827 LYERRLOG("send request fail");
828 perror("[LYNQ_DATA] send request fail:");
829 return -1;
830 }
831 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800832 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800833 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
834 return error;
835}
836*/
837int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
838{
839 Parcel p;
840 lynq_client_t client;
841 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800842 int token;
843 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800844 int slot_id = -1;
845 int error = -1;
846 int version =0;
847 int num = 0;
lhf81a46f2022-02-13 23:57:37 -0800848 char *temp_char = NULL;
849 if(dataCallList==NULL)
850 {
851 LYERRLOG("dataCallList is null!!!");
852 return -1;
853 }
854 client.uToken = Global_uToken;
855 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
856 client.paramLen = 0;
857 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
858 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800859 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800860 if(send_request(lynq_client_sockfd,&client)==-1)
861 {
862 LYERRLOG("send request fail");
863 perror("[LYNQ_DATA] send request fail:");
864 return -1;
865 }
866 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800867 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800868 if(p.dataAvail() > 0)
869 {
rjw0fb4ccb2022-09-16 19:12:35 +0800870 p.readInt32(&resp_type);
871 p.readInt32(&token);
872 p.readInt32(&request);
873 p.readInt32(&slot_id);
874 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +0800875 }
876 else
877 {
878 return -1;
879 }
lhf81a46f2022-02-13 23:57:37 -0800880 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
881 p.readInt32(&version);
882 if(version==11)
883 {
884 p.readInt32(&num);
885 *realNum = num;
886 for (int i = 0; i < num; i++)
887 {
888 p.readInt32(&dataCallList[i].status);
889 p.readInt32(&dataCallList[i].suggestedRetryTime);
890 p.readInt32(&dataCallList[i].cid);
891 p.readInt32(&dataCallList[i].active);
892 temp_char = strdupReadString(p);
893 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
894 temp_char = strdupReadString(p);
895 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
896 temp_char = strdupReadString(p);
897 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
898 temp_char = strdupReadString(p);
899 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
900 temp_char = strdupReadString(p);
901 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
902 temp_char = strdupReadString(p);
903 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
904 p.readInt32(&dataCallList[i].mtu);
905 }
906 }
907 return error;
908}
909int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
910{
911 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
912 int number = 0;
913 int lynq_data_call_id = 0;
914 int error = 0;
915 lynq_data_call_id = *handle;
916 if(handle==NULL)
917 {
918 LYERRLOG("handle is NULL");
919 return LYNQ_E_NULL_ANONALY;
920 }
rjw3938f262023-03-08 16:09:28 +0800921 if (*handle<0 && handle>8)
922 {
923 LYERRLOG("handle value error");
924 }
925 LYINFLOG("incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800926 memset(interDataCallList,0,sizeof(interDataCallList));
927 error = getDataCallLists(interDataCallList,&number);
928 if(error == 0)
929 {
930 for(int i = 0;i < number;i++)
931 {
932 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
933 {
934 dataCallList->active = interDataCallList[i].active;
935 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
936 dataCallList->cid = interDataCallList[i].cid;
937 dataCallList->status = interDataCallList[i].status;
938 dataCallList->mtu = interDataCallList[i].mtu;
939 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
940 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
941 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
942 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
943 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
944 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
945 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
946 }
947 }
948 }
949 return error;
950}
951int lynq_wait_data_call_state_change(int *handle)
952{
rjw7ee7bb42023-01-18 11:34:28 +0800953
954 std::vector<int>::iterator iter;
lhf81a46f2022-02-13 23:57:37 -0800955 waitPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800956
957 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
958 iter = s_data_urc_wait_list.begin();
rjw3938f262023-03-08 16:09:28 +0800959 *handle = s_data_urc_wait_list.front();
960
rjw7ee7bb42023-01-18 11:34:28 +0800961 s_data_urc_wait_list.erase(iter);
962 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
963
rjw3938f262023-03-08 16:09:28 +0800964 LYINFLOG("lynq data call id:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800965 return 0;
966}
967/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +0800968
969/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +0800970
971int 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 +0800972{
973 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +0800974 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +0800975 {
rjw61fcae32022-08-18 14:03:39 +0800976 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +0800977 }
rjw61fcae32022-08-18 14:03:39 +0800978 else
rjw0cdacbc2022-06-22 10:51:07 +0800979 {
rjw61fcae32022-08-18 14:03:39 +0800980 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +0800981 }
rjw20006d12022-04-21 16:29:04 +0800982 if (mcc == NULL)
983 {
984 sprintf(strtmp[1], "mcc=;");
985 }
986 else
987 {
988 sprintf(strtmp[1], "mcc=%s;", mcc);
989 }
990 if (mnc == NULL)
991 {
rjw61fcae32022-08-18 14:03:39 +0800992 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +0800993 }
994 else
995 {
996 sprintf(strtmp[2], "mnc=%s;", mnc);
997 }
998 if (apn == NULL)
999 {
1000 sprintf(strtmp[3], "apn=;");
1001 }
1002 else
1003 {
1004 sprintf(strtmp[3], "apn=%s;", apn);
1005 }
1006 if (apntype == NULL)
1007 {
1008 sprintf(strtmp[4], "apntype=;");
1009 }
1010 else
1011 {
1012 sprintf(strtmp[4], "apntype=%s;", apntype);
1013 }
1014 if (user == NULL)
1015 {
1016 sprintf(strtmp[5], "user=;");
1017 }
1018 else
1019 {
1020 sprintf(strtmp[5], "user=%s;", user);
1021 }
1022 if (password == NULL)
1023 {
1024 sprintf(strtmp[6], "password=;");
1025 }
1026 else
1027 {
1028 sprintf(strtmp[6], "password=%s;", password);
1029 }
1030 if (normalprotocol == NULL)
1031 {
1032 sprintf(strtmp[7], "normalprotocol=;");
1033 }
1034 else
1035 {
1036 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1037 }
1038 if (roamingprotocol == NULL)
1039 {
1040 sprintf(strtmp[8], "roamingprotocol=;");
1041 }
1042 else
1043 {
1044 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1045 }
1046 if (carrier == NULL)
1047 {
1048 sprintf(strtmp[9], "carrier=;");
1049 }
1050 else
1051 {
1052 sprintf(strtmp[9], "carrier=%s;", carrier);
1053 }
rjw61fcae32022-08-18 14:03:39 +08001054 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 +08001055
rjw20006d12022-04-21 16:29:04 +08001056 return 0;
1057}
1058
1059int 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)
1060{
1061 char strtmp[10][32];
1062 if (id == NULL)
1063 {
1064 sprintf(strtmp[0], "id=;");
1065 }
1066 else
1067 {
1068 sprintf(strtmp[0], "id=%s;", id);
1069 }
1070 if (mcc == NULL)
1071 {
1072 sprintf(strtmp[1], "mcc=;");
1073 }
1074 else
1075 {
1076 sprintf(strtmp[1], "mcc=%s;", mcc);
1077 }
1078 if (mnc == NULL)
1079 {
1080 sprintf(strtmp[2], "mnc=;");
1081 }
1082 else
1083 {
1084 sprintf(strtmp[2], "mnc=%s;", mnc);
1085 }
1086 if (apn == NULL)
1087 {
1088 sprintf(strtmp[3], "apn=;");
1089 }
1090 else
1091 {
1092 sprintf(strtmp[3], "apn=%s;", apn);
1093 }
1094 if (apntype == NULL)
1095 {
1096 sprintf(strtmp[4], "apntype=;");
1097 }
1098 else
1099 {
1100 sprintf(strtmp[4], "apntype=%s;", apntype);
1101 }
1102 if (user == NULL)
1103 {
1104 sprintf(strtmp[5], "user=;");
1105 }
1106 else
1107 {
1108 sprintf(strtmp[5], "user=%s;", user);
1109 }
1110 if (password == NULL)
1111 {
1112 sprintf(strtmp[6], "password=;");
1113 }
1114 else
1115 {
1116 sprintf(strtmp[6], "password=%s;", password);
1117 }
1118 if (normalprotocol == NULL)
1119 {
1120 sprintf(strtmp[7], "normalprotocol=;");
1121 }
1122 else
1123 {
1124 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1125 }
1126 if (roamingprotocol == NULL)
1127 {
1128 sprintf(strtmp[8], "roamingprotocol=;");
1129 }
1130 else
1131 {
1132 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1133 }
1134 if (carrier == NULL)
1135 {
1136 sprintf(strtmp[9], "carrier=;");
1137 }
1138 else
1139 {
1140 sprintf(strtmp[9], "carrier=%s;", carrier);
1141 }
1142 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]);
1143 return 0;
1144}
1145
rjwaf4b1612022-06-13 17:26:01 +08001146
1147int 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)
1148{
1149 char strtmp[10][32];
1150 if (id == NULL)
1151 {
1152 sprintf(strtmp[0], "");
1153 }
1154 else
1155 {
1156 sprintf(strtmp[0], "id=%s;", id);
1157 }
1158 if (mcc == NULL)
1159 {
1160 sprintf(strtmp[1], "");
1161 }
1162 else
1163 {
1164 sprintf(strtmp[1], "mcc=%s;", mcc);
1165 }
1166 if (mnc == NULL)
1167 {
1168 sprintf(strtmp[2], "");
1169 }
1170 else
1171 {
1172 sprintf(strtmp[2], "mnc=%s;", mnc);
1173 }
1174 if (apn == NULL)
1175 {
1176 sprintf(strtmp[3], "");
1177 }
1178 else
1179 {
1180 sprintf(strtmp[3], "apn=%s;", apn);
1181 }
1182 if (apntype == NULL)
1183 {
1184 sprintf(strtmp[4], "");
1185 }
1186 else
1187 {
1188 sprintf(strtmp[4], "apntype=%s;", apntype);
1189 }
1190 if (user == NULL)
1191 {
1192 sprintf(strtmp[5], "");
1193 }
1194 else
1195 {
1196 sprintf(strtmp[5], "user=%s;", user);
1197 }
1198 if (password == NULL)
1199 {
1200 sprintf(strtmp[6], "");
1201 }
1202 else
1203 {
1204 sprintf(strtmp[6], "password=%s;", password);
1205 }
1206 if (normalprotocol == NULL)
1207 {
1208 sprintf(strtmp[7], "");
1209 }
1210 else
1211 {
1212 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1213 }
1214 if (roamingprotocol == NULL)
1215 {
1216 sprintf(strtmp[8], "");
1217 }
1218 else
1219 {
1220 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1221 }
1222 if (carrier == NULL)
1223 {
1224 sprintf(strtmp[9], "");
1225 }
1226 else
1227 {
1228 sprintf(strtmp[9], "carrier=%s;", carrier);
1229 }
1230 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]);
1231 return 0;
1232}
1233
rjw20006d12022-04-21 16:29:04 +08001234static char *lynqStrdupReadString(Parcel &p)
1235{
1236 size_t stringlen;
1237 const char16_t *s16;
1238
1239 s16 = p.readString16Inplace(&stringlen);
1240 return strndup16to8(s16, stringlen);
1241}
1242
1243int 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)
1244{
1245 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1246 {
1247 LYERRLOG("There are no valid parameters");
1248 return -1;
1249 }
1250 lynq_client_t client;
1251 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001252 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001253 Parcel p;
1254 if (cmd == 0) // insert apn db
1255 {
rjw61fcae32022-08-18 14:03:39 +08001256 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1257
rjw20006d12022-04-21 16:29:04 +08001258 client.uToken = Global_uToken;
1259 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1260 client.paramLen = 2;
1261 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1262 sprintf(client.param, "%d %s", cmd, argc);
1263 }
rjw61fcae32022-08-18 14:03:39 +08001264 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001265 {
1266 if (NULL == id)
1267 {
1268 LYERRLOG("id is NULL!!!please input id: ");
1269 }
1270 sprintf(argc, "id=%s", id);
1271 client.uToken = Global_uToken;
1272 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1273 client.paramLen = 2;
1274 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1275 sprintf(client.param, "%d %s", cmd, argc);
1276 }
rjw61fcae32022-08-18 14:03:39 +08001277 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001278 {
rjwaf4b1612022-06-13 17:26:01 +08001279 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001280 client.uToken = Global_uToken;
1281 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1282 client.paramLen = 2;
1283 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1284 sprintf(client.param, "%d %s", cmd, argc);
1285 }
rjw61fcae32022-08-18 14:03:39 +08001286 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001287 {
1288 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
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 }
1295 else
1296 {
1297 LYERRLOG("incoming command is invalid");
1298 return -1;
1299 }
1300 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001301 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001302 if(send_request(lynq_client_sockfd,&client)==-1)
1303 {
1304 LYERRLOG("send request fail");
1305 return -1;
1306 }
rjwed00d042022-05-25 09:18:16 +08001307 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001308 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001309 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001310 LYINFLOG(">>>>>output info:%s",out);
1311 return 0;
1312}
1313
1314int lynq_reset_apn(char *result)
1315{
1316 Parcel p;
1317 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001318 if (NULL == result)
1319 {
1320 LYERRLOG("incoming paramters error");
1321 }
rjw20006d12022-04-21 16:29:04 +08001322 client.uToken = Global_uToken;
1323 client.request = 2000 + 194;
1324 client.paramLen = 0;
1325 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1326 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001327 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001328 if (send_request(lynq_client_sockfd, &client) == -1)
1329 {
1330 LYERRLOG("send request fail");
1331 return -1;
1332 }
rjwed00d042022-05-25 09:18:16 +08001333 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001334 waitApnResult();
1335 strcpy(result, g_lynq_apn_result);
1336 LYINFLOG(">>>>>result:%s",result);
1337 return 0;
1338}
1339
rjw3bcbbf12022-04-22 16:47:18 +08001340/*Typethree add for T800 platform 2022/04/21 end*/