liubin | 281ac46 | 2023-07-19 14:22:54 +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 <string.h> |
| 11 | #include <fcntl.h> |
| 12 | #include <signal.h> |
| 13 | |
| 14 | #include "mbtk_info.h" |
| 15 | #include "mbtk_list.h" |
| 16 | #include "mbtk_utils.h" |
| 17 | |
| 18 | #include "time.h" |
| 19 | |
| 20 | #define EPOLL_LISTEN_MAX 100 |
| 21 | #define EPOLL_LISTEN_MAX 100 |
| 22 | |
| 23 | #if 0 |
| 24 | struct |
| 25 | { |
| 26 | uint8 operator[128]; |
| 27 | uint8 operator[128]; |
| 28 | uint8 mcc_mnc[10]; |
| 29 | } operator_mcc_mnc = |
| 30 | { |
| 31 | {"China Mobile","CMCC","46000"}, |
| 32 | {"China Unicom","CU","46001"}, |
| 33 | {"China Mobile","CMCC","46002"}, |
| 34 | {"China Telecom","CT","46003"}, |
| 35 | {"China Mobile","CMCC","46004"}, |
| 36 | {"China Telecom","CT","46005"}, |
| 37 | {"China Unicom","CU","46006"}, |
| 38 | {"China Mobile","CMCC","46007"}, |
| 39 | {"China Mobile","CMCC","46008"}, |
| 40 | {"China Unicom","CU","46009"}, |
| 41 | {"China Telecom","CT","46011"}, |
| 42 | {NULL, NULL, NULL} |
| 43 | }; |
| 44 | #endif |
| 45 | |
| 46 | static int pack_process(mbtk_info_handle_t* handle, mbtk_info_pack_t* pack) |
| 47 | { |
| 48 | mbtk_info_type_enum info_type = mbtk_info_type_get(pack->info_id); |
| 49 | LOG("Type : %s, ID : %s, Result : %s ,Length : %d", type2str(info_type), |
| 50 | id2str(pack->info_id), |
| 51 | err2str(pack->info_err), |
| 52 | pack->data_len); |
| 53 | if(0 && pack->data_len > 0) |
| 54 | { |
| 55 | log_hex("DATA", pack->data, pack->data_len); |
| 56 | } |
| 57 | // IND Message. |
| 58 | if(info_type == MBTK_INFO_TYPE_IND) |
| 59 | { |
| 60 | if(pack->data_len > 0 && pack->data != NULL) // IND message. |
| 61 | { |
| 62 | log_hex(id2str(pack->info_id), pack->data, pack->data_len); |
| 63 | switch(pack->info_id) |
| 64 | { |
| 65 | case MBTK_INFO_ID_IND_NET_STATE_CHANGE: |
| 66 | { |
| 67 | if(handle->net_state_cb) |
| 68 | handle->net_state_cb(pack->data, pack->data_len); |
| 69 | break; |
| 70 | } |
| 71 | case MBTK_INFO_ID_IND_CALL_STATE_CHANGE: |
| 72 | { |
| 73 | if(handle->call_state_cb) |
| 74 | handle->call_state_cb(pack->data, pack->data_len); |
| 75 | break; |
| 76 | } |
| 77 | case MBTK_INFO_ID_IND_SMS_STATE_CHANGE: |
| 78 | { |
| 79 | if(handle->sms_state_cb) |
| 80 | handle->sms_state_cb(pack->data, pack->data_len); |
| 81 | break; |
| 82 | } |
| 83 | case MBTK_INFO_ID_IND_RADIO_STATE_CHANGE: |
| 84 | { |
| 85 | if(handle->radio_state_cb) |
| 86 | handle->radio_state_cb(pack->data, pack->data_len); |
| 87 | break; |
| 88 | } |
| 89 | case MBTK_INFO_ID_IND_SIM_STATE_CHANGE: |
| 90 | { |
| 91 | if(handle->sim_state_cb) |
| 92 | handle->sim_state_cb(pack->data, pack->data_len); |
| 93 | break; |
| 94 | } |
| 95 | case MBTK_INFO_ID_IND_PDP_STATE_CHANGE: |
| 96 | { |
| 97 | if(handle->pdp_state_cb) |
| 98 | handle->pdp_state_cb(pack->data, pack->data_len); |
| 99 | break; |
| 100 | } |
| 101 | //mbtk wyq for server_ready_status add start |
| 102 | case MBTK_INFO_ID_IND_SERVER_STATE_CHANGE: |
| 103 | { |
| 104 | handle->server_ready_status = 1; |
| 105 | LOG("handshake message recv ok."); |
| 106 | break; |
| 107 | } |
| 108 | //mbtk wyq for server_ready_status add end |
| 109 | default: |
| 110 | { |
| 111 | LOG("Unknown IND : %d", pack->info_id); |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | else // Register IND response. |
| 117 | { |
| 118 | handle->info_err = pack->info_err; |
| 119 | if(pack->info_err == MBTK_INFO_ERR_SUCCESS) |
| 120 | { |
| 121 | LOG("IND %s register success.", id2str(pack->info_id)); |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | LOG("IND %s register fail : %s", id2str(pack->info_id), err2str(pack->info_err)); |
| 126 | } |
| 127 | |
| 128 | if(handle->is_waitting) { |
| 129 | pthread_mutex_lock(&handle->mutex); |
| 130 | pthread_cond_signal(&handle->cond); |
| 131 | pthread_mutex_unlock(&handle->mutex); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | else // Response Information. |
| 136 | { |
| 137 | handle->info_err = pack->info_err; |
| 138 | |
| 139 | // Set data length. |
| 140 | // If data change,will change this lenght in mbtk_info_pack_data_get(). |
| 141 | handle->data_len = pack->data_len; |
| 142 | // Copy data buffer,because it will be released. |
| 143 | if(handle->data && pack->data && pack->data_len > 0) { |
| 144 | memcpy(handle->data, pack->data, handle->data_len); |
| 145 | } |
| 146 | |
| 147 | if(handle->is_waitting) { |
| 148 | pthread_mutex_lock(&handle->mutex); |
| 149 | pthread_cond_signal(&handle->cond); |
| 150 | pthread_mutex_unlock(&handle->mutex); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | #if 0 |
| 155 | if(pack->info_err == MBTK_INFO_ERR_SUCCESS) |
| 156 | { |
| 157 | LOG("REQ %s success.", id2str(pack->info_id)); |
| 158 | #if 0 |
| 159 | if(pack->data_len > 0) |
| 160 | { |
| 161 | log_hex("DATA", pack->data, pack->data_len); |
| 162 | } |
| 163 | #endif |
| 164 | switch(pack->info_id) |
| 165 | { |
| 166 | case MBTK_INFO_ID_NET_AVAILABLE_RSP: |
| 167 | { |
| 168 | mbtk_net_array_info_t* nets = (mbtk_net_array_info_t*)mbtk_info_pack_data_get(pack); |
| 169 | if(nets) |
| 170 | { |
| 171 | mbtk_net_info_t *net = NULL; |
| 172 | list_first(nets->net_list); |
| 173 | while ((net = (mbtk_net_info_t*) list_next(nets->net_list))) |
| 174 | { |
| 175 | LOG("NET : %d, %d, %s", net->net_sel_mode, net->net_type, net->plmn); |
| 176 | } |
| 177 | list_free(nets->net_list); |
| 178 | free(nets); |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | LOG("mbtk_info_pack_data_get() fail."); |
| 183 | } |
| 184 | |
| 185 | break; |
| 186 | } |
| 187 | case MBTK_INFO_ID_NET_SEL_MODE_RSP: |
| 188 | { |
| 189 | mbtk_net_info_t* net = (mbtk_net_info_t*)mbtk_info_pack_data_get(pack); |
| 190 | if(net) |
| 191 | { |
| 192 | LOG("NET : %d, %d, %d", net->net_sel_mode, net->net_type, net->plmn); |
| 193 | free(net); |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | LOG("mbtk_info_pack_data_get() fail."); |
| 198 | } |
| 199 | |
| 200 | break; |
| 201 | } |
| 202 | case MBTK_INFO_ID_NET_BAND_RSP: |
| 203 | { |
| 204 | mbtk_band_info_t* band = (mbtk_band_info_t*)mbtk_info_pack_data_get(pack); |
| 205 | if(band) { |
| 206 | LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, |
| 207 | band->gsm_band, |
| 208 | band->umts_band, |
| 209 | band->tdlte_band, |
| 210 | band->fddlte_band); |
| 211 | } else { |
| 212 | LOG("mbtk_info_pack_data_get() fail."); |
| 213 | } |
| 214 | |
| 215 | break; |
| 216 | } |
| 217 | default: |
| 218 | { |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | LOG("REQ %s fail : %s", id2str(pack->info_id), err2str(pack->info_err)); |
| 226 | } |
| 227 | #endif |
| 228 | } |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | static void* info_read_run(void* arg) |
| 234 | { |
| 235 | int epoll_fd = epoll_create(5); |
| 236 | if(epoll_fd < 0) |
| 237 | { |
| 238 | LOG("epoll_create() fail[%d].", errno); |
| 239 | return NULL; |
| 240 | } |
| 241 | mbtk_info_handle_t* handle = (mbtk_info_handle_t*)arg; |
| 242 | |
| 243 | uint32 event = EPOLLIN | EPOLLET; |
| 244 | struct epoll_event ev_cli, ev_exit; |
| 245 | ev_cli.data.fd = handle->client_fd; |
| 246 | ev_cli.events = event; //EPOLLIN | EPOLLERR | EPOLLET; |
| 247 | epoll_ctl(epoll_fd,EPOLL_CTL_ADD,handle->client_fd,&ev_cli); |
| 248 | |
| 249 | ev_exit.data.fd = handle->exit_fd[0]; |
| 250 | ev_exit.events = event; //EPOLLIN | EPOLLERR | EPOLLET; |
| 251 | epoll_ctl(epoll_fd,EPOLL_CTL_ADD,handle->exit_fd[0],&ev_exit); |
| 252 | |
| 253 | int nready = -1; |
| 254 | struct epoll_event epoll_events[EPOLL_LISTEN_MAX]; |
| 255 | while(1) |
| 256 | { |
| 257 | nready = epoll_wait(epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1); |
| 258 | if(nready > 0) |
| 259 | { |
| 260 | int i; |
| 261 | for(i = 0; i < nready; i++) |
| 262 | { |
| 263 | LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events); |
| 264 | if(epoll_events[i].events & EPOLLHUP) // Closed by server. |
| 265 | { |
| 266 | |
| 267 | } |
| 268 | else if(epoll_events[i].events & EPOLLIN) |
| 269 | { |
| 270 | if(handle->client_fd == epoll_events[i].data.fd) // Server data arrive. |
| 271 | { |
| 272 | // Read and process every message. |
| 273 | mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS; |
| 274 | mbtk_info_pack_t **pack = mbtk_info_pack_recv(handle->client_fd, false, &err); |
| 275 | |
| 276 | // Parse packet error,send error response to client. |
| 277 | if(pack == NULL) |
| 278 | { |
| 279 | if(err != MBTK_INFO_ERR_SUCCESS) |
| 280 | { |
| 281 | LOG("RSP packet error[%s].", err2str(err)); |
| 282 | } |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | mbtk_info_pack_t** pack_ptr = pack; |
| 287 | while(*pack_ptr) |
| 288 | { |
| 289 | pack_process(handle, *pack_ptr); |
| 290 | mbtk_info_pack_free(pack_ptr); |
| 291 | pack_ptr++; |
| 292 | } |
| 293 | free(pack); |
| 294 | } |
| 295 | } |
| 296 | else if(handle->exit_fd[0] == epoll_events[i].data.fd) // |
| 297 | { |
| 298 | char buff[100] = {0}; |
| 299 | int len = read(handle->exit_fd[0], buff, 100); |
| 300 | if(len > 0) { |
| 301 | LOGI("CMD : %s", buff); |
| 302 | if(strcmp(buff, "EXIT") == 0) { |
| 303 | goto read_thread_exit; |
| 304 | } else { |
| 305 | LOGD("Unkonw cmd : %s", buff); |
| 306 | } |
| 307 | } else { |
| 308 | LOGE("sock_read() fail."); |
| 309 | } |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | LOG("Unknown socket : %d", epoll_events[i].data.fd); |
| 314 | } |
| 315 | } |
| 316 | else |
| 317 | { |
| 318 | LOG("Unknown event : %x", epoll_events[i].events); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | LOG("epoll_wait() fail[%d].", errno); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | read_thread_exit: |
| 329 | LOGD("info_read thread exit."); |
| 330 | return NULL; |
| 331 | } |
| 332 | |
| 333 | #if 0 |
| 334 | static int info_item_get(mbtk_info_handle_t* handle, mbtk_info_id_enum id, void* data) |
| 335 | { |
| 336 | int data_len = 0; |
| 337 | if(data == NULL) { |
| 338 | LOG("data is null."); |
| 339 | return -1; |
| 340 | } |
| 341 | mbtk_info_pack_t* pack = mbtk_info_pack_creat(id); |
| 342 | if(pack == NULL) { |
| 343 | LOG("mbtk_info_item_get() fail."); |
| 344 | return -1; |
| 345 | } |
| 346 | |
| 347 | mbtk_info_pack_send(handle->client_fd, pack); |
| 348 | mbtk_info_pack_free(&pack); |
| 349 | handle->data = data; |
| 350 | |
| 351 | // Wait for server response. |
| 352 | pthread_mutex_lock(&handle->mutex); |
| 353 | handle->is_waitting = true; |
| 354 | pthread_cond_wait(&handle->cond, &handle->mutex); |
| 355 | handle->is_waitting = false; |
| 356 | pthread_mutex_unlock(&handle->mutex); |
| 357 | |
| 358 | if(handle->info_err == MBTK_INFO_ERR_SUCCESS) |
| 359 | { |
| 360 | LOG("REQ %s success.", id2str(id)); |
| 361 | if(data && handle->data_len > 0) { |
| 362 | data_len = handle->data_len; |
| 363 | handle->data_len = 0; |
| 364 | handle->data = NULL; |
| 365 | } |
| 366 | return data_len; |
| 367 | } else { |
| 368 | LOG("REQ %s fail : %s", id2str(id), err2str(handle->info_err)); |
| 369 | return -1; |
| 370 | } |
| 371 | } |
| 372 | #endif |
| 373 | |
| 374 | /* |
| 375 | * Return recv data length. |
| 376 | * -1 : fail. |
| 377 | */ |
| 378 | static int info_item_process(mbtk_info_handle_t *handle, |
| 379 | mbtk_info_id_enum id, |
| 380 | const void *send_buff, |
| 381 | int send_buff_len, |
| 382 | void *recv_buff) |
| 383 | { |
| 384 | if(handle == NULL/* || ((send_buff == NULL || send_buff_len == 0) && recv_buff == NULL)*/) { |
| 385 | LOG("ARG error."); |
| 386 | return -1; |
| 387 | } |
| 388 | |
| 389 | mbtk_info_pack_t* pack = mbtk_info_pack_creat(id); |
| 390 | if(pack == NULL) { |
| 391 | return -1; |
| 392 | } |
| 393 | if(send_buff && send_buff_len > 0) { // Set the data to be sent. |
| 394 | // log_hex("data", send_buff, send_buff_len); |
| 395 | // mbtk_info_pack_data_set(pack, data, data_len); |
| 396 | pack->data_len = (uint16)send_buff_len; |
| 397 | pack->data = (const uint8*)send_buff; |
| 398 | } |
| 399 | mbtk_info_pack_send(handle->client_fd, pack); |
| 400 | mbtk_info_pack_free(&pack); |
| 401 | |
| 402 | if(recv_buff != NULL) |
| 403 | handle->data = recv_buff; |
| 404 | |
| 405 | // Wait for server response. |
| 406 | pthread_mutex_lock(&handle->mutex); |
| 407 | handle->is_waitting = true; |
| 408 | pthread_cond_wait(&handle->cond, &handle->mutex); |
| 409 | handle->is_waitting = false; |
| 410 | pthread_mutex_unlock(&handle->mutex); |
| 411 | |
| 412 | if(handle->info_err == MBTK_INFO_ERR_SUCCESS) |
| 413 | { |
| 414 | LOG("REQ %s success.", id2str(id)); |
| 415 | int recv_len = 0; |
| 416 | if(recv_buff && handle->data_len > 0) { |
| 417 | recv_len = handle->data_len; |
| 418 | handle->data_len = 0; |
| 419 | handle->data = NULL; |
| 420 | } |
| 421 | return recv_len; |
| 422 | } else { |
| 423 | LOG("REQ %s fail : %s", id2str(id), err2str(handle->info_err)); |
| 424 | return -1; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | |
| 429 | |
| 430 | mbtk_info_handle_t* mbtk_info_handle_get() |
| 431 | { |
| 432 | mbtk_info_handle_t* handle = (mbtk_info_handle_t*)malloc(sizeof(mbtk_info_handle_t)); |
| 433 | if(!handle) |
| 434 | { |
| 435 | LOG("malloc() error[%d].", errno); |
| 436 | return NULL; |
| 437 | } |
| 438 | memset(handle, 0, sizeof(mbtk_info_handle_t)); |
| 439 | handle->client_fd = socket(AF_LOCAL, SOCK_STREAM, 0); |
| 440 | if(handle->client_fd < 0) |
| 441 | { |
| 442 | LOG("socket() fail[%d].", errno); |
| 443 | goto error; |
| 444 | } |
| 445 | |
| 446 | // Set O_NONBLOCK |
| 447 | int flags = fcntl(handle->client_fd, F_GETFL, 0); |
| 448 | if (flags < 0) |
| 449 | { |
| 450 | LOG("Get flags error:%d", errno); |
| 451 | goto error; |
| 452 | } |
| 453 | flags |= O_NONBLOCK; |
| 454 | if (fcntl(handle->client_fd, F_SETFL, flags) < 0) |
| 455 | { |
| 456 | LOG("Set flags error:%d", errno); |
| 457 | goto error; |
| 458 | } |
| 459 | |
| 460 | struct sockaddr_un cli_addr; |
| 461 | memset(&cli_addr, 0, sizeof(cli_addr)); |
| 462 | cli_addr.sun_family = AF_LOCAL; |
| 463 | strcpy(cli_addr.sun_path, SOCK_INFO_PATH); |
| 464 | if(connect(handle->client_fd, (struct sockaddr *)&cli_addr, sizeof(cli_addr))) |
| 465 | { |
| 466 | LOG("connect() fail[%d].", errno); |
| 467 | goto error; |
| 468 | } |
| 469 | |
| 470 | if(pipe(handle->exit_fd)) { |
| 471 | LOG("pipe() fail[%d].", errno); |
| 472 | goto error; |
| 473 | } |
| 474 | #if 0 |
| 475 | pthread_attr_t thread_attr; |
| 476 | pthread_attr_init(&thread_attr); |
| 477 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 478 | { |
| 479 | LOG("pthread_attr_setdetachstate() fail."); |
| 480 | goto error; |
| 481 | } |
| 482 | |
| 483 | if(pthread_create(&(handle->read_thread_id), &thread_attr, info_read_run, handle)) |
| 484 | { |
| 485 | LOG("pthread_create() fail."); |
| 486 | goto error; |
| 487 | } |
| 488 | pthread_attr_destroy(&thread_attr); |
| 489 | #else |
| 490 | if(pthread_create(&(handle->read_thread_id), NULL, info_read_run, handle)) |
| 491 | { |
| 492 | LOG("pthread_create() fail."); |
| 493 | goto error; |
| 494 | } |
| 495 | #endif |
| 496 | |
| 497 | pthread_mutex_init(&handle->mutex, NULL); |
| 498 | pthread_cond_init(&handle->cond, NULL); |
| 499 | handle->is_waitting = false; |
| 500 | |
| 501 | //mbtk wyq for server_ready_status add start |
| 502 | int timeout = 5;//The wait server timeout by default |
| 503 | LOG("wait server handshake message--->."); |
| 504 | while(timeout) |
| 505 | { |
| 506 | if(handle->server_ready_status) |
| 507 | { |
| 508 | break; |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | sleep(1); |
| 513 | timeout--; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | if(timeout <= 0) |
| 518 | { |
| 519 | if(handle->exit_fd[1] > 0) |
| 520 | { |
| 521 | write(handle->exit_fd[1], "EXIT", 4); |
| 522 | } |
| 523 | pthread_join(handle->read_thread_id,NULL); |
| 524 | LOG("mbtk_info_handle_get() server not ready."); |
| 525 | goto error; |
| 526 | } |
| 527 | else |
| 528 | { |
| 529 | LOG("mbtk_info_handle_get() server ready ok."); |
| 530 | } |
| 531 | //mbtk wyq for server_ready_status add end |
| 532 | return handle; |
| 533 | error: |
| 534 | if(handle) |
| 535 | { |
| 536 | if(handle->client_fd > 0) |
| 537 | { |
| 538 | close(handle->client_fd); |
| 539 | } |
| 540 | if(handle->exit_fd[0] > 0) { |
| 541 | close(handle->exit_fd[0]); |
| 542 | } |
| 543 | if(handle->exit_fd[1] > 0) { |
| 544 | close(handle->exit_fd[1]); |
| 545 | } |
| 546 | free(handle); |
| 547 | handle = NULL; |
| 548 | } |
| 549 | |
| 550 | return NULL; |
| 551 | } |
| 552 | |
| 553 | int mbtk_info_handle_free(mbtk_info_handle_t** handle) |
| 554 | { |
| 555 | if(handle == NULL || *handle == NULL) |
| 556 | { |
| 557 | LOG("Handle is NULL."); |
| 558 | return -1; |
| 559 | } |
| 560 | |
| 561 | if((*handle)->exit_fd[1] > 0) { |
| 562 | write((*handle)->exit_fd[1], "EXIT", 4); |
| 563 | } |
| 564 | |
| 565 | // Wait read_thread exit. |
| 566 | pthread_join((*handle)->read_thread_id,NULL); |
| 567 | |
| 568 | if((*handle)->exit_fd[0] > 0) { |
| 569 | close((*handle)->exit_fd[0]); |
| 570 | (*handle)->exit_fd[0] = -1; |
| 571 | } |
| 572 | |
| 573 | if((*handle)->exit_fd[1] > 0) { |
| 574 | close((*handle)->exit_fd[1]); |
| 575 | (*handle)->exit_fd[1] = -1; |
| 576 | } |
| 577 | |
| 578 | if((*handle)->client_fd > 0) |
| 579 | { |
| 580 | close((*handle)->client_fd); |
| 581 | (*handle)->client_fd = -1; |
| 582 | } |
| 583 | free(*handle); |
| 584 | *handle = NULL; |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | /* |
| 589 | * Get platform version. |
| 590 | */ |
| 591 | int mbtk_version_get(mbtk_info_handle_t* handle, void *version) |
| 592 | { |
| 593 | if(handle == NULL || version == NULL) |
| 594 | { |
| 595 | LOGE("ARG error."); |
| 596 | return -1; |
| 597 | } |
| 598 | |
| 599 | if(info_item_process(handle, MBTK_INFO_ID_DEV_VERSION_REQ, NULL, 0, version) > 0) { |
| 600 | LOG("Version : %s", version); |
| 601 | return 0; |
| 602 | } else { |
| 603 | return handle->info_err; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | /* |
| 608 | * Get platform version. |
| 609 | */ |
| 610 | int mbtk_model_get(mbtk_info_handle_t* handle, void *model) |
| 611 | { |
| 612 | if(handle == NULL || model == NULL) |
| 613 | { |
| 614 | LOGE("ARG error."); |
| 615 | return -1; |
| 616 | } |
| 617 | |
| 618 | if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEL_REQ, NULL, 0, model) > 0) { |
| 619 | LOG("Version : %s", model); |
| 620 | return 0; |
| 621 | } else { |
| 622 | return handle->info_err; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | /* |
| 627 | * Get platform IMEI. |
| 628 | */ |
| 629 | int mbtk_imei_get(mbtk_info_handle_t* handle, void *imei) |
| 630 | { |
| 631 | if(handle == NULL || imei == NULL) |
| 632 | { |
| 633 | LOGE("ARG error."); |
| 634 | return -1; |
| 635 | } |
| 636 | if(info_item_process(handle, MBTK_INFO_ID_DEV_IMEI_REQ, NULL, 0, imei) > 0) { |
| 637 | LOG("IMEI : %s", imei); |
| 638 | return 0; |
| 639 | } else { |
| 640 | return handle->info_err; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | * Get platform SN. |
| 646 | */ |
| 647 | int mbtk_sn_get(mbtk_info_handle_t* handle, void *sn) |
| 648 | { |
| 649 | if(handle == NULL || sn == NULL) |
| 650 | { |
| 651 | LOGE("ARG error."); |
| 652 | return -1; |
| 653 | } |
| 654 | if(info_item_process(handle, MBTK_INFO_ID_DEV_SN_REQ, NULL, 0, sn) > 0) { |
| 655 | LOG("SN : %s", sn); |
| 656 | return 0; |
| 657 | } else { |
| 658 | return handle->info_err; |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | * Get platform MEID. |
| 664 | */ |
| 665 | int mbtk_meid_get(mbtk_info_handle_t* handle, void *meid) |
| 666 | { |
| 667 | if(handle == NULL || meid == NULL) |
| 668 | { |
| 669 | LOGE("ARG error."); |
| 670 | return -1; |
| 671 | } |
| 672 | if(info_item_process(handle, MBTK_INFO_ID_DEV_MEID_REQ, NULL, 0, meid) > 0) { |
| 673 | LOG("MEID : %s", meid); |
| 674 | return 0; |
| 675 | } else { |
| 676 | return handle->info_err; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /* |
| 681 | * Return VoLTE state. |
| 682 | */ |
| 683 | int mbtk_volte_state_get(mbtk_info_handle_t* handle, int *volte_state) |
| 684 | { |
| 685 | uint8 state; |
| 686 | if(handle == NULL || volte_state == NULL) |
| 687 | { |
| 688 | LOGE("ARG error."); |
| 689 | return -1; |
| 690 | } |
| 691 | if(info_item_process(handle, MBTK_INFO_ID_DEV_VOLTE_REQ, NULL, 0, &state) > 0) { |
| 692 | LOG("VoLTE State : %d", state); |
| 693 | *volte_state = state; |
| 694 | return 0; |
| 695 | } else { |
| 696 | return handle->info_err; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * Set VoLTE state. |
| 702 | * |
| 703 | * volte_state: |
| 704 | * 0 : Close VoLTE. |
| 705 | * 1 : Open VoLTE. |
| 706 | * |
| 707 | * Restarting takes effect after execution. |
| 708 | */ |
| 709 | int mbtk_volte_state_set(mbtk_info_handle_t* handle, int volte_state) |
| 710 | { |
| 711 | if(handle == NULL) |
| 712 | { |
| 713 | LOGE("ARG error."); |
| 714 | return -1; |
| 715 | } |
| 716 | return info_item_process(handle, MBTK_INFO_ID_DEV_VOLTE_REQ, (uint8*)&volte_state, sizeof(uint8), NULL) ? handle->info_err : 0; |
| 717 | } |
| 718 | |
| 719 | /* |
| 720 | * Get platform IMSI. |
| 721 | */ |
| 722 | int mbtk_imsi_get(mbtk_info_handle_t* handle, void *imsi) |
| 723 | { |
| 724 | if(handle == NULL || imsi == NULL) |
| 725 | { |
| 726 | LOGE("ARG error."); |
| 727 | return -1; |
| 728 | } |
| 729 | if(info_item_process(handle, MBTK_INFO_ID_SIM_IMSI_REQ, NULL, 0, imsi) > 0) { |
| 730 | LOG("IMSI : %s", imsi); |
| 731 | return 0; |
| 732 | } else { |
| 733 | return handle->info_err; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | /* |
| 738 | * Get platform ICCID. |
| 739 | */ |
| 740 | int mbtk_iccid_get(mbtk_info_handle_t* handle, void *iccid) |
| 741 | { |
| 742 | if(handle == NULL || iccid == NULL) |
| 743 | { |
| 744 | LOGE("ARG error."); |
| 745 | return -1; |
| 746 | } |
| 747 | if(info_item_process(handle, MBTK_INFO_ID_SIM_ICCID_REQ, NULL, 0, iccid) > 0) { |
| 748 | LOG("ICCID : %s", iccid); |
| 749 | return 0; |
| 750 | } else { |
| 751 | return handle->info_err; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | * Get current phone number. |
| 757 | */ |
| 758 | int mbtk_phone_number_get(mbtk_info_handle_t* handle, void *phone_number) |
| 759 | { |
| 760 | if(handle == NULL || phone_number == NULL) |
| 761 | { |
| 762 | LOGE("ARG error."); |
| 763 | return -1; |
| 764 | } |
| 765 | if(info_item_process(handle, MBTK_INFO_ID_SIM_PN_REQ, NULL, 0, phone_number) > 0) { |
| 766 | LOG("Phone Number : %s", phone_number); |
| 767 | return 0; |
| 768 | } else { |
| 769 | return handle->info_err; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | /* |
| 774 | * Get PIN’s number of remaining retry |
| 775 | */ |
| 776 | int mbtk_pin_last_num_get(mbtk_info_handle_t* handle, mbtk_pin_puk_last_times *last_times) |
| 777 | { |
| 778 | if(handle == NULL || last_times == NULL) |
| 779 | { |
| 780 | LOGE("ARG error."); |
| 781 | return -1; |
| 782 | } |
| 783 | if(info_item_process(handle, MBTK_INFO_ID_SIM_PINPUK_TIMES_REQ, NULL, 0, last_times) > 0) { |
| 784 | LOG("Sim sim_pin_puk_last_times : %d, %d, %d, %d", last_times->p1_retry,last_times->p2_retry,last_times->puk1_retry,last_times->puk2_retry); |
| 785 | return 0; |
| 786 | } else { |
| 787 | return handle->info_err; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | /* |
| 792 | * emable PIN |
| 793 | */ |
| 794 | int mbtk_enable_pin(mbtk_info_handle_t* handle, mbtk_enable_pin_info *pin) |
| 795 | { |
| 796 | if(handle == NULL) |
| 797 | { |
| 798 | LOGE("ARG error."); |
| 799 | return -1; |
| 800 | } |
| 801 | if(info_item_process(handle, MBTK_INFO_ID_SIM_ENABLE_PIN_REQ, pin, sizeof(mbtk_enable_pin_info), NULL) >= 0) { |
| 802 | LOG("pin Number : %s", pin->pin_value); |
| 803 | return 0; |
| 804 | } else { |
| 805 | return handle->info_err; |
| 806 | } |
| 807 | |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | * Verify PIN |
| 812 | */ |
| 813 | int mbtk_verify_pin(mbtk_info_handle_t* handle, char *pin) |
| 814 | { |
| 815 | if(handle == NULL) |
| 816 | { |
| 817 | LOGE("ARG error."); |
| 818 | return -1; |
| 819 | } |
| 820 | if(info_item_process(handle, MBTK_INFO_ID_SIM_PIN_REQ, pin, strlen(pin), NULL) >= 0) { |
| 821 | LOG("pin Number : %s", pin); |
| 822 | return 0; |
| 823 | } else { |
| 824 | return handle->info_err; |
| 825 | } |
| 826 | |
| 827 | } |
| 828 | |
| 829 | /* |
| 830 | * Verify PIN |
| 831 | */ |
| 832 | int mbtk_change_pin(mbtk_info_handle_t* handle, mbtk_change_pin_info *pin) |
| 833 | { |
| 834 | if(handle == NULL) |
| 835 | { |
| 836 | LOGE("ARG error."); |
| 837 | return -1; |
| 838 | } |
| 839 | if(info_item_process(handle, MBTK_INFO_ID_SIM_CHANGE_PIN_REQ, pin, sizeof(mbtk_change_pin_info), NULL) >= 0) { |
| 840 | LOG("Change PIN : %s -> %s", pin->old_pin_value, pin->new_pin_value); |
| 841 | return 0; |
| 842 | } else { |
| 843 | return handle->info_err; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | /* |
| 848 | * unblock_pin |
| 849 | */ |
| 850 | int mbtk_unlock_pin(mbtk_info_handle_t* handle, mbtk_unlock_pin_info *pin) |
| 851 | { |
| 852 | if(handle == NULL) |
| 853 | { |
| 854 | LOGE("ARG error."); |
| 855 | return -1; |
| 856 | } |
| 857 | if(info_item_process(handle, MBTK_INFO_ID_SIM_PUK_REQ, pin, sizeof(mbtk_unlock_pin_info), NULL) >= 0) { |
| 858 | LOG("Unlock : %s , %s", pin->pin_value , pin->puk_value); |
| 859 | return 0; |
| 860 | } else { |
| 861 | return handle->info_err; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | /* |
| 866 | * Get plmn list |
| 867 | */ |
| 868 | int mbtk_get_plmn_list(mbtk_info_handle_t* handle, mbtk_plmn_info *pin) |
| 869 | { |
| 870 | if(handle == NULL) |
| 871 | { |
| 872 | LOGE("ARG error."); |
| 873 | return -1; |
| 874 | } |
| 875 | if(info_item_process(handle, MBTK_INFO_ID_SIM_PLMN_REQ, NULL, 0, pin) >= 0) { |
| 876 | //LOG("pin Number : %s", pin); |
| 877 | return 0; |
| 878 | } else { |
| 879 | return handle->info_err; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | |
| 884 | /* |
| 885 | * Get available network. |
| 886 | */ |
| 887 | int mbtk_available_net_get(mbtk_info_handle_t* handle, list_node_t **net_list) |
| 888 | { |
| 889 | if(handle == NULL) |
| 890 | { |
| 891 | LOGE("ARG error."); |
| 892 | return -1; |
| 893 | } |
| 894 | *net_list = list_create(NULL); |
| 895 | if(*net_list == NULL) |
| 896 | { |
| 897 | LOG("list_create() fail."); |
| 898 | return MBTK_INFO_ERR_MEMORY; |
| 899 | } |
| 900 | |
| 901 | uint8 buff[SOCK_MSG_LEN_MAX] = {0}; |
| 902 | int buff_len; |
| 903 | if((buff_len = info_item_process(handle, MBTK_INFO_ID_NET_AVAILABLE_REQ, NULL, 0, buff)) > 0) { |
| 904 | int i = 0; |
| 905 | while (i < buff_len / sizeof(mbtk_net_info_t)) |
| 906 | { |
| 907 | mbtk_net_info_t* net = (mbtk_net_info_t*)malloc(sizeof(mbtk_net_info_t)); |
| 908 | if(net == NULL) |
| 909 | { |
| 910 | LOG("malloc() fail."); |
| 911 | list_free(*net_list); |
| 912 | return MBTK_INFO_ERR_MEMORY; |
| 913 | } |
| 914 | memcpy(net, buff + i * sizeof(mbtk_net_info_t), sizeof(mbtk_net_info_t)); |
| 915 | list_add(*net_list, net); |
| 916 | |
| 917 | LOG("NET-%d: %d, %d, %d, %d", i + 1, net->net_sel_mode, net->net_type, net->net_state, net->plmn); |
| 918 | i++; |
| 919 | } |
| 920 | |
| 921 | return 0; |
| 922 | } else { |
| 923 | list_free(*net_list); |
| 924 | return handle->info_err; |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | /* |
| 929 | * Set network select mode. (+COPS=...) |
| 930 | */ |
| 931 | int mbtk_net_sel_mode_set(mbtk_info_handle_t* handle, const mbtk_net_info_t *net) |
| 932 | { |
| 933 | if(handle == NULL || net == NULL) |
| 934 | { |
| 935 | LOGE("ARG error."); |
| 936 | return -1; |
| 937 | } |
| 938 | return info_item_process(handle, MBTK_INFO_ID_NET_SEL_MODE_REQ, net, sizeof(mbtk_net_info_t), NULL) ? handle->info_err : 0; |
| 939 | } |
| 940 | |
| 941 | /* |
| 942 | * Get network select mode. (+COPS?) |
| 943 | */ |
| 944 | int mbtk_net_sel_mode_get(mbtk_info_handle_t* handle, mbtk_net_info_t *net) |
| 945 | { |
| 946 | if(handle == NULL || net == NULL) |
| 947 | { |
| 948 | LOGE("ARG error."); |
| 949 | return -1; |
| 950 | } |
| 951 | if(info_item_process(handle, MBTK_INFO_ID_NET_SEL_MODE_REQ, NULL, 0, net) > 0) { |
| 952 | LOG("NET : %d, %d, %d, %d", net->net_sel_mode, net->net_type, net->net_state, net->plmn); |
| 953 | return 0; |
| 954 | } else { |
| 955 | return handle->info_err; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | /* |
| 960 | * Get platform support bands. |
| 961 | */ |
| 962 | int mbtk_support_band_get(mbtk_info_handle_t* handle, mbtk_band_info_t *band) |
| 963 | { |
| 964 | uint8 type = 0; // Get support bands. |
| 965 | if(handle == NULL || band == NULL) |
| 966 | { |
| 967 | LOGE("ARG error."); |
| 968 | return -1; |
| 969 | } |
| 970 | if(info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, &type, sizeof(uint8), band) > 0) { |
| 971 | LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band); |
| 972 | return 0; |
| 973 | } else { |
| 974 | return handle->info_err; |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | /* |
| 979 | * Get platform current bands. |
| 980 | */ |
| 981 | int mbtk_current_band_get(mbtk_info_handle_t* handle, mbtk_band_info_t *band) |
| 982 | { |
| 983 | uint8 type = 1; // Get current bands. |
| 984 | if(handle == NULL || band == NULL) |
| 985 | { |
| 986 | LOGE("ARG error."); |
| 987 | return -1; |
| 988 | } |
| 989 | if(info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, &type, sizeof(uint8), band) > 0) { |
| 990 | LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band); |
| 991 | return 0; |
| 992 | } else { |
| 993 | return handle->info_err; |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | /* |
| 998 | * Set platform current bands. |
| 999 | */ |
| 1000 | int mbtk_current_band_set(mbtk_info_handle_t* handle, const mbtk_band_info_t *band) |
| 1001 | { |
| 1002 | if(handle == NULL || band == NULL) |
| 1003 | { |
| 1004 | LOGE("ARG error."); |
| 1005 | return -1; |
| 1006 | } |
| 1007 | return info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, band, sizeof(mbtk_band_info_t), NULL) ? handle->info_err : 0; |
| 1008 | } |
| 1009 | |
| 1010 | /* |
| 1011 | * Get current cell infomation. |
| 1012 | */ |
| 1013 | int mbtk_cell_get(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list) |
| 1014 | { |
| 1015 | if(handle == NULL) |
| 1016 | { |
| 1017 | LOGE("ARG error."); |
| 1018 | return -1; |
| 1019 | } |
| 1020 | *cell_list = list_create(NULL); |
| 1021 | if(*cell_list == NULL) |
| 1022 | { |
| 1023 | LOG("list_create() fail."); |
| 1024 | return MBTK_INFO_ERR_MEMORY; |
| 1025 | } |
| 1026 | |
| 1027 | uint8 buff[SOCK_MSG_LEN_MAX] = {0}; |
| 1028 | int buff_len; |
| 1029 | if((buff_len = info_item_process(handle, MBTK_INFO_ID_NET_CELL_REQ, NULL, 0, buff)) > 0) { |
| 1030 | int i = 0; |
| 1031 | *type = buff[0]; // Set network type. |
| 1032 | while (i < (buff_len - sizeof(uint8)) / sizeof(mbtk_cell_info_t)) |
| 1033 | { |
| 1034 | mbtk_cell_info_t* cell = (mbtk_cell_info_t*)malloc(sizeof(mbtk_cell_info_t)); |
| 1035 | if(cell == NULL) |
| 1036 | { |
| 1037 | LOG("malloc() fail."); |
| 1038 | list_free(*cell_list); |
| 1039 | return MBTK_INFO_ERR_MEMORY; |
| 1040 | } |
| 1041 | memcpy(cell, buff + sizeof(uint8) + i * sizeof(mbtk_cell_info_t), sizeof(mbtk_cell_info_t)); |
| 1042 | list_add(*cell_list, cell); |
| 1043 | |
| 1044 | // LOG("Cell-%d: %d, %d, %d, %d, %d", i + 1, cell->value1, cell->value2, cell->value3, cell->value4, cell->value5); |
| 1045 | i++; |
| 1046 | } |
| 1047 | |
| 1048 | return 0; |
| 1049 | } else { |
| 1050 | list_free(*cell_list); |
| 1051 | return handle->info_err; |
| 1052 | } |
| 1053 | } |
| 1054 | /* |
| 1055 | * Set cell info. |
| 1056 | * |
| 1057 | * at*CELL=<mode>,<act>,< band>,<freq>,<cellId> |
| 1058 | * at*cell=2,3,,40936,429 // |
| 1059 | * at*cell=0 // |
| 1060 | * |
| 1061 | * Restarting takes effect after execution. |
| 1062 | */ |
| 1063 | int mbtk_cell_set(mbtk_info_handle_t* handle, char * info, char* response) |
| 1064 | { |
| 1065 | printf("mbtk_cell_set() info:%s, len:%d",info, strlen(info)); |
| 1066 | char req[128] = {0}; |
| 1067 | if( info_item_process(handle, MBTK_INFO_ID_NET_CELL_REQ, info, strlen(info), req) > 0){ |
| 1068 | memcpy(response, req, strlen(req)); |
| 1069 | return 0; |
| 1070 | } |
| 1071 | else{ |
| 1072 | return 0; |
| 1073 | // return handle->info_err; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | * Get all APN informations. |
| 1079 | */ |
| 1080 | int mbtk_apn_get(mbtk_info_handle_t* handle, int *apn_num, mbtk_apn_info_t apns[]) |
| 1081 | { |
| 1082 | int len; |
| 1083 | if(handle == NULL || apn_num == NULL || apns == NULL) |
| 1084 | { |
| 1085 | LOGE("ARG error."); |
| 1086 | return -1; |
| 1087 | } |
| 1088 | uint8 data[SOCK_MSG_LEN_MAX]; |
| 1089 | if((len = info_item_process(handle, MBTK_INFO_ID_NET_APN_REQ, NULL, 0, data)) > 0) { |
| 1090 | /* |
| 1091 | <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>... |
| 1092 | <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth> |
| 1093 | */ |
| 1094 | uint8* ptr = data; |
| 1095 | if(apn_num == NULL || apns == NULL || *apn_num < *ptr) { |
| 1096 | *apn_num = 0; |
| 1097 | LOGE("APN array size to not enough."); |
| 1098 | return -1; |
| 1099 | } |
| 1100 | *apn_num = *ptr++; |
| 1101 | LOG("APN Number : %d", *apn_num); |
| 1102 | int i = 0; |
| 1103 | while(i < *apn_num) { |
| 1104 | memset(&(apns[i]), 0 ,sizeof(mbtk_apn_info_t)); |
| 1105 | apns[i].cid = *ptr++; |
| 1106 | apns[i].ip_type = (mbtk_ip_type_enum)(*ptr++); |
| 1107 | |
| 1108 | // apn |
| 1109 | len = byte_2_uint16(ptr, false); |
| 1110 | ptr += sizeof(uint16); |
| 1111 | if(len > 0) { // Has APN |
| 1112 | memcpy(apns[i].apn, ptr, len); |
| 1113 | ptr += len; |
| 1114 | } |
| 1115 | // user |
| 1116 | len = byte_2_uint16(ptr, false); |
| 1117 | ptr += sizeof(uint16); |
| 1118 | if(len > 0) { // Has APN |
| 1119 | memcpy(apns[i].user, ptr, len); |
| 1120 | ptr += len; |
| 1121 | } |
| 1122 | |
| 1123 | // pass |
| 1124 | len = byte_2_uint16(ptr, false); |
| 1125 | ptr += sizeof(uint16); |
| 1126 | if(len > 0) { // Has APN |
| 1127 | memcpy(apns[i].pass, ptr, len); |
| 1128 | ptr += len; |
| 1129 | } |
| 1130 | // auth |
| 1131 | len = byte_2_uint16(ptr, false); |
| 1132 | ptr += sizeof(uint16); |
| 1133 | if(len > 0) { // Has APN |
| 1134 | memcpy(apns[i].auth, ptr, len); |
| 1135 | ptr += len; |
| 1136 | } |
| 1137 | |
| 1138 | i++; |
| 1139 | } |
| 1140 | return 0; |
| 1141 | } else { |
| 1142 | return handle->info_err; |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | /* |
| 1147 | * Set current APN informations. |
| 1148 | */ |
| 1149 | int mbtk_apn_set(mbtk_info_handle_t* handle, int cid, mbtk_ip_type_enum ip_type, const void* apn_name, |
| 1150 | const void *user_name, const void *user_pass, const void *auth) |
| 1151 | { |
| 1152 | if(handle == NULL) |
| 1153 | { |
| 1154 | LOGE("ARG error."); |
| 1155 | return -1; |
| 1156 | } |
| 1157 | uint8 data[SOCK_MSG_LEN_MAX]; |
| 1158 | memset(data, 0, SOCK_MSG_LEN_MAX); |
| 1159 | // cid : 2 - 7 |
| 1160 | if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) { |
| 1161 | LOGE("CID error."); |
| 1162 | return -1; |
| 1163 | } |
| 1164 | uint8* ptr = data; |
| 1165 | // <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth> |
| 1166 | *ptr++ = (uint8)cid; |
| 1167 | *ptr++ = (uint8)ip_type; |
| 1168 | if(str_empty(apn_name)) { |
| 1169 | uint16_2_byte((uint16)0, ptr, false); |
| 1170 | ptr += sizeof(uint16); |
| 1171 | } else { |
| 1172 | uint16_2_byte((uint16)strlen(apn_name), ptr, false); |
| 1173 | ptr += sizeof(uint16); |
| 1174 | memcpy(ptr, apn_name, strlen(apn_name)); |
| 1175 | ptr += strlen(apn_name); |
| 1176 | } |
| 1177 | if(str_empty(user_name)) { |
| 1178 | uint16_2_byte((uint16)0, ptr, false); |
| 1179 | ptr += sizeof(uint16); |
| 1180 | } else { |
| 1181 | uint16_2_byte((uint16)strlen(user_name), ptr, false); |
| 1182 | ptr += sizeof(uint16); |
| 1183 | memcpy(ptr, user_name, strlen(user_name)); |
| 1184 | ptr += strlen(user_name); |
| 1185 | } |
| 1186 | |
| 1187 | if(str_empty(user_pass)) { |
| 1188 | uint16_2_byte((uint16)0, ptr, false); |
| 1189 | ptr += sizeof(uint16); |
| 1190 | } else { |
| 1191 | uint16_2_byte((uint16)strlen(user_pass), ptr, false); |
| 1192 | ptr += sizeof(uint16); |
| 1193 | memcpy(ptr, user_pass, strlen(user_pass)); |
| 1194 | ptr += strlen(user_pass); |
| 1195 | } |
| 1196 | |
| 1197 | if(str_empty(auth)) { |
| 1198 | uint16_2_byte((uint16)0, ptr, false); |
| 1199 | ptr += sizeof(uint16); |
| 1200 | } else { |
| 1201 | uint16_2_byte((uint16)strlen(auth), ptr, false); |
| 1202 | ptr += sizeof(uint16); |
| 1203 | memcpy(ptr, auth, strlen(auth)); |
| 1204 | ptr += strlen(auth); |
| 1205 | } |
| 1206 | |
| 1207 | return info_item_process(handle, MBTK_INFO_ID_NET_APN_REQ, data, ptr - data, NULL) ? handle->info_err : 0; |
| 1208 | } |
| 1209 | |
| 1210 | /* |
| 1211 | * Start data call. |
| 1212 | */ |
| 1213 | int mbtk_data_call_start(mbtk_info_handle_t* handle, int cid, int auto_conn_interval, bool boot_conn, int timeout) |
| 1214 | { |
| 1215 | uint8 data[10]; |
| 1216 | if(handle == NULL) |
| 1217 | { |
| 1218 | LOGE("ARG error."); |
| 1219 | return -1; |
| 1220 | } |
| 1221 | memset(data, 0, 10); |
| 1222 | if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) { |
| 1223 | LOGE("CID error."); |
| 1224 | return -1; |
| 1225 | } |
| 1226 | uint8* ptr = data; |
| 1227 | /* <call_type[1]><cid[1]><auto_conn_interval[1]><boot_conn[1]><timeout[1]> |
| 1228 | call_type : mbtk_data_call_type_enum |
| 1229 | cid : 2 - 7 |
| 1230 | timeout : second |
| 1231 | */ |
| 1232 | *ptr++ = (uint8)MBTK_DATA_CALL_START; |
| 1233 | *ptr++ = (uint8)cid; |
| 1234 | *ptr++ = (uint8)(auto_conn_interval > 0 ? auto_conn_interval : 0); // 拨号失败后重拨间隔(s) |
| 1235 | *ptr++ = (uint8)(boot_conn ? 1 : 0); // 开机自动拨号 |
| 1236 | if(timeout <= 0) { |
| 1237 | *ptr++ = (uint8)MBTK_DATA_CALL_TIMEOUT_DEFAULT; |
| 1238 | } else { |
| 1239 | *ptr++ = (uint8)timeout; |
| 1240 | } |
| 1241 | |
| 1242 | return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 5, NULL) ? handle->info_err : 0; |
| 1243 | } |
| 1244 | |
| 1245 | /* |
| 1246 | * Stop data call. |
| 1247 | */ |
| 1248 | int mbtk_data_call_stop(mbtk_info_handle_t* handle, int cid, int timeout) |
| 1249 | { |
| 1250 | uint8 data[10]; |
| 1251 | if(handle == NULL) |
| 1252 | { |
| 1253 | LOGE("ARG error."); |
| 1254 | return -1; |
| 1255 | } |
| 1256 | memset(data, 0, 10); |
| 1257 | if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) { |
| 1258 | LOGE("CID error."); |
| 1259 | return -1; |
| 1260 | } |
| 1261 | uint8* ptr = data; |
| 1262 | /* <call_type[1]><cid[1]><timeout[1]> |
| 1263 | call_type : mbtk_data_call_type_enum |
| 1264 | cid : 2 - 7 |
| 1265 | timeout : second |
| 1266 | */ |
| 1267 | *ptr++ = (uint8)MBTK_DATA_CALL_STOP; |
| 1268 | *ptr++ = (uint8)cid; |
| 1269 | *ptr++ = (uint8)timeout; |
| 1270 | |
| 1271 | return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, NULL) ? handle->info_err : 0; |
| 1272 | } |
| 1273 | |
| 1274 | /* |
| 1275 | * Get data call state. |
| 1276 | */ |
| 1277 | int mbtk_data_call_state_get(mbtk_info_handle_t* handle, int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6) |
| 1278 | { |
| 1279 | uint8 data[10]; |
| 1280 | if(handle == NULL) |
| 1281 | { |
| 1282 | LOGE("ARG error."); |
| 1283 | return -1; |
| 1284 | } |
| 1285 | uint8 recv_buff[SOCK_MSG_LEN_MAX]={0}; |
| 1286 | memset(data, 0, 10); |
| 1287 | if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) { |
| 1288 | LOGE("CID error."); |
| 1289 | return -1; |
| 1290 | } |
| 1291 | uint8* ptr = data; |
| 1292 | /* <call_type[1]><cid[1]><timeout[1]> |
| 1293 | call_type : mbtk_data_call_type_enum |
| 1294 | cid : 2 - 7 |
| 1295 | timeout : second |
| 1296 | */ |
| 1297 | *ptr++ = (uint8)MBTK_DATA_CALL_STATE; |
| 1298 | *ptr++ = (uint8)cid; |
| 1299 | *ptr++ = (uint8)0; |
| 1300 | |
| 1301 | if(ipv4) { |
| 1302 | memset(ipv4, 0, sizeof(mbtk_ipv4_info_t)); |
| 1303 | } |
| 1304 | |
| 1305 | if(ipv6) { |
| 1306 | memset(ipv6, 0, sizeof(mbtk_ipv6_info_t)); |
| 1307 | } |
| 1308 | |
| 1309 | if(info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, recv_buff) > 0) { |
| 1310 | if(recv_buff[0] == 0) { // IPv4 Only. |
| 1311 | if(ipv4) { |
| 1312 | memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t)); |
| 1313 | } |
| 1314 | } else if(recv_buff[0] == 1) { // IPv6 Only. |
| 1315 | if(ipv6) { |
| 1316 | memcpy(ipv6, recv_buff + sizeof(uint8), sizeof(mbtk_ipv6_info_t)); |
| 1317 | } |
| 1318 | } else if(recv_buff[0] == 2) { // IPv4 and IPv6. |
| 1319 | if(ipv4) { |
| 1320 | memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t)); |
| 1321 | } |
| 1322 | |
| 1323 | if(ipv6) { |
| 1324 | memcpy(ipv6, recv_buff + sizeof(uint8) + sizeof(mbtk_ipv4_info_t), sizeof(mbtk_ipv6_info_t)); |
| 1325 | } |
| 1326 | } else { |
| 1327 | LOGE("Unknown IP type : %d", recv_buff[0]); |
| 1328 | return -1; |
| 1329 | } |
| 1330 | return 0; |
| 1331 | } else { |
| 1332 | return handle->info_err; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | /* |
| 1339 | * Get current network signal. |
| 1340 | */ |
| 1341 | int mbtk_net_signal_get(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal) |
| 1342 | { |
| 1343 | if(handle == NULL || signal == NULL) |
| 1344 | { |
| 1345 | LOGE("ARG error."); |
| 1346 | return -1; |
| 1347 | } |
| 1348 | if(info_item_process(handle, MBTK_INFO_ID_NET_SIGNAL_REQ, NULL, 0, signal) > 0) { |
| 1349 | LOG("Signal : %d, %d, %d, %d, %d, %d, %d", signal->rssi, signal->rxlev, signal->ber, signal->rscp, signal->ecno, |
| 1350 | signal->rsrq, signal->rsrp); |
| 1351 | return 0; |
| 1352 | } else { |
| 1353 | return handle->info_err; |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | /* |
| 1358 | * Get current network register information. |
| 1359 | */ |
| 1360 | int mbtk_net_reg_get(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg) |
| 1361 | { |
| 1362 | if(handle == NULL || reg == NULL) |
| 1363 | { |
| 1364 | LOGE("ARG error."); |
| 1365 | return -1; |
| 1366 | } |
| 1367 | if(info_item_process(handle, MBTK_INFO_ID_NET_REG_REQ, NULL, 0, reg) > 0) { |
| 1368 | if(reg->call_state || reg->data_state || reg->ims_state) { |
| 1369 | LOGD("REG : call_state=%d, data_state=%d, ims_state=%d, net_type=%d, %04x, %08x", reg->call_state, reg->data_state, reg->ims_state, reg->type, reg->lac, reg->ci); |
| 1370 | } else { |
| 1371 | LOGE("Net not reg."); |
| 1372 | } |
| 1373 | return 0; |
| 1374 | } else { |
| 1375 | return handle->info_err; |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | |
| 1380 | /* |
| 1381 | * Get radio state. |
| 1382 | */ |
| 1383 | int mbtk_radio_state_get(mbtk_info_handle_t* handle, int *radio_state) |
| 1384 | { |
| 1385 | uint8 state; |
| 1386 | if(handle == NULL || radio_state == NULL) |
| 1387 | { |
| 1388 | LOGE("ARG error."); |
| 1389 | return -1; |
| 1390 | } |
| 1391 | if(info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, NULL, 0, &state) > 0) { |
| 1392 | LOG("Radio state : %d", state); |
| 1393 | *radio_state = state; |
| 1394 | return 0; |
| 1395 | } else { |
| 1396 | return handle->info_err; |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | /* |
| 1401 | * Set radio state. |
| 1402 | */ |
| 1403 | int mbtk_radio_state_set(mbtk_info_handle_t* handle, int radio_state) |
| 1404 | { |
| 1405 | if(handle == NULL) |
| 1406 | { |
| 1407 | LOGE("ARG error."); |
| 1408 | return -1; |
| 1409 | } |
| 1410 | return info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, (uint8*)&radio_state, sizeof(uint8), NULL) ? handle->info_err : 0; |
| 1411 | } |
| 1412 | |
| 1413 | /* |
| 1414 | * Get time type. |
| 1415 | */ |
| 1416 | int mbtk_time_get(mbtk_info_handle_t* handle, int *time_type) |
| 1417 | { |
| 1418 | uint8 state; |
| 1419 | if(handle == NULL || time_type == NULL) |
| 1420 | { |
| 1421 | LOGE("ARG error."); |
| 1422 | return -1; |
| 1423 | } |
| 1424 | if(info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ, NULL, 0, &state) > 0) { |
| 1425 | LOG("Time type : %d", state); |
| 1426 | *time_type = state; |
| 1427 | return 0; |
| 1428 | } else { |
| 1429 | return handle->info_err; |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | /* |
| 1434 | *Get Absolute time |
| 1435 | *"23/05/24 06:09:32 +32 00" |
| 1436 | */ |
| 1437 | int mbtk_get_abs_time(char *time_str, time_t *time_out) |
| 1438 | { |
| 1439 | struct tm tm_; |
| 1440 | |
| 1441 | char *ptr = strstr(time_str + 10, " "); |
| 1442 | *ptr = '\0'; |
| 1443 | |
| 1444 | LOGD("time : \"%s\"", time_str); |
| 1445 | #if 1 |
| 1446 | if(strptime(time_str, "%y/%m/%d %T", &tm_) == NULL) { |
| 1447 | LOGE("strptime() fail."); |
| 1448 | return -1; |
| 1449 | } |
| 1450 | #else |
| 1451 | int year, month, day, hour, minute,second,time_zone; |
| 1452 | if(strstr(time_str, "+")) { |
| 1453 | sscanf(time_str, "%d/%d/%d %d:%d:%d +%d",&year,&month,&day,&hour,&minute,&second,&time_zone); |
| 1454 | } else if(strstr(time_str, "-")) { |
| 1455 | sscanf(time_str, "%d/%d/%d %d:%d:%d -%d",&year,&month,&day,&hour,&minute,&second,&time_zone); |
| 1456 | } else { |
| 1457 | LOGE("Time format error:%s", time_str); |
| 1458 | return -1; |
| 1459 | } |
| 1460 | |
| 1461 | // 1970+ |
| 1462 | if(year < 70) { // 20xx |
| 1463 | tm_.tm_year = 2000 + year; |
| 1464 | } else { // 19xx |
| 1465 | tm_.tm_year = 1900 + year; |
| 1466 | } |
| 1467 | tm_.tm_mon = month - 1; |
| 1468 | tm_.tm_mday = day; |
| 1469 | tm_.tm_hour = hour; |
| 1470 | tm_.tm_min = minute; |
| 1471 | tm_.tm_sec = second; |
| 1472 | tm_.tm_isdst = 0; |
| 1473 | #endif |
| 1474 | |
| 1475 | time_t timeStamp = mktime(&tm_); |
| 1476 | LOGD("tm_.tm_year = %d,tm_.tm_mon = %d,tm_.tm_mday = %d,tm_.tm_hour = %d,tm_.tm_min = %d,tm_.tm_sec = %d,tm_.tm_isdst = %d",tm_.tm_year,tm_.tm_mon,tm_.tm_mday,tm_.tm_hour,tm_.tm_min,tm_.tm_sec,tm_.tm_isdst); |
| 1477 | LOGD("time = %ld,%x", timeStamp,timeStamp); |
| 1478 | *time_out = timeStamp; |
| 1479 | |
| 1480 | return 0; |
| 1481 | } |
| 1482 | |
| 1483 | /* |
| 1484 | * Get time type. |
| 1485 | * "23/05/24,06:09:32+32" -> "23/05/24 06:09:32 +32 00" |
| 1486 | */ |
| 1487 | int mbtk_net_time_get(mbtk_info_handle_t* handle, char* time_str) |
| 1488 | { |
| 1489 | uint8 buff[SOCK_MSG_LEN_MAX] = {0}; |
| 1490 | if(handle == NULL || time_str == NULL) |
| 1491 | { |
| 1492 | LOGE("ARG error."); |
| 1493 | return -1; |
| 1494 | } |
| 1495 | //printf("mbtk_net_time_get begin info_item_process\n"); |
| 1496 | if(info_item_process(handle, MBTK_INFO_ID_NET_TIME_REQ, NULL, 0, buff) > 0) { |
| 1497 | memcpy(time_str,buff,strlen(buff)); |
| 1498 | |
| 1499 | uint8 *temp = strstr(time_str, ","); |
| 1500 | if(temp) { |
| 1501 | *temp = ' '; // ',' -> ' ' |
| 1502 | |
| 1503 | temp = strstr(time_str, "+"); |
| 1504 | if(temp == NULL) { |
| 1505 | temp = strstr(time_str, "-"); |
| 1506 | } |
| 1507 | |
| 1508 | if(temp) { |
| 1509 | // Copy +XX or -XX |
| 1510 | uint8 *last_ptr = temp + strlen(temp) + 1; |
| 1511 | while(last_ptr > temp) { |
| 1512 | *last_ptr = *(last_ptr - 1); |
| 1513 | last_ptr--; |
| 1514 | } |
| 1515 | |
| 1516 | *last_ptr = ' '; |
| 1517 | |
| 1518 | memcpy(temp + strlen(temp), "00", 2); |
| 1519 | |
| 1520 | LOGD("%s -> %s", buff, time_str); |
| 1521 | return 0; |
| 1522 | } else { |
| 1523 | LOGE("Time error:%s",buff); |
| 1524 | return MBTK_INFO_ERR_TIME_FORMAT; |
| 1525 | } |
| 1526 | } else { |
| 1527 | LOGE("Time error:%s",buff); |
| 1528 | return MBTK_INFO_ERR_TIME_FORMAT; |
| 1529 | } |
| 1530 | } else { |
| 1531 | return handle->info_err; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | /* |
| 1536 | * Set time. |
| 1537 | * |
| 1538 | * time_type: |
| 1539 | * 0: Cell time |
| 1540 | * 1: NTP time |
| 1541 | * 2: User time |
| 1542 | * time_str: "YYYY-MM-DD HH:MM:SS" |
| 1543 | */ |
| 1544 | int mbtk_time_set(mbtk_info_handle_t* handle, mbtk_time_type_enum time_type, char* time_str) |
| 1545 | { |
| 1546 | if(handle == NULL) |
| 1547 | { |
| 1548 | LOGE("ARG error."); |
| 1549 | return -1; |
| 1550 | } |
| 1551 | uint8 buffer[100] = {0}; |
| 1552 | buffer[0] = (uint8)time_type; |
| 1553 | if(time_type == MBTK_TIME_TYPE_USER) { |
| 1554 | if(!str_empty(time_str)) { |
| 1555 | memcpy(buffer + sizeof(uint8), time_str, strlen(time_str)); |
| 1556 | return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ, |
| 1557 | buffer, sizeof(uint8) + strlen(time_str), NULL) ? handle->info_err : 0; |
| 1558 | } else { |
| 1559 | return -1; |
| 1560 | } |
| 1561 | } else { |
| 1562 | return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ, |
| 1563 | buffer, sizeof(uint8), NULL) ? handle->info_err : 0; |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | /* |
| 1568 | * Return sms cmgf. |
| 1569 | */ |
| 1570 | int mbtk_sms_cmgf_get(mbtk_info_handle_t* handle, int *volte_state) |
| 1571 | { |
| 1572 | uint8 state; |
| 1573 | if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, NULL, 0, &state) > 0) { |
| 1574 | LOG("mbtk_sms_cmgf_get()-----------sms cmgf : %d", state); |
| 1575 | *volte_state = state; |
| 1576 | return 0; |
| 1577 | } else { |
| 1578 | return handle->info_err; |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | /* |
| 1583 | * Set sms cmgf. |
| 1584 | * |
| 1585 | * volte_state: |
| 1586 | * 0 : PDU mode. |
| 1587 | * 1 : text mode. |
| 1588 | * |
| 1589 | * Restarting takes effect after execution. |
| 1590 | */ |
| 1591 | int mbtk_sms_cmgf_set(mbtk_info_handle_t* handle, int mode) |
| 1592 | { |
| 1593 | printf("mbtk_sms_cmgf_set()--------mode=:%d, len:%d", mode, sizeof(uint8)); |
| 1594 | return info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, (uint8*)&mode, sizeof(uint8), NULL) ? handle->info_err : 0; |
| 1595 | } |
| 1596 | |
| 1597 | /* |
| 1598 | * Set sms cmgs. |
| 1599 | * |
| 1600 | if PDU mode (+CMGF=0): |
| 1601 | +CMGS=<length><CR> |
| 1602 | PDU is given<ctrl-Z/ESC> |
| 1603 | |
| 1604 | if text mode (+CMGF=1): |
| 1605 | +CMGS=<da>[,<toda>]<CR> |
| 1606 | text is entered<ctrl-Z/ESC> |
| 1607 | |
| 1608 | * Restarting takes effect after execution. |
| 1609 | */ |
| 1610 | int mbtk_sms_cmgs_set(mbtk_info_handle_t* handle, char * cmgs, char *resp) |
| 1611 | { |
| 1612 | printf("mbtk_sms_cmgs_set(1)--------cmgs=:%s, len:%d", cmgs, strlen(cmgs)); |
| 1613 | // char req[20] = {0} |
| 1614 | if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGS_REQ, cmgs, strlen(cmgs), resp) > 0){ |
| 1615 | printf("resp:%s\n", resp); |
| 1616 | return 0; |
| 1617 | }else{ |
| 1618 | return handle->info_err; |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | /* |
| 1623 | * Set sms cmgw. |
| 1624 | * |
| 1625 | if text mode (+CMGF=1): |
| 1626 | +CMGW=<oa/da>[,<tooa/toda>[,<stat>]] |
| 1627 | <CR> |
| 1628 | text is entered<ctrl-Z/ESC> |
| 1629 | if PDU mode (+CMGF=0): |
| 1630 | +CMGW=<length>[,<stat>]<CR>PDU is |
| 1631 | given<ctrl-Z/ESC> |
| 1632 | |
| 1633 | */ |
| 1634 | |
| 1635 | int mbtk_sms_cmgw_set(mbtk_info_handle_t* handle, char * cmgw, char *resp) |
| 1636 | { |
| 1637 | printf("mbtk_sms_cmgw_set() ----------cmgw:%s, len:%d", cmgw, strlen(cmgw)); |
| 1638 | if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGW_REQ, cmgw, strlen(cmgw), resp) > 0){ |
| 1639 | printf("resp:%s\n", resp); |
| 1640 | return 0; |
| 1641 | }else{ |
| 1642 | return handle->info_err; |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | /* |
| 1647 | * Set sms cmgd. |
| 1648 | * |
| 1649 | * +CMGD=<index>[,<delflag>] |
| 1650 | * |
| 1651 | * Restarting takes effect after execution. |
| 1652 | */ |
| 1653 | int mbtk_sms_cmgd_set(mbtk_info_handle_t* handle, char * cmdg) |
| 1654 | { |
| 1655 | printf("mbtk_sms_cmgd_set() cmdg:%s, len:%d",cmdg, strlen(cmdg)); |
| 1656 | return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, cmdg, strlen(cmdg), NULL) ? handle->info_err : 0; |
| 1657 | } |
| 1658 | |
| 1659 | /* |
| 1660 | * Set sms cmgl. |
| 1661 | * |
| 1662 | * AT+CMGL[=<stat>] |
| 1663 | * |
| 1664 | * Restarting takes effect after execution. |
| 1665 | */ |
| 1666 | int mbtk_sms_cmgl_set(mbtk_info_handle_t* handle, char * cmgl, char *resp) |
| 1667 | { |
| 1668 | printf("0mbtk_sms_cmgl_set() cmgl:%s, len:%d\n",cmgl, strlen(cmgl)); |
| 1669 | char reg[5*1024] ={0}; |
| 1670 | if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGL_REQ, cmgl, strlen(cmgl), reg) > 0){ |
| 1671 | printf("len:%d , reg:%s\n", strlen(reg), reg); |
| 1672 | // memcpy(resp, reg, strlen(reg)); |
| 1673 | return 0; |
| 1674 | }else { |
| 1675 | return handle->info_err; |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | /* |
| 1680 | * Return sms csca. |
| 1681 | */ |
| 1682 | int mbtk_sms_csca_get(mbtk_info_handle_t* handle, char *buf) |
| 1683 | { |
| 1684 | // char state; |
| 1685 | if(info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, NULL, 0, buf) > 0) { |
| 1686 | LOG("mbtk_sms_csca_get()-----------sms csca : %s", buf); |
| 1687 | // *volte_state = state; |
| 1688 | return 0; |
| 1689 | } else { |
| 1690 | return handle->info_err; |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | /* |
| 1695 | * Set sms csca. |
| 1696 | * |
| 1697 | * AT+CSCA=<number> [,<type>] |
| 1698 | * |
| 1699 | * Restarting takes effect after execution. |
| 1700 | */ |
| 1701 | int mbtk_sms_csca_set(mbtk_info_handle_t* handle, char * csca) |
| 1702 | { |
| 1703 | printf("mbtk_sms_csca_set() csca:%s, len:%d",csca, strlen(csca)); |
| 1704 | return info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, csca, strlen(csca), NULL) ? handle->info_err : 0; |
| 1705 | } |
| 1706 | |
| 1707 | /* |
| 1708 | * Set sms csmp. |
| 1709 | * |
| 1710 | * AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]] |
| 1711 | * |
| 1712 | * Restarting takes effect after execution. |
| 1713 | */ |
| 1714 | int mbtk_sms_csmp_set(mbtk_info_handle_t* handle, char * csmp) |
| 1715 | { |
| 1716 | printf("mbtk_sms_csmp_set() csmp:%s, len:%d",csmp, strlen(csmp)); |
| 1717 | return info_item_process(handle, MBTK_INFO_ID_SMS_CSMP_REQ, csmp, strlen(csmp), NULL) ? handle->info_err : 0; |
| 1718 | } |
| 1719 | |
| 1720 | /* |
| 1721 | * Set sms cscb. |
| 1722 | * |
| 1723 | * AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]> |
| 1724 | * |
| 1725 | * Restarting takes effect after execution. |
| 1726 | */ |
| 1727 | int mbtk_sms_cscb_set(mbtk_info_handle_t* handle, char * cscb) |
| 1728 | { |
| 1729 | printf("mbtk_sms_cscb_set() cscb:%s, len:%d",cscb, strlen(cscb)); |
| 1730 | return info_item_process(handle, MBTK_INFO_ID_SMS_CSCB_REQ, cscb, strlen(cscb), NULL) ? handle->info_err : 0; |
| 1731 | } |
| 1732 | |
| 1733 | /* |
| 1734 | * Set sms cnmi. |
| 1735 | * |
| 1736 | at+cnmi=1,2 |
| 1737 | |
| 1738 | OK |
| 1739 | if sending fails: |
| 1740 | +CMS ERROR: <err> |
| 1741 | */ |
| 1742 | int mbtk_sms_cnmi_set(mbtk_info_handle_t* handle) |
| 1743 | { |
| 1744 | printf("mbtk_sms_cnmi_set()------------start\n"); |
| 1745 | |
| 1746 | return info_item_process(handle, MBTK_INFO_ID_SMS_CNMI_REQ, NULL, 0, NULL)? handle->info_err : 0; |
| 1747 | } |
| 1748 | |
| 1749 | /* |
| 1750 | * Set sms cmss. |
| 1751 | * |
| 1752 | +CMSS=<index>[,<da>[,<toda>]] |
| 1753 | |
| 1754 | if sending successful: |
| 1755 | +CMSS: <mr> |
| 1756 | OK |
| 1757 | if sending fails: |
| 1758 | +CMS ERROR: <err> |
| 1759 | */ |
| 1760 | int mbtk_sms_cmss_set(mbtk_info_handle_t* handle, char * cmss, char *resp) |
| 1761 | { |
| 1762 | printf("mbtk_sms_cmss_set()------------cmss:%s, len:%d", cmss, strlen(cmss)); |
| 1763 | if( info_item_process(handle, MBTK_INFO_ID_SMS_CMSS_REQ, cmss, strlen(cmss), resp) > 0){ |
| 1764 | printf("resp:%s\n", resp); |
| 1765 | return 0; |
| 1766 | }else{ |
| 1767 | return handle->info_err; |
| 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | /* |
| 1772 | * Return sms cmgf. |
| 1773 | */ |
| 1774 | int mbtk_sms_cpms_get(mbtk_info_handle_t* handle, char * mem) |
| 1775 | { |
| 1776 | char req[128] = {0}; |
| 1777 | if(info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, NULL, 0, &req) > 0) { |
| 1778 | LOG("mbtk_sms_cpms_get() req : %s, strlen(mem_ptr):%d\n", req, strlen(req)); |
| 1779 | memcpy(mem, req, strlen(req)); |
| 1780 | return 0; |
| 1781 | } else { |
| 1782 | return handle->info_err; |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | |
| 1787 | /* |
| 1788 | * Set sms cpms. |
| 1789 | * |
| 1790 | * AT+CPMS=<mem1>[,<mem2>[,<mem3>]] |
| 1791 | * |
| 1792 | * Restarting takes effect after execution. |
| 1793 | */ |
| 1794 | int mbtk_sms_cpms_set(mbtk_info_handle_t* handle, char * mem, char* response) |
| 1795 | { |
| 1796 | printf("mbtk_sms_cpms_set() mem:%s, len:%d",mem, strlen(mem)); |
| 1797 | char req[128] = {0}; |
| 1798 | if( info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, mem, strlen(mem), req) > 0){ |
| 1799 | memcpy(response, req, strlen(req)); |
| 1800 | return 0; |
| 1801 | } |
| 1802 | else{ |
| 1803 | return handle->info_err; |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | /* |
| 1808 | * Set sms cm. |
| 1809 | * |
| 1810 | * +CMGR=<index> |
| 1811 | |
| 1812 | if PDU mode (+CMGF=0) ��command successful: |
| 1813 | +CMGR: <stat>,[<alpha>],<length><CR><LF><pdu> |
| 1814 | OK |
| 1815 | if text mode (+CMGF=1), command successful and SMS-DELIVER: |
| 1816 | +CMGR:<stat>,<oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs |
| 1817 | >, <sca>,<tosca>,<length>]<CR><LF><data> |
| 1818 | OK |
| 1819 | if text mode (+CMGF=1), command successful and SMS-SUBMIT: |
| 1820 | +CMGR: |
| 1821 | <stat>,<da>,[<alpha>][,<toda>,<fo>,<pid>,<dcs>,[<vp>], |
| 1822 | <sca>,<tosca>,<length>]<CR><LF><data> |
| 1823 | OK |
| 1824 | otherwise: |
| 1825 | +CMS ERROR: <err> |
| 1826 | * |
| 1827 | * Restarting takes effect after execution. |
| 1828 | */ |
| 1829 | int mbtk_sms_cmgr_set(mbtk_info_handle_t* handle, int index, char *resp) |
| 1830 | { |
| 1831 | printf("mbtk_sms_cmgr_set() --------------index:%d",index); |
| 1832 | if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGR_REQ, (uint8*)&index, sizeof(uint8), resp) > 0){ |
| 1833 | printf("resp:%s\n", resp); |
| 1834 | return 0; |
| 1835 | }else{ |
| 1836 | return handle->info_err; |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | |
| 1841 | /* |
| 1842 | * Get sim state. |
| 1843 | */ |
| 1844 | int mbtk_sim_state_get(mbtk_info_handle_t* handle, mbtk_sim_state_enum *sim_state) |
| 1845 | { |
| 1846 | uint8 state; |
| 1847 | if(handle == NULL || sim_state == NULL) |
| 1848 | { |
| 1849 | LOGE("ARG error."); |
| 1850 | return -1; |
| 1851 | } |
| 1852 | if(info_item_process(handle, MBTK_INFO_ID_SIM_STATE_REQ, NULL, 0, &state) > 0) { |
| 1853 | *sim_state = (mbtk_sim_state_enum)state; |
| 1854 | LOG("Sim state : %d", *sim_state); |
| 1855 | return 0; |
| 1856 | } else { |
| 1857 | return handle->info_err; |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | /* |
| 1862 | * Get sim card type. |
| 1863 | */ |
| 1864 | int mbtk_sim_card_type_get(mbtk_info_handle_t* handle, mbtk_sim_card_type_enum *sim_card_type) |
| 1865 | { |
| 1866 | uint8 state; |
| 1867 | if(handle == NULL || sim_card_type == NULL) |
| 1868 | { |
| 1869 | LOGE("ARG error."); |
| 1870 | return -1; |
| 1871 | } |
| 1872 | if(info_item_process(handle, MBTK_INFO_ID_SIM_STYPE_REQ, NULL, 0, &state) > 0) { |
| 1873 | *sim_card_type = (mbtk_sim_card_type_enum)state; |
| 1874 | LOG("Sim sim_card_type : %d", *sim_card_type); |
| 1875 | return 0; |
| 1876 | } else { |
| 1877 | return handle->info_err; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | /* |
| 1882 | * Get system temperature. |
| 1883 | * |
| 1884 | * type[IN]: |
| 1885 | * 0: Soc temperature. |
| 1886 | * 1: RF temperature. |
| 1887 | * temp[OUT]: |
| 1888 | * temperature in celsius. |
| 1889 | */ |
| 1890 | int mbtk_temp_get(mbtk_info_handle_t* handle, int type, int* temp) |
| 1891 | { |
| 1892 | if(handle == NULL) |
| 1893 | { |
| 1894 | LOGE("ARG error."); |
| 1895 | return -1; |
| 1896 | } |
| 1897 | if(type != 0 && type != 1 || temp == NULL) |
| 1898 | { |
| 1899 | return -1; |
| 1900 | } |
| 1901 | |
| 1902 | uint8 temp_type = (uint8)type; |
| 1903 | uint8 temp_ptr; |
| 1904 | if(info_item_process(handle, MBTK_INFO_ID_DEV_TEMP_REQ, &temp_type, sizeof(uint8), &temp_ptr) > 0) { |
| 1905 | *temp = temp_ptr; |
| 1906 | LOG("Temperature : %d", *temp); |
| 1907 | return 0; |
| 1908 | } else { |
| 1909 | return handle->info_err; |
| 1910 | } |
| 1911 | |
| 1912 | return 0; |
| 1913 | } |
| 1914 | |
| 1915 | |
| 1916 | /* |
| 1917 | * Set sim power state. |
| 1918 | * power: |
| 1919 | * 0: Sim power off. |
| 1920 | * 1: Sim power on. |
| 1921 | */ |
| 1922 | int mbtk_sim_power_set(int power) |
| 1923 | { |
| 1924 | if(power != 0 && power != 1) |
| 1925 | { |
| 1926 | return -1; |
| 1927 | } |
| 1928 | |
| 1929 | // /sys/devices/virtual/usim_event/usim0/send_event |
| 1930 | char cmd[100] = {0}; |
| 1931 | sprintf(cmd, "echo %d > /sys/devices/virtual/usim_event/usim0/send_event", power ? 0 : 1); |
| 1932 | system(cmd); |
| 1933 | |
| 1934 | return 0; |
| 1935 | } |
| 1936 | |
| 1937 | /* |
| 1938 | * System power. |
| 1939 | * type: |
| 1940 | * 0: Reboot system. |
| 1941 | * 1: Poweroff system. |
| 1942 | * 2: Halt system. |
| 1943 | */ |
| 1944 | int mbtk_system_reboot(int type) |
| 1945 | { |
| 1946 | if(type != 0 && type != 1 && type != 2) |
| 1947 | { |
| 1948 | return -1; |
| 1949 | } |
| 1950 | |
| 1951 | switch(type) { |
| 1952 | case 0: { |
| 1953 | system("reboot"); |
| 1954 | break; |
| 1955 | } |
| 1956 | case 1: { |
| 1957 | system("poweroff"); |
| 1958 | break; |
| 1959 | } |
| 1960 | case 2: { |
| 1961 | system("halt"); |
| 1962 | break; |
| 1963 | } |
| 1964 | default: { |
| 1965 | break; |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | return 0; |
| 1970 | } |
| 1971 | |
| 1972 | /* |
| 1973 | * set modem fun |
| 1974 | * |
| 1975 | */ |
| 1976 | int mbtk_set_modem_fun(mbtk_info_handle_t* handle, mbtk_modem_info_t *info) |
| 1977 | { |
| 1978 | if(handle == NULL) |
| 1979 | { |
| 1980 | LOGE("ARG error."); |
| 1981 | return -1; |
| 1982 | } |
| 1983 | return info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, info, sizeof(mbtk_modem_info_t), NULL) ? handle->info_err : 0; |
| 1984 | } |
| 1985 | |
| 1986 | /* |
| 1987 | * get modem fun |
| 1988 | * |
| 1989 | */ |
| 1990 | int mbtk_get_modem_fun(mbtk_info_handle_t* handle, int* fun) |
| 1991 | { |
| 1992 | uint8 state; |
| 1993 | if(handle == NULL || fun == NULL) |
| 1994 | { |
| 1995 | LOGE("ARG error."); |
| 1996 | return -1; |
| 1997 | } |
| 1998 | if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, NULL, 0, &state) > 0) { |
| 1999 | LOG("modem type : %d", state); |
| 2000 | *fun = state; |
| 2001 | return 0; |
| 2002 | } else { |
| 2003 | return handle->info_err; |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | /* |
| 2008 | * call_start |
| 2009 | * |
| 2010 | */ |
| 2011 | int mbtk_call_start(mbtk_info_handle_t* handle, char* phone_number) |
| 2012 | { |
| 2013 | if(handle == NULL) |
| 2014 | { |
| 2015 | LOGE("ARG error."); |
| 2016 | return -1; |
| 2017 | } |
| 2018 | if(str_empty(phone_number)) |
| 2019 | return -1; |
| 2020 | |
| 2021 | return info_item_process(handle, MBTK_INFO_ID_CALL_START_REQ, |
| 2022 | phone_number, strlen(phone_number), NULL) ? handle->info_err : 0; |
| 2023 | } |
| 2024 | /* |
| 2025 | * Answer the phone call. |
| 2026 | * |
| 2027 | */ |
| 2028 | int mbtk_call_answer(mbtk_info_handle_t* handle) |
| 2029 | { |
| 2030 | return info_item_process(handle, MBTK_INFO_ID_CALL_ANSWER_REQ, NULL, 0, NULL) ? handle->info_err : 0; |
| 2031 | } |
| 2032 | |
| 2033 | /* |
| 2034 | * Hang up all call. |
| 2035 | * |
| 2036 | */ |
| 2037 | int mbtk_call_hang(mbtk_info_handle_t* handle) |
| 2038 | { |
| 2039 | return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_REQ, NULL, 0, NULL) ? handle->info_err : 0; |
| 2040 | } |
| 2041 | |
| 2042 | /* |
| 2043 | * Hang up a call. |
| 2044 | * |
| 2045 | */ |
| 2046 | int mbtk_a_call_hang(mbtk_info_handle_t* handle, int phone_id) |
| 2047 | { |
| 2048 | return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_A_REQ, (uint8*)&phone_id, sizeof(uint8), NULL) ? handle->info_err : 0; |
| 2049 | } |
| 2050 | |
| 2051 | /* |
| 2052 | * Hang up waiting or background call. |
| 2053 | * |
| 2054 | */ |
| 2055 | int mbtk_waiting_or_background_call_hang(mbtk_info_handle_t* handle) |
| 2056 | { |
| 2057 | return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_B_REQ, NULL, 0, NULL) ? handle->info_err : 0; |
| 2058 | } |
| 2059 | |
| 2060 | /* |
| 2061 | * Hang up foreground resume background call. |
| 2062 | * |
| 2063 | */ |
| 2064 | int mbtk_foreground_resume_background_call_hang(mbtk_info_handle_t* handle) |
| 2065 | { |
| 2066 | return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_C_REQ, NULL, 0, NULL) ? handle->info_err : 0; |
| 2067 | } |
| 2068 | |
| 2069 | /* |
| 2070 | * Get current call phone number. |
| 2071 | */ |
| 2072 | int mbtk_call_reg_get(mbtk_info_handle_t* handle, mbtk_call_info_t *reg) |
| 2073 | { |
| 2074 | if(info_item_process(handle, MBTK_INFO_ID_CALL_WAITIN_REQ, NULL, 0, reg) > 0) { |
| 2075 | LOG("CLCC : %d, %d, %d, %d, %d, %s, %d", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type); |
| 2076 | return 0; |
| 2077 | } else { |
| 2078 | return handle->info_err; |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | /* |
| 2083 | * Return mute state. |
| 2084 | */ |
| 2085 | int mbtk_mute_state_get(mbtk_info_handle_t* handle, int *mute_state) |
| 2086 | { |
| 2087 | uint8 state; |
| 2088 | if(info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, NULL, 0, &state) > 0) { |
| 2089 | LOG("Mute State : %d", state); |
| 2090 | *mute_state = state; |
| 2091 | return 0; |
| 2092 | } else { |
| 2093 | return handle->info_err; |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | /* |
| 2098 | * Set mute state. |
| 2099 | * |
| 2100 | * mute_state: |
| 2101 | * 0 : of mute. |
| 2102 | * 1 : on mute. |
| 2103 | * |
| 2104 | * Restarting takes effect after execution. |
| 2105 | */ |
| 2106 | int mbtk_mute_state_set(mbtk_info_handle_t* handle, int mute_state) |
| 2107 | { |
| 2108 | return info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, (uint8*)&mute_state, sizeof(uint8), NULL) ? handle->info_err : 0; |
| 2109 | } |
| 2110 | |
| 2111 | /* |
| 2112 | * Set DTMF character. |
| 2113 | * |
| 2114 | */ |
| 2115 | int mbtk_dtmf_send(mbtk_info_handle_t* handle, mbtk_call_dtmf_info_t *dtmf_character) |
| 2116 | { |
| 2117 | if(handle == NULL) |
| 2118 | { |
| 2119 | LOGE("ARG error."); |
| 2120 | return -1; |
| 2121 | } |
| 2122 | return info_item_process(handle, MBTK_INFO_ID_CALL_DTMF_REQ, |
| 2123 | dtmf_character, sizeof(mbtk_call_dtmf_info_t), NULL) ? handle->info_err : 0; |
| 2124 | } |
| 2125 | |
| 2126 | /* |
| 2127 | * Set pdp state change callback function. |
| 2128 | */ |
| 2129 | int mbtk_pdp_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb) |
| 2130 | { |
| 2131 | if(handle == NULL) |
| 2132 | { |
| 2133 | LOGE("ARG error."); |
| 2134 | return -1; |
| 2135 | } |
| 2136 | if(info_item_process(handle, MBTK_INFO_ID_IND_PDP_STATE_CHANGE, NULL, 0, NULL) < 0) { |
| 2137 | return handle->info_err; |
| 2138 | } else { |
| 2139 | handle->pdp_state_cb = cb; |
| 2140 | return 0; |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | /* |
| 2145 | * Set network state change callback function. |
| 2146 | */ |
| 2147 | int mbtk_net_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb) |
| 2148 | { |
| 2149 | if(handle == NULL) |
| 2150 | { |
| 2151 | LOGE("ARG error."); |
| 2152 | return -1; |
| 2153 | } |
| 2154 | if(info_item_process(handle, MBTK_INFO_ID_IND_NET_STATE_CHANGE, NULL, 0, NULL) > 0) { |
| 2155 | handle->net_state_cb = cb; |
| 2156 | return 0; |
| 2157 | } else { |
| 2158 | return handle->info_err; |
| 2159 | } |
| 2160 | } |
| 2161 | |
| 2162 | /* |
| 2163 | * Set call state change callback function. |
| 2164 | */ |
| 2165 | int mbtk_call_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb) |
| 2166 | { |
| 2167 | if(handle == NULL) |
| 2168 | { |
| 2169 | LOGE("ARG error."); |
| 2170 | return -1; |
| 2171 | } |
| 2172 | if(info_item_process(handle, MBTK_INFO_ID_IND_CALL_STATE_CHANGE, NULL, 0, NULL) < 0) { |
| 2173 | return handle->info_err; |
| 2174 | } else { |
| 2175 | handle->call_state_cb = cb; |
| 2176 | return 0; |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | /* |
| 2181 | * Set sms state change callback function. |
| 2182 | */ |
| 2183 | int mbtk_sms_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb) |
| 2184 | { |
| 2185 | if(handle == NULL) |
| 2186 | { |
| 2187 | LOGE("ARG error."); |
| 2188 | return -1; |
| 2189 | } |
| 2190 | if(info_item_process(handle, MBTK_INFO_ID_IND_SMS_STATE_CHANGE, NULL, 0, NULL) < 0) { |
| 2191 | return handle->info_err; |
| 2192 | } else { |
| 2193 | handle->sms_state_cb = cb; |
| 2194 | return 0; |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | /* |
| 2199 | * Set radio state change callback function. |
| 2200 | */ |
| 2201 | int mbtk_radio_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb) |
| 2202 | { |
| 2203 | if(handle == NULL) |
| 2204 | { |
| 2205 | LOGE("ARG error."); |
| 2206 | return -1; |
| 2207 | } |
| 2208 | if(info_item_process(handle, MBTK_INFO_ID_IND_RADIO_STATE_CHANGE, NULL, 0, NULL) < 0) { |
| 2209 | return handle->info_err; |
| 2210 | } else { |
| 2211 | handle->radio_state_cb = cb; |
| 2212 | return 0; |
| 2213 | } |
| 2214 | } |
| 2215 | |
| 2216 | /* |
| 2217 | * Set sim state change callback function. |
| 2218 | */ |
| 2219 | int mbtk_sim_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb) |
| 2220 | { |
| 2221 | if(handle == NULL) |
| 2222 | { |
| 2223 | LOGE("ARG error."); |
| 2224 | return -1; |
| 2225 | } |
| 2226 | if(info_item_process(handle, MBTK_INFO_ID_IND_SIM_STATE_CHANGE, NULL, 0, NULL) < 0) { |
| 2227 | return handle->info_err; |
| 2228 | } else { |
| 2229 | handle->sim_state_cb = cb; |
| 2230 | return 0; |
| 2231 | } |
| 2232 | } |