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