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