blob: 0bff5b4cd4d263f154893d2d3e36cba663e6a983 [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
Hong_Liu7163bbe2023-06-04 03:03:44 -070031
rjw61fcae32022-08-18 14:03:39 +080032
lhf81a46f2022-02-13 23:57:37 -080033using ::android::Parcel;
34typedef struct{
35 int uToken;
36 int request;
37 int paramLen;
38 char param[LYNQ_REQUEST_PARAM_BUF];
39}lynq_client_t;
lh13586612022-01-11 21:58:58 -080040typedef enum{
41 LYNQ_E_CARDSTATE_ERROR=8000,
42 /* The voice service state is out of service*/
43 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
44 /* The voice service state is EMERGENCY_ONLY*/
45 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
46 /* The radio power is power off*/
47 LYNQ_E_STATE_POWER_OFF=8003,
48 LYNQ_E_TIME_OUT=8004,
49 /*create or open sms DB fail */
50 LYNQ_E_SMS_DB_FAIL=8005,
51 /*Failed to execute sql statement*/
52 LYNQ_E_SMS_SQL_FAIL = 8006,
53 LYNQ_E_SMS_NOT_FIND = 8007,
Hong_Liu25edfe72023-06-16 01:13:42 -070054 LYNQ_E_GET_RESP_FAIL = 8008,
55 LYNQ_E_NOT_THIS_APN = 8087,
56 LYNQ_E_NOT_ANY_APN = 8088,
57 LYNQ_E_MD_NOT_READY = 8089,
lh13586612022-01-11 21:58:58 -080058 /* The logic conflict*/
59 LYNQ_E_CONFLICT=9000,
60 /*Null anomaly*/
61 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080062}LYNQ_E;
63
64int lynq_client_sockfd = 0;
65int Global_uToken = 0;
Hong_Liu7e1b85e2023-05-16 05:51:57 -070066struct sockaddr_in lynq_data_socket_server_addr;
67int lynq_data_socket_server_addr_len;
rjw7ee7bb42023-01-18 11:34:28 +080068
lhf81a46f2022-02-13 23:57:37 -080069int lynq_data_call_change_id = -1;
70pthread_t lynq_data_tid =-1;
71static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
72static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080073
Hong_Liu25edfe72023-06-16 01:13:42 -070074static pthread_mutex_t s_data_call_deactived_mutex = PTHREAD_MUTEX_INITIALIZER;
75static pthread_cond_t s_data_call_deactived_cond = PTHREAD_COND_INITIALIZER;
76
77
rjw20006d12022-04-21 16:29:04 +080078static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
79static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080080static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
81static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER;
rjwed00d042022-05-25 09:18:16 +080082/**g_lynq_data_sendto_mutex
83* @brief mark data send request mutex
84*/
85static pthread_mutex_t g_lynq_data_sendto_mutex;
rjwf9ec3832023-04-12 10:59:15 +080086/*This value data the state of the wait*/
rjwc3d6e582023-03-28 17:19:11 +080087static int data_waiting_status = 0;
rjwf9ec3832023-04-12 10:59:15 +080088/*The value indicates that 8085 error occurs in data*/
rjwc63abb42023-03-31 18:22:42 +080089static int data_invaild_error = 0;
rjwf9ec3832023-04-12 10:59:15 +080090/*This value ensure the data call timing is correct*/
91static int data_timelimit = 0;
rjwc63abb42023-03-31 18:22:42 +080092
rjw22947c22022-03-15 09:21:29 +080093/**g_lynq_data_init_flag
94* @brief mark data initialization state
95* 0:deinit status
96* 1:init state
97*/
98static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +080099/**g_lynq_apn_result
100* @brief temp of apn result info
101*/
102char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +0800103
rjw7ee7bb42023-01-18 11:34:28 +0800104static std::vector<int> s_data_urc_wait_list;
105
rjw20006d12022-04-21 16:29:04 +0800106typedef struct
107{
lhf81a46f2022-02-13 23:57:37 -0800108 char apn[LYNQ_APN_MAX_LEN];
109 char apnType[LYNQ_APN_TYPE_MAX_LEN];
110 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
111 int hasUsed;
112 int hasTimeout;
Hong_Liudc46d412023-05-18 13:36:26 -0700113 int status;
114 char statusApnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800115}lynq_apn_t;
116lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
117lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
118int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800119
lhf81a46f2022-02-13 23:57:37 -0800120int getLynqApnID(char apnType[])
121{
122 int ret = 0;
rjwc63abb42023-03-31 18:22:42 +0800123 int len = 0;
lhf81a46f2022-02-13 23:57:37 -0800124 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
125 {
Hong_Liudc46d412023-05-18 13:36:26 -0700126 len = strlen(apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700127 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 +0800128 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
lh13586612022-01-11 21:58:58 -0800129 {
lhf81a46f2022-02-13 23:57:37 -0800130 return ret;
131 }
132 }
133 return -1;
134}
rjw7ee7bb42023-01-18 11:34:28 +0800135
Hong_Liudc46d412023-05-18 13:36:26 -0700136int getDeactApnID(char apnType[])
137{
138 int ret = 0;
139 int len = 0;
140 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
141 {
142 len = strlen(apnType);
143 LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len);
144 if(strncmp(lynq_apn_table[ret].statusApnType,apnType,len)==0)
145 {
146 return ret;
147 }
148 }
149 return -1;
150}
151
lhf81a46f2022-02-13 23:57:37 -0800152void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
153{
154 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
155 if(apn_table==NULL)
156 {
157 LYERRLOG("apn_table is null");
158 return;
159 }
160 memcpy(apn_table->apn,apn,strlen(apn)+1);
161 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
162 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
163 apn_table->hasTimeout = 0;
164 apn_table->hasUsed = 1;
165 return;
166}
rjw7ee7bb42023-01-18 11:34:28 +0800167
lhf81a46f2022-02-13 23:57:37 -0800168void cleanOnceApnTable(int apnId)
169{
Hong_Liudc46d412023-05-18 13:36:26 -0700170 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
lhf81a46f2022-02-13 23:57:37 -0800171 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
172 {
173 LYERRLOG("apn id is invalid!!!");
174 return;
175 }
176 lynq_apn_table[apnId].hasTimeout = 0;
177 lynq_apn_table[apnId].hasUsed = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700178 memcpy(lynq_apn_table[apnId].statusApnType,lynq_apn_table[apnId].apnType,strlen(lynq_apn_table[apnId].apnType));
lhf81a46f2022-02-13 23:57:37 -0800179 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700180 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
lhf81a46f2022-02-13 23:57:37 -0800181 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700182 lynq_apn_table[apnId].status = 32;
lhf81a46f2022-02-13 23:57:37 -0800183 return;
184}
Hong_Liudc46d412023-05-18 13:36:26 -0700185void cleanDeactApn(int apnId)
186{
187 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
188 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
189 {
190 LYERRLOG("apn id is invalid!!!");
191 return;
192 }
193 lynq_apn_table[apnId].status = 0;
194 bzero(lynq_apn_table[apnId].statusApnType,LYNQ_APN_TYPE_MAX_LEN);
195}
196
197void updateDeactApn(int apnId,int pdnState)
198{
199 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
200 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
201 {
202 LYERRLOG("apn id is invalid!!!");
203 return;
204 }
205 lynq_apn_table[apnId].status = pdnState;
206}
207
208
lhf81a46f2022-02-13 23:57:37 -0800209int getUnusedElement()
210{
Hong_Liudc46d412023-05-18 13:36:26 -0700211 if (lynq_apn_table == NULL)
212 {
213 LYERRLOG("get UnusedElemnt apn_table is null");
214 return -1;
215 }
lhf81a46f2022-02-13 23:57:37 -0800216 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
217 {
218 if(lynq_apn_table[i].hasUsed!=1)
219 {
220 return i;
221 }
222 }
rjwc63abb42023-03-31 18:22:42 +0800223 LYERRLOG("None of get unused Element");
lhf81a46f2022-02-13 23:57:37 -0800224 return -1;
225}
226int updateApn(char apnType[])
227{
228 int ret = 0;
229 ret = getUnusedElement();
Hong_Liu55668712023-05-16 21:49:17 -0700230 if(ret >= 0)
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700231 {
232 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
233 lynq_apn_table[ret].hasUsed = 1;
234 }
lhf81a46f2022-02-13 23:57:37 -0800235 return ret;
236}
Hong_Liu55c62f52023-08-24 19:05:50 -0700237//@return
238//other:this apn has been used in apn table
239//-1:this apn not has been used in apn table
240int check_used_apn(char apnType[])
241{
242 LYINFLOG("check_used_apn.apnType:%s",apnType);
243 int ret = 0;
244 int len = 0;
245 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
246 {
247 len = strlen(apnType);
248 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
249 {
250 LYINFLOG("check_used_apn.apnType:%s in apn table",apnType);
251 return ret;
252 }
253 }
254 return -1;
255}
256int get_handle(char apnType[])
257{
258 int call_id = 0;
259 call_id = check_used_apn(apnType);
260 if(call_id == -1)
261 {
262 call_id = updateApn(apnType);
263 }
264 LYINFLOG("handle:%d",call_id);
265 return call_id;
266}
rjw1309e232022-07-22 09:54:06 +0800267
268int handleCheck(int handle)
269{
Hong_Liu7163bbe2023-06-04 03:03:44 -0700270 if ((handle >= 0) && (handle <= 6))
rjw1309e232022-07-22 09:54:06 +0800271 {
Hong_Liu7163bbe2023-06-04 03:03:44 -0700272 if (lynq_apn_table[handle].hasUsed == 1)
273 {
274 return 0;
275 }
rjw1309e232022-07-22 09:54:06 +0800276 return -1;
277 }
Hong_Liu7163bbe2023-06-04 03:03:44 -0700278 return -1;
rjw1309e232022-07-22 09:54:06 +0800279}
rjw20006d12022-04-21 16:29:04 +0800280int waitApnResult()
281{
282 int ret = 0;
283 LYINFLOG("start wait apn result!!!");
284 int sec = 0;
285 int usec = 0;
286 struct timeval now;
287 struct timespec timeout;
288 gettimeofday(&now, NULL);
289 sec = 20000 / 1000;
290 usec = 20000 % 1000;
291 timeout.tv_sec = now.tv_sec + sec;
292 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
293 pthread_mutex_lock(&s_lynq_apn_change_mutex);
294 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
295 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
296 return ret;
297}
298
299void sendSignalApnChange()
300{
301 LYINFLOG("start send Signal Apn Change");
302 pthread_mutex_lock(&s_lynq_apn_change_mutex);
303 pthread_cond_signal(&s_lynq_apn_change_cond);
304 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
305 return;
306}
lhf81a46f2022-02-13 23:57:37 -0800307
308int waitPdnChange()
309{
310 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800311 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
312 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
313 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800314 return ret;
315}
316int waitDataCallstateChange(int mtime)
317{
318 int ret = 0;
319 int sec = 0;
320 int usec = 0;
321 struct timeval now;
322 struct timespec timeout;
323 gettimeofday(&now,NULL);
324 sec = mtime/1000;
325 usec = mtime%1000;
326 timeout.tv_sec = now.tv_sec+sec;
327 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
328 pthread_mutex_lock(&s_data_call_state_change_mutex);
329 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
330 pthread_mutex_unlock(&s_data_call_state_change_mutex);
331 return ret;
332}
333void sendSignalDataCallStateChange()
334{
335 pthread_mutex_lock(&s_data_call_state_change_mutex);
336 pthread_cond_signal(&s_data_call_state_change_cond);
337 pthread_mutex_unlock(&s_data_call_state_change_mutex);
338 return;
339}
Hong_Liu25edfe72023-06-16 01:13:42 -0700340int waitDeactived(int mtime)
341{
342 int ret = 0;
343 int sec = 0;
344 int usec = 0;
345 struct timeval now;
346 struct timespec timeout;
347 gettimeofday(&now,NULL);
348 sec = mtime/1000;
349 usec = mtime%1000;
350 timeout.tv_sec = now.tv_sec+sec;
351 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
352 pthread_mutex_lock(&s_data_call_deactived_mutex);
353 ret = pthread_cond_timedwait(&s_data_call_deactived_cond,&s_data_call_deactived_mutex,&timeout);
354 pthread_mutex_unlock(&s_data_call_deactived_mutex);
355 return ret;
356}
357void sendSignalDeactvied()
358{
359 pthread_mutex_lock(&s_data_call_deactived_mutex);
360 pthread_cond_signal(&s_data_call_deactived_cond);
361 pthread_mutex_unlock(&s_data_call_deactived_mutex);
362 return;
363}
364
lhf81a46f2022-02-13 23:57:37 -0800365void sendSignalPdnChange()
366{
rjw7ee7bb42023-01-18 11:34:28 +0800367 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
368 pthread_cond_signal(&s_lynq_urc_vector_cond);
369 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800370 return;
371}
372
373int get_response(int sockfd,Parcel &p)
374{
375 int len = 0;
376 char recvline[LYNQ_REC_BUF];
377 bzero(recvline,LYNQ_REC_BUF);
378 /* receive data from server */
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700379 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
380 //len = read(sockfd, recvline, LYNQ_REC_BUF);
rjw08528682022-07-04 21:28:02 +0800381 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800382 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700383 LYERRLOG("get_response fail,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800384 return -1;
385 }
386 if (recvline != NULL) {
387 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
388 p.setDataPosition(0);
389 }
390 return 0;
391}
Hong_Liu25edfe72023-06-16 01:13:42 -0700392/**@brief get utoken in range 0 to 10000
393* @return utoken
394*/
395int get_utoken()
lhf81a46f2022-02-13 23:57:37 -0800396{
Hong_Liu25edfe72023-06-16 01:13:42 -0700397 return (Global_uToken++)%10000;/*0-10000*/
398}
399/**@brief wait response with expected token and write msg to parcel in some time
400* @param fd [IN]: socket fd
401* @param p [OUT]: quote the parcel,if return success need delete p.
402* @param token [IN]: the expected token for the response msg
403* @return
404* 0:success
405* other:failure
406*/
407int wait_response(int sockfd,Parcel *& p,int utoken)
408{
409 int len = 0;
410 int flag = 1;
411 int count = 0;
412 int in_utoken = -1;
413 int resp_type = -1;
414 Parcel *temp = NULL;
415 char recvline[LYNQ_REC_BUF];
416 //Sometimes the socket is abnormal, causing the socket buffer to store the response of the last request.
417 //Here it does not return until the response corresponding to the request is read.
418 while(flag && (count < 20))//why?
lhf81a46f2022-02-13 23:57:37 -0800419 {
Hong_Liu25edfe72023-06-16 01:13:42 -0700420 bzero(recvline,LYNQ_REC_BUF);
421 count++;
422 LYINFLOG("wait_response,count:%d",count);
423 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
424 if(len == -1)
425 {
426 LYERRLOG("wait_response fail,errno:%d",errno);
427 return LYNQ_E_GET_RESP_FAIL;
428 }
429 if (len != 0)
430 {
431 temp = new Parcel;
432 int i = 0;
433 while((NULL == temp) && (i < 100))
434 {
435 usleep(1000);
436 temp = new Parcel;
437 i++;
438 }
439 if((i >= 100) || (NULL == temp))
440 {
441 LYERRLOG("wait_response i:%d",i);
442 return LYNQ_E_GET_RESP_FAIL;
443 }
444 temp->setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
445 temp->setDataPosition(0);
446 temp->readInt32(&resp_type);
447 temp->readInt32(&in_utoken);
448 LYINFLOG("[%s]in_utoken:%d,utoken:%d",__FUNCTION__,in_utoken,utoken);
449 if (in_utoken != utoken)
450 {
451 delete temp;
452 temp = NULL;
453 in_utoken = 0;
454 continue;
455 }
456 temp->setDataPosition(0);
457 p = temp;
458 flag = 0;
459 return 0;
460 }
461 else
462 {
463 LYERRLOG("recvline is null,errno:%d",errno);
464 return LYNQ_E_GET_RESP_FAIL;
465 }
466 }
467 return LYNQ_E_GET_RESP_FAIL;
468}
469
470int JumpHeader(Parcel *p,int *resp_type,int *utoken,int *request,int *slot_id,int *error)
471{
472 if(NULL == p)
473 {
474 LYERRLOG("JumpHeader is null");
475 return -1;
476 }
477 if(p->dataAvail() > 0)
478 {
479 p->readInt32(resp_type);
480 p->readInt32(utoken);
481 p->readInt32(request);
482 p->readInt32(slot_id);
483 p->readInt32(error);
lhf81a46f2022-02-13 23:57:37 -0800484 return 0;
485 }
486 else
487 {
488 return -1;
489 }
490}
Hong_Liu25edfe72023-06-16 01:13:42 -0700491void free_parcel(Parcel *p)
492{
493 if(p)
494 {
495 delete p;
496 p = NULL;
497 }
498}
lhf81a46f2022-02-13 23:57:37 -0800499int send_request(int sockfd,lynq_client_t *client_tmp)
500{
501 int ret=0;
lh8d290112023-10-22 20:53:06 -0700502 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 -0800503 if(ret==-1)
504 {
lh8d290112023-10-22 20:53:06 -0700505 LYERRLOG("%s:errno code:%d",__FUNCTION__,errno);
lhf81a46f2022-02-13 23:57:37 -0800506 return -1;
507 }
508 return 0;
509}
510static char *strdupReadString(Parcel &p) {
511 size_t stringlen;
512 const char16_t *s16;
513 s16 = p.readString16Inplace(&stringlen);
514 return strndup16to8(s16, stringlen);
515}
516static char *strdupReadString_p(Parcel *p) {
517 size_t stringlen;
518 const char16_t *s16;
519 s16 = p->readString16Inplace(&stringlen);
520 return strndup16to8(s16, stringlen);
521}
522
lhf81a46f2022-02-13 23:57:37 -0800523/*Warren add for T800 platform 2021/11/19 start*/
524int lynq_socket_client_start()
525{
lh8d290112023-10-22 20:53:06 -0700526 int ret;
527 struct timeval timeOut;
528 struct sockaddr_in liblynq_data_socket;
rjw747deea2022-07-01 18:25:30 +0800529
lh8d290112023-10-22 20:53:06 -0700530 ret = 0;
rjwa59bf312022-07-05 11:50:31 +0800531 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800532 timeOut.tv_usec = 0;
lh8d290112023-10-22 20:53:06 -0700533 bzero(&liblynq_data_socket, sizeof(liblynq_data_socket));
534 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
535
536 //set this lib socket config
537 liblynq_data_socket.sin_family = AF_INET;
538 liblynq_data_socket.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
rjw747deea2022-07-01 18:25:30 +0800539
lh8d290112023-10-22 20:53:06 -0700540 //set ril service socket config
541 lynq_data_socket_server_addr.sin_family = AF_INET;
542 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
543 lynq_data_socket_server_addr.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
544 lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr);
545
546 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
547 ret = bind(lynq_client_sockfd, (struct sockaddr *)&liblynq_data_socket, sizeof(liblynq_data_socket));
548 if (-1 == ret)
549 {
550 LYERRLOG("liblynq_data_socket bind fail,errno:%d",errno);
551 return -1;
552 }
rjw747deea2022-07-01 18:25:30 +0800553 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
554 {
lh8d290112023-10-22 20:53:06 -0700555 LYERRLOG("time out setting failed,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800556 return -1;
557 }
558 return 0;
559}
rjw7ee7bb42023-01-18 11:34:28 +0800560
561bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800562{
rjw7ee7bb42023-01-18 11:34:28 +0800563 switch(urc_id)
564 {
565 case LYNQ_URC_DATA_CALL_STATUS_IND:
566
567 case LYNQ_URC_MODIFY_APNDB:
568 case LYNQ_URC_RESET_APNDB:
569 return true;
570 default:
571 return false;
572 }
573}
574
rjwc63abb42023-03-31 18:22:42 +0800575int printf_apn_table()
576{
577 int ret = 0;
Hong_Liu6149f182023-05-12 02:15:14 -0700578 if (lynq_apn_table == NULL)
579 {
580 LYERRLOG("apn table is null");
581 return -1;
582 }
rjwc63abb42023-03-31 18:22:42 +0800583 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
584 {
Hong_Liudc46d412023-05-18 13:36:26 -0700585 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 +0800586 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
Hong_Liudc46d412023-05-18 13:36:26 -0700587 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 +0800588 }
589 return 0;
590}
591
Hong_Liu6149f182023-05-12 02:15:14 -0700592void printf_apn_table_debug(const char *fun,int line)
593{
594 LYINFLOG("[%s][%d]apn_table msg",fun,line);
595 printf_apn_table();
596}
rjwc63abb42023-03-31 18:22:42 +0800597
rjw7ee7bb42023-01-18 11:34:28 +0800598void urc_msg_process(Parcel *p)
599{
600 int len;
601 int resp_type;
602 int urcid;
603 int slot_id;
rjwf9ec3832023-04-12 10:59:15 +0800604 int check_count = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700605 static int apnId=-1;
rjw7ee7bb42023-01-18 11:34:28 +0800606
607 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800608 char apn[LYNQ_APN_MAX_LEN];
609 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800610 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800611 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800612
613 int size = p->dataSize();
614 p->readInt32(&resp_type);
615 p->readInt32(&urcid);
616 p->readInt32(&slot_id);
617 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
618 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800619 {
rjw7ee7bb42023-01-18 11:34:28 +0800620 case LYNQ_URC_DATA_CALL_STATUS_IND:
621 p->readInt32(&pdnState);
622 bzero(apn,LYNQ_APN_MAX_LEN);
623 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
624 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
625 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800626 {
rjw20006d12022-04-21 16:29:04 +0800627 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800628 int len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700629 if((len < LYNQ_APN_MAX_LEN-1) && (len > 0))
rjw20006d12022-04-21 16:29:04 +0800630 {
rjw7ee7bb42023-01-18 11:34:28 +0800631 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800632 }
Hong_Liu6149f182023-05-12 02:15:14 -0700633 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800634 urc_msg = strdupReadString_p(p);
635 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700636 if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800637 {
638 memcpy(apnType,urc_msg,len+1);
639 }
Hong_Liu6149f182023-05-12 02:15:14 -0700640 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800641 urc_msg = strdupReadString_p(p);
642 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700643 if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800644 {
645 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
646 }
Hong_Liu6149f182023-05-12 02:15:14 -0700647 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800648 //sendSignalDataCallStateChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700649 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800650 if(apnId >= 0)
651 {
Hong_Liudc46d412023-05-18 13:36:26 -0700652 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800653 if(lynq_apn_table[apnId].hasTimeout==1)
654 {
rjwc63abb42023-03-31 18:22:42 +0800655 /*whether timeout?,real or not,*/
656 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800657 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800658 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 +0800659 {
660 LYERRLOG("deactive this time out APN");
661 lynq_deactive_data_call(&apnId);
662 }
rjwc63abb42023-03-31 18:22:42 +0800663 else
rjw7ee7bb42023-01-18 11:34:28 +0800664 {
rjwc63abb42023-03-31 18:22:42 +0800665 /*if apn lose,update apn and deactive all apn*/
666 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800667 }
668 break;
669 }
rjwacdb2152023-02-07 14:12:49 +0800670 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
Hong_Liu6149f182023-05-12 02:15:14 -0700671 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800672 }
673 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800674 else
675 {
Hong_Liu6149f182023-05-12 02:15:14 -0700676 data_invaild_error = 1;
Hong_Liudc46d412023-05-18 13:36:26 -0700677 printf_apn_table_debug(__FUNCTION__,__LINE__);
678 apnId = getDeactApnID(apnType);
679 if(apnId < 0)
680 {
681 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
682 break;
683 }
684 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
685 updateDeactApn(apnId,pdnState);
686 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800687 }
rjw7ee7bb42023-01-18 11:34:28 +0800688 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
689 s_data_urc_wait_list.push_back(apnId);
690 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
691 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800692 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800693 LYDBGLOG("data call state:%d",lynq_data_call);
694 if(lynq_data_call==1)
695 {
rjwf9ec3832023-04-12 10:59:15 +0800696 while (data_timelimit == 0)
697 {
698 LYINFLOG("client not ready to wait");
699 for (check_count = 0;check_count < 500;check_count++)
700 {
701 /*wait 10ms*/
702 usleep(10*1000);
703 }
704 LYERRLOG("client still without res");
705 break;
706 }
rjw7ee7bb42023-01-18 11:34:28 +0800707 sendSignalDataCallStateChange();
708 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800709 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800710 }
Hong_Liu6149f182023-05-12 02:15:14 -0700711 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800712 }
rjw7ee7bb42023-01-18 11:34:28 +0800713 else
rjw20006d12022-04-21 16:29:04 +0800714 {
rjw7ee7bb42023-01-18 11:34:28 +0800715 urc_msg = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -0700716 free(urc_msg);
717 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800718 len = strlen(urc_msg);
719 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
720 {
721 memcpy(apnType,urc_msg,len+1);
722 }
Hong_Liu6149f182023-05-12 02:15:14 -0700723 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800724 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
Hong_Liudc46d412023-05-18 13:36:26 -0700725 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800726 if(apnId >= 0)
727 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700728 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 -0700729 lynq_data_call_change_id = apnId;
730 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
731 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
732 s_data_urc_wait_list.push_back(apnId);
733 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
734 sendSignalPdnChange();
735 }
736 else
737 {
738 apnId = getDeactApnID(apnType);
739 if(apnId < 0)
740 {
741 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
742 break;
743 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700744 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 -0700745 cleanDeactApn(apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800746 lynq_data_call_change_id = apnId;
747 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800748 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
749 s_data_urc_wait_list.push_back(apnId);
750 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -0700751 sendSignalDeactvied();
rjwc3d6e582023-03-28 17:19:11 +0800752 sendSignalPdnChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700753 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800754 }
rjw7ee7bb42023-01-18 11:34:28 +0800755 LYDBGLOG("data call state:%d",lynq_data_call);
756 if(lynq_data_call==1)
757 {
rjwf9ec3832023-04-12 10:59:15 +0800758 while (data_timelimit == 0)
759 {
760 LYINFLOG("client not ready to wait");
761 for (check_count = 0;check_count < 500;check_count++)
762 {
763 /*wait 10ms*/
764 usleep(10*1000);
765 }
766 LYERRLOG("client still without res");
767 break;
768 }
rjw7ee7bb42023-01-18 11:34:28 +0800769 sendSignalDataCallStateChange();
770 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800771 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800772 }
Hong_Liu6149f182023-05-12 02:15:14 -0700773 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800774 }
775 break;
776 case LYNQ_URC_MODIFY_APNDB:
777 urc_msg = strdupReadString_p(p);
778 if (NULL == urc_msg)
779 {
780 LYERRLOG("error apn msg");
781 }
782 else
783 {
784 bzero(g_lynq_apn_result, 1024);
785 strcpy(g_lynq_apn_result, urc_msg);
786 sendSignalApnChange();
787 }
Hong_Liu6149f182023-05-12 02:15:14 -0700788 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800789 break;
790 case LYNQ_URC_RESET_APNDB:
791 {
rjw20006d12022-04-21 16:29:04 +0800792 urc_msg = strdupReadString_p(p);
793 if (NULL == urc_msg)
794 {
795 LYERRLOG("error apn msg");
796 }
797 else
798 {
799 bzero(g_lynq_apn_result, 1024);
800 strcpy(g_lynq_apn_result, urc_msg);
801 sendSignalApnChange();
802 }
Hong_Liu6149f182023-05-12 02:15:14 -0700803 free(urc_msg);
rjw20006d12022-04-21 16:29:04 +0800804 }
rjw7ee7bb42023-01-18 11:34:28 +0800805 default:
806 break;
lhf81a46f2022-02-13 23:57:37 -0800807 }
rjw7ee7bb42023-01-18 11:34:28 +0800808
lhf81a46f2022-02-13 23:57:37 -0800809}
rjw7ee7bb42023-01-18 11:34:28 +0800810
rjw7ee7bb42023-01-18 11:34:28 +0800811int create_urc_vector_signal_thread()
812{
813 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800814 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800815 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
816 s_data_urc_wait_list.clear();
817 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800818 return 0;
819}
Hong_Liu25edfe72023-06-16 01:13:42 -0700820int get_imsi();
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700821int check_apn_status();
822int radio_switch(int status);
lhf81a46f2022-02-13 23:57:37 -0800823int lynq_init_data(int uToken)
824{
rjw22947c22022-03-15 09:21:29 +0800825 if (g_lynq_data_init_flag == 1)
826 {
827 LYERRLOG("init twice is not allowed");
828 return -1;
829 }
830 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800831 int result = 0;
832 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800833 LYLOGSET(LOG_INFO);
834 LYLOGEINIT(USER_LOG_TAG);
835 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800836 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800837 if(result!=0)
838 {
839 LYERRLOG("init socket client fail!!!");
840 return -1;
841 }
rjw7ee7bb42023-01-18 11:34:28 +0800842 result = lynq_init_data_urc_thread();
843 if(result!=0)
844 {
845 LYERRLOG("init socket urc fail!!!");
846 return -1;
847 }
848
849 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800850 if(result!=0)
851 {
852 LYERRLOG("init socket urc fail!!!");
853 return -1;
854 }
855 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700856 LYINFLOG("[%s] radio on/off solution 20230724",__FUNCTION__);
Hong_Liu25edfe72023-06-16 01:13:42 -0700857 int count = 0;
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700858 while(count < 2)//try recover the network within 10s.
859 {
860 result = check_apn_status();
861 if(result==0)
862 {
863 break;
864 }
865 radio_switch(0);
866 sleep(1);
867 radio_switch(1);
868 sleep(3);
869 count++;
870 }
871 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
872 if(result!=0)
873 {
874 LYDBGLOG("lynq init call fail!!!");
875 return LYNQ_E_MD_NOT_READY;//
876 }
877 /* old
Hong_Liu25edfe72023-06-16 01:13:42 -0700878 while(count < 10)
879 {
880 result = get_imsi();
881 if(result==0)
882 {
883 break;
884 }
885 sleep(1);
886 count++;
887 }
888 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
889 if(result!=0)
890 {
891 LYDBGLOG("lynq init call fail!!!");
892 return LYNQ_E_MD_NOT_READY;//
893 }
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700894 */
lhf81a46f2022-02-13 23:57:37 -0800895 LYDBGLOG("lynq init call success!!!");
896 return 0;
897
898}
899int lynq_deinit_data()
900{
901 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800902 if (g_lynq_data_init_flag == 0)
903 {
904 LYERRLOG("deinit twice is not allowed");
905 return ret;
906 }
907 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800908 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
909 {
910 if(strlen(lynq_apn_table[i].apnType)!=0)
911 {
912 lynq_deactive_data_call(&i);
913 }
914 }
915 if(lynq_client_sockfd>0)
916 {
917 close(lynq_client_sockfd);
918 }
rjw7ee7bb42023-01-18 11:34:28 +0800919 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800920 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800921 {
rjw7ee7bb42023-01-18 11:34:28 +0800922 LYERRLOG("lynq_deinit_data_urc_thread fail");
923 return ret;
rjw22947c22022-03-15 09:21:29 +0800924 }
rjwc3d6e582023-03-28 17:19:11 +0800925 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
926 s_data_urc_wait_list.clear();
927 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800928 return 0;
929}
930int lynq_setup_data_call(int *handle)
931{
Hong_Liue54db8c2023-04-21 02:37:23 -0700932 int error = -1;
933 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
934 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
Hong_Liue9879152023-04-25 20:40:26 -0700935 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -0700936 #else
Hong_Liu25edfe72023-06-16 01:13:42 -0700937 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -0800938 lynq_client_t client;
939 int resp_type = -1;
940 int request = -1;
941 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -0800942 int lynq_data_call_id = 0;
943 if(handle==NULL)
944 {
945 LYERRLOG("handle is null!!!");
946 return LYNQ_E_NULL_ANONALY;
947 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700948 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -0800949 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
950 client.paramLen = 0;
951 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
952 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -0700953 lynq_data_call_id = get_handle("default");
rjwc63abb42023-03-31 18:22:42 +0800954 if (lynq_data_call_id < 0)
955 {
956 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700957 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +0800958 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700959 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect.
960 //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate.
rjw733b9832023-04-03 10:20:08 +0800961 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800962 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800963 if(send_request(lynq_client_sockfd,&client)==-1)
964 {
965 LYERRLOG("send request fail");
966 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -0700967 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700968 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -0800969 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700970 //get_response(lynq_client_sockfd,p);
971 error = wait_response(lynq_client_sockfd,p,client.uToken);
972 if(error!=0)
973 {
974 LYERRLOG("wait_response fail,ret:%d",error);
975 printf_apn_table_debug(__FUNCTION__,__LINE__);
976 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
977 return error;
978 }
rjwed00d042022-05-25 09:18:16 +0800979 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liuaa7f4b32023-07-19 07:51:25 -0700980 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
Hong_Liu25edfe72023-06-16 01:13:42 -0700981 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -0800982 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -0800983 if(error==0)
984 {
rjwf9ec3832023-04-12 10:59:15 +0800985 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -0700986 if (waitDataCallstateChange(LYNQ_DATA_TIME_OUT) == ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -0800987 {
988 error = LYNQ_E_TIME_OUT;
989 LYERRLOG("timeout:wait data Call state fail!!!");
990 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -0700991 if (data_invaild_error == 1)
992 {
993 data_invaild_error = 0;
994 LYERRLOG("urc apn info error!!!");
995 return 8085;
996 }
997 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -0800998 return error;
999 }
lhf81a46f2022-02-13 23:57:37 -08001000 }
Hong_Liu6149f182023-05-12 02:15:14 -07001001 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liue54db8c2023-04-21 02:37:23 -07001002 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001003 return error;
1004}
rjw7ee7bb42023-01-18 11:34:28 +08001005
lhf81a46f2022-02-13 23:57:37 -08001006int lynq_deactive_data_call(int *handle)
1007{
Hong_Liu25edfe72023-06-16 01:13:42 -07001008 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001009 lynq_client_t client;
1010 int resp_type = -1;
1011 int request = -1;
1012 int slot_id = -1;
1013 int error = -1;
1014 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +08001015 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -08001016 if(handle==NULL)
1017 {
1018 LYERRLOG("handle is null!!!");
1019 return -1;
1020 }
rjw1309e232022-07-22 09:54:06 +08001021 ret = handleCheck(*handle);
1022 if (ret != 0)
1023 {
1024 LYERRLOG("incomming handle is invalid");
1025 return -1;
1026 }
1027 lynq_data_call_id = *handle;
Hong_Liu25edfe72023-06-16 01:13:42 -07001028 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001029 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
Hong_Liue3d35262023-05-04 00:20:12 -07001030 client.paramLen = 0;
1031 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1032 #ifdef GSW_RIL_CFG
1033 client.paramLen = 1;
1034 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1035 #else
1036 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -08001037 {
lhf81a46f2022-02-13 23:57:37 -08001038 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -08001039 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1040 }
Hong_Liue3d35262023-05-04 00:20:12 -07001041 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001042 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001043 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001044 if(send_request(lynq_client_sockfd,&client)==-1)
1045 {
1046 LYERRLOG("send request fail");
1047 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001048 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001049 return -1;
1050 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001051 //get_response(lynq_client_sockfd,p);
1052 error = wait_response(lynq_client_sockfd,p,client.uToken);
1053 if(error!=0)
1054 {
1055 LYERRLOG("wait_response fail,ret:%d",error);
1056 printf_apn_table_debug(__FUNCTION__,__LINE__);
1057 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1058 return error;
1059 }
rjwed00d042022-05-25 09:18:16 +08001060 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001061 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1062 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 -08001063 cleanOnceApnTable(lynq_data_call_id);
Hong_Liu6149f182023-05-12 02:15:14 -07001064 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liu25edfe72023-06-16 01:13:42 -07001065 if(error==0)
1066 {
1067 if(waitDeactived(20000)==ETIMEDOUT)
1068 {
1069 error = LYNQ_E_TIME_OUT;
1070 LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!");
1071 printf_apn_table_debug(__FUNCTION__,__LINE__);
1072 }
1073 }
1074 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001075 return error;
1076}
1077int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
1078{
Hong_Liu25edfe72023-06-16 01:13:42 -07001079 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001080 lynq_client_t client;
1081 int resp_type = -1;
1082 int request = -1;
1083 int slot_id = -1;
1084 int error = -1;
lhf81a46f2022-02-13 23:57:37 -08001085 int lynq_data_call_id = -1;
1086 char *argv[10] = {};
Hong_Liue54db8c2023-04-21 02:37:23 -07001087 #ifdef GSW_RIL_CFG
1088 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
1089 if(handle==NULL||apnType==NULL)
1090 {
1091 LYERRLOG("handle or apntype is null!!!");
1092 return -1;
1093 }
1094 #else
lhf81a46f2022-02-13 23:57:37 -08001095 if(handle==NULL||apn==NULL||apnType==NULL)
1096 {
1097 LYERRLOG("handle ,apn or apntype is null!!!");
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001098 return LYNQ_E_NULL_ANONALY;
lhf81a46f2022-02-13 23:57:37 -08001099 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001100 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001101 if(user==NULL)
1102 {
1103 argv[1] = "null";
1104 }
1105 else
1106 {
1107 argv[1] = user;
lh13586612022-01-11 21:58:58 -08001108 }
1109 if(password==NULL)
1110 {
lhf81a46f2022-02-13 23:57:37 -08001111 argv[2] = "null";
lh13586612022-01-11 21:58:58 -08001112 }
1113 else
1114 {
lhf81a46f2022-02-13 23:57:37 -08001115 argv[2] = password;
lh13586612022-01-11 21:58:58 -08001116 }
1117 if(authType==NULL)
1118 {
lhf81a46f2022-02-13 23:57:37 -08001119 argv[3] = "null";
lh13586612022-01-11 21:58:58 -08001120 }
1121 else
1122 {
lhf81a46f2022-02-13 23:57:37 -08001123 argv[3] = authType;
lh13586612022-01-11 21:58:58 -08001124 }
1125 if(normalProtocol==NULL)
1126 {
lhf81a46f2022-02-13 23:57:37 -08001127 argv[4] = "null";
lh13586612022-01-11 21:58:58 -08001128 }
1129 else
1130 {
lhf81a46f2022-02-13 23:57:37 -08001131 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -08001132 }
1133 if(roamingProtocol==NULL)
1134 {
lhf81a46f2022-02-13 23:57:37 -08001135 argv[5] = "null";
lh13586612022-01-11 21:58:58 -08001136 }
1137 else
1138 {
lhf81a46f2022-02-13 23:57:37 -08001139 argv[5] = roamingProtocol;
1140 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001141 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001142 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1143 client.paramLen = 7;
1144 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -07001145 #ifdef GSW_RIL_CFG
1146 if(NULL == apn)
1147 {
1148 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1149 }
1150 else
1151 {
1152 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1153 }
1154 #else
lhf81a46f2022-02-13 23:57:37 -08001155 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 -07001156 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001157 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -07001158 lynq_data_call_id = get_handle(apnType);
rjwc63abb42023-03-31 18:22:42 +08001159 if (lynq_data_call_id < 0)
1160 {
1161 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001162 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001163 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001164 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16)
rjw733b9832023-04-03 10:20:08 +08001165 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001166 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001167 if(send_request(lynq_client_sockfd,&client)==-1)
1168 {
1169 LYERRLOG("send request fail");
1170 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001171 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001172 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001173 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001174 //get_response(lynq_client_sockfd,p);
1175 error = wait_response(lynq_client_sockfd,p,client.uToken);
1176 if(error!=0)
1177 {
1178 LYERRLOG("wait_response fail,ret:%d",error);
1179 printf_apn_table_debug(__FUNCTION__,__LINE__);
1180 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1181 return error;
1182 }
rjwed00d042022-05-25 09:18:16 +08001183 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001184 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1185 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1186 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001187 if(error==0)
1188 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001189 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001190 if(waitDataCallstateChange(LYNQ_DATA_TIME_OUT)==ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001191 {
1192 error = LYNQ_E_TIME_OUT;
1193 LYERRLOG("timeout:wait data Call state fail!!!");
1194 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001195 if (data_invaild_error == 1)
1196 {
1197 data_invaild_error = 0;
1198 LYERRLOG("urc apn info error!!!");
1199 return 8085;
1200 }
1201 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001202 return error;
1203 }
lhf81a46f2022-02-13 23:57:37 -08001204 }
Hong_Liu6149f182023-05-12 02:15:14 -07001205 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001206 return error;
1207}
1208/*
1209int lynq_deactive_data_call_sp(int *handle,char *apnType)
1210{
1211 Parcel p;
1212 lynq_client_t client;
1213 int resp_type = -1;
1214 int request = -1;
1215 int slot_id = -1;
1216 int error = -1;
1217 if(handle==NULL||apnType==NULL)
1218 {
1219 LYERRLOG("handle is null!!!");
1220 return -1;
1221 }
1222 client.uToken = Global_uToken;
1223 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
1224 client.paramLen = 1;
1225 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1226 sprintf(client.param,"%s",apnType);
1227 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1228 if(send_request(lynq_client_sockfd,&client)==-1)
1229 {
1230 LYERRLOG("send request fail");
1231 perror("[LYNQ_DATA] send request fail:");
1232 return -1;
1233 }
1234 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +08001235 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -08001236 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1237 return error;
1238}
1239*/
1240int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
1241{
Hong_Liu25edfe72023-06-16 01:13:42 -07001242 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001243 lynq_client_t client;
1244 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001245 int token;
Hong_Liu25edfe72023-06-16 01:13:42 -07001246 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001247 int slot_id = -1;
1248 int error = -1;
1249 int version =0;
1250 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001251 char *temp_char = NULL;
1252 if(dataCallList==NULL)
1253 {
1254 LYERRLOG("dataCallList is null!!!");
1255 return -1;
1256 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001257 client.uToken = get_utoken();;
lhf81a46f2022-02-13 23:57:37 -08001258 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1259 client.paramLen = 0;
1260 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1261 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001262 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001263 if(send_request(lynq_client_sockfd,&client)==-1)
1264 {
1265 LYERRLOG("send request fail");
1266 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001267 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001268 return -1;
1269 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001270 //get_response(lynq_client_sockfd,p);
1271 error = wait_response(lynq_client_sockfd,p,client.uToken);
1272 if(error!=0)
1273 {
1274 LYERRLOG("wait_response fail,ret:%d",error);
1275 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1276 return error;
1277 }
rjwed00d042022-05-25 09:18:16 +08001278 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001279 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
rjwfa532972022-09-16 13:39:41 +08001280 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001281 LYERRLOG("JumpHeader fail");
rjwfa532972022-09-16 13:39:41 +08001282 return -1;
1283 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001284 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1285 p->readInt32(&version);
lhf81a46f2022-02-13 23:57:37 -08001286 if(version==11)
1287 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001288 p->readInt32(&num);
lhf81a46f2022-02-13 23:57:37 -08001289 *realNum = num;
1290 for (int i = 0; i < num; i++)
1291 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001292 p->readInt32(&dataCallList[i].status);
1293 p->readInt32(&dataCallList[i].suggestedRetryTime);
1294 p->readInt32(&dataCallList[i].cid);
1295 p->readInt32(&dataCallList[i].active);
1296 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001297 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1298 if(temp_char)
1299 {
1300 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1301 free(temp_char);
1302 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001303 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001304 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1305 if(temp_char)
1306 {
1307 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1308 free(temp_char);
1309 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001310 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001311 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1312 if(temp_char)
1313 {
1314 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1315 free(temp_char);
1316 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001317 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001318 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1319 if(temp_char)
1320 {
1321 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1322 free(temp_char);
1323 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001324 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001325 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1326 if(temp_char)
1327 {
1328 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1329 free(temp_char);
1330 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001331 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001332 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1333 if(temp_char)
1334 {
1335 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1336 free(temp_char);
1337 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001338 p->readInt32(&dataCallList[i].mtu);
lhf81a46f2022-02-13 23:57:37 -08001339 }
1340 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001341 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001342 return error;
1343}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001344
1345int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
1346{
1347 LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
1348 if((handle < 0) || (handle > 6) || (NULL == apn_msg))
1349 {
1350 LYERRLOG("handle value error,or apn_msg is null");
1351 return LYNQ_E_NULL_ANONALY;
1352 }
1353 apn_msg->handle = handle;
1354 if(apn_msg->apn!=NULL)
1355 {
1356 memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
1357 }
1358 if(apn_msg->apnType!=NULL)
1359 {
1360 memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
1361 }
1362 return 0;
1363}
1364
lhf81a46f2022-02-13 23:57:37 -08001365int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1366{
1367 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1368 int number = 0;
1369 int lynq_data_call_id = 0;
1370 int error = 0;
1371 lynq_data_call_id = *handle;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001372 if((handle==NULL) || (dataCallList==NULL))
lhf81a46f2022-02-13 23:57:37 -08001373 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001374 LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
lhf81a46f2022-02-13 23:57:37 -08001375 return LYNQ_E_NULL_ANONALY;
1376 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001377 if ((*handle < 0) || (*handle > 6))
rjw3938f262023-03-08 16:09:28 +08001378 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001379 LYERRLOG("[lynq_get_data_call_list] handle value error");
1380 return LYNQ_E_NULL_ANONALY;
rjw3938f262023-03-08 16:09:28 +08001381 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001382 LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001383 memset(interDataCallList,0,sizeof(interDataCallList));
1384 error = getDataCallLists(interDataCallList,&number);
1385 if(error == 0)
1386 {
1387 for(int i = 0;i < number;i++)
1388 {
1389 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1390 {
1391 dataCallList->active = interDataCallList[i].active;
1392 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1393 dataCallList->cid = interDataCallList[i].cid;
1394 dataCallList->status = interDataCallList[i].status;
1395 dataCallList->mtu = interDataCallList[i].mtu;
1396 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1397 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1398 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1399 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1400 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1401 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1402 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1403 }
1404 }
1405 }
1406 return error;
1407}
1408int lynq_wait_data_call_state_change(int *handle)
1409{
rjwc3d6e582023-03-28 17:19:11 +08001410 if (data_waiting_status == 1)
1411 {
1412 LYDBGLOG("some thread is waiting");
1413 return -3;
1414 }
1415 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1416 if (s_data_urc_wait_list.empty())
1417 {
1418 LYDBGLOG("start wait");
1419 data_waiting_status = 1;
1420 waitPdnChange();
1421 }
1422 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001423 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001424
1425 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1426 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001427 if (iter != s_data_urc_wait_list.end())
1428 {
1429 *handle = *iter;
1430 }
rjw7ee7bb42023-01-18 11:34:28 +08001431 s_data_urc_wait_list.erase(iter);
1432 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1433
Hong_Liudc46d412023-05-18 13:36:26 -07001434 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001435 return 0;
1436}
1437/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001438
1439/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001440
1441int 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 +08001442{
1443 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001444 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001445 {
rjw61fcae32022-08-18 14:03:39 +08001446 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001447 }
rjw61fcae32022-08-18 14:03:39 +08001448 else
rjw0cdacbc2022-06-22 10:51:07 +08001449 {
rjw61fcae32022-08-18 14:03:39 +08001450 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001451 }
rjw20006d12022-04-21 16:29:04 +08001452 if (mcc == NULL)
1453 {
1454 sprintf(strtmp[1], "mcc=;");
1455 }
1456 else
1457 {
1458 sprintf(strtmp[1], "mcc=%s;", mcc);
1459 }
1460 if (mnc == NULL)
1461 {
rjw61fcae32022-08-18 14:03:39 +08001462 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001463 }
1464 else
1465 {
1466 sprintf(strtmp[2], "mnc=%s;", mnc);
1467 }
1468 if (apn == NULL)
1469 {
1470 sprintf(strtmp[3], "apn=;");
1471 }
1472 else
1473 {
1474 sprintf(strtmp[3], "apn=%s;", apn);
1475 }
1476 if (apntype == NULL)
1477 {
1478 sprintf(strtmp[4], "apntype=;");
1479 }
1480 else
1481 {
1482 sprintf(strtmp[4], "apntype=%s;", apntype);
1483 }
1484 if (user == NULL)
1485 {
1486 sprintf(strtmp[5], "user=;");
1487 }
1488 else
1489 {
1490 sprintf(strtmp[5], "user=%s;", user);
1491 }
1492 if (password == NULL)
1493 {
1494 sprintf(strtmp[6], "password=;");
1495 }
1496 else
1497 {
1498 sprintf(strtmp[6], "password=%s;", password);
1499 }
1500 if (normalprotocol == NULL)
1501 {
1502 sprintf(strtmp[7], "normalprotocol=;");
1503 }
1504 else
1505 {
1506 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1507 }
1508 if (roamingprotocol == NULL)
1509 {
1510 sprintf(strtmp[8], "roamingprotocol=;");
1511 }
1512 else
1513 {
1514 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1515 }
1516 if (carrier == NULL)
1517 {
1518 sprintf(strtmp[9], "carrier=;");
1519 }
1520 else
1521 {
1522 sprintf(strtmp[9], "carrier=%s;", carrier);
1523 }
rjw61fcae32022-08-18 14:03:39 +08001524 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 +08001525
rjw20006d12022-04-21 16:29:04 +08001526 return 0;
1527}
1528
1529int 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)
1530{
1531 char strtmp[10][32];
1532 if (id == NULL)
1533 {
1534 sprintf(strtmp[0], "id=;");
1535 }
1536 else
1537 {
1538 sprintf(strtmp[0], "id=%s;", id);
1539 }
1540 if (mcc == NULL)
1541 {
1542 sprintf(strtmp[1], "mcc=;");
1543 }
1544 else
1545 {
1546 sprintf(strtmp[1], "mcc=%s;", mcc);
1547 }
1548 if (mnc == NULL)
1549 {
1550 sprintf(strtmp[2], "mnc=;");
1551 }
1552 else
1553 {
1554 sprintf(strtmp[2], "mnc=%s;", mnc);
1555 }
1556 if (apn == NULL)
1557 {
1558 sprintf(strtmp[3], "apn=;");
1559 }
1560 else
1561 {
1562 sprintf(strtmp[3], "apn=%s;", apn);
1563 }
1564 if (apntype == NULL)
1565 {
1566 sprintf(strtmp[4], "apntype=;");
1567 }
1568 else
1569 {
1570 sprintf(strtmp[4], "apntype=%s;", apntype);
1571 }
1572 if (user == NULL)
1573 {
1574 sprintf(strtmp[5], "user=;");
1575 }
1576 else
1577 {
1578 sprintf(strtmp[5], "user=%s;", user);
1579 }
1580 if (password == NULL)
1581 {
1582 sprintf(strtmp[6], "password=;");
1583 }
1584 else
1585 {
1586 sprintf(strtmp[6], "password=%s;", password);
1587 }
1588 if (normalprotocol == NULL)
1589 {
1590 sprintf(strtmp[7], "normalprotocol=;");
1591 }
1592 else
1593 {
1594 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1595 }
1596 if (roamingprotocol == NULL)
1597 {
1598 sprintf(strtmp[8], "roamingprotocol=;");
1599 }
1600 else
1601 {
1602 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1603 }
1604 if (carrier == NULL)
1605 {
1606 sprintf(strtmp[9], "carrier=;");
1607 }
1608 else
1609 {
1610 sprintf(strtmp[9], "carrier=%s;", carrier);
1611 }
1612 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]);
1613 return 0;
1614}
1615
rjwaf4b1612022-06-13 17:26:01 +08001616
1617int 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)
1618{
1619 char strtmp[10][32];
1620 if (id == NULL)
1621 {
1622 sprintf(strtmp[0], "");
1623 }
1624 else
1625 {
1626 sprintf(strtmp[0], "id=%s;", id);
1627 }
1628 if (mcc == NULL)
1629 {
1630 sprintf(strtmp[1], "");
1631 }
1632 else
1633 {
1634 sprintf(strtmp[1], "mcc=%s;", mcc);
1635 }
1636 if (mnc == NULL)
1637 {
1638 sprintf(strtmp[2], "");
1639 }
1640 else
1641 {
1642 sprintf(strtmp[2], "mnc=%s;", mnc);
1643 }
1644 if (apn == NULL)
1645 {
1646 sprintf(strtmp[3], "");
1647 }
1648 else
1649 {
1650 sprintf(strtmp[3], "apn=%s;", apn);
1651 }
1652 if (apntype == NULL)
1653 {
1654 sprintf(strtmp[4], "");
1655 }
1656 else
1657 {
1658 sprintf(strtmp[4], "apntype=%s;", apntype);
1659 }
1660 if (user == NULL)
1661 {
1662 sprintf(strtmp[5], "");
1663 }
1664 else
1665 {
1666 sprintf(strtmp[5], "user=%s;", user);
1667 }
1668 if (password == NULL)
1669 {
1670 sprintf(strtmp[6], "");
1671 }
1672 else
1673 {
1674 sprintf(strtmp[6], "password=%s;", password);
1675 }
1676 if (normalprotocol == NULL)
1677 {
1678 sprintf(strtmp[7], "");
1679 }
1680 else
1681 {
1682 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1683 }
1684 if (roamingprotocol == NULL)
1685 {
1686 sprintf(strtmp[8], "");
1687 }
1688 else
1689 {
1690 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1691 }
1692 if (carrier == NULL)
1693 {
1694 sprintf(strtmp[9], "");
1695 }
1696 else
1697 {
1698 sprintf(strtmp[9], "carrier=%s;", carrier);
1699 }
1700 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]);
1701 return 0;
1702}
1703
rjw20006d12022-04-21 16:29:04 +08001704static char *lynqStrdupReadString(Parcel &p)
1705{
1706 size_t stringlen;
1707 const char16_t *s16;
1708
1709 s16 = p.readString16Inplace(&stringlen);
1710 return strndup16to8(s16, stringlen);
1711}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001712int get_imsi()
1713{
Hong_Liu25edfe72023-06-16 01:13:42 -07001714 Parcel *p =NULL;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001715 lynq_client_t client;
1716 int resp_type = -1;
1717 int token;
1718 int request = -1;
1719 int slot_id = -1;
1720 int error = -1;
1721 int version =0;
1722 int num = 0;
1723 char *temp_char = NULL;
1724 char mccmnc[32] = {0};
1725 char mccmnckey[64] = {0};
Hong_Liu25edfe72023-06-16 01:13:42 -07001726 client.uToken = get_utoken();
Hong_Liu7163bbe2023-06-04 03:03:44 -07001727 client.request = 11;//RIL_REQUEST_GET_IMSI 11
1728 client.paramLen = 0;
1729 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1730 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1731 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1732 if(send_request(lynq_client_sockfd,&client)==-1)
1733 {
1734 LYERRLOG("send request fail");
1735 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001736 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001737 return -1;
1738 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001739 //get_response(lynq_client_sockfd,p);
1740 error = wait_response(lynq_client_sockfd,p,client.uToken);
1741 if(error!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001742 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001743 LYERRLOG("wait_response fail,ret:%d",error);
1744 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001745 return error;
1746 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001747 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1748 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001749 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001750 LYERRLOG("JumpHeader fail");
Hong_Liu7163bbe2023-06-04 03:03:44 -07001751 return -1;
1752 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001753 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1754 if(error == 0)
1755 {
1756 char * test = strdupReadString_p(p);
1757 memcpy(mccmnc, test,5);
1758 mccmnc[5]='\0';
1759 free(test);
1760 sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
1761 system(mccmnckey);
1762 system("uci commit");
1763 }
1764 free_parcel(p);
1765 return error;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001766}
rjw20006d12022-04-21 16:29:04 +08001767int 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)
1768{
1769 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1770 {
1771 LYERRLOG("There are no valid parameters");
1772 return -1;
1773 }
1774 lynq_client_t client;
1775 char argc[512];
Hong_Liu7163bbe2023-06-04 03:03:44 -07001776 int res = -1;
rjw20006d12022-04-21 16:29:04 +08001777 if (cmd == 0) // insert apn db
1778 {
rjw61fcae32022-08-18 14:03:39 +08001779 res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001780 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001781 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1782 client.paramLen = 2;
1783 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1784 sprintf(client.param, "%d %s", cmd, argc);
1785 }
rjw61fcae32022-08-18 14:03:39 +08001786 else if (cmd == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001787 {
1788 if (NULL == id)
1789 {
1790 LYERRLOG("id is NULL!!!please input id: ");
1791 }
1792 sprintf(argc, "id=%s", id);
Hong_Liu25edfe72023-06-16 01:13:42 -07001793 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001794 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1795 client.paramLen = 2;
1796 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1797 sprintf(client.param, "%d %s", cmd, argc);
1798 }
rjw61fcae32022-08-18 14:03:39 +08001799 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001800 {
rjwaf4b1612022-06-13 17:26:01 +08001801 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001802 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001803 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1804 client.paramLen = 2;
1805 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1806 sprintf(client.param, "%d %s", cmd, argc);
1807 }
rjw61fcae32022-08-18 14:03:39 +08001808 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001809 {
1810 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001811 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001812 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1813 client.paramLen = 2;
1814 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1815 sprintf(client.param, "%d %s", cmd, argc);
1816 }
1817 else
1818 {
1819 LYERRLOG("incoming command is invalid");
1820 return -1;
1821 }
1822 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001823 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001824 if(send_request(lynq_client_sockfd,&client)==-1)
1825 {
1826 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001827 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001828 return -1;
1829 }
rjwed00d042022-05-25 09:18:16 +08001830 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001831 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001832 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001833 LYINFLOG(">>>>>output info:%s",out);
1834 return 0;
1835}
1836
1837int lynq_reset_apn(char *result)
1838{
rjw20006d12022-04-21 16:29:04 +08001839 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001840 if (NULL == result)
1841 {
1842 LYERRLOG("incoming paramters error");
1843 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001844 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001845 client.request = 2000 + 194;
1846 client.paramLen = 0;
1847 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1848 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001849 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001850 if (send_request(lynq_client_sockfd, &client) == -1)
1851 {
1852 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001853 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001854 return -1;
1855 }
rjwed00d042022-05-25 09:18:16 +08001856 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001857 waitApnResult();
1858 strcpy(result, g_lynq_apn_result);
1859 LYINFLOG(">>>>>result:%s",result);
1860 return 0;
1861}
1862
rjw3bcbbf12022-04-22 16:47:18 +08001863/*Typethree add for T800 platform 2022/04/21 end*/
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07001864static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) {
1865 FILE *fp;
1866 //printf("to exec cmd:%s\n", str_cmd);
1867 if((fp=popen(str_cmd,"r"))==NULL)
1868 {
1869 perror("popen error!");
1870 return -1;
1871 }
1872 if((fread(str_cmd_ret,max_len,1,fp))<0)
1873 {
1874 perror("fread fail!");
1875 fclose(fp);
1876 return -1;
1877 }
1878 fclose(fp);
1879 return 0;
1880}
1881int check_apn_status()
1882{
1883 LYINFLOG("check_apn_status enter");
1884 int ret = -1;
1885 char cmd_ret[8] ={0};//get mccmnc
1886 const char *cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc0";
1887 const char *empty_str = ":empty";
1888 ret = exec_cmd(cmd,cmd_ret,8);
1889 if(ret==0)
1890 {
1891 if(strlen(cmd_ret)==0)
1892 {
1893 LYERRLOG("not have mccmnc config in uci ram");
1894 return 1;
1895 }
1896 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
1897 {
1898 LYERRLOG("mccmnc is empty");
1899 return 2;
1900 }
1901 LYINFLOG("mccmnc is %s",cmd_ret);
1902 return 0;
1903 }
1904 else
1905 {
1906 LYERRLOG("exec cmd fail");
1907 return -1;
1908 }
1909 return 0;
1910}
1911int radio_switch(int status)
1912{
1913 Parcel *p =NULL;
1914 lynq_client_t client;
1915 int resp_type = -1;
1916 int token;
1917 int request = -1;
1918 int slot_id = -1;
1919 int error = -1;
1920 int version =0;
1921 int num = 0;
1922 char *temp_char = NULL;
1923 char mccmnc[32] = {0};
1924 char mccmnckey[64] = {0};
1925 client.uToken = get_utoken();
1926 client.request = 59;//RIL_REQUEST_OEM_HOOK_RAW 59
1927 client.paramLen = 1;
1928 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1929 sprintf(client.param,"AT+CFUN=%d",status);
1930 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1931 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1932 if(send_request(lynq_client_sockfd,&client)==-1)
1933 {
1934 LYERRLOG("send request fail");
1935 perror("[LYNQ_DATA] send request fail:");
1936 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1937 return -1;
1938 }
1939 //get_response(lynq_client_sockfd,p);
1940 error = wait_response(lynq_client_sockfd,p,client.uToken);
1941 if(error!=0)
1942 {
1943 LYERRLOG("wait_response fail,ret:%d",error);
1944 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1945 return error;
1946 }
1947 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1948 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
1949 {
1950 LYERRLOG("JumpHeader fail");
1951 return -1;
1952 }
1953 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1954 free_parcel(p);
1955 return error;
1956}