blob: 8add8138a90e68c08fe67dc37d92f4b4a9315360 [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;
xy.he509e4812024-08-26 16:06:56 +080041//xy.he add for bug-view-73 on 2024-08-26 start
42#ifdef MODE_DSDS
43typedef struct{
44 int uToken;
45 int request;
46 int paramLen;
47 char param[LYNQ_REQUEST_PARAM_BUF];
48 char slot_status;
49 char slot;
50}lynq_client_dual_t;
51
52#endif
53//xy.he add for bug-view-73 on 2024-08-26 end
lh13586612022-01-11 21:58:58 -080054typedef enum{
55 LYNQ_E_CARDSTATE_ERROR=8000,
56 /* The voice service state is out of service*/
57 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
58 /* The voice service state is EMERGENCY_ONLY*/
59 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
60 /* The radio power is power off*/
61 LYNQ_E_STATE_POWER_OFF=8003,
62 LYNQ_E_TIME_OUT=8004,
63 /*create or open sms DB fail */
64 LYNQ_E_SMS_DB_FAIL=8005,
65 /*Failed to execute sql statement*/
66 LYNQ_E_SMS_SQL_FAIL = 8006,
67 LYNQ_E_SMS_NOT_FIND = 8007,
Hong_Liu25edfe72023-06-16 01:13:42 -070068 LYNQ_E_GET_RESP_FAIL = 8008,
69 LYNQ_E_NOT_THIS_APN = 8087,
70 LYNQ_E_NOT_ANY_APN = 8088,
71 LYNQ_E_MD_NOT_READY = 8089,
lh13586612022-01-11 21:58:58 -080072 /* The logic conflict*/
73 LYNQ_E_CONFLICT=9000,
74 /*Null anomaly*/
75 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080076}LYNQ_E;
77
lha62e0882023-10-31 05:17:11 -070078typedef enum {
79 PDN_IDLE,
80 PDN_CONNECTING,
81 PDN_CONNECTED,
82 PDN_DISCONNECTING,
83 PDN_DISCONNECTED,
84 PDN_RETRYING,
85 PDN_FAILED,
86 PDN_SCANNING,
87 PDN_TIMEOUT_CANCEL,
88} RIL_Data_Call_PdnState;
89
lhf81a46f2022-02-13 23:57:37 -080090int lynq_client_sockfd = 0;
91int Global_uToken = 0;
Hong_Liu7e1b85e2023-05-16 05:51:57 -070092struct sockaddr_in lynq_data_socket_server_addr;
93int lynq_data_socket_server_addr_len;
rjw7ee7bb42023-01-18 11:34:28 +080094
lhf81a46f2022-02-13 23:57:37 -080095int lynq_data_call_change_id = -1;
xy.hef5d74f12023-10-23 06:48:52 -070096int lynq_telephony_restart_g = 0;
lhf81a46f2022-02-13 23:57:37 -080097pthread_t lynq_data_tid =-1;
98static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
99static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +0800100
Hong_Liu25edfe72023-06-16 01:13:42 -0700101static pthread_mutex_t s_data_call_deactived_mutex = PTHREAD_MUTEX_INITIALIZER;
102static pthread_cond_t s_data_call_deactived_cond = PTHREAD_COND_INITIALIZER;
103
104
rjw20006d12022-04-21 16:29:04 +0800105static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
106static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +0800107static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
108static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER;
rjwed00d042022-05-25 09:18:16 +0800109/**g_lynq_data_sendto_mutex
110* @brief mark data send request mutex
111*/
112static pthread_mutex_t g_lynq_data_sendto_mutex;
rjwf9ec3832023-04-12 10:59:15 +0800113/*This value data the state of the wait*/
rjwc3d6e582023-03-28 17:19:11 +0800114static int data_waiting_status = 0;
rjwf9ec3832023-04-12 10:59:15 +0800115/*The value indicates that 8085 error occurs in data*/
rjwc63abb42023-03-31 18:22:42 +0800116static int data_invaild_error = 0;
rjwf9ec3832023-04-12 10:59:15 +0800117/*This value ensure the data call timing is correct*/
118static int data_timelimit = 0;
rjwc63abb42023-03-31 18:22:42 +0800119
rjw22947c22022-03-15 09:21:29 +0800120/**g_lynq_data_init_flag
121* @brief mark data initialization state
122* 0:deinit status
123* 1:init state
124*/
125static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +0800126/**g_lynq_apn_result
127* @brief temp of apn result info
128*/
129char g_lynq_apn_result[1024] = {};
lha62e0882023-10-31 05:17:11 -0700130int g_data_call_timeout_value = LYNQ_DATA_TIME_OUT;
rjw747deea2022-07-01 18:25:30 +0800131
rjw7ee7bb42023-01-18 11:34:28 +0800132static std::vector<int> s_data_urc_wait_list;
133
rjw20006d12022-04-21 16:29:04 +0800134typedef struct
135{
lhf81a46f2022-02-13 23:57:37 -0800136 char apn[LYNQ_APN_MAX_LEN];
137 char apnType[LYNQ_APN_TYPE_MAX_LEN];
138 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
139 int hasUsed;
140 int hasTimeout;
Hong_Liudc46d412023-05-18 13:36:26 -0700141 int status;
142 char statusApnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800143}lynq_apn_t;
144lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
145lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
146int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800147
xy.hef5d74f12023-10-23 06:48:52 -0700148int radio_switch(int status);
149
lhf81a46f2022-02-13 23:57:37 -0800150int getLynqApnID(char apnType[])
151{
152 int ret = 0;
rjwc63abb42023-03-31 18:22:42 +0800153 int len = 0;
lhf81a46f2022-02-13 23:57:37 -0800154 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
155 {
Hong_Liudc46d412023-05-18 13:36:26 -0700156 len = strlen(apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700157 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 +0800158 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
lh13586612022-01-11 21:58:58 -0800159 {
lhf81a46f2022-02-13 23:57:37 -0800160 return ret;
161 }
162 }
163 return -1;
164}
rjw7ee7bb42023-01-18 11:34:28 +0800165
Hong_Liudc46d412023-05-18 13:36:26 -0700166int getDeactApnID(char apnType[])
167{
168 int ret = 0;
169 int len = 0;
170 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
171 {
172 len = strlen(apnType);
173 LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len);
174 if(strncmp(lynq_apn_table[ret].statusApnType,apnType,len)==0)
175 {
176 return ret;
177 }
178 }
179 return -1;
180}
181
lhf81a46f2022-02-13 23:57:37 -0800182void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
183{
184 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
185 if(apn_table==NULL)
186 {
187 LYERRLOG("apn_table is null");
188 return;
189 }
190 memcpy(apn_table->apn,apn,strlen(apn)+1);
191 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
192 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
193 apn_table->hasTimeout = 0;
194 apn_table->hasUsed = 1;
195 return;
196}
rjw7ee7bb42023-01-18 11:34:28 +0800197
lhf81a46f2022-02-13 23:57:37 -0800198void cleanOnceApnTable(int apnId)
199{
Hong_Liudc46d412023-05-18 13:36:26 -0700200 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
lhf81a46f2022-02-13 23:57:37 -0800201 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
202 {
203 LYERRLOG("apn id is invalid!!!");
204 return;
205 }
206 lynq_apn_table[apnId].hasTimeout = 0;
207 lynq_apn_table[apnId].hasUsed = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700208 memcpy(lynq_apn_table[apnId].statusApnType,lynq_apn_table[apnId].apnType,strlen(lynq_apn_table[apnId].apnType));
lhf81a46f2022-02-13 23:57:37 -0800209 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700210 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
lhf81a46f2022-02-13 23:57:37 -0800211 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700212 lynq_apn_table[apnId].status = 32;
lhf81a46f2022-02-13 23:57:37 -0800213 return;
214}
Hong_Liudc46d412023-05-18 13:36:26 -0700215void cleanDeactApn(int apnId)
216{
217 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
218 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
219 {
220 LYERRLOG("apn id is invalid!!!");
221 return;
222 }
223 lynq_apn_table[apnId].status = 0;
224 bzero(lynq_apn_table[apnId].statusApnType,LYNQ_APN_TYPE_MAX_LEN);
225}
226
227void updateDeactApn(int apnId,int pdnState)
228{
229 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
230 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
231 {
232 LYERRLOG("apn id is invalid!!!");
233 return;
234 }
235 lynq_apn_table[apnId].status = pdnState;
236}
237
238
lhf81a46f2022-02-13 23:57:37 -0800239int getUnusedElement()
240{
Hong_Liudc46d412023-05-18 13:36:26 -0700241 if (lynq_apn_table == NULL)
242 {
243 LYERRLOG("get UnusedElemnt apn_table is null");
244 return -1;
245 }
lhf81a46f2022-02-13 23:57:37 -0800246 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
247 {
248 if(lynq_apn_table[i].hasUsed!=1)
249 {
250 return i;
251 }
252 }
rjwc63abb42023-03-31 18:22:42 +0800253 LYERRLOG("None of get unused Element");
lhf81a46f2022-02-13 23:57:37 -0800254 return -1;
255}
256int updateApn(char apnType[])
257{
258 int ret = 0;
259 ret = getUnusedElement();
Hong_Liu55668712023-05-16 21:49:17 -0700260 if(ret >= 0)
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700261 {
262 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
263 lynq_apn_table[ret].hasUsed = 1;
264 }
lhf81a46f2022-02-13 23:57:37 -0800265 return ret;
266}
Hong_Liu55c62f52023-08-24 19:05:50 -0700267//@return
268//other:this apn has been used in apn table
269//-1:this apn not has been used in apn table
270int check_used_apn(char apnType[])
271{
272 LYINFLOG("check_used_apn.apnType:%s",apnType);
273 int ret = 0;
274 int len = 0;
275 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
276 {
277 len = strlen(apnType);
278 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
279 {
280 LYINFLOG("check_used_apn.apnType:%s in apn table",apnType);
281 return ret;
282 }
283 }
284 return -1;
285}
286int get_handle(char apnType[])
287{
288 int call_id = 0;
289 call_id = check_used_apn(apnType);
290 if(call_id == -1)
291 {
292 call_id = updateApn(apnType);
293 }
294 LYINFLOG("handle:%d",call_id);
295 return call_id;
296}
rjw1309e232022-07-22 09:54:06 +0800297
298int handleCheck(int handle)
299{
Hong_Liu7163bbe2023-06-04 03:03:44 -0700300 if ((handle >= 0) && (handle <= 6))
rjw1309e232022-07-22 09:54:06 +0800301 {
Hong_Liu7163bbe2023-06-04 03:03:44 -0700302 if (lynq_apn_table[handle].hasUsed == 1)
303 {
304 return 0;
305 }
rjw1309e232022-07-22 09:54:06 +0800306 return -1;
307 }
Hong_Liu7163bbe2023-06-04 03:03:44 -0700308 return -1;
rjw1309e232022-07-22 09:54:06 +0800309}
rjw20006d12022-04-21 16:29:04 +0800310int waitApnResult()
311{
312 int ret = 0;
313 LYINFLOG("start wait apn result!!!");
314 int sec = 0;
315 int usec = 0;
316 struct timeval now;
317 struct timespec timeout;
318 gettimeofday(&now, NULL);
319 sec = 20000 / 1000;
320 usec = 20000 % 1000;
321 timeout.tv_sec = now.tv_sec + sec;
322 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
323 pthread_mutex_lock(&s_lynq_apn_change_mutex);
324 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
325 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
326 return ret;
327}
328
329void sendSignalApnChange()
330{
331 LYINFLOG("start send Signal Apn Change");
332 pthread_mutex_lock(&s_lynq_apn_change_mutex);
333 pthread_cond_signal(&s_lynq_apn_change_cond);
334 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
335 return;
336}
lhf81a46f2022-02-13 23:57:37 -0800337
338int waitPdnChange()
339{
340 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800341 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
342 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
343 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800344 return ret;
345}
346int waitDataCallstateChange(int mtime)
347{
348 int ret = 0;
349 int sec = 0;
350 int usec = 0;
351 struct timeval now;
352 struct timespec timeout;
353 gettimeofday(&now,NULL);
354 sec = mtime/1000;
355 usec = mtime%1000;
356 timeout.tv_sec = now.tv_sec+sec;
357 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
358 pthread_mutex_lock(&s_data_call_state_change_mutex);
359 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
360 pthread_mutex_unlock(&s_data_call_state_change_mutex);
361 return ret;
362}
363void sendSignalDataCallStateChange()
364{
365 pthread_mutex_lock(&s_data_call_state_change_mutex);
366 pthread_cond_signal(&s_data_call_state_change_cond);
367 pthread_mutex_unlock(&s_data_call_state_change_mutex);
368 return;
369}
Hong_Liu25edfe72023-06-16 01:13:42 -0700370int waitDeactived(int mtime)
371{
372 int ret = 0;
373 int sec = 0;
374 int usec = 0;
375 struct timeval now;
376 struct timespec timeout;
377 gettimeofday(&now,NULL);
378 sec = mtime/1000;
379 usec = mtime%1000;
380 timeout.tv_sec = now.tv_sec+sec;
381 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
382 pthread_mutex_lock(&s_data_call_deactived_mutex);
383 ret = pthread_cond_timedwait(&s_data_call_deactived_cond,&s_data_call_deactived_mutex,&timeout);
384 pthread_mutex_unlock(&s_data_call_deactived_mutex);
385 return ret;
386}
387void sendSignalDeactvied()
388{
389 pthread_mutex_lock(&s_data_call_deactived_mutex);
390 pthread_cond_signal(&s_data_call_deactived_cond);
391 pthread_mutex_unlock(&s_data_call_deactived_mutex);
392 return;
393}
394
lhf81a46f2022-02-13 23:57:37 -0800395void sendSignalPdnChange()
396{
rjw7ee7bb42023-01-18 11:34:28 +0800397 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
398 pthread_cond_signal(&s_lynq_urc_vector_cond);
399 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800400 return;
401}
402
403int get_response(int sockfd,Parcel &p)
404{
405 int len = 0;
406 char recvline[LYNQ_REC_BUF];
407 bzero(recvline,LYNQ_REC_BUF);
408 /* receive data from server */
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700409 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
410 //len = read(sockfd, recvline, LYNQ_REC_BUF);
rjw08528682022-07-04 21:28:02 +0800411 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800412 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700413 LYERRLOG("get_response fail,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800414 return -1;
415 }
416 if (recvline != NULL) {
417 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
418 p.setDataPosition(0);
419 }
420 return 0;
421}
Hong_Liu25edfe72023-06-16 01:13:42 -0700422/**@brief get utoken in range 0 to 10000
423* @return utoken
424*/
425int get_utoken()
lhf81a46f2022-02-13 23:57:37 -0800426{
Hong_Liu25edfe72023-06-16 01:13:42 -0700427 return (Global_uToken++)%10000;/*0-10000*/
428}
429/**@brief wait response with expected token and write msg to parcel in some time
430* @param fd [IN]: socket fd
431* @param p [OUT]: quote the parcel,if return success need delete p.
432* @param token [IN]: the expected token for the response msg
433* @return
434* 0:success
435* other:failure
436*/
437int wait_response(int sockfd,Parcel *& p,int utoken)
438{
439 int len = 0;
440 int flag = 1;
441 int count = 0;
442 int in_utoken = -1;
443 int resp_type = -1;
444 Parcel *temp = NULL;
445 char recvline[LYNQ_REC_BUF];
446 //Sometimes the socket is abnormal, causing the socket buffer to store the response of the last request.
447 //Here it does not return until the response corresponding to the request is read.
448 while(flag && (count < 20))//why?
lhf81a46f2022-02-13 23:57:37 -0800449 {
Hong_Liu25edfe72023-06-16 01:13:42 -0700450 bzero(recvline,LYNQ_REC_BUF);
451 count++;
452 LYINFLOG("wait_response,count:%d",count);
453 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
454 if(len == -1)
455 {
456 LYERRLOG("wait_response fail,errno:%d",errno);
457 return LYNQ_E_GET_RESP_FAIL;
458 }
459 if (len != 0)
460 {
461 temp = new Parcel;
462 int i = 0;
463 while((NULL == temp) && (i < 100))
464 {
465 usleep(1000);
466 temp = new Parcel;
467 i++;
468 }
469 if((i >= 100) || (NULL == temp))
470 {
471 LYERRLOG("wait_response i:%d",i);
472 return LYNQ_E_GET_RESP_FAIL;
473 }
474 temp->setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
475 temp->setDataPosition(0);
476 temp->readInt32(&resp_type);
477 temp->readInt32(&in_utoken);
478 LYINFLOG("[%s]in_utoken:%d,utoken:%d",__FUNCTION__,in_utoken,utoken);
479 if (in_utoken != utoken)
480 {
481 delete temp;
482 temp = NULL;
483 in_utoken = 0;
484 continue;
485 }
486 temp->setDataPosition(0);
487 p = temp;
488 flag = 0;
489 return 0;
490 }
491 else
492 {
493 LYERRLOG("recvline is null,errno:%d",errno);
494 return LYNQ_E_GET_RESP_FAIL;
495 }
496 }
497 return LYNQ_E_GET_RESP_FAIL;
498}
499
500int JumpHeader(Parcel *p,int *resp_type,int *utoken,int *request,int *slot_id,int *error)
501{
502 if(NULL == p)
503 {
504 LYERRLOG("JumpHeader is null");
505 return -1;
506 }
507 if(p->dataAvail() > 0)
508 {
509 p->readInt32(resp_type);
510 p->readInt32(utoken);
511 p->readInt32(request);
512 p->readInt32(slot_id);
513 p->readInt32(error);
lhf81a46f2022-02-13 23:57:37 -0800514 return 0;
515 }
516 else
517 {
518 return -1;
519 }
520}
Hong_Liu25edfe72023-06-16 01:13:42 -0700521void free_parcel(Parcel *p)
522{
523 if(p)
524 {
525 delete p;
526 p = NULL;
527 }
528}
xy.he509e4812024-08-26 16:06:56 +0800529//xy.he add for bug-view-73 on 2024-08-26 start
530int send_request_dual(int sockfd,lynq_client_dual_t *client_tmp,int size)
531{
532 int ret=0;
533 LYINFLOG("client size = %d",size);
534 ret = sendto(sockfd,client_tmp,size,0,(struct sockaddr *)&lynq_data_socket_server_addr,lynq_data_socket_server_addr_len);
535 LYINFLOG("sendto size = %d",ret);
536 if(ret==-1)
537 {
538 LYERRLOG("%s:errno code:%d",__FUNCTION__,errno);
539 return -1;
540 }
541 return 0;
542}
543//xy.he add for bug-view-73 on 2024-08-26 end
lhf81a46f2022-02-13 23:57:37 -0800544int send_request(int sockfd,lynq_client_t *client_tmp)
545{
546 int ret=0;
lh8d290112023-10-22 20:53:06 -0700547 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 -0800548 if(ret==-1)
549 {
lh8d290112023-10-22 20:53:06 -0700550 LYERRLOG("%s:errno code:%d",__FUNCTION__,errno);
lhf81a46f2022-02-13 23:57:37 -0800551 return -1;
552 }
553 return 0;
554}
555static char *strdupReadString(Parcel &p) {
556 size_t stringlen;
557 const char16_t *s16;
558 s16 = p.readString16Inplace(&stringlen);
559 return strndup16to8(s16, stringlen);
560}
561static char *strdupReadString_p(Parcel *p) {
562 size_t stringlen;
563 const char16_t *s16;
564 s16 = p->readString16Inplace(&stringlen);
565 return strndup16to8(s16, stringlen);
566}
567
lhf81a46f2022-02-13 23:57:37 -0800568/*Warren add for T800 platform 2021/11/19 start*/
569int lynq_socket_client_start()
570{
lh8d290112023-10-22 20:53:06 -0700571 int ret;
572 struct timeval timeOut;
573 struct sockaddr_in liblynq_data_socket;
rjw747deea2022-07-01 18:25:30 +0800574
lh8d290112023-10-22 20:53:06 -0700575 ret = 0;
rjwa59bf312022-07-05 11:50:31 +0800576 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800577 timeOut.tv_usec = 0;
lh8d290112023-10-22 20:53:06 -0700578 bzero(&liblynq_data_socket, sizeof(liblynq_data_socket));
579 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
580
581 //set this lib socket config
582 liblynq_data_socket.sin_family = AF_INET;
583 liblynq_data_socket.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
rjw747deea2022-07-01 18:25:30 +0800584
lh8d290112023-10-22 20:53:06 -0700585 //set ril service socket config
586 lynq_data_socket_server_addr.sin_family = AF_INET;
587 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
588 lynq_data_socket_server_addr.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
589 lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr);
590
591 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
592 ret = bind(lynq_client_sockfd, (struct sockaddr *)&liblynq_data_socket, sizeof(liblynq_data_socket));
593 if (-1 == ret)
594 {
595 LYERRLOG("liblynq_data_socket bind fail,errno:%d",errno);
596 return -1;
597 }
rjw747deea2022-07-01 18:25:30 +0800598 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
599 {
lh8d290112023-10-22 20:53:06 -0700600 LYERRLOG("time out setting failed,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800601 return -1;
602 }
603 return 0;
604}
rjw7ee7bb42023-01-18 11:34:28 +0800605
606bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800607{
rjw7ee7bb42023-01-18 11:34:28 +0800608 switch(urc_id)
609 {
610 case LYNQ_URC_DATA_CALL_STATUS_IND:
611
612 case LYNQ_URC_MODIFY_APNDB:
613 case LYNQ_URC_RESET_APNDB:
xy.hef5d74f12023-10-23 06:48:52 -0700614 case LYNQ_TELEPHONY_RESTART:
rjw7ee7bb42023-01-18 11:34:28 +0800615 return true;
616 default:
617 return false;
618 }
619}
620
rjwc63abb42023-03-31 18:22:42 +0800621int printf_apn_table()
622{
623 int ret = 0;
Hong_Liu6149f182023-05-12 02:15:14 -0700624 if (lynq_apn_table == NULL)
625 {
626 LYERRLOG("apn table is null");
627 return -1;
628 }
rjwc63abb42023-03-31 18:22:42 +0800629 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
630 {
Hong_Liudc46d412023-05-18 13:36:26 -0700631 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 +0800632 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
Hong_Liudc46d412023-05-18 13:36:26 -0700633 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 +0800634 }
635 return 0;
636}
637
Hong_Liu6149f182023-05-12 02:15:14 -0700638void printf_apn_table_debug(const char *fun,int line)
639{
640 LYINFLOG("[%s][%d]apn_table msg",fun,line);
641 printf_apn_table();
642}
rjwc63abb42023-03-31 18:22:42 +0800643
rjw7ee7bb42023-01-18 11:34:28 +0800644void urc_msg_process(Parcel *p)
645{
646 int len;
647 int resp_type;
648 int urcid;
649 int slot_id;
rjwf9ec3832023-04-12 10:59:15 +0800650 int check_count = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700651 static int apnId=-1;
rjw7ee7bb42023-01-18 11:34:28 +0800652
653 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800654 char apn[LYNQ_APN_MAX_LEN];
655 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800656 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800657 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800658
659 int size = p->dataSize();
660 p->readInt32(&resp_type);
661 p->readInt32(&urcid);
662 p->readInt32(&slot_id);
663 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
664 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800665 {
rjw7ee7bb42023-01-18 11:34:28 +0800666 case LYNQ_URC_DATA_CALL_STATUS_IND:
667 p->readInt32(&pdnState);
668 bzero(apn,LYNQ_APN_MAX_LEN);
669 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
670 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
lha62e0882023-10-31 05:17:11 -0700671 if(pdnState != RIL_Data_Call_PdnState::PDN_DISCONNECTED)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800672 {
rjw20006d12022-04-21 16:29:04 +0800673 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800674 int len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700675 if((len < LYNQ_APN_MAX_LEN-1) && (len > 0))
rjw20006d12022-04-21 16:29:04 +0800676 {
rjw7ee7bb42023-01-18 11:34:28 +0800677 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800678 }
Hong_Liu6149f182023-05-12 02:15:14 -0700679 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800680 urc_msg = strdupReadString_p(p);
681 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700682 if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800683 {
684 memcpy(apnType,urc_msg,len+1);
685 }
Hong_Liu6149f182023-05-12 02:15:14 -0700686 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800687 urc_msg = strdupReadString_p(p);
688 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700689 if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800690 {
691 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
692 }
Hong_Liu6149f182023-05-12 02:15:14 -0700693 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800694 //sendSignalDataCallStateChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700695 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800696 if(apnId >= 0)
697 {
Hong_Liudc46d412023-05-18 13:36:26 -0700698 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800699 if(lynq_apn_table[apnId].hasTimeout==1)
700 {
rjwc63abb42023-03-31 18:22:42 +0800701 /*whether timeout?,real or not,*/
702 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800703 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800704 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 +0800705 {
706 LYERRLOG("deactive this time out APN");
707 lynq_deactive_data_call(&apnId);
708 }
rjwc63abb42023-03-31 18:22:42 +0800709 else
rjw7ee7bb42023-01-18 11:34:28 +0800710 {
rjwc63abb42023-03-31 18:22:42 +0800711 /*if apn lose,update apn and deactive all apn*/
712 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800713 }
714 break;
715 }
rjwacdb2152023-02-07 14:12:49 +0800716 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
Hong_Liu6149f182023-05-12 02:15:14 -0700717 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800718 }
719 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800720 else
721 {
Hong_Liu6149f182023-05-12 02:15:14 -0700722 data_invaild_error = 1;
Hong_Liudc46d412023-05-18 13:36:26 -0700723 printf_apn_table_debug(__FUNCTION__,__LINE__);
724 apnId = getDeactApnID(apnType);
725 if(apnId < 0)
726 {
727 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
728 break;
729 }
730 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
731 updateDeactApn(apnId,pdnState);
732 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800733 }
rjw7ee7bb42023-01-18 11:34:28 +0800734 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
735 s_data_urc_wait_list.push_back(apnId);
736 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
737 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800738 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800739 LYDBGLOG("data call state:%d",lynq_data_call);
740 if(lynq_data_call==1)
741 {
rjwf9ec3832023-04-12 10:59:15 +0800742 while (data_timelimit == 0)
743 {
744 LYINFLOG("client not ready to wait");
745 for (check_count = 0;check_count < 500;check_count++)
746 {
747 /*wait 10ms*/
748 usleep(10*1000);
749 }
750 LYERRLOG("client still without res");
751 break;
752 }
lha62e0882023-10-31 05:17:11 -0700753 if(pdnState == RIL_Data_Call_PdnState::PDN_TIMEOUT_CANCEL)
754 {
755 lynq_data_call = LYNQ_E_TIME_OUT;
756 }
757 else
758 {
759 lynq_data_call = 0;
760 }
rjw7ee7bb42023-01-18 11:34:28 +0800761 sendSignalDataCallStateChange();
rjwf9ec3832023-04-12 10:59:15 +0800762 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800763 }
Hong_Liu6149f182023-05-12 02:15:14 -0700764 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800765 }
rjw7ee7bb42023-01-18 11:34:28 +0800766 else
rjw20006d12022-04-21 16:29:04 +0800767 {
rjw7ee7bb42023-01-18 11:34:28 +0800768 urc_msg = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -0700769 free(urc_msg);
770 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800771 len = strlen(urc_msg);
772 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
773 {
774 memcpy(apnType,urc_msg,len+1);
775 }
Hong_Liu6149f182023-05-12 02:15:14 -0700776 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800777 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
Hong_Liudc46d412023-05-18 13:36:26 -0700778 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800779 if(apnId >= 0)
780 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700781 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 -0700782 lynq_data_call_change_id = apnId;
783 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
784 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
785 s_data_urc_wait_list.push_back(apnId);
786 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
787 sendSignalPdnChange();
788 }
789 else
790 {
791 apnId = getDeactApnID(apnType);
792 if(apnId < 0)
793 {
794 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
795 break;
796 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700797 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 -0700798 cleanDeactApn(apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800799 lynq_data_call_change_id = apnId;
800 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800801 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
802 s_data_urc_wait_list.push_back(apnId);
803 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -0700804 sendSignalDeactvied();
rjwc3d6e582023-03-28 17:19:11 +0800805 sendSignalPdnChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700806 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800807 }
rjw7ee7bb42023-01-18 11:34:28 +0800808 LYDBGLOG("data call state:%d",lynq_data_call);
809 if(lynq_data_call==1)
810 {
rjwf9ec3832023-04-12 10:59:15 +0800811 while (data_timelimit == 0)
812 {
813 LYINFLOG("client not ready to wait");
814 for (check_count = 0;check_count < 500;check_count++)
815 {
816 /*wait 10ms*/
817 usleep(10*1000);
818 }
819 LYERRLOG("client still without res");
820 break;
821 }
rjw7ee7bb42023-01-18 11:34:28 +0800822 sendSignalDataCallStateChange();
823 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800824 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800825 }
Hong_Liu6149f182023-05-12 02:15:14 -0700826 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800827 }
828 break;
829 case LYNQ_URC_MODIFY_APNDB:
830 urc_msg = strdupReadString_p(p);
831 if (NULL == urc_msg)
832 {
833 LYERRLOG("error apn msg");
834 }
835 else
836 {
837 bzero(g_lynq_apn_result, 1024);
838 strcpy(g_lynq_apn_result, urc_msg);
839 sendSignalApnChange();
840 }
Hong_Liu6149f182023-05-12 02:15:14 -0700841 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800842 break;
843 case LYNQ_URC_RESET_APNDB:
844 {
rjw20006d12022-04-21 16:29:04 +0800845 urc_msg = strdupReadString_p(p);
846 if (NULL == urc_msg)
847 {
848 LYERRLOG("error apn msg");
849 }
850 else
851 {
852 bzero(g_lynq_apn_result, 1024);
853 strcpy(g_lynq_apn_result, urc_msg);
854 sendSignalApnChange();
855 }
Hong_Liu6149f182023-05-12 02:15:14 -0700856 free(urc_msg);
xy.heac05ee02023-11-29 14:36:31 +0800857 break;
rjw20006d12022-04-21 16:29:04 +0800858 }
xy.hef5d74f12023-10-23 06:48:52 -0700859 case LYNQ_TELEPHONY_RESTART:
860 {
861 if(slot_id == 0)
862 {
863 RLOGI("data has received telephony has restart");
864 RLOGI("handle set to 10");
865 lynq_telephony_restart_g = 1;
866 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
867 s_data_urc_wait_list.push_back(TELEPHONY_RESTART);
868 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
xy.hef5d74f12023-10-23 06:48:52 -0700869 sendSignalPdnChange();
870 }
xy.heac05ee02023-11-29 14:36:31 +0800871 break;
xy.hef5d74f12023-10-23 06:48:52 -0700872 }
rjw7ee7bb42023-01-18 11:34:28 +0800873 default:
874 break;
lhf81a46f2022-02-13 23:57:37 -0800875 }
rjw7ee7bb42023-01-18 11:34:28 +0800876
lhf81a46f2022-02-13 23:57:37 -0800877}
rjw7ee7bb42023-01-18 11:34:28 +0800878
rjw7ee7bb42023-01-18 11:34:28 +0800879int create_urc_vector_signal_thread()
880{
881 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800882 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800883 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
884 s_data_urc_wait_list.clear();
885 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800886 return 0;
887}
Hong_Liu25edfe72023-06-16 01:13:42 -0700888int get_imsi();
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700889int check_apn_status();
xy.he509e4812024-08-26 16:06:56 +0800890//xy.he add for bug-view-73 on 2024-08-26 start
891int getDataSim();
892//xy.he add for bug-view-73 on 2024-08-26 end
lha62e0882023-10-31 05:17:11 -0700893int get_timeout_value();
lhf81a46f2022-02-13 23:57:37 -0800894int lynq_init_data(int uToken)
895{
q.huangf6a9ddc2023-12-08 20:23:56 +0800896 LYLOGSET(LOG_INFO);
897 LYLOGEINIT(USER_LOG_TAG);
q.huang78c21ff2023-12-13 20:46:43 +0800898 LYERRLOG("%s start, parameter is %d", __func__,uToken);
q.huangf6a9ddc2023-12-08 20:23:56 +0800899
rjw22947c22022-03-15 09:21:29 +0800900 if (g_lynq_data_init_flag == 1)
901 {
902 LYERRLOG("init twice is not allowed");
903 return -1;
904 }
905 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800906 int result = 0;
907 Global_uToken = uToken;
q.huangf6a9ddc2023-12-08 20:23:56 +0800908
lha62e0882023-10-31 05:17:11 -0700909 int ret = get_timeout_value();
910 if(ret >= 30000)
911 {
912 g_data_call_timeout_value = ret;
913 }
914 else
915 {
916 LYERRLOG("timeout must greater or equal to 30s!!!");
917 }
lhf81a46f2022-02-13 23:57:37 -0800918 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800919 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800920 if(result!=0)
921 {
922 LYERRLOG("init socket client fail!!!");
923 return -1;
924 }
rjw7ee7bb42023-01-18 11:34:28 +0800925 result = lynq_init_data_urc_thread();
926 if(result!=0)
927 {
928 LYERRLOG("init socket urc fail!!!");
929 return -1;
930 }
931
932 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800933 if(result!=0)
934 {
935 LYERRLOG("init socket urc fail!!!");
936 return -1;
937 }
938 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700939 LYINFLOG("[%s] radio on/off solution 20230724",__FUNCTION__);
Hong_Liu25edfe72023-06-16 01:13:42 -0700940 int count = 0;
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700941 while(count < 2)//try recover the network within 10s.
942 {
943 result = check_apn_status();
944 if(result==0)
945 {
946 break;
947 }
948 radio_switch(0);
949 sleep(1);
950 radio_switch(1);
951 sleep(3);
952 count++;
953 }
954 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
955 if(result!=0)
956 {
957 LYDBGLOG("lynq init call fail!!!");
958 return LYNQ_E_MD_NOT_READY;//
959 }
960 /* old
Hong_Liu25edfe72023-06-16 01:13:42 -0700961 while(count < 10)
962 {
963 result = get_imsi();
964 if(result==0)
965 {
966 break;
967 }
968 sleep(1);
969 count++;
970 }
971 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
972 if(result!=0)
973 {
974 LYDBGLOG("lynq init call fail!!!");
975 return LYNQ_E_MD_NOT_READY;//
976 }
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700977 */
q.huangf6a9ddc2023-12-08 20:23:56 +0800978 LYERRLOG("%s end suc", __func__);
lhf81a46f2022-02-13 23:57:37 -0800979 return 0;
980
981}
982int lynq_deinit_data()
983{
q.huangf6a9ddc2023-12-08 20:23:56 +0800984 LYERRLOG("%s start", __func__);
985
986 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800987 if (g_lynq_data_init_flag == 0)
988 {
989 LYERRLOG("deinit twice is not allowed");
990 return ret;
991 }
992 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800993 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
994 {
995 if(strlen(lynq_apn_table[i].apnType)!=0)
996 {
997 lynq_deactive_data_call(&i);
998 }
999 }
1000 if(lynq_client_sockfd>0)
1001 {
1002 close(lynq_client_sockfd);
1003 }
rjw7ee7bb42023-01-18 11:34:28 +08001004 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +08001005 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +08001006 {
rjw7ee7bb42023-01-18 11:34:28 +08001007 LYERRLOG("lynq_deinit_data_urc_thread fail");
1008 return ret;
rjw22947c22022-03-15 09:21:29 +08001009 }
rjwc3d6e582023-03-28 17:19:11 +08001010 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1011 s_data_urc_wait_list.clear();
1012 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
q.huangf6a9ddc2023-12-08 20:23:56 +08001013 LYERRLOG("%s end suc", __func__);
lhf81a46f2022-02-13 23:57:37 -08001014 return 0;
1015}
1016int lynq_setup_data_call(int *handle)
1017{
Hong_Liue54db8c2023-04-21 02:37:23 -07001018 int error = -1;
lha62e0882023-10-31 05:17:11 -07001019 if (g_lynq_data_init_flag == 0)
1020 {
1021 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
1022 return error;
1023 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001024 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
1025 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
Hong_Liue9879152023-04-25 20:40:26 -07001026 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -07001027 #else
Hong_Liu25edfe72023-06-16 01:13:42 -07001028 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001029 lynq_client_t client;
1030 int resp_type = -1;
1031 int request = -1;
1032 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -08001033 int lynq_data_call_id = 0;
1034 if(handle==NULL)
1035 {
1036 LYERRLOG("handle is null!!!");
1037 return LYNQ_E_NULL_ANONALY;
1038 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001039 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001040 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1041 client.paramLen = 0;
1042 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1043 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -07001044 lynq_data_call_id = get_handle("default");
rjwc63abb42023-03-31 18:22:42 +08001045 if (lynq_data_call_id < 0)
1046 {
1047 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001048 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001049 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001050 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect.
1051 //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate.
rjw733b9832023-04-03 10:20:08 +08001052 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001053 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001054 if(send_request(lynq_client_sockfd,&client)==-1)
1055 {
1056 LYERRLOG("send request fail");
1057 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001058 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001059 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001060 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001061 //get_response(lynq_client_sockfd,p);
1062 error = wait_response(lynq_client_sockfd,p,client.uToken);
1063 if(error!=0)
1064 {
1065 LYERRLOG("wait_response fail,ret:%d",error);
1066 printf_apn_table_debug(__FUNCTION__,__LINE__);
1067 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1068 return error;
1069 }
rjwed00d042022-05-25 09:18:16 +08001070 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liuaa7f4b32023-07-19 07:51:25 -07001071 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
Hong_Liu25edfe72023-06-16 01:13:42 -07001072 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001073 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -08001074 if(error==0)
1075 {
rjwf9ec3832023-04-12 10:59:15 +08001076 data_timelimit = 1;
lha62e0882023-10-31 05:17:11 -07001077 if (waitDataCallstateChange(g_data_call_timeout_value) == ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001078 {
1079 error = LYNQ_E_TIME_OUT;
1080 LYERRLOG("timeout:wait data Call state fail!!!");
1081 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001082 if (data_invaild_error == 1)
1083 {
1084 data_invaild_error = 0;
1085 LYERRLOG("urc apn info error!!!");
1086 return 8085;
1087 }
1088 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001089 return error;
1090 }
lha62e0882023-10-31 05:17:11 -07001091 if(lynq_data_call == LYNQ_E_TIME_OUT)
1092 {
1093 error = LYNQ_E_TIME_OUT;
1094 LYERRLOG("PDN_TIMEOUT_CANCLE:wait data Call state fail!!!");
1095 printf_apn_table_debug(__FUNCTION__,__LINE__);
1096 return error;
1097 }
lhf81a46f2022-02-13 23:57:37 -08001098 }
Hong_Liu6149f182023-05-12 02:15:14 -07001099 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liue54db8c2023-04-21 02:37:23 -07001100 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001101 return error;
1102}
rjw7ee7bb42023-01-18 11:34:28 +08001103
xy.hefb1ab522024-01-17 13:48:45 +08001104void deactiveAfterTimeout(int apnId)
1105{
1106 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
1107 cleanDeactApn(apnId);
1108 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1109 s_data_urc_wait_list.push_back(apnId);
1110 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1111 sendSignalPdnChange();
1112}
lhf81a46f2022-02-13 23:57:37 -08001113int lynq_deactive_data_call(int *handle)
1114{
Hong_Liu25edfe72023-06-16 01:13:42 -07001115 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001116 lynq_client_t client;
1117 int resp_type = -1;
1118 int request = -1;
1119 int slot_id = -1;
1120 int error = -1;
1121 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +08001122 int ret = 0;
lha62e0882023-10-31 05:17:11 -07001123 if (g_lynq_data_init_flag == 0)
1124 {
1125 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
1126 return error;
1127 }
lhf81a46f2022-02-13 23:57:37 -08001128 if(handle==NULL)
1129 {
1130 LYERRLOG("handle is null!!!");
1131 return -1;
1132 }
rjw1309e232022-07-22 09:54:06 +08001133 ret = handleCheck(*handle);
1134 if (ret != 0)
1135 {
1136 LYERRLOG("incomming handle is invalid");
1137 return -1;
1138 }
1139 lynq_data_call_id = *handle;
Hong_Liu25edfe72023-06-16 01:13:42 -07001140 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001141 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
Hong_Liue3d35262023-05-04 00:20:12 -07001142 client.paramLen = 0;
1143 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1144 #ifdef GSW_RIL_CFG
1145 client.paramLen = 1;
1146 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1147 #else
1148 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -08001149 {
lhf81a46f2022-02-13 23:57:37 -08001150 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -08001151 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1152 }
Hong_Liue3d35262023-05-04 00:20:12 -07001153 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001154 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001155 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001156 if(send_request(lynq_client_sockfd,&client)==-1)
1157 {
1158 LYERRLOG("send request fail");
1159 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001160 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001161 return -1;
1162 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001163 //get_response(lynq_client_sockfd,p);
1164 error = wait_response(lynq_client_sockfd,p,client.uToken);
1165 if(error!=0)
1166 {
1167 LYERRLOG("wait_response fail,ret:%d",error);
1168 printf_apn_table_debug(__FUNCTION__,__LINE__);
1169 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1170 return error;
1171 }
rjwed00d042022-05-25 09:18:16 +08001172 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001173 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1174 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 -08001175 cleanOnceApnTable(lynq_data_call_id);
Hong_Liu6149f182023-05-12 02:15:14 -07001176 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liu25edfe72023-06-16 01:13:42 -07001177 if(error==0)
1178 {
1179 if(waitDeactived(20000)==ETIMEDOUT)
1180 {
1181 error = LYNQ_E_TIME_OUT;
1182 LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!");
xy.hefb1ab522024-01-17 13:48:45 +08001183 deactiveAfterTimeout(lynq_data_call_id);
Hong_Liu25edfe72023-06-16 01:13:42 -07001184 printf_apn_table_debug(__FUNCTION__,__LINE__);
1185 }
1186 }
1187 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001188 return error;
1189}
1190int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
1191{
Hong_Liu25edfe72023-06-16 01:13:42 -07001192 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001193 lynq_client_t client;
1194 int resp_type = -1;
1195 int request = -1;
1196 int slot_id = -1;
1197 int error = -1;
lhf81a46f2022-02-13 23:57:37 -08001198 int lynq_data_call_id = -1;
1199 char *argv[10] = {};
lha62e0882023-10-31 05:17:11 -07001200 if (g_lynq_data_init_flag == 0)
1201 {
1202 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
1203 return error;
1204 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001205 #ifdef GSW_RIL_CFG
1206 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
1207 if(handle==NULL||apnType==NULL)
1208 {
1209 LYERRLOG("handle or apntype is null!!!");
1210 return -1;
1211 }
1212 #else
lhf81a46f2022-02-13 23:57:37 -08001213 if(handle==NULL||apn==NULL||apnType==NULL)
1214 {
1215 LYERRLOG("handle ,apn or apntype is null!!!");
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001216 return LYNQ_E_NULL_ANONALY;
lhf81a46f2022-02-13 23:57:37 -08001217 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001218 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001219 if(user==NULL)
1220 {
1221 argv[1] = "null";
1222 }
1223 else
1224 {
1225 argv[1] = user;
lh13586612022-01-11 21:58:58 -08001226 }
1227 if(password==NULL)
1228 {
lhf81a46f2022-02-13 23:57:37 -08001229 argv[2] = "null";
lh13586612022-01-11 21:58:58 -08001230 }
1231 else
1232 {
lhf81a46f2022-02-13 23:57:37 -08001233 argv[2] = password;
lh13586612022-01-11 21:58:58 -08001234 }
1235 if(authType==NULL)
1236 {
lhf81a46f2022-02-13 23:57:37 -08001237 argv[3] = "null";
lh13586612022-01-11 21:58:58 -08001238 }
1239 else
1240 {
lhf81a46f2022-02-13 23:57:37 -08001241 argv[3] = authType;
lh13586612022-01-11 21:58:58 -08001242 }
1243 if(normalProtocol==NULL)
1244 {
lhf81a46f2022-02-13 23:57:37 -08001245 argv[4] = "null";
lh13586612022-01-11 21:58:58 -08001246 }
1247 else
1248 {
lhf81a46f2022-02-13 23:57:37 -08001249 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -08001250 }
1251 if(roamingProtocol==NULL)
1252 {
lhf81a46f2022-02-13 23:57:37 -08001253 argv[5] = "null";
lh13586612022-01-11 21:58:58 -08001254 }
1255 else
1256 {
lhf81a46f2022-02-13 23:57:37 -08001257 argv[5] = roamingProtocol;
1258 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001259 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001260 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1261 client.paramLen = 7;
1262 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -07001263 #ifdef GSW_RIL_CFG
1264 if(NULL == apn)
1265 {
1266 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1267 }
1268 else
1269 {
1270 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1271 }
1272 #else
lhf81a46f2022-02-13 23:57:37 -08001273 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 -07001274 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001275 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -07001276 lynq_data_call_id = get_handle(apnType);
rjwc63abb42023-03-31 18:22:42 +08001277 if (lynq_data_call_id < 0)
1278 {
1279 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001280 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001281 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001282 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16)
rjw733b9832023-04-03 10:20:08 +08001283 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001284 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001285 if(send_request(lynq_client_sockfd,&client)==-1)
1286 {
1287 LYERRLOG("send request fail");
1288 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001289 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001290 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001291 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001292 //get_response(lynq_client_sockfd,p);
1293 error = wait_response(lynq_client_sockfd,p,client.uToken);
1294 if(error!=0)
1295 {
1296 LYERRLOG("wait_response fail,ret:%d",error);
1297 printf_apn_table_debug(__FUNCTION__,__LINE__);
1298 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1299 return error;
1300 }
rjwed00d042022-05-25 09:18:16 +08001301 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001302 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1303 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1304 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001305 if(error==0)
1306 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001307 data_timelimit = 1;
lha62e0882023-10-31 05:17:11 -07001308 if(waitDataCallstateChange(g_data_call_timeout_value)==ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001309 {
1310 error = LYNQ_E_TIME_OUT;
1311 LYERRLOG("timeout:wait data Call state fail!!!");
1312 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001313 if (data_invaild_error == 1)
1314 {
1315 data_invaild_error = 0;
1316 LYERRLOG("urc apn info error!!!");
1317 return 8085;
1318 }
1319 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001320 return error;
1321 }
lha62e0882023-10-31 05:17:11 -07001322 if(lynq_data_call == LYNQ_E_TIME_OUT)
1323 {
1324 error = LYNQ_E_TIME_OUT;
1325 LYERRLOG("PDN_TIMEOUT_CANCLE:wait data Call state fail!!!");
1326 printf_apn_table_debug(__FUNCTION__,__LINE__);
1327 return error;
1328 }
lhf81a46f2022-02-13 23:57:37 -08001329 }
Hong_Liu6149f182023-05-12 02:15:14 -07001330 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001331 return error;
1332}
1333/*
1334int lynq_deactive_data_call_sp(int *handle,char *apnType)
1335{
1336 Parcel p;
1337 lynq_client_t client;
1338 int resp_type = -1;
1339 int request = -1;
1340 int slot_id = -1;
1341 int error = -1;
1342 if(handle==NULL||apnType==NULL)
1343 {
1344 LYERRLOG("handle is null!!!");
1345 return -1;
1346 }
1347 client.uToken = Global_uToken;
1348 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
1349 client.paramLen = 1;
1350 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1351 sprintf(client.param,"%s",apnType);
1352 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1353 if(send_request(lynq_client_sockfd,&client)==-1)
1354 {
1355 LYERRLOG("send request fail");
1356 perror("[LYNQ_DATA] send request fail:");
1357 return -1;
1358 }
1359 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +08001360 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -08001361 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1362 return error;
1363}
1364*/
1365int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
1366{
Hong_Liu25edfe72023-06-16 01:13:42 -07001367 Parcel *p = NULL;
xy.he509e4812024-08-26 16:06:56 +08001368 //xy.he add for bug-view-73 on 2024-08-26 start
1369 #ifdef MODE_DSDS
1370 lynq_client_dual_t client;
1371 #else
lhf81a46f2022-02-13 23:57:37 -08001372 lynq_client_t client;
xy.he509e4812024-08-26 16:06:56 +08001373 #endif
1374 //xy.he add for bug-view-73 on 2024-08-26 end
lhf81a46f2022-02-13 23:57:37 -08001375 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001376 int token;
Hong_Liu25edfe72023-06-16 01:13:42 -07001377 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001378 int slot_id = -1;
1379 int error = -1;
1380 int version =0;
1381 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001382 char *temp_char = NULL;
1383 if(dataCallList==NULL)
1384 {
1385 LYERRLOG("dataCallList is null!!!");
1386 return -1;
1387 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001388 client.uToken = get_utoken();;
lhf81a46f2022-02-13 23:57:37 -08001389 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1390 client.paramLen = 0;
xy.he509e4812024-08-26 16:06:56 +08001391 //xy.he add for bug-view-73 on 2024-08-26 start
1392 #ifdef MODE_DSDS
1393 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1394 char slot_status = '0';
1395 int data_sim = -1;
1396 data_sim = getDataSim();
1397 if(data_sim >= 0)
1398 {
1399 client.slot_status = '1';
1400 client.slot = (char)('0'+data_sim);
1401 }
1402 LYINFLOG("uToken=%d,request=%d,slot_status=%c,slot=%c,paralen=%d,param=%s",client.uToken,client.request,client.slot_status,client.slot,client.paramLen,client.param);
1403 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1404 if(send_request_dual(lynq_client_sockfd,&client,sizeof(client))==-1)
1405 {
1406 LYERRLOG("send request fail");
1407 perror("[LYNQ_DATA] send request fail:");
1408 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1409 return -1;
1410 }
1411 #else
lhf81a46f2022-02-13 23:57:37 -08001412 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1413 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001414 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001415 if(send_request(lynq_client_sockfd,&client)==-1)
1416 {
1417 LYERRLOG("send request fail");
1418 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001419 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001420 return -1;
1421 }
xy.he509e4812024-08-26 16:06:56 +08001422 #endif
1423 //xy.he add for bug-view-73 on 2024-08-26 end
Hong_Liu25edfe72023-06-16 01:13:42 -07001424 //get_response(lynq_client_sockfd,p);
1425 error = wait_response(lynq_client_sockfd,p,client.uToken);
1426 if(error!=0)
1427 {
1428 LYERRLOG("wait_response fail,ret:%d",error);
1429 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1430 return error;
1431 }
rjwed00d042022-05-25 09:18:16 +08001432 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001433 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
rjwfa532972022-09-16 13:39:41 +08001434 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001435 LYERRLOG("JumpHeader fail");
rjwfa532972022-09-16 13:39:41 +08001436 return -1;
1437 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001438 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1439 p->readInt32(&version);
lhf81a46f2022-02-13 23:57:37 -08001440 if(version==11)
1441 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001442 p->readInt32(&num);
lhf81a46f2022-02-13 23:57:37 -08001443 *realNum = num;
1444 for (int i = 0; i < num; i++)
1445 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001446 p->readInt32(&dataCallList[i].status);
1447 p->readInt32(&dataCallList[i].suggestedRetryTime);
1448 p->readInt32(&dataCallList[i].cid);
1449 p->readInt32(&dataCallList[i].active);
1450 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001451 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1452 if(temp_char)
1453 {
1454 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1455 free(temp_char);
1456 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001457 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001458 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1459 if(temp_char)
1460 {
1461 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1462 free(temp_char);
1463 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001464 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001465 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1466 if(temp_char)
1467 {
1468 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1469 free(temp_char);
1470 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001471 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001472 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1473 if(temp_char)
1474 {
1475 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1476 free(temp_char);
1477 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001478 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001479 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1480 if(temp_char)
1481 {
1482 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1483 free(temp_char);
1484 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001485 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001486 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1487 if(temp_char)
1488 {
1489 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1490 free(temp_char);
1491 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001492 p->readInt32(&dataCallList[i].mtu);
lhf81a46f2022-02-13 23:57:37 -08001493 }
1494 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001495 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001496 return error;
1497}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001498
1499int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
1500{
1501 LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
1502 if((handle < 0) || (handle > 6) || (NULL == apn_msg))
1503 {
1504 LYERRLOG("handle value error,or apn_msg is null");
1505 return LYNQ_E_NULL_ANONALY;
1506 }
1507 apn_msg->handle = handle;
1508 if(apn_msg->apn!=NULL)
1509 {
1510 memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
1511 }
1512 if(apn_msg->apnType!=NULL)
1513 {
1514 memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
1515 }
1516 return 0;
1517}
1518
lhf81a46f2022-02-13 23:57:37 -08001519int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1520{
1521 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1522 int number = 0;
1523 int lynq_data_call_id = 0;
1524 int error = 0;
lha62e0882023-10-31 05:17:11 -07001525 if (g_lynq_data_init_flag == 0)
1526 {
1527 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
1528 return -1;
1529 }
lhf81a46f2022-02-13 23:57:37 -08001530 lynq_data_call_id = *handle;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001531 if((handle==NULL) || (dataCallList==NULL))
lhf81a46f2022-02-13 23:57:37 -08001532 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001533 LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
lhf81a46f2022-02-13 23:57:37 -08001534 return LYNQ_E_NULL_ANONALY;
1535 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001536 if ((*handle < 0) || (*handle > 6))
rjw3938f262023-03-08 16:09:28 +08001537 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001538 LYERRLOG("[lynq_get_data_call_list] handle value error");
1539 return LYNQ_E_NULL_ANONALY;
rjw3938f262023-03-08 16:09:28 +08001540 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001541 LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001542 memset(interDataCallList,0,sizeof(interDataCallList));
1543 error = getDataCallLists(interDataCallList,&number);
1544 if(error == 0)
1545 {
1546 for(int i = 0;i < number;i++)
1547 {
1548 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1549 {
1550 dataCallList->active = interDataCallList[i].active;
1551 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1552 dataCallList->cid = interDataCallList[i].cid;
1553 dataCallList->status = interDataCallList[i].status;
1554 dataCallList->mtu = interDataCallList[i].mtu;
1555 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1556 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1557 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1558 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1559 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1560 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1561 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1562 }
1563 }
1564 }
1565 return error;
1566}
1567int lynq_wait_data_call_state_change(int *handle)
1568{
rjwc3d6e582023-03-28 17:19:11 +08001569 if (data_waiting_status == 1)
1570 {
1571 LYDBGLOG("some thread is waiting");
1572 return -3;
1573 }
1574 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1575 if (s_data_urc_wait_list.empty())
1576 {
1577 LYDBGLOG("start wait");
1578 data_waiting_status = 1;
1579 waitPdnChange();
1580 }
1581 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001582 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001583
1584 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1585 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001586 if (iter != s_data_urc_wait_list.end())
1587 {
1588 *handle = *iter;
1589 }
rjw7ee7bb42023-01-18 11:34:28 +08001590 s_data_urc_wait_list.erase(iter);
1591 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1592
Hong_Liudc46d412023-05-18 13:36:26 -07001593 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001594 return 0;
1595}
1596/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001597
1598/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001599
1600int 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 +08001601{
1602 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001603 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001604 {
rjw61fcae32022-08-18 14:03:39 +08001605 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001606 }
rjw61fcae32022-08-18 14:03:39 +08001607 else
rjw0cdacbc2022-06-22 10:51:07 +08001608 {
rjw61fcae32022-08-18 14:03:39 +08001609 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001610 }
rjw20006d12022-04-21 16:29:04 +08001611 if (mcc == NULL)
1612 {
1613 sprintf(strtmp[1], "mcc=;");
1614 }
1615 else
1616 {
1617 sprintf(strtmp[1], "mcc=%s;", mcc);
1618 }
1619 if (mnc == NULL)
1620 {
rjw61fcae32022-08-18 14:03:39 +08001621 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001622 }
1623 else
1624 {
1625 sprintf(strtmp[2], "mnc=%s;", mnc);
1626 }
1627 if (apn == NULL)
1628 {
1629 sprintf(strtmp[3], "apn=;");
1630 }
1631 else
1632 {
1633 sprintf(strtmp[3], "apn=%s;", apn);
1634 }
1635 if (apntype == NULL)
1636 {
1637 sprintf(strtmp[4], "apntype=;");
1638 }
1639 else
1640 {
1641 sprintf(strtmp[4], "apntype=%s;", apntype);
1642 }
1643 if (user == NULL)
1644 {
1645 sprintf(strtmp[5], "user=;");
1646 }
1647 else
1648 {
1649 sprintf(strtmp[5], "user=%s;", user);
1650 }
1651 if (password == NULL)
1652 {
1653 sprintf(strtmp[6], "password=;");
1654 }
1655 else
1656 {
1657 sprintf(strtmp[6], "password=%s;", password);
1658 }
1659 if (normalprotocol == NULL)
1660 {
xy.hee128f7a2024-08-08 16:07:12 +08001661 sprintf(strtmp[7], "protocol=;");
rjw20006d12022-04-21 16:29:04 +08001662 }
1663 else
1664 {
xy.hee128f7a2024-08-08 16:07:12 +08001665 sprintf(strtmp[7], "protocol=%s;", normalprotocol);
rjw20006d12022-04-21 16:29:04 +08001666 }
1667 if (roamingprotocol == NULL)
1668 {
xy.hee128f7a2024-08-08 16:07:12 +08001669 sprintf(strtmp[8], "roaming_protocol=;");
rjw20006d12022-04-21 16:29:04 +08001670 }
1671 else
1672 {
xy.hee128f7a2024-08-08 16:07:12 +08001673 sprintf(strtmp[8], "roaming_protocol=%s;", roamingprotocol);
rjw20006d12022-04-21 16:29:04 +08001674 }
1675 if (carrier == NULL)
1676 {
1677 sprintf(strtmp[9], "carrier=;");
1678 }
1679 else
1680 {
1681 sprintf(strtmp[9], "carrier=%s;", carrier);
1682 }
rjw61fcae32022-08-18 14:03:39 +08001683 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 +08001684
rjw20006d12022-04-21 16:29:04 +08001685 return 0;
1686}
1687
1688int 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)
1689{
1690 char strtmp[10][32];
1691 if (id == NULL)
1692 {
1693 sprintf(strtmp[0], "id=;");
1694 }
1695 else
1696 {
1697 sprintf(strtmp[0], "id=%s;", id);
1698 }
1699 if (mcc == NULL)
1700 {
1701 sprintf(strtmp[1], "mcc=;");
1702 }
1703 else
1704 {
1705 sprintf(strtmp[1], "mcc=%s;", mcc);
1706 }
1707 if (mnc == NULL)
1708 {
1709 sprintf(strtmp[2], "mnc=;");
1710 }
1711 else
1712 {
1713 sprintf(strtmp[2], "mnc=%s;", mnc);
1714 }
1715 if (apn == NULL)
1716 {
1717 sprintf(strtmp[3], "apn=;");
1718 }
1719 else
1720 {
1721 sprintf(strtmp[3], "apn=%s;", apn);
1722 }
1723 if (apntype == NULL)
1724 {
1725 sprintf(strtmp[4], "apntype=;");
1726 }
1727 else
1728 {
1729 sprintf(strtmp[4], "apntype=%s;", apntype);
1730 }
1731 if (user == NULL)
1732 {
1733 sprintf(strtmp[5], "user=;");
1734 }
1735 else
1736 {
1737 sprintf(strtmp[5], "user=%s;", user);
1738 }
1739 if (password == NULL)
1740 {
1741 sprintf(strtmp[6], "password=;");
1742 }
1743 else
1744 {
1745 sprintf(strtmp[6], "password=%s;", password);
1746 }
1747 if (normalprotocol == NULL)
1748 {
xy.hee128f7a2024-08-08 16:07:12 +08001749 sprintf(strtmp[7], "protocol=;");
rjw20006d12022-04-21 16:29:04 +08001750 }
1751 else
1752 {
xy.hee128f7a2024-08-08 16:07:12 +08001753 sprintf(strtmp[7], "protocol=%s;", normalprotocol);
rjw20006d12022-04-21 16:29:04 +08001754 }
1755 if (roamingprotocol == NULL)
1756 {
xy.hee128f7a2024-08-08 16:07:12 +08001757 sprintf(strtmp[8], "roaming_protocol=;");
rjw20006d12022-04-21 16:29:04 +08001758 }
1759 else
1760 {
xy.hee128f7a2024-08-08 16:07:12 +08001761 sprintf(strtmp[8], "roaming_protocol=%s;", roamingprotocol);
rjw20006d12022-04-21 16:29:04 +08001762 }
1763 if (carrier == NULL)
1764 {
1765 sprintf(strtmp[9], "carrier=;");
1766 }
1767 else
1768 {
1769 sprintf(strtmp[9], "carrier=%s;", carrier);
1770 }
1771 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]);
1772 return 0;
1773}
1774
rjwaf4b1612022-06-13 17:26:01 +08001775
1776int 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)
1777{
1778 char strtmp[10][32];
1779 if (id == NULL)
1780 {
1781 sprintf(strtmp[0], "");
1782 }
1783 else
1784 {
1785 sprintf(strtmp[0], "id=%s;", id);
1786 }
1787 if (mcc == NULL)
1788 {
1789 sprintf(strtmp[1], "");
1790 }
1791 else
1792 {
1793 sprintf(strtmp[1], "mcc=%s;", mcc);
1794 }
1795 if (mnc == NULL)
1796 {
1797 sprintf(strtmp[2], "");
1798 }
1799 else
1800 {
1801 sprintf(strtmp[2], "mnc=%s;", mnc);
1802 }
1803 if (apn == NULL)
1804 {
1805 sprintf(strtmp[3], "");
1806 }
1807 else
1808 {
1809 sprintf(strtmp[3], "apn=%s;", apn);
1810 }
1811 if (apntype == NULL)
1812 {
1813 sprintf(strtmp[4], "");
1814 }
1815 else
1816 {
1817 sprintf(strtmp[4], "apntype=%s;", apntype);
1818 }
1819 if (user == NULL)
1820 {
1821 sprintf(strtmp[5], "");
1822 }
1823 else
1824 {
1825 sprintf(strtmp[5], "user=%s;", user);
1826 }
1827 if (password == NULL)
1828 {
1829 sprintf(strtmp[6], "");
1830 }
1831 else
1832 {
1833 sprintf(strtmp[6], "password=%s;", password);
1834 }
1835 if (normalprotocol == NULL)
1836 {
1837 sprintf(strtmp[7], "");
1838 }
1839 else
1840 {
1841 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1842 }
1843 if (roamingprotocol == NULL)
1844 {
1845 sprintf(strtmp[8], "");
1846 }
1847 else
1848 {
1849 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1850 }
1851 if (carrier == NULL)
1852 {
1853 sprintf(strtmp[9], "");
1854 }
1855 else
1856 {
1857 sprintf(strtmp[9], "carrier=%s;", carrier);
1858 }
1859 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]);
1860 return 0;
1861}
1862
rjw20006d12022-04-21 16:29:04 +08001863static char *lynqStrdupReadString(Parcel &p)
1864{
1865 size_t stringlen;
1866 const char16_t *s16;
1867
1868 s16 = p.readString16Inplace(&stringlen);
1869 return strndup16to8(s16, stringlen);
1870}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001871int get_imsi()
1872{
Hong_Liu25edfe72023-06-16 01:13:42 -07001873 Parcel *p =NULL;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001874 lynq_client_t client;
1875 int resp_type = -1;
1876 int token;
1877 int request = -1;
1878 int slot_id = -1;
1879 int error = -1;
1880 int version =0;
1881 int num = 0;
1882 char *temp_char = NULL;
1883 char mccmnc[32] = {0};
1884 char mccmnckey[64] = {0};
Hong_Liu25edfe72023-06-16 01:13:42 -07001885 client.uToken = get_utoken();
Hong_Liu7163bbe2023-06-04 03:03:44 -07001886 client.request = 11;//RIL_REQUEST_GET_IMSI 11
1887 client.paramLen = 0;
1888 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1889 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1890 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1891 if(send_request(lynq_client_sockfd,&client)==-1)
1892 {
1893 LYERRLOG("send request fail");
1894 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001895 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001896 return -1;
1897 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001898 //get_response(lynq_client_sockfd,p);
1899 error = wait_response(lynq_client_sockfd,p,client.uToken);
1900 if(error!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001901 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001902 LYERRLOG("wait_response fail,ret:%d",error);
1903 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001904 return error;
1905 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001906 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1907 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001908 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001909 LYERRLOG("JumpHeader fail");
Hong_Liu7163bbe2023-06-04 03:03:44 -07001910 return -1;
1911 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001912 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1913 if(error == 0)
1914 {
1915 char * test = strdupReadString_p(p);
1916 memcpy(mccmnc, test,5);
1917 mccmnc[5]='\0';
1918 free(test);
1919 sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
1920 system(mccmnckey);
1921 system("uci commit");
1922 }
1923 free_parcel(p);
1924 return error;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001925}
rjw20006d12022-04-21 16:29:04 +08001926int 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)
1927{
1928 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1929 {
1930 LYERRLOG("There are no valid parameters");
1931 return -1;
1932 }
1933 lynq_client_t client;
1934 char argc[512];
Hong_Liu7163bbe2023-06-04 03:03:44 -07001935 int res = -1;
rjw20006d12022-04-21 16:29:04 +08001936 if (cmd == 0) // insert apn db
1937 {
rjw61fcae32022-08-18 14:03:39 +08001938 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001939 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001940 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1941 client.paramLen = 2;
1942 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1943 sprintf(client.param, "%d %s", cmd, argc);
1944 }
rjw61fcae32022-08-18 14:03:39 +08001945 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001946 {
1947 if (NULL == id)
1948 {
1949 LYERRLOG("id is NULL!!!please input id: ");
1950 }
1951 sprintf(argc, "id=%s", id);
Hong_Liu25edfe72023-06-16 01:13:42 -07001952 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001953 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1954 client.paramLen = 2;
1955 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1956 sprintf(client.param, "%d %s", cmd, argc);
1957 }
rjw61fcae32022-08-18 14:03:39 +08001958 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001959 {
rjwaf4b1612022-06-13 17:26:01 +08001960 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001961 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001962 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1963 client.paramLen = 2;
1964 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1965 sprintf(client.param, "%d %s", cmd, argc);
1966 }
rjw61fcae32022-08-18 14:03:39 +08001967 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001968 {
1969 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001970 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001971 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1972 client.paramLen = 2;
1973 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1974 sprintf(client.param, "%d %s", cmd, argc);
1975 }
1976 else
1977 {
1978 LYERRLOG("incoming command is invalid");
1979 return -1;
1980 }
1981 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001982 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001983 if(send_request(lynq_client_sockfd,&client)==-1)
1984 {
1985 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001986 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001987 return -1;
1988 }
rjwed00d042022-05-25 09:18:16 +08001989 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001990 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001991 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001992 LYINFLOG(">>>>>output info:%s",out);
1993 return 0;
1994}
1995
1996int lynq_reset_apn(char *result)
1997{
rjw20006d12022-04-21 16:29:04 +08001998 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001999 if (NULL == result)
2000 {
2001 LYERRLOG("incoming paramters error");
2002 }
Hong_Liu25edfe72023-06-16 01:13:42 -07002003 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08002004 client.request = 2000 + 194;
2005 client.paramLen = 0;
2006 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
2007 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08002008 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08002009 if (send_request(lynq_client_sockfd, &client) == -1)
2010 {
2011 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07002012 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08002013 return -1;
2014 }
rjwed00d042022-05-25 09:18:16 +08002015 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08002016 waitApnResult();
2017 strcpy(result, g_lynq_apn_result);
2018 LYINFLOG(">>>>>result:%s",result);
2019 return 0;
2020}
2021
rjw3bcbbf12022-04-22 16:47:18 +08002022/*Typethree add for T800 platform 2022/04/21 end*/
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002023static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) {
2024 FILE *fp;
2025 //printf("to exec cmd:%s\n", str_cmd);
2026 if((fp=popen(str_cmd,"r"))==NULL)
2027 {
2028 perror("popen error!");
2029 return -1;
2030 }
2031 if((fread(str_cmd_ret,max_len,1,fp))<0)
2032 {
2033 perror("fread fail!");
2034 fclose(fp);
2035 return -1;
2036 }
2037 fclose(fp);
2038 return 0;
2039}
xy.he509e4812024-08-26 16:06:56 +08002040//xy.he add for bug-view-73 on 2024-08-26 start
2041int getDataSim()
2042{
2043 LYINFLOG("getDataSim enter");
2044 const char *data_sim_cmd = "uci get radio_property.property.persist_vendor_radio_data_sim";
2045 char cmd_ret[8] ={0};
2046 int slot = 0;
2047 int sim_ret = -1;
2048 int ret = -1;
2049 const char *empty_str = ":empty";
2050
2051 sim_ret = exec_cmd(data_sim_cmd,cmd_ret,8);
2052 if(sim_ret==0)
2053 {
2054 if(strlen(cmd_ret)==0)
2055 {
2056 LYERRLOG("not have data_sim config in uci ram");
2057 return -1;
2058 }
2059 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
2060 {
2061 LYERRLOG("sim is empty");
2062 return -2;
2063 }
2064 LYINFLOG("sim is %s",cmd_ret);
2065 slot = atoi(cmd_ret);
2066 return (slot-1);
2067 }
2068 else
2069 {
2070 LYERRLOG("exec cmd fail");
2071 return -1;
2072 }
2073}
2074//xy.he add for bug-view-73 on 2024-08-26 end
2075
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002076int check_apn_status()
2077{
2078 LYINFLOG("check_apn_status enter");
2079 int ret = -1;
xy.he334804f2024-05-07 14:56:18 +08002080 int sim_ret = -1;
2081 int slot = -1;
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002082 char cmd_ret[8] ={0};//get mccmnc
xy.he334804f2024-05-07 14:56:18 +08002083 const char *sim_0_cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc0";
2084 const char *sim_1_cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc1";
2085 const char *sim_cmd = "uci get radio_property.property.persist_vendor_radio_data_sim";
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002086 const char *empty_str = ":empty";
xy.he334804f2024-05-07 14:56:18 +08002087 //xy.he add for get sim slot at 20240507 start
2088 sim_ret = exec_cmd(sim_cmd,cmd_ret,8);
2089 if(sim_ret==0)
2090 {
2091 if(strlen(cmd_ret)==0)
2092 {
2093 LYERRLOG("not have sim config in uci ram");
2094 return 1;
2095 }
2096 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
2097 {
2098 LYERRLOG("sim is empty");
2099 return 2;
2100 }
2101 LYINFLOG("sim is %s",cmd_ret);
2102 slot = atoi(cmd_ret);
2103 }
2104 else
2105 {
2106 LYERRLOG("exec cmd fail");
2107 return -1;
2108 }
2109
2110 if(slot == 1)
2111 {
2112 ret = exec_cmd(sim_0_cmd,cmd_ret,8);
2113 }
2114
2115 else if(slot == 2)
2116 {
2117 ret = exec_cmd(sim_1_cmd,cmd_ret,8);
2118 }
2119 //xy.he add for get sim slot at 20240507 end
2120
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002121 if(ret==0)
2122 {
2123 if(strlen(cmd_ret)==0)
2124 {
2125 LYERRLOG("not have mccmnc config in uci ram");
2126 return 1;
2127 }
2128 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
2129 {
2130 LYERRLOG("mccmnc is empty");
2131 return 2;
2132 }
2133 LYINFLOG("mccmnc is %s",cmd_ret);
2134 return 0;
2135 }
2136 else
2137 {
2138 LYERRLOG("exec cmd fail");
2139 return -1;
2140 }
2141 return 0;
2142}
lha62e0882023-10-31 05:17:11 -07002143int get_timeout_value()
2144{
2145 LYINFLOG("get_timeout_value enter");
2146 int ret = -1;
2147 char timeout_value[8] ={0};//get get_timeout_value
2148 ret = lynq_get_value("lynq_uci","data_call","timeout",timeout_value);
2149 if(ret == 0)
2150 {
2151 LYINFLOG("data_call.timeout is %s",timeout_value);
2152 return atoi(timeout_value);
2153 }
2154 else
2155 {
2156 LYERRLOG("get_timeout_value");
2157 return -1;
2158 }
2159}
2160
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002161int radio_switch(int status)
2162{
2163 Parcel *p =NULL;
2164 lynq_client_t client;
2165 int resp_type = -1;
2166 int token;
2167 int request = -1;
2168 int slot_id = -1;
2169 int error = -1;
2170 int version =0;
2171 int num = 0;
2172 char *temp_char = NULL;
2173 char mccmnc[32] = {0};
2174 char mccmnckey[64] = {0};
2175 client.uToken = get_utoken();
2176 client.request = 59;//RIL_REQUEST_OEM_HOOK_RAW 59
2177 client.paramLen = 1;
2178 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
2179 sprintf(client.param,"AT+CFUN=%d",status);
2180 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
2181 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
2182 if(send_request(lynq_client_sockfd,&client)==-1)
2183 {
2184 LYERRLOG("send request fail");
2185 perror("[LYNQ_DATA] send request fail:");
2186 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2187 return -1;
2188 }
2189 //get_response(lynq_client_sockfd,p);
2190 error = wait_response(lynq_client_sockfd,p,client.uToken);
2191 if(error!=0)
2192 {
2193 LYERRLOG("wait_response fail,ret:%d",error);
2194 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2195 return error;
2196 }
2197 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2198 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
2199 {
2200 LYERRLOG("JumpHeader fail");
2201 return -1;
2202 }
2203 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
2204 free_parcel(p);
2205 return error;
2206}