lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1 | #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> |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame^] | 16 | #include <include/lynq_uci.h> |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 17 | #define LYNQ_SERVICE_PORT 8088 |
| 18 | #define LYNQ_URC_SERVICE_PORT 8086 |
| 19 | #define LYNQ_REC_BUF 8192 |
| 20 | #define LYNQ_REQUEST_PARAM_BUF 8192 |
| 21 | #define LYQN_SEDN_BUF 1024*8+sizeof(int)*3 |
| 22 | #define USER_LOG_TAG "LYNQ_DATA" |
| 23 | |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame^] | 24 | #define LYNQ_DATA_UCI_BUF 258 |
| 25 | #define LYNQ_DATA_UCI_APN_SECTION "lynq_apn_info" |
| 26 | #define LYNQ_DATA_UCI_APN_KEY "insertId" |
| 27 | |
| 28 | |
| 29 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 30 | using ::android::Parcel; |
| 31 | typedef struct{ |
| 32 | int uToken; |
| 33 | int request; |
| 34 | int paramLen; |
| 35 | char param[LYNQ_REQUEST_PARAM_BUF]; |
| 36 | }lynq_client_t; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 37 | typedef enum{ |
| 38 | LYNQ_E_CARDSTATE_ERROR=8000, |
| 39 | /* The voice service state is out of service*/ |
| 40 | LYNQ_E_STATE_OUT_OF_SERVICE=8001, |
| 41 | /* The voice service state is EMERGENCY_ONLY*/ |
| 42 | LYNQ_E_STATE_EMERGENCY_ONLY=8002, |
| 43 | /* The radio power is power off*/ |
| 44 | LYNQ_E_STATE_POWER_OFF=8003, |
| 45 | LYNQ_E_TIME_OUT=8004, |
| 46 | /*create or open sms DB fail */ |
| 47 | LYNQ_E_SMS_DB_FAIL=8005, |
| 48 | /*Failed to execute sql statement*/ |
| 49 | LYNQ_E_SMS_SQL_FAIL = 8006, |
| 50 | LYNQ_E_SMS_NOT_FIND = 8007, |
| 51 | /* The logic conflict*/ |
| 52 | LYNQ_E_CONFLICT=9000, |
| 53 | /*Null anomaly*/ |
| 54 | LYNQ_E_NULL_ANONALY=9001 |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 55 | }LYNQ_E; |
| 56 | |
| 57 | int lynq_client_sockfd = 0; |
| 58 | int Global_uToken = 0; |
| 59 | bool data_urc_recive_status = 1; |
| 60 | int lynq_data_call_change_id = -1; |
| 61 | pthread_t lynq_data_tid =-1; |
| 62 | static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 63 | static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER; |
| 64 | static pthread_mutex_t s_pdn_change_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 65 | static pthread_cond_t s_pdn_change_cond = PTHREAD_COND_INITIALIZER; |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 66 | static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 67 | static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER; |
| 68 | |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 69 | /**g_lynq_data_sendto_mutex |
| 70 | * @brief mark data send request mutex |
| 71 | */ |
| 72 | static pthread_mutex_t g_lynq_data_sendto_mutex; |
| 73 | |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 74 | /**g_lynq_data_init_flag |
| 75 | * @brief mark data initialization state |
| 76 | * 0:deinit status |
| 77 | * 1:init state |
| 78 | */ |
| 79 | static int g_lynq_data_init_flag = 0; |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 80 | /**g_lynq_apn_result |
| 81 | * @brief temp of apn result info |
| 82 | */ |
| 83 | char g_lynq_apn_result[1024] = {}; |
| 84 | typedef struct |
| 85 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 86 | char apn[LYNQ_APN_MAX_LEN]; |
| 87 | char apnType[LYNQ_APN_TYPE_MAX_LEN]; |
| 88 | char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; |
| 89 | int hasUsed; |
| 90 | int hasTimeout; |
| 91 | }lynq_apn_t; |
| 92 | lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {}; |
| 93 | lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {}; |
| 94 | int lynq_data_call = 0; |
| 95 | int millli_sleep_with_restart(int millisecond) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 96 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 97 | int left = millisecond*1000; |
| 98 | while (left > 0) |
| 99 | { |
| 100 | left = usleep(left); |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | int getLynqApnID(char apnType[]) |
| 106 | { |
| 107 | int ret = 0; |
| 108 | for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++) |
| 109 | { |
| 110 | if(strcmp(lynq_apn_table[ret].apnType,apnType)==0) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 111 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 112 | return ret; |
| 113 | } |
| 114 | } |
| 115 | return -1; |
| 116 | } |
| 117 | void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[]) |
| 118 | { |
| 119 | LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName); |
| 120 | if(apn_table==NULL) |
| 121 | { |
| 122 | LYERRLOG("apn_table is null"); |
| 123 | return; |
| 124 | } |
| 125 | memcpy(apn_table->apn,apn,strlen(apn)+1); |
| 126 | memcpy(apn_table->apnType,apntype,strlen(apntype)+1); |
| 127 | memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1); |
| 128 | apn_table->hasTimeout = 0; |
| 129 | apn_table->hasUsed = 1; |
| 130 | return; |
| 131 | } |
| 132 | void cleanOnceApnTable(int apnId) |
| 133 | { |
| 134 | LYDBGLOG("apn id:%d",apnId); |
| 135 | if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1)) |
| 136 | { |
| 137 | LYERRLOG("apn id is invalid!!!"); |
| 138 | return; |
| 139 | } |
| 140 | lynq_apn_table[apnId].hasTimeout = 0; |
| 141 | lynq_apn_table[apnId].hasUsed = 0; |
| 142 | bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN); |
| 143 | //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN); |
| 144 | bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN); |
| 145 | return; |
| 146 | } |
| 147 | int getUnusedElement() |
| 148 | { |
| 149 | for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++) |
| 150 | { |
| 151 | if(lynq_apn_table[i].hasUsed!=1) |
| 152 | { |
| 153 | return i; |
| 154 | } |
| 155 | } |
| 156 | return -1; |
| 157 | } |
| 158 | int updateApn(char apnType[]) |
| 159 | { |
| 160 | int ret = 0; |
| 161 | ret = getUnusedElement(); |
| 162 | memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1); |
| 163 | lynq_apn_table[ret].hasUsed = 1; |
| 164 | return ret; |
| 165 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 166 | int waitApnResult() |
| 167 | { |
| 168 | int ret = 0; |
| 169 | LYINFLOG("start wait apn result!!!"); |
| 170 | int sec = 0; |
| 171 | int usec = 0; |
| 172 | struct timeval now; |
| 173 | struct timespec timeout; |
| 174 | gettimeofday(&now, NULL); |
| 175 | sec = 20000 / 1000; |
| 176 | usec = 20000 % 1000; |
| 177 | timeout.tv_sec = now.tv_sec + sec; |
| 178 | timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000; |
| 179 | pthread_mutex_lock(&s_lynq_apn_change_mutex); |
| 180 | ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout); |
| 181 | pthread_mutex_unlock(&s_lynq_apn_change_mutex); |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | void sendSignalApnChange() |
| 186 | { |
| 187 | LYINFLOG("start send Signal Apn Change"); |
| 188 | pthread_mutex_lock(&s_lynq_apn_change_mutex); |
| 189 | pthread_cond_signal(&s_lynq_apn_change_cond); |
| 190 | pthread_mutex_unlock(&s_lynq_apn_change_mutex); |
| 191 | return; |
| 192 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 193 | |
| 194 | int waitPdnChange() |
| 195 | { |
| 196 | int ret = 0; |
| 197 | pthread_mutex_lock(&s_pdn_change_mutex); |
| 198 | ret = pthread_cond_wait(&s_pdn_change_cond,&s_pdn_change_mutex); |
| 199 | pthread_mutex_unlock(&s_pdn_change_mutex); |
| 200 | return ret; |
| 201 | } |
| 202 | int waitDataCallstateChange(int mtime) |
| 203 | { |
| 204 | int ret = 0; |
| 205 | int sec = 0; |
| 206 | int usec = 0; |
| 207 | struct timeval now; |
| 208 | struct timespec timeout; |
| 209 | gettimeofday(&now,NULL); |
| 210 | sec = mtime/1000; |
| 211 | usec = mtime%1000; |
| 212 | timeout.tv_sec = now.tv_sec+sec; |
| 213 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000; |
| 214 | pthread_mutex_lock(&s_data_call_state_change_mutex); |
| 215 | ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout); |
| 216 | pthread_mutex_unlock(&s_data_call_state_change_mutex); |
| 217 | return ret; |
| 218 | } |
| 219 | void sendSignalDataCallStateChange() |
| 220 | { |
| 221 | pthread_mutex_lock(&s_data_call_state_change_mutex); |
| 222 | pthread_cond_signal(&s_data_call_state_change_cond); |
| 223 | pthread_mutex_unlock(&s_data_call_state_change_mutex); |
| 224 | return; |
| 225 | } |
| 226 | void sendSignalPdnChange() |
| 227 | { |
| 228 | pthread_mutex_lock(&s_pdn_change_mutex); |
| 229 | pthread_cond_signal(&s_pdn_change_cond); |
| 230 | pthread_mutex_unlock(&s_pdn_change_mutex); |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | int get_response(int sockfd,Parcel &p) |
| 235 | { |
| 236 | int len = 0; |
| 237 | char recvline[LYNQ_REC_BUF]; |
| 238 | bzero(recvline,LYNQ_REC_BUF); |
| 239 | /* receive data from server */ |
| 240 | len = read(sockfd, recvline, LYNQ_REC_BUF); |
| 241 | if(len == -1) |
| 242 | { |
| 243 | perror("read error"); |
| 244 | return -1; |
| 245 | } |
| 246 | if (recvline != NULL) { |
| 247 | p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen); |
| 248 | p.setDataPosition(0); |
| 249 | } |
| 250 | return 0; |
| 251 | } |
| 252 | int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error) |
| 253 | { |
| 254 | if(p.dataAvail() > 0) |
| 255 | { |
| 256 | p.readInt32(resp_type); |
| 257 | p.readInt32(request); |
| 258 | p.readInt32(slot_id); |
| 259 | p.readInt32(error); |
| 260 | return 0; |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | return -1; |
| 265 | } |
| 266 | } |
| 267 | int send_request(int sockfd,lynq_client_t *client_tmp) |
| 268 | { |
| 269 | int ret=0; |
| 270 | ret = write(sockfd, client_tmp, LYQN_SEDN_BUF); |
| 271 | if(ret==-1) |
| 272 | { |
| 273 | perror("write error"); |
| 274 | return -1; |
| 275 | } |
| 276 | return 0; |
| 277 | } |
| 278 | static char *strdupReadString(Parcel &p) { |
| 279 | size_t stringlen; |
| 280 | const char16_t *s16; |
| 281 | s16 = p.readString16Inplace(&stringlen); |
| 282 | return strndup16to8(s16, stringlen); |
| 283 | } |
| 284 | static char *strdupReadString_p(Parcel *p) { |
| 285 | size_t stringlen; |
| 286 | const char16_t *s16; |
| 287 | s16 = p->readString16Inplace(&stringlen); |
| 288 | return strndup16to8(s16, stringlen); |
| 289 | } |
| 290 | |
| 291 | |
| 292 | /*Warren add for T800 platform 2021/11/19 start*/ |
| 293 | int lynq_socket_client_start() |
| 294 | { |
| 295 | struct sockaddr_in lynq_socket_server_addr; |
| 296 | /* init lynq_socket_server_addr */ |
| 297 | bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)); |
| 298 | lynq_socket_server_addr.sin_family = AF_INET; |
| 299 | lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT); |
| 300 | lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY); |
| 301 | /* |
| 302 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0) |
| 303 | { |
| 304 | printf("[%s] is not a valid IPaddress\n", argv[1]); |
| 305 | exit(1); |
| 306 | } |
| 307 | */ |
| 308 | lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0); |
| 309 | if(connect(lynq_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1) |
| 310 | { |
| 311 | perror("connect error"); |
| 312 | return -1; |
| 313 | } |
| 314 | return 0; |
| 315 | } |
| 316 | void *thread_urc_recv(void *parg) |
| 317 | { |
| 318 | int socket_fd = (int64_t)parg; |
| 319 | int len=0; |
| 320 | socklen_t addr_len=0; |
| 321 | uint8_t *dataLength = NULL; |
| 322 | char urc_data[LYNQ_REC_BUF]; |
| 323 | char apn[LYNQ_APN_MAX_LEN]; |
| 324 | char apnType[LYNQ_APN_TYPE_MAX_LEN]; |
| 325 | int pdnState = 0; |
| 326 | char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; |
| 327 | int slot_id = -1; |
| 328 | int resp_type = -1; |
| 329 | int urcid = -1; |
| 330 | char *urc_msg = NULL; |
| 331 | Parcel *p = NULL; |
| 332 | struct sockaddr_in dest_addr; |
| 333 | LYINFLOG("thread_urc_recv in running....\n"); |
| 334 | while(data_urc_recive_status) |
| 335 | { |
| 336 | bzero(urc_data,LYNQ_REC_BUF); |
| 337 | //get data msg |
| 338 | len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len); |
| 339 | if(len <= 0) |
| 340 | { |
| 341 | perror("thread_urc_recv step2 fail:"); |
| 342 | millli_sleep_with_restart(1); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 343 | break; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 344 | } |
| 345 | LYDBGLOG("=====>urc data len<=====:%d\n",len); |
| 346 | p = new Parcel(); |
| 347 | if(p==NULL) |
| 348 | { |
| 349 | RLOGD("new parcel failure!!!"); |
| 350 | break; |
| 351 | } |
| 352 | p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen); |
| 353 | p->setDataPosition(0); |
| 354 | if(p->dataAvail() > 0) |
| 355 | { |
| 356 | p->readInt32(&resp_type); |
| 357 | p->readInt32(&urcid); |
| 358 | p->readInt32(&slot_id); |
| 359 | //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); |
| 360 | switch (urcid) |
| 361 | { |
| 362 | case 9003://LYNQ_URC_DATA_CALL_STATUS_IND |
| 363 | { |
| 364 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); |
| 365 | p->readInt32(&pdnState); |
| 366 | bzero(apn,LYNQ_APN_MAX_LEN); |
| 367 | bzero(apnType,LYNQ_APN_TYPE_MAX_LEN); |
| 368 | bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN); |
| 369 | if(pdnState!=4)//PDN_DISCONNECTED |
| 370 | { |
| 371 | urc_msg = strdupReadString_p(p); |
| 372 | int len = strlen(urc_msg); |
| 373 | if(len < LYNQ_APN_MAX_LEN-1) |
| 374 | { |
| 375 | memcpy(apn,urc_msg,len+1); |
| 376 | } |
| 377 | urc_msg = strdupReadString_p(p); |
| 378 | len = strlen(urc_msg); |
| 379 | if(len < LYNQ_APN_TYPE_MAX_LEN-1) |
| 380 | { |
| 381 | memcpy(apnType,urc_msg,len+1); |
| 382 | } |
| 383 | urc_msg = strdupReadString_p(p); |
| 384 | len = strlen(urc_msg); |
| 385 | if(len < LYNQ_IFACE_NAME_MAX_LEN-1) |
| 386 | { |
| 387 | memcpy(ifaceName,urc_msg,strlen(urc_msg)+1); |
| 388 | } |
| 389 | //sendSignalDataCallStateChange(); |
| 390 | int apnId = getLynqApnID(apnType); |
| 391 | if(apnId >= 0) |
| 392 | { |
| 393 | if(lynq_apn_table[apnId].hasTimeout==1) |
| 394 | { |
| 395 | LYERRLOG("apn:%s has time out",lynq_apn_table[apnId].apn); |
| 396 | lynq_deactive_data_call(&apnId); |
| 397 | continue; |
| 398 | } |
| 399 | updateApnTable(&lynq_apn_table[apnId], apn,apnType,ifaceName); |
| 400 | } |
| 401 | lynq_data_call_change_id = apnId; |
| 402 | sendSignalPdnChange(); |
| 403 | LYDBGLOG("data call state:%d",lynq_data_call); |
| 404 | if(lynq_data_call==1) |
| 405 | { |
| 406 | sendSignalDataCallStateChange(); |
| 407 | lynq_data_call = 0; |
| 408 | } |
| 409 | } |
| 410 | else |
| 411 | { |
| 412 | urc_msg = strdupReadString_p(p); |
| 413 | len = strlen(urc_msg); |
| 414 | if(len < LYNQ_APN_TYPE_MAX_LEN-1) |
| 415 | { |
| 416 | memcpy(apnType,urc_msg,len+1); |
| 417 | } |
| 418 | LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType); |
| 419 | int apnId = getLynqApnID(apnType); |
| 420 | if(apnId >= 0) |
| 421 | { |
| 422 | lynq_data_call_change_id = apnId; |
| 423 | bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean |
| 424 | } |
| 425 | sendSignalPdnChange(); |
| 426 | LYDBGLOG("data call state:%d",lynq_data_call); |
| 427 | if(lynq_data_call==1) |
| 428 | { |
| 429 | sendSignalDataCallStateChange(); |
| 430 | lynq_data_call = 0; |
| 431 | } |
| 432 | } |
| 433 | break; |
| 434 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 435 | case 9004: |
| 436 | { |
| 437 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); |
| 438 | urc_msg = strdupReadString_p(p); |
| 439 | if (NULL == urc_msg) |
| 440 | { |
| 441 | LYERRLOG("error apn msg"); |
| 442 | } |
| 443 | else |
| 444 | { |
| 445 | bzero(g_lynq_apn_result, 1024); |
| 446 | strcpy(g_lynq_apn_result, urc_msg); |
| 447 | sendSignalApnChange(); |
| 448 | } |
| 449 | break; |
| 450 | } |
| 451 | case 9005: |
| 452 | { |
| 453 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); |
| 454 | urc_msg = strdupReadString_p(p); |
| 455 | if (NULL == urc_msg) |
| 456 | { |
| 457 | LYERRLOG("error apn msg"); |
| 458 | } |
| 459 | else |
| 460 | { |
| 461 | bzero(g_lynq_apn_result, 1024); |
| 462 | strcpy(g_lynq_apn_result, urc_msg); |
| 463 | sendSignalApnChange(); |
| 464 | } |
| 465 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 466 | default: |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | delete p; |
| 471 | p = NULL; |
| 472 | } |
| 473 | close(socket_fd); |
| 474 | } |
| 475 | int lynq_socket_urc_start() |
| 476 | { |
| 477 | int socket_fd=0; |
| 478 | int rt=0; |
| 479 | int len=0; |
| 480 | int on=1; |
| 481 | struct sockaddr_in urc_local_addr; |
| 482 | pthread_attr_t attr; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 483 | socket_fd = socket(AF_INET,SOCK_DGRAM,0); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 484 | if(socket_fd < 0) |
| 485 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 486 | perror("creaet socket for udp fail"); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 487 | return -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 488 | } |
| 489 | urc_local_addr.sin_family = AF_INET; |
| 490 | urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT); |
| 491 | urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY); |
| 492 | /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/ |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 493 | rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on); |
| 494 | if(rt<0) |
| 495 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 496 | perror("SO_REUSEADDR fail\n"); |
| 497 | return -1; |
| 498 | } |
| 499 | rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr)); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 500 | if (rt == -1) |
| 501 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 502 | perror("bind failed"); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 503 | return -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 504 | } |
| 505 | pthread_attr_init(&attr); |
| 506 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 507 | rt = pthread_create(&lynq_data_tid,&attr,thread_urc_recv,(void *)socket_fd); |
| 508 | if(rt < 0) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 509 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 510 | LYERRLOG("urc loop failure!!!\n"); |
| 511 | return -1; |
| 512 | } |
| 513 | LYDBGLOG("urc loop success!!!\n"); |
| 514 | return 0; |
| 515 | } |
| 516 | int lynq_init_data(int uToken) |
| 517 | { |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 518 | if (g_lynq_data_init_flag == 1) |
| 519 | { |
| 520 | LYERRLOG("init twice is not allowed"); |
| 521 | return -1; |
| 522 | } |
| 523 | g_lynq_data_init_flag = 1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 524 | int result = 0; |
| 525 | Global_uToken = uToken; |
| 526 | data_urc_recive_status = 1; |
| 527 | LYLOGSET(LOG_INFO); |
| 528 | LYLOGEINIT(USER_LOG_TAG); |
| 529 | result = lynq_socket_client_start(); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 530 | pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 531 | if(result!=0) |
| 532 | { |
| 533 | LYERRLOG("init socket client fail!!!"); |
| 534 | return -1; |
| 535 | } |
| 536 | result = lynq_socket_urc_start(); |
| 537 | if(result!=0) |
| 538 | { |
| 539 | LYERRLOG("init socket urc fail!!!"); |
| 540 | return -1; |
| 541 | } |
| 542 | memset(lynq_apn_table,0,sizeof(lynq_apn_table)); |
| 543 | LYDBGLOG("lynq init call success!!!"); |
| 544 | return 0; |
| 545 | |
| 546 | } |
| 547 | int lynq_deinit_data() |
| 548 | { |
| 549 | int ret = -1; |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 550 | if (g_lynq_data_init_flag == 0) |
| 551 | { |
| 552 | LYERRLOG("deinit twice is not allowed"); |
| 553 | return ret; |
| 554 | } |
| 555 | g_lynq_data_init_flag = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 556 | for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++) |
| 557 | { |
| 558 | if(strlen(lynq_apn_table[i].apnType)!=0) |
| 559 | { |
| 560 | lynq_deactive_data_call(&i); |
| 561 | } |
| 562 | } |
| 563 | if(lynq_client_sockfd>0) |
| 564 | { |
| 565 | close(lynq_client_sockfd); |
| 566 | } |
| 567 | data_urc_recive_status = 0; |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 568 | if (lynq_data_tid > 0) |
| 569 | { |
| 570 | ret = pthread_cancel(lynq_data_tid); |
| 571 | LYDBGLOG("pthread cancel ret = %d",ret); |
| 572 | ret = pthread_join(lynq_data_tid,NULL); |
| 573 | LYDBGLOG("pthread join ret = %d",ret); |
| 574 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 575 | return 0; |
| 576 | } |
| 577 | int lynq_setup_data_call(int *handle) |
| 578 | { |
| 579 | Parcel p; |
| 580 | lynq_client_t client; |
| 581 | int resp_type = -1; |
| 582 | int request = -1; |
| 583 | int slot_id = -1; |
| 584 | int error = -1; |
| 585 | char iface = NULL; |
| 586 | int lynq_data_call_id = 0; |
| 587 | if(handle==NULL) |
| 588 | { |
| 589 | LYERRLOG("handle is null!!!"); |
| 590 | return LYNQ_E_NULL_ANONALY; |
| 591 | } |
| 592 | client.uToken = Global_uToken; |
| 593 | client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL |
| 594 | client.paramLen = 0; |
| 595 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 596 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 597 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 598 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 599 | { |
| 600 | LYERRLOG("send request fail"); |
| 601 | perror("[LYNQ_DATA] send request fail:"); |
| 602 | return -1; |
| 603 | } |
| 604 | get_response(lynq_client_sockfd,p); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 605 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 606 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 607 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 608 | lynq_data_call_id = updateApn("default"); |
| 609 | lynq_data_call = 1; |
| 610 | if(error==0) |
| 611 | { |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 612 | if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 613 | { |
| 614 | error = LYNQ_E_TIME_OUT; |
| 615 | LYERRLOG("timeout:wait data Call state fail!!!"); |
| 616 | lynq_apn_table[lynq_data_call_id].hasTimeout = 1; |
| 617 | return error; |
| 618 | } |
| 619 | *handle = lynq_data_call_id; |
| 620 | } |
| 621 | return error; |
| 622 | } |
| 623 | int lynq_deactive_data_call(int *handle) |
| 624 | { |
| 625 | Parcel p; |
| 626 | lynq_client_t client; |
| 627 | int resp_type = -1; |
| 628 | int request = -1; |
| 629 | int slot_id = -1; |
| 630 | int error = -1; |
| 631 | int lynq_data_call_id = -1; |
| 632 | lynq_data_call_id = *handle; |
| 633 | if(handle==NULL) |
| 634 | { |
| 635 | LYERRLOG("handle is null!!!"); |
| 636 | return -1; |
| 637 | } |
| 638 | client.uToken = Global_uToken; |
| 639 | client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL |
| 640 | if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0) |
| 641 | { |
| 642 | client.paramLen = 0; |
| 643 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 644 | } |
| 645 | else |
| 646 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 647 | client.paramLen = 1; |
| 648 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 649 | sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType); |
| 650 | } |
| 651 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 652 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 653 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 654 | { |
| 655 | LYERRLOG("send request fail"); |
| 656 | perror("[LYNQ_DATA] send request fail:"); |
| 657 | return -1; |
| 658 | } |
| 659 | get_response(lynq_client_sockfd,p); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 660 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 661 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 662 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 663 | cleanOnceApnTable(lynq_data_call_id); |
| 664 | return error; |
| 665 | } |
| 666 | int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol) |
| 667 | { |
| 668 | Parcel p; |
| 669 | lynq_client_t client; |
| 670 | int resp_type = -1; |
| 671 | int request = -1; |
| 672 | int slot_id = -1; |
| 673 | int error = -1; |
| 674 | char iface = NULL; |
| 675 | int lynq_data_call_id = -1; |
| 676 | char *argv[10] = {}; |
| 677 | if(handle==NULL||apn==NULL||apnType==NULL) |
| 678 | { |
| 679 | LYERRLOG("handle ,apn or apntype is null!!!"); |
| 680 | return -1; |
| 681 | } |
| 682 | if(user==NULL) |
| 683 | { |
| 684 | argv[1] = "null"; |
| 685 | } |
| 686 | else |
| 687 | { |
| 688 | argv[1] = user; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 689 | } |
| 690 | if(password==NULL) |
| 691 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 692 | argv[2] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 693 | } |
| 694 | else |
| 695 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 696 | argv[2] = password; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 697 | } |
| 698 | if(authType==NULL) |
| 699 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 700 | argv[3] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 701 | } |
| 702 | else |
| 703 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 704 | argv[3] = authType; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 705 | } |
| 706 | if(normalProtocol==NULL) |
| 707 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 708 | argv[4] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 709 | } |
| 710 | else |
| 711 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 712 | argv[4] = normalProtocol; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 713 | } |
| 714 | if(roamingProtocol==NULL) |
| 715 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 716 | argv[5] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 717 | } |
| 718 | else |
| 719 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 720 | argv[5] = roamingProtocol; |
| 721 | } |
| 722 | client.uToken = Global_uToken; |
| 723 | client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL |
| 724 | client.paramLen = 7; |
| 725 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 726 | sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]); |
| 727 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 728 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 729 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 730 | { |
| 731 | LYERRLOG("send request fail"); |
| 732 | perror("[LYNQ_DATA] send request fail:"); |
| 733 | return -1; |
| 734 | } |
| 735 | get_response(lynq_client_sockfd,p); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 736 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 737 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 738 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 739 | lynq_data_call_id = updateApn(apnType); |
| 740 | lynq_data_call = 1; |
| 741 | if(error==0) |
| 742 | { |
| 743 | if(waitDataCallstateChange(20000)==ETIMEDOUT)//20s |
| 744 | { |
| 745 | error = LYNQ_E_TIME_OUT; |
| 746 | LYERRLOG("timeout:wait data Call state fail!!!"); |
| 747 | lynq_apn_table[lynq_data_call_id].hasTimeout = 1; |
| 748 | return error; |
| 749 | } |
| 750 | *handle = lynq_data_call_id; |
| 751 | } |
| 752 | return error; |
| 753 | } |
| 754 | /* |
| 755 | int lynq_deactive_data_call_sp(int *handle,char *apnType) |
| 756 | { |
| 757 | Parcel p; |
| 758 | lynq_client_t client; |
| 759 | int resp_type = -1; |
| 760 | int request = -1; |
| 761 | int slot_id = -1; |
| 762 | int error = -1; |
| 763 | if(handle==NULL||apnType==NULL) |
| 764 | { |
| 765 | LYERRLOG("handle is null!!!"); |
| 766 | return -1; |
| 767 | } |
| 768 | client.uToken = Global_uToken; |
| 769 | client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL |
| 770 | client.paramLen = 1; |
| 771 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 772 | sprintf(client.param,"%s",apnType); |
| 773 | LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 774 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 775 | { |
| 776 | LYERRLOG("send request fail"); |
| 777 | perror("[LYNQ_DATA] send request fail:"); |
| 778 | return -1; |
| 779 | } |
| 780 | get_response(lynq_client_sockfd,p); |
| 781 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 782 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 783 | return error; |
| 784 | } |
| 785 | */ |
| 786 | int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum) |
| 787 | { |
| 788 | Parcel p; |
| 789 | lynq_client_t client; |
| 790 | int resp_type = -1; |
| 791 | int request = -1; |
| 792 | int slot_id = -1; |
| 793 | int error = -1; |
| 794 | int version =0; |
| 795 | int num = 0; |
| 796 | int temp_int =0; |
| 797 | char *temp_char = NULL; |
| 798 | if(dataCallList==NULL) |
| 799 | { |
| 800 | LYERRLOG("dataCallList is null!!!"); |
| 801 | return -1; |
| 802 | } |
| 803 | client.uToken = Global_uToken; |
| 804 | client.request = 57;//RIL_REQUEST_DATA_CALL_LIST |
| 805 | client.paramLen = 0; |
| 806 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 807 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 808 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 809 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 810 | { |
| 811 | LYERRLOG("send request fail"); |
| 812 | perror("[LYNQ_DATA] send request fail:"); |
| 813 | return -1; |
| 814 | } |
| 815 | get_response(lynq_client_sockfd,p); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 816 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 817 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 818 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 819 | p.readInt32(&version); |
| 820 | if(version==11) |
| 821 | { |
| 822 | p.readInt32(&num); |
| 823 | *realNum = num; |
| 824 | for (int i = 0; i < num; i++) |
| 825 | { |
| 826 | p.readInt32(&dataCallList[i].status); |
| 827 | p.readInt32(&dataCallList[i].suggestedRetryTime); |
| 828 | p.readInt32(&dataCallList[i].cid); |
| 829 | p.readInt32(&dataCallList[i].active); |
| 830 | temp_char = strdupReadString(p); |
| 831 | memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1); |
| 832 | temp_char = strdupReadString(p); |
| 833 | memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1); |
| 834 | temp_char = strdupReadString(p); |
| 835 | memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1); |
| 836 | temp_char = strdupReadString(p); |
| 837 | memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1); |
| 838 | temp_char = strdupReadString(p); |
| 839 | memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1); |
| 840 | temp_char = strdupReadString(p); |
| 841 | memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1); |
| 842 | p.readInt32(&dataCallList[i].mtu); |
| 843 | } |
| 844 | } |
| 845 | return error; |
| 846 | } |
| 847 | int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList) |
| 848 | { |
| 849 | lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={}; |
| 850 | int number = 0; |
| 851 | int lynq_data_call_id = 0; |
| 852 | int error = 0; |
| 853 | lynq_data_call_id = *handle; |
| 854 | if(handle==NULL) |
| 855 | { |
| 856 | LYERRLOG("handle is NULL"); |
| 857 | return LYNQ_E_NULL_ANONALY; |
| 858 | } |
| 859 | memset(interDataCallList,0,sizeof(interDataCallList)); |
| 860 | error = getDataCallLists(interDataCallList,&number); |
| 861 | if(error == 0) |
| 862 | { |
| 863 | for(int i = 0;i < number;i++) |
| 864 | { |
| 865 | if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0) |
| 866 | { |
| 867 | dataCallList->active = interDataCallList[i].active; |
| 868 | dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime; |
| 869 | dataCallList->cid = interDataCallList[i].cid; |
| 870 | dataCallList->status = interDataCallList[i].status; |
| 871 | dataCallList->mtu = interDataCallList[i].mtu; |
| 872 | memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses)); |
| 873 | memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname)); |
| 874 | memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses)); |
| 875 | memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type)); |
| 876 | memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways)); |
| 877 | memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf)); |
| 878 | LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses); |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | return error; |
| 883 | } |
| 884 | int lynq_wait_data_call_state_change(int *handle) |
| 885 | { |
| 886 | waitPdnChange(); |
| 887 | *handle = lynq_data_call_change_id; |
| 888 | LYINFLOG("lynq data call id:%d",lynq_data_call_change_id); |
| 889 | return 0; |
| 890 | } |
| 891 | /*Warren add for T800 platform 2021/11/19 end*/ |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 892 | |
| 893 | /*Typethree add for T800 platform 2022/04/21 start*/ |
| 894 | int insert_apn_char(char *agc, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier) |
| 895 | { |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame^] | 896 | int ret = 0; |
| 897 | int fact_apn_id=0; |
| 898 | int tmp_id_num = 0; |
| 899 | char tmp_ID[16]=""; |
| 900 | char apn_info_buf[LYNQ_DATA_UCI_BUF]=""; |
| 901 | char apn_info_outbuf[LYNQ_DATA_UCI_BUF]; |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 902 | char strtmp[10][32]; |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame^] | 903 | |
| 904 | sprintf(apn_info_buf,"%s.%s.%s",LYNQ_UCI_FILE,LYNQ_DATA_UCI_APN_SECTION,LYNQ_DATA_UCI_APN_KEY); |
| 905 | ret = lynq_uci_get(apn_info_buf,apn_info_outbuf); |
| 906 | if (ret != UCI_OK) |
| 907 | { |
| 908 | LYERRLOG("Description APN failed to allocate an ID :ret = -1"); |
| 909 | return -1; |
| 910 | } |
| 911 | tmp_id_num = atoi(apn_info_outbuf); |
| 912 | fact_apn_id = -tmp_id_num; |
| 913 | tmp_id_num = tmp_id_num + 1; |
| 914 | |
| 915 | apn_info_buf[LYNQ_DATA_UCI_BUF]=""; |
| 916 | sprintf(apn_info_buf,"%s.%s.%s=%d",LYNQ_UCI_FILE,LYNQ_DATA_UCI_APN_SECTION,LYNQ_DATA_UCI_APN_KEY,tmp_id_num); |
| 917 | |
| 918 | ret = lynq_uci_set(apn_info_buf); |
| 919 | if (ret != UCI_OK) |
| 920 | { |
| 921 | LYERRLOG("Description APN failed to allocate an ID :ret = -2"); |
| 922 | return -1; |
| 923 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 924 | if (mcc == NULL) |
| 925 | { |
| 926 | sprintf(strtmp[1], "mcc=;"); |
| 927 | } |
| 928 | else |
| 929 | { |
| 930 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 931 | } |
| 932 | if (mnc == NULL) |
| 933 | { |
| 934 | sprintf(strtmp[12], "mnc=;"); |
| 935 | } |
| 936 | else |
| 937 | { |
| 938 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 939 | } |
| 940 | if (apn == NULL) |
| 941 | { |
| 942 | sprintf(strtmp[3], "apn=;"); |
| 943 | } |
| 944 | else |
| 945 | { |
| 946 | sprintf(strtmp[3], "apn=%s;", apn); |
| 947 | } |
| 948 | if (apntype == NULL) |
| 949 | { |
| 950 | sprintf(strtmp[4], "apntype=;"); |
| 951 | } |
| 952 | else |
| 953 | { |
| 954 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 955 | } |
| 956 | if (user == NULL) |
| 957 | { |
| 958 | sprintf(strtmp[5], "user=;"); |
| 959 | } |
| 960 | else |
| 961 | { |
| 962 | sprintf(strtmp[5], "user=%s;", user); |
| 963 | } |
| 964 | if (password == NULL) |
| 965 | { |
| 966 | sprintf(strtmp[6], "password=;"); |
| 967 | } |
| 968 | else |
| 969 | { |
| 970 | sprintf(strtmp[6], "password=%s;", password); |
| 971 | } |
| 972 | if (normalprotocol == NULL) |
| 973 | { |
| 974 | sprintf(strtmp[7], "normalprotocol=;"); |
| 975 | } |
| 976 | else |
| 977 | { |
| 978 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 979 | } |
| 980 | if (roamingprotocol == NULL) |
| 981 | { |
| 982 | sprintf(strtmp[8], "roamingprotocol=;"); |
| 983 | } |
| 984 | else |
| 985 | { |
| 986 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 987 | } |
| 988 | if (carrier == NULL) |
| 989 | { |
| 990 | sprintf(strtmp[9], "carrier=;"); |
| 991 | } |
| 992 | else |
| 993 | { |
| 994 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 995 | } |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame^] | 996 | sprintf(agc, "id=%d;%s%s%s%s%s%s%s%s%s",fact_apn_id, strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]); |
| 997 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | int 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) |
| 1002 | { |
| 1003 | char strtmp[10][32]; |
| 1004 | if (id == NULL) |
| 1005 | { |
| 1006 | sprintf(strtmp[0], "id=;"); |
| 1007 | } |
| 1008 | else |
| 1009 | { |
| 1010 | sprintf(strtmp[0], "id=%s;", id); |
| 1011 | } |
| 1012 | if (mcc == NULL) |
| 1013 | { |
| 1014 | sprintf(strtmp[1], "mcc=;"); |
| 1015 | } |
| 1016 | else |
| 1017 | { |
| 1018 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 1019 | } |
| 1020 | if (mnc == NULL) |
| 1021 | { |
| 1022 | sprintf(strtmp[2], "mnc=;"); |
| 1023 | } |
| 1024 | else |
| 1025 | { |
| 1026 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 1027 | } |
| 1028 | if (apn == NULL) |
| 1029 | { |
| 1030 | sprintf(strtmp[3], "apn=;"); |
| 1031 | } |
| 1032 | else |
| 1033 | { |
| 1034 | sprintf(strtmp[3], "apn=%s;", apn); |
| 1035 | } |
| 1036 | if (apntype == NULL) |
| 1037 | { |
| 1038 | sprintf(strtmp[4], "apntype=;"); |
| 1039 | } |
| 1040 | else |
| 1041 | { |
| 1042 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 1043 | } |
| 1044 | if (user == NULL) |
| 1045 | { |
| 1046 | sprintf(strtmp[5], "user=;"); |
| 1047 | } |
| 1048 | else |
| 1049 | { |
| 1050 | sprintf(strtmp[5], "user=%s;", user); |
| 1051 | } |
| 1052 | if (password == NULL) |
| 1053 | { |
| 1054 | sprintf(strtmp[6], "password=;"); |
| 1055 | } |
| 1056 | else |
| 1057 | { |
| 1058 | sprintf(strtmp[6], "password=%s;", password); |
| 1059 | } |
| 1060 | if (normalprotocol == NULL) |
| 1061 | { |
| 1062 | sprintf(strtmp[7], "normalprotocol=;"); |
| 1063 | } |
| 1064 | else |
| 1065 | { |
| 1066 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 1067 | } |
| 1068 | if (roamingprotocol == NULL) |
| 1069 | { |
| 1070 | sprintf(strtmp[8], "roamingprotocol=;"); |
| 1071 | } |
| 1072 | else |
| 1073 | { |
| 1074 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 1075 | } |
| 1076 | if (carrier == NULL) |
| 1077 | { |
| 1078 | sprintf(strtmp[9], "carrier=;"); |
| 1079 | } |
| 1080 | else |
| 1081 | { |
| 1082 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 1083 | } |
| 1084 | 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]); |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
rjw | af4b161 | 2022-06-13 17:26:01 +0800 | [diff] [blame] | 1088 | |
| 1089 | int 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) |
| 1090 | { |
| 1091 | char strtmp[10][32]; |
| 1092 | if (id == NULL) |
| 1093 | { |
| 1094 | sprintf(strtmp[0], ""); |
| 1095 | } |
| 1096 | else |
| 1097 | { |
| 1098 | sprintf(strtmp[0], "id=%s;", id); |
| 1099 | } |
| 1100 | if (mcc == NULL) |
| 1101 | { |
| 1102 | sprintf(strtmp[1], ""); |
| 1103 | } |
| 1104 | else |
| 1105 | { |
| 1106 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 1107 | } |
| 1108 | if (mnc == NULL) |
| 1109 | { |
| 1110 | sprintf(strtmp[2], ""); |
| 1111 | } |
| 1112 | else |
| 1113 | { |
| 1114 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 1115 | } |
| 1116 | if (apn == NULL) |
| 1117 | { |
| 1118 | sprintf(strtmp[3], ""); |
| 1119 | } |
| 1120 | else |
| 1121 | { |
| 1122 | sprintf(strtmp[3], "apn=%s;", apn); |
| 1123 | } |
| 1124 | if (apntype == NULL) |
| 1125 | { |
| 1126 | sprintf(strtmp[4], ""); |
| 1127 | } |
| 1128 | else |
| 1129 | { |
| 1130 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 1131 | } |
| 1132 | if (user == NULL) |
| 1133 | { |
| 1134 | sprintf(strtmp[5], ""); |
| 1135 | } |
| 1136 | else |
| 1137 | { |
| 1138 | sprintf(strtmp[5], "user=%s;", user); |
| 1139 | } |
| 1140 | if (password == NULL) |
| 1141 | { |
| 1142 | sprintf(strtmp[6], ""); |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | sprintf(strtmp[6], "password=%s;", password); |
| 1147 | } |
| 1148 | if (normalprotocol == NULL) |
| 1149 | { |
| 1150 | sprintf(strtmp[7], ""); |
| 1151 | } |
| 1152 | else |
| 1153 | { |
| 1154 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 1155 | } |
| 1156 | if (roamingprotocol == NULL) |
| 1157 | { |
| 1158 | sprintf(strtmp[8], ""); |
| 1159 | } |
| 1160 | else |
| 1161 | { |
| 1162 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 1163 | } |
| 1164 | if (carrier == NULL) |
| 1165 | { |
| 1166 | sprintf(strtmp[9], ""); |
| 1167 | } |
| 1168 | else |
| 1169 | { |
| 1170 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 1171 | } |
| 1172 | 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]); |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1176 | static char *lynqStrdupReadString(Parcel &p) |
| 1177 | { |
| 1178 | size_t stringlen; |
| 1179 | const char16_t *s16; |
| 1180 | |
| 1181 | s16 = p.readString16Inplace(&stringlen); |
| 1182 | return strndup16to8(s16, stringlen); |
| 1183 | } |
| 1184 | |
| 1185 | int 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) |
| 1186 | { |
| 1187 | if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier) |
| 1188 | { |
| 1189 | LYERRLOG("There are no valid parameters"); |
| 1190 | return -1; |
| 1191 | } |
| 1192 | lynq_client_t client; |
| 1193 | char argc[512]; |
| 1194 | char recvline[LYNQ_REC_BUF]; |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame^] | 1195 | int res = 0; |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1196 | Parcel p; |
| 1197 | if (cmd == 0) // insert apn db |
| 1198 | { |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame^] | 1199 | res = insert_apn_char(argc, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
| 1200 | if (res != UCI_OK) |
| 1201 | { |
| 1202 | LYERRLOG("Description APN failed to allocate an ID"); |
| 1203 | return -1; |
| 1204 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1205 | client.uToken = Global_uToken; |
| 1206 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1207 | client.paramLen = 2; |
| 1208 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1209 | sprintf(client.param, "%d %s", cmd, argc); |
| 1210 | } |
| 1211 | else if (cmd == 1) |
| 1212 | { |
| 1213 | if (NULL == id) |
| 1214 | { |
| 1215 | LYERRLOG("id is NULL!!!please input id: "); |
| 1216 | } |
| 1217 | sprintf(argc, "id=%s", id); |
| 1218 | client.uToken = Global_uToken; |
| 1219 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1220 | client.paramLen = 2; |
| 1221 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1222 | sprintf(client.param, "%d %s", cmd, argc); |
| 1223 | } |
| 1224 | else if (cmd == 2) |
| 1225 | { |
rjw | af4b161 | 2022-06-13 17:26:01 +0800 | [diff] [blame] | 1226 | query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1227 | client.uToken = Global_uToken; |
| 1228 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1229 | client.paramLen = 2; |
| 1230 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1231 | sprintf(client.param, "%d %s", cmd, argc); |
| 1232 | } |
| 1233 | else if (cmd == 3) |
| 1234 | { |
| 1235 | modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
| 1236 | client.uToken = Global_uToken; |
| 1237 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1238 | client.paramLen = 2; |
| 1239 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1240 | sprintf(client.param, "%d %s", cmd, argc); |
| 1241 | } |
| 1242 | else |
| 1243 | { |
| 1244 | LYERRLOG("incoming command is invalid"); |
| 1245 | return -1; |
| 1246 | } |
| 1247 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1248 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1249 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1250 | { |
| 1251 | LYERRLOG("send request fail"); |
| 1252 | return -1; |
| 1253 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1254 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1255 | waitApnResult(); |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1256 | strcpy(out, g_lynq_apn_result); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1257 | LYINFLOG(">>>>>output info:%s",out); |
| 1258 | return 0; |
| 1259 | } |
| 1260 | |
| 1261 | int lynq_reset_apn(char *result) |
| 1262 | { |
| 1263 | Parcel p; |
| 1264 | lynq_client_t client; |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1265 | if (NULL == result) |
| 1266 | { |
| 1267 | LYERRLOG("incoming paramters error"); |
| 1268 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1269 | client.uToken = Global_uToken; |
| 1270 | client.request = 2000 + 194; |
| 1271 | client.paramLen = 0; |
| 1272 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1273 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1274 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1275 | if (send_request(lynq_client_sockfd, &client) == -1) |
| 1276 | { |
| 1277 | LYERRLOG("send request fail"); |
| 1278 | return -1; |
| 1279 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1280 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1281 | waitApnResult(); |
| 1282 | strcpy(result, g_lynq_apn_result); |
| 1283 | LYINFLOG(">>>>>result:%s",result); |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1287 | /*Typethree add for T800 platform 2022/04/21 end*/ |