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