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 | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame^] | 59 | /**g_lynq_data_init_flag |
| 60 | * @brief mark data initialization state |
| 61 | * 0:deinit status |
| 62 | * 1:init state |
| 63 | */ |
| 64 | static int g_lynq_data_init_flag = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 65 | |
| 66 | typedef struct{ |
| 67 | char apn[LYNQ_APN_MAX_LEN]; |
| 68 | char apnType[LYNQ_APN_TYPE_MAX_LEN]; |
| 69 | char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; |
| 70 | int hasUsed; |
| 71 | int hasTimeout; |
| 72 | }lynq_apn_t; |
| 73 | lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {}; |
| 74 | lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {}; |
| 75 | int lynq_data_call = 0; |
| 76 | int millli_sleep_with_restart(int millisecond) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 77 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 78 | int left = millisecond*1000; |
| 79 | while (left > 0) |
| 80 | { |
| 81 | left = usleep(left); |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | int getLynqApnID(char apnType[]) |
| 87 | { |
| 88 | int ret = 0; |
| 89 | for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++) |
| 90 | { |
| 91 | if(strcmp(lynq_apn_table[ret].apnType,apnType)==0) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 92 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 93 | return ret; |
| 94 | } |
| 95 | } |
| 96 | return -1; |
| 97 | } |
| 98 | void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[]) |
| 99 | { |
| 100 | LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName); |
| 101 | if(apn_table==NULL) |
| 102 | { |
| 103 | LYERRLOG("apn_table is null"); |
| 104 | return; |
| 105 | } |
| 106 | memcpy(apn_table->apn,apn,strlen(apn)+1); |
| 107 | memcpy(apn_table->apnType,apntype,strlen(apntype)+1); |
| 108 | memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1); |
| 109 | apn_table->hasTimeout = 0; |
| 110 | apn_table->hasUsed = 1; |
| 111 | return; |
| 112 | } |
| 113 | void cleanOnceApnTable(int apnId) |
| 114 | { |
| 115 | LYDBGLOG("apn id:%d",apnId); |
| 116 | if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1)) |
| 117 | { |
| 118 | LYERRLOG("apn id is invalid!!!"); |
| 119 | return; |
| 120 | } |
| 121 | lynq_apn_table[apnId].hasTimeout = 0; |
| 122 | lynq_apn_table[apnId].hasUsed = 0; |
| 123 | bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN); |
| 124 | //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN); |
| 125 | bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN); |
| 126 | return; |
| 127 | } |
| 128 | int getUnusedElement() |
| 129 | { |
| 130 | for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++) |
| 131 | { |
| 132 | if(lynq_apn_table[i].hasUsed!=1) |
| 133 | { |
| 134 | return i; |
| 135 | } |
| 136 | } |
| 137 | return -1; |
| 138 | } |
| 139 | int updateApn(char apnType[]) |
| 140 | { |
| 141 | int ret = 0; |
| 142 | ret = getUnusedElement(); |
| 143 | memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1); |
| 144 | lynq_apn_table[ret].hasUsed = 1; |
| 145 | return ret; |
| 146 | } |
| 147 | |
| 148 | int waitPdnChange() |
| 149 | { |
| 150 | int ret = 0; |
| 151 | pthread_mutex_lock(&s_pdn_change_mutex); |
| 152 | ret = pthread_cond_wait(&s_pdn_change_cond,&s_pdn_change_mutex); |
| 153 | pthread_mutex_unlock(&s_pdn_change_mutex); |
| 154 | return ret; |
| 155 | } |
| 156 | int waitDataCallstateChange(int mtime) |
| 157 | { |
| 158 | int ret = 0; |
| 159 | int sec = 0; |
| 160 | int usec = 0; |
| 161 | struct timeval now; |
| 162 | struct timespec timeout; |
| 163 | gettimeofday(&now,NULL); |
| 164 | sec = mtime/1000; |
| 165 | usec = mtime%1000; |
| 166 | timeout.tv_sec = now.tv_sec+sec; |
| 167 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000; |
| 168 | pthread_mutex_lock(&s_data_call_state_change_mutex); |
| 169 | ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout); |
| 170 | pthread_mutex_unlock(&s_data_call_state_change_mutex); |
| 171 | return ret; |
| 172 | } |
| 173 | void sendSignalDataCallStateChange() |
| 174 | { |
| 175 | pthread_mutex_lock(&s_data_call_state_change_mutex); |
| 176 | pthread_cond_signal(&s_data_call_state_change_cond); |
| 177 | pthread_mutex_unlock(&s_data_call_state_change_mutex); |
| 178 | return; |
| 179 | } |
| 180 | void sendSignalPdnChange() |
| 181 | { |
| 182 | pthread_mutex_lock(&s_pdn_change_mutex); |
| 183 | pthread_cond_signal(&s_pdn_change_cond); |
| 184 | pthread_mutex_unlock(&s_pdn_change_mutex); |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | int get_response(int sockfd,Parcel &p) |
| 189 | { |
| 190 | int len = 0; |
| 191 | char recvline[LYNQ_REC_BUF]; |
| 192 | bzero(recvline,LYNQ_REC_BUF); |
| 193 | /* receive data from server */ |
| 194 | len = read(sockfd, recvline, LYNQ_REC_BUF); |
| 195 | if(len == -1) |
| 196 | { |
| 197 | perror("read error"); |
| 198 | return -1; |
| 199 | } |
| 200 | if (recvline != NULL) { |
| 201 | p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen); |
| 202 | p.setDataPosition(0); |
| 203 | } |
| 204 | return 0; |
| 205 | } |
| 206 | int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error) |
| 207 | { |
| 208 | if(p.dataAvail() > 0) |
| 209 | { |
| 210 | p.readInt32(resp_type); |
| 211 | p.readInt32(request); |
| 212 | p.readInt32(slot_id); |
| 213 | p.readInt32(error); |
| 214 | return 0; |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | return -1; |
| 219 | } |
| 220 | } |
| 221 | int send_request(int sockfd,lynq_client_t *client_tmp) |
| 222 | { |
| 223 | int ret=0; |
| 224 | ret = write(sockfd, client_tmp, LYQN_SEDN_BUF); |
| 225 | if(ret==-1) |
| 226 | { |
| 227 | perror("write error"); |
| 228 | return -1; |
| 229 | } |
| 230 | return 0; |
| 231 | } |
| 232 | static char *strdupReadString(Parcel &p) { |
| 233 | size_t stringlen; |
| 234 | const char16_t *s16; |
| 235 | s16 = p.readString16Inplace(&stringlen); |
| 236 | return strndup16to8(s16, stringlen); |
| 237 | } |
| 238 | static char *strdupReadString_p(Parcel *p) { |
| 239 | size_t stringlen; |
| 240 | const char16_t *s16; |
| 241 | s16 = p->readString16Inplace(&stringlen); |
| 242 | return strndup16to8(s16, stringlen); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /*Warren add for T800 platform 2021/11/19 start*/ |
| 247 | int lynq_socket_client_start() |
| 248 | { |
| 249 | struct sockaddr_in lynq_socket_server_addr; |
| 250 | /* init lynq_socket_server_addr */ |
| 251 | bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)); |
| 252 | lynq_socket_server_addr.sin_family = AF_INET; |
| 253 | lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT); |
| 254 | lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY); |
| 255 | /* |
| 256 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0) |
| 257 | { |
| 258 | printf("[%s] is not a valid IPaddress\n", argv[1]); |
| 259 | exit(1); |
| 260 | } |
| 261 | */ |
| 262 | lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0); |
| 263 | if(connect(lynq_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1) |
| 264 | { |
| 265 | perror("connect error"); |
| 266 | return -1; |
| 267 | } |
| 268 | return 0; |
| 269 | } |
| 270 | void *thread_urc_recv(void *parg) |
| 271 | { |
| 272 | int socket_fd = (int64_t)parg; |
| 273 | int len=0; |
| 274 | socklen_t addr_len=0; |
| 275 | uint8_t *dataLength = NULL; |
| 276 | char urc_data[LYNQ_REC_BUF]; |
| 277 | char apn[LYNQ_APN_MAX_LEN]; |
| 278 | char apnType[LYNQ_APN_TYPE_MAX_LEN]; |
| 279 | int pdnState = 0; |
| 280 | char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; |
| 281 | int slot_id = -1; |
| 282 | int resp_type = -1; |
| 283 | int urcid = -1; |
| 284 | char *urc_msg = NULL; |
| 285 | Parcel *p = NULL; |
| 286 | struct sockaddr_in dest_addr; |
| 287 | LYINFLOG("thread_urc_recv in running....\n"); |
| 288 | while(data_urc_recive_status) |
| 289 | { |
| 290 | bzero(urc_data,LYNQ_REC_BUF); |
| 291 | //get data msg |
| 292 | len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len); |
| 293 | if(len <= 0) |
| 294 | { |
| 295 | perror("thread_urc_recv step2 fail:"); |
| 296 | millli_sleep_with_restart(1); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 297 | break; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 298 | } |
| 299 | LYDBGLOG("=====>urc data len<=====:%d\n",len); |
| 300 | p = new Parcel(); |
| 301 | if(p==NULL) |
| 302 | { |
| 303 | RLOGD("new parcel failure!!!"); |
| 304 | break; |
| 305 | } |
| 306 | p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen); |
| 307 | p->setDataPosition(0); |
| 308 | if(p->dataAvail() > 0) |
| 309 | { |
| 310 | p->readInt32(&resp_type); |
| 311 | p->readInt32(&urcid); |
| 312 | p->readInt32(&slot_id); |
| 313 | //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); |
| 314 | switch (urcid) |
| 315 | { |
| 316 | case 9003://LYNQ_URC_DATA_CALL_STATUS_IND |
| 317 | { |
| 318 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); |
| 319 | p->readInt32(&pdnState); |
| 320 | bzero(apn,LYNQ_APN_MAX_LEN); |
| 321 | bzero(apnType,LYNQ_APN_TYPE_MAX_LEN); |
| 322 | bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN); |
| 323 | if(pdnState!=4)//PDN_DISCONNECTED |
| 324 | { |
| 325 | urc_msg = strdupReadString_p(p); |
| 326 | int len = strlen(urc_msg); |
| 327 | if(len < LYNQ_APN_MAX_LEN-1) |
| 328 | { |
| 329 | memcpy(apn,urc_msg,len+1); |
| 330 | } |
| 331 | urc_msg = strdupReadString_p(p); |
| 332 | len = strlen(urc_msg); |
| 333 | if(len < LYNQ_APN_TYPE_MAX_LEN-1) |
| 334 | { |
| 335 | memcpy(apnType,urc_msg,len+1); |
| 336 | } |
| 337 | urc_msg = strdupReadString_p(p); |
| 338 | len = strlen(urc_msg); |
| 339 | if(len < LYNQ_IFACE_NAME_MAX_LEN-1) |
| 340 | { |
| 341 | memcpy(ifaceName,urc_msg,strlen(urc_msg)+1); |
| 342 | } |
| 343 | //sendSignalDataCallStateChange(); |
| 344 | int apnId = getLynqApnID(apnType); |
| 345 | if(apnId >= 0) |
| 346 | { |
| 347 | if(lynq_apn_table[apnId].hasTimeout==1) |
| 348 | { |
| 349 | LYERRLOG("apn:%s has time out",lynq_apn_table[apnId].apn); |
| 350 | lynq_deactive_data_call(&apnId); |
| 351 | continue; |
| 352 | } |
| 353 | updateApnTable(&lynq_apn_table[apnId], apn,apnType,ifaceName); |
| 354 | } |
| 355 | lynq_data_call_change_id = apnId; |
| 356 | sendSignalPdnChange(); |
| 357 | LYDBGLOG("data call state:%d",lynq_data_call); |
| 358 | if(lynq_data_call==1) |
| 359 | { |
| 360 | sendSignalDataCallStateChange(); |
| 361 | lynq_data_call = 0; |
| 362 | } |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | urc_msg = strdupReadString_p(p); |
| 367 | len = strlen(urc_msg); |
| 368 | if(len < LYNQ_APN_TYPE_MAX_LEN-1) |
| 369 | { |
| 370 | memcpy(apnType,urc_msg,len+1); |
| 371 | } |
| 372 | LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType); |
| 373 | int apnId = getLynqApnID(apnType); |
| 374 | if(apnId >= 0) |
| 375 | { |
| 376 | lynq_data_call_change_id = apnId; |
| 377 | bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean |
| 378 | } |
| 379 | sendSignalPdnChange(); |
| 380 | LYDBGLOG("data call state:%d",lynq_data_call); |
| 381 | if(lynq_data_call==1) |
| 382 | { |
| 383 | sendSignalDataCallStateChange(); |
| 384 | lynq_data_call = 0; |
| 385 | } |
| 386 | } |
| 387 | break; |
| 388 | } |
| 389 | default: |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | delete p; |
| 394 | p = NULL; |
| 395 | } |
| 396 | close(socket_fd); |
| 397 | } |
| 398 | int lynq_socket_urc_start() |
| 399 | { |
| 400 | int socket_fd=0; |
| 401 | int rt=0; |
| 402 | int len=0; |
| 403 | int on=1; |
| 404 | struct sockaddr_in urc_local_addr; |
| 405 | pthread_attr_t attr; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 406 | socket_fd = socket(AF_INET,SOCK_DGRAM,0); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 407 | if(socket_fd < 0) |
| 408 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 409 | perror("creaet socket for udp fail"); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 410 | return -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 411 | } |
| 412 | urc_local_addr.sin_family = AF_INET; |
| 413 | urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT); |
| 414 | urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY); |
| 415 | /* 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] | 416 | rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on); |
| 417 | if(rt<0) |
| 418 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 419 | perror("SO_REUSEADDR fail\n"); |
| 420 | return -1; |
| 421 | } |
| 422 | rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr)); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 423 | if (rt == -1) |
| 424 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 425 | perror("bind failed"); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 426 | return -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 427 | } |
| 428 | pthread_attr_init(&attr); |
| 429 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 430 | rt = pthread_create(&lynq_data_tid,&attr,thread_urc_recv,(void *)socket_fd); |
| 431 | if(rt < 0) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 432 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 433 | LYERRLOG("urc loop failure!!!\n"); |
| 434 | return -1; |
| 435 | } |
| 436 | LYDBGLOG("urc loop success!!!\n"); |
| 437 | return 0; |
| 438 | } |
| 439 | int lynq_init_data(int uToken) |
| 440 | { |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame^] | 441 | if (g_lynq_data_init_flag == 1) |
| 442 | { |
| 443 | LYERRLOG("init twice is not allowed"); |
| 444 | return -1; |
| 445 | } |
| 446 | g_lynq_data_init_flag = 1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 447 | int result = 0; |
| 448 | Global_uToken = uToken; |
| 449 | data_urc_recive_status = 1; |
| 450 | LYLOGSET(LOG_INFO); |
| 451 | LYLOGEINIT(USER_LOG_TAG); |
| 452 | result = lynq_socket_client_start(); |
| 453 | if(result!=0) |
| 454 | { |
| 455 | LYERRLOG("init socket client fail!!!"); |
| 456 | return -1; |
| 457 | } |
| 458 | result = lynq_socket_urc_start(); |
| 459 | if(result!=0) |
| 460 | { |
| 461 | LYERRLOG("init socket urc fail!!!"); |
| 462 | return -1; |
| 463 | } |
| 464 | memset(lynq_apn_table,0,sizeof(lynq_apn_table)); |
| 465 | LYDBGLOG("lynq init call success!!!"); |
| 466 | return 0; |
| 467 | |
| 468 | } |
| 469 | int lynq_deinit_data() |
| 470 | { |
| 471 | int ret = -1; |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame^] | 472 | if (g_lynq_data_init_flag == 0) |
| 473 | { |
| 474 | LYERRLOG("deinit twice is not allowed"); |
| 475 | return ret; |
| 476 | } |
| 477 | g_lynq_data_init_flag = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 478 | for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++) |
| 479 | { |
| 480 | if(strlen(lynq_apn_table[i].apnType)!=0) |
| 481 | { |
| 482 | lynq_deactive_data_call(&i); |
| 483 | } |
| 484 | } |
| 485 | if(lynq_client_sockfd>0) |
| 486 | { |
| 487 | close(lynq_client_sockfd); |
| 488 | } |
| 489 | data_urc_recive_status = 0; |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame^] | 490 | if (lynq_data_tid > 0) |
| 491 | { |
| 492 | ret = pthread_cancel(lynq_data_tid); |
| 493 | LYDBGLOG("pthread cancel ret = %d",ret); |
| 494 | ret = pthread_join(lynq_data_tid,NULL); |
| 495 | LYDBGLOG("pthread join ret = %d",ret); |
| 496 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 497 | return 0; |
| 498 | } |
| 499 | int lynq_setup_data_call(int *handle) |
| 500 | { |
| 501 | Parcel p; |
| 502 | lynq_client_t client; |
| 503 | int resp_type = -1; |
| 504 | int request = -1; |
| 505 | int slot_id = -1; |
| 506 | int error = -1; |
| 507 | char iface = NULL; |
| 508 | int lynq_data_call_id = 0; |
| 509 | if(handle==NULL) |
| 510 | { |
| 511 | LYERRLOG("handle is null!!!"); |
| 512 | return LYNQ_E_NULL_ANONALY; |
| 513 | } |
| 514 | client.uToken = Global_uToken; |
| 515 | client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL |
| 516 | client.paramLen = 0; |
| 517 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 518 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 519 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 520 | { |
| 521 | LYERRLOG("send request fail"); |
| 522 | perror("[LYNQ_DATA] send request fail:"); |
| 523 | return -1; |
| 524 | } |
| 525 | get_response(lynq_client_sockfd,p); |
| 526 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 527 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 528 | lynq_data_call_id = updateApn("default"); |
| 529 | lynq_data_call = 1; |
| 530 | if(error==0) |
| 531 | { |
| 532 | if(waitDataCallstateChange(20000)==ETIMEDOUT)//20s |
| 533 | { |
| 534 | error = LYNQ_E_TIME_OUT; |
| 535 | LYERRLOG("timeout:wait data Call state fail!!!"); |
| 536 | lynq_apn_table[lynq_data_call_id].hasTimeout = 1; |
| 537 | return error; |
| 538 | } |
| 539 | *handle = lynq_data_call_id; |
| 540 | } |
| 541 | return error; |
| 542 | } |
| 543 | int lynq_deactive_data_call(int *handle) |
| 544 | { |
| 545 | Parcel p; |
| 546 | lynq_client_t client; |
| 547 | int resp_type = -1; |
| 548 | int request = -1; |
| 549 | int slot_id = -1; |
| 550 | int error = -1; |
| 551 | int lynq_data_call_id = -1; |
| 552 | lynq_data_call_id = *handle; |
| 553 | if(handle==NULL) |
| 554 | { |
| 555 | LYERRLOG("handle is null!!!"); |
| 556 | return -1; |
| 557 | } |
| 558 | client.uToken = Global_uToken; |
| 559 | client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL |
| 560 | if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0) |
| 561 | { |
| 562 | client.paramLen = 0; |
| 563 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 564 | } |
| 565 | else |
| 566 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 567 | client.paramLen = 1; |
| 568 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 569 | sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType); |
| 570 | } |
| 571 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 572 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 573 | { |
| 574 | LYERRLOG("send request fail"); |
| 575 | perror("[LYNQ_DATA] send request fail:"); |
| 576 | return -1; |
| 577 | } |
| 578 | get_response(lynq_client_sockfd,p); |
| 579 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 580 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 581 | cleanOnceApnTable(lynq_data_call_id); |
| 582 | return error; |
| 583 | } |
| 584 | int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol) |
| 585 | { |
| 586 | Parcel p; |
| 587 | lynq_client_t client; |
| 588 | int resp_type = -1; |
| 589 | int request = -1; |
| 590 | int slot_id = -1; |
| 591 | int error = -1; |
| 592 | char iface = NULL; |
| 593 | int lynq_data_call_id = -1; |
| 594 | char *argv[10] = {}; |
| 595 | if(handle==NULL||apn==NULL||apnType==NULL) |
| 596 | { |
| 597 | LYERRLOG("handle ,apn or apntype is null!!!"); |
| 598 | return -1; |
| 599 | } |
| 600 | if(user==NULL) |
| 601 | { |
| 602 | argv[1] = "null"; |
| 603 | } |
| 604 | else |
| 605 | { |
| 606 | argv[1] = user; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 607 | } |
| 608 | if(password==NULL) |
| 609 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 610 | argv[2] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 611 | } |
| 612 | else |
| 613 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 614 | argv[2] = password; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 615 | } |
| 616 | if(authType==NULL) |
| 617 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 618 | argv[3] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 619 | } |
| 620 | else |
| 621 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 622 | argv[3] = authType; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 623 | } |
| 624 | if(normalProtocol==NULL) |
| 625 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 626 | argv[4] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 627 | } |
| 628 | else |
| 629 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 630 | argv[4] = normalProtocol; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 631 | } |
| 632 | if(roamingProtocol==NULL) |
| 633 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 634 | argv[5] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 635 | } |
| 636 | else |
| 637 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 638 | argv[5] = roamingProtocol; |
| 639 | } |
| 640 | client.uToken = Global_uToken; |
| 641 | client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL |
| 642 | client.paramLen = 7; |
| 643 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 644 | sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]); |
| 645 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 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); |
| 653 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 654 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 655 | lynq_data_call_id = updateApn(apnType); |
| 656 | lynq_data_call = 1; |
| 657 | if(error==0) |
| 658 | { |
| 659 | if(waitDataCallstateChange(20000)==ETIMEDOUT)//20s |
| 660 | { |
| 661 | error = LYNQ_E_TIME_OUT; |
| 662 | LYERRLOG("timeout:wait data Call state fail!!!"); |
| 663 | lynq_apn_table[lynq_data_call_id].hasTimeout = 1; |
| 664 | return error; |
| 665 | } |
| 666 | *handle = lynq_data_call_id; |
| 667 | } |
| 668 | return error; |
| 669 | } |
| 670 | /* |
| 671 | int lynq_deactive_data_call_sp(int *handle,char *apnType) |
| 672 | { |
| 673 | Parcel p; |
| 674 | lynq_client_t client; |
| 675 | int resp_type = -1; |
| 676 | int request = -1; |
| 677 | int slot_id = -1; |
| 678 | int error = -1; |
| 679 | if(handle==NULL||apnType==NULL) |
| 680 | { |
| 681 | LYERRLOG("handle is null!!!"); |
| 682 | return -1; |
| 683 | } |
| 684 | client.uToken = Global_uToken; |
| 685 | client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL |
| 686 | client.paramLen = 1; |
| 687 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 688 | sprintf(client.param,"%s",apnType); |
| 689 | LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 690 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 691 | { |
| 692 | LYERRLOG("send request fail"); |
| 693 | perror("[LYNQ_DATA] send request fail:"); |
| 694 | return -1; |
| 695 | } |
| 696 | get_response(lynq_client_sockfd,p); |
| 697 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 698 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 699 | return error; |
| 700 | } |
| 701 | */ |
| 702 | int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum) |
| 703 | { |
| 704 | Parcel p; |
| 705 | lynq_client_t client; |
| 706 | int resp_type = -1; |
| 707 | int request = -1; |
| 708 | int slot_id = -1; |
| 709 | int error = -1; |
| 710 | int version =0; |
| 711 | int num = 0; |
| 712 | int temp_int =0; |
| 713 | char *temp_char = NULL; |
| 714 | if(dataCallList==NULL) |
| 715 | { |
| 716 | LYERRLOG("dataCallList is null!!!"); |
| 717 | return -1; |
| 718 | } |
| 719 | client.uToken = Global_uToken; |
| 720 | client.request = 57;//RIL_REQUEST_DATA_CALL_LIST |
| 721 | client.paramLen = 0; |
| 722 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 723 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 724 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 725 | { |
| 726 | LYERRLOG("send request fail"); |
| 727 | perror("[LYNQ_DATA] send request fail:"); |
| 728 | return -1; |
| 729 | } |
| 730 | get_response(lynq_client_sockfd,p); |
| 731 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
| 732 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 733 | p.readInt32(&version); |
| 734 | if(version==11) |
| 735 | { |
| 736 | p.readInt32(&num); |
| 737 | *realNum = num; |
| 738 | for (int i = 0; i < num; i++) |
| 739 | { |
| 740 | p.readInt32(&dataCallList[i].status); |
| 741 | p.readInt32(&dataCallList[i].suggestedRetryTime); |
| 742 | p.readInt32(&dataCallList[i].cid); |
| 743 | p.readInt32(&dataCallList[i].active); |
| 744 | temp_char = strdupReadString(p); |
| 745 | memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1); |
| 746 | temp_char = strdupReadString(p); |
| 747 | memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1); |
| 748 | temp_char = strdupReadString(p); |
| 749 | memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1); |
| 750 | temp_char = strdupReadString(p); |
| 751 | memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1); |
| 752 | temp_char = strdupReadString(p); |
| 753 | memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1); |
| 754 | temp_char = strdupReadString(p); |
| 755 | memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1); |
| 756 | p.readInt32(&dataCallList[i].mtu); |
| 757 | } |
| 758 | } |
| 759 | return error; |
| 760 | } |
| 761 | int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList) |
| 762 | { |
| 763 | lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={}; |
| 764 | int number = 0; |
| 765 | int lynq_data_call_id = 0; |
| 766 | int error = 0; |
| 767 | lynq_data_call_id = *handle; |
| 768 | if(handle==NULL) |
| 769 | { |
| 770 | LYERRLOG("handle is NULL"); |
| 771 | return LYNQ_E_NULL_ANONALY; |
| 772 | } |
| 773 | memset(interDataCallList,0,sizeof(interDataCallList)); |
| 774 | error = getDataCallLists(interDataCallList,&number); |
| 775 | if(error == 0) |
| 776 | { |
| 777 | for(int i = 0;i < number;i++) |
| 778 | { |
| 779 | if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0) |
| 780 | { |
| 781 | dataCallList->active = interDataCallList[i].active; |
| 782 | dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime; |
| 783 | dataCallList->cid = interDataCallList[i].cid; |
| 784 | dataCallList->status = interDataCallList[i].status; |
| 785 | dataCallList->mtu = interDataCallList[i].mtu; |
| 786 | memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses)); |
| 787 | memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname)); |
| 788 | memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses)); |
| 789 | memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type)); |
| 790 | memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways)); |
| 791 | memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf)); |
| 792 | LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses); |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | return error; |
| 797 | } |
| 798 | int lynq_wait_data_call_state_change(int *handle) |
| 799 | { |
| 800 | waitPdnChange(); |
| 801 | *handle = lynq_data_call_change_id; |
| 802 | LYINFLOG("lynq data call id:%d",lynq_data_call_change_id); |
| 803 | return 0; |
| 804 | } |
| 805 | /*Warren add for T800 platform 2021/11/19 end*/ |