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