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