blob: eee2f6cc86f649abb58790e6a5dd945f2e0cec24 [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__);
Hong_Liue9879152023-04-25 20:40:26 -0700637 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -0700638 #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
Hong_Liue3d35262023-05-04 00:20:12 -0700719 client.paramLen = 0;
720 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
721 #ifdef GSW_RIL_CFG
722 client.paramLen = 1;
723 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
724 #else
725 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -0800726 {
lhf81a46f2022-02-13 23:57:37 -0800727 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -0800728 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
729 }
Hong_Liue3d35262023-05-04 00:20:12 -0700730 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800731 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800732 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800733 if(send_request(lynq_client_sockfd,&client)==-1)
734 {
735 LYERRLOG("send request fail");
736 perror("[LYNQ_DATA] send request fail:");
737 return -1;
738 }
739 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800740 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800741 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800742 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
743 cleanOnceApnTable(lynq_data_call_id);
744 return error;
745}
746int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
747{
748 Parcel p;
749 lynq_client_t client;
750 int resp_type = -1;
751 int request = -1;
752 int slot_id = -1;
753 int error = -1;
lhf81a46f2022-02-13 23:57:37 -0800754 int lynq_data_call_id = -1;
755 char *argv[10] = {};
Hong_Liue54db8c2023-04-21 02:37:23 -0700756 #ifdef GSW_RIL_CFG
757 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
758 if(handle==NULL||apnType==NULL)
759 {
760 LYERRLOG("handle or apntype is null!!!");
761 return -1;
762 }
763 #else
lhf81a46f2022-02-13 23:57:37 -0800764 if(handle==NULL||apn==NULL||apnType==NULL)
765 {
766 LYERRLOG("handle ,apn or apntype is null!!!");
767 return -1;
768 }
Hong_Liue54db8c2023-04-21 02:37:23 -0700769 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800770 if(user==NULL)
771 {
772 argv[1] = "null";
773 }
774 else
775 {
776 argv[1] = user;
lh13586612022-01-11 21:58:58 -0800777 }
778 if(password==NULL)
779 {
lhf81a46f2022-02-13 23:57:37 -0800780 argv[2] = "null";
lh13586612022-01-11 21:58:58 -0800781 }
782 else
783 {
lhf81a46f2022-02-13 23:57:37 -0800784 argv[2] = password;
lh13586612022-01-11 21:58:58 -0800785 }
786 if(authType==NULL)
787 {
lhf81a46f2022-02-13 23:57:37 -0800788 argv[3] = "null";
lh13586612022-01-11 21:58:58 -0800789 }
790 else
791 {
lhf81a46f2022-02-13 23:57:37 -0800792 argv[3] = authType;
lh13586612022-01-11 21:58:58 -0800793 }
794 if(normalProtocol==NULL)
795 {
lhf81a46f2022-02-13 23:57:37 -0800796 argv[4] = "null";
lh13586612022-01-11 21:58:58 -0800797 }
798 else
799 {
lhf81a46f2022-02-13 23:57:37 -0800800 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -0800801 }
802 if(roamingProtocol==NULL)
803 {
lhf81a46f2022-02-13 23:57:37 -0800804 argv[5] = "null";
lh13586612022-01-11 21:58:58 -0800805 }
806 else
807 {
lhf81a46f2022-02-13 23:57:37 -0800808 argv[5] = roamingProtocol;
809 }
810 client.uToken = Global_uToken;
811 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
812 client.paramLen = 7;
813 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -0700814 #ifdef GSW_RIL_CFG
815 if(NULL == apn)
816 {
817 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
818 }
819 else
820 {
821 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
822 }
823 #else
lhf81a46f2022-02-13 23:57:37 -0800824 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 -0700825 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -0800826 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwc63abb42023-03-31 18:22:42 +0800827 lynq_data_call_id = updateApn(apnType);
828 if (lynq_data_call_id < 0)
829 {
830 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
831 return -1;
832 }
rjw733b9832023-04-03 10:20:08 +0800833 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800834 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800835 if(send_request(lynq_client_sockfd,&client)==-1)
836 {
837 LYERRLOG("send request fail");
838 perror("[LYNQ_DATA] send request fail:");
839 return -1;
840 }
841 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800842 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800843 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800844 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800845 if(error==0)
846 {
rjwf9ec3832023-04-12 10:59:15 +0800847 data_timelimit = 1;
rjw7ee7bb42023-01-18 11:34:28 +0800848 if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
lhf81a46f2022-02-13 23:57:37 -0800849 {
850 error = LYNQ_E_TIME_OUT;
851 LYERRLOG("timeout:wait data Call state fail!!!");
852 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
rjwc63abb42023-03-31 18:22:42 +0800853 if (data_invaild_error == 1)
854 {
855 data_invaild_error = 0;
856 LYERRLOG("urc apn info error!!!");
857 return 8085;
858 }
lhf81a46f2022-02-13 23:57:37 -0800859 return error;
860 }
861 *handle = lynq_data_call_id;
862 }
863 return error;
864}
865/*
866int lynq_deactive_data_call_sp(int *handle,char *apnType)
867{
868 Parcel p;
869 lynq_client_t client;
870 int resp_type = -1;
871 int request = -1;
872 int slot_id = -1;
873 int error = -1;
874 if(handle==NULL||apnType==NULL)
875 {
876 LYERRLOG("handle is null!!!");
877 return -1;
878 }
879 client.uToken = Global_uToken;
880 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
881 client.paramLen = 1;
882 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
883 sprintf(client.param,"%s",apnType);
884 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
885 if(send_request(lynq_client_sockfd,&client)==-1)
886 {
887 LYERRLOG("send request fail");
888 perror("[LYNQ_DATA] send request fail:");
889 return -1;
890 }
891 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +0800892 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -0800893 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
894 return error;
895}
896*/
897int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
898{
899 Parcel p;
900 lynq_client_t client;
901 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +0800902 int token;
903 int request = -1;
lhf81a46f2022-02-13 23:57:37 -0800904 int slot_id = -1;
905 int error = -1;
906 int version =0;
907 int num = 0;
lhf81a46f2022-02-13 23:57:37 -0800908 char *temp_char = NULL;
909 if(dataCallList==NULL)
910 {
911 LYERRLOG("dataCallList is null!!!");
912 return -1;
913 }
914 client.uToken = Global_uToken;
915 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
916 client.paramLen = 0;
917 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
918 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +0800919 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800920 if(send_request(lynq_client_sockfd,&client)==-1)
921 {
922 LYERRLOG("send request fail");
923 perror("[LYNQ_DATA] send request fail:");
924 return -1;
925 }
926 get_response(lynq_client_sockfd,p);
rjwed00d042022-05-25 09:18:16 +0800927 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjwfa532972022-09-16 13:39:41 +0800928 if(p.dataAvail() > 0)
929 {
rjw0fb4ccb2022-09-16 19:12:35 +0800930 p.readInt32(&resp_type);
931 p.readInt32(&token);
932 p.readInt32(&request);
933 p.readInt32(&slot_id);
934 p.readInt32(&error);
rjwfa532972022-09-16 13:39:41 +0800935 }
936 else
937 {
938 return -1;
939 }
lhf81a46f2022-02-13 23:57:37 -0800940 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
941 p.readInt32(&version);
942 if(version==11)
943 {
944 p.readInt32(&num);
945 *realNum = num;
946 for (int i = 0; i < num; i++)
947 {
948 p.readInt32(&dataCallList[i].status);
949 p.readInt32(&dataCallList[i].suggestedRetryTime);
950 p.readInt32(&dataCallList[i].cid);
951 p.readInt32(&dataCallList[i].active);
952 temp_char = strdupReadString(p);
953 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
954 temp_char = strdupReadString(p);
955 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
956 temp_char = strdupReadString(p);
957 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
958 temp_char = strdupReadString(p);
959 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
960 temp_char = strdupReadString(p);
961 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
962 temp_char = strdupReadString(p);
963 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
964 p.readInt32(&dataCallList[i].mtu);
965 }
966 }
967 return error;
968}
969int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
970{
971 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
972 int number = 0;
973 int lynq_data_call_id = 0;
974 int error = 0;
975 lynq_data_call_id = *handle;
976 if(handle==NULL)
977 {
978 LYERRLOG("handle is NULL");
979 return LYNQ_E_NULL_ANONALY;
980 }
rjw3938f262023-03-08 16:09:28 +0800981 if (*handle<0 && handle>8)
982 {
983 LYERRLOG("handle value error");
984 }
985 LYINFLOG("incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -0800986 memset(interDataCallList,0,sizeof(interDataCallList));
987 error = getDataCallLists(interDataCallList,&number);
988 if(error == 0)
989 {
990 for(int i = 0;i < number;i++)
991 {
992 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
993 {
994 dataCallList->active = interDataCallList[i].active;
995 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
996 dataCallList->cid = interDataCallList[i].cid;
997 dataCallList->status = interDataCallList[i].status;
998 dataCallList->mtu = interDataCallList[i].mtu;
999 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1000 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1001 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1002 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1003 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1004 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1005 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1006 }
1007 }
1008 }
1009 return error;
1010}
1011int lynq_wait_data_call_state_change(int *handle)
1012{
rjwc3d6e582023-03-28 17:19:11 +08001013 if (data_waiting_status == 1)
1014 {
1015 LYDBGLOG("some thread is waiting");
1016 return -3;
1017 }
1018 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1019 if (s_data_urc_wait_list.empty())
1020 {
1021 LYDBGLOG("start wait");
1022 data_waiting_status = 1;
1023 waitPdnChange();
1024 }
1025 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001026 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001027
1028 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1029 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001030 if (iter != s_data_urc_wait_list.end())
1031 {
1032 *handle = *iter;
1033 }
rjw7ee7bb42023-01-18 11:34:28 +08001034 s_data_urc_wait_list.erase(iter);
1035 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1036
rjw3938f262023-03-08 16:09:28 +08001037 LYINFLOG("lynq data call id:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001038 return 0;
1039}
1040/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001041
1042/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001043
1044int 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 +08001045{
1046 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001047 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001048 {
rjw61fcae32022-08-18 14:03:39 +08001049 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001050 }
rjw61fcae32022-08-18 14:03:39 +08001051 else
rjw0cdacbc2022-06-22 10:51:07 +08001052 {
rjw61fcae32022-08-18 14:03:39 +08001053 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001054 }
rjw20006d12022-04-21 16:29:04 +08001055 if (mcc == NULL)
1056 {
1057 sprintf(strtmp[1], "mcc=;");
1058 }
1059 else
1060 {
1061 sprintf(strtmp[1], "mcc=%s;", mcc);
1062 }
1063 if (mnc == NULL)
1064 {
rjw61fcae32022-08-18 14:03:39 +08001065 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001066 }
1067 else
1068 {
1069 sprintf(strtmp[2], "mnc=%s;", mnc);
1070 }
1071 if (apn == NULL)
1072 {
1073 sprintf(strtmp[3], "apn=;");
1074 }
1075 else
1076 {
1077 sprintf(strtmp[3], "apn=%s;", apn);
1078 }
1079 if (apntype == NULL)
1080 {
1081 sprintf(strtmp[4], "apntype=;");
1082 }
1083 else
1084 {
1085 sprintf(strtmp[4], "apntype=%s;", apntype);
1086 }
1087 if (user == NULL)
1088 {
1089 sprintf(strtmp[5], "user=;");
1090 }
1091 else
1092 {
1093 sprintf(strtmp[5], "user=%s;", user);
1094 }
1095 if (password == NULL)
1096 {
1097 sprintf(strtmp[6], "password=;");
1098 }
1099 else
1100 {
1101 sprintf(strtmp[6], "password=%s;", password);
1102 }
1103 if (normalprotocol == NULL)
1104 {
1105 sprintf(strtmp[7], "normalprotocol=;");
1106 }
1107 else
1108 {
1109 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1110 }
1111 if (roamingprotocol == NULL)
1112 {
1113 sprintf(strtmp[8], "roamingprotocol=;");
1114 }
1115 else
1116 {
1117 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1118 }
1119 if (carrier == NULL)
1120 {
1121 sprintf(strtmp[9], "carrier=;");
1122 }
1123 else
1124 {
1125 sprintf(strtmp[9], "carrier=%s;", carrier);
1126 }
rjw61fcae32022-08-18 14:03:39 +08001127 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 +08001128
rjw20006d12022-04-21 16:29:04 +08001129 return 0;
1130}
1131
1132int 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)
1133{
1134 char strtmp[10][32];
1135 if (id == NULL)
1136 {
1137 sprintf(strtmp[0], "id=;");
1138 }
1139 else
1140 {
1141 sprintf(strtmp[0], "id=%s;", id);
1142 }
1143 if (mcc == NULL)
1144 {
1145 sprintf(strtmp[1], "mcc=;");
1146 }
1147 else
1148 {
1149 sprintf(strtmp[1], "mcc=%s;", mcc);
1150 }
1151 if (mnc == NULL)
1152 {
1153 sprintf(strtmp[2], "mnc=;");
1154 }
1155 else
1156 {
1157 sprintf(strtmp[2], "mnc=%s;", mnc);
1158 }
1159 if (apn == NULL)
1160 {
1161 sprintf(strtmp[3], "apn=;");
1162 }
1163 else
1164 {
1165 sprintf(strtmp[3], "apn=%s;", apn);
1166 }
1167 if (apntype == NULL)
1168 {
1169 sprintf(strtmp[4], "apntype=;");
1170 }
1171 else
1172 {
1173 sprintf(strtmp[4], "apntype=%s;", apntype);
1174 }
1175 if (user == NULL)
1176 {
1177 sprintf(strtmp[5], "user=;");
1178 }
1179 else
1180 {
1181 sprintf(strtmp[5], "user=%s;", user);
1182 }
1183 if (password == NULL)
1184 {
1185 sprintf(strtmp[6], "password=;");
1186 }
1187 else
1188 {
1189 sprintf(strtmp[6], "password=%s;", password);
1190 }
1191 if (normalprotocol == NULL)
1192 {
1193 sprintf(strtmp[7], "normalprotocol=;");
1194 }
1195 else
1196 {
1197 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1198 }
1199 if (roamingprotocol == NULL)
1200 {
1201 sprintf(strtmp[8], "roamingprotocol=;");
1202 }
1203 else
1204 {
1205 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1206 }
1207 if (carrier == NULL)
1208 {
1209 sprintf(strtmp[9], "carrier=;");
1210 }
1211 else
1212 {
1213 sprintf(strtmp[9], "carrier=%s;", carrier);
1214 }
1215 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]);
1216 return 0;
1217}
1218
rjwaf4b1612022-06-13 17:26:01 +08001219
1220int 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)
1221{
1222 char strtmp[10][32];
1223 if (id == NULL)
1224 {
1225 sprintf(strtmp[0], "");
1226 }
1227 else
1228 {
1229 sprintf(strtmp[0], "id=%s;", id);
1230 }
1231 if (mcc == NULL)
1232 {
1233 sprintf(strtmp[1], "");
1234 }
1235 else
1236 {
1237 sprintf(strtmp[1], "mcc=%s;", mcc);
1238 }
1239 if (mnc == NULL)
1240 {
1241 sprintf(strtmp[2], "");
1242 }
1243 else
1244 {
1245 sprintf(strtmp[2], "mnc=%s;", mnc);
1246 }
1247 if (apn == NULL)
1248 {
1249 sprintf(strtmp[3], "");
1250 }
1251 else
1252 {
1253 sprintf(strtmp[3], "apn=%s;", apn);
1254 }
1255 if (apntype == NULL)
1256 {
1257 sprintf(strtmp[4], "");
1258 }
1259 else
1260 {
1261 sprintf(strtmp[4], "apntype=%s;", apntype);
1262 }
1263 if (user == NULL)
1264 {
1265 sprintf(strtmp[5], "");
1266 }
1267 else
1268 {
1269 sprintf(strtmp[5], "user=%s;", user);
1270 }
1271 if (password == NULL)
1272 {
1273 sprintf(strtmp[6], "");
1274 }
1275 else
1276 {
1277 sprintf(strtmp[6], "password=%s;", password);
1278 }
1279 if (normalprotocol == NULL)
1280 {
1281 sprintf(strtmp[7], "");
1282 }
1283 else
1284 {
1285 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1286 }
1287 if (roamingprotocol == NULL)
1288 {
1289 sprintf(strtmp[8], "");
1290 }
1291 else
1292 {
1293 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1294 }
1295 if (carrier == NULL)
1296 {
1297 sprintf(strtmp[9], "");
1298 }
1299 else
1300 {
1301 sprintf(strtmp[9], "carrier=%s;", carrier);
1302 }
1303 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]);
1304 return 0;
1305}
1306
rjw20006d12022-04-21 16:29:04 +08001307static char *lynqStrdupReadString(Parcel &p)
1308{
1309 size_t stringlen;
1310 const char16_t *s16;
1311
1312 s16 = p.readString16Inplace(&stringlen);
1313 return strndup16to8(s16, stringlen);
1314}
1315
1316int 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)
1317{
1318 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1319 {
1320 LYERRLOG("There are no valid parameters");
1321 return -1;
1322 }
1323 lynq_client_t client;
1324 char argc[512];
rjw0cdacbc2022-06-22 10:51:07 +08001325 int res = 0;
rjw20006d12022-04-21 16:29:04 +08001326 Parcel p;
1327 if (cmd == 0) // insert apn db
1328 {
rjw61fcae32022-08-18 14:03:39 +08001329 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1330
rjw20006d12022-04-21 16:29:04 +08001331 client.uToken = Global_uToken;
1332 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1333 client.paramLen = 2;
1334 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1335 sprintf(client.param, "%d %s", cmd, argc);
1336 }
rjw61fcae32022-08-18 14:03:39 +08001337 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001338 {
1339 if (NULL == id)
1340 {
1341 LYERRLOG("id is NULL!!!please input id: ");
1342 }
1343 sprintf(argc, "id=%s", id);
1344 client.uToken = Global_uToken;
1345 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1346 client.paramLen = 2;
1347 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1348 sprintf(client.param, "%d %s", cmd, argc);
1349 }
rjw61fcae32022-08-18 14:03:39 +08001350 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001351 {
rjwaf4b1612022-06-13 17:26:01 +08001352 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
rjw20006d12022-04-21 16:29:04 +08001353 client.uToken = Global_uToken;
1354 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1355 client.paramLen = 2;
1356 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1357 sprintf(client.param, "%d %s", cmd, argc);
1358 }
rjw61fcae32022-08-18 14:03:39 +08001359 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001360 {
1361 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
1362 client.uToken = Global_uToken;
1363 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1364 client.paramLen = 2;
1365 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1366 sprintf(client.param, "%d %s", cmd, argc);
1367 }
1368 else
1369 {
1370 LYERRLOG("incoming command is invalid");
1371 return -1;
1372 }
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();
rjw3bcbbf12022-04-22 16:47:18 +08001382 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001383 LYINFLOG(">>>>>output info:%s",out);
1384 return 0;
1385}
1386
1387int lynq_reset_apn(char *result)
1388{
1389 Parcel p;
1390 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001391 if (NULL == result)
1392 {
1393 LYERRLOG("incoming paramters error");
1394 }
rjw20006d12022-04-21 16:29:04 +08001395 client.uToken = Global_uToken;
1396 client.request = 2000 + 194;
1397 client.paramLen = 0;
1398 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1399 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001400 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001401 if (send_request(lynq_client_sockfd, &client) == -1)
1402 {
1403 LYERRLOG("send request fail");
1404 return -1;
1405 }
rjwed00d042022-05-25 09:18:16 +08001406 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001407 waitApnResult();
1408 strcpy(result, g_lynq_apn_result);
1409 LYINFLOG(">>>>>result:%s",result);
1410 return 0;
1411}
1412
rjw3bcbbf12022-04-22 16:47:18 +08001413/*Typethree add for T800 platform 2022/04/21 end*/