blob: 248000d7c451455b7610fc4637add280d26e5e98 [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
lh8d290112023-10-22 20:53:06 -070022#define LYNQ_RIL_FWK_IP "127.0.0.1"
23
lhf81a46f2022-02-13 23:57:37 -080024#define LYNQ_REC_BUF 8192
25#define LYNQ_REQUEST_PARAM_BUF 8192
26#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
27#define USER_LOG_TAG "LYNQ_DATA"
28
rjw0cdacbc2022-06-22 10:51:07 +080029#define LYNQ_DATA_UCI_BUF 258
Hong_Liu25edfe72023-06-16 01:13:42 -070030#define LYNQ_DATA_TIME_OUT 1000*120
xy.hef5d74f12023-10-23 06:48:52 -070031#define TELEPHONY_RESTART 10
Hong_Liu7163bbe2023-06-04 03:03:44 -070032
rjw61fcae32022-08-18 14:03:39 +080033
lhf81a46f2022-02-13 23:57:37 -080034using ::android::Parcel;
35typedef struct{
36 int uToken;
37 int request;
38 int paramLen;
39 char param[LYNQ_REQUEST_PARAM_BUF];
40}lynq_client_t;
lh13586612022-01-11 21:58:58 -080041typedef enum{
42 LYNQ_E_CARDSTATE_ERROR=8000,
43 /* The voice service state is out of service*/
44 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
45 /* The voice service state is EMERGENCY_ONLY*/
46 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
47 /* The radio power is power off*/
48 LYNQ_E_STATE_POWER_OFF=8003,
49 LYNQ_E_TIME_OUT=8004,
50 /*create or open sms DB fail */
51 LYNQ_E_SMS_DB_FAIL=8005,
52 /*Failed to execute sql statement*/
53 LYNQ_E_SMS_SQL_FAIL = 8006,
54 LYNQ_E_SMS_NOT_FIND = 8007,
Hong_Liu25edfe72023-06-16 01:13:42 -070055 LYNQ_E_GET_RESP_FAIL = 8008,
56 LYNQ_E_NOT_THIS_APN = 8087,
57 LYNQ_E_NOT_ANY_APN = 8088,
58 LYNQ_E_MD_NOT_READY = 8089,
lh13586612022-01-11 21:58:58 -080059 /* The logic conflict*/
60 LYNQ_E_CONFLICT=9000,
61 /*Null anomaly*/
62 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080063}LYNQ_E;
64
lha62e0882023-10-31 05:17:11 -070065typedef enum {
66 PDN_IDLE,
67 PDN_CONNECTING,
68 PDN_CONNECTED,
69 PDN_DISCONNECTING,
70 PDN_DISCONNECTED,
71 PDN_RETRYING,
72 PDN_FAILED,
73 PDN_SCANNING,
74 PDN_TIMEOUT_CANCEL,
75} RIL_Data_Call_PdnState;
76
lhf81a46f2022-02-13 23:57:37 -080077int lynq_client_sockfd = 0;
78int Global_uToken = 0;
Hong_Liu7e1b85e2023-05-16 05:51:57 -070079struct sockaddr_in lynq_data_socket_server_addr;
80int lynq_data_socket_server_addr_len;
rjw7ee7bb42023-01-18 11:34:28 +080081
lhf81a46f2022-02-13 23:57:37 -080082int lynq_data_call_change_id = -1;
xy.hef5d74f12023-10-23 06:48:52 -070083int lynq_telephony_restart_g = 0;
lhf81a46f2022-02-13 23:57:37 -080084pthread_t lynq_data_tid =-1;
85static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
86static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080087
Hong_Liu25edfe72023-06-16 01:13:42 -070088static pthread_mutex_t s_data_call_deactived_mutex = PTHREAD_MUTEX_INITIALIZER;
89static pthread_cond_t s_data_call_deactived_cond = PTHREAD_COND_INITIALIZER;
90
91
rjw20006d12022-04-21 16:29:04 +080092static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
93static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080094static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
95static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER;
rjwed00d042022-05-25 09:18:16 +080096/**g_lynq_data_sendto_mutex
97* @brief mark data send request mutex
98*/
99static pthread_mutex_t g_lynq_data_sendto_mutex;
rjwf9ec3832023-04-12 10:59:15 +0800100/*This value data the state of the wait*/
rjwc3d6e582023-03-28 17:19:11 +0800101static int data_waiting_status = 0;
rjwf9ec3832023-04-12 10:59:15 +0800102/*The value indicates that 8085 error occurs in data*/
rjwc63abb42023-03-31 18:22:42 +0800103static int data_invaild_error = 0;
rjwf9ec3832023-04-12 10:59:15 +0800104/*This value ensure the data call timing is correct*/
105static int data_timelimit = 0;
rjwc63abb42023-03-31 18:22:42 +0800106
rjw22947c22022-03-15 09:21:29 +0800107/**g_lynq_data_init_flag
108* @brief mark data initialization state
109* 0:deinit status
110* 1:init state
111*/
112static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +0800113/**g_lynq_apn_result
114* @brief temp of apn result info
115*/
116char g_lynq_apn_result[1024] = {};
lha62e0882023-10-31 05:17:11 -0700117int g_data_call_timeout_value = LYNQ_DATA_TIME_OUT;
rjw747deea2022-07-01 18:25:30 +0800118
rjw7ee7bb42023-01-18 11:34:28 +0800119static std::vector<int> s_data_urc_wait_list;
120
rjw20006d12022-04-21 16:29:04 +0800121typedef struct
122{
lhf81a46f2022-02-13 23:57:37 -0800123 char apn[LYNQ_APN_MAX_LEN];
124 char apnType[LYNQ_APN_TYPE_MAX_LEN];
125 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
126 int hasUsed;
127 int hasTimeout;
Hong_Liudc46d412023-05-18 13:36:26 -0700128 int status;
129 char statusApnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800130}lynq_apn_t;
131lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
132lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
133int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800134
xy.hef5d74f12023-10-23 06:48:52 -0700135int radio_switch(int status);
136
lhf81a46f2022-02-13 23:57:37 -0800137int getLynqApnID(char apnType[])
138{
139 int ret = 0;
rjwc63abb42023-03-31 18:22:42 +0800140 int len = 0;
lhf81a46f2022-02-13 23:57:37 -0800141 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
142 {
Hong_Liudc46d412023-05-18 13:36:26 -0700143 len = strlen(apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700144 LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len);
rjwc63abb42023-03-31 18:22:42 +0800145 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
lh13586612022-01-11 21:58:58 -0800146 {
lhf81a46f2022-02-13 23:57:37 -0800147 return ret;
148 }
149 }
150 return -1;
151}
rjw7ee7bb42023-01-18 11:34:28 +0800152
Hong_Liudc46d412023-05-18 13:36:26 -0700153int getDeactApnID(char apnType[])
154{
155 int ret = 0;
156 int len = 0;
157 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
158 {
159 len = strlen(apnType);
160 LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len);
161 if(strncmp(lynq_apn_table[ret].statusApnType,apnType,len)==0)
162 {
163 return ret;
164 }
165 }
166 return -1;
167}
168
lhf81a46f2022-02-13 23:57:37 -0800169void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
170{
171 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
172 if(apn_table==NULL)
173 {
174 LYERRLOG("apn_table is null");
175 return;
176 }
177 memcpy(apn_table->apn,apn,strlen(apn)+1);
178 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
179 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
180 apn_table->hasTimeout = 0;
181 apn_table->hasUsed = 1;
182 return;
183}
rjw7ee7bb42023-01-18 11:34:28 +0800184
lhf81a46f2022-02-13 23:57:37 -0800185void cleanOnceApnTable(int apnId)
186{
Hong_Liudc46d412023-05-18 13:36:26 -0700187 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
lhf81a46f2022-02-13 23:57:37 -0800188 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
189 {
190 LYERRLOG("apn id is invalid!!!");
191 return;
192 }
193 lynq_apn_table[apnId].hasTimeout = 0;
194 lynq_apn_table[apnId].hasUsed = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700195 memcpy(lynq_apn_table[apnId].statusApnType,lynq_apn_table[apnId].apnType,strlen(lynq_apn_table[apnId].apnType));
lhf81a46f2022-02-13 23:57:37 -0800196 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700197 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
lhf81a46f2022-02-13 23:57:37 -0800198 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700199 lynq_apn_table[apnId].status = 32;
lhf81a46f2022-02-13 23:57:37 -0800200 return;
201}
Hong_Liudc46d412023-05-18 13:36:26 -0700202void cleanDeactApn(int apnId)
203{
204 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
205 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
206 {
207 LYERRLOG("apn id is invalid!!!");
208 return;
209 }
210 lynq_apn_table[apnId].status = 0;
211 bzero(lynq_apn_table[apnId].statusApnType,LYNQ_APN_TYPE_MAX_LEN);
212}
213
214void updateDeactApn(int apnId,int pdnState)
215{
216 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
217 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
218 {
219 LYERRLOG("apn id is invalid!!!");
220 return;
221 }
222 lynq_apn_table[apnId].status = pdnState;
223}
224
225
lhf81a46f2022-02-13 23:57:37 -0800226int getUnusedElement()
227{
Hong_Liudc46d412023-05-18 13:36:26 -0700228 if (lynq_apn_table == NULL)
229 {
230 LYERRLOG("get UnusedElemnt apn_table is null");
231 return -1;
232 }
lhf81a46f2022-02-13 23:57:37 -0800233 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
234 {
235 if(lynq_apn_table[i].hasUsed!=1)
236 {
237 return i;
238 }
239 }
rjwc63abb42023-03-31 18:22:42 +0800240 LYERRLOG("None of get unused Element");
lhf81a46f2022-02-13 23:57:37 -0800241 return -1;
242}
243int updateApn(char apnType[])
244{
245 int ret = 0;
246 ret = getUnusedElement();
Hong_Liu55668712023-05-16 21:49:17 -0700247 if(ret >= 0)
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700248 {
249 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
250 lynq_apn_table[ret].hasUsed = 1;
251 }
lhf81a46f2022-02-13 23:57:37 -0800252 return ret;
253}
Hong_Liu55c62f52023-08-24 19:05:50 -0700254//@return
255//other:this apn has been used in apn table
256//-1:this apn not has been used in apn table
257int check_used_apn(char apnType[])
258{
259 LYINFLOG("check_used_apn.apnType:%s",apnType);
260 int ret = 0;
261 int len = 0;
262 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
263 {
264 len = strlen(apnType);
265 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
266 {
267 LYINFLOG("check_used_apn.apnType:%s in apn table",apnType);
268 return ret;
269 }
270 }
271 return -1;
272}
273int get_handle(char apnType[])
274{
275 int call_id = 0;
276 call_id = check_used_apn(apnType);
277 if(call_id == -1)
278 {
279 call_id = updateApn(apnType);
280 }
281 LYINFLOG("handle:%d",call_id);
282 return call_id;
283}
rjw1309e232022-07-22 09:54:06 +0800284
285int handleCheck(int handle)
286{
Hong_Liu7163bbe2023-06-04 03:03:44 -0700287 if ((handle >= 0) && (handle <= 6))
rjw1309e232022-07-22 09:54:06 +0800288 {
Hong_Liu7163bbe2023-06-04 03:03:44 -0700289 if (lynq_apn_table[handle].hasUsed == 1)
290 {
291 return 0;
292 }
rjw1309e232022-07-22 09:54:06 +0800293 return -1;
294 }
Hong_Liu7163bbe2023-06-04 03:03:44 -0700295 return -1;
rjw1309e232022-07-22 09:54:06 +0800296}
rjw20006d12022-04-21 16:29:04 +0800297int waitApnResult()
298{
299 int ret = 0;
300 LYINFLOG("start wait apn result!!!");
301 int sec = 0;
302 int usec = 0;
303 struct timeval now;
304 struct timespec timeout;
305 gettimeofday(&now, NULL);
306 sec = 20000 / 1000;
307 usec = 20000 % 1000;
308 timeout.tv_sec = now.tv_sec + sec;
309 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
310 pthread_mutex_lock(&s_lynq_apn_change_mutex);
311 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
312 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
313 return ret;
314}
315
316void sendSignalApnChange()
317{
318 LYINFLOG("start send Signal Apn Change");
319 pthread_mutex_lock(&s_lynq_apn_change_mutex);
320 pthread_cond_signal(&s_lynq_apn_change_cond);
321 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
322 return;
323}
lhf81a46f2022-02-13 23:57:37 -0800324
325int waitPdnChange()
326{
327 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800328 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
329 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
330 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800331 return ret;
332}
333int waitDataCallstateChange(int mtime)
334{
335 int ret = 0;
336 int sec = 0;
337 int usec = 0;
338 struct timeval now;
339 struct timespec timeout;
340 gettimeofday(&now,NULL);
341 sec = mtime/1000;
342 usec = mtime%1000;
343 timeout.tv_sec = now.tv_sec+sec;
344 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
345 pthread_mutex_lock(&s_data_call_state_change_mutex);
346 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
347 pthread_mutex_unlock(&s_data_call_state_change_mutex);
348 return ret;
349}
350void sendSignalDataCallStateChange()
351{
352 pthread_mutex_lock(&s_data_call_state_change_mutex);
353 pthread_cond_signal(&s_data_call_state_change_cond);
354 pthread_mutex_unlock(&s_data_call_state_change_mutex);
355 return;
356}
Hong_Liu25edfe72023-06-16 01:13:42 -0700357int waitDeactived(int mtime)
358{
359 int ret = 0;
360 int sec = 0;
361 int usec = 0;
362 struct timeval now;
363 struct timespec timeout;
364 gettimeofday(&now,NULL);
365 sec = mtime/1000;
366 usec = mtime%1000;
367 timeout.tv_sec = now.tv_sec+sec;
368 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
369 pthread_mutex_lock(&s_data_call_deactived_mutex);
370 ret = pthread_cond_timedwait(&s_data_call_deactived_cond,&s_data_call_deactived_mutex,&timeout);
371 pthread_mutex_unlock(&s_data_call_deactived_mutex);
372 return ret;
373}
374void sendSignalDeactvied()
375{
376 pthread_mutex_lock(&s_data_call_deactived_mutex);
377 pthread_cond_signal(&s_data_call_deactived_cond);
378 pthread_mutex_unlock(&s_data_call_deactived_mutex);
379 return;
380}
381
lhf81a46f2022-02-13 23:57:37 -0800382void sendSignalPdnChange()
383{
rjw7ee7bb42023-01-18 11:34:28 +0800384 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
385 pthread_cond_signal(&s_lynq_urc_vector_cond);
386 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800387 return;
388}
389
390int get_response(int sockfd,Parcel &p)
391{
392 int len = 0;
393 char recvline[LYNQ_REC_BUF];
394 bzero(recvline,LYNQ_REC_BUF);
395 /* receive data from server */
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700396 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
397 //len = read(sockfd, recvline, LYNQ_REC_BUF);
rjw08528682022-07-04 21:28:02 +0800398 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800399 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700400 LYERRLOG("get_response fail,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800401 return -1;
402 }
403 if (recvline != NULL) {
404 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
405 p.setDataPosition(0);
406 }
407 return 0;
408}
Hong_Liu25edfe72023-06-16 01:13:42 -0700409/**@brief get utoken in range 0 to 10000
410* @return utoken
411*/
412int get_utoken()
lhf81a46f2022-02-13 23:57:37 -0800413{
Hong_Liu25edfe72023-06-16 01:13:42 -0700414 return (Global_uToken++)%10000;/*0-10000*/
415}
416/**@brief wait response with expected token and write msg to parcel in some time
417* @param fd [IN]: socket fd
418* @param p [OUT]: quote the parcel,if return success need delete p.
419* @param token [IN]: the expected token for the response msg
420* @return
421* 0:success
422* other:failure
423*/
424int wait_response(int sockfd,Parcel *& p,int utoken)
425{
426 int len = 0;
427 int flag = 1;
428 int count = 0;
429 int in_utoken = -1;
430 int resp_type = -1;
431 Parcel *temp = NULL;
432 char recvline[LYNQ_REC_BUF];
433 //Sometimes the socket is abnormal, causing the socket buffer to store the response of the last request.
434 //Here it does not return until the response corresponding to the request is read.
435 while(flag && (count < 20))//why?
lhf81a46f2022-02-13 23:57:37 -0800436 {
Hong_Liu25edfe72023-06-16 01:13:42 -0700437 bzero(recvline,LYNQ_REC_BUF);
438 count++;
439 LYINFLOG("wait_response,count:%d",count);
440 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
441 if(len == -1)
442 {
443 LYERRLOG("wait_response fail,errno:%d",errno);
444 return LYNQ_E_GET_RESP_FAIL;
445 }
446 if (len != 0)
447 {
448 temp = new Parcel;
449 int i = 0;
450 while((NULL == temp) && (i < 100))
451 {
452 usleep(1000);
453 temp = new Parcel;
454 i++;
455 }
456 if((i >= 100) || (NULL == temp))
457 {
458 LYERRLOG("wait_response i:%d",i);
459 return LYNQ_E_GET_RESP_FAIL;
460 }
461 temp->setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
462 temp->setDataPosition(0);
463 temp->readInt32(&resp_type);
464 temp->readInt32(&in_utoken);
465 LYINFLOG("[%s]in_utoken:%d,utoken:%d",__FUNCTION__,in_utoken,utoken);
466 if (in_utoken != utoken)
467 {
468 delete temp;
469 temp = NULL;
470 in_utoken = 0;
471 continue;
472 }
473 temp->setDataPosition(0);
474 p = temp;
475 flag = 0;
476 return 0;
477 }
478 else
479 {
480 LYERRLOG("recvline is null,errno:%d",errno);
481 return LYNQ_E_GET_RESP_FAIL;
482 }
483 }
484 return LYNQ_E_GET_RESP_FAIL;
485}
486
487int JumpHeader(Parcel *p,int *resp_type,int *utoken,int *request,int *slot_id,int *error)
488{
489 if(NULL == p)
490 {
491 LYERRLOG("JumpHeader is null");
492 return -1;
493 }
494 if(p->dataAvail() > 0)
495 {
496 p->readInt32(resp_type);
497 p->readInt32(utoken);
498 p->readInt32(request);
499 p->readInt32(slot_id);
500 p->readInt32(error);
lhf81a46f2022-02-13 23:57:37 -0800501 return 0;
502 }
503 else
504 {
505 return -1;
506 }
507}
Hong_Liu25edfe72023-06-16 01:13:42 -0700508void free_parcel(Parcel *p)
509{
510 if(p)
511 {
512 delete p;
513 p = NULL;
514 }
515}
lhf81a46f2022-02-13 23:57:37 -0800516int send_request(int sockfd,lynq_client_t *client_tmp)
517{
518 int ret=0;
lh8d290112023-10-22 20:53:06 -0700519 ret = sendto(sockfd,client_tmp,LYQN_SEDN_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,lynq_data_socket_server_addr_len);
lhf81a46f2022-02-13 23:57:37 -0800520 if(ret==-1)
521 {
lh8d290112023-10-22 20:53:06 -0700522 LYERRLOG("%s:errno code:%d",__FUNCTION__,errno);
lhf81a46f2022-02-13 23:57:37 -0800523 return -1;
524 }
525 return 0;
526}
527static char *strdupReadString(Parcel &p) {
528 size_t stringlen;
529 const char16_t *s16;
530 s16 = p.readString16Inplace(&stringlen);
531 return strndup16to8(s16, stringlen);
532}
533static char *strdupReadString_p(Parcel *p) {
534 size_t stringlen;
535 const char16_t *s16;
536 s16 = p->readString16Inplace(&stringlen);
537 return strndup16to8(s16, stringlen);
538}
539
lhf81a46f2022-02-13 23:57:37 -0800540/*Warren add for T800 platform 2021/11/19 start*/
541int lynq_socket_client_start()
542{
lh8d290112023-10-22 20:53:06 -0700543 int ret;
544 struct timeval timeOut;
545 struct sockaddr_in liblynq_data_socket;
rjw747deea2022-07-01 18:25:30 +0800546
lh8d290112023-10-22 20:53:06 -0700547 ret = 0;
rjwa59bf312022-07-05 11:50:31 +0800548 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800549 timeOut.tv_usec = 0;
lh8d290112023-10-22 20:53:06 -0700550 bzero(&liblynq_data_socket, sizeof(liblynq_data_socket));
551 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
552
553 //set this lib socket config
554 liblynq_data_socket.sin_family = AF_INET;
555 liblynq_data_socket.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
rjw747deea2022-07-01 18:25:30 +0800556
lh8d290112023-10-22 20:53:06 -0700557 //set ril service socket config
558 lynq_data_socket_server_addr.sin_family = AF_INET;
559 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
560 lynq_data_socket_server_addr.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
561 lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr);
562
563 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
564 ret = bind(lynq_client_sockfd, (struct sockaddr *)&liblynq_data_socket, sizeof(liblynq_data_socket));
565 if (-1 == ret)
566 {
567 LYERRLOG("liblynq_data_socket bind fail,errno:%d",errno);
568 return -1;
569 }
rjw747deea2022-07-01 18:25:30 +0800570 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
571 {
lh8d290112023-10-22 20:53:06 -0700572 LYERRLOG("time out setting failed,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800573 return -1;
574 }
575 return 0;
576}
rjw7ee7bb42023-01-18 11:34:28 +0800577
578bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800579{
rjw7ee7bb42023-01-18 11:34:28 +0800580 switch(urc_id)
581 {
582 case LYNQ_URC_DATA_CALL_STATUS_IND:
583
584 case LYNQ_URC_MODIFY_APNDB:
585 case LYNQ_URC_RESET_APNDB:
xy.hef5d74f12023-10-23 06:48:52 -0700586 case LYNQ_TELEPHONY_RESTART:
rjw7ee7bb42023-01-18 11:34:28 +0800587 return true;
588 default:
589 return false;
590 }
591}
592
rjwc63abb42023-03-31 18:22:42 +0800593int printf_apn_table()
594{
595 int ret = 0;
Hong_Liu6149f182023-05-12 02:15:14 -0700596 if (lynq_apn_table == NULL)
597 {
598 LYERRLOG("apn table is null");
599 return -1;
600 }
rjwc63abb42023-03-31 18:22:42 +0800601 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
602 {
Hong_Liudc46d412023-05-18 13:36:26 -0700603 LYINFLOG("[%s][%d] apn=%s ;apntype=%s ;ifname=%s ;hasTimeout = %d ; hasUsed = %d,status = %d,statusDeactApn = %s",__FUNCTION__,ret, \
rjwc63abb42023-03-31 18:22:42 +0800604 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
Hong_Liudc46d412023-05-18 13:36:26 -0700605 lynq_apn_table[ret].hasTimeout,lynq_apn_table[ret].hasUsed,lynq_apn_table[ret].status,lynq_apn_table[ret].statusApnType);
rjwc63abb42023-03-31 18:22:42 +0800606 }
607 return 0;
608}
609
Hong_Liu6149f182023-05-12 02:15:14 -0700610void printf_apn_table_debug(const char *fun,int line)
611{
612 LYINFLOG("[%s][%d]apn_table msg",fun,line);
613 printf_apn_table();
614}
rjwc63abb42023-03-31 18:22:42 +0800615
rjw7ee7bb42023-01-18 11:34:28 +0800616void urc_msg_process(Parcel *p)
617{
618 int len;
619 int resp_type;
620 int urcid;
621 int slot_id;
rjwf9ec3832023-04-12 10:59:15 +0800622 int check_count = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700623 static int apnId=-1;
rjw7ee7bb42023-01-18 11:34:28 +0800624
625 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800626 char apn[LYNQ_APN_MAX_LEN];
627 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800628 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800629 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800630
631 int size = p->dataSize();
632 p->readInt32(&resp_type);
633 p->readInt32(&urcid);
634 p->readInt32(&slot_id);
635 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
636 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800637 {
rjw7ee7bb42023-01-18 11:34:28 +0800638 case LYNQ_URC_DATA_CALL_STATUS_IND:
639 p->readInt32(&pdnState);
640 bzero(apn,LYNQ_APN_MAX_LEN);
641 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
642 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
lha62e0882023-10-31 05:17:11 -0700643 if(pdnState != RIL_Data_Call_PdnState::PDN_DISCONNECTED)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800644 {
rjw20006d12022-04-21 16:29:04 +0800645 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800646 int len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700647 if((len < LYNQ_APN_MAX_LEN-1) && (len > 0))
rjw20006d12022-04-21 16:29:04 +0800648 {
rjw7ee7bb42023-01-18 11:34:28 +0800649 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800650 }
Hong_Liu6149f182023-05-12 02:15:14 -0700651 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800652 urc_msg = strdupReadString_p(p);
653 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700654 if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800655 {
656 memcpy(apnType,urc_msg,len+1);
657 }
Hong_Liu6149f182023-05-12 02:15:14 -0700658 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800659 urc_msg = strdupReadString_p(p);
660 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700661 if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800662 {
663 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
664 }
Hong_Liu6149f182023-05-12 02:15:14 -0700665 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800666 //sendSignalDataCallStateChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700667 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800668 if(apnId >= 0)
669 {
Hong_Liudc46d412023-05-18 13:36:26 -0700670 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800671 if(lynq_apn_table[apnId].hasTimeout==1)
672 {
rjwc63abb42023-03-31 18:22:42 +0800673 /*whether timeout?,real or not,*/
674 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800675 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800676 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 +0800677 {
678 LYERRLOG("deactive this time out APN");
679 lynq_deactive_data_call(&apnId);
680 }
rjwc63abb42023-03-31 18:22:42 +0800681 else
rjw7ee7bb42023-01-18 11:34:28 +0800682 {
rjwc63abb42023-03-31 18:22:42 +0800683 /*if apn lose,update apn and deactive all apn*/
684 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800685 }
686 break;
687 }
rjwacdb2152023-02-07 14:12:49 +0800688 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
Hong_Liu6149f182023-05-12 02:15:14 -0700689 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800690 }
691 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800692 else
693 {
Hong_Liu6149f182023-05-12 02:15:14 -0700694 data_invaild_error = 1;
Hong_Liudc46d412023-05-18 13:36:26 -0700695 printf_apn_table_debug(__FUNCTION__,__LINE__);
696 apnId = getDeactApnID(apnType);
697 if(apnId < 0)
698 {
699 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
700 break;
701 }
702 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
703 updateDeactApn(apnId,pdnState);
704 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800705 }
rjw7ee7bb42023-01-18 11:34:28 +0800706 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
707 s_data_urc_wait_list.push_back(apnId);
708 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
709 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800710 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800711 LYDBGLOG("data call state:%d",lynq_data_call);
712 if(lynq_data_call==1)
713 {
rjwf9ec3832023-04-12 10:59:15 +0800714 while (data_timelimit == 0)
715 {
716 LYINFLOG("client not ready to wait");
717 for (check_count = 0;check_count < 500;check_count++)
718 {
719 /*wait 10ms*/
720 usleep(10*1000);
721 }
722 LYERRLOG("client still without res");
723 break;
724 }
lha62e0882023-10-31 05:17:11 -0700725 if(pdnState == RIL_Data_Call_PdnState::PDN_TIMEOUT_CANCEL)
726 {
727 lynq_data_call = LYNQ_E_TIME_OUT;
728 }
729 else
730 {
731 lynq_data_call = 0;
732 }
rjw7ee7bb42023-01-18 11:34:28 +0800733 sendSignalDataCallStateChange();
rjwf9ec3832023-04-12 10:59:15 +0800734 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800735 }
Hong_Liu6149f182023-05-12 02:15:14 -0700736 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800737 }
rjw7ee7bb42023-01-18 11:34:28 +0800738 else
rjw20006d12022-04-21 16:29:04 +0800739 {
rjw7ee7bb42023-01-18 11:34:28 +0800740 urc_msg = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -0700741 free(urc_msg);
742 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800743 len = strlen(urc_msg);
744 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
745 {
746 memcpy(apnType,urc_msg,len+1);
747 }
Hong_Liu6149f182023-05-12 02:15:14 -0700748 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800749 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
Hong_Liudc46d412023-05-18 13:36:26 -0700750 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800751 if(apnId >= 0)
752 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700753 LYINFLOG("[%d]URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",__LINE__,apnType,ifaceName,apn,pdnState,apnId);
Hong_Liudc46d412023-05-18 13:36:26 -0700754 lynq_data_call_change_id = apnId;
755 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
756 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
757 s_data_urc_wait_list.push_back(apnId);
758 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
759 sendSignalPdnChange();
760 }
761 else
762 {
763 apnId = getDeactApnID(apnType);
764 if(apnId < 0)
765 {
766 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
767 break;
768 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700769 LYINFLOG("[%d]URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",__LINE__,apnType,ifaceName,apn,pdnState,apnId);
Hong_Liudc46d412023-05-18 13:36:26 -0700770 cleanDeactApn(apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800771 lynq_data_call_change_id = apnId;
772 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800773 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
774 s_data_urc_wait_list.push_back(apnId);
775 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -0700776 sendSignalDeactvied();
rjwc3d6e582023-03-28 17:19:11 +0800777 sendSignalPdnChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700778 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800779 }
rjw7ee7bb42023-01-18 11:34:28 +0800780 LYDBGLOG("data call state:%d",lynq_data_call);
781 if(lynq_data_call==1)
782 {
rjwf9ec3832023-04-12 10:59:15 +0800783 while (data_timelimit == 0)
784 {
785 LYINFLOG("client not ready to wait");
786 for (check_count = 0;check_count < 500;check_count++)
787 {
788 /*wait 10ms*/
789 usleep(10*1000);
790 }
791 LYERRLOG("client still without res");
792 break;
793 }
rjw7ee7bb42023-01-18 11:34:28 +0800794 sendSignalDataCallStateChange();
795 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800796 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800797 }
Hong_Liu6149f182023-05-12 02:15:14 -0700798 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800799 }
800 break;
801 case LYNQ_URC_MODIFY_APNDB:
802 urc_msg = strdupReadString_p(p);
803 if (NULL == urc_msg)
804 {
805 LYERRLOG("error apn msg");
806 }
807 else
808 {
809 bzero(g_lynq_apn_result, 1024);
810 strcpy(g_lynq_apn_result, urc_msg);
811 sendSignalApnChange();
812 }
Hong_Liu6149f182023-05-12 02:15:14 -0700813 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800814 break;
815 case LYNQ_URC_RESET_APNDB:
816 {
rjw20006d12022-04-21 16:29:04 +0800817 urc_msg = strdupReadString_p(p);
818 if (NULL == urc_msg)
819 {
820 LYERRLOG("error apn msg");
821 }
822 else
823 {
824 bzero(g_lynq_apn_result, 1024);
825 strcpy(g_lynq_apn_result, urc_msg);
826 sendSignalApnChange();
827 }
Hong_Liu6149f182023-05-12 02:15:14 -0700828 free(urc_msg);
rjw20006d12022-04-21 16:29:04 +0800829 }
xy.hef5d74f12023-10-23 06:48:52 -0700830 case LYNQ_TELEPHONY_RESTART:
831 {
832 if(slot_id == 0)
833 {
834 RLOGI("data has received telephony has restart");
835 RLOGI("handle set to 10");
836 lynq_telephony_restart_g = 1;
837 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
838 s_data_urc_wait_list.push_back(TELEPHONY_RESTART);
839 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
840 radio_switch(0);
841 sleep(1);
842 radio_switch(1);
843 sleep(1);
844 sendSignalPdnChange();
845 }
846 }
rjw7ee7bb42023-01-18 11:34:28 +0800847 default:
848 break;
lhf81a46f2022-02-13 23:57:37 -0800849 }
rjw7ee7bb42023-01-18 11:34:28 +0800850
lhf81a46f2022-02-13 23:57:37 -0800851}
rjw7ee7bb42023-01-18 11:34:28 +0800852
rjw7ee7bb42023-01-18 11:34:28 +0800853int create_urc_vector_signal_thread()
854{
855 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800856 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800857 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
858 s_data_urc_wait_list.clear();
859 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800860 return 0;
861}
Hong_Liu25edfe72023-06-16 01:13:42 -0700862int get_imsi();
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700863int check_apn_status();
xy.hef5d74f12023-10-23 06:48:52 -0700864
lha62e0882023-10-31 05:17:11 -0700865int get_timeout_value();
lhf81a46f2022-02-13 23:57:37 -0800866int lynq_init_data(int uToken)
867{
rjw22947c22022-03-15 09:21:29 +0800868 if (g_lynq_data_init_flag == 1)
869 {
870 LYERRLOG("init twice is not allowed");
871 return -1;
872 }
873 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800874 int result = 0;
875 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800876 LYLOGSET(LOG_INFO);
877 LYLOGEINIT(USER_LOG_TAG);
lha62e0882023-10-31 05:17:11 -0700878 int ret = get_timeout_value();
879 if(ret >= 30000)
880 {
881 g_data_call_timeout_value = ret;
882 }
883 else
884 {
885 LYERRLOG("timeout must greater or equal to 30s!!!");
886 }
lhf81a46f2022-02-13 23:57:37 -0800887 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800888 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800889 if(result!=0)
890 {
891 LYERRLOG("init socket client fail!!!");
892 return -1;
893 }
rjw7ee7bb42023-01-18 11:34:28 +0800894 result = lynq_init_data_urc_thread();
895 if(result!=0)
896 {
897 LYERRLOG("init socket urc fail!!!");
898 return -1;
899 }
900
901 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800902 if(result!=0)
903 {
904 LYERRLOG("init socket urc fail!!!");
905 return -1;
906 }
907 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700908 LYINFLOG("[%s] radio on/off solution 20230724",__FUNCTION__);
Hong_Liu25edfe72023-06-16 01:13:42 -0700909 int count = 0;
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700910 while(count < 2)//try recover the network within 10s.
911 {
912 result = check_apn_status();
913 if(result==0)
914 {
915 break;
916 }
917 radio_switch(0);
918 sleep(1);
919 radio_switch(1);
920 sleep(3);
921 count++;
922 }
923 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
924 if(result!=0)
925 {
926 LYDBGLOG("lynq init call fail!!!");
927 return LYNQ_E_MD_NOT_READY;//
928 }
929 /* old
Hong_Liu25edfe72023-06-16 01:13:42 -0700930 while(count < 10)
931 {
932 result = get_imsi();
933 if(result==0)
934 {
935 break;
936 }
937 sleep(1);
938 count++;
939 }
940 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
941 if(result!=0)
942 {
943 LYDBGLOG("lynq init call fail!!!");
944 return LYNQ_E_MD_NOT_READY;//
945 }
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700946 */
lhf81a46f2022-02-13 23:57:37 -0800947 LYDBGLOG("lynq init call success!!!");
948 return 0;
949
950}
951int lynq_deinit_data()
952{
953 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800954 if (g_lynq_data_init_flag == 0)
955 {
956 LYERRLOG("deinit twice is not allowed");
957 return ret;
958 }
959 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800960 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
961 {
962 if(strlen(lynq_apn_table[i].apnType)!=0)
963 {
964 lynq_deactive_data_call(&i);
965 }
966 }
967 if(lynq_client_sockfd>0)
968 {
969 close(lynq_client_sockfd);
970 }
rjw7ee7bb42023-01-18 11:34:28 +0800971 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800972 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800973 {
rjw7ee7bb42023-01-18 11:34:28 +0800974 LYERRLOG("lynq_deinit_data_urc_thread fail");
975 return ret;
rjw22947c22022-03-15 09:21:29 +0800976 }
rjwc3d6e582023-03-28 17:19:11 +0800977 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
978 s_data_urc_wait_list.clear();
979 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800980 return 0;
981}
982int lynq_setup_data_call(int *handle)
983{
Hong_Liue54db8c2023-04-21 02:37:23 -0700984 int error = -1;
lha62e0882023-10-31 05:17:11 -0700985 if (g_lynq_data_init_flag == 0)
986 {
987 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
988 return error;
989 }
Hong_Liue54db8c2023-04-21 02:37:23 -0700990 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
991 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
Hong_Liue9879152023-04-25 20:40:26 -0700992 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -0700993 #else
Hong_Liu25edfe72023-06-16 01:13:42 -0700994 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -0800995 lynq_client_t client;
996 int resp_type = -1;
997 int request = -1;
998 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -0800999 int lynq_data_call_id = 0;
1000 if(handle==NULL)
1001 {
1002 LYERRLOG("handle is null!!!");
1003 return LYNQ_E_NULL_ANONALY;
1004 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001005 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001006 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1007 client.paramLen = 0;
1008 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1009 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -07001010 lynq_data_call_id = get_handle("default");
rjwc63abb42023-03-31 18:22:42 +08001011 if (lynq_data_call_id < 0)
1012 {
1013 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001014 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001015 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001016 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect.
1017 //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate.
rjw733b9832023-04-03 10:20:08 +08001018 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001019 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001020 if(send_request(lynq_client_sockfd,&client)==-1)
1021 {
1022 LYERRLOG("send request fail");
1023 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001024 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001025 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001026 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001027 //get_response(lynq_client_sockfd,p);
1028 error = wait_response(lynq_client_sockfd,p,client.uToken);
1029 if(error!=0)
1030 {
1031 LYERRLOG("wait_response fail,ret:%d",error);
1032 printf_apn_table_debug(__FUNCTION__,__LINE__);
1033 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1034 return error;
1035 }
rjwed00d042022-05-25 09:18:16 +08001036 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liuaa7f4b32023-07-19 07:51:25 -07001037 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
Hong_Liu25edfe72023-06-16 01:13:42 -07001038 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001039 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -08001040 if(error==0)
1041 {
rjwf9ec3832023-04-12 10:59:15 +08001042 data_timelimit = 1;
lha62e0882023-10-31 05:17:11 -07001043 if (waitDataCallstateChange(g_data_call_timeout_value) == ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001044 {
1045 error = LYNQ_E_TIME_OUT;
1046 LYERRLOG("timeout:wait data Call state fail!!!");
1047 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001048 if (data_invaild_error == 1)
1049 {
1050 data_invaild_error = 0;
1051 LYERRLOG("urc apn info error!!!");
1052 return 8085;
1053 }
1054 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001055 return error;
1056 }
lha62e0882023-10-31 05:17:11 -07001057 if(lynq_data_call == LYNQ_E_TIME_OUT)
1058 {
1059 error = LYNQ_E_TIME_OUT;
1060 LYERRLOG("PDN_TIMEOUT_CANCLE:wait data Call state fail!!!");
1061 printf_apn_table_debug(__FUNCTION__,__LINE__);
1062 return error;
1063 }
lhf81a46f2022-02-13 23:57:37 -08001064 }
Hong_Liu6149f182023-05-12 02:15:14 -07001065 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liue54db8c2023-04-21 02:37:23 -07001066 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001067 return error;
1068}
rjw7ee7bb42023-01-18 11:34:28 +08001069
lhf81a46f2022-02-13 23:57:37 -08001070int lynq_deactive_data_call(int *handle)
1071{
Hong_Liu25edfe72023-06-16 01:13:42 -07001072 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001073 lynq_client_t client;
1074 int resp_type = -1;
1075 int request = -1;
1076 int slot_id = -1;
1077 int error = -1;
1078 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +08001079 int ret = 0;
lha62e0882023-10-31 05:17:11 -07001080 if (g_lynq_data_init_flag == 0)
1081 {
1082 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
1083 return error;
1084 }
lhf81a46f2022-02-13 23:57:37 -08001085 if(handle==NULL)
1086 {
1087 LYERRLOG("handle is null!!!");
1088 return -1;
1089 }
rjw1309e232022-07-22 09:54:06 +08001090 ret = handleCheck(*handle);
1091 if (ret != 0)
1092 {
1093 LYERRLOG("incomming handle is invalid");
1094 return -1;
1095 }
1096 lynq_data_call_id = *handle;
Hong_Liu25edfe72023-06-16 01:13:42 -07001097 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001098 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
Hong_Liue3d35262023-05-04 00:20:12 -07001099 client.paramLen = 0;
1100 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1101 #ifdef GSW_RIL_CFG
1102 client.paramLen = 1;
1103 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1104 #else
1105 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -08001106 {
lhf81a46f2022-02-13 23:57:37 -08001107 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -08001108 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1109 }
Hong_Liue3d35262023-05-04 00:20:12 -07001110 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001111 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001112 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001113 if(send_request(lynq_client_sockfd,&client)==-1)
1114 {
1115 LYERRLOG("send request fail");
1116 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001117 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001118 return -1;
1119 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001120 //get_response(lynq_client_sockfd,p);
1121 error = wait_response(lynq_client_sockfd,p,client.uToken);
1122 if(error!=0)
1123 {
1124 LYERRLOG("wait_response fail,ret:%d",error);
1125 printf_apn_table_debug(__FUNCTION__,__LINE__);
1126 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1127 return error;
1128 }
rjwed00d042022-05-25 09:18:16 +08001129 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001130 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1131 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -08001132 cleanOnceApnTable(lynq_data_call_id);
Hong_Liu6149f182023-05-12 02:15:14 -07001133 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liu25edfe72023-06-16 01:13:42 -07001134 if(error==0)
1135 {
1136 if(waitDeactived(20000)==ETIMEDOUT)
1137 {
1138 error = LYNQ_E_TIME_OUT;
1139 LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!");
1140 printf_apn_table_debug(__FUNCTION__,__LINE__);
1141 }
1142 }
1143 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001144 return error;
1145}
1146int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
1147{
Hong_Liu25edfe72023-06-16 01:13:42 -07001148 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001149 lynq_client_t client;
1150 int resp_type = -1;
1151 int request = -1;
1152 int slot_id = -1;
1153 int error = -1;
lhf81a46f2022-02-13 23:57:37 -08001154 int lynq_data_call_id = -1;
1155 char *argv[10] = {};
lha62e0882023-10-31 05:17:11 -07001156 if (g_lynq_data_init_flag == 0)
1157 {
1158 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
1159 return error;
1160 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001161 #ifdef GSW_RIL_CFG
1162 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
1163 if(handle==NULL||apnType==NULL)
1164 {
1165 LYERRLOG("handle or apntype is null!!!");
1166 return -1;
1167 }
1168 #else
lhf81a46f2022-02-13 23:57:37 -08001169 if(handle==NULL||apn==NULL||apnType==NULL)
1170 {
1171 LYERRLOG("handle ,apn or apntype is null!!!");
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001172 return LYNQ_E_NULL_ANONALY;
lhf81a46f2022-02-13 23:57:37 -08001173 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001174 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001175 if(user==NULL)
1176 {
1177 argv[1] = "null";
1178 }
1179 else
1180 {
1181 argv[1] = user;
lh13586612022-01-11 21:58:58 -08001182 }
1183 if(password==NULL)
1184 {
lhf81a46f2022-02-13 23:57:37 -08001185 argv[2] = "null";
lh13586612022-01-11 21:58:58 -08001186 }
1187 else
1188 {
lhf81a46f2022-02-13 23:57:37 -08001189 argv[2] = password;
lh13586612022-01-11 21:58:58 -08001190 }
1191 if(authType==NULL)
1192 {
lhf81a46f2022-02-13 23:57:37 -08001193 argv[3] = "null";
lh13586612022-01-11 21:58:58 -08001194 }
1195 else
1196 {
lhf81a46f2022-02-13 23:57:37 -08001197 argv[3] = authType;
lh13586612022-01-11 21:58:58 -08001198 }
1199 if(normalProtocol==NULL)
1200 {
lhf81a46f2022-02-13 23:57:37 -08001201 argv[4] = "null";
lh13586612022-01-11 21:58:58 -08001202 }
1203 else
1204 {
lhf81a46f2022-02-13 23:57:37 -08001205 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -08001206 }
1207 if(roamingProtocol==NULL)
1208 {
lhf81a46f2022-02-13 23:57:37 -08001209 argv[5] = "null";
lh13586612022-01-11 21:58:58 -08001210 }
1211 else
1212 {
lhf81a46f2022-02-13 23:57:37 -08001213 argv[5] = roamingProtocol;
1214 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001215 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001216 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1217 client.paramLen = 7;
1218 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -07001219 #ifdef GSW_RIL_CFG
1220 if(NULL == apn)
1221 {
1222 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1223 }
1224 else
1225 {
1226 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1227 }
1228 #else
lhf81a46f2022-02-13 23:57:37 -08001229 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 -07001230 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001231 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -07001232 lynq_data_call_id = get_handle(apnType);
rjwc63abb42023-03-31 18:22:42 +08001233 if (lynq_data_call_id < 0)
1234 {
1235 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001236 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001237 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001238 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16)
rjw733b9832023-04-03 10:20:08 +08001239 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001240 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001241 if(send_request(lynq_client_sockfd,&client)==-1)
1242 {
1243 LYERRLOG("send request fail");
1244 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001245 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001246 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001247 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001248 //get_response(lynq_client_sockfd,p);
1249 error = wait_response(lynq_client_sockfd,p,client.uToken);
1250 if(error!=0)
1251 {
1252 LYERRLOG("wait_response fail,ret:%d",error);
1253 printf_apn_table_debug(__FUNCTION__,__LINE__);
1254 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1255 return error;
1256 }
rjwed00d042022-05-25 09:18:16 +08001257 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001258 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1259 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1260 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001261 if(error==0)
1262 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001263 data_timelimit = 1;
lha62e0882023-10-31 05:17:11 -07001264 if(waitDataCallstateChange(g_data_call_timeout_value)==ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001265 {
1266 error = LYNQ_E_TIME_OUT;
1267 LYERRLOG("timeout:wait data Call state fail!!!");
1268 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001269 if (data_invaild_error == 1)
1270 {
1271 data_invaild_error = 0;
1272 LYERRLOG("urc apn info error!!!");
1273 return 8085;
1274 }
1275 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001276 return error;
1277 }
lha62e0882023-10-31 05:17:11 -07001278 if(lynq_data_call == LYNQ_E_TIME_OUT)
1279 {
1280 error = LYNQ_E_TIME_OUT;
1281 LYERRLOG("PDN_TIMEOUT_CANCLE:wait data Call state fail!!!");
1282 printf_apn_table_debug(__FUNCTION__,__LINE__);
1283 return error;
1284 }
lhf81a46f2022-02-13 23:57:37 -08001285 }
Hong_Liu6149f182023-05-12 02:15:14 -07001286 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001287 return error;
1288}
1289/*
1290int lynq_deactive_data_call_sp(int *handle,char *apnType)
1291{
1292 Parcel p;
1293 lynq_client_t client;
1294 int resp_type = -1;
1295 int request = -1;
1296 int slot_id = -1;
1297 int error = -1;
1298 if(handle==NULL||apnType==NULL)
1299 {
1300 LYERRLOG("handle is null!!!");
1301 return -1;
1302 }
1303 client.uToken = Global_uToken;
1304 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
1305 client.paramLen = 1;
1306 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1307 sprintf(client.param,"%s",apnType);
1308 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1309 if(send_request(lynq_client_sockfd,&client)==-1)
1310 {
1311 LYERRLOG("send request fail");
1312 perror("[LYNQ_DATA] send request fail:");
1313 return -1;
1314 }
1315 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +08001316 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -08001317 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1318 return error;
1319}
1320*/
1321int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
1322{
Hong_Liu25edfe72023-06-16 01:13:42 -07001323 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001324 lynq_client_t client;
1325 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001326 int token;
Hong_Liu25edfe72023-06-16 01:13:42 -07001327 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001328 int slot_id = -1;
1329 int error = -1;
1330 int version =0;
1331 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001332 char *temp_char = NULL;
1333 if(dataCallList==NULL)
1334 {
1335 LYERRLOG("dataCallList is null!!!");
1336 return -1;
1337 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001338 client.uToken = get_utoken();;
lhf81a46f2022-02-13 23:57:37 -08001339 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1340 client.paramLen = 0;
1341 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1342 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001343 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001344 if(send_request(lynq_client_sockfd,&client)==-1)
1345 {
1346 LYERRLOG("send request fail");
1347 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001348 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001349 return -1;
1350 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001351 //get_response(lynq_client_sockfd,p);
1352 error = wait_response(lynq_client_sockfd,p,client.uToken);
1353 if(error!=0)
1354 {
1355 LYERRLOG("wait_response fail,ret:%d",error);
1356 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1357 return error;
1358 }
rjwed00d042022-05-25 09:18:16 +08001359 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001360 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
rjwfa532972022-09-16 13:39:41 +08001361 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001362 LYERRLOG("JumpHeader fail");
rjwfa532972022-09-16 13:39:41 +08001363 return -1;
1364 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001365 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1366 p->readInt32(&version);
lhf81a46f2022-02-13 23:57:37 -08001367 if(version==11)
1368 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001369 p->readInt32(&num);
lhf81a46f2022-02-13 23:57:37 -08001370 *realNum = num;
1371 for (int i = 0; i < num; i++)
1372 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001373 p->readInt32(&dataCallList[i].status);
1374 p->readInt32(&dataCallList[i].suggestedRetryTime);
1375 p->readInt32(&dataCallList[i].cid);
1376 p->readInt32(&dataCallList[i].active);
1377 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001378 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1379 if(temp_char)
1380 {
1381 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1382 free(temp_char);
1383 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001384 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001385 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1386 if(temp_char)
1387 {
1388 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1389 free(temp_char);
1390 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001391 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001392 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1393 if(temp_char)
1394 {
1395 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1396 free(temp_char);
1397 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001398 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001399 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1400 if(temp_char)
1401 {
1402 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1403 free(temp_char);
1404 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001405 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001406 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1407 if(temp_char)
1408 {
1409 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1410 free(temp_char);
1411 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001412 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001413 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1414 if(temp_char)
1415 {
1416 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1417 free(temp_char);
1418 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001419 p->readInt32(&dataCallList[i].mtu);
lhf81a46f2022-02-13 23:57:37 -08001420 }
1421 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001422 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001423 return error;
1424}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001425
1426int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
1427{
1428 LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
1429 if((handle < 0) || (handle > 6) || (NULL == apn_msg))
1430 {
1431 LYERRLOG("handle value error,or apn_msg is null");
1432 return LYNQ_E_NULL_ANONALY;
1433 }
1434 apn_msg->handle = handle;
1435 if(apn_msg->apn!=NULL)
1436 {
1437 memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
1438 }
1439 if(apn_msg->apnType!=NULL)
1440 {
1441 memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
1442 }
1443 return 0;
1444}
1445
lhf81a46f2022-02-13 23:57:37 -08001446int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1447{
1448 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1449 int number = 0;
1450 int lynq_data_call_id = 0;
1451 int error = 0;
lha62e0882023-10-31 05:17:11 -07001452 if (g_lynq_data_init_flag == 0)
1453 {
1454 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
1455 return -1;
1456 }
lhf81a46f2022-02-13 23:57:37 -08001457 lynq_data_call_id = *handle;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001458 if((handle==NULL) || (dataCallList==NULL))
lhf81a46f2022-02-13 23:57:37 -08001459 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001460 LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
lhf81a46f2022-02-13 23:57:37 -08001461 return LYNQ_E_NULL_ANONALY;
1462 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001463 if ((*handle < 0) || (*handle > 6))
rjw3938f262023-03-08 16:09:28 +08001464 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001465 LYERRLOG("[lynq_get_data_call_list] handle value error");
1466 return LYNQ_E_NULL_ANONALY;
rjw3938f262023-03-08 16:09:28 +08001467 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001468 LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001469 memset(interDataCallList,0,sizeof(interDataCallList));
1470 error = getDataCallLists(interDataCallList,&number);
1471 if(error == 0)
1472 {
1473 for(int i = 0;i < number;i++)
1474 {
1475 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1476 {
1477 dataCallList->active = interDataCallList[i].active;
1478 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1479 dataCallList->cid = interDataCallList[i].cid;
1480 dataCallList->status = interDataCallList[i].status;
1481 dataCallList->mtu = interDataCallList[i].mtu;
1482 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1483 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1484 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1485 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1486 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1487 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1488 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1489 }
1490 }
1491 }
1492 return error;
1493}
1494int lynq_wait_data_call_state_change(int *handle)
1495{
rjwc3d6e582023-03-28 17:19:11 +08001496 if (data_waiting_status == 1)
1497 {
1498 LYDBGLOG("some thread is waiting");
1499 return -3;
1500 }
1501 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1502 if (s_data_urc_wait_list.empty())
1503 {
1504 LYDBGLOG("start wait");
1505 data_waiting_status = 1;
1506 waitPdnChange();
1507 }
1508 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001509 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001510
1511 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1512 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001513 if (iter != s_data_urc_wait_list.end())
1514 {
1515 *handle = *iter;
1516 }
rjw7ee7bb42023-01-18 11:34:28 +08001517 s_data_urc_wait_list.erase(iter);
1518 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1519
Hong_Liudc46d412023-05-18 13:36:26 -07001520 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001521 return 0;
1522}
1523/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001524
1525/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001526
1527int 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 +08001528{
1529 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001530 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001531 {
rjw61fcae32022-08-18 14:03:39 +08001532 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001533 }
rjw61fcae32022-08-18 14:03:39 +08001534 else
rjw0cdacbc2022-06-22 10:51:07 +08001535 {
rjw61fcae32022-08-18 14:03:39 +08001536 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001537 }
rjw20006d12022-04-21 16:29:04 +08001538 if (mcc == NULL)
1539 {
1540 sprintf(strtmp[1], "mcc=;");
1541 }
1542 else
1543 {
1544 sprintf(strtmp[1], "mcc=%s;", mcc);
1545 }
1546 if (mnc == NULL)
1547 {
rjw61fcae32022-08-18 14:03:39 +08001548 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001549 }
1550 else
1551 {
1552 sprintf(strtmp[2], "mnc=%s;", mnc);
1553 }
1554 if (apn == NULL)
1555 {
1556 sprintf(strtmp[3], "apn=;");
1557 }
1558 else
1559 {
1560 sprintf(strtmp[3], "apn=%s;", apn);
1561 }
1562 if (apntype == NULL)
1563 {
1564 sprintf(strtmp[4], "apntype=;");
1565 }
1566 else
1567 {
1568 sprintf(strtmp[4], "apntype=%s;", apntype);
1569 }
1570 if (user == NULL)
1571 {
1572 sprintf(strtmp[5], "user=;");
1573 }
1574 else
1575 {
1576 sprintf(strtmp[5], "user=%s;", user);
1577 }
1578 if (password == NULL)
1579 {
1580 sprintf(strtmp[6], "password=;");
1581 }
1582 else
1583 {
1584 sprintf(strtmp[6], "password=%s;", password);
1585 }
1586 if (normalprotocol == NULL)
1587 {
1588 sprintf(strtmp[7], "normalprotocol=;");
1589 }
1590 else
1591 {
1592 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1593 }
1594 if (roamingprotocol == NULL)
1595 {
1596 sprintf(strtmp[8], "roamingprotocol=;");
1597 }
1598 else
1599 {
1600 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1601 }
1602 if (carrier == NULL)
1603 {
1604 sprintf(strtmp[9], "carrier=;");
1605 }
1606 else
1607 {
1608 sprintf(strtmp[9], "carrier=%s;", carrier);
1609 }
rjw61fcae32022-08-18 14:03:39 +08001610 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 +08001611
rjw20006d12022-04-21 16:29:04 +08001612 return 0;
1613}
1614
1615int 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)
1616{
1617 char strtmp[10][32];
1618 if (id == NULL)
1619 {
1620 sprintf(strtmp[0], "id=;");
1621 }
1622 else
1623 {
1624 sprintf(strtmp[0], "id=%s;", id);
1625 }
1626 if (mcc == NULL)
1627 {
1628 sprintf(strtmp[1], "mcc=;");
1629 }
1630 else
1631 {
1632 sprintf(strtmp[1], "mcc=%s;", mcc);
1633 }
1634 if (mnc == NULL)
1635 {
1636 sprintf(strtmp[2], "mnc=;");
1637 }
1638 else
1639 {
1640 sprintf(strtmp[2], "mnc=%s;", mnc);
1641 }
1642 if (apn == NULL)
1643 {
1644 sprintf(strtmp[3], "apn=;");
1645 }
1646 else
1647 {
1648 sprintf(strtmp[3], "apn=%s;", apn);
1649 }
1650 if (apntype == NULL)
1651 {
1652 sprintf(strtmp[4], "apntype=;");
1653 }
1654 else
1655 {
1656 sprintf(strtmp[4], "apntype=%s;", apntype);
1657 }
1658 if (user == NULL)
1659 {
1660 sprintf(strtmp[5], "user=;");
1661 }
1662 else
1663 {
1664 sprintf(strtmp[5], "user=%s;", user);
1665 }
1666 if (password == NULL)
1667 {
1668 sprintf(strtmp[6], "password=;");
1669 }
1670 else
1671 {
1672 sprintf(strtmp[6], "password=%s;", password);
1673 }
1674 if (normalprotocol == NULL)
1675 {
1676 sprintf(strtmp[7], "normalprotocol=;");
1677 }
1678 else
1679 {
1680 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1681 }
1682 if (roamingprotocol == NULL)
1683 {
1684 sprintf(strtmp[8], "roamingprotocol=;");
1685 }
1686 else
1687 {
1688 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1689 }
1690 if (carrier == NULL)
1691 {
1692 sprintf(strtmp[9], "carrier=;");
1693 }
1694 else
1695 {
1696 sprintf(strtmp[9], "carrier=%s;", carrier);
1697 }
1698 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]);
1699 return 0;
1700}
1701
rjwaf4b1612022-06-13 17:26:01 +08001702
1703int 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)
1704{
1705 char strtmp[10][32];
1706 if (id == NULL)
1707 {
1708 sprintf(strtmp[0], "");
1709 }
1710 else
1711 {
1712 sprintf(strtmp[0], "id=%s;", id);
1713 }
1714 if (mcc == NULL)
1715 {
1716 sprintf(strtmp[1], "");
1717 }
1718 else
1719 {
1720 sprintf(strtmp[1], "mcc=%s;", mcc);
1721 }
1722 if (mnc == NULL)
1723 {
1724 sprintf(strtmp[2], "");
1725 }
1726 else
1727 {
1728 sprintf(strtmp[2], "mnc=%s;", mnc);
1729 }
1730 if (apn == NULL)
1731 {
1732 sprintf(strtmp[3], "");
1733 }
1734 else
1735 {
1736 sprintf(strtmp[3], "apn=%s;", apn);
1737 }
1738 if (apntype == NULL)
1739 {
1740 sprintf(strtmp[4], "");
1741 }
1742 else
1743 {
1744 sprintf(strtmp[4], "apntype=%s;", apntype);
1745 }
1746 if (user == NULL)
1747 {
1748 sprintf(strtmp[5], "");
1749 }
1750 else
1751 {
1752 sprintf(strtmp[5], "user=%s;", user);
1753 }
1754 if (password == NULL)
1755 {
1756 sprintf(strtmp[6], "");
1757 }
1758 else
1759 {
1760 sprintf(strtmp[6], "password=%s;", password);
1761 }
1762 if (normalprotocol == NULL)
1763 {
1764 sprintf(strtmp[7], "");
1765 }
1766 else
1767 {
1768 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1769 }
1770 if (roamingprotocol == NULL)
1771 {
1772 sprintf(strtmp[8], "");
1773 }
1774 else
1775 {
1776 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1777 }
1778 if (carrier == NULL)
1779 {
1780 sprintf(strtmp[9], "");
1781 }
1782 else
1783 {
1784 sprintf(strtmp[9], "carrier=%s;", carrier);
1785 }
1786 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]);
1787 return 0;
1788}
1789
rjw20006d12022-04-21 16:29:04 +08001790static char *lynqStrdupReadString(Parcel &p)
1791{
1792 size_t stringlen;
1793 const char16_t *s16;
1794
1795 s16 = p.readString16Inplace(&stringlen);
1796 return strndup16to8(s16, stringlen);
1797}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001798int get_imsi()
1799{
Hong_Liu25edfe72023-06-16 01:13:42 -07001800 Parcel *p =NULL;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001801 lynq_client_t client;
1802 int resp_type = -1;
1803 int token;
1804 int request = -1;
1805 int slot_id = -1;
1806 int error = -1;
1807 int version =0;
1808 int num = 0;
1809 char *temp_char = NULL;
1810 char mccmnc[32] = {0};
1811 char mccmnckey[64] = {0};
Hong_Liu25edfe72023-06-16 01:13:42 -07001812 client.uToken = get_utoken();
Hong_Liu7163bbe2023-06-04 03:03:44 -07001813 client.request = 11;//RIL_REQUEST_GET_IMSI 11
1814 client.paramLen = 0;
1815 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1816 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1817 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1818 if(send_request(lynq_client_sockfd,&client)==-1)
1819 {
1820 LYERRLOG("send request fail");
1821 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001822 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001823 return -1;
1824 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001825 //get_response(lynq_client_sockfd,p);
1826 error = wait_response(lynq_client_sockfd,p,client.uToken);
1827 if(error!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001828 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001829 LYERRLOG("wait_response fail,ret:%d",error);
1830 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001831 return error;
1832 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001833 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1834 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001835 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001836 LYERRLOG("JumpHeader fail");
Hong_Liu7163bbe2023-06-04 03:03:44 -07001837 return -1;
1838 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001839 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1840 if(error == 0)
1841 {
1842 char * test = strdupReadString_p(p);
1843 memcpy(mccmnc, test,5);
1844 mccmnc[5]='\0';
1845 free(test);
1846 sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
1847 system(mccmnckey);
1848 system("uci commit");
1849 }
1850 free_parcel(p);
1851 return error;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001852}
rjw20006d12022-04-21 16:29:04 +08001853int 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)
1854{
1855 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1856 {
1857 LYERRLOG("There are no valid parameters");
1858 return -1;
1859 }
1860 lynq_client_t client;
1861 char argc[512];
Hong_Liu7163bbe2023-06-04 03:03:44 -07001862 int res = -1;
rjw20006d12022-04-21 16:29:04 +08001863 if (cmd == 0) // insert apn db
1864 {
rjw61fcae32022-08-18 14:03:39 +08001865 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001866 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001867 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1868 client.paramLen = 2;
1869 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1870 sprintf(client.param, "%d %s", cmd, argc);
1871 }
rjw61fcae32022-08-18 14:03:39 +08001872 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001873 {
1874 if (NULL == id)
1875 {
1876 LYERRLOG("id is NULL!!!please input id: ");
1877 }
1878 sprintf(argc, "id=%s", id);
Hong_Liu25edfe72023-06-16 01:13:42 -07001879 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001880 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1881 client.paramLen = 2;
1882 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1883 sprintf(client.param, "%d %s", cmd, argc);
1884 }
rjw61fcae32022-08-18 14:03:39 +08001885 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001886 {
rjwaf4b1612022-06-13 17:26:01 +08001887 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001888 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001889 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1890 client.paramLen = 2;
1891 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1892 sprintf(client.param, "%d %s", cmd, argc);
1893 }
rjw61fcae32022-08-18 14:03:39 +08001894 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001895 {
1896 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001897 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001898 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1899 client.paramLen = 2;
1900 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1901 sprintf(client.param, "%d %s", cmd, argc);
1902 }
1903 else
1904 {
1905 LYERRLOG("incoming command is invalid");
1906 return -1;
1907 }
1908 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001909 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001910 if(send_request(lynq_client_sockfd,&client)==-1)
1911 {
1912 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001913 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001914 return -1;
1915 }
rjwed00d042022-05-25 09:18:16 +08001916 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001917 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001918 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001919 LYINFLOG(">>>>>output info:%s",out);
1920 return 0;
1921}
1922
1923int lynq_reset_apn(char *result)
1924{
rjw20006d12022-04-21 16:29:04 +08001925 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001926 if (NULL == result)
1927 {
1928 LYERRLOG("incoming paramters error");
1929 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001930 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001931 client.request = 2000 + 194;
1932 client.paramLen = 0;
1933 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1934 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001935 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001936 if (send_request(lynq_client_sockfd, &client) == -1)
1937 {
1938 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001939 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001940 return -1;
1941 }
rjwed00d042022-05-25 09:18:16 +08001942 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001943 waitApnResult();
1944 strcpy(result, g_lynq_apn_result);
1945 LYINFLOG(">>>>>result:%s",result);
1946 return 0;
1947}
1948
rjw3bcbbf12022-04-22 16:47:18 +08001949/*Typethree add for T800 platform 2022/04/21 end*/
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07001950static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) {
1951 FILE *fp;
1952 //printf("to exec cmd:%s\n", str_cmd);
1953 if((fp=popen(str_cmd,"r"))==NULL)
1954 {
1955 perror("popen error!");
1956 return -1;
1957 }
1958 if((fread(str_cmd_ret,max_len,1,fp))<0)
1959 {
1960 perror("fread fail!");
1961 fclose(fp);
1962 return -1;
1963 }
1964 fclose(fp);
1965 return 0;
1966}
1967int check_apn_status()
1968{
1969 LYINFLOG("check_apn_status enter");
1970 int ret = -1;
1971 char cmd_ret[8] ={0};//get mccmnc
1972 const char *cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc0";
1973 const char *empty_str = ":empty";
1974 ret = exec_cmd(cmd,cmd_ret,8);
1975 if(ret==0)
1976 {
1977 if(strlen(cmd_ret)==0)
1978 {
1979 LYERRLOG("not have mccmnc config in uci ram");
1980 return 1;
1981 }
1982 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
1983 {
1984 LYERRLOG("mccmnc is empty");
1985 return 2;
1986 }
1987 LYINFLOG("mccmnc is %s",cmd_ret);
1988 return 0;
1989 }
1990 else
1991 {
1992 LYERRLOG("exec cmd fail");
1993 return -1;
1994 }
1995 return 0;
1996}
lha62e0882023-10-31 05:17:11 -07001997int get_timeout_value()
1998{
1999 LYINFLOG("get_timeout_value enter");
2000 int ret = -1;
2001 char timeout_value[8] ={0};//get get_timeout_value
2002 ret = lynq_get_value("lynq_uci","data_call","timeout",timeout_value);
2003 if(ret == 0)
2004 {
2005 LYINFLOG("data_call.timeout is %s",timeout_value);
2006 return atoi(timeout_value);
2007 }
2008 else
2009 {
2010 LYERRLOG("get_timeout_value");
2011 return -1;
2012 }
2013}
2014
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002015int radio_switch(int status)
2016{
2017 Parcel *p =NULL;
2018 lynq_client_t client;
2019 int resp_type = -1;
2020 int token;
2021 int request = -1;
2022 int slot_id = -1;
2023 int error = -1;
2024 int version =0;
2025 int num = 0;
2026 char *temp_char = NULL;
2027 char mccmnc[32] = {0};
2028 char mccmnckey[64] = {0};
2029 client.uToken = get_utoken();
2030 client.request = 59;//RIL_REQUEST_OEM_HOOK_RAW 59
2031 client.paramLen = 1;
2032 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
2033 sprintf(client.param,"AT+CFUN=%d",status);
2034 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
2035 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
2036 if(send_request(lynq_client_sockfd,&client)==-1)
2037 {
2038 LYERRLOG("send request fail");
2039 perror("[LYNQ_DATA] send request fail:");
2040 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2041 return -1;
2042 }
2043 //get_response(lynq_client_sockfd,p);
2044 error = wait_response(lynq_client_sockfd,p,client.uToken);
2045 if(error!=0)
2046 {
2047 LYERRLOG("wait_response fail,ret:%d",error);
2048 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2049 return error;
2050 }
2051 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2052 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
2053 {
2054 LYERRLOG("JumpHeader fail");
2055 return -1;
2056 }
2057 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
2058 free_parcel(p);
2059 return error;
2060}