blob: facd0fe2f0ebcccd461810abc839175840496aef [file] [log] [blame]
lhf81a46f2022-02-13 23:57:37 -08001#include <stdio.h>
2#include <sys/types.h>
3#include <sys/socket.h>
4#include <arpa/inet.h>
5#include <fcntl.h>
6#include <string.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <binder/Parcel.h>
10#include <log/log.h>
11#include "lynq_data.h"
12#include <cutils/jstring.h>
13#include <pthread.h>
14#include "liblog/lynq_deflog.h"
15#include <sys/time.h>
rjw0cdacbc2022-06-22 10:51:07 +080016#include <include/lynq_uci.h>
rjw747deea2022-07-01 18:25:30 +080017#include <errno.h>
rjw7ee7bb42023-01-18 11:34:28 +080018#include <vector>
19#include "lynq_data_urc.h"
20
lhf81a46f2022-02-13 23:57:37 -080021#define LYNQ_SERVICE_PORT 8088
lh8d290112023-10-22 20:53:06 -070022#define LYNQ_RIL_FWK_IP "127.0.0.1"
23
lhf81a46f2022-02-13 23:57:37 -080024#define LYNQ_REC_BUF 8192
25#define LYNQ_REQUEST_PARAM_BUF 8192
26#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
27#define USER_LOG_TAG "LYNQ_DATA"
28
rjw0cdacbc2022-06-22 10:51:07 +080029#define LYNQ_DATA_UCI_BUF 258
Hong_Liu25edfe72023-06-16 01:13:42 -070030#define LYNQ_DATA_TIME_OUT 1000*120
xy.hef5d74f12023-10-23 06:48:52 -070031#define TELEPHONY_RESTART 10
Hong_Liu7163bbe2023-06-04 03:03:44 -070032
rjw61fcae32022-08-18 14:03:39 +080033
lhf81a46f2022-02-13 23:57:37 -080034using ::android::Parcel;
35typedef struct{
36 int uToken;
37 int request;
38 int paramLen;
39 char param[LYNQ_REQUEST_PARAM_BUF];
40}lynq_client_t;
lh13586612022-01-11 21:58:58 -080041typedef enum{
42 LYNQ_E_CARDSTATE_ERROR=8000,
43 /* The voice service state is out of service*/
44 LYNQ_E_STATE_OUT_OF_SERVICE=8001,
45 /* The voice service state is EMERGENCY_ONLY*/
46 LYNQ_E_STATE_EMERGENCY_ONLY=8002,
47 /* The radio power is power off*/
48 LYNQ_E_STATE_POWER_OFF=8003,
49 LYNQ_E_TIME_OUT=8004,
50 /*create or open sms DB fail */
51 LYNQ_E_SMS_DB_FAIL=8005,
52 /*Failed to execute sql statement*/
53 LYNQ_E_SMS_SQL_FAIL = 8006,
54 LYNQ_E_SMS_NOT_FIND = 8007,
Hong_Liu25edfe72023-06-16 01:13:42 -070055 LYNQ_E_GET_RESP_FAIL = 8008,
56 LYNQ_E_NOT_THIS_APN = 8087,
57 LYNQ_E_NOT_ANY_APN = 8088,
58 LYNQ_E_MD_NOT_READY = 8089,
lh13586612022-01-11 21:58:58 -080059 /* The logic conflict*/
60 LYNQ_E_CONFLICT=9000,
61 /*Null anomaly*/
62 LYNQ_E_NULL_ANONALY=9001
lhf81a46f2022-02-13 23:57:37 -080063}LYNQ_E;
64
65int lynq_client_sockfd = 0;
66int Global_uToken = 0;
Hong_Liu7e1b85e2023-05-16 05:51:57 -070067struct sockaddr_in lynq_data_socket_server_addr;
68int lynq_data_socket_server_addr_len;
rjw7ee7bb42023-01-18 11:34:28 +080069
lhf81a46f2022-02-13 23:57:37 -080070int lynq_data_call_change_id = -1;
xy.hef5d74f12023-10-23 06:48:52 -070071int lynq_telephony_restart_g = 0;
lhf81a46f2022-02-13 23:57:37 -080072pthread_t lynq_data_tid =-1;
73static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
74static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080075
Hong_Liu25edfe72023-06-16 01:13:42 -070076static pthread_mutex_t s_data_call_deactived_mutex = PTHREAD_MUTEX_INITIALIZER;
77static pthread_cond_t s_data_call_deactived_cond = PTHREAD_COND_INITIALIZER;
78
79
rjw20006d12022-04-21 16:29:04 +080080static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
81static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
rjw7ee7bb42023-01-18 11:34:28 +080082static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
83static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER;
rjwed00d042022-05-25 09:18:16 +080084/**g_lynq_data_sendto_mutex
85* @brief mark data send request mutex
86*/
87static pthread_mutex_t g_lynq_data_sendto_mutex;
rjwf9ec3832023-04-12 10:59:15 +080088/*This value data the state of the wait*/
rjwc3d6e582023-03-28 17:19:11 +080089static int data_waiting_status = 0;
rjwf9ec3832023-04-12 10:59:15 +080090/*The value indicates that 8085 error occurs in data*/
rjwc63abb42023-03-31 18:22:42 +080091static int data_invaild_error = 0;
rjwf9ec3832023-04-12 10:59:15 +080092/*This value ensure the data call timing is correct*/
93static int data_timelimit = 0;
rjwc63abb42023-03-31 18:22:42 +080094
rjw22947c22022-03-15 09:21:29 +080095/**g_lynq_data_init_flag
96* @brief mark data initialization state
97* 0:deinit status
98* 1:init state
99*/
100static int g_lynq_data_init_flag = 0;
rjw20006d12022-04-21 16:29:04 +0800101/**g_lynq_apn_result
102* @brief temp of apn result info
103*/
104char g_lynq_apn_result[1024] = {};
rjw747deea2022-07-01 18:25:30 +0800105
rjw7ee7bb42023-01-18 11:34:28 +0800106static std::vector<int> s_data_urc_wait_list;
107
rjw20006d12022-04-21 16:29:04 +0800108typedef struct
109{
lhf81a46f2022-02-13 23:57:37 -0800110 char apn[LYNQ_APN_MAX_LEN];
111 char apnType[LYNQ_APN_TYPE_MAX_LEN];
112 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
113 int hasUsed;
114 int hasTimeout;
Hong_Liudc46d412023-05-18 13:36:26 -0700115 int status;
116 char statusApnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800117}lynq_apn_t;
118lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {};
119lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
120int lynq_data_call = 0;
lhf81a46f2022-02-13 23:57:37 -0800121
xy.hef5d74f12023-10-23 06:48:52 -0700122int radio_switch(int status);
123
lhf81a46f2022-02-13 23:57:37 -0800124int getLynqApnID(char apnType[])
125{
126 int ret = 0;
rjwc63abb42023-03-31 18:22:42 +0800127 int len = 0;
lhf81a46f2022-02-13 23:57:37 -0800128 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
129 {
Hong_Liudc46d412023-05-18 13:36:26 -0700130 len = strlen(apnType);
Hong_Liu6149f182023-05-12 02:15:14 -0700131 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 +0800132 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
lh13586612022-01-11 21:58:58 -0800133 {
lhf81a46f2022-02-13 23:57:37 -0800134 return ret;
135 }
136 }
137 return -1;
138}
rjw7ee7bb42023-01-18 11:34:28 +0800139
Hong_Liudc46d412023-05-18 13:36:26 -0700140int getDeactApnID(char apnType[])
141{
142 int ret = 0;
143 int len = 0;
144 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
145 {
146 len = strlen(apnType);
147 LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len);
148 if(strncmp(lynq_apn_table[ret].statusApnType,apnType,len)==0)
149 {
150 return ret;
151 }
152 }
153 return -1;
154}
155
lhf81a46f2022-02-13 23:57:37 -0800156void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[])
157{
158 LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName);
159 if(apn_table==NULL)
160 {
161 LYERRLOG("apn_table is null");
162 return;
163 }
164 memcpy(apn_table->apn,apn,strlen(apn)+1);
165 memcpy(apn_table->apnType,apntype,strlen(apntype)+1);
166 memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1);
167 apn_table->hasTimeout = 0;
168 apn_table->hasUsed = 1;
169 return;
170}
rjw7ee7bb42023-01-18 11:34:28 +0800171
lhf81a46f2022-02-13 23:57:37 -0800172void cleanOnceApnTable(int apnId)
173{
Hong_Liudc46d412023-05-18 13:36:26 -0700174 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
lhf81a46f2022-02-13 23:57:37 -0800175 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
176 {
177 LYERRLOG("apn id is invalid!!!");
178 return;
179 }
180 lynq_apn_table[apnId].hasTimeout = 0;
181 lynq_apn_table[apnId].hasUsed = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700182 memcpy(lynq_apn_table[apnId].statusApnType,lynq_apn_table[apnId].apnType,strlen(lynq_apn_table[apnId].apnType));
lhf81a46f2022-02-13 23:57:37 -0800183 bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700184 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);
lhf81a46f2022-02-13 23:57:37 -0800185 bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
Hong_Liudc46d412023-05-18 13:36:26 -0700186 lynq_apn_table[apnId].status = 32;
lhf81a46f2022-02-13 23:57:37 -0800187 return;
188}
Hong_Liudc46d412023-05-18 13:36:26 -0700189void cleanDeactApn(int apnId)
190{
191 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
192 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
193 {
194 LYERRLOG("apn id is invalid!!!");
195 return;
196 }
197 lynq_apn_table[apnId].status = 0;
198 bzero(lynq_apn_table[apnId].statusApnType,LYNQ_APN_TYPE_MAX_LEN);
199}
200
201void updateDeactApn(int apnId,int pdnState)
202{
203 LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId);
204 if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1))
205 {
206 LYERRLOG("apn id is invalid!!!");
207 return;
208 }
209 lynq_apn_table[apnId].status = pdnState;
210}
211
212
lhf81a46f2022-02-13 23:57:37 -0800213int getUnusedElement()
214{
Hong_Liudc46d412023-05-18 13:36:26 -0700215 if (lynq_apn_table == NULL)
216 {
217 LYERRLOG("get UnusedElemnt apn_table is null");
218 return -1;
219 }
lhf81a46f2022-02-13 23:57:37 -0800220 for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++)
221 {
222 if(lynq_apn_table[i].hasUsed!=1)
223 {
224 return i;
225 }
226 }
rjwc63abb42023-03-31 18:22:42 +0800227 LYERRLOG("None of get unused Element");
lhf81a46f2022-02-13 23:57:37 -0800228 return -1;
229}
230int updateApn(char apnType[])
231{
232 int ret = 0;
233 ret = getUnusedElement();
Hong_Liu55668712023-05-16 21:49:17 -0700234 if(ret >= 0)
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700235 {
236 memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1);
237 lynq_apn_table[ret].hasUsed = 1;
238 }
lhf81a46f2022-02-13 23:57:37 -0800239 return ret;
240}
Hong_Liu55c62f52023-08-24 19:05:50 -0700241//@return
242//other:this apn has been used in apn table
243//-1:this apn not has been used in apn table
244int check_used_apn(char apnType[])
245{
246 LYINFLOG("check_used_apn.apnType:%s",apnType);
247 int ret = 0;
248 int len = 0;
249 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
250 {
251 len = strlen(apnType);
252 if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0)
253 {
254 LYINFLOG("check_used_apn.apnType:%s in apn table",apnType);
255 return ret;
256 }
257 }
258 return -1;
259}
260int get_handle(char apnType[])
261{
262 int call_id = 0;
263 call_id = check_used_apn(apnType);
264 if(call_id == -1)
265 {
266 call_id = updateApn(apnType);
267 }
268 LYINFLOG("handle:%d",call_id);
269 return call_id;
270}
rjw1309e232022-07-22 09:54:06 +0800271
272int handleCheck(int handle)
273{
Hong_Liu7163bbe2023-06-04 03:03:44 -0700274 if ((handle >= 0) && (handle <= 6))
rjw1309e232022-07-22 09:54:06 +0800275 {
Hong_Liu7163bbe2023-06-04 03:03:44 -0700276 if (lynq_apn_table[handle].hasUsed == 1)
277 {
278 return 0;
279 }
rjw1309e232022-07-22 09:54:06 +0800280 return -1;
281 }
Hong_Liu7163bbe2023-06-04 03:03:44 -0700282 return -1;
rjw1309e232022-07-22 09:54:06 +0800283}
rjw20006d12022-04-21 16:29:04 +0800284int waitApnResult()
285{
286 int ret = 0;
287 LYINFLOG("start wait apn result!!!");
288 int sec = 0;
289 int usec = 0;
290 struct timeval now;
291 struct timespec timeout;
292 gettimeofday(&now, NULL);
293 sec = 20000 / 1000;
294 usec = 20000 % 1000;
295 timeout.tv_sec = now.tv_sec + sec;
296 timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
297 pthread_mutex_lock(&s_lynq_apn_change_mutex);
298 ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
299 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
300 return ret;
301}
302
303void sendSignalApnChange()
304{
305 LYINFLOG("start send Signal Apn Change");
306 pthread_mutex_lock(&s_lynq_apn_change_mutex);
307 pthread_cond_signal(&s_lynq_apn_change_cond);
308 pthread_mutex_unlock(&s_lynq_apn_change_mutex);
309 return;
310}
lhf81a46f2022-02-13 23:57:37 -0800311
312int waitPdnChange()
313{
314 int ret = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800315 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
316 ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex);
317 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800318 return ret;
319}
320int waitDataCallstateChange(int mtime)
321{
322 int ret = 0;
323 int sec = 0;
324 int usec = 0;
325 struct timeval now;
326 struct timespec timeout;
327 gettimeofday(&now,NULL);
328 sec = mtime/1000;
329 usec = mtime%1000;
330 timeout.tv_sec = now.tv_sec+sec;
331 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
332 pthread_mutex_lock(&s_data_call_state_change_mutex);
333 ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout);
334 pthread_mutex_unlock(&s_data_call_state_change_mutex);
335 return ret;
336}
337void sendSignalDataCallStateChange()
338{
339 pthread_mutex_lock(&s_data_call_state_change_mutex);
340 pthread_cond_signal(&s_data_call_state_change_cond);
341 pthread_mutex_unlock(&s_data_call_state_change_mutex);
342 return;
343}
Hong_Liu25edfe72023-06-16 01:13:42 -0700344int waitDeactived(int mtime)
345{
346 int ret = 0;
347 int sec = 0;
348 int usec = 0;
349 struct timeval now;
350 struct timespec timeout;
351 gettimeofday(&now,NULL);
352 sec = mtime/1000;
353 usec = mtime%1000;
354 timeout.tv_sec = now.tv_sec+sec;
355 timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
356 pthread_mutex_lock(&s_data_call_deactived_mutex);
357 ret = pthread_cond_timedwait(&s_data_call_deactived_cond,&s_data_call_deactived_mutex,&timeout);
358 pthread_mutex_unlock(&s_data_call_deactived_mutex);
359 return ret;
360}
361void sendSignalDeactvied()
362{
363 pthread_mutex_lock(&s_data_call_deactived_mutex);
364 pthread_cond_signal(&s_data_call_deactived_cond);
365 pthread_mutex_unlock(&s_data_call_deactived_mutex);
366 return;
367}
368
lhf81a46f2022-02-13 23:57:37 -0800369void sendSignalPdnChange()
370{
rjw7ee7bb42023-01-18 11:34:28 +0800371 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
372 pthread_cond_signal(&s_lynq_urc_vector_cond);
373 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800374 return;
375}
376
377int get_response(int sockfd,Parcel &p)
378{
379 int len = 0;
380 char recvline[LYNQ_REC_BUF];
381 bzero(recvline,LYNQ_REC_BUF);
382 /* receive data from server */
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700383 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
384 //len = read(sockfd, recvline, LYNQ_REC_BUF);
rjw08528682022-07-04 21:28:02 +0800385 if(len == -1)
lhf81a46f2022-02-13 23:57:37 -0800386 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700387 LYERRLOG("get_response fail,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800388 return -1;
389 }
390 if (recvline != NULL) {
391 p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
392 p.setDataPosition(0);
393 }
394 return 0;
395}
Hong_Liu25edfe72023-06-16 01:13:42 -0700396/**@brief get utoken in range 0 to 10000
397* @return utoken
398*/
399int get_utoken()
lhf81a46f2022-02-13 23:57:37 -0800400{
Hong_Liu25edfe72023-06-16 01:13:42 -0700401 return (Global_uToken++)%10000;/*0-10000*/
402}
403/**@brief wait response with expected token and write msg to parcel in some time
404* @param fd [IN]: socket fd
405* @param p [OUT]: quote the parcel,if return success need delete p.
406* @param token [IN]: the expected token for the response msg
407* @return
408* 0:success
409* other:failure
410*/
411int wait_response(int sockfd,Parcel *& p,int utoken)
412{
413 int len = 0;
414 int flag = 1;
415 int count = 0;
416 int in_utoken = -1;
417 int resp_type = -1;
418 Parcel *temp = NULL;
419 char recvline[LYNQ_REC_BUF];
420 //Sometimes the socket is abnormal, causing the socket buffer to store the response of the last request.
421 //Here it does not return until the response corresponding to the request is read.
422 while(flag && (count < 20))//why?
lhf81a46f2022-02-13 23:57:37 -0800423 {
Hong_Liu25edfe72023-06-16 01:13:42 -0700424 bzero(recvline,LYNQ_REC_BUF);
425 count++;
426 LYINFLOG("wait_response,count:%d",count);
427 len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
428 if(len == -1)
429 {
430 LYERRLOG("wait_response fail,errno:%d",errno);
431 return LYNQ_E_GET_RESP_FAIL;
432 }
433 if (len != 0)
434 {
435 temp = new Parcel;
436 int i = 0;
437 while((NULL == temp) && (i < 100))
438 {
439 usleep(1000);
440 temp = new Parcel;
441 i++;
442 }
443 if((i >= 100) || (NULL == temp))
444 {
445 LYERRLOG("wait_response i:%d",i);
446 return LYNQ_E_GET_RESP_FAIL;
447 }
448 temp->setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
449 temp->setDataPosition(0);
450 temp->readInt32(&resp_type);
451 temp->readInt32(&in_utoken);
452 LYINFLOG("[%s]in_utoken:%d,utoken:%d",__FUNCTION__,in_utoken,utoken);
453 if (in_utoken != utoken)
454 {
455 delete temp;
456 temp = NULL;
457 in_utoken = 0;
458 continue;
459 }
460 temp->setDataPosition(0);
461 p = temp;
462 flag = 0;
463 return 0;
464 }
465 else
466 {
467 LYERRLOG("recvline is null,errno:%d",errno);
468 return LYNQ_E_GET_RESP_FAIL;
469 }
470 }
471 return LYNQ_E_GET_RESP_FAIL;
472}
473
474int JumpHeader(Parcel *p,int *resp_type,int *utoken,int *request,int *slot_id,int *error)
475{
476 if(NULL == p)
477 {
478 LYERRLOG("JumpHeader is null");
479 return -1;
480 }
481 if(p->dataAvail() > 0)
482 {
483 p->readInt32(resp_type);
484 p->readInt32(utoken);
485 p->readInt32(request);
486 p->readInt32(slot_id);
487 p->readInt32(error);
lhf81a46f2022-02-13 23:57:37 -0800488 return 0;
489 }
490 else
491 {
492 return -1;
493 }
494}
Hong_Liu25edfe72023-06-16 01:13:42 -0700495void free_parcel(Parcel *p)
496{
497 if(p)
498 {
499 delete p;
500 p = NULL;
501 }
502}
lhf81a46f2022-02-13 23:57:37 -0800503int send_request(int sockfd,lynq_client_t *client_tmp)
504{
505 int ret=0;
lh8d290112023-10-22 20:53:06 -0700506 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 -0800507 if(ret==-1)
508 {
lh8d290112023-10-22 20:53:06 -0700509 LYERRLOG("%s:errno code:%d",__FUNCTION__,errno);
lhf81a46f2022-02-13 23:57:37 -0800510 return -1;
511 }
512 return 0;
513}
514static char *strdupReadString(Parcel &p) {
515 size_t stringlen;
516 const char16_t *s16;
517 s16 = p.readString16Inplace(&stringlen);
518 return strndup16to8(s16, stringlen);
519}
520static char *strdupReadString_p(Parcel *p) {
521 size_t stringlen;
522 const char16_t *s16;
523 s16 = p->readString16Inplace(&stringlen);
524 return strndup16to8(s16, stringlen);
525}
526
lhf81a46f2022-02-13 23:57:37 -0800527/*Warren add for T800 platform 2021/11/19 start*/
528int lynq_socket_client_start()
529{
lh8d290112023-10-22 20:53:06 -0700530 int ret;
531 struct timeval timeOut;
532 struct sockaddr_in liblynq_data_socket;
rjw747deea2022-07-01 18:25:30 +0800533
lh8d290112023-10-22 20:53:06 -0700534 ret = 0;
rjwa59bf312022-07-05 11:50:31 +0800535 timeOut.tv_sec = 30;
rjw747deea2022-07-01 18:25:30 +0800536 timeOut.tv_usec = 0;
lh8d290112023-10-22 20:53:06 -0700537 bzero(&liblynq_data_socket, sizeof(liblynq_data_socket));
538 bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr));
539
540 //set this lib socket config
541 liblynq_data_socket.sin_family = AF_INET;
542 liblynq_data_socket.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
rjw747deea2022-07-01 18:25:30 +0800543
lh8d290112023-10-22 20:53:06 -0700544 //set ril service socket config
545 lynq_data_socket_server_addr.sin_family = AF_INET;
546 lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
547 lynq_data_socket_server_addr.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
548 lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr);
549
550 lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
551 ret = bind(lynq_client_sockfd, (struct sockaddr *)&liblynq_data_socket, sizeof(liblynq_data_socket));
552 if (-1 == ret)
553 {
554 LYERRLOG("liblynq_data_socket bind fail,errno:%d",errno);
555 return -1;
556 }
rjw747deea2022-07-01 18:25:30 +0800557 if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
558 {
lh8d290112023-10-22 20:53:06 -0700559 LYERRLOG("time out setting failed,errno:%d",errno);
lhf81a46f2022-02-13 23:57:37 -0800560 return -1;
561 }
562 return 0;
563}
rjw7ee7bb42023-01-18 11:34:28 +0800564
565bool is_support_urc(int urc_id)
lhf81a46f2022-02-13 23:57:37 -0800566{
rjw7ee7bb42023-01-18 11:34:28 +0800567 switch(urc_id)
568 {
569 case LYNQ_URC_DATA_CALL_STATUS_IND:
570
571 case LYNQ_URC_MODIFY_APNDB:
572 case LYNQ_URC_RESET_APNDB:
xy.hef5d74f12023-10-23 06:48:52 -0700573 case LYNQ_TELEPHONY_RESTART:
rjw7ee7bb42023-01-18 11:34:28 +0800574 return true;
575 default:
576 return false;
577 }
578}
579
rjwc63abb42023-03-31 18:22:42 +0800580int printf_apn_table()
581{
582 int ret = 0;
Hong_Liu6149f182023-05-12 02:15:14 -0700583 if (lynq_apn_table == NULL)
584 {
585 LYERRLOG("apn table is null");
586 return -1;
587 }
rjwc63abb42023-03-31 18:22:42 +0800588 for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++)
589 {
Hong_Liudc46d412023-05-18 13:36:26 -0700590 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 +0800591 lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \
Hong_Liudc46d412023-05-18 13:36:26 -0700592 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 +0800593 }
594 return 0;
595}
596
Hong_Liu6149f182023-05-12 02:15:14 -0700597void printf_apn_table_debug(const char *fun,int line)
598{
599 LYINFLOG("[%s][%d]apn_table msg",fun,line);
600 printf_apn_table();
601}
rjwc63abb42023-03-31 18:22:42 +0800602
rjw7ee7bb42023-01-18 11:34:28 +0800603void urc_msg_process(Parcel *p)
604{
605 int len;
606 int resp_type;
607 int urcid;
608 int slot_id;
rjwf9ec3832023-04-12 10:59:15 +0800609 int check_count = 0;
Hong_Liudc46d412023-05-18 13:36:26 -0700610 static int apnId=-1;
rjw7ee7bb42023-01-18 11:34:28 +0800611
612 int pdnState = 0;
lhf81a46f2022-02-13 23:57:37 -0800613 char apn[LYNQ_APN_MAX_LEN];
614 char apnType[LYNQ_APN_TYPE_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800615 char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
lhf81a46f2022-02-13 23:57:37 -0800616 char *urc_msg = NULL;
rjw7ee7bb42023-01-18 11:34:28 +0800617
618 int size = p->dataSize();
619 p->readInt32(&resp_type);
620 p->readInt32(&urcid);
621 p->readInt32(&slot_id);
622 LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size);
623 switch(urcid)
lhf81a46f2022-02-13 23:57:37 -0800624 {
rjw7ee7bb42023-01-18 11:34:28 +0800625 case LYNQ_URC_DATA_CALL_STATUS_IND:
626 p->readInt32(&pdnState);
627 bzero(apn,LYNQ_APN_MAX_LEN);
628 bzero(apnType,LYNQ_APN_TYPE_MAX_LEN);
629 bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
630 if(pdnState!=4)//PDN_DISCONNECTED
lhf81a46f2022-02-13 23:57:37 -0800631 {
rjw20006d12022-04-21 16:29:04 +0800632 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800633 int len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700634 if((len < LYNQ_APN_MAX_LEN-1) && (len > 0))
rjw20006d12022-04-21 16:29:04 +0800635 {
rjw7ee7bb42023-01-18 11:34:28 +0800636 memcpy(apn,urc_msg,len+1);
rjw20006d12022-04-21 16:29:04 +0800637 }
Hong_Liu6149f182023-05-12 02:15:14 -0700638 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800639 urc_msg = strdupReadString_p(p);
640 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700641 if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800642 {
643 memcpy(apnType,urc_msg,len+1);
644 }
Hong_Liu6149f182023-05-12 02:15:14 -0700645 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800646 urc_msg = strdupReadString_p(p);
647 len = strlen(urc_msg);
Hong_Liu6149f182023-05-12 02:15:14 -0700648 if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0))
rjw7ee7bb42023-01-18 11:34:28 +0800649 {
650 memcpy(ifaceName,urc_msg,strlen(urc_msg)+1);
651 }
Hong_Liu6149f182023-05-12 02:15:14 -0700652 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800653 //sendSignalDataCallStateChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700654 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800655 if(apnId >= 0)
656 {
Hong_Liudc46d412023-05-18 13:36:26 -0700657 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800658 if(lynq_apn_table[apnId].hasTimeout==1)
659 {
rjwc63abb42023-03-31 18:22:42 +0800660 /*whether timeout?,real or not,*/
661 printf_apn_table();
rjw7ee7bb42023-01-18 11:34:28 +0800662 LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn);
rjw3938f262023-03-08 16:09:28 +0800663 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 +0800664 {
665 LYERRLOG("deactive this time out APN");
666 lynq_deactive_data_call(&apnId);
667 }
rjwc63abb42023-03-31 18:22:42 +0800668 else
rjw7ee7bb42023-01-18 11:34:28 +0800669 {
rjwc63abb42023-03-31 18:22:42 +0800670 /*if apn lose,update apn and deactive all apn*/
671 LYERRLOG("this table is invalid update APN table");
rjw7ee7bb42023-01-18 11:34:28 +0800672 }
673 break;
674 }
rjwacdb2152023-02-07 14:12:49 +0800675 updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName);
Hong_Liu6149f182023-05-12 02:15:14 -0700676 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800677 }
678 /*To be completed*/
rjw20006d12022-04-21 16:29:04 +0800679 else
680 {
Hong_Liu6149f182023-05-12 02:15:14 -0700681 data_invaild_error = 1;
Hong_Liudc46d412023-05-18 13:36:26 -0700682 printf_apn_table_debug(__FUNCTION__,__LINE__);
683 apnId = getDeactApnID(apnType);
684 if(apnId < 0)
685 {
686 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
687 break;
688 }
689 LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId);
690 updateDeactApn(apnId,pdnState);
691 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800692 }
rjw7ee7bb42023-01-18 11:34:28 +0800693 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
694 s_data_urc_wait_list.push_back(apnId);
695 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
696 lynq_data_call_change_id = apnId;
rjwc3d6e582023-03-28 17:19:11 +0800697 sendSignalPdnChange();
rjw7ee7bb42023-01-18 11:34:28 +0800698 LYDBGLOG("data call state:%d",lynq_data_call);
699 if(lynq_data_call==1)
700 {
rjwf9ec3832023-04-12 10:59:15 +0800701 while (data_timelimit == 0)
702 {
703 LYINFLOG("client not ready to wait");
704 for (check_count = 0;check_count < 500;check_count++)
705 {
706 /*wait 10ms*/
707 usleep(10*1000);
708 }
709 LYERRLOG("client still without res");
710 break;
711 }
rjw7ee7bb42023-01-18 11:34:28 +0800712 sendSignalDataCallStateChange();
713 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800714 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800715 }
Hong_Liu6149f182023-05-12 02:15:14 -0700716 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw20006d12022-04-21 16:29:04 +0800717 }
rjw7ee7bb42023-01-18 11:34:28 +0800718 else
rjw20006d12022-04-21 16:29:04 +0800719 {
rjw7ee7bb42023-01-18 11:34:28 +0800720 urc_msg = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -0700721 free(urc_msg);
722 urc_msg = strdupReadString_p(p);
rjw7ee7bb42023-01-18 11:34:28 +0800723 len = strlen(urc_msg);
724 if(len < LYNQ_APN_TYPE_MAX_LEN-1)
725 {
726 memcpy(apnType,urc_msg,len+1);
727 }
Hong_Liu6149f182023-05-12 02:15:14 -0700728 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800729 LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType);
Hong_Liudc46d412023-05-18 13:36:26 -0700730 apnId = getLynqApnID(apnType);
rjw7ee7bb42023-01-18 11:34:28 +0800731 if(apnId >= 0)
732 {
Hong_Liu8d77acf2023-08-30 02:11:09 -0700733 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 -0700734 lynq_data_call_change_id = apnId;
735 //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
736 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
737 s_data_urc_wait_list.push_back(apnId);
738 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
739 sendSignalPdnChange();
740 }
741 else
742 {
743 apnId = getDeactApnID(apnType);
744 if(apnId < 0)
745 {
746 LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId);
747 break;
748 }
Hong_Liu8d77acf2023-08-30 02:11:09 -0700749 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 -0700750 cleanDeactApn(apnId);
rjw7ee7bb42023-01-18 11:34:28 +0800751 lynq_data_call_change_id = apnId;
752 bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean
rjw3938f262023-03-08 16:09:28 +0800753 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
754 s_data_urc_wait_list.push_back(apnId);
755 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -0700756 sendSignalDeactvied();
rjwc3d6e582023-03-28 17:19:11 +0800757 sendSignalPdnChange();
Hong_Liudc46d412023-05-18 13:36:26 -0700758 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800759 }
rjw7ee7bb42023-01-18 11:34:28 +0800760 LYDBGLOG("data call state:%d",lynq_data_call);
761 if(lynq_data_call==1)
762 {
rjwf9ec3832023-04-12 10:59:15 +0800763 while (data_timelimit == 0)
764 {
765 LYINFLOG("client not ready to wait");
766 for (check_count = 0;check_count < 500;check_count++)
767 {
768 /*wait 10ms*/
769 usleep(10*1000);
770 }
771 LYERRLOG("client still without res");
772 break;
773 }
rjw7ee7bb42023-01-18 11:34:28 +0800774 sendSignalDataCallStateChange();
775 lynq_data_call = 0;
rjwf9ec3832023-04-12 10:59:15 +0800776 data_timelimit = 0;
rjw7ee7bb42023-01-18 11:34:28 +0800777 }
Hong_Liu6149f182023-05-12 02:15:14 -0700778 printf_apn_table_debug(__FUNCTION__,__LINE__);
rjw7ee7bb42023-01-18 11:34:28 +0800779 }
780 break;
781 case LYNQ_URC_MODIFY_APNDB:
782 urc_msg = strdupReadString_p(p);
783 if (NULL == urc_msg)
784 {
785 LYERRLOG("error apn msg");
786 }
787 else
788 {
789 bzero(g_lynq_apn_result, 1024);
790 strcpy(g_lynq_apn_result, urc_msg);
791 sendSignalApnChange();
792 }
Hong_Liu6149f182023-05-12 02:15:14 -0700793 free(urc_msg);
rjw7ee7bb42023-01-18 11:34:28 +0800794 break;
795 case LYNQ_URC_RESET_APNDB:
796 {
rjw20006d12022-04-21 16:29:04 +0800797 urc_msg = strdupReadString_p(p);
798 if (NULL == urc_msg)
799 {
800 LYERRLOG("error apn msg");
801 }
802 else
803 {
804 bzero(g_lynq_apn_result, 1024);
805 strcpy(g_lynq_apn_result, urc_msg);
806 sendSignalApnChange();
807 }
Hong_Liu6149f182023-05-12 02:15:14 -0700808 free(urc_msg);
rjw20006d12022-04-21 16:29:04 +0800809 }
xy.hef5d74f12023-10-23 06:48:52 -0700810 case LYNQ_TELEPHONY_RESTART:
811 {
812 if(slot_id == 0)
813 {
814 RLOGI("data has received telephony has restart");
815 RLOGI("handle set to 10");
816 lynq_telephony_restart_g = 1;
817 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
818 s_data_urc_wait_list.push_back(TELEPHONY_RESTART);
819 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
820 radio_switch(0);
821 sleep(1);
822 radio_switch(1);
823 sleep(1);
824 sendSignalPdnChange();
825 }
826 }
rjw7ee7bb42023-01-18 11:34:28 +0800827 default:
828 break;
lhf81a46f2022-02-13 23:57:37 -0800829 }
rjw7ee7bb42023-01-18 11:34:28 +0800830
lhf81a46f2022-02-13 23:57:37 -0800831}
rjw7ee7bb42023-01-18 11:34:28 +0800832
rjw7ee7bb42023-01-18 11:34:28 +0800833int create_urc_vector_signal_thread()
834{
835 int ret;
rjw7ee7bb42023-01-18 11:34:28 +0800836 pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL);
rjw7ee7bb42023-01-18 11:34:28 +0800837 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
838 s_data_urc_wait_list.clear();
839 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800840 return 0;
841}
Hong_Liu25edfe72023-06-16 01:13:42 -0700842int get_imsi();
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700843int check_apn_status();
xy.hef5d74f12023-10-23 06:48:52 -0700844
lhf81a46f2022-02-13 23:57:37 -0800845int lynq_init_data(int uToken)
846{
rjw22947c22022-03-15 09:21:29 +0800847 if (g_lynq_data_init_flag == 1)
848 {
849 LYERRLOG("init twice is not allowed");
850 return -1;
851 }
852 g_lynq_data_init_flag = 1;
lhf81a46f2022-02-13 23:57:37 -0800853 int result = 0;
854 Global_uToken = uToken;
lhf81a46f2022-02-13 23:57:37 -0800855 LYLOGSET(LOG_INFO);
856 LYLOGEINIT(USER_LOG_TAG);
857 result = lynq_socket_client_start();
rjwed00d042022-05-25 09:18:16 +0800858 pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
lhf81a46f2022-02-13 23:57:37 -0800859 if(result!=0)
860 {
861 LYERRLOG("init socket client fail!!!");
862 return -1;
863 }
rjw7ee7bb42023-01-18 11:34:28 +0800864 result = lynq_init_data_urc_thread();
865 if(result!=0)
866 {
867 LYERRLOG("init socket urc fail!!!");
868 return -1;
869 }
870
871 result = create_urc_vector_signal_thread();
lhf81a46f2022-02-13 23:57:37 -0800872 if(result!=0)
873 {
874 LYERRLOG("init socket urc fail!!!");
875 return -1;
876 }
877 memset(lynq_apn_table,0,sizeof(lynq_apn_table));
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700878 LYINFLOG("[%s] radio on/off solution 20230724",__FUNCTION__);
Hong_Liu25edfe72023-06-16 01:13:42 -0700879 int count = 0;
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700880 while(count < 2)//try recover the network within 10s.
881 {
882 result = check_apn_status();
883 if(result==0)
884 {
885 break;
886 }
887 radio_switch(0);
888 sleep(1);
889 radio_switch(1);
890 sleep(3);
891 count++;
892 }
893 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
894 if(result!=0)
895 {
896 LYDBGLOG("lynq init call fail!!!");
897 return LYNQ_E_MD_NOT_READY;//
898 }
899 /* old
Hong_Liu25edfe72023-06-16 01:13:42 -0700900 while(count < 10)
901 {
902 result = get_imsi();
903 if(result==0)
904 {
905 break;
906 }
907 sleep(1);
908 count++;
909 }
910 LYINFLOG("[%s] count is %d",__FUNCTION__,count);
911 if(result!=0)
912 {
913 LYDBGLOG("lynq init call fail!!!");
914 return LYNQ_E_MD_NOT_READY;//
915 }
Hong_Liu7d9ac8d2023-07-24 00:40:31 -0700916 */
lhf81a46f2022-02-13 23:57:37 -0800917 LYDBGLOG("lynq init call success!!!");
918 return 0;
919
920}
921int lynq_deinit_data()
922{
923 int ret = -1;
rjw22947c22022-03-15 09:21:29 +0800924 if (g_lynq_data_init_flag == 0)
925 {
926 LYERRLOG("deinit twice is not allowed");
927 return ret;
928 }
929 g_lynq_data_init_flag = 0;
lhf81a46f2022-02-13 23:57:37 -0800930 for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++)
931 {
932 if(strlen(lynq_apn_table[i].apnType)!=0)
933 {
934 lynq_deactive_data_call(&i);
935 }
936 }
937 if(lynq_client_sockfd>0)
938 {
939 close(lynq_client_sockfd);
940 }
rjw7ee7bb42023-01-18 11:34:28 +0800941 ret = lynq_deinit_data_urc_thread();
rjweb65a2f2023-02-01 16:43:23 +0800942 if (ret != 0)
rjw22947c22022-03-15 09:21:29 +0800943 {
rjw7ee7bb42023-01-18 11:34:28 +0800944 LYERRLOG("lynq_deinit_data_urc_thread fail");
945 return ret;
rjw22947c22022-03-15 09:21:29 +0800946 }
rjwc3d6e582023-03-28 17:19:11 +0800947 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
948 s_data_urc_wait_list.clear();
949 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
lhf81a46f2022-02-13 23:57:37 -0800950 return 0;
951}
952int lynq_setup_data_call(int *handle)
953{
Hong_Liue54db8c2023-04-21 02:37:23 -0700954 int error = -1;
955 #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman.
956 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
Hong_Liue9879152023-04-25 20:40:26 -0700957 error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
Hong_Liue54db8c2023-04-21 02:37:23 -0700958 #else
Hong_Liu25edfe72023-06-16 01:13:42 -0700959 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -0800960 lynq_client_t client;
961 int resp_type = -1;
962 int request = -1;
963 int slot_id = -1;
lhf81a46f2022-02-13 23:57:37 -0800964 int lynq_data_call_id = 0;
965 if(handle==NULL)
966 {
967 LYERRLOG("handle is null!!!");
968 return LYNQ_E_NULL_ANONALY;
969 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700970 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -0800971 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
972 client.paramLen = 0;
973 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
974 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -0700975 lynq_data_call_id = get_handle("default");
rjwc63abb42023-03-31 18:22:42 +0800976 if (lynq_data_call_id < 0)
977 {
978 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700979 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +0800980 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700981 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect.
982 //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate.
rjw733b9832023-04-03 10:20:08 +0800983 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +0800984 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -0800985 if(send_request(lynq_client_sockfd,&client)==-1)
986 {
987 LYERRLOG("send request fail");
988 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -0700989 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -0700990 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -0800991 }
Hong_Liu25edfe72023-06-16 01:13:42 -0700992 //get_response(lynq_client_sockfd,p);
993 error = wait_response(lynq_client_sockfd,p,client.uToken);
994 if(error!=0)
995 {
996 LYERRLOG("wait_response fail,ret:%d",error);
997 printf_apn_table_debug(__FUNCTION__,__LINE__);
998 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
999 return error;
1000 }
rjwed00d042022-05-25 09:18:16 +08001001 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liuaa7f4b32023-07-19 07:51:25 -07001002 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
Hong_Liu25edfe72023-06-16 01:13:42 -07001003 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001004 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
lhf81a46f2022-02-13 23:57:37 -08001005 if(error==0)
1006 {
rjwf9ec3832023-04-12 10:59:15 +08001007 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001008 if (waitDataCallstateChange(LYNQ_DATA_TIME_OUT) == ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001009 {
1010 error = LYNQ_E_TIME_OUT;
1011 LYERRLOG("timeout:wait data Call state fail!!!");
1012 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001013 if (data_invaild_error == 1)
1014 {
1015 data_invaild_error = 0;
1016 LYERRLOG("urc apn info error!!!");
1017 return 8085;
1018 }
1019 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001020 return error;
1021 }
lhf81a46f2022-02-13 23:57:37 -08001022 }
Hong_Liu6149f182023-05-12 02:15:14 -07001023 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liue54db8c2023-04-21 02:37:23 -07001024 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001025 return error;
1026}
rjw7ee7bb42023-01-18 11:34:28 +08001027
lhf81a46f2022-02-13 23:57:37 -08001028int lynq_deactive_data_call(int *handle)
1029{
Hong_Liu25edfe72023-06-16 01:13:42 -07001030 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001031 lynq_client_t client;
1032 int resp_type = -1;
1033 int request = -1;
1034 int slot_id = -1;
1035 int error = -1;
1036 int lynq_data_call_id = -1;
rjw1309e232022-07-22 09:54:06 +08001037 int ret = 0;
lhf81a46f2022-02-13 23:57:37 -08001038 if(handle==NULL)
1039 {
1040 LYERRLOG("handle is null!!!");
1041 return -1;
1042 }
rjw1309e232022-07-22 09:54:06 +08001043 ret = handleCheck(*handle);
1044 if (ret != 0)
1045 {
1046 LYERRLOG("incomming handle is invalid");
1047 return -1;
1048 }
1049 lynq_data_call_id = *handle;
Hong_Liu25edfe72023-06-16 01:13:42 -07001050 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001051 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
Hong_Liue3d35262023-05-04 00:20:12 -07001052 client.paramLen = 0;
1053 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1054 #ifdef GSW_RIL_CFG
1055 client.paramLen = 1;
1056 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1057 #else
1058 if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0)
lh13586612022-01-11 21:58:58 -08001059 {
lhf81a46f2022-02-13 23:57:37 -08001060 client.paramLen = 1;
lhf81a46f2022-02-13 23:57:37 -08001061 sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType);
1062 }
Hong_Liue3d35262023-05-04 00:20:12 -07001063 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001064 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001065 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001066 if(send_request(lynq_client_sockfd,&client)==-1)
1067 {
1068 LYERRLOG("send request fail");
1069 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001070 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001071 return -1;
1072 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001073 //get_response(lynq_client_sockfd,p);
1074 error = wait_response(lynq_client_sockfd,p,client.uToken);
1075 if(error!=0)
1076 {
1077 LYERRLOG("wait_response fail,ret:%d",error);
1078 printf_apn_table_debug(__FUNCTION__,__LINE__);
1079 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1080 return error;
1081 }
rjwed00d042022-05-25 09:18:16 +08001082 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001083 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1084 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 -08001085 cleanOnceApnTable(lynq_data_call_id);
Hong_Liu6149f182023-05-12 02:15:14 -07001086 printf_apn_table_debug(__FUNCTION__,__LINE__);
Hong_Liu25edfe72023-06-16 01:13:42 -07001087 if(error==0)
1088 {
1089 if(waitDeactived(20000)==ETIMEDOUT)
1090 {
1091 error = LYNQ_E_TIME_OUT;
1092 LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!");
1093 printf_apn_table_debug(__FUNCTION__,__LINE__);
1094 }
1095 }
1096 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001097 return error;
1098}
1099int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
1100{
Hong_Liu25edfe72023-06-16 01:13:42 -07001101 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001102 lynq_client_t client;
1103 int resp_type = -1;
1104 int request = -1;
1105 int slot_id = -1;
1106 int error = -1;
lhf81a46f2022-02-13 23:57:37 -08001107 int lynq_data_call_id = -1;
1108 char *argv[10] = {};
Hong_Liue54db8c2023-04-21 02:37:23 -07001109 #ifdef GSW_RIL_CFG
1110 LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
1111 if(handle==NULL||apnType==NULL)
1112 {
1113 LYERRLOG("handle or apntype is null!!!");
1114 return -1;
1115 }
1116 #else
lhf81a46f2022-02-13 23:57:37 -08001117 if(handle==NULL||apn==NULL||apnType==NULL)
1118 {
1119 LYERRLOG("handle ,apn or apntype is null!!!");
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001120 return LYNQ_E_NULL_ANONALY;
lhf81a46f2022-02-13 23:57:37 -08001121 }
Hong_Liue54db8c2023-04-21 02:37:23 -07001122 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001123 if(user==NULL)
1124 {
1125 argv[1] = "null";
1126 }
1127 else
1128 {
1129 argv[1] = user;
lh13586612022-01-11 21:58:58 -08001130 }
1131 if(password==NULL)
1132 {
lhf81a46f2022-02-13 23:57:37 -08001133 argv[2] = "null";
lh13586612022-01-11 21:58:58 -08001134 }
1135 else
1136 {
lhf81a46f2022-02-13 23:57:37 -08001137 argv[2] = password;
lh13586612022-01-11 21:58:58 -08001138 }
1139 if(authType==NULL)
1140 {
lhf81a46f2022-02-13 23:57:37 -08001141 argv[3] = "null";
lh13586612022-01-11 21:58:58 -08001142 }
1143 else
1144 {
lhf81a46f2022-02-13 23:57:37 -08001145 argv[3] = authType;
lh13586612022-01-11 21:58:58 -08001146 }
1147 if(normalProtocol==NULL)
1148 {
lhf81a46f2022-02-13 23:57:37 -08001149 argv[4] = "null";
lh13586612022-01-11 21:58:58 -08001150 }
1151 else
1152 {
lhf81a46f2022-02-13 23:57:37 -08001153 argv[4] = normalProtocol;
lh13586612022-01-11 21:58:58 -08001154 }
1155 if(roamingProtocol==NULL)
1156 {
lhf81a46f2022-02-13 23:57:37 -08001157 argv[5] = "null";
lh13586612022-01-11 21:58:58 -08001158 }
1159 else
1160 {
lhf81a46f2022-02-13 23:57:37 -08001161 argv[5] = roamingProtocol;
1162 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001163 client.uToken = get_utoken();
lhf81a46f2022-02-13 23:57:37 -08001164 client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
1165 client.paramLen = 7;
1166 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
Hong_Liue54db8c2023-04-21 02:37:23 -07001167 #ifdef GSW_RIL_CFG
1168 if(NULL == apn)
1169 {
1170 sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1171 }
1172 else
1173 {
1174 sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]);
1175 }
1176 #else
lhf81a46f2022-02-13 23:57:37 -08001177 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 -07001178 #endif //GSW_RIL_CFG
lhf81a46f2022-02-13 23:57:37 -08001179 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
Hong_Liu55c62f52023-08-24 19:05:50 -07001180 lynq_data_call_id = get_handle(apnType);
rjwc63abb42023-03-31 18:22:42 +08001181 if (lynq_data_call_id < 0)
1182 {
1183 LYERRLOG("update apn table fail error id = %d",lynq_data_call_id);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001184 return LYNQ_E_NULL_ANONALY+1;
rjwc63abb42023-03-31 18:22:42 +08001185 }
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001186 *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16)
rjw733b9832023-04-03 10:20:08 +08001187 lynq_data_call = 1;
rjwed00d042022-05-25 09:18:16 +08001188 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
lhf81a46f2022-02-13 23:57:37 -08001189 if(send_request(lynq_client_sockfd,&client)==-1)
1190 {
1191 LYERRLOG("send request fail");
1192 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001193 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001194 return LYNQ_E_NULL_ANONALY+2;
lhf81a46f2022-02-13 23:57:37 -08001195 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001196 //get_response(lynq_client_sockfd,p);
1197 error = wait_response(lynq_client_sockfd,p,client.uToken);
1198 if(error!=0)
1199 {
1200 LYERRLOG("wait_response fail,ret:%d",error);
1201 printf_apn_table_debug(__FUNCTION__,__LINE__);
1202 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1203 return error;
1204 }
rjwed00d042022-05-25 09:18:16 +08001205 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001206 JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
1207 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1208 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001209 if(error==0)
1210 {
Hong_Liu7e1b85e2023-05-16 05:51:57 -07001211 data_timelimit = 1;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001212 if(waitDataCallstateChange(LYNQ_DATA_TIME_OUT)==ETIMEDOUT)
lhf81a46f2022-02-13 23:57:37 -08001213 {
1214 error = LYNQ_E_TIME_OUT;
1215 LYERRLOG("timeout:wait data Call state fail!!!");
1216 lynq_apn_table[lynq_data_call_id].hasTimeout = 1;
Hong_Liu6149f182023-05-12 02:15:14 -07001217 if (data_invaild_error == 1)
1218 {
1219 data_invaild_error = 0;
1220 LYERRLOG("urc apn info error!!!");
1221 return 8085;
1222 }
1223 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001224 return error;
1225 }
lhf81a46f2022-02-13 23:57:37 -08001226 }
Hong_Liu6149f182023-05-12 02:15:14 -07001227 printf_apn_table_debug(__FUNCTION__,__LINE__);
lhf81a46f2022-02-13 23:57:37 -08001228 return error;
1229}
1230/*
1231int lynq_deactive_data_call_sp(int *handle,char *apnType)
1232{
1233 Parcel p;
1234 lynq_client_t client;
1235 int resp_type = -1;
1236 int request = -1;
1237 int slot_id = -1;
1238 int error = -1;
1239 if(handle==NULL||apnType==NULL)
1240 {
1241 LYERRLOG("handle is null!!!");
1242 return -1;
1243 }
1244 client.uToken = Global_uToken;
1245 client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
1246 client.paramLen = 1;
1247 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1248 sprintf(client.param,"%s",apnType);
1249 LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1250 if(send_request(lynq_client_sockfd,&client)==-1)
1251 {
1252 LYERRLOG("send request fail");
1253 perror("[LYNQ_DATA] send request fail:");
1254 return -1;
1255 }
1256 get_response(lynq_client_sockfd,p);
rjwfa532972022-09-16 13:39:41 +08001257 JumpHeader(p,&resp_type,&request,&slot_id,&error);
lhf81a46f2022-02-13 23:57:37 -08001258 LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
1259 return error;
1260}
1261*/
1262int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
1263{
Hong_Liu25edfe72023-06-16 01:13:42 -07001264 Parcel *p = NULL;
lhf81a46f2022-02-13 23:57:37 -08001265 lynq_client_t client;
1266 int resp_type = -1;
q.huang7de1d662022-09-13 14:19:24 +08001267 int token;
Hong_Liu25edfe72023-06-16 01:13:42 -07001268 int request = -1;
lhf81a46f2022-02-13 23:57:37 -08001269 int slot_id = -1;
1270 int error = -1;
1271 int version =0;
1272 int num = 0;
lhf81a46f2022-02-13 23:57:37 -08001273 char *temp_char = NULL;
1274 if(dataCallList==NULL)
1275 {
1276 LYERRLOG("dataCallList is null!!!");
1277 return -1;
1278 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001279 client.uToken = get_utoken();;
lhf81a46f2022-02-13 23:57:37 -08001280 client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
1281 client.paramLen = 0;
1282 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1283 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
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);
lhf81a46f2022-02-13 23:57:37 -08001290 return -1;
1291 }
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 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1298 return error;
1299 }
rjwed00d042022-05-25 09:18:16 +08001300 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu25edfe72023-06-16 01:13:42 -07001301 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
rjwfa532972022-09-16 13:39:41 +08001302 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001303 LYERRLOG("JumpHeader fail");
rjwfa532972022-09-16 13:39:41 +08001304 return -1;
1305 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001306 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1307 p->readInt32(&version);
lhf81a46f2022-02-13 23:57:37 -08001308 if(version==11)
1309 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001310 p->readInt32(&num);
lhf81a46f2022-02-13 23:57:37 -08001311 *realNum = num;
1312 for (int i = 0; i < num; i++)
1313 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001314 p->readInt32(&dataCallList[i].status);
1315 p->readInt32(&dataCallList[i].suggestedRetryTime);
1316 p->readInt32(&dataCallList[i].cid);
1317 p->readInt32(&dataCallList[i].active);
1318 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001319 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1320 if(temp_char)
1321 {
1322 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
1323 free(temp_char);
1324 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001325 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001326 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1327 if(temp_char)
1328 {
1329 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
1330 free(temp_char);
1331 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001332 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001333 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1334 if(temp_char)
1335 {
1336 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
1337 free(temp_char);
1338 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001339 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001340 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1341 if(temp_char)
1342 {
1343 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
1344 free(temp_char);
1345 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001346 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001347 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1348 if(temp_char)
1349 {
1350 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
1351 free(temp_char);
1352 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001353 temp_char = strdupReadString_p(p);
Hong_Liu6149f182023-05-12 02:15:14 -07001354 LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
1355 if(temp_char)
1356 {
1357 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
1358 free(temp_char);
1359 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001360 p->readInt32(&dataCallList[i].mtu);
lhf81a46f2022-02-13 23:57:37 -08001361 }
1362 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001363 free_parcel(p);
lhf81a46f2022-02-13 23:57:37 -08001364 return error;
1365}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001366
1367int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
1368{
1369 LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
1370 if((handle < 0) || (handle > 6) || (NULL == apn_msg))
1371 {
1372 LYERRLOG("handle value error,or apn_msg is null");
1373 return LYNQ_E_NULL_ANONALY;
1374 }
1375 apn_msg->handle = handle;
1376 if(apn_msg->apn!=NULL)
1377 {
1378 memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
1379 }
1380 if(apn_msg->apnType!=NULL)
1381 {
1382 memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
1383 }
1384 return 0;
1385}
1386
lhf81a46f2022-02-13 23:57:37 -08001387int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
1388{
1389 lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
1390 int number = 0;
1391 int lynq_data_call_id = 0;
1392 int error = 0;
1393 lynq_data_call_id = *handle;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001394 if((handle==NULL) || (dataCallList==NULL))
lhf81a46f2022-02-13 23:57:37 -08001395 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001396 LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
lhf81a46f2022-02-13 23:57:37 -08001397 return LYNQ_E_NULL_ANONALY;
1398 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001399 if ((*handle < 0) || (*handle > 6))
rjw3938f262023-03-08 16:09:28 +08001400 {
Hong_Liu7163bbe2023-06-04 03:03:44 -07001401 LYERRLOG("[lynq_get_data_call_list] handle value error");
1402 return LYNQ_E_NULL_ANONALY;
rjw3938f262023-03-08 16:09:28 +08001403 }
Hong_Liu7163bbe2023-06-04 03:03:44 -07001404 LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001405 memset(interDataCallList,0,sizeof(interDataCallList));
1406 error = getDataCallLists(interDataCallList,&number);
1407 if(error == 0)
1408 {
1409 for(int i = 0;i < number;i++)
1410 {
1411 if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0)
1412 {
1413 dataCallList->active = interDataCallList[i].active;
1414 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime;
1415 dataCallList->cid = interDataCallList[i].cid;
1416 dataCallList->status = interDataCallList[i].status;
1417 dataCallList->mtu = interDataCallList[i].mtu;
1418 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses));
1419 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname));
1420 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses));
1421 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type));
1422 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways));
1423 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf));
1424 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses);
1425 }
1426 }
1427 }
1428 return error;
1429}
1430int lynq_wait_data_call_state_change(int *handle)
1431{
rjwc3d6e582023-03-28 17:19:11 +08001432 if (data_waiting_status == 1)
1433 {
1434 LYDBGLOG("some thread is waiting");
1435 return -3;
1436 }
1437 LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty());
1438 if (s_data_urc_wait_list.empty())
1439 {
1440 LYDBGLOG("start wait");
1441 data_waiting_status = 1;
1442 waitPdnChange();
1443 }
1444 data_waiting_status = 0;
rjw7ee7bb42023-01-18 11:34:28 +08001445 std::vector<int>::iterator iter;
rjw7ee7bb42023-01-18 11:34:28 +08001446
1447 pthread_mutex_lock(&s_lynq_urc_vector_mutex);
1448 iter = s_data_urc_wait_list.begin();
rjwc3d6e582023-03-28 17:19:11 +08001449 if (iter != s_data_urc_wait_list.end())
1450 {
1451 *handle = *iter;
1452 }
rjw7ee7bb42023-01-18 11:34:28 +08001453 s_data_urc_wait_list.erase(iter);
1454 pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
1455
Hong_Liudc46d412023-05-18 13:36:26 -07001456 LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle);
lhf81a46f2022-02-13 23:57:37 -08001457 return 0;
1458}
1459/*Warren add for T800 platform 2021/11/19 end*/
rjw20006d12022-04-21 16:29:04 +08001460
1461/*Typethree add for T800 platform 2022/04/21 start*/
rjw61fcae32022-08-18 14:03:39 +08001462
1463int 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 +08001464{
1465 char strtmp[10][32];
rjw61fcae32022-08-18 14:03:39 +08001466 if (id == NULL)
rjw0cdacbc2022-06-22 10:51:07 +08001467 {
rjw61fcae32022-08-18 14:03:39 +08001468 sprintf(strtmp[0], "id=;");
rjw0cdacbc2022-06-22 10:51:07 +08001469 }
rjw61fcae32022-08-18 14:03:39 +08001470 else
rjw0cdacbc2022-06-22 10:51:07 +08001471 {
rjw61fcae32022-08-18 14:03:39 +08001472 sprintf(strtmp[0], "id=%s;", id);
rjw0cdacbc2022-06-22 10:51:07 +08001473 }
rjw20006d12022-04-21 16:29:04 +08001474 if (mcc == NULL)
1475 {
1476 sprintf(strtmp[1], "mcc=;");
1477 }
1478 else
1479 {
1480 sprintf(strtmp[1], "mcc=%s;", mcc);
1481 }
1482 if (mnc == NULL)
1483 {
rjw61fcae32022-08-18 14:03:39 +08001484 sprintf(strtmp[2], "mnc=;");
rjw20006d12022-04-21 16:29:04 +08001485 }
1486 else
1487 {
1488 sprintf(strtmp[2], "mnc=%s;", mnc);
1489 }
1490 if (apn == NULL)
1491 {
1492 sprintf(strtmp[3], "apn=;");
1493 }
1494 else
1495 {
1496 sprintf(strtmp[3], "apn=%s;", apn);
1497 }
1498 if (apntype == NULL)
1499 {
1500 sprintf(strtmp[4], "apntype=;");
1501 }
1502 else
1503 {
1504 sprintf(strtmp[4], "apntype=%s;", apntype);
1505 }
1506 if (user == NULL)
1507 {
1508 sprintf(strtmp[5], "user=;");
1509 }
1510 else
1511 {
1512 sprintf(strtmp[5], "user=%s;", user);
1513 }
1514 if (password == NULL)
1515 {
1516 sprintf(strtmp[6], "password=;");
1517 }
1518 else
1519 {
1520 sprintf(strtmp[6], "password=%s;", password);
1521 }
1522 if (normalprotocol == NULL)
1523 {
1524 sprintf(strtmp[7], "normalprotocol=;");
1525 }
1526 else
1527 {
1528 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1529 }
1530 if (roamingprotocol == NULL)
1531 {
1532 sprintf(strtmp[8], "roamingprotocol=;");
1533 }
1534 else
1535 {
1536 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1537 }
1538 if (carrier == NULL)
1539 {
1540 sprintf(strtmp[9], "carrier=;");
1541 }
1542 else
1543 {
1544 sprintf(strtmp[9], "carrier=%s;", carrier);
1545 }
rjw61fcae32022-08-18 14:03:39 +08001546 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 +08001547
rjw20006d12022-04-21 16:29:04 +08001548 return 0;
1549}
1550
1551int 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)
1552{
1553 char strtmp[10][32];
1554 if (id == NULL)
1555 {
1556 sprintf(strtmp[0], "id=;");
1557 }
1558 else
1559 {
1560 sprintf(strtmp[0], "id=%s;", id);
1561 }
1562 if (mcc == NULL)
1563 {
1564 sprintf(strtmp[1], "mcc=;");
1565 }
1566 else
1567 {
1568 sprintf(strtmp[1], "mcc=%s;", mcc);
1569 }
1570 if (mnc == NULL)
1571 {
1572 sprintf(strtmp[2], "mnc=;");
1573 }
1574 else
1575 {
1576 sprintf(strtmp[2], "mnc=%s;", mnc);
1577 }
1578 if (apn == NULL)
1579 {
1580 sprintf(strtmp[3], "apn=;");
1581 }
1582 else
1583 {
1584 sprintf(strtmp[3], "apn=%s;", apn);
1585 }
1586 if (apntype == NULL)
1587 {
1588 sprintf(strtmp[4], "apntype=;");
1589 }
1590 else
1591 {
1592 sprintf(strtmp[4], "apntype=%s;", apntype);
1593 }
1594 if (user == NULL)
1595 {
1596 sprintf(strtmp[5], "user=;");
1597 }
1598 else
1599 {
1600 sprintf(strtmp[5], "user=%s;", user);
1601 }
1602 if (password == NULL)
1603 {
1604 sprintf(strtmp[6], "password=;");
1605 }
1606 else
1607 {
1608 sprintf(strtmp[6], "password=%s;", password);
1609 }
1610 if (normalprotocol == NULL)
1611 {
1612 sprintf(strtmp[7], "normalprotocol=;");
1613 }
1614 else
1615 {
1616 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1617 }
1618 if (roamingprotocol == NULL)
1619 {
1620 sprintf(strtmp[8], "roamingprotocol=;");
1621 }
1622 else
1623 {
1624 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1625 }
1626 if (carrier == NULL)
1627 {
1628 sprintf(strtmp[9], "carrier=;");
1629 }
1630 else
1631 {
1632 sprintf(strtmp[9], "carrier=%s;", carrier);
1633 }
1634 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]);
1635 return 0;
1636}
1637
rjwaf4b1612022-06-13 17:26:01 +08001638
1639int 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)
1640{
1641 char strtmp[10][32];
1642 if (id == NULL)
1643 {
1644 sprintf(strtmp[0], "");
1645 }
1646 else
1647 {
1648 sprintf(strtmp[0], "id=%s;", id);
1649 }
1650 if (mcc == NULL)
1651 {
1652 sprintf(strtmp[1], "");
1653 }
1654 else
1655 {
1656 sprintf(strtmp[1], "mcc=%s;", mcc);
1657 }
1658 if (mnc == NULL)
1659 {
1660 sprintf(strtmp[2], "");
1661 }
1662 else
1663 {
1664 sprintf(strtmp[2], "mnc=%s;", mnc);
1665 }
1666 if (apn == NULL)
1667 {
1668 sprintf(strtmp[3], "");
1669 }
1670 else
1671 {
1672 sprintf(strtmp[3], "apn=%s;", apn);
1673 }
1674 if (apntype == NULL)
1675 {
1676 sprintf(strtmp[4], "");
1677 }
1678 else
1679 {
1680 sprintf(strtmp[4], "apntype=%s;", apntype);
1681 }
1682 if (user == NULL)
1683 {
1684 sprintf(strtmp[5], "");
1685 }
1686 else
1687 {
1688 sprintf(strtmp[5], "user=%s;", user);
1689 }
1690 if (password == NULL)
1691 {
1692 sprintf(strtmp[6], "");
1693 }
1694 else
1695 {
1696 sprintf(strtmp[6], "password=%s;", password);
1697 }
1698 if (normalprotocol == NULL)
1699 {
1700 sprintf(strtmp[7], "");
1701 }
1702 else
1703 {
1704 sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
1705 }
1706 if (roamingprotocol == NULL)
1707 {
1708 sprintf(strtmp[8], "");
1709 }
1710 else
1711 {
1712 sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
1713 }
1714 if (carrier == NULL)
1715 {
1716 sprintf(strtmp[9], "");
1717 }
1718 else
1719 {
1720 sprintf(strtmp[9], "carrier=%s;", carrier);
1721 }
1722 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]);
1723 return 0;
1724}
1725
rjw20006d12022-04-21 16:29:04 +08001726static char *lynqStrdupReadString(Parcel &p)
1727{
1728 size_t stringlen;
1729 const char16_t *s16;
1730
1731 s16 = p.readString16Inplace(&stringlen);
1732 return strndup16to8(s16, stringlen);
1733}
Hong_Liu7163bbe2023-06-04 03:03:44 -07001734int get_imsi()
1735{
Hong_Liu25edfe72023-06-16 01:13:42 -07001736 Parcel *p =NULL;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001737 lynq_client_t client;
1738 int resp_type = -1;
1739 int token;
1740 int request = -1;
1741 int slot_id = -1;
1742 int error = -1;
1743 int version =0;
1744 int num = 0;
1745 char *temp_char = NULL;
1746 char mccmnc[32] = {0};
1747 char mccmnckey[64] = {0};
Hong_Liu25edfe72023-06-16 01:13:42 -07001748 client.uToken = get_utoken();
Hong_Liu7163bbe2023-06-04 03:03:44 -07001749 client.request = 11;//RIL_REQUEST_GET_IMSI 11
1750 client.paramLen = 0;
1751 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1752 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1753 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1754 if(send_request(lynq_client_sockfd,&client)==-1)
1755 {
1756 LYERRLOG("send request fail");
1757 perror("[LYNQ_DATA] send request fail:");
Hong_Liu25edfe72023-06-16 01:13:42 -07001758 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001759 return -1;
1760 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001761 //get_response(lynq_client_sockfd,p);
1762 error = wait_response(lynq_client_sockfd,p,client.uToken);
1763 if(error!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001764 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001765 LYERRLOG("wait_response fail,ret:%d",error);
1766 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
Hong_Liu7163bbe2023-06-04 03:03:44 -07001767 return error;
1768 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001769 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1770 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
Hong_Liu7163bbe2023-06-04 03:03:44 -07001771 {
Hong_Liu25edfe72023-06-16 01:13:42 -07001772 LYERRLOG("JumpHeader fail");
Hong_Liu7163bbe2023-06-04 03:03:44 -07001773 return -1;
1774 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001775 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1776 if(error == 0)
1777 {
1778 char * test = strdupReadString_p(p);
1779 memcpy(mccmnc, test,5);
1780 mccmnc[5]='\0';
1781 free(test);
1782 sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
1783 system(mccmnckey);
1784 system("uci commit");
1785 }
1786 free_parcel(p);
1787 return error;
Hong_Liu7163bbe2023-06-04 03:03:44 -07001788}
rjw20006d12022-04-21 16:29:04 +08001789int 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)
1790{
1791 if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
1792 {
1793 LYERRLOG("There are no valid parameters");
1794 return -1;
1795 }
1796 lynq_client_t client;
1797 char argc[512];
Hong_Liu7163bbe2023-06-04 03:03:44 -07001798 int res = -1;
rjw20006d12022-04-21 16:29:04 +08001799 if (cmd == 0) // insert apn db
1800 {
rjw61fcae32022-08-18 14:03:39 +08001801 res = insert_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 == 1) //delete apn db
rjw20006d12022-04-21 16:29:04 +08001809 {
1810 if (NULL == id)
1811 {
1812 LYERRLOG("id is NULL!!!please input id: ");
1813 }
1814 sprintf(argc, "id=%s", id);
Hong_Liu25edfe72023-06-16 01:13:42 -07001815 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001816 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1817 client.paramLen = 2;
1818 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1819 sprintf(client.param, "%d %s", cmd, argc);
1820 }
rjw61fcae32022-08-18 14:03:39 +08001821 else if (cmd == 2) //query apn db
rjw20006d12022-04-21 16:29:04 +08001822 {
rjwaf4b1612022-06-13 17:26:01 +08001823 query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001824 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001825 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1826 client.paramLen = 2;
1827 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1828 sprintf(client.param, "%d %s", cmd, argc);
1829 }
rjw61fcae32022-08-18 14:03:39 +08001830 else if (cmd == 3) //modify apn db
rjw20006d12022-04-21 16:29:04 +08001831 {
1832 modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
Hong_Liu25edfe72023-06-16 01:13:42 -07001833 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001834 client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
1835 client.paramLen = 2;
1836 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1837 sprintf(client.param, "%d %s", cmd, argc);
1838 }
1839 else
1840 {
1841 LYERRLOG("incoming command is invalid");
1842 return -1;
1843 }
1844 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
rjwed00d042022-05-25 09:18:16 +08001845 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001846 if(send_request(lynq_client_sockfd,&client)==-1)
1847 {
1848 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001849 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001850 return -1;
1851 }
rjwed00d042022-05-25 09:18:16 +08001852 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001853 waitApnResult();
rjw3bcbbf12022-04-22 16:47:18 +08001854 strcpy(out, g_lynq_apn_result);
rjw20006d12022-04-21 16:29:04 +08001855 LYINFLOG(">>>>>output info:%s",out);
1856 return 0;
1857}
1858
1859int lynq_reset_apn(char *result)
1860{
rjw20006d12022-04-21 16:29:04 +08001861 lynq_client_t client;
rjw3bcbbf12022-04-22 16:47:18 +08001862 if (NULL == result)
1863 {
1864 LYERRLOG("incoming paramters error");
1865 }
Hong_Liu25edfe72023-06-16 01:13:42 -07001866 client.uToken = get_utoken();
rjw20006d12022-04-21 16:29:04 +08001867 client.request = 2000 + 194;
1868 client.paramLen = 0;
1869 bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
1870 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
rjwed00d042022-05-25 09:18:16 +08001871 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001872 if (send_request(lynq_client_sockfd, &client) == -1)
1873 {
1874 LYERRLOG("send request fail");
Hong_Liu25edfe72023-06-16 01:13:42 -07001875 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001876 return -1;
1877 }
rjwed00d042022-05-25 09:18:16 +08001878 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
rjw20006d12022-04-21 16:29:04 +08001879 waitApnResult();
1880 strcpy(result, g_lynq_apn_result);
1881 LYINFLOG(">>>>>result:%s",result);
1882 return 0;
1883}
1884
rjw3bcbbf12022-04-22 16:47:18 +08001885/*Typethree add for T800 platform 2022/04/21 end*/
Hong_Liu7d9ac8d2023-07-24 00:40:31 -07001886static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) {
1887 FILE *fp;
1888 //printf("to exec cmd:%s\n", str_cmd);
1889 if((fp=popen(str_cmd,"r"))==NULL)
1890 {
1891 perror("popen error!");
1892 return -1;
1893 }
1894 if((fread(str_cmd_ret,max_len,1,fp))<0)
1895 {
1896 perror("fread fail!");
1897 fclose(fp);
1898 return -1;
1899 }
1900 fclose(fp);
1901 return 0;
1902}
1903int check_apn_status()
1904{
1905 LYINFLOG("check_apn_status enter");
1906 int ret = -1;
1907 char cmd_ret[8] ={0};//get mccmnc
1908 const char *cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc0";
1909 const char *empty_str = ":empty";
1910 ret = exec_cmd(cmd,cmd_ret,8);
1911 if(ret==0)
1912 {
1913 if(strlen(cmd_ret)==0)
1914 {
1915 LYERRLOG("not have mccmnc config in uci ram");
1916 return 1;
1917 }
1918 if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0)
1919 {
1920 LYERRLOG("mccmnc is empty");
1921 return 2;
1922 }
1923 LYINFLOG("mccmnc is %s",cmd_ret);
1924 return 0;
1925 }
1926 else
1927 {
1928 LYERRLOG("exec cmd fail");
1929 return -1;
1930 }
1931 return 0;
1932}
1933int radio_switch(int status)
1934{
1935 Parcel *p =NULL;
1936 lynq_client_t client;
1937 int resp_type = -1;
1938 int token;
1939 int request = -1;
1940 int slot_id = -1;
1941 int error = -1;
1942 int version =0;
1943 int num = 0;
1944 char *temp_char = NULL;
1945 char mccmnc[32] = {0};
1946 char mccmnckey[64] = {0};
1947 client.uToken = get_utoken();
1948 client.request = 59;//RIL_REQUEST_OEM_HOOK_RAW 59
1949 client.paramLen = 1;
1950 bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
1951 sprintf(client.param,"AT+CFUN=%d",status);
1952 LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
1953 pthread_mutex_lock(&g_lynq_data_sendto_mutex);
1954 if(send_request(lynq_client_sockfd,&client)==-1)
1955 {
1956 LYERRLOG("send request fail");
1957 perror("[LYNQ_DATA] send request fail:");
1958 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1959 return -1;
1960 }
1961 //get_response(lynq_client_sockfd,p);
1962 error = wait_response(lynq_client_sockfd,p,client.uToken);
1963 if(error!=0)
1964 {
1965 LYERRLOG("wait_response fail,ret:%d",error);
1966 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1967 return error;
1968 }
1969 pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
1970 if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
1971 {
1972 LYERRLOG("JumpHeader fail");
1973 return -1;
1974 }
1975 LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
1976 free_parcel(p);
1977 return error;
1978}