blob: 460eb9cdce5a6b90c2ed9718eb7e767c654d7341 [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;
rjwf9ec3832023-04-12 10:59:15 +080074/*This value data the state of the wait*/
rjwc3d6e582023-03-28 17:19:11 +080075static int data_waiting_status = 0;
rjwf9ec3832023-04-12 10:59:15 +080076/*The value indicates that 8085 error occurs in data*/
rjwc63abb42023-03-31 18:22:42 +080077static int data_invaild_error = 0;
rjwf9ec3832023-04-12 10:59:15 +080078/*This value ensure the data call timing is correct*/
79static int data_timelimit = 0;
rjwc63abb42023-03-31 18:22:42 +080080
rjw22947c22022-03-15 09:21:29 +080081/**g_lynq_data_init_flag
82* @brief mark data initialization state
83* 0:deinit status
84* 1:init state
85*/
86static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080087/**g_lynq_apn_result
88* @brief temp of apn result info
89*/
90char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +080091
rjw7ee7bb42023-01-18 11:34:28 +080092static std::vector<int> s_data_urc_wait_list;
93
rjw20006d12022-04-21 16:29:04 +080094typedef struct
95{
lhf81a46f2022-02-13 23:57:37 -080096 char apn[LYNQ_APN_MAX_LEN];
97 char apnType[LYNQ_APN_TYPE_MAX_LEN];
98 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
99 int hasUsed;
100 int hasTimeout;
101}lynq_apn_t;
102lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
103lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
104int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800105
lhf81a46f2022-02-13 23:57:37 -0800106int getLynqApnID(char apnType[])
107{
108 int ret = 0;
rjwc63abb42023-03-31 18:22:42 +0800109 int len = 0;
lhf81a46f2022-02-13 23:57:37 -0800110 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
111 {
rjwc63abb42023-03-31 18:22:42 +0800112 len = strlen(lynq_apn_table[ret].apnType)<strlen(apnType) ? strlen(lynq_apn_table[ret].apnType):strlen(apnType);
113 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
lh13586612022-01-11 21:58:58 -0800114 {
lhf81a46f2022-02-13 23:57:37 -0800115 return ret;
116 }
117 }
118 return -1;
119}
rjw7ee7bb42023-01-18 11:34:28 +0800120
lhf81a46f2022-02-13 23:57:37 -0800121void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
122{
123 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
124 if(apn_table==NULL)
125 {
126 LYERRLOG("apn_table is null");
127 return;
128 }
129 memcpy(apn_table->apn,apn,strlen(apn)+1);
130 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
131 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
132 apn_table->hasTimeout = 0;
133 apn_table->hasUsed = 1;
134 return;
135}
rjw7ee7bb42023-01-18 11:34:28 +0800136
lhf81a46f2022-02-13 23:57:37 -0800137void cleanOnceApnTable(int apnId)
138{
139 LYDBGLOG("apn id:%d",apnId);
140 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
141 {
142 LYERRLOG("apn id is invalid!!!");
143 return;
144 }
145 lynq_apn_table[apnId].hasTimeout = 0;
146 lynq_apn_table[apnId].hasUsed = 0;
147 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
148 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
149 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
150 return;
151}
152int getUnusedElement()
153{
rjwc63abb42023-03-31 18:22:42 +0800154 if (lynq_apn_table == NULL)
155 {
156 LYERRLOG("get UnusedElemnt apn_table is null");
157 return -1;
158 }
lhf81a46f2022-02-13 23:57:37 -0800159 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
160 {
161 if(lynq_apn_table[i].hasUsed!=1)
162 {
163 return i;
164 }
165 }
rjwc63abb42023-03-31 18:22:42 +0800166 LYERRLOG("None of get unused Element");
lhf81a46f2022-02-13 23:57:37 -0800167 return -1;
168}
169int updateApn(char apnType[])
170{
171 int ret = 0;
172 ret = getUnusedElement();
173 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
174 lynq_apn_table[ret].hasUsed = 1;
175 return ret;
176}
rjw1309e232022-07-22 09:54:06 +0800177
178int handleCheck(int handle)
179{
180 if (lynq_apn_table[handle].hasUsed == 1)
181 {
182 return 0;
183 }
184 else
185 {
186 return -1;
187 }
188}
rjw20006d12022-04-21 16:29:04 +0800189int waitApnResult()
190{
191 int ret = 0;
192 LYINFLOG("start wait apn result!!!");
193 int sec = 0;
194 int usec = 0;
195 struct timeval now;
196 struct timespec timeout;
197 gettimeofday(&now, NULL);
198 sec = 20000 / 1000;
199 usec = 20000 % 1000;
200 timeout.tv_sec = now.tv_sec + sec;
201 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
202 pthread_mutex_lock(&s_lynq_apn_change_mutex);
203 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
204 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
205 return ret;
206}
207
208void sendSignalApnChange()
209{
210 LYINFLOG("start send Signal Apn Change");
211 pthread_mutex_lock(&s_lynq_apn_change_mutex);
212 pthread_cond_signal(&s_lynq_apn_change_cond);
213 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
214 return;
215}
lhf81a46f2022-02-13 23:57:37 -0800216
217int waitPdnChange()
218{
219 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800220 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
221 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
222 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800223 return ret;
224}
225int waitDataCallstateChange(int mtime)
226{
227 int ret = 0;
228 int sec = 0;
229 int usec = 0;
230 struct timeval now;
231 struct timespec timeout;
232 gettimeofday(&now,NULL);
233 sec = mtime/1000;
234 usec = mtime%1000;
235 timeout.tv_sec = now.tv_sec+sec;
236 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
237 pthread_mutex_lock(&s_data_call_state_change_mutex);
238 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
239 pthread_mutex_unlock(&s_data_call_state_change_mutex);
240 return ret;
241}
242void sendSignalDataCallStateChange()
243{
244 pthread_mutex_lock(&s_data_call_state_change_mutex);
245 pthread_cond_signal(&s_data_call_state_change_cond);
246 pthread_mutex_unlock(&s_data_call_state_change_mutex);
247 return;
248}
249void sendSignalPdnChange()
250{
rjw7ee7bb42023-01-18 11:34:28 +0800251 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
252 pthread_cond_signal(&s_lynq_urc_vector_cond);
253 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800254 return;
255}
256
257int get_response(int sockfd,Parcel &p)
258{
259 int len = 0;
260 char recvline[LYNQ_REC_BUF];
261 bzero(recvline,LYNQ_REC_BUF);
262 /* receive data from server */
rjw08528682022-07-04 21:28:02 +0800263 len = read(sockfd, recvline, LYNQ_REC_BUF);
264 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800265 {
rjw747deea2022-07-01 18:25:30 +0800266 LYERRLOG("read error");
lhf81a46f2022-02-13 23:57:37 -0800267 return -1;
268 }
269 if (recvline != NULL) {
270 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
271 p.setDataPosition(0);
272 }
273 return 0;
274}
rjwfa532972022-09-16 13:39:41 +0800275int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
lhf81a46f2022-02-13 23:57:37 -0800276{
277 if(p.dataAvail() > 0)
278 {
279 p.readInt32(resp_type);
280 p.readInt32(request);
281 p.readInt32(slot_id);
282 p.readInt32(error);
283 return 0;
284 }
285 else
286 {
287 return -1;
288 }
289}
290int send_request(int sockfd,lynq_client_t *client_tmp)
291{
292 int ret=0;
293 ret = write(sockfd, client_tmp, LYQN_SEDN_BUF);
294 if(ret==-1)
295 {
296 perror("write error");
297 return -1;
298 }
299 return 0;
300}
301static char *strdupReadString(Parcel &p) {
302 size_t stringlen;
303 const char16_t *s16;
304 s16 = p.readString16Inplace(&stringlen);
305 return strndup16to8(s16, stringlen);
306}
307static char *strdupReadString_p(Parcel *p) {
308 size_t stringlen;
309 const char16_t *s16;
310 s16 = p->readString16Inplace(&stringlen);
311 return strndup16to8(s16, stringlen);
312}
313
lhf81a46f2022-02-13 23:57:37 -0800314/*Warren add for T800 platform 2021/11/19 start*/
315int lynq_socket_client_start()
316{
rjw08528682022-07-04 21:28:02 +0800317 struct sockaddr_in lynq_data_socket_server_addr;
lhf81a46f2022-02-13 23:57:37 -0800318 /* init lynq_socket_server_addr */
rjw747deea2022-07-01 18:25:30 +0800319 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
320 lynq_data_socket_server_addr.sin_family = AF_INET;
321 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
jb.qid5852372023-03-29 10:29:12 +0800322 lynq_data_socket_server_addr.sin_addr.s_addr = inet_addr(LYNQ_ADDRESS);
lhf81a46f2022-02-13 23:57:37 -0800323 /*
324 if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
325 {
326 printf("[%s] is not a valid IPaddress\n", argv[1]);
327 exit(1);
328 }
329*/
330 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
rjw747deea2022-07-01 18:25:30 +0800331 struct timeval timeOut;
332
rjwa59bf312022-07-05 11:50:31 +0800333 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800334 timeOut.tv_usec = 0;
335
336 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
337 {
338 LYERRLOG("time out setting failed");
339 }
340 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 -0800341 {
342 perror("connect error");
343 return -1;
344 }
345 return 0;
346}
rjw7ee7bb42023-01-18 11:34:28 +0800347
348bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800349{
rjw7ee7bb42023-01-18 11:34:28 +0800350 switch(urc_id)
351 {
352 case LYNQ_URC_DATA_CALL_STATUS_IND:
353
354 case LYNQ_URC_MODIFY_APNDB:
355 case LYNQ_URC_RESET_APNDB:
356 return true;
357 default:
358 return false;
359 }
360}
361
rjwc63abb42023-03-31 18:22:42 +0800362int printf_apn_table()
363{
364 int ret = 0;
365 if (lynq_apn_table == NULL)
366 {
367 LYERRLOG("apn table is null");
368 return -1;
369 }
370 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
371 {
372 LYINFLOG("[Typethree test info]apn=%s ;apntype=%s ;ifname=%s ;hasTimeout = %d ; hasUsed = %d", \
373 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
374 lynq_apn_table[ret].hasTimeout,lynq_apn_table[ret].hasUsed);
375 }
376 return 0;
377}
378
379
rjw7ee7bb42023-01-18 11:34:28 +0800380void urc_msg_process(Parcel *p)
381{
382 int len;
383 int resp_type;
384 int urcid;
385 int slot_id;
rjwf9ec3832023-04-12 10:59:15 +0800386 int check_count = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800387
388 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800389 char apn[LYNQ_APN_MAX_LEN];
390 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800391 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800392 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800393
394 int size = p->dataSize();
395 p->readInt32(&resp_type);
396 p->readInt32(&urcid);
397 p->readInt32(&slot_id);
398 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
399 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800400 {
rjw7ee7bb42023-01-18 11:34:28 +0800401 case LYNQ_URC_DATA_CALL_STATUS_IND:
402 p->readInt32(&pdnState);
403 bzero(apn,LYNQ_APN_MAX_LEN);
404 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
405 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
406 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800407 {
rjw20006d12022-04-21 16:29:04 +0800408 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800409 int len = strlen(urc_msg);
410 if(len < LYNQ_APN_MAX_LEN-1)
rjw20006d12022-04-21 16:29:04 +0800411 {
rjw7ee7bb42023-01-18 11:34:28 +0800412 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800413 }
rjw7ee7bb42023-01-18 11:34:28 +0800414 urc_msg = strdupReadString_p(p);
415 len = strlen(urc_msg);
416 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
417 {
418 memcpy(apnType,urc_msg,len+1);
419 }
420 urc_msg = strdupReadString_p(p);
421 len = strlen(urc_msg);
422 if(len < LYNQ_IFACE_NAME_MAX_LEN-1)
423 {
424 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
425 }
426 //sendSignalDataCallStateChange();
427 int apnId = getLynqApnID(apnType);
rjwc63abb42023-03-31 18:22:42 +0800428 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d",apnType,ifaceName,apn,pdnState);
rjw7ee7bb42023-01-18 11:34:28 +0800429 if(apnId >= 0)
430 {
431 if(lynq_apn_table[apnId].hasTimeout==1)
432 {
rjwc63abb42023-03-31 18:22:42 +0800433 /*whether timeout?,real or not,*/
434 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800435 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800436 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 +0800437 {
438 LYERRLOG("deactive this time out APN");
439 lynq_deactive_data_call(&apnId);
440 }
rjwc63abb42023-03-31 18:22:42 +0800441 else
rjw7ee7bb42023-01-18 11:34:28 +0800442 {
rjwc63abb42023-03-31 18:22:42 +0800443 /*if apn lose,update apn and deactive all apn*/
444 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800445 }
446 break;
447 }
rjwacdb2152023-02-07 14:12:49 +0800448 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
rjw7ee7bb42023-01-18 11:34:28 +0800449 }
450 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800451 else
452 {
rjwc63abb42023-03-31 18:22:42 +0800453 data_invaild_error = 1;
454 printf_apn_table();
455 LYERRLOG("invalid apnId:%d",apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800456 break;
rjw20006d12022-04-21 16:29:04 +0800457 }
rjw7ee7bb42023-01-18 11:34:28 +0800458 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
459 s_data_urc_wait_list.push_back(apnId);
460 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
461 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800462 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800463 LYDBGLOG("data call state:%d",lynq_data_call);
464 if(lynq_data_call==1)
465 {
rjwf9ec3832023-04-12 10:59:15 +0800466 while (data_timelimit == 0)
467 {
468 LYINFLOG("client not ready to wait");
469 for (check_count = 0;check_count < 500;check_count++)
470 {
471 /*wait 10ms*/
472 usleep(10*1000);
473 }
474 LYERRLOG("client still without res");
475 break;
476 }
rjw7ee7bb42023-01-18 11:34:28 +0800477 sendSignalDataCallStateChange();
478 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800479 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800480 }
rjw20006d12022-04-21 16:29:04 +0800481 }
rjw7ee7bb42023-01-18 11:34:28 +0800482 else
rjw20006d12022-04-21 16:29:04 +0800483 {
rjw7ee7bb42023-01-18 11:34:28 +0800484 urc_msg = strdupReadString_p(p);
485 len = strlen(urc_msg);
486 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
487 {
488 memcpy(apnType,urc_msg,len+1);
489 }
490 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
491 int apnId = getLynqApnID(apnType);
492 if(apnId >= 0)
493 {
494 lynq_data_call_change_id = apnId;
495 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800496 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
497 s_data_urc_wait_list.push_back(apnId);
498 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
rjwc3d6e582023-03-28 17:19:11 +0800499 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800500 }
rjw7ee7bb42023-01-18 11:34:28 +0800501 LYDBGLOG("data call state:%d",lynq_data_call);
502 if(lynq_data_call==1)
503 {
rjwf9ec3832023-04-12 10:59:15 +0800504 while (data_timelimit == 0)
505 {
506 LYINFLOG("client not ready to wait");
507 for (check_count = 0;check_count < 500;check_count++)
508 {
509 /*wait 10ms*/
510 usleep(10*1000);
511 }
512 LYERRLOG("client still without res");
513 break;
514 }
rjw7ee7bb42023-01-18 11:34:28 +0800515 sendSignalDataCallStateChange();
516 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800517 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800518 }
519 }
520 break;
521 case LYNQ_URC_MODIFY_APNDB:
522 urc_msg = strdupReadString_p(p);
523 if (NULL == urc_msg)
524 {
525 LYERRLOG("error apn msg");
526 }
527 else
528 {
529 bzero(g_lynq_apn_result, 1024);
530 strcpy(g_lynq_apn_result, urc_msg);
531 sendSignalApnChange();
532 }
533 break;
534 case LYNQ_URC_RESET_APNDB:
535 {
rjw20006d12022-04-21 16:29:04 +0800536 urc_msg = strdupReadString_p(p);
537 if (NULL == urc_msg)
538 {
539 LYERRLOG("error apn msg");
540 }
541 else
542 {
543 bzero(g_lynq_apn_result, 1024);
544 strcpy(g_lynq_apn_result, urc_msg);
545 sendSignalApnChange();
546 }
547 }
rjw7ee7bb42023-01-18 11:34:28 +0800548 default:
549 break;
lhf81a46f2022-02-13 23:57:37 -0800550 }
rjw7ee7bb42023-01-18 11:34:28 +0800551
lhf81a46f2022-02-13 23:57:37 -0800552}
rjw7ee7bb42023-01-18 11:34:28 +0800553
rjw7ee7bb42023-01-18 11:34:28 +0800554int create_urc_vector_signal_thread()
555{
556 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800557 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800558 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
559 s_data_urc_wait_list.clear();
560 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800561 return 0;
562}
rjw7ee7bb42023-01-18 11:34:28 +0800563
lhf81a46f2022-02-13 23:57:37 -0800564int lynq_init_data(int uToken)
565{
rjw22947c22022-03-15 09:21:29 +0800566 if (g_lynq_data_init_flag == 1)
567 {
568 LYERRLOG("init twice is not allowed");
569 return -1;
570 }
571 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800572 int result = 0;
573 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800574 LYLOGSET(LOG_INFO);
575 LYLOGEINIT(USER_LOG_TAG);
576 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800577 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800578 if(result!=0)
579 {
580 LYERRLOG("init socket client fail!!!");
581 return -1;
582 }
rjw7ee7bb42023-01-18 11:34:28 +0800583 result = lynq_init_data_urc_thread();
584 if(result!=0)
585 {
586 LYERRLOG("init socket urc fail!!!");
587 return -1;
588 }
589
590 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800591 if(result!=0)
592 {
593 LYERRLOG("init socket urc fail!!!");
594 return -1;
595 }
596 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
597 LYDBGLOG("lynq init call success!!!");
598 return 0;
599
600}
601int lynq_deinit_data()
602{
603 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800604 if (g_lynq_data_init_flag == 0)
605 {
606 LYERRLOG("deinit twice is not allowed");
607 return ret;
608 }
609 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800610 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
611 {
612 if(strlen(lynq_apn_table[i].apnType)!=0)
613 {
614 lynq_deactive_data_call(&i);
615 }
616 }
617 if(lynq_client_sockfd>0)
618 {
619 close(lynq_client_sockfd);
620 }
rjw7ee7bb42023-01-18 11:34:28 +0800621 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800622 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800623 {
rjw7ee7bb42023-01-18 11:34:28 +0800624 LYERRLOG("lynq_deinit_data_urc_thread fail");
625 return ret;
rjw22947c22022-03-15 09:21:29 +0800626 }
rjwc3d6e582023-03-28 17:19:11 +0800627 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
628 s_data_urc_wait_list.clear();
629 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800630 return 0;
631}
632int lynq_setup_data_call(int *handle)
633{
634 Parcel p;
635 lynq_client_t client;
636 int resp_type = -1;
637 int request = -1;
638 int slot_id = -1;
639 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800640 int lynq_data_call_id = 0;
641 if(handle==NULL)
642 {
643 LYERRLOG("handle is null!!!");
644 return LYNQ_E_NULL_ANONALY;
645 }
646 client.uToken = Global_uToken;
647 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
648 client.paramLen = 0;
649 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
650 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800651 lynq_data_call_id = updateApn("default");
652 if (lynq_data_call_id < 0)
653 {
654 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
655 return -1;
656 }
rjw733b9832023-04-03 10:20:08 +0800657 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800658 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800659 if(send_request(lynq_client_sockfd,&client)==-1)
660 {
661 LYERRLOG("send request fail");
662 perror("[LYNQ_DATA] send request fail:");
663 return -1;
664 }
665 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800666 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800667 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800668 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800669 if(error==0)
670 {
rjwf9ec3832023-04-12 10:59:15 +0800671 data_timelimit = 1;
rjw20006d12022-04-21 16:29:04 +0800672 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800673 {
674 error = LYNQ_E_TIME_OUT;
675 LYERRLOG("timeout:wait data Call state fail!!!");
676 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
rjwc63abb42023-03-31 18:22:42 +0800677 if (data_invaild_error == 1)
678 {
679 data_invaild_error = 0;
680 LYERRLOG("urc apn info error!!!");
681 return 8085;
682 }
lhf81a46f2022-02-13 23:57:37 -0800683 return error;
684 }
685 *handle = lynq_data_call_id;
686 }
687 return error;
688}
rjw7ee7bb42023-01-18 11:34:28 +0800689
lhf81a46f2022-02-13 23:57:37 -0800690int lynq_deactive_data_call(int *handle)
691{
692 Parcel p;
693 lynq_client_t client;
694 int resp_type = -1;
695 int request = -1;
696 int slot_id = -1;
697 int error = -1;
698 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800699 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800700 if(handle==NULL)
701 {
702 LYERRLOG("handle is null!!!");
703 return -1;
704 }
rjw1309e232022-07-22 09:54:06 +0800705 ret = handleCheck(*handle);
706 if (ret != 0)
707 {
708 LYERRLOG("incomming handle is invalid");
709 return -1;
710 }
711 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800712 client.uToken = Global_uToken;
713 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
714 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
715 {
716 client.paramLen = 0;
717 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800718 }
719 else
720 {
lhf81a46f2022-02-13 23:57:37 -0800721 client.paramLen = 1;
722 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
723 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
724 }
725 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800726 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800727 if(send_request(lynq_client_sockfd,&client)==-1)
728 {
729 LYERRLOG("send request fail");
730 perror("[LYNQ_DATA] send request fail:");
731 return -1;
732 }
733 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800734 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800735 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800736 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
737 cleanOnceApnTable(lynq_data_call_id);
738 return error;
739}
740int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
741{
742 Parcel p;
743 lynq_client_t client;
744 int resp_type = -1;
745 int request = -1;
746 int slot_id = -1;
747 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800748 int lynq_data_call_id = -1;
749 char *argv[10] = {};
750 if(handle==NULL||apn==NULL||apnType==NULL)
751 {
752 LYERRLOG("handle ,apn or apntype is null!!!");
753 return -1;
754 }
755 if(user==NULL)
756 {
757 argv[1] = "null";
758 }
759 else
760 {
761 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800762 }
763 if(password==NULL)
764 {
lhf81a46f2022-02-13 23:57:37 -0800765 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800766 }
767 else
768 {
lhf81a46f2022-02-13 23:57:37 -0800769 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800770 }
771 if(authType==NULL)
772 {
lhf81a46f2022-02-13 23:57:37 -0800773 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800774 }
775 else
776 {
lhf81a46f2022-02-13 23:57:37 -0800777 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800778 }
779 if(normalProtocol==NULL)
780 {
lhf81a46f2022-02-13 23:57:37 -0800781 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800782 }
783 else
784 {
lhf81a46f2022-02-13 23:57:37 -0800785 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800786 }
787 if(roamingProtocol==NULL)
788 {
lhf81a46f2022-02-13 23:57:37 -0800789 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800790 }
791 else
792 {
lhf81a46f2022-02-13 23:57:37 -0800793 argv[5] = roamingProtocol;
794 }
795 client.uToken = Global_uToken;
796 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
797 client.paramLen = 7;
798 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
799 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
800 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800801 lynq_data_call_id = updateApn(apnType);
802 if (lynq_data_call_id < 0)
803 {
804 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
805 return -1;
806 }
rjw733b9832023-04-03 10:20:08 +0800807 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800808 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800809 if(send_request(lynq_client_sockfd,&client)==-1)
810 {
811 LYERRLOG("send request fail");
812 perror("[LYNQ_DATA] send request fail:");
813 return -1;
814 }
815 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800816 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800817 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800818 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800819 if(error==0)
820 {
rjwf9ec3832023-04-12 10:59:15 +0800821 data_timelimit = 1;
rjw7ee7bb42023-01-18 11:34:28 +0800822 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800823 {
824 error = LYNQ_E_TIME_OUT;
825 LYERRLOG("timeout:wait data Call state fail!!!");
826 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
rjwc63abb42023-03-31 18:22:42 +0800827 if (data_invaild_error == 1)
828 {
829 data_invaild_error = 0;
830 LYERRLOG("urc apn info error!!!");
831 return 8085;
832 }
lhf81a46f2022-02-13 23:57:37 -0800833 return error;
834 }
835 *handle = lynq_data_call_id;
836 }
837 return error;
838}
839/*
840int lynq_deactive_data_call_sp(int *handle,char *apnType)
841{
842 Parcel p;
843 lynq_client_t client;
844 int resp_type = -1;
845 int request = -1;
846 int slot_id = -1;
847 int error = -1;
848 if(handle==NULL||apnType==NULL)
849 {
850 LYERRLOG("handle is null!!!");
851 return -1;
852 }
853 client.uToken = Global_uToken;
854 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
855 client.paramLen = 1;
856 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
857 sprintf(client.param,"%s",apnType);
858 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
859 if(send_request(lynq_client_sockfd,&client)==-1)
860 {
861 LYERRLOG("send request fail");
862 perror("[LYNQ_DATA] send request fail:");
863 return -1;
864 }
865 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800866 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800867 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
868 return error;
869}
870*/
871int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
872{
873 Parcel p;
874 lynq_client_t client;
875 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800876 int token;
877 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800878 int slot_id = -1;
879 int error = -1;
880 int version =0;
881 int num = 0;
lhf81a46f2022-02-13 23:57:37 -0800882 char *temp_char = NULL;
883 if(dataCallList==NULL)
884 {
885 LYERRLOG("dataCallList is null!!!");
886 return -1;
887 }
888 client.uToken = Global_uToken;
889 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
890 client.paramLen = 0;
891 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
892 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800893 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800894 if(send_request(lynq_client_sockfd,&client)==-1)
895 {
896 LYERRLOG("send request fail");
897 perror("[LYNQ_DATA] send request fail:");
898 return -1;
899 }
900 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800901 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800902 if(p.dataAvail() > 0)
903 {
rjw0fb4ccb2022-09-16 19:12:35 +0800904 p.readInt32(&resp_type);
905 p.readInt32(&token);
906 p.readInt32(&request);
907 p.readInt32(&slot_id);
908 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +0800909 }
910 else
911 {
912 return -1;
913 }
lhf81a46f2022-02-13 23:57:37 -0800914 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
915 p.readInt32(&version);
916 if(version==11)
917 {
918 p.readInt32(&num);
919 *realNum = num;
920 for (int i = 0; i < num; i++)
921 {
922 p.readInt32(&dataCallList[i].status);
923 p.readInt32(&dataCallList[i].suggestedRetryTime);
924 p.readInt32(&dataCallList[i].cid);
925 p.readInt32(&dataCallList[i].active);
926 temp_char = strdupReadString(p);
927 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
928 temp_char = strdupReadString(p);
929 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
930 temp_char = strdupReadString(p);
931 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
932 temp_char = strdupReadString(p);
933 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
934 temp_char = strdupReadString(p);
935 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
936 temp_char = strdupReadString(p);
937 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
938 p.readInt32(&dataCallList[i].mtu);
939 }
940 }
941 return error;
942}
943int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
944{
945 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
946 int number = 0;
947 int lynq_data_call_id = 0;
948 int error = 0;
949 lynq_data_call_id = *handle;
950 if(handle==NULL)
951 {
952 LYERRLOG("handle is NULL");
953 return LYNQ_E_NULL_ANONALY;
954 }
rjw3938f262023-03-08 16:09:28 +0800955 if (*handle<0 && handle>8)
956 {
957 LYERRLOG("handle value error");
958 }
959 LYINFLOG("incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800960 memset(interDataCallList,0,sizeof(interDataCallList));
961 error = getDataCallLists(interDataCallList,&number);
962 if(error == 0)
963 {
964 for(int i = 0;i < number;i++)
965 {
966 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
967 {
968 dataCallList->active = interDataCallList[i].active;
969 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
970 dataCallList->cid = interDataCallList[i].cid;
971 dataCallList->status = interDataCallList[i].status;
972 dataCallList->mtu = interDataCallList[i].mtu;
973 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
974 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
975 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
976 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
977 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
978 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
979 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
980 }
981 }
982 }
983 return error;
984}
985int lynq_wait_data_call_state_change(int *handle)
986{
rjwc3d6e582023-03-28 17:19:11 +0800987 if (data_waiting_status == 1)
988 {
989 LYDBGLOG("some thread is waiting");
990 return -3;
991 }
992 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
993 if (s_data_urc_wait_list.empty())
994 {
995 LYDBGLOG("start wait");
996 data_waiting_status = 1;
997 waitPdnChange();
998 }
999 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001000 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001001
1002 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1003 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001004 if (iter != s_data_urc_wait_list.end())
1005 {
1006 *handle = *iter;
1007 }
rjw7ee7bb42023-01-18 11:34:28 +08001008 s_data_urc_wait_list.erase(iter);
1009 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1010
rjw3938f262023-03-08 16:09:28 +08001011 LYINFLOG("lynq data call id:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001012 return 0;
1013}
1014/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001015
1016/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001017
1018int 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 +08001019{
1020 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001021 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001022 {
rjw61fcae32022-08-18 14:03:39 +08001023 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001024 }
rjw61fcae32022-08-18 14:03:39 +08001025 else
rjw0cdacbc2022-06-22 10:51:07 +08001026 {
rjw61fcae32022-08-18 14:03:39 +08001027 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001028 }
rjw20006d12022-04-21 16:29:04 +08001029 if (mcc == NULL)
1030 {
1031 sprintf(strtmp[1], "mcc=;");
1032 }
1033 else
1034 {
1035 sprintf(strtmp[1], "mcc=%s;", mcc);
1036 }
1037 if (mnc == NULL)
1038 {
rjw61fcae32022-08-18 14:03:39 +08001039 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001040 }
1041 else
1042 {
1043 sprintf(strtmp[2], "mnc=%s;", mnc);
1044 }
1045 if (apn == NULL)
1046 {
1047 sprintf(strtmp[3], "apn=;");
1048 }
1049 else
1050 {
1051 sprintf(strtmp[3], "apn=%s;", apn);
1052 }
1053 if (apntype == NULL)
1054 {
1055 sprintf(strtmp[4], "apntype=;");
1056 }
1057 else
1058 {
1059 sprintf(strtmp[4], "apntype=%s;", apntype);
1060 }
1061 if (user == NULL)
1062 {
1063 sprintf(strtmp[5], "user=;");
1064 }
1065 else
1066 {
1067 sprintf(strtmp[5], "user=%s;", user);
1068 }
1069 if (password == NULL)
1070 {
1071 sprintf(strtmp[6], "password=;");
1072 }
1073 else
1074 {
1075 sprintf(strtmp[6], "password=%s;", password);
1076 }
1077 if (normalprotocol == NULL)
1078 {
1079 sprintf(strtmp[7], "normalprotocol=;");
1080 }
1081 else
1082 {
1083 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1084 }
1085 if (roamingprotocol == NULL)
1086 {
1087 sprintf(strtmp[8], "roamingprotocol=;");
1088 }
1089 else
1090 {
1091 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1092 }
1093 if (carrier == NULL)
1094 {
1095 sprintf(strtmp[9], "carrier=;");
1096 }
1097 else
1098 {
1099 sprintf(strtmp[9], "carrier=%s;", carrier);
1100 }
rjw61fcae32022-08-18 14:03:39 +08001101 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 +08001102
rjw20006d12022-04-21 16:29:04 +08001103 return 0;
1104}
1105
1106int 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)
1107{
1108 char strtmp[10][32];
1109 if (id == NULL)
1110 {
1111 sprintf(strtmp[0], "id=;");
1112 }
1113 else
1114 {
1115 sprintf(strtmp[0], "id=%s;", id);
1116 }
1117 if (mcc == NULL)
1118 {
1119 sprintf(strtmp[1], "mcc=;");
1120 }
1121 else
1122 {
1123 sprintf(strtmp[1], "mcc=%s;", mcc);
1124 }
1125 if (mnc == NULL)
1126 {
1127 sprintf(strtmp[2], "mnc=;");
1128 }
1129 else
1130 {
1131 sprintf(strtmp[2], "mnc=%s;", mnc);
1132 }
1133 if (apn == NULL)
1134 {
1135 sprintf(strtmp[3], "apn=;");
1136 }
1137 else
1138 {
1139 sprintf(strtmp[3], "apn=%s;", apn);
1140 }
1141 if (apntype == NULL)
1142 {
1143 sprintf(strtmp[4], "apntype=;");
1144 }
1145 else
1146 {
1147 sprintf(strtmp[4], "apntype=%s;", apntype);
1148 }
1149 if (user == NULL)
1150 {
1151 sprintf(strtmp[5], "user=;");
1152 }
1153 else
1154 {
1155 sprintf(strtmp[5], "user=%s;", user);
1156 }
1157 if (password == NULL)
1158 {
1159 sprintf(strtmp[6], "password=;");
1160 }
1161 else
1162 {
1163 sprintf(strtmp[6], "password=%s;", password);
1164 }
1165 if (normalprotocol == NULL)
1166 {
1167 sprintf(strtmp[7], "normalprotocol=;");
1168 }
1169 else
1170 {
1171 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1172 }
1173 if (roamingprotocol == NULL)
1174 {
1175 sprintf(strtmp[8], "roamingprotocol=;");
1176 }
1177 else
1178 {
1179 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1180 }
1181 if (carrier == NULL)
1182 {
1183 sprintf(strtmp[9], "carrier=;");
1184 }
1185 else
1186 {
1187 sprintf(strtmp[9], "carrier=%s;", carrier);
1188 }
1189 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]);
1190 return 0;
1191}
1192
rjwaf4b1612022-06-13 17:26:01 +08001193
1194int 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)
1195{
1196 char strtmp[10][32];
1197 if (id == NULL)
1198 {
1199 sprintf(strtmp[0], "");
1200 }
1201 else
1202 {
1203 sprintf(strtmp[0], "id=%s;", id);
1204 }
1205 if (mcc == NULL)
1206 {
1207 sprintf(strtmp[1], "");
1208 }
1209 else
1210 {
1211 sprintf(strtmp[1], "mcc=%s;", mcc);
1212 }
1213 if (mnc == NULL)
1214 {
1215 sprintf(strtmp[2], "");
1216 }
1217 else
1218 {
1219 sprintf(strtmp[2], "mnc=%s;", mnc);
1220 }
1221 if (apn == NULL)
1222 {
1223 sprintf(strtmp[3], "");
1224 }
1225 else
1226 {
1227 sprintf(strtmp[3], "apn=%s;", apn);
1228 }
1229 if (apntype == NULL)
1230 {
1231 sprintf(strtmp[4], "");
1232 }
1233 else
1234 {
1235 sprintf(strtmp[4], "apntype=%s;", apntype);
1236 }
1237 if (user == NULL)
1238 {
1239 sprintf(strtmp[5], "");
1240 }
1241 else
1242 {
1243 sprintf(strtmp[5], "user=%s;", user);
1244 }
1245 if (password == NULL)
1246 {
1247 sprintf(strtmp[6], "");
1248 }
1249 else
1250 {
1251 sprintf(strtmp[6], "password=%s;", password);
1252 }
1253 if (normalprotocol == NULL)
1254 {
1255 sprintf(strtmp[7], "");
1256 }
1257 else
1258 {
1259 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1260 }
1261 if (roamingprotocol == NULL)
1262 {
1263 sprintf(strtmp[8], "");
1264 }
1265 else
1266 {
1267 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1268 }
1269 if (carrier == NULL)
1270 {
1271 sprintf(strtmp[9], "");
1272 }
1273 else
1274 {
1275 sprintf(strtmp[9], "carrier=%s;", carrier);
1276 }
1277 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]);
1278 return 0;
1279}
1280
rjw20006d12022-04-21 16:29:04 +08001281static char *lynqStrdupReadString(Parcel &p)
1282{
1283 size_t stringlen;
1284 const char16_t *s16;
1285
1286 s16 = p.readString16Inplace(&stringlen);
1287 return strndup16to8(s16, stringlen);
1288}
1289
1290int 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)
1291{
1292 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1293 {
1294 LYERRLOG("There are no valid parameters");
1295 return -1;
1296 }
1297 lynq_client_t client;
1298 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001299 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001300 Parcel p;
1301 if (cmd == 0) // insert apn db
1302 {
rjw61fcae32022-08-18 14:03:39 +08001303 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1304
rjw20006d12022-04-21 16:29:04 +08001305 client.uToken = Global_uToken;
1306 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1307 client.paramLen = 2;
1308 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1309 sprintf(client.param, "%d %s", cmd, argc);
1310 }
rjw61fcae32022-08-18 14:03:39 +08001311 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001312 {
1313 if (NULL == id)
1314 {
1315 LYERRLOG("id is NULL!!!please input id: ");
1316 }
1317 sprintf(argc, "id=%s", id);
1318 client.uToken = Global_uToken;
1319 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1320 client.paramLen = 2;
1321 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1322 sprintf(client.param, "%d %s", cmd, argc);
1323 }
rjw61fcae32022-08-18 14:03:39 +08001324 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001325 {
rjwaf4b1612022-06-13 17:26:01 +08001326 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001327 client.uToken = Global_uToken;
1328 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1329 client.paramLen = 2;
1330 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1331 sprintf(client.param, "%d %s", cmd, argc);
1332 }
rjw61fcae32022-08-18 14:03:39 +08001333 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001334 {
1335 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1336 client.uToken = Global_uToken;
1337 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1338 client.paramLen = 2;
1339 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1340 sprintf(client.param, "%d %s", cmd, argc);
1341 }
1342 else
1343 {
1344 LYERRLOG("incoming command is invalid");
1345 return -1;
1346 }
1347 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001348 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001349 if(send_request(lynq_client_sockfd,&client)==-1)
1350 {
1351 LYERRLOG("send request fail");
1352 return -1;
1353 }
rjwed00d042022-05-25 09:18:16 +08001354 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001355 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001356 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001357 LYINFLOG(">>>>>output info:%s",out);
1358 return 0;
1359}
1360
1361int lynq_reset_apn(char *result)
1362{
1363 Parcel p;
1364 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001365 if (NULL == result)
1366 {
1367 LYERRLOG("incoming paramters error");
1368 }
rjw20006d12022-04-21 16:29:04 +08001369 client.uToken = Global_uToken;
1370 client.request = 2000 + 194;
1371 client.paramLen = 0;
1372 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1373 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001374 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001375 if (send_request(lynq_client_sockfd, &client) == -1)
1376 {
1377 LYERRLOG("send request fail");
1378 return -1;
1379 }
rjwed00d042022-05-25 09:18:16 +08001380 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001381 waitApnResult();
1382 strcpy(result, g_lynq_apn_result);
1383 LYINFLOG(">>>>>result:%s",result);
1384 return 0;
1385}
1386
rjw3bcbbf12022-04-22 16:47:18 +08001387/*Typethree add for T800 platform 2022/04/21 end*/