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