b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <errno.h> |
| 5 | #include <sys/socket.h> |
| 6 | #include <sys/un.h> |
| 7 | #include <netinet/in.h> |
| 8 | #include <pthread.h> |
| 9 | #include <sys/epoll.h> |
| 10 | #include <fcntl.h> |
| 11 | #include <signal.h> |
| 12 | #include <cutils/properties.h> |
| 13 | #include <arpa/inet.h> |
| 14 | |
| 15 | #include "mbtk_type.h" |
| 16 | #include "mbtk_ril.h" |
| 17 | #include "atchannel.h" |
| 18 | #include "at_tok.h" |
| 19 | #include "mbtk_utils.h" |
| 20 | #include "ril_info.h" |
| 21 | #include "mbtk_str.h" |
| 22 | |
| 23 | extern ril_band_info_t band_info; |
| 24 | void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len); |
| 25 | static int req_apn_get(mbtk_apn_info_array_t *apns, int *cme_err); |
| 26 | static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err); |
| 27 | static void apn_prop_get(ril_apn_info_array_t *apns); |
| 28 | |
| 29 | void apn_auto_conf_from_prop() |
| 30 | { |
| 31 | ril_apn_info_array_t apns; |
| 32 | int i = 0; |
| 33 | memset(&apns, 0, sizeof(ril_apn_info_array_t)); |
| 34 | apn_prop_get(&apns); |
| 35 | while(i < apns.num) { |
| 36 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 37 | if(req_apn_set(&(apns.apns[i]), &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 38 | { |
| 39 | LOGD("Set APN fail."); |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | LOGD("Set APN - %d success.", apns.apns[i].cid); |
| 44 | } |
| 45 | i++; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | static bool apn_conf_support(mbtk_ril_cid_enum cid) |
| 50 | { |
| 51 | if(cid == MBTK_RIL_CID_DEF) { |
| 52 | /* |
| 53 | uci show wan_default.default.enable |
| 54 | wan_default.default.enable='1' |
| 55 | |
| 56 | uci get wan_default.default.enable |
| 57 | 1 |
| 58 | */ |
| 59 | char buff[128] = {0}; |
| 60 | if(mbtk_cmd_line("uci get wan_default.default.enable", buff, sizeof(buff)) && strlen(buff) > 0) { |
| 61 | return buff[0] == '1' ? FALSE : TRUE; |
| 62 | } |
| 63 | } |
| 64 | return TRUE; |
| 65 | } |
| 66 | |
| 67 | static int apn_cid_reset(mbtk_apn_info_t *apn) |
| 68 | { |
| 69 | // Delete apn |
| 70 | if(str_empty(apn->apn)) { |
| 71 | if(apn->cid == MBTK_RIL_CID_NUL) |
| 72 | return -1; |
| 73 | |
| 74 | if(!apn_conf_support(MBTK_RIL_CID_DEF) && apn->cid == MBTK_RIL_CID_DEF) |
| 75 | return -1; |
| 76 | |
| 77 | mbtk_apn_info_array_t apns; |
| 78 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 79 | memset(&apns, 0, sizeof(mbtk_apn_info_array_t)); |
| 80 | if(req_apn_get(&apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 81 | { |
| 82 | LOGW("Get APN fail."); |
| 83 | return 0; |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | int index = 0; |
| 88 | while(index < apns.num) { |
| 89 | if(apns.apns[index].cid == apn->cid) |
| 90 | return 0; |
| 91 | index++; |
| 92 | } |
| 93 | return -1; |
| 94 | } |
| 95 | } else { |
| 96 | if(apn->cid == MBTK_RIL_CID_NUL) { |
| 97 | int start_cid; |
| 98 | bool asr_auto_call_open = !apn_conf_support(MBTK_RIL_CID_DEF); |
| 99 | mbtk_apn_info_array_t apns; |
| 100 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 101 | if(asr_auto_call_open) { |
| 102 | start_cid = MBTK_RIL_CID_2; |
| 103 | } else { |
| 104 | start_cid = MBTK_APN_CID_MIN; |
| 105 | } |
| 106 | memset(&apns, 0, sizeof(mbtk_apn_info_array_t)); |
| 107 | if(req_apn_get(&apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 108 | { |
| 109 | LOGW("Get APN fail."); |
| 110 | apn->cid = start_cid; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | for(; start_cid <= MBTK_APN_CID_MAX; start_cid++) { |
| 115 | int index = 0; |
| 116 | while(index < apns.num) { |
| 117 | if(apns.apns[index].cid == start_cid) |
| 118 | break; |
| 119 | index++; |
| 120 | } |
| 121 | |
| 122 | if(index == apns.num) { // Found not used cid : start_cid. |
| 123 | LOGD("Change CID : %d -> %d", apn->cid, start_cid); |
| 124 | apn->cid = start_cid; |
| 125 | return 0; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | if(start_cid > MBTK_APN_CID_MAX) { |
| 130 | LOGE("APN full."); |
| 131 | return -1; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static void apn_prop_get(ril_apn_info_array_t *apns) |
| 140 | { |
| 141 | char prop_name[20] = {0}; |
| 142 | char prop_data[300] = {0}; |
| 143 | int cid; |
| 144 | memset(apns, 0, sizeof(ril_apn_info_array_t)); |
| 145 | bool asr_auto_call_open = !apn_conf_support(MBTK_RIL_CID_DEF); |
| 146 | |
| 147 | // If auto data call is open,the default route is CID 1. |
| 148 | if(asr_auto_call_open) { |
| 149 | apns->cid_for_def_route = MBTK_RIL_CID_DEF; |
| 150 | cid = MBTK_RIL_CID_2; |
| 151 | } else { |
| 152 | if(property_get(MBTK_DEF_ROUTE_CID, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 153 | apns->cid_for_def_route = (mbtk_ril_cid_enum)atoi(prop_data); |
| 154 | } |
| 155 | cid = MBTK_APN_CID_MIN; |
| 156 | } |
| 157 | for(; cid <= MBTK_APN_CID_MAX; cid++) { |
| 158 | memset(prop_name, 0, 20); |
| 159 | memset(prop_data, 0, 300); |
| 160 | |
| 161 | sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid); |
| 162 | // ip_type,auth,auto_data_call,apn,user,pass |
| 163 | if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 164 | apns->apns[apns->num].cid = (mbtk_ril_cid_enum)cid; |
| 165 | char *ptr_1 = prop_data; |
| 166 | apns->apns[apns->num].ip_type = (mbtk_ip_type_enum)atoi(ptr_1); |
| 167 | ptr_1 = strstr(ptr_1, ","); |
| 168 | if(!ptr_1) { |
| 169 | continue; |
| 170 | } |
| 171 | ptr_1++; // Jump ',' to auth |
| 172 | |
| 173 | apns->apns[apns->num].auth = (mbtk_apn_auth_type_enum)atoi(ptr_1); |
| 174 | ptr_1 = strstr(ptr_1, ","); |
| 175 | if(!ptr_1) { |
| 176 | continue; |
| 177 | } |
| 178 | ptr_1++; // Jump ',' to auto_data_call |
| 179 | |
| 180 | apns->apns[apns->num].auto_boot_call = (uint8)atoi(ptr_1); |
| 181 | ptr_1 = strstr(ptr_1, ","); |
| 182 | if(!ptr_1) { |
| 183 | continue; |
| 184 | } |
| 185 | ptr_1++; // Jump ',' to apn |
| 186 | |
| 187 | char *ptr_2 = strstr(ptr_1, ","); |
| 188 | if(!ptr_2) { |
| 189 | continue; |
| 190 | } |
| 191 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 192 | memcpy(apns->apns[apns->num].apn, ptr_1, ptr_2 - ptr_1); // apn |
| 193 | } |
| 194 | |
| 195 | ptr_2++; // Jump ',' to user |
| 196 | ptr_1 = strstr(ptr_2, ","); |
| 197 | if(!ptr_1) { |
| 198 | continue; |
| 199 | } |
| 200 | if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL" |
| 201 | memcpy(apns->apns[apns->num].user, ptr_2, ptr_1 - ptr_2); // user |
| 202 | } |
| 203 | |
| 204 | ptr_1++; // Jump ',' to pass |
| 205 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 206 | memcpy(apns->apns[apns->num].pass, ptr_1, strlen(ptr_1)); // pass |
| 207 | } |
| 208 | |
| 209 | apns->num++; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | static int apn_prop_get_by_cid(mbtk_ril_cid_enum cid, mbtk_apn_info_t *apn) |
| 215 | { |
| 216 | char prop_name[20] = {0}; |
| 217 | char prop_data[300] = {0}; |
| 218 | memset(apn, 0, sizeof(mbtk_apn_info_t)); |
| 219 | |
| 220 | sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid); |
| 221 | // ip_type,auth,auto_data_call,apn,user,pass |
| 222 | if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 223 | apn->cid = cid; |
| 224 | apn->auto_save = (uint8)1; |
| 225 | char *ptr_1 = prop_data; |
| 226 | apn->ip_type = (mbtk_ip_type_enum)atoi(ptr_1); |
| 227 | ptr_1 = strstr(ptr_1, ","); |
| 228 | if(!ptr_1) { |
| 229 | return -1; |
| 230 | } |
| 231 | ptr_1++; // Jump ',' to auth |
| 232 | |
| 233 | apn->auth = (mbtk_apn_auth_type_enum)atoi(ptr_1); |
| 234 | ptr_1 = strstr(ptr_1, ","); |
| 235 | if(!ptr_1) { |
| 236 | return -1; |
| 237 | } |
| 238 | ptr_1++; // Jump ',' to auto_data_call |
| 239 | |
| 240 | apn->auto_boot_call = (uint8)atoi(ptr_1); |
| 241 | ptr_1 = strstr(ptr_1, ","); |
| 242 | if(!ptr_1) { |
| 243 | return -1; |
| 244 | } |
| 245 | ptr_1++; // Jump ',' to apn |
| 246 | |
| 247 | char *ptr_2 = strstr(ptr_1, ","); |
| 248 | if(!ptr_2) { |
| 249 | return -1; |
| 250 | } |
| 251 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 252 | memcpy(apn->apn, ptr_1, ptr_2 - ptr_1); // apn |
| 253 | } |
| 254 | |
| 255 | ptr_2++; // Jump ',' to user |
| 256 | ptr_1 = strstr(ptr_2, ","); |
| 257 | if(!ptr_1) { |
| 258 | return -1; |
| 259 | } |
| 260 | if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL" |
| 261 | memcpy(apn->user, ptr_2, ptr_1 - ptr_2); // user |
| 262 | } |
| 263 | |
| 264 | ptr_1++; // Jump ',' to pass |
| 265 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 266 | memcpy(apn->pass, ptr_1, strlen(ptr_1)); // pass |
| 267 | } |
| 268 | return 0; |
| 269 | } |
| 270 | return -1; |
| 271 | } |
| 272 | |
| 273 | static int apn_prop_set(mbtk_apn_info_t *apn) |
| 274 | { |
| 275 | char prop_name[20] = {0}; |
| 276 | char prop_data[300] = {0}; |
| 277 | int ret = -1; |
| 278 | if(apn->auto_save) { |
| 279 | sprintf(prop_name, "%s_%d", MBTK_APN_PROP, apn->cid); |
| 280 | // Delete apn |
| 281 | if(!str_empty(apn->apn)) { |
| 282 | snprintf(prop_data, 300, "%d,%d,%d,%s,%s,%s", apn->ip_type, apn->auth, apn->auto_boot_call, |
| 283 | apn->apn, |
| 284 | str_empty(apn->user) ? "NULL" : apn->user, |
| 285 | str_empty(apn->pass) ? "NULL" : apn->pass); |
| 286 | } |
| 287 | |
| 288 | ret = property_set(prop_name, prop_data); |
| 289 | } |
| 290 | |
| 291 | if(apn->def_route) { |
| 292 | memset(prop_data, 0, sizeof(prop_data)); |
| 293 | prop_data[0] = '0' + apn->cid; |
| 294 | ret = property_set(MBTK_DEF_ROUTE_CID, prop_data); |
| 295 | } |
| 296 | return ret; |
| 297 | } |
| 298 | |
| 299 | static int apn_prop_reset(mbtk_data_call_info_t *data_info) |
| 300 | { |
| 301 | mbtk_apn_info_t apn; |
| 302 | if(apn_prop_get_by_cid(data_info->cid, &apn)) { |
| 303 | return -1; |
| 304 | } else { |
| 305 | apn.auto_boot_call = data_info->auto_boot_call; |
| 306 | apn.def_route = data_info->def_route; |
| 307 | return apn_prop_set(&apn); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | |
| 312 | /* |
| 313 | AT+COPS=? |
| 314 | |
| 315 | +COPS: (2, "CHN-CT", "CT", "46011", 7),(3, "CHN-UNICOM", "UNICOM", "46001", 7),(3, "CHINA MOBILE", "CMCC", "46000", 0),(3, "CHINA MOBILE", "CMCC", "46000", 7),(3, "China Broadnet", "CBN", "46015", 7),,(0,1,2,3,4),(0,1,2) |
| 316 | |
| 317 | OK |
| 318 | */ |
| 319 | static int req_available_net_get(mbtk_net_info_array_t* nets, int *cme_err) |
| 320 | { |
| 321 | ATResponse *response = NULL; |
| 322 | int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response); |
| 323 | |
| 324 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 325 | if(cme_err) { |
| 326 | *cme_err = at_get_cme_error(response); |
| 327 | } |
| 328 | goto exit; |
| 329 | } |
| 330 | char *line_ptr = response->p_intermediates->line; |
| 331 | if(line_ptr == NULL) { |
| 332 | LOG("line is NULL"); |
| 333 | err = -1; |
| 334 | goto exit; |
| 335 | } |
| 336 | //LOG("Line:%s",line_ptr); |
| 337 | line_ptr = strstr(line_ptr, "("); |
| 338 | while(line_ptr) { |
| 339 | line_ptr++; |
| 340 | // Only for available/current net. |
| 341 | if(*line_ptr == '1' || *line_ptr == '2' || *line_ptr == '3') { |
| 342 | nets->net_info[nets->num].net_state = (uint8)atoi(line_ptr); // net_state |
| 343 | |
| 344 | line_ptr = strstr(line_ptr, ","); |
| 345 | if(line_ptr == NULL) { |
| 346 | err = -1; |
| 347 | goto exit; |
| 348 | } |
| 349 | line_ptr++; |
| 350 | |
| 351 | line_ptr = strstr(line_ptr, ","); |
| 352 | if(line_ptr == NULL) { |
| 353 | err = -1; |
| 354 | goto exit; |
| 355 | } |
| 356 | line_ptr++; |
| 357 | |
| 358 | line_ptr = strstr(line_ptr, ","); |
| 359 | if(line_ptr == NULL) { |
| 360 | err = -1; |
| 361 | goto exit; |
| 362 | } |
| 363 | |
| 364 | while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"')) |
| 365 | line_ptr++; |
| 366 | |
| 367 | // set sel_mode to 0 |
| 368 | nets->net_info[nets->num].net_sel_mode = (uint8)0; |
| 369 | // Point to "46000" |
| 370 | //LOG("PLMN:%s",line_ptr); |
| 371 | //sleep(1); |
| 372 | //uint32_2_byte((uint32)atoi(line_ptr), buff_ptr + 3, false); // plmn |
| 373 | nets->net_info[nets->num].plmn = (uint32)atoi(line_ptr); |
| 374 | |
| 375 | line_ptr = strstr(line_ptr, ","); |
| 376 | if(line_ptr == NULL) { |
| 377 | err = -1; |
| 378 | goto exit; |
| 379 | } |
| 380 | |
| 381 | while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ')) |
| 382 | line_ptr++; |
| 383 | |
| 384 | // Point to "7" |
| 385 | if(*line_ptr == '\0') { |
| 386 | err = -1; |
| 387 | goto exit; |
| 388 | } |
| 389 | //LOG("Type:%s",line_ptr); |
| 390 | //sleep(1); |
| 391 | nets->net_info[nets->num].net_type = (uint8)atoi(line_ptr); // net_type |
| 392 | |
| 393 | nets->num++; |
| 394 | } |
| 395 | |
| 396 | line_ptr = strstr(line_ptr, "("); |
| 397 | } |
| 398 | exit: |
| 399 | at_response_free(response); |
| 400 | return err; |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | AT+COPS? |
| 405 | +COPS: 1 |
| 406 | |
| 407 | OK |
| 408 | |
| 409 | or |
| 410 | |
| 411 | AT+COPS? |
| 412 | +COPS: 0,2,"46001",7 |
| 413 | |
| 414 | OK |
| 415 | |
| 416 | */ |
| 417 | static int req_net_sel_mode_get(mbtk_net_info_t *net, int *cme_err) |
| 418 | { |
| 419 | //LOG("req_net_sel_mode_get() 0"); |
| 420 | //sleep(1); |
| 421 | ATResponse *response = NULL; |
| 422 | int tmp_int; |
| 423 | char *tmp_ptr = NULL; |
| 424 | int err = at_send_command_singleline("AT+COPS?", "+COPS:", &response); |
| 425 | //LOG("req_net_sel_mode_get() 00"); |
| 426 | //sleep(1); |
| 427 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 428 | if(cme_err != NULL) |
| 429 | *cme_err = at_get_cme_error(response); |
| 430 | err = -1; |
| 431 | goto exit; |
| 432 | } |
| 433 | //LOG("req_net_sel_mode_get() 1"); |
| 434 | //sleep(1); |
| 435 | char *line = response->p_intermediates->line; |
| 436 | if(line == NULL) { |
| 437 | LOG("line is NULL"); |
| 438 | goto exit; |
| 439 | } |
| 440 | //LOG("req_net_sel_mode_get() 2"); |
| 441 | //sleep(1); |
| 442 | err = at_tok_start(&line); |
| 443 | if (err < 0) |
| 444 | { |
| 445 | goto exit; |
| 446 | } |
| 447 | //LOG("req_net_sel_mode_get() 3"); |
| 448 | //sleep(1); |
| 449 | err = at_tok_nextint(&line, &tmp_int); |
| 450 | if (err < 0) |
| 451 | { |
| 452 | goto exit; |
| 453 | } |
| 454 | net->net_sel_mode = (uint8)tmp_int; |
| 455 | //LOG("req_net_sel_mode_get() 4"); |
| 456 | //sleep(1); |
| 457 | // +COPS: 1 |
| 458 | if(!at_tok_hasmore(&line)) { |
| 459 | goto exit; |
| 460 | } |
| 461 | //LOG("req_net_sel_mode_get() 5"); |
| 462 | //sleep(1); |
| 463 | err = at_tok_nextint(&line, &tmp_int); |
| 464 | if (err < 0) |
| 465 | { |
| 466 | goto exit; |
| 467 | } |
| 468 | //LOG("req_net_sel_mode_get() 6"); |
| 469 | //sleep(1); |
| 470 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 471 | if (err < 0) |
| 472 | { |
| 473 | goto exit; |
| 474 | } |
| 475 | // memcpy(net->plmn, tmp_ptr, strlen(tmp_ptr)); |
| 476 | net->plmn = (uint32)atoi(tmp_ptr); |
| 477 | //LOG("req_net_sel_mode_get() 7"); |
| 478 | //sleep(1); |
| 479 | err = at_tok_nextint(&line, &tmp_int); |
| 480 | if (err < 0) |
| 481 | { |
| 482 | goto exit; |
| 483 | } |
| 484 | net->net_type = (uint8)tmp_int; |
| 485 | |
| 486 | net->net_state = (uint8)MBTK_NET_AVIL_STATE_CURRENT; |
| 487 | |
| 488 | exit: |
| 489 | //LOG("req_net_sel_mode_get() 8"); |
| 490 | //sleep(1); |
| 491 | at_response_free(response); |
| 492 | return err; |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | AT+COPS=0 |
| 497 | or |
| 498 | AT+COPS=1,2,"46000",7 |
| 499 | |
| 500 | OK |
| 501 | |
| 502 | */ |
| 503 | static int req_net_sel_mode_set(mbtk_net_info_t* net, int *cme_err) |
| 504 | { |
| 505 | ATResponse *response = NULL; |
| 506 | char cmd[50] = {0}; |
| 507 | char* cmp_ptr = cmd; |
| 508 | if(net == NULL) { |
| 509 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0"); |
| 510 | } else { |
| 511 | if(net->net_sel_mode == 0) { |
| 512 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0"); |
| 513 | } else if(net->net_type == 0xFF) { |
| 514 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\"",net->plmn); |
| 515 | } else { |
| 516 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\",%d",net->plmn, net->net_type); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | int err = at_send_command(cmd, &response); |
| 521 | |
| 522 | if (err < 0 || response->success == 0) { |
| 523 | if(cme_err) { |
| 524 | *cme_err = at_get_cme_error(response); |
| 525 | } |
| 526 | goto exit; |
| 527 | } |
| 528 | |
| 529 | exit: |
| 530 | at_response_free(response); |
| 531 | return err; |
| 532 | } |
| 533 | |
| 534 | /* |
| 535 | AT*BAND=15 |
| 536 | OK |
| 537 | |
| 538 | */ |
| 539 | static int req_band_set(mbtk_band_info_t* band, int *cme_err) |
| 540 | { |
| 541 | ATResponse *response = NULL; |
| 542 | char cmd[100] = {0}; |
| 543 | int err = -1; |
| 544 | |
| 545 | if(band->gsm_band == 0 && band->umts_band == 0 |
| 546 | && band->tdlte_band == 0 && band->fddlte_band == 0) { |
| 547 | sprintf(cmd, "AT*BAND=%d", band->net_pref); |
| 548 | } else { |
| 549 | log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t)); |
| 550 | log_hex("BAND", band, sizeof(mbtk_band_info_t)); |
| 551 | |
| 552 | if(band->gsm_band == 0) { |
| 553 | band->gsm_band = band_info.band_support.gsm_band; |
| 554 | } |
| 555 | if(band->umts_band == 0) { |
| 556 | band->umts_band = band_info.band_support.umts_band; |
| 557 | } |
| 558 | if(band->tdlte_band == 0) { |
| 559 | band->tdlte_band = band_info.band_support.tdlte_band; |
| 560 | } |
| 561 | if(band->fddlte_band == 0) { |
| 562 | band->fddlte_band = band_info.band_support.fddlte_band; |
| 563 | } |
| 564 | |
| 565 | if((band->gsm_band & band_info.band_support.gsm_band) != band->gsm_band) { |
| 566 | LOG("GSM band error."); |
| 567 | goto exit; |
| 568 | } |
| 569 | |
| 570 | if((band->umts_band & band_info.band_support.umts_band) != band->umts_band) { |
| 571 | LOG("UMTS band error."); |
| 572 | goto exit; |
| 573 | } |
| 574 | |
| 575 | if((band->tdlte_band & band_info.band_support.tdlte_band) != band->tdlte_band) { |
| 576 | LOG("TDLTE band error."); |
| 577 | goto exit; |
| 578 | } |
| 579 | |
| 580 | if((band->fddlte_band & band_info.band_support.fddlte_band) != band->fddlte_band) { |
| 581 | LOG("FDDLTE band error."); |
| 582 | goto exit; |
| 583 | } |
| 584 | |
| 585 | if((band->lte_ext_band & band_info.band_support.lte_ext_band) != band->lte_ext_band) { |
| 586 | LOG("EXT_LTE band error."); |
| 587 | goto exit; |
| 588 | } |
| 589 | |
| 590 | if(band->net_pref == 0xFF) { // No change net_pref. |
| 591 | int tmp_int; |
| 592 | err = at_send_command_singleline("AT*BAND?", "*BAND:", &response); |
| 593 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 594 | if(cme_err) { |
| 595 | *cme_err = at_get_cme_error(response); |
| 596 | } |
| 597 | goto exit; |
| 598 | } |
| 599 | |
| 600 | char *line = response->p_intermediates->line; |
| 601 | err = at_tok_start(&line); |
| 602 | if (err < 0) |
| 603 | { |
| 604 | goto exit; |
| 605 | } |
| 606 | |
| 607 | err = at_tok_nextint(&line, &tmp_int); |
| 608 | if (err < 0) |
| 609 | { |
| 610 | goto exit; |
| 611 | } |
| 612 | band->net_pref = (uint8)tmp_int; // Set to current net_pref. |
| 613 | |
| 614 | at_response_free(response); |
| 615 | } |
| 616 | |
| 617 | if(band->lte_ext_band > 0) { |
| 618 | sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d,,,,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band, band->lte_ext_band); |
| 619 | } else { |
| 620 | sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band); |
| 621 | } |
| 622 | } |
| 623 | err = at_send_command(cmd, &response); |
| 624 | |
| 625 | if (err < 0 || response->success == 0){ |
| 626 | if(cme_err) { |
| 627 | *cme_err = at_get_cme_error(response); |
| 628 | } |
| 629 | goto exit; |
| 630 | } |
| 631 | |
| 632 | err = 0; |
| 633 | exit: |
| 634 | at_response_free(response); |
| 635 | return err; |
| 636 | } |
| 637 | |
| 638 | /* |
| 639 | // ??????? |
| 640 | AT*BAND=? |
| 641 | *BAND:(0-18),79,147,482,524503 |
| 642 | |
| 643 | OK |
| 644 | |
| 645 | // ??????????? |
| 646 | AT*BAND? |
| 647 | *BAND: 15, 78, 147, 482, 524503, 0, 2, 2, 0, 0 |
| 648 | |
| 649 | OK |
| 650 | |
| 651 | // ????????? |
| 652 | AT*BAND=5,79,147,128,1 |
| 653 | OK |
| 654 | |
| 655 | net_prefferred?? |
| 656 | 0 : GSM only |
| 657 | 1 : UMTS only |
| 658 | 2 : GSM/UMTS(auto) |
| 659 | 3 : GSM/UMTS(GSM preferred) |
| 660 | 4 : GSM/UMTS(UMTS preferred) |
| 661 | 5 : LTE only |
| 662 | 6 : GSM/LTE(auto) |
| 663 | 7 : GSM/LTE(GSM preferred) |
| 664 | 8 : GSM/LTE(LTE preferred) |
| 665 | 9 : UMTS/LTE(auto) |
| 666 | 10 : UMTS/LTE(UMTS preferred) |
| 667 | 11 : UMTS/LTE(LTE preferred) |
| 668 | 12 : GSM/UMTS/LTE(auto) |
| 669 | 13 : GSM/UMTS/LTE(GSM preferred) |
| 670 | 14 : GSM/UMTS/LTE(UMTS preferred) |
| 671 | 15 : GSM/UMTS/LTE(LTE preferred) |
| 672 | GSM band?? |
| 673 | 1 ?C PGSM 900 (standard or primary) |
| 674 | 2 ?C DCS GSM 1800 |
| 675 | 4 ?C PCS GSM 1900 |
| 676 | 8 ?C EGSM 900 (extended) |
| 677 | 16 ?C GSM 450 |
| 678 | 32 ?C GSM 480 |
| 679 | 64 ?C GSM 850 |
| 680 | 512 - BAND_LOCK_BIT // used for GSM band setting |
| 681 | UMTS band?? |
| 682 | 1 ?C UMTS_BAND_1 |
| 683 | 2 ?C UMTS_BAND_2 |
| 684 | 4 ?C UMTS_BAND_3 |
| 685 | 8 ?C UMTS_BAND_4 |
| 686 | 16 ?C UMTS_BAND_5 |
| 687 | 32 ?C UMTS_BAND_6 |
| 688 | 64 ?C UMTS_BAND_7 |
| 689 | 128 ?C UMTS_BAND_8 |
| 690 | 256 ?C UMTS_BAND_9 |
| 691 | LTEbandH(TDD-LTE band) |
| 692 | 32 ?C TDLTE_BAND_38 |
| 693 | 64 ?C TDLTE_BAND_39 |
| 694 | 128 ?C TDLTE_BAND_40 |
| 695 | 256 ?C TDLTE_BAND_41 |
| 696 | LTEbandL(FDD-LTE band) |
| 697 | 1 ?C FDDLTE_BAND_1 |
| 698 | 4 ?C FDDLTE _BAND_3 |
| 699 | 8 ?C FDDLTE _BAND_4 |
| 700 | 64 ?C FDDLTE _BAND_7 |
| 701 | 65536 ?C FDDLTE _BAND_17 |
| 702 | 524288 ?C FDDLTE _BAND_20 |
| 703 | */ |
| 704 | static int req_band_get(mbtk_band_info_t *band, int *cme_err) |
| 705 | { |
| 706 | ATResponse *response = NULL; |
| 707 | int tmp_int; |
| 708 | |
| 709 | log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t)); |
| 710 | int err = at_send_command_singleline("AT*BAND?", "*BAND:", &response); |
| 711 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 712 | if(cme_err) { |
| 713 | *cme_err = at_get_cme_error(response); |
| 714 | } |
| 715 | goto exit; |
| 716 | } |
| 717 | |
| 718 | char *line = response->p_intermediates->line; |
| 719 | err = at_tok_start(&line); |
| 720 | if (err < 0) |
| 721 | { |
| 722 | goto exit; |
| 723 | } |
| 724 | |
| 725 | err = at_tok_nextint(&line, &tmp_int); |
| 726 | if (err < 0) |
| 727 | { |
| 728 | goto exit; |
| 729 | } |
| 730 | band->net_pref = (uint8)tmp_int; |
| 731 | |
| 732 | err = at_tok_nextint(&line, &tmp_int); |
| 733 | if (err < 0) |
| 734 | { |
| 735 | goto exit; |
| 736 | } |
| 737 | band->gsm_band = (uint16)tmp_int; |
| 738 | |
| 739 | err = at_tok_nextint(&line, &tmp_int); |
| 740 | if (err < 0) |
| 741 | { |
| 742 | goto exit; |
| 743 | } |
| 744 | band->umts_band = (uint16)tmp_int; |
| 745 | |
| 746 | err = at_tok_nextint(&line, &tmp_int); |
| 747 | if (err < 0) |
| 748 | { |
| 749 | goto exit; |
| 750 | } |
| 751 | band->tdlte_band = (uint32)tmp_int; |
| 752 | |
| 753 | err = at_tok_nextint(&line, &tmp_int); |
| 754 | if (err < 0) |
| 755 | { |
| 756 | goto exit; |
| 757 | } |
| 758 | band->fddlte_band = (uint32)tmp_int; |
| 759 | |
| 760 | // roamingConfig |
| 761 | err = at_tok_nextint(&line, &tmp_int); |
| 762 | if (err < 0) |
| 763 | { |
| 764 | goto exit; |
| 765 | } |
| 766 | |
| 767 | // srvDomain |
| 768 | err = at_tok_nextint(&line, &tmp_int); |
| 769 | if (err < 0) |
| 770 | { |
| 771 | goto exit; |
| 772 | } |
| 773 | |
| 774 | // bandPriorityFlag |
| 775 | err = at_tok_nextint(&line, &tmp_int); |
| 776 | if (err < 0) |
| 777 | { |
| 778 | goto exit; |
| 779 | } |
| 780 | |
| 781 | // |
| 782 | err = at_tok_nextint(&line, &tmp_int); |
| 783 | if (err < 0) |
| 784 | { |
| 785 | goto exit; |
| 786 | } |
| 787 | |
| 788 | // ltebandExt |
| 789 | err = at_tok_nextint(&line, &tmp_int); |
| 790 | if (err < 0) |
| 791 | { |
| 792 | goto exit; |
| 793 | } |
| 794 | band->lte_ext_band = (uint32)tmp_int; |
| 795 | |
| 796 | log_hex("BAND", band, sizeof(mbtk_band_info_t)); |
| 797 | |
| 798 | exit: |
| 799 | at_response_free(response); |
| 800 | return err; |
| 801 | } |
| 802 | |
| 803 | /* |
| 804 | AT+CSQ |
| 805 | +CSQ: 31,99 |
| 806 | |
| 807 | OK |
| 808 | |
| 809 | AT+CESQ |
| 810 | +CESQ: 60,99,255,255,20,61 |
| 811 | |
| 812 | OK |
| 813 | |
| 814 | AT+COPS? |
| 815 | +COPS: 0,2,"46001",7 |
| 816 | |
| 817 | OK |
| 818 | |
| 819 | */ |
| 820 | static int req_net_signal_get(mbtk_signal_info_t *signal, int *cme_err) |
| 821 | { |
| 822 | ATResponse *response = NULL; |
| 823 | int tmp_int; |
| 824 | char *tmp_ptr = NULL; |
| 825 | // AT+EEMOPT=1 in the first. |
| 826 | int err = at_send_command_singleline("AT+CSQ", "+CSQ:", &response); |
| 827 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 828 | if(cme_err != NULL) |
| 829 | *cme_err = at_get_cme_error(response); |
| 830 | err = -1; |
| 831 | goto exit; |
| 832 | } |
| 833 | |
| 834 | char *line = response->p_intermediates->line; |
| 835 | err = at_tok_start(&line); |
| 836 | if (err < 0) |
| 837 | { |
| 838 | goto exit; |
| 839 | } |
| 840 | err = at_tok_nextint(&line, &tmp_int); |
| 841 | if (err < 0) |
| 842 | { |
| 843 | goto exit; |
| 844 | } |
| 845 | signal->rssi = (uint8)tmp_int; |
| 846 | at_response_free(response); |
| 847 | |
| 848 | err = at_send_command_singleline("AT+CESQ", "+CESQ:", &response); |
| 849 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 850 | if(cme_err != NULL) |
| 851 | *cme_err = at_get_cme_error(response); |
| 852 | err = -1; |
| 853 | goto exit; |
| 854 | } |
| 855 | |
| 856 | line = response->p_intermediates->line; |
| 857 | err = at_tok_start(&line); |
| 858 | if (err < 0) |
| 859 | { |
| 860 | goto exit; |
| 861 | } |
| 862 | err = at_tok_nextint(&line, &tmp_int); |
| 863 | if (err < 0) |
| 864 | { |
| 865 | goto exit; |
| 866 | } |
| 867 | signal->rxlev = (uint8)tmp_int; |
| 868 | |
| 869 | err = at_tok_nextint(&line, &tmp_int); |
| 870 | if (err < 0) |
| 871 | { |
| 872 | goto exit; |
| 873 | } |
| 874 | signal->ber = (uint8)tmp_int; |
| 875 | |
| 876 | err = at_tok_nextint(&line, &tmp_int); |
| 877 | if (err < 0) |
| 878 | { |
| 879 | goto exit; |
| 880 | } |
| 881 | signal->rscp = (uint8)tmp_int; |
| 882 | |
| 883 | err = at_tok_nextint(&line, &tmp_int); |
| 884 | if (err < 0) |
| 885 | { |
| 886 | goto exit; |
| 887 | } |
| 888 | signal->ecno = (uint8)tmp_int; |
| 889 | |
| 890 | err = at_tok_nextint(&line, &tmp_int); |
| 891 | if (err < 0) |
| 892 | { |
| 893 | goto exit; |
| 894 | } |
| 895 | signal->rsrq = (uint8)tmp_int; |
| 896 | |
| 897 | err = at_tok_nextint(&line, &tmp_int); |
| 898 | if (err < 0) |
| 899 | { |
| 900 | goto exit; |
| 901 | } |
| 902 | signal->rsrp = (uint8)tmp_int; |
| 903 | |
| 904 | at_response_free(response); |
| 905 | err = at_send_command_singleline("AT+COPS?", "+COPS:", &response); |
| 906 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 907 | if(cme_err != NULL) |
| 908 | *cme_err = at_get_cme_error(response); |
| 909 | err = -1; |
| 910 | goto exit; |
| 911 | } |
| 912 | line = response->p_intermediates->line; |
| 913 | err = at_tok_start(&line); |
| 914 | if (err < 0) |
| 915 | { |
| 916 | goto exit; |
| 917 | } |
| 918 | err = at_tok_nextint(&line, &tmp_int); |
| 919 | if (err < 0) |
| 920 | { |
| 921 | goto exit; |
| 922 | } |
| 923 | if(!at_tok_hasmore(&line)) { |
| 924 | goto exit; |
| 925 | } |
| 926 | err = at_tok_nextint(&line, &tmp_int); |
| 927 | if (err < 0) |
| 928 | { |
| 929 | goto exit; |
| 930 | } |
| 931 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 932 | if (err < 0) |
| 933 | { |
| 934 | goto exit; |
| 935 | } |
| 936 | err = at_tok_nextint(&line, &tmp_int); |
| 937 | if (err < 0) |
| 938 | { |
| 939 | goto exit; |
| 940 | } |
| 941 | signal->type = (uint8)tmp_int; |
| 942 | |
| 943 | exit: |
| 944 | at_response_free(response); |
| 945 | return err; |
| 946 | } |
| 947 | |
| 948 | /* |
| 949 | AT+CREG=3 |
| 950 | OK |
| 951 | |
| 952 | AT+CREG? |
| 953 | +CREG: 3,1,"8330","06447340",7 |
| 954 | |
| 955 | OK |
| 956 | |
| 957 | AT+CREG? |
| 958 | +CREG: 3,0 |
| 959 | |
| 960 | OK |
| 961 | |
| 962 | AT+CEREG? |
| 963 | +CEREG: 3,1,"8330","06447340",7 |
| 964 | |
| 965 | OK |
| 966 | |
| 967 | |
| 968 | AT+CIREG? |
| 969 | +CIREG: 2,1,15 |
| 970 | |
| 971 | OK |
| 972 | |
| 973 | AT+CIREG? |
| 974 | +CIREG: 0 |
| 975 | |
| 976 | OK |
| 977 | |
| 978 | |
| 979 | */ |
| 980 | static int req_net_reg_get(mbtk_net_reg_info_t *reg, int *cme_err) |
| 981 | { |
| 982 | ATResponse *response = NULL; |
| 983 | int tmp_int; |
| 984 | char *tmp_str = NULL; |
| 985 | int err = at_send_command("AT+CREG=3", &response); |
| 986 | if (err < 0 || response->success == 0){ |
| 987 | if(cme_err) { |
| 988 | *cme_err = at_get_cme_error(response); |
| 989 | } |
| 990 | goto exit; |
| 991 | } |
| 992 | at_response_free(response); |
| 993 | |
| 994 | err = at_send_command_multiline("AT+CREG?", "+CREG:", &response); |
| 995 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 996 | if(cme_err) { |
| 997 | *cme_err = at_get_cme_error(response); |
| 998 | } |
| 999 | goto exit; |
| 1000 | } |
| 1001 | |
| 1002 | char *line = response->p_intermediates->line; |
| 1003 | err = at_tok_start(&line); |
| 1004 | if (err < 0) |
| 1005 | { |
| 1006 | goto exit; |
| 1007 | } |
| 1008 | err = at_tok_nextint(&line, &tmp_int); // n |
| 1009 | if (err < 0) |
| 1010 | { |
| 1011 | goto exit; |
| 1012 | } |
| 1013 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 1014 | if (err < 0) |
| 1015 | { |
| 1016 | goto exit; |
| 1017 | } |
| 1018 | reg->call_state = (uint8)tmp_int; |
| 1019 | |
| 1020 | if(at_tok_hasmore(&line)) { |
| 1021 | err = at_tok_nextstr(&line, &tmp_str); // lac |
| 1022 | if (err < 0) |
| 1023 | { |
| 1024 | goto exit; |
| 1025 | } |
| 1026 | reg->lac = strtol(tmp_str, NULL, 16); |
| 1027 | |
| 1028 | err = at_tok_nextstr(&line, &tmp_str); // ci |
| 1029 | if (err < 0) |
| 1030 | { |
| 1031 | goto exit; |
| 1032 | } |
| 1033 | reg->ci = strtol(tmp_str, NULL, 16); |
| 1034 | |
| 1035 | err = at_tok_nextint(&line, &tmp_int);// AcT |
| 1036 | if (err < 0) |
| 1037 | { |
| 1038 | goto exit; |
| 1039 | } |
| 1040 | reg->type = (uint8)tmp_int; |
| 1041 | } |
| 1042 | at_response_free(response); |
| 1043 | |
| 1044 | err = at_send_command_multiline("AT+CEREG?", "+CEREG:", &response); |
| 1045 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1046 | if(cme_err) { |
| 1047 | *cme_err = at_get_cme_error(response); |
| 1048 | } |
| 1049 | goto exit; |
| 1050 | } |
| 1051 | |
| 1052 | line = response->p_intermediates->line; |
| 1053 | err = at_tok_start(&line); |
| 1054 | if (err < 0) |
| 1055 | { |
| 1056 | goto exit; |
| 1057 | } |
| 1058 | err = at_tok_nextint(&line, &tmp_int); // n |
| 1059 | if (err < 0) |
| 1060 | { |
| 1061 | goto exit; |
| 1062 | } |
| 1063 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 1064 | if (err < 0) |
| 1065 | { |
| 1066 | goto exit; |
| 1067 | } |
| 1068 | reg->data_state = (uint8)tmp_int; |
| 1069 | |
| 1070 | if(reg->lac == 0 && at_tok_hasmore(&line)) { |
| 1071 | err = at_tok_nextstr(&line, &tmp_str); // lac |
| 1072 | if (err < 0) |
| 1073 | { |
| 1074 | goto exit; |
| 1075 | } |
| 1076 | reg->lac = strtol(tmp_str, NULL, 16); |
| 1077 | |
| 1078 | err = at_tok_nextstr(&line, &tmp_str); // ci |
| 1079 | if (err < 0) |
| 1080 | { |
| 1081 | goto exit; |
| 1082 | } |
| 1083 | reg->ci = strtol(tmp_str, NULL, 16); |
| 1084 | |
| 1085 | err = at_tok_nextint(&line, &tmp_int);// AcT |
| 1086 | if (err < 0) |
| 1087 | { |
| 1088 | goto exit; |
| 1089 | } |
| 1090 | reg->type = (uint8)tmp_int; |
| 1091 | } |
| 1092 | at_response_free(response); |
| 1093 | |
| 1094 | err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response); |
| 1095 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1096 | reg->ims_state = (uint8)0; |
| 1097 | err = 0; |
| 1098 | goto exit; |
| 1099 | } |
| 1100 | line = response->p_intermediates->line; |
| 1101 | err = at_tok_start(&line); |
| 1102 | if (err < 0) |
| 1103 | { |
| 1104 | goto exit; |
| 1105 | } |
| 1106 | err = at_tok_nextint(&line, &tmp_int); // n/stat |
| 1107 | if (err < 0) |
| 1108 | { |
| 1109 | goto exit; |
| 1110 | } |
| 1111 | if(at_tok_hasmore(&line)) { |
| 1112 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 1113 | if (err < 0) |
| 1114 | { |
| 1115 | goto exit; |
| 1116 | } |
| 1117 | reg->ims_state = (uint8)tmp_int; |
| 1118 | } else { |
| 1119 | reg->ims_state = (uint8)tmp_int; |
| 1120 | } |
| 1121 | |
| 1122 | exit: |
| 1123 | at_response_free(response); |
| 1124 | return err; |
| 1125 | } |
| 1126 | |
| 1127 | /* |
| 1128 | AT+CGDCONT? |
| 1129 | |
| 1130 | +CGDCONT: 1,"IPV4V6","ctnet","10.142.64.116 254.128.0.0.0.0.0.0.0.0.0.0.0.0.0.1",0,0,0,2,0,0 |
| 1131 | |
| 1132 | +CGDCONT: 8,"IPV4V6","IMS","254.128.0.0.0.0.0.0.0.0.0.0.0.0.0.1",0,0,0,2,1,1 |
| 1133 | |
| 1134 | OK |
| 1135 | |
| 1136 | */ |
| 1137 | static int req_apn_get(mbtk_apn_info_array_t *apns, int *cme_err) |
| 1138 | { |
| 1139 | ATResponse *response = NULL; |
| 1140 | int err = at_send_command_multiline("AT+CGDCONT?", "+CGDCONT:", &response); |
| 1141 | |
| 1142 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1143 | if(cme_err) { |
| 1144 | *cme_err = at_get_cme_error(response); |
| 1145 | } |
| 1146 | goto exit; |
| 1147 | } |
| 1148 | |
| 1149 | ATLine* lines_ptr = response->p_intermediates; |
| 1150 | char *line = NULL; |
| 1151 | int tmp_int; |
| 1152 | char *tmp_str = NULL; |
| 1153 | /* |
| 1154 | <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>... |
| 1155 | <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth> |
| 1156 | */ |
| 1157 | while(lines_ptr) |
| 1158 | { |
| 1159 | line = lines_ptr->line; |
| 1160 | err = at_tok_start(&line); |
| 1161 | if (err < 0) |
| 1162 | { |
| 1163 | goto exit; |
| 1164 | } |
| 1165 | |
| 1166 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 1167 | if (err < 0) |
| 1168 | { |
| 1169 | goto exit; |
| 1170 | } |
| 1171 | // Only get CID 1-7 |
| 1172 | if(tmp_int >= MBTK_APN_CID_MIN && tmp_int <= MBTK_APN_CID_MAX) { |
| 1173 | apns->apns[apns->num].cid = (mbtk_ril_cid_enum)tmp_int; |
| 1174 | |
| 1175 | err = at_tok_nextstr(&line, &tmp_str);// ip type |
| 1176 | if (err < 0) |
| 1177 | { |
| 1178 | goto exit; |
| 1179 | } |
| 1180 | if(!strcasecmp(tmp_str, "IP")) { |
| 1181 | apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IP; |
| 1182 | } else if(!strcasecmp(tmp_str, "IPV6")) { |
| 1183 | apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IPV6; |
| 1184 | } else if(!strcasecmp(tmp_str, "IPV4V6")) { |
| 1185 | apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IPV4V6; |
| 1186 | } else { |
| 1187 | apns->apns[apns->num].ip_type = MBTK_IP_TYPE_PPP; |
| 1188 | } |
| 1189 | |
| 1190 | err = at_tok_nextstr(&line, &tmp_str); // apn |
| 1191 | if (err < 0) |
| 1192 | { |
| 1193 | goto exit; |
| 1194 | } |
| 1195 | if(!str_empty(tmp_str)) { |
| 1196 | memcpy(apns->apns[apns->num].apn, tmp_str, strlen(tmp_str)); |
| 1197 | } |
| 1198 | |
| 1199 | apns->num++; |
| 1200 | } |
| 1201 | |
| 1202 | lines_ptr = lines_ptr->p_next; |
| 1203 | } |
| 1204 | |
| 1205 | goto exit; |
| 1206 | exit: |
| 1207 | at_response_free(response); |
| 1208 | return err; |
| 1209 | } |
| 1210 | |
| 1211 | /* |
| 1212 | AT+CGDCONT=1,"IPV4V6","cmnet" |
| 1213 | OK |
| 1214 | |
| 1215 | AT*AUTHReq=1,1,marvell,123456 |
| 1216 | OK |
| 1217 | |
| 1218 | */ |
| 1219 | static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err) |
| 1220 | { |
| 1221 | ATResponse *response = NULL; |
| 1222 | char cmd[400] = {0}; |
| 1223 | int index = 0; |
| 1224 | int err = 0; |
| 1225 | |
| 1226 | // Delete apn |
| 1227 | if(str_empty(apn->apn)) { |
| 1228 | sprintf(cmd, "AT+CGDCONT=%d", apn->cid); |
| 1229 | err = at_send_command(cmd, &response); |
| 1230 | if (err < 0 || response->success == 0){ |
| 1231 | if(cme_err) { |
| 1232 | *cme_err = at_get_cme_error(response); |
| 1233 | } |
| 1234 | goto exit; |
| 1235 | } |
| 1236 | } else { |
| 1237 | index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid); |
| 1238 | switch(apn->ip_type) { |
| 1239 | case MBTK_IP_TYPE_IP: { |
| 1240 | index += sprintf(cmd + index,"\"IP\","); |
| 1241 | break; |
| 1242 | } |
| 1243 | case MBTK_IP_TYPE_IPV6: { |
| 1244 | index += sprintf(cmd + index,"\"IPV6\","); |
| 1245 | break; |
| 1246 | } |
| 1247 | case MBTK_IP_TYPE_IPV4V6: { |
| 1248 | index += sprintf(cmd + index,"\"IPV4V6\","); |
| 1249 | break; |
| 1250 | } |
| 1251 | default: { |
| 1252 | index += sprintf(cmd + index,"\"PPP\","); |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | if(strlen(apn->apn) > 0) { |
| 1257 | index += sprintf(cmd + index,"\"%s\"", apn->apn); |
| 1258 | } |
| 1259 | |
| 1260 | err = at_send_command(cmd, &response); |
| 1261 | if (err < 0 || response->success == 0){ |
| 1262 | if(cme_err) { |
| 1263 | *cme_err = at_get_cme_error(response); |
| 1264 | } |
| 1265 | goto exit; |
| 1266 | } |
| 1267 | |
| 1268 | if(!str_empty(apn->user) || !str_empty(apn->pass)) { |
| 1269 | at_response_free(response); |
| 1270 | |
| 1271 | memset(cmd,0,400); |
| 1272 | int cmd_auth=0; |
| 1273 | if(apn->auth == MBTK_APN_AUTH_PROTO_NONE) |
| 1274 | cmd_auth = 0; |
| 1275 | else if(apn->auth == MBTK_APN_AUTH_PROTO_PAP) |
| 1276 | cmd_auth = 1; |
| 1277 | else if(apn->auth == MBTK_APN_AUTH_PROTO_CHAP) |
| 1278 | cmd_auth = 2; |
| 1279 | else |
| 1280 | goto exit; |
| 1281 | |
| 1282 | sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass); |
| 1283 | err = at_send_command(cmd, &response); |
| 1284 | if (err < 0 || response->success == 0){ |
| 1285 | if(cme_err) { |
| 1286 | *cme_err = at_get_cme_error(response); |
| 1287 | } |
| 1288 | goto exit; |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | exit: |
| 1294 | at_response_free(response); |
| 1295 | return err; |
| 1296 | } |
| 1297 | |
| 1298 | /* |
| 1299 | AT+CGACT? |
| 1300 | +CGACT: 1,1 |
| 1301 | +CGACT: 8,1 |
| 1302 | OK |
| 1303 | |
| 1304 | AT+CGACT=1,<cid> |
| 1305 | OK |
| 1306 | |
| 1307 | */ |
| 1308 | static int req_data_call_start(mbtk_ril_cid_enum cid, bool def_route, |
| 1309 | int retry_interval, int timeout, mbtk_ip_info_t *ip_info, int *cme_err) |
| 1310 | { |
| 1311 | ATResponse *response = NULL; |
| 1312 | char cmd[400] = {0}; |
| 1313 | int err = 0; |
| 1314 | |
| 1315 | sprintf(cmd, "AT+CGACT=1,%d", cid); |
| 1316 | err = at_send_command(cmd, &response); |
| 1317 | if (err < 0 || response->success == 0){ |
| 1318 | if(cme_err) { |
| 1319 | *cme_err = at_get_cme_error(response); |
| 1320 | } |
| 1321 | goto exit; |
| 1322 | } |
| 1323 | |
| 1324 | exit: |
| 1325 | at_response_free(response); |
| 1326 | return err; |
| 1327 | } |
| 1328 | |
| 1329 | /* |
| 1330 | AT+CGACT=0,<cid> |
| 1331 | OK |
| 1332 | |
| 1333 | */ |
| 1334 | static int req_data_call_stop(mbtk_ril_cid_enum cid, int timeout, int *cme_err) |
| 1335 | { |
| 1336 | ATResponse *response = NULL; |
| 1337 | char cmd[400] = {0}; |
| 1338 | int err = 0; |
| 1339 | |
| 1340 | sprintf(cmd, "AT+CGACT=0,%d", cid); |
| 1341 | err = at_send_command(cmd, &response); |
| 1342 | if (err < 0 || response->success == 0){ |
| 1343 | if(cme_err) { |
| 1344 | *cme_err = at_get_cme_error(response); |
| 1345 | } |
| 1346 | goto exit; |
| 1347 | } |
| 1348 | |
| 1349 | exit: |
| 1350 | at_response_free(response); |
| 1351 | return err; |
| 1352 | } |
| 1353 | |
| 1354 | /* |
| 1355 | AT+CGCONTRDP=1 |
| 1356 | +CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","10.255.74.26","","223.87.253.100","223.87.253.253","","",0,0 |
| 1357 | +CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239","","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.1","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.2","","",0,0 |
| 1358 | |
| 1359 | OK |
| 1360 | |
| 1361 | */ |
| 1362 | static int req_data_call_state_get(mbtk_ril_cid_enum cid, mbtk_ip_info_t *ip_info, int *cme_err) |
| 1363 | { |
| 1364 | ATResponse *response = NULL; |
| 1365 | char cmd[50] = {0}; |
| 1366 | int err = 0; |
| 1367 | |
| 1368 | sprintf(cmd, "AT+CGCONTRDP=%d", cid); |
| 1369 | |
| 1370 | err = at_send_command_multiline(cmd, "+CGCONTRDP:", &response); |
| 1371 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1372 | *cme_err = at_get_cme_error(response); |
| 1373 | goto exit; |
| 1374 | } |
| 1375 | ATLine* lines_ptr = response->p_intermediates; |
| 1376 | char *line = NULL; |
| 1377 | int tmp_int; |
| 1378 | char *tmp_ptr = NULL; |
| 1379 | while(lines_ptr) |
| 1380 | { |
| 1381 | line = lines_ptr->line; |
| 1382 | err = at_tok_start(&line); |
| 1383 | if (err < 0) |
| 1384 | { |
| 1385 | goto exit; |
| 1386 | } |
| 1387 | |
| 1388 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 1389 | if (err < 0) |
| 1390 | { |
| 1391 | goto exit; |
| 1392 | } |
| 1393 | err = at_tok_nextint(&line, &tmp_int); // bearer_id |
| 1394 | if (err < 0) |
| 1395 | { |
| 1396 | goto exit; |
| 1397 | } |
| 1398 | err = at_tok_nextstr(&line, &tmp_ptr); // APN |
| 1399 | if (err < 0) |
| 1400 | { |
| 1401 | goto exit; |
| 1402 | } |
| 1403 | |
| 1404 | err = at_tok_nextstr(&line, &tmp_ptr); // IP |
| 1405 | if (err < 0 || str_empty(tmp_ptr)) |
| 1406 | { |
| 1407 | goto exit; |
| 1408 | } |
| 1409 | if(is_ipv4(tmp_ptr)) { |
| 1410 | if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.IPAddr)) < 0) { |
| 1411 | LOGE("inet_pton() fail."); |
| 1412 | err = -1; |
| 1413 | goto exit; |
| 1414 | } |
| 1415 | |
| 1416 | ip_info->ipv4.valid = true; |
| 1417 | //log_hex("IPv4", &(ipv4->IPAddr), sizeof(struct in_addr)); |
| 1418 | } else { |
| 1419 | if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.IPV6Addr))) { |
| 1420 | LOGE("str_2_ipv6() fail."); |
| 1421 | err = -1; |
| 1422 | goto exit; |
| 1423 | } |
| 1424 | |
| 1425 | ip_info->ipv6.valid = true; |
| 1426 | //log_hex("IPv6", &(ipv6->IPV6Addr), 16); |
| 1427 | } |
| 1428 | |
| 1429 | err = at_tok_nextstr(&line, &tmp_ptr); // Gateway |
| 1430 | if (err < 0) |
| 1431 | { |
| 1432 | goto exit; |
| 1433 | } |
| 1434 | if(!str_empty(tmp_ptr)) { // No found gateway |
| 1435 | if(is_ipv4(tmp_ptr)) { |
| 1436 | if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.GateWay)) < 0) { |
| 1437 | LOGE("inet_pton() fail."); |
| 1438 | err = -1; |
| 1439 | goto exit; |
| 1440 | } |
| 1441 | |
| 1442 | //log_hex("IPv4", &(ipv4->GateWay), sizeof(struct in_addr)); |
| 1443 | } else { |
| 1444 | if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.GateWay))) { |
| 1445 | LOGE("str_2_ipv6() fail."); |
| 1446 | err = -1; |
| 1447 | goto exit; |
| 1448 | } |
| 1449 | |
| 1450 | //log_hex("IPv6", &(ipv6->GateWay), 16); |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | err = at_tok_nextstr(&line, &tmp_ptr); // prim_DNS |
| 1455 | if (err < 0) |
| 1456 | { |
| 1457 | goto exit; |
| 1458 | } |
| 1459 | if(!str_empty(tmp_ptr)) { // No found Primary DNS |
| 1460 | if(is_ipv4(tmp_ptr)) { |
| 1461 | if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.PrimaryDNS)) < 0) { |
| 1462 | LOGE("inet_pton() fail."); |
| 1463 | err = -1; |
| 1464 | goto exit; |
| 1465 | } |
| 1466 | |
| 1467 | //log_hex("IPv4", &(ipv4->PrimaryDNS), sizeof(struct in_addr)); |
| 1468 | } else { |
| 1469 | if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.PrimaryDNS))) { |
| 1470 | LOGE("str_2_ipv6() fail."); |
| 1471 | err = -1; |
| 1472 | goto exit; |
| 1473 | } |
| 1474 | |
| 1475 | //log_hex("IPv6", &(ipv6->PrimaryDNS), 16); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | err = at_tok_nextstr(&line, &tmp_ptr); // sec_DNS |
| 1480 | if (err < 0) |
| 1481 | { |
| 1482 | goto exit; |
| 1483 | } |
| 1484 | if(!str_empty(tmp_ptr)) { // No found Secondary DNS |
| 1485 | if(is_ipv4(tmp_ptr)) { |
| 1486 | if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.SecondaryDNS)) < 0) { |
| 1487 | LOGE("inet_pton() fail."); |
| 1488 | err = -1; |
| 1489 | goto exit; |
| 1490 | } |
| 1491 | |
| 1492 | //log_hex("IPv4", &(ipv4->SecondaryDNS), sizeof(struct in_addr)); |
| 1493 | } else { |
| 1494 | if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.SecondaryDNS))) { |
| 1495 | LOGE("str_2_ipv6() fail."); |
| 1496 | err = -1; |
| 1497 | goto exit; |
| 1498 | } |
| 1499 | |
| 1500 | //log_hex("IPv6", &(ipv6->SecondaryDNS), 16); |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | lines_ptr = lines_ptr->p_next; |
| 1505 | } |
| 1506 | |
| 1507 | exit: |
| 1508 | at_response_free(response); |
| 1509 | return err; |
| 1510 | } |
| 1511 | |
| 1512 | |
| 1513 | //void net_list_free(void *data); |
| 1514 | // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP. |
| 1515 | // Otherwise, do not call pack_error_send(). |
| 1516 | mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack) |
| 1517 | { |
| 1518 | mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS; |
| 1519 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 1520 | switch(pack->msg_id) |
| 1521 | { |
| 1522 | case RIL_MSG_ID_NET_AVAILABLE: |
| 1523 | { |
| 1524 | if(pack->data_len == 0 || pack->data == NULL) |
| 1525 | { |
| 1526 | mbtk_net_info_array_t net_array; |
| 1527 | memset(&net_array, 0, sizeof(mbtk_net_info_array_t)); |
| 1528 | if(req_available_net_get(&net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1529 | { |
| 1530 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1531 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1532 | } else { |
| 1533 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1534 | } |
| 1535 | LOGD("Get Available Net fail."); |
| 1536 | } |
| 1537 | else |
| 1538 | { |
| 1539 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t)); |
| 1540 | } |
| 1541 | } |
| 1542 | else // Set |
| 1543 | { |
| 1544 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1545 | LOGW("Unsupport set available net."); |
| 1546 | } |
| 1547 | break; |
| 1548 | } |
| 1549 | case RIL_MSG_ID_NET_SEL_MODE: |
| 1550 | { |
| 1551 | if(pack->data_len == 0 || pack->data == NULL) |
| 1552 | { |
| 1553 | mbtk_net_info_t info; |
| 1554 | memset(&info, 0, sizeof(mbtk_net_info_t)); |
| 1555 | if(req_net_sel_mode_get(&info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1556 | { |
| 1557 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1558 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1559 | } else { |
| 1560 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1561 | } |
| 1562 | LOGD("Get Net sel mode fail."); |
| 1563 | } |
| 1564 | else |
| 1565 | { |
| 1566 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t)); |
| 1567 | } |
| 1568 | } |
| 1569 | else // Set |
| 1570 | { |
| 1571 | mbtk_net_info_t *info = (mbtk_net_info_t*)pack->data; |
| 1572 | if(req_net_sel_mode_set(info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1573 | { |
| 1574 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1575 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1576 | } else { |
| 1577 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1578 | } |
| 1579 | LOGD("Set Net sel mode fail."); |
| 1580 | } |
| 1581 | else |
| 1582 | { |
| 1583 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 1584 | } |
| 1585 | } |
| 1586 | break; |
| 1587 | } |
| 1588 | case RIL_MSG_ID_NET_BAND: |
| 1589 | { |
| 1590 | if(pack->data_len == 0 || pack->data == NULL) |
| 1591 | { |
| 1592 | err = MBTK_RIL_ERR_REQ_PARAMETER; |
| 1593 | LOG("No data found."); |
| 1594 | } |
| 1595 | else // Set |
| 1596 | { |
| 1597 | if(pack->data_len == sizeof(uint8)) { |
| 1598 | if(*(pack->data)) { // Get current bands. |
| 1599 | mbtk_band_info_t band; |
| 1600 | memset(&band, 0x0, sizeof(mbtk_band_info_t)); |
| 1601 | if(req_band_get(&band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1602 | { |
| 1603 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1604 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1605 | } else { |
| 1606 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1607 | } |
| 1608 | LOG("Get net band fail."); |
| 1609 | } |
| 1610 | else |
| 1611 | { |
| 1612 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t)); |
| 1613 | } |
| 1614 | } else { // Get support bands. |
| 1615 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &band_info.band_support , sizeof(mbtk_band_info_t)); |
| 1616 | } |
| 1617 | } else { // Set current bands. |
| 1618 | mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data; |
| 1619 | if(pack->data_len != sizeof(mbtk_band_info_t)) |
| 1620 | { |
| 1621 | err = MBTK_RIL_ERR_REQ_PARAMETER; |
| 1622 | LOG("Set net band error."); |
| 1623 | break; |
| 1624 | } |
| 1625 | |
| 1626 | if(req_band_set(band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1627 | { |
| 1628 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1629 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1630 | } else { |
| 1631 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1632 | } |
| 1633 | LOG("Set net band fail."); |
| 1634 | } |
| 1635 | else |
| 1636 | { |
| 1637 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | break; |
| 1642 | } |
| 1643 | case RIL_MSG_ID_NET_SIGNAL: |
| 1644 | { |
| 1645 | if(pack->data_len == 0 || pack->data == NULL) |
| 1646 | { |
| 1647 | mbtk_signal_info_t signal; |
| 1648 | memset(&signal, 0, sizeof(mbtk_signal_info_t)); |
| 1649 | if(req_net_signal_get(&signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1650 | { |
| 1651 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1652 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1653 | } else { |
| 1654 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1655 | } |
| 1656 | LOGD("Get net signal fail."); |
| 1657 | } |
| 1658 | else |
| 1659 | { |
| 1660 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t)); |
| 1661 | } |
| 1662 | } |
| 1663 | else // Set |
| 1664 | { |
| 1665 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1666 | LOGW("Unsupport set net signal."); |
| 1667 | } |
| 1668 | break; |
| 1669 | } |
| 1670 | case RIL_MSG_ID_NET_REG: |
| 1671 | { |
| 1672 | if(pack->data_len == 0 || pack->data == NULL) |
| 1673 | { |
| 1674 | mbtk_net_reg_info_t net_reg; |
| 1675 | memset(&net_reg, 0, sizeof(mbtk_net_reg_info_t)); |
| 1676 | if(req_net_reg_get(&net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1677 | { |
| 1678 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1679 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1680 | } else { |
| 1681 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1682 | } |
| 1683 | LOGD("Get Net reg info fail."); |
| 1684 | } |
| 1685 | else |
| 1686 | { |
| 1687 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_reg, sizeof(mbtk_net_reg_info_t)); |
| 1688 | } |
| 1689 | } |
| 1690 | else // Set |
| 1691 | { |
| 1692 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1693 | LOGW("Unsupport set net reg info."); |
| 1694 | } |
| 1695 | break; |
| 1696 | } |
| 1697 | case RIL_MSG_ID_NET_CELL: |
| 1698 | { |
| 1699 | if(pack->data_len == 0 || pack->data == NULL) |
| 1700 | { |
| 1701 | mbtk_net_info_array_t net_array; |
| 1702 | memset(&net_array, 0, sizeof(mbtk_net_info_array_t)); |
| 1703 | if(req_available_net_get(&net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1704 | { |
| 1705 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1706 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1707 | } else { |
| 1708 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1709 | } |
| 1710 | LOGD("Get Available Net fail."); |
| 1711 | } |
| 1712 | else |
| 1713 | { |
| 1714 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t)); |
| 1715 | } |
| 1716 | } |
| 1717 | else // Set |
| 1718 | { |
| 1719 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1720 | LOGW("Unsupport set available net."); |
| 1721 | } |
| 1722 | break; |
| 1723 | } |
| 1724 | case RIL_MSG_ID_NET_APN: |
| 1725 | { |
| 1726 | if(pack->data_len == 0 || pack->data == NULL) |
| 1727 | { |
| 1728 | mbtk_apn_info_array_t apns; |
| 1729 | memset(&apns, 0, sizeof(mbtk_apn_info_array_t)); |
| 1730 | if(req_apn_get(&apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1731 | { |
| 1732 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1733 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1734 | } else { |
| 1735 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1736 | } |
| 1737 | LOGD("Get APN fail."); |
| 1738 | } |
| 1739 | else |
| 1740 | { |
| 1741 | LOGD("size - %d", sizeof(mbtk_apn_info_array_t)); |
| 1742 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &apns, sizeof(mbtk_apn_info_array_t)); |
| 1743 | } |
| 1744 | } |
| 1745 | else // Set |
| 1746 | { |
| 1747 | mbtk_apn_info_t *apn = (mbtk_apn_info_t*)pack->data; |
| 1748 | if(apn_cid_reset(apn)) { |
| 1749 | err = MBTK_RIL_ERR_CID; |
| 1750 | } else { |
| 1751 | if(apn_conf_support(apn->cid)) { |
| 1752 | if(req_apn_set(apn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1753 | { |
| 1754 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1755 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1756 | } else { |
| 1757 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1758 | } |
| 1759 | LOGD("Set APN fail."); |
| 1760 | } |
| 1761 | else |
| 1762 | { |
| 1763 | if(apn_prop_set(apn)) { |
| 1764 | LOGE("Save APN fail."); |
| 1765 | } |
| 1766 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 1767 | } |
| 1768 | } else { |
| 1769 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1770 | LOGD("Can not set APN for CID : %d", apn->cid); |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | break; |
| 1775 | } |
| 1776 | case RIL_MSG_ID_NET_DATA_CALL: |
| 1777 | { |
| 1778 | if(pack->data_len == 0 || pack->data == NULL) |
| 1779 | { |
| 1780 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1781 | } |
| 1782 | else // Set |
| 1783 | { |
| 1784 | mbtk_data_call_info_t *call_info = (mbtk_data_call_info_t*)pack->data; |
| 1785 | if(call_info->type == MBTK_DATA_CALL_START) { |
| 1786 | mbtk_ip_info_t ip_info; |
| 1787 | memset(&ip_info, 0, sizeof(ip_info)); |
| 1788 | if(apn_prop_reset(call_info)) { |
| 1789 | err = MBTK_RIL_ERR_REQ_UNKNOWN; |
| 1790 | LOG("apn_prop_reset() fail."); |
| 1791 | } else { |
| 1792 | if(req_data_call_start(call_info->cid, call_info->def_route, |
| 1793 | call_info->retry_interval, call_info->timeout, &ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1794 | { |
| 1795 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1796 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1797 | } else { |
| 1798 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1799 | } |
| 1800 | LOGD("Start data call fail."); |
| 1801 | } |
| 1802 | else |
| 1803 | { |
| 1804 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t)); |
| 1805 | } |
| 1806 | } |
| 1807 | } else if(call_info->type == MBTK_DATA_CALL_STOP) { |
| 1808 | if(req_data_call_stop(call_info->cid, call_info->timeout, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1809 | { |
| 1810 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1811 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1812 | } else { |
| 1813 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1814 | } |
| 1815 | LOGD("Stop data call fail."); |
| 1816 | } |
| 1817 | else |
| 1818 | { |
| 1819 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 1820 | } |
| 1821 | } else { |
| 1822 | mbtk_ip_info_t ip_info; |
| 1823 | memset(&ip_info, 0, sizeof(ip_info)); |
| 1824 | if(req_data_call_state_get(call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1825 | { |
| 1826 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1827 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1828 | } else { |
| 1829 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1830 | } |
| 1831 | LOGD("Get data call state fail."); |
| 1832 | } |
| 1833 | else |
| 1834 | { |
| 1835 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t)); |
| 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | break; |
| 1840 | } |
| 1841 | default: |
| 1842 | { |
| 1843 | err = MBTK_RIL_ERR_REQ_UNKNOWN; |
| 1844 | LOG("Unknown request : %s", id2str(pack->msg_id)); |
| 1845 | break; |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | return err; |
| 1850 | } |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |