blob: 9ed40dac7858b4f28240cce09bc5a1bf14f287f7 [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.heac0d3882024-08-26 18:01:57 +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.heac0d3882024-08-26 18:01:57 +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.heac0d3882024-08-26 18:01:57 +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.heac0d3882024-08-26 18:01:57 +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.heac0d3882024-08-26 18:01:57 +08001373 #endif
lhf81a46f2022-02-13 23:57:37 -08001374 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001375 int token;
Hong_Liu25edfe72023-06-16 01:13:42 -07001376 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001377 int slot_id = -1;
1378 int error = -1;
1379 int version =0;
1380 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001381 char *temp_char = NULL;
1382 if(dataCallList==NULL)
1383 {
1384 LYERRLOG("dataCallList is null!!!");
1385 return -1;
1386 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001387 client.uToken = get_utoken();;
lhf81a46f2022-02-13 23:57:37 -08001388 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1389 client.paramLen = 0;
xy.heac0d3882024-08-26 18:01:57 +08001390 #ifdef MODE_DSDS
1391 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1392 char slot_status = '0';
1393 int data_sim = -1;
1394 data_sim = getDataSim();
1395 if(data_sim >= 0)
1396 {
1397 client.slot_status = '1';
1398 client.slot = (char)('0'+data_sim);
1399 }
1400 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);
1401 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1402 if(send_request_dual(lynq_client_sockfd,&client,sizeof(client))==-1)
1403 {
1404 LYERRLOG("send request fail");
1405 perror("[LYNQ_DATA] send request fail:");
1406 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1407 return -1;
1408 }
1409 #else
lhf81a46f2022-02-13 23:57:37 -08001410 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1411 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001412 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001413 if(send_request(lynq_client_sockfd,&client)==-1)
1414 {
1415 LYERRLOG("send request fail");
1416 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001417 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001418 return -1;
1419 }
xy.heac0d3882024-08-26 18:01:57 +08001420 #endif
1421 //xy.he add for bug-view-73 on 2024-08-26 start
Hong_Liu25edfe72023-06-16 01:13:42 -07001422 //get_response(lynq_client_sockfd,p);
1423 error = wait_response(lynq_client_sockfd,p,client.uToken);
1424 if(error!=0)
1425 {
1426 LYERRLOG("wait_response fail,ret:%d",error);
1427 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1428 return error;
1429 }
rjwed00d042022-05-25 09:18:16 +08001430 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001431 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
rjwfa532972022-09-16 13:39:41 +08001432 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001433 LYERRLOG("JumpHeader fail");
rjwfa532972022-09-16 13:39:41 +08001434 return -1;
1435 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001436 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1437 p->readInt32(&version);
lhf81a46f2022-02-13 23:57:37 -08001438 if(version==11)
1439 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001440 p->readInt32(&num);
lhf81a46f2022-02-13 23:57:37 -08001441 *realNum = num;
1442 for (int i = 0; i < num; i++)
1443 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001444 p->readInt32(&dataCallList[i].status);
1445 p->readInt32(&dataCallList[i].suggestedRetryTime);
1446 p->readInt32(&dataCallList[i].cid);
1447 p->readInt32(&dataCallList[i].active);
1448 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001449 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1450 if(temp_char)
1451 {
1452 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1453 free(temp_char);
1454 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001455 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001456 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1457 if(temp_char)
1458 {
1459 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1460 free(temp_char);
1461 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001462 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001463 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1464 if(temp_char)
1465 {
1466 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1467 free(temp_char);
1468 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001469 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001470 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1471 if(temp_char)
1472 {
1473 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1474 free(temp_char);
1475 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001476 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001477 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1478 if(temp_char)
1479 {
1480 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1481 free(temp_char);
1482 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001483 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001484 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1485 if(temp_char)
1486 {
1487 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1488 free(temp_char);
1489 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001490 p->readInt32(&dataCallList[i].mtu);
lhf81a46f2022-02-13 23:57:37 -08001491 }
1492 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001493 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001494 return error;
1495}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001496
1497int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
1498{
1499 LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
1500 if((handle < 0) || (handle > 6) || (NULL == apn_msg))
1501 {
1502 LYERRLOG("handle value error,or apn_msg is null");
1503 return LYNQ_E_NULL_ANONALY;
1504 }
1505 apn_msg->handle = handle;
1506 if(apn_msg->apn!=NULL)
1507 {
1508 memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
1509 }
1510 if(apn_msg->apnType!=NULL)
1511 {
1512 memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
1513 }
1514 return 0;
1515}
1516
lhf81a46f2022-02-13 23:57:37 -08001517int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1518{
1519 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1520 int number = 0;
1521 int lynq_data_call_id = 0;
1522 int error = 0;
lha62e0882023-10-31 05:17:11 -07001523 if (g_lynq_data_init_flag == 0)
1524 {
1525 LYERRLOG("[%s][%d]Invalid operation",__FUNCTION__,__LINE__);
1526 return -1;
1527 }
lhf81a46f2022-02-13 23:57:37 -08001528 lynq_data_call_id = *handle;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001529 if((handle==NULL) || (dataCallList==NULL))
lhf81a46f2022-02-13 23:57:37 -08001530 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001531 LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
lhf81a46f2022-02-13 23:57:37 -08001532 return LYNQ_E_NULL_ANONALY;
1533 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001534 if ((*handle < 0) || (*handle > 6))
rjw3938f262023-03-08 16:09:28 +08001535 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001536 LYERRLOG("[lynq_get_data_call_list] handle value error");
1537 return LYNQ_E_NULL_ANONALY;
rjw3938f262023-03-08 16:09:28 +08001538 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001539 LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001540 memset(interDataCallList,0,sizeof(interDataCallList));
1541 error = getDataCallLists(interDataCallList,&number);
1542 if(error == 0)
1543 {
1544 for(int i = 0;i < number;i++)
1545 {
1546 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1547 {
1548 dataCallList->active = interDataCallList[i].active;
1549 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1550 dataCallList->cid = interDataCallList[i].cid;
1551 dataCallList->status = interDataCallList[i].status;
1552 dataCallList->mtu = interDataCallList[i].mtu;
1553 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1554 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1555 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1556 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1557 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1558 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1559 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1560 }
1561 }
1562 }
1563 return error;
1564}
1565int lynq_wait_data_call_state_change(int *handle)
1566{
rjwc3d6e582023-03-28 17:19:11 +08001567 if (data_waiting_status == 1)
1568 {
1569 LYDBGLOG("some thread is waiting");
1570 return -3;
1571 }
1572 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1573 if (s_data_urc_wait_list.empty())
1574 {
1575 LYDBGLOG("start wait");
1576 data_waiting_status = 1;
1577 waitPdnChange();
1578 }
1579 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001580 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001581
1582 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1583 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001584 if (iter != s_data_urc_wait_list.end())
1585 {
1586 *handle = *iter;
1587 }
rjw7ee7bb42023-01-18 11:34:28 +08001588 s_data_urc_wait_list.erase(iter);
1589 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1590
Hong_Liudc46d412023-05-18 13:36:26 -07001591 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001592 return 0;
1593}
1594/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001595
1596/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001597
1598int 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 +08001599{
1600 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001601 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001602 {
rjw61fcae32022-08-18 14:03:39 +08001603 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001604 }
rjw61fcae32022-08-18 14:03:39 +08001605 else
rjw0cdacbc2022-06-22 10:51:07 +08001606 {
rjw61fcae32022-08-18 14:03:39 +08001607 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001608 }
rjw20006d12022-04-21 16:29:04 +08001609 if (mcc == NULL)
1610 {
1611 sprintf(strtmp[1], "mcc=;");
1612 }
1613 else
1614 {
1615 sprintf(strtmp[1], "mcc=%s;", mcc);
1616 }
1617 if (mnc == NULL)
1618 {
rjw61fcae32022-08-18 14:03:39 +08001619 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001620 }
1621 else
1622 {
1623 sprintf(strtmp[2], "mnc=%s;", mnc);
1624 }
1625 if (apn == NULL)
1626 {
1627 sprintf(strtmp[3], "apn=;");
1628 }
1629 else
1630 {
1631 sprintf(strtmp[3], "apn=%s;", apn);
1632 }
1633 if (apntype == NULL)
1634 {
1635 sprintf(strtmp[4], "apntype=;");
1636 }
1637 else
1638 {
1639 sprintf(strtmp[4], "apntype=%s;", apntype);
1640 }
1641 if (user == NULL)
1642 {
1643 sprintf(strtmp[5], "user=;");
1644 }
1645 else
1646 {
1647 sprintf(strtmp[5], "user=%s;", user);
1648 }
1649 if (password == NULL)
1650 {
1651 sprintf(strtmp[6], "password=;");
1652 }
1653 else
1654 {
1655 sprintf(strtmp[6], "password=%s;", password);
1656 }
1657 if (normalprotocol == NULL)
1658 {
xy.hee128f7a2024-08-08 16:07:12 +08001659 sprintf(strtmp[7], "protocol=;");
rjw20006d12022-04-21 16:29:04 +08001660 }
1661 else
1662 {
xy.hee128f7a2024-08-08 16:07:12 +08001663 sprintf(strtmp[7], "protocol=%s;", normalprotocol);
rjw20006d12022-04-21 16:29:04 +08001664 }
1665 if (roamingprotocol == NULL)
1666 {
xy.hee128f7a2024-08-08 16:07:12 +08001667 sprintf(strtmp[8], "roaming_protocol=;");
rjw20006d12022-04-21 16:29:04 +08001668 }
1669 else
1670 {
xy.hee128f7a2024-08-08 16:07:12 +08001671 sprintf(strtmp[8], "roaming_protocol=%s;", roamingprotocol);
rjw20006d12022-04-21 16:29:04 +08001672 }
1673 if (carrier == NULL)
1674 {
1675 sprintf(strtmp[9], "carrier=;");
1676 }
1677 else
1678 {
1679 sprintf(strtmp[9], "carrier=%s;", carrier);
1680 }
rjw61fcae32022-08-18 14:03:39 +08001681 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 +08001682
rjw20006d12022-04-21 16:29:04 +08001683 return 0;
1684}
1685
1686int 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)
1687{
1688 char strtmp[10][32];
1689 if (id == NULL)
1690 {
1691 sprintf(strtmp[0], "id=;");
1692 }
1693 else
1694 {
1695 sprintf(strtmp[0], "id=%s;", id);
1696 }
1697 if (mcc == NULL)
1698 {
1699 sprintf(strtmp[1], "mcc=;");
1700 }
1701 else
1702 {
1703 sprintf(strtmp[1], "mcc=%s;", mcc);
1704 }
1705 if (mnc == NULL)
1706 {
1707 sprintf(strtmp[2], "mnc=;");
1708 }
1709 else
1710 {
1711 sprintf(strtmp[2], "mnc=%s;", mnc);
1712 }
1713 if (apn == NULL)
1714 {
1715 sprintf(strtmp[3], "apn=;");
1716 }
1717 else
1718 {
1719 sprintf(strtmp[3], "apn=%s;", apn);
1720 }
1721 if (apntype == NULL)
1722 {
1723 sprintf(strtmp[4], "apntype=;");
1724 }
1725 else
1726 {
1727 sprintf(strtmp[4], "apntype=%s;", apntype);
1728 }
1729 if (user == NULL)
1730 {
1731 sprintf(strtmp[5], "user=;");
1732 }
1733 else
1734 {
1735 sprintf(strtmp[5], "user=%s;", user);
1736 }
1737 if (password == NULL)
1738 {
1739 sprintf(strtmp[6], "password=;");
1740 }
1741 else
1742 {
1743 sprintf(strtmp[6], "password=%s;", password);
1744 }
1745 if (normalprotocol == NULL)
1746 {
xy.hee128f7a2024-08-08 16:07:12 +08001747 sprintf(strtmp[7], "protocol=;");
rjw20006d12022-04-21 16:29:04 +08001748 }
1749 else
1750 {
xy.hee128f7a2024-08-08 16:07:12 +08001751 sprintf(strtmp[7], "protocol=%s;", normalprotocol);
rjw20006d12022-04-21 16:29:04 +08001752 }
1753 if (roamingprotocol == NULL)
1754 {
xy.hee128f7a2024-08-08 16:07:12 +08001755 sprintf(strtmp[8], "roaming_protocol=;");
rjw20006d12022-04-21 16:29:04 +08001756 }
1757 else
1758 {
xy.hee128f7a2024-08-08 16:07:12 +08001759 sprintf(strtmp[8], "roaming_protocol=%s;", roamingprotocol);
rjw20006d12022-04-21 16:29:04 +08001760 }
1761 if (carrier == NULL)
1762 {
1763 sprintf(strtmp[9], "carrier=;");
1764 }
1765 else
1766 {
1767 sprintf(strtmp[9], "carrier=%s;", carrier);
1768 }
1769 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]);
1770 return 0;
1771}
1772
rjwaf4b1612022-06-13 17:26:01 +08001773
1774int 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)
1775{
1776 char strtmp[10][32];
1777 if (id == NULL)
1778 {
1779 sprintf(strtmp[0], "");
1780 }
1781 else
1782 {
1783 sprintf(strtmp[0], "id=%s;", id);
1784 }
1785 if (mcc == NULL)
1786 {
1787 sprintf(strtmp[1], "");
1788 }
1789 else
1790 {
1791 sprintf(strtmp[1], "mcc=%s;", mcc);
1792 }
1793 if (mnc == NULL)
1794 {
1795 sprintf(strtmp[2], "");
1796 }
1797 else
1798 {
1799 sprintf(strtmp[2], "mnc=%s;", mnc);
1800 }
1801 if (apn == NULL)
1802 {
1803 sprintf(strtmp[3], "");
1804 }
1805 else
1806 {
1807 sprintf(strtmp[3], "apn=%s;", apn);
1808 }
1809 if (apntype == NULL)
1810 {
1811 sprintf(strtmp[4], "");
1812 }
1813 else
1814 {
1815 sprintf(strtmp[4], "apntype=%s;", apntype);
1816 }
1817 if (user == NULL)
1818 {
1819 sprintf(strtmp[5], "");
1820 }
1821 else
1822 {
1823 sprintf(strtmp[5], "user=%s;", user);
1824 }
1825 if (password == NULL)
1826 {
1827 sprintf(strtmp[6], "");
1828 }
1829 else
1830 {
1831 sprintf(strtmp[6], "password=%s;", password);
1832 }
1833 if (normalprotocol == NULL)
1834 {
1835 sprintf(strtmp[7], "");
1836 }
1837 else
1838 {
1839 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1840 }
1841 if (roamingprotocol == NULL)
1842 {
1843 sprintf(strtmp[8], "");
1844 }
1845 else
1846 {
1847 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1848 }
1849 if (carrier == NULL)
1850 {
1851 sprintf(strtmp[9], "");
1852 }
1853 else
1854 {
1855 sprintf(strtmp[9], "carrier=%s;", carrier);
1856 }
1857 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]);
1858 return 0;
1859}
1860
rjw20006d12022-04-21 16:29:04 +08001861static char *lynqStrdupReadString(Parcel &p)
1862{
1863 size_t stringlen;
1864 const char16_t *s16;
1865
1866 s16 = p.readString16Inplace(&stringlen);
1867 return strndup16to8(s16, stringlen);
1868}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001869int get_imsi()
1870{
Hong_Liu25edfe72023-06-16 01:13:42 -07001871 Parcel *p =NULL;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001872 lynq_client_t client;
1873 int resp_type = -1;
1874 int token;
1875 int request = -1;
1876 int slot_id = -1;
1877 int error = -1;
1878 int version =0;
1879 int num = 0;
1880 char *temp_char = NULL;
1881 char mccmnc[32] = {0};
1882 char mccmnckey[64] = {0};
Hong_Liu25edfe72023-06-16 01:13:42 -07001883 client.uToken = get_utoken();
Hong_Liu7163bbe2023-06-04 03:03:44 -07001884 client.request = 11;//RIL_REQUEST_GET_IMSI 11
1885 client.paramLen = 0;
1886 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1887 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1888 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1889 if(send_request(lynq_client_sockfd,&client)==-1)
1890 {
1891 LYERRLOG("send request fail");
1892 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001893 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001894 return -1;
1895 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001896 //get_response(lynq_client_sockfd,p);
1897 error = wait_response(lynq_client_sockfd,p,client.uToken);
1898 if(error!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001899 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001900 LYERRLOG("wait_response fail,ret:%d",error);
1901 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001902 return error;
1903 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001904 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1905 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001906 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001907 LYERRLOG("JumpHeader fail");
Hong_Liu7163bbe2023-06-04 03:03:44 -07001908 return -1;
1909 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001910 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1911 if(error == 0)
1912 {
1913 char * test = strdupReadString_p(p);
1914 memcpy(mccmnc, test,5);
1915 mccmnc[5]='\0';
1916 free(test);
1917 sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
1918 system(mccmnckey);
1919 system("uci commit");
1920 }
1921 free_parcel(p);
1922 return error;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001923}
rjw20006d12022-04-21 16:29:04 +08001924int 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)
1925{
1926 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1927 {
1928 LYERRLOG("There are no valid parameters");
1929 return -1;
1930 }
1931 lynq_client_t client;
1932 char argc[512];
Hong_Liu7163bbe2023-06-04 03:03:44 -07001933 int res = -1;
rjw20006d12022-04-21 16:29:04 +08001934 if (cmd == 0) // insert apn db
1935 {
rjw61fcae32022-08-18 14:03:39 +08001936 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001937 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001938 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1939 client.paramLen = 2;
1940 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1941 sprintf(client.param, "%d %s", cmd, argc);
1942 }
rjw61fcae32022-08-18 14:03:39 +08001943 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001944 {
1945 if (NULL == id)
1946 {
1947 LYERRLOG("id is NULL!!!please input id: ");
1948 }
1949 sprintf(argc, "id=%s", id);
Hong_Liu25edfe72023-06-16 01:13:42 -07001950 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001951 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1952 client.paramLen = 2;
1953 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1954 sprintf(client.param, "%d %s", cmd, argc);
1955 }
rjw61fcae32022-08-18 14:03:39 +08001956 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001957 {
rjwaf4b1612022-06-13 17:26:01 +08001958 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001959 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001960 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1961 client.paramLen = 2;
1962 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1963 sprintf(client.param, "%d %s", cmd, argc);
1964 }
rjw61fcae32022-08-18 14:03:39 +08001965 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001966 {
1967 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001968 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001969 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1970 client.paramLen = 2;
1971 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1972 sprintf(client.param, "%d %s", cmd, argc);
1973 }
1974 else
1975 {
1976 LYERRLOG("incoming command is invalid");
1977 return -1;
1978 }
1979 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001980 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001981 if(send_request(lynq_client_sockfd,&client)==-1)
1982 {
1983 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001984 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001985 return -1;
1986 }
rjwed00d042022-05-25 09:18:16 +08001987 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001988 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001989 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001990 LYINFLOG(">>>>>output info:%s",out);
1991 return 0;
1992}
1993
1994int lynq_reset_apn(char *result)
1995{
rjw20006d12022-04-21 16:29:04 +08001996 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001997 if (NULL == result)
1998 {
1999 LYERRLOG("incoming paramters error");
2000 }
Hong_Liu25edfe72023-06-16 01:13:42 -07002001 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08002002 client.request = 2000 + 194;
2003 client.paramLen = 0;
2004 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
2005 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08002006 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08002007 if (send_request(lynq_client_sockfd, &client) == -1)
2008 {
2009 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07002010 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08002011 return -1;
2012 }
rjwed00d042022-05-25 09:18:16 +08002013 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08002014 waitApnResult();
2015 strcpy(result, g_lynq_apn_result);
2016 LYINFLOG(">>>>>result:%s",result);
2017 return 0;
2018}
2019
rjw3bcbbf12022-04-22 16:47:18 +08002020/*Typethree add for T800 platform 2022/04/21 end*/
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002021static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) {
2022 FILE *fp;
2023 //printf("to exec cmd:%s\n", str_cmd);
2024 if((fp=popen(str_cmd,"r"))==NULL)
2025 {
2026 perror("popen error!");
2027 return -1;
2028 }
2029 if((fread(str_cmd_ret,max_len,1,fp))<0)
2030 {
2031 perror("fread fail!");
2032 fclose(fp);
2033 return -1;
2034 }
2035 fclose(fp);
2036 return 0;
2037}
xy.heac0d3882024-08-26 18:01:57 +08002038//xy.he add for bug-view-73 on 2024-08-26 start
2039int getDataSim()
2040{
2041 LYINFLOG("getDataSim enter");
2042 const char *data_sim_cmd = "uci get radio_property.property.persist_vendor_radio_data_sim";
2043 char cmd_ret[8] ={0};
2044 int slot = 0;
2045 int sim_ret = -1;
2046 int ret = -1;
2047 const char *empty_str = ":empty";
2048
2049 sim_ret = exec_cmd(data_sim_cmd,cmd_ret,8);
2050 if(sim_ret==0)
2051 {
2052 if(strlen(cmd_ret)==0)
2053 {
2054 LYERRLOG("not have data_sim config in uci ram");
2055 return -1;
2056 }
2057 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
2058 {
2059 LYERRLOG("sim is empty");
2060 return -2;
2061 }
2062 LYINFLOG("sim is %s",cmd_ret);
2063 slot = atoi(cmd_ret);
2064 return (slot-1);
2065 }
2066 else
2067 {
2068 LYERRLOG("exec cmd fail");
2069 return -1;
2070 }
2071}
2072//xy.he add for bug-view-73 on 2024-08-26 end
2073
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002074int check_apn_status()
2075{
2076 LYINFLOG("check_apn_status enter");
2077 int ret = -1;
xy.he334804f2024-05-07 14:56:18 +08002078 int sim_ret = -1;
2079 int slot = -1;
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002080 char cmd_ret[8] ={0};//get mccmnc
xy.he334804f2024-05-07 14:56:18 +08002081 const char *sim_0_cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc0";
2082 const char *sim_1_cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc1";
2083 const char *sim_cmd = "uci get radio_property.property.persist_vendor_radio_data_sim";
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002084 const char *empty_str = ":empty";
xy.he334804f2024-05-07 14:56:18 +08002085 //xy.he add for get sim slot at 20240507 start
2086 sim_ret = exec_cmd(sim_cmd,cmd_ret,8);
2087 if(sim_ret==0)
2088 {
2089 if(strlen(cmd_ret)==0)
2090 {
2091 LYERRLOG("not have sim config in uci ram");
2092 return 1;
2093 }
2094 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
2095 {
2096 LYERRLOG("sim is empty");
2097 return 2;
2098 }
2099 LYINFLOG("sim is %s",cmd_ret);
2100 slot = atoi(cmd_ret);
2101 }
2102 else
2103 {
2104 LYERRLOG("exec cmd fail");
2105 return -1;
2106 }
2107
2108 if(slot == 1)
2109 {
2110 ret = exec_cmd(sim_0_cmd,cmd_ret,8);
2111 }
2112
2113 else if(slot == 2)
2114 {
2115 ret = exec_cmd(sim_1_cmd,cmd_ret,8);
2116 }
2117 //xy.he add for get sim slot at 20240507 end
2118
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002119 if(ret==0)
2120 {
2121 if(strlen(cmd_ret)==0)
2122 {
2123 LYERRLOG("not have mccmnc config in uci ram");
2124 return 1;
2125 }
2126 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
2127 {
2128 LYERRLOG("mccmnc is empty");
2129 return 2;
2130 }
2131 LYINFLOG("mccmnc is %s",cmd_ret);
2132 return 0;
2133 }
2134 else
2135 {
2136 LYERRLOG("exec cmd fail");
2137 return -1;
2138 }
2139 return 0;
2140}
lha62e0882023-10-31 05:17:11 -07002141int get_timeout_value()
2142{
2143 LYINFLOG("get_timeout_value enter");
2144 int ret = -1;
2145 char timeout_value[8] ={0};//get get_timeout_value
2146 ret = lynq_get_value("lynq_uci","data_call","timeout",timeout_value);
2147 if(ret == 0)
2148 {
2149 LYINFLOG("data_call.timeout is %s",timeout_value);
2150 return atoi(timeout_value);
2151 }
2152 else
2153 {
2154 LYERRLOG("get_timeout_value");
2155 return -1;
2156 }
2157}
2158
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07002159int radio_switch(int status)
2160{
2161 Parcel *p =NULL;
2162 lynq_client_t client;
2163 int resp_type = -1;
2164 int token;
2165 int request = -1;
2166 int slot_id = -1;
2167 int error = -1;
2168 int version =0;
2169 int num = 0;
2170 char *temp_char = NULL;
2171 char mccmnc[32] = {0};
2172 char mccmnckey[64] = {0};
2173 client.uToken = get_utoken();
2174 client.request = 59;//RIL_REQUEST_OEM_HOOK_RAW 59
2175 client.paramLen = 1;
2176 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
2177 sprintf(client.param,"AT+CFUN=%d",status);
2178 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
2179 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
2180 if(send_request(lynq_client_sockfd,&client)==-1)
2181 {
2182 LYERRLOG("send request fail");
2183 perror("[LYNQ_DATA] send request fail:");
2184 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2185 return -1;
2186 }
2187 //get_response(lynq_client_sockfd,p);
2188 error = wait_response(lynq_client_sockfd,p,client.uToken);
2189 if(error!=0)
2190 {
2191 LYERRLOG("wait_response fail,ret:%d",error);
2192 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2193 return error;
2194 }
2195 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
2196 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
2197 {
2198 LYERRLOG("JumpHeader fail");
2199 return -1;
2200 }
2201 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
2202 free_parcel(p);
2203 return error;
2204}