blob: 27f08498c2067c8ba6a3dc323ba909d49d0ec8cf [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{
Hong_Liue54db8c2023-04-21 02:37:23 -0700634 int error = -1;
635 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
636 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
637 error = lynq_setup_data_call_sp(handle,NULL,"iot_default",NULL,NULL,NULL,NULL,NULL);
638 #else
lhf81a46f2022-02-13 23:57:37 -0800639 Parcel p;
640 lynq_client_t client;
641 int resp_type = -1;
642 int request = -1;
643 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -0800644 int lynq_data_call_id = 0;
645 if(handle==NULL)
646 {
647 LYERRLOG("handle is null!!!");
648 return LYNQ_E_NULL_ANONALY;
649 }
650 client.uToken = Global_uToken;
651 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
652 client.paramLen = 0;
653 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
654 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800655 lynq_data_call_id = updateApn("default");
656 if (lynq_data_call_id < 0)
657 {
658 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
659 return -1;
660 }
rjw733b9832023-04-03 10:20:08 +0800661 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800662 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800663 if(send_request(lynq_client_sockfd,&client)==-1)
664 {
665 LYERRLOG("send request fail");
666 perror("[LYNQ_DATA] send request fail:");
667 return -1;
668 }
669 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800670 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800671 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800672 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800673 if(error==0)
674 {
rjwf9ec3832023-04-12 10:59:15 +0800675 data_timelimit = 1;
rjw20006d12022-04-21 16:29:04 +0800676 if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
lhf81a46f2022-02-13 23:57:37 -0800677 {
678 error = LYNQ_E_TIME_OUT;
679 LYERRLOG("timeout:wait data Call state fail!!!");
680 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
rjwc63abb42023-03-31 18:22:42 +0800681 if (data_invaild_error == 1)
682 {
683 data_invaild_error = 0;
684 LYERRLOG("urc apn info error!!!");
685 return 8085;
686 }
lhf81a46f2022-02-13 23:57:37 -0800687 return error;
688 }
689 *handle = lynq_data_call_id;
690 }
Hong_Liue54db8c2023-04-21 02:37:23 -0700691 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800692 return error;
693}
rjw7ee7bb42023-01-18 11:34:28 +0800694
lhf81a46f2022-02-13 23:57:37 -0800695int lynq_deactive_data_call(int *handle)
696{
697 Parcel p;
698 lynq_client_t client;
699 int resp_type = -1;
700 int request = -1;
701 int slot_id = -1;
702 int error = -1;
703 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +0800704 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -0800705 if(handle==NULL)
706 {
707 LYERRLOG("handle is null!!!");
708 return -1;
709 }
rjw1309e232022-07-22 09:54:06 +0800710 ret = handleCheck(*handle);
711 if (ret != 0)
712 {
713 LYERRLOG("incomming handle is invalid");
714 return -1;
715 }
716 lynq_data_call_id = *handle;
lhf81a46f2022-02-13 23:57:37 -0800717 client.uToken = Global_uToken;
718 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
719 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0)
720 {
721 client.paramLen = 0;
722 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
lh13586612022-01-11 21:58:58 -0800723 }
724 else
725 {
lhf81a46f2022-02-13 23:57:37 -0800726 client.paramLen = 1;
727 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
728 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
729 }
730 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800731 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800732 if(send_request(lynq_client_sockfd,&client)==-1)
733 {
734 LYERRLOG("send request fail");
735 perror("[LYNQ_DATA] send request fail:");
736 return -1;
737 }
738 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800739 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800740 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800741 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
742 cleanOnceApnTable(lynq_data_call_id);
743 return error;
744}
745int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
746{
747 Parcel p;
748 lynq_client_t client;
749 int resp_type = -1;
750 int request = -1;
751 int slot_id = -1;
752 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800753 int lynq_data_call_id = -1;
754 char *argv[10] = {};
Hong_Liue54db8c2023-04-21 02:37:23 -0700755 #ifdef GSW_RIL_CFG
756 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
757 if(handle==NULL||apnType==NULL)
758 {
759 LYERRLOG("handle or apntype is null!!!");
760 return -1;
761 }
762 #else
lhf81a46f2022-02-13 23:57:37 -0800763 if(handle==NULL||apn==NULL||apnType==NULL)
764 {
765 LYERRLOG("handle ,apn or apntype is null!!!");
766 return -1;
767 }
Hong_Liue54db8c2023-04-21 02:37:23 -0700768 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800769 if(user==NULL)
770 {
771 argv[1] = "null";
772 }
773 else
774 {
775 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800776 }
777 if(password==NULL)
778 {
lhf81a46f2022-02-13 23:57:37 -0800779 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800780 }
781 else
782 {
lhf81a46f2022-02-13 23:57:37 -0800783 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800784 }
785 if(authType==NULL)
786 {
lhf81a46f2022-02-13 23:57:37 -0800787 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800788 }
789 else
790 {
lhf81a46f2022-02-13 23:57:37 -0800791 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800792 }
793 if(normalProtocol==NULL)
794 {
lhf81a46f2022-02-13 23:57:37 -0800795 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800796 }
797 else
798 {
lhf81a46f2022-02-13 23:57:37 -0800799 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800800 }
801 if(roamingProtocol==NULL)
802 {
lhf81a46f2022-02-13 23:57:37 -0800803 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800804 }
805 else
806 {
lhf81a46f2022-02-13 23:57:37 -0800807 argv[5] = roamingProtocol;
808 }
809 client.uToken = Global_uToken;
810 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
811 client.paramLen = 7;
812 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -0700813 #ifdef GSW_RIL_CFG
814 if(NULL == apn)
815 {
816 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
817 }
818 else
819 {
820 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
821 }
822 #else
lhf81a46f2022-02-13 23:57:37 -0800823 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
Hong_Liue54db8c2023-04-21 02:37:23 -0700824 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800825 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800826 lynq_data_call_id = updateApn(apnType);
827 if (lynq_data_call_id < 0)
828 {
829 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
830 return -1;
831 }
rjw733b9832023-04-03 10:20:08 +0800832 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800833 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800834 if(send_request(lynq_client_sockfd,&client)==-1)
835 {
836 LYERRLOG("send request fail");
837 perror("[LYNQ_DATA] send request fail:");
838 return -1;
839 }
840 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800841 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800842 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800843 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800844 if(error==0)
845 {
rjwf9ec3832023-04-12 10:59:15 +0800846 data_timelimit = 1;
rjw7ee7bb42023-01-18 11:34:28 +0800847 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800848 {
849 error = LYNQ_E_TIME_OUT;
850 LYERRLOG("timeout:wait data Call state fail!!!");
851 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
rjwc63abb42023-03-31 18:22:42 +0800852 if (data_invaild_error == 1)
853 {
854 data_invaild_error = 0;
855 LYERRLOG("urc apn info error!!!");
856 return 8085;
857 }
lhf81a46f2022-02-13 23:57:37 -0800858 return error;
859 }
860 *handle = lynq_data_call_id;
861 }
862 return error;
863}
864/*
865int lynq_deactive_data_call_sp(int *handle,char *apnType)
866{
867 Parcel p;
868 lynq_client_t client;
869 int resp_type = -1;
870 int request = -1;
871 int slot_id = -1;
872 int error = -1;
873 if(handle==NULL||apnType==NULL)
874 {
875 LYERRLOG("handle is null!!!");
876 return -1;
877 }
878 client.uToken = Global_uToken;
879 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
880 client.paramLen = 1;
881 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
882 sprintf(client.param,"%s",apnType);
883 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
884 if(send_request(lynq_client_sockfd,&client)==-1)
885 {
886 LYERRLOG("send request fail");
887 perror("[LYNQ_DATA] send request fail:");
888 return -1;
889 }
890 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800891 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800892 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
893 return error;
894}
895*/
896int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
897{
898 Parcel p;
899 lynq_client_t client;
900 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800901 int token;
902 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800903 int slot_id = -1;
904 int error = -1;
905 int version =0;
906 int num = 0;
lhf81a46f2022-02-13 23:57:37 -0800907 char *temp_char = NULL;
908 if(dataCallList==NULL)
909 {
910 LYERRLOG("dataCallList is null!!!");
911 return -1;
912 }
913 client.uToken = Global_uToken;
914 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
915 client.paramLen = 0;
916 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
917 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800918 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800919 if(send_request(lynq_client_sockfd,&client)==-1)
920 {
921 LYERRLOG("send request fail");
922 perror("[LYNQ_DATA] send request fail:");
923 return -1;
924 }
925 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800926 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800927 if(p.dataAvail() > 0)
928 {
rjw0fb4ccb2022-09-16 19:12:35 +0800929 p.readInt32(&resp_type);
930 p.readInt32(&token);
931 p.readInt32(&request);
932 p.readInt32(&slot_id);
933 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +0800934 }
935 else
936 {
937 return -1;
938 }
lhf81a46f2022-02-13 23:57:37 -0800939 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
940 p.readInt32(&version);
941 if(version==11)
942 {
943 p.readInt32(&num);
944 *realNum = num;
945 for (int i = 0; i < num; i++)
946 {
947 p.readInt32(&dataCallList[i].status);
948 p.readInt32(&dataCallList[i].suggestedRetryTime);
949 p.readInt32(&dataCallList[i].cid);
950 p.readInt32(&dataCallList[i].active);
951 temp_char = strdupReadString(p);
952 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
953 temp_char = strdupReadString(p);
954 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
955 temp_char = strdupReadString(p);
956 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
957 temp_char = strdupReadString(p);
958 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
959 temp_char = strdupReadString(p);
960 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
961 temp_char = strdupReadString(p);
962 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
963 p.readInt32(&dataCallList[i].mtu);
964 }
965 }
966 return error;
967}
968int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
969{
970 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
971 int number = 0;
972 int lynq_data_call_id = 0;
973 int error = 0;
974 lynq_data_call_id = *handle;
975 if(handle==NULL)
976 {
977 LYERRLOG("handle is NULL");
978 return LYNQ_E_NULL_ANONALY;
979 }
rjw3938f262023-03-08 16:09:28 +0800980 if (*handle<0 && handle>8)
981 {
982 LYERRLOG("handle value error");
983 }
984 LYINFLOG("incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800985 memset(interDataCallList,0,sizeof(interDataCallList));
986 error = getDataCallLists(interDataCallList,&number);
987 if(error == 0)
988 {
989 for(int i = 0;i < number;i++)
990 {
991 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
992 {
993 dataCallList->active = interDataCallList[i].active;
994 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
995 dataCallList->cid = interDataCallList[i].cid;
996 dataCallList->status = interDataCallList[i].status;
997 dataCallList->mtu = interDataCallList[i].mtu;
998 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
999 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1000 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1001 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1002 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1003 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1004 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1005 }
1006 }
1007 }
1008 return error;
1009}
1010int lynq_wait_data_call_state_change(int *handle)
1011{
rjwc3d6e582023-03-28 17:19:11 +08001012 if (data_waiting_status == 1)
1013 {
1014 LYDBGLOG("some thread is waiting");
1015 return -3;
1016 }
1017 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1018 if (s_data_urc_wait_list.empty())
1019 {
1020 LYDBGLOG("start wait");
1021 data_waiting_status = 1;
1022 waitPdnChange();
1023 }
1024 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001025 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001026
1027 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1028 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001029 if (iter != s_data_urc_wait_list.end())
1030 {
1031 *handle = *iter;
1032 }
rjw7ee7bb42023-01-18 11:34:28 +08001033 s_data_urc_wait_list.erase(iter);
1034 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1035
rjw3938f262023-03-08 16:09:28 +08001036 LYINFLOG("lynq data call id:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001037 return 0;
1038}
1039/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001040
1041/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001042
1043int 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 +08001044{
1045 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001046 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001047 {
rjw61fcae32022-08-18 14:03:39 +08001048 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001049 }
rjw61fcae32022-08-18 14:03:39 +08001050 else
rjw0cdacbc2022-06-22 10:51:07 +08001051 {
rjw61fcae32022-08-18 14:03:39 +08001052 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001053 }
rjw20006d12022-04-21 16:29:04 +08001054 if (mcc == NULL)
1055 {
1056 sprintf(strtmp[1], "mcc=;");
1057 }
1058 else
1059 {
1060 sprintf(strtmp[1], "mcc=%s;", mcc);
1061 }
1062 if (mnc == NULL)
1063 {
rjw61fcae32022-08-18 14:03:39 +08001064 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001065 }
1066 else
1067 {
1068 sprintf(strtmp[2], "mnc=%s;", mnc);
1069 }
1070 if (apn == NULL)
1071 {
1072 sprintf(strtmp[3], "apn=;");
1073 }
1074 else
1075 {
1076 sprintf(strtmp[3], "apn=%s;", apn);
1077 }
1078 if (apntype == NULL)
1079 {
1080 sprintf(strtmp[4], "apntype=;");
1081 }
1082 else
1083 {
1084 sprintf(strtmp[4], "apntype=%s;", apntype);
1085 }
1086 if (user == NULL)
1087 {
1088 sprintf(strtmp[5], "user=;");
1089 }
1090 else
1091 {
1092 sprintf(strtmp[5], "user=%s;", user);
1093 }
1094 if (password == NULL)
1095 {
1096 sprintf(strtmp[6], "password=;");
1097 }
1098 else
1099 {
1100 sprintf(strtmp[6], "password=%s;", password);
1101 }
1102 if (normalprotocol == NULL)
1103 {
1104 sprintf(strtmp[7], "normalprotocol=;");
1105 }
1106 else
1107 {
1108 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1109 }
1110 if (roamingprotocol == NULL)
1111 {
1112 sprintf(strtmp[8], "roamingprotocol=;");
1113 }
1114 else
1115 {
1116 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1117 }
1118 if (carrier == NULL)
1119 {
1120 sprintf(strtmp[9], "carrier=;");
1121 }
1122 else
1123 {
1124 sprintf(strtmp[9], "carrier=%s;", carrier);
1125 }
rjw61fcae32022-08-18 14:03:39 +08001126 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 +08001127
rjw20006d12022-04-21 16:29:04 +08001128 return 0;
1129}
1130
1131int 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)
1132{
1133 char strtmp[10][32];
1134 if (id == NULL)
1135 {
1136 sprintf(strtmp[0], "id=;");
1137 }
1138 else
1139 {
1140 sprintf(strtmp[0], "id=%s;", id);
1141 }
1142 if (mcc == NULL)
1143 {
1144 sprintf(strtmp[1], "mcc=;");
1145 }
1146 else
1147 {
1148 sprintf(strtmp[1], "mcc=%s;", mcc);
1149 }
1150 if (mnc == NULL)
1151 {
1152 sprintf(strtmp[2], "mnc=;");
1153 }
1154 else
1155 {
1156 sprintf(strtmp[2], "mnc=%s;", mnc);
1157 }
1158 if (apn == NULL)
1159 {
1160 sprintf(strtmp[3], "apn=;");
1161 }
1162 else
1163 {
1164 sprintf(strtmp[3], "apn=%s;", apn);
1165 }
1166 if (apntype == NULL)
1167 {
1168 sprintf(strtmp[4], "apntype=;");
1169 }
1170 else
1171 {
1172 sprintf(strtmp[4], "apntype=%s;", apntype);
1173 }
1174 if (user == NULL)
1175 {
1176 sprintf(strtmp[5], "user=;");
1177 }
1178 else
1179 {
1180 sprintf(strtmp[5], "user=%s;", user);
1181 }
1182 if (password == NULL)
1183 {
1184 sprintf(strtmp[6], "password=;");
1185 }
1186 else
1187 {
1188 sprintf(strtmp[6], "password=%s;", password);
1189 }
1190 if (normalprotocol == NULL)
1191 {
1192 sprintf(strtmp[7], "normalprotocol=;");
1193 }
1194 else
1195 {
1196 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1197 }
1198 if (roamingprotocol == NULL)
1199 {
1200 sprintf(strtmp[8], "roamingprotocol=;");
1201 }
1202 else
1203 {
1204 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1205 }
1206 if (carrier == NULL)
1207 {
1208 sprintf(strtmp[9], "carrier=;");
1209 }
1210 else
1211 {
1212 sprintf(strtmp[9], "carrier=%s;", carrier);
1213 }
1214 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]);
1215 return 0;
1216}
1217
rjwaf4b1612022-06-13 17:26:01 +08001218
1219int 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)
1220{
1221 char strtmp[10][32];
1222 if (id == NULL)
1223 {
1224 sprintf(strtmp[0], "");
1225 }
1226 else
1227 {
1228 sprintf(strtmp[0], "id=%s;", id);
1229 }
1230 if (mcc == NULL)
1231 {
1232 sprintf(strtmp[1], "");
1233 }
1234 else
1235 {
1236 sprintf(strtmp[1], "mcc=%s;", mcc);
1237 }
1238 if (mnc == NULL)
1239 {
1240 sprintf(strtmp[2], "");
1241 }
1242 else
1243 {
1244 sprintf(strtmp[2], "mnc=%s;", mnc);
1245 }
1246 if (apn == NULL)
1247 {
1248 sprintf(strtmp[3], "");
1249 }
1250 else
1251 {
1252 sprintf(strtmp[3], "apn=%s;", apn);
1253 }
1254 if (apntype == NULL)
1255 {
1256 sprintf(strtmp[4], "");
1257 }
1258 else
1259 {
1260 sprintf(strtmp[4], "apntype=%s;", apntype);
1261 }
1262 if (user == NULL)
1263 {
1264 sprintf(strtmp[5], "");
1265 }
1266 else
1267 {
1268 sprintf(strtmp[5], "user=%s;", user);
1269 }
1270 if (password == NULL)
1271 {
1272 sprintf(strtmp[6], "");
1273 }
1274 else
1275 {
1276 sprintf(strtmp[6], "password=%s;", password);
1277 }
1278 if (normalprotocol == NULL)
1279 {
1280 sprintf(strtmp[7], "");
1281 }
1282 else
1283 {
1284 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1285 }
1286 if (roamingprotocol == NULL)
1287 {
1288 sprintf(strtmp[8], "");
1289 }
1290 else
1291 {
1292 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1293 }
1294 if (carrier == NULL)
1295 {
1296 sprintf(strtmp[9], "");
1297 }
1298 else
1299 {
1300 sprintf(strtmp[9], "carrier=%s;", carrier);
1301 }
1302 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]);
1303 return 0;
1304}
1305
rjw20006d12022-04-21 16:29:04 +08001306static char *lynqStrdupReadString(Parcel &p)
1307{
1308 size_t stringlen;
1309 const char16_t *s16;
1310
1311 s16 = p.readString16Inplace(&stringlen);
1312 return strndup16to8(s16, stringlen);
1313}
1314
1315int 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)
1316{
1317 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1318 {
1319 LYERRLOG("There are no valid parameters");
1320 return -1;
1321 }
1322 lynq_client_t client;
1323 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001324 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001325 Parcel p;
1326 if (cmd == 0) // insert apn db
1327 {
rjw61fcae32022-08-18 14:03:39 +08001328 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1329
rjw20006d12022-04-21 16:29:04 +08001330 client.uToken = Global_uToken;
1331 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1332 client.paramLen = 2;
1333 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1334 sprintf(client.param, "%d %s", cmd, argc);
1335 }
rjw61fcae32022-08-18 14:03:39 +08001336 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001337 {
1338 if (NULL == id)
1339 {
1340 LYERRLOG("id is NULL!!!please input id: ");
1341 }
1342 sprintf(argc, "id=%s", id);
1343 client.uToken = Global_uToken;
1344 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1345 client.paramLen = 2;
1346 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1347 sprintf(client.param, "%d %s", cmd, argc);
1348 }
rjw61fcae32022-08-18 14:03:39 +08001349 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001350 {
rjwaf4b1612022-06-13 17:26:01 +08001351 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001352 client.uToken = Global_uToken;
1353 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1354 client.paramLen = 2;
1355 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1356 sprintf(client.param, "%d %s", cmd, argc);
1357 }
rjw61fcae32022-08-18 14:03:39 +08001358 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001359 {
1360 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1361 client.uToken = Global_uToken;
1362 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1363 client.paramLen = 2;
1364 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1365 sprintf(client.param, "%d %s", cmd, argc);
1366 }
1367 else
1368 {
1369 LYERRLOG("incoming command is invalid");
1370 return -1;
1371 }
1372 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001373 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001374 if(send_request(lynq_client_sockfd,&client)==-1)
1375 {
1376 LYERRLOG("send request fail");
1377 return -1;
1378 }
rjwed00d042022-05-25 09:18:16 +08001379 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001380 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001381 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001382 LYINFLOG(">>>>>output info:%s",out);
1383 return 0;
1384}
1385
1386int lynq_reset_apn(char *result)
1387{
1388 Parcel p;
1389 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001390 if (NULL == result)
1391 {
1392 LYERRLOG("incoming paramters error");
1393 }
rjw20006d12022-04-21 16:29:04 +08001394 client.uToken = Global_uToken;
1395 client.request = 2000 + 194;
1396 client.paramLen = 0;
1397 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1398 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001399 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001400 if (send_request(lynq_client_sockfd, &client) == -1)
1401 {
1402 LYERRLOG("send request fail");
1403 return -1;
1404 }
rjwed00d042022-05-25 09:18:16 +08001405 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001406 waitApnResult();
1407 strcpy(result, g_lynq_apn_result);
1408 LYINFLOG(">>>>>result:%s",result);
1409 return 0;
1410}
1411
rjw3bcbbf12022-04-22 16:47:18 +08001412/*Typethree add for T800 platform 2022/04/21 end*/