b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame^] | 1 | /*-----------------------------------------------------------------------------------------------*/ |
| 2 | /** |
| 3 | @file ql_nw.c |
| 4 | @brief network registration API |
| 5 | */ |
| 6 | /*-----------------------------------------------------------------------------------------------*/ |
| 7 | |
| 8 | /*------------------------------------------------------------------------------------------------- |
| 9 | Copyright (c) 2024 mobiletek Wireless Solution, Co., Ltd. All Rights Reserved. |
| 10 | mobiletek Wireless Solution Proprietary and Confidential. |
| 11 | -------------------------------------------------------------------------------------------------*/ |
| 12 | |
| 13 | /*------------------------------------------------------------------------------------------------- |
| 14 | EDIT HISTORY |
| 15 | This section contains comments describing changes made to the file. |
| 16 | Notice that changes are listed in reverse chronological order. |
| 17 | $Header: $ |
| 18 | when who what, where, why |
| 19 | -------- --------- ----------------------------------------------------------------- |
| 20 | 20241022 yq.wang Created . |
| 21 | -------------------------------------------------------------------------------------------------*/ |
| 22 | #include <stdint.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <sys/epoll.h> |
| 26 | #include <unistd.h> |
| 27 | #include <errno.h> |
| 28 | #include <pthread.h> |
| 29 | #include <string.h> |
| 30 | #include <fcntl.h> |
| 31 | |
| 32 | #include "ql_nw.h" |
| 33 | #include "ql_type.h" |
| 34 | #include "mbtk_type.h" |
| 35 | #include "mbtk_ril_api.h" |
| 36 | |
| 37 | /*----------------------------------------------DEFINE-------------------------------------------*/ |
| 38 | #define QL_NW_LOGE LOGE |
| 39 | #define QL_NW_LOGD LOGD |
| 40 | |
| 41 | #define MBTK_ERR_OK 0 |
| 42 | |
| 43 | #define MBTK_BUFF_TEMP_SIZE_8 8 |
| 44 | |
| 45 | #define QL_NW_MCC_LENGHT 3 |
| 46 | #define QL_NW_MNC_MAX 3 |
| 47 | #define QL_NW_MCC_MNC_MAX 6 |
| 48 | #define QL_NW_MCC_MNC_MIN 5 |
| 49 | |
| 50 | #define MBTK_READ_EVENT_SIZE 1 |
| 51 | #define MBTK_WRITE_EVENT_SIZE 1 |
| 52 | |
| 53 | /*----------------------------------------------DEFINE-------------------------------------------*/ |
| 54 | |
| 55 | /*----------------------------------------------ENUM---------------------------------------------*/ |
| 56 | typedef enum { |
| 57 | QL_NW_REG_TYPE_VOICE = 0, |
| 58 | QL_NW_REG_TYPE_DATA, |
| 59 | }ql_nw_reg_type_enum; |
| 60 | |
| 61 | typedef enum { |
| 62 | QL_NW_EVENT_THREAD_QUIT = 0, |
| 63 | QL_NW_EVENT_SIGNAL_CB, |
| 64 | QL_NW_EVENT_VOICE_CB, |
| 65 | QL_NW_EVENT_MAX = 255, |
| 66 | }ql_nw_event_enum; |
| 67 | |
| 68 | /*----------------------------------------------ENUM---------------------------------------------*/ |
| 69 | |
| 70 | /*----------------------------------------------STRUCT-------------------------------------------*/ |
| 71 | typedef struct { |
| 72 | mbtk_ril_handle* handle; |
| 73 | int control[2]; |
| 74 | pthread_t cb_thread_id; |
| 75 | ql_nw_signal_strength_ind_cb signal_cb; |
| 76 | ql_nw_voice_reg_ind_cb voice_cb; |
| 77 | ql_nw_service_error_cb_f server_cb; |
| 78 | }ql_nw_info_handle_t; |
| 79 | |
| 80 | /*----------------------------------------------STRUCT-------------------------------------------*/ |
| 81 | |
| 82 | /*----------------------------------------------GLOBAL STATIC VARIABLE---------------------------*/ |
| 83 | static ql_nw_info_handle_t* nw_handle = NULL; |
| 84 | |
| 85 | /*----------------------------------------------GLOBAL STATIC VARIABLE---------------------------*/ |
| 86 | |
| 87 | /*----------------------------------------------NW FUNCTION--------------------------------------*/ |
| 88 | static int ql_get_cops_state(ql_nw_reg_status_info_t *p_info, ql_nw_info_handle_t *p_handle) |
| 89 | { |
| 90 | int ret = 0; |
| 91 | char mcc_mnc[MBTK_BUFF_TEMP_SIZE_8] = {0}; |
| 92 | mbtk_net_info_t net = {0}; |
| 93 | memset(&net, 0x0, sizeof(mbtk_net_info_t)); |
| 94 | ret = mbtk_net_sel_mode_get(p_handle->handle, &net); |
| 95 | if(ret != MBTK_ERR_OK) |
| 96 | { |
| 97 | QL_NW_LOGE("[%s] net sel mode get fail.[%d]", __func__, ret); |
| 98 | return QL_ERR_FAILED; |
| 99 | } |
| 100 | |
| 101 | switch(net.net_type) |
| 102 | { |
| 103 | case MBTK_RADIO_TECH_GSM: |
| 104 | case MBTK_RADIO_TECH_GSM_COMPACT: |
| 105 | { |
| 106 | p_info->radio_tech = QL_NW_RADIO_TECH_GSM; |
| 107 | break; |
| 108 | } |
| 109 | case MBTK_RADIO_TECH_GSM_EGPRS: |
| 110 | { |
| 111 | p_info->radio_tech = QL_NW_RADIO_TECH_GPRS; |
| 112 | break; |
| 113 | } |
| 114 | case MBTK_RADIO_TECH_UTRAN: |
| 115 | { |
| 116 | p_info->radio_tech = QL_NW_RADIO_TECH_UMTS; |
| 117 | break; |
| 118 | } |
| 119 | case MBTK_RADIO_TECH_UTRAN_HSDPA: |
| 120 | { |
| 121 | p_info->radio_tech = QL_NW_RADIO_TECH_HSDPA; |
| 122 | break; |
| 123 | } |
| 124 | case MBTK_RADIO_TECH_UTRAN_HSUPA: |
| 125 | { |
| 126 | p_info->radio_tech = QL_NW_RADIO_TECH_HSUPA; |
| 127 | break; |
| 128 | } |
| 129 | case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA: |
| 130 | { |
| 131 | p_info->radio_tech = QL_NW_RADIO_TECH_HSPA; |
| 132 | break; |
| 133 | } |
| 134 | case MBTK_RADIO_TECH_UTRAN_HSPA: |
| 135 | { |
| 136 | p_info->radio_tech = QL_NW_RADIO_TECH_HSPAP; |
| 137 | break; |
| 138 | } |
| 139 | case MBTK_RADIO_TECH_E_UTRAN: |
| 140 | { |
| 141 | p_info->radio_tech = QL_NW_RADIO_TECH_LTE; |
| 142 | break; |
| 143 | } |
| 144 | default: |
| 145 | { |
| 146 | p_info->radio_tech = QL_NW_RADIO_TECH_NONE; |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | memset(mcc_mnc, 0x0, MBTK_BUFF_TEMP_SIZE_8); |
| 152 | ret = snprintf(mcc_mnc, MBTK_BUFF_TEMP_SIZE_8, "%d", net.plmn); |
| 153 | if(ret != QL_NW_MCC_MNC_MIN && ret != QL_NW_MCC_MNC_MAX) |
| 154 | { |
| 155 | QL_NW_LOGE("[%s] mcc mnc get fail.[%d]", __func__, ret); |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | memcpy(p_info->mcc, mcc_mnc, QL_NW_MCC_LENGHT); |
| 160 | memcpy(p_info->mnc, mcc_mnc + QL_NW_MCC_LENGHT, ret - QL_NW_MCC_LENGHT); |
| 161 | } |
| 162 | |
| 163 | return QL_ERR_OK; |
| 164 | } |
| 165 | |
| 166 | static int ql_get_creg_state(ql_nw_reg_status_info_t *p_info, ql_nw_info_handle_t *p_handle, ql_nw_reg_type_enum reg_type) |
| 167 | { |
| 168 | int ret = 0; |
| 169 | uint8 reg_state = 0; |
| 170 | mbtk_net_reg_info_t reg; |
| 171 | memset(®, 0x0, sizeof(mbtk_net_reg_info_t)); |
| 172 | ret = mbtk_net_reg_get(p_handle->handle, ®); |
| 173 | if(ret != MBTK_ERR_OK) |
| 174 | { |
| 175 | QL_NW_LOGE("[%s] net reg get fail.[%d]", __func__, ret); |
| 176 | return QL_ERR_FAILED; |
| 177 | } |
| 178 | |
| 179 | if(reg_type == QL_NW_REG_TYPE_VOICE) |
| 180 | { |
| 181 | if(reg.ims_state == 0) |
| 182 | { |
| 183 | reg_state = reg.call_state; |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | reg_state = reg.ims_state; |
| 188 | } |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | if(reg.type == MBTK_RADIO_TECH_E_UTRAN) |
| 193 | { |
| 194 | reg_state = reg.data_state; |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | reg_state = reg.call_state; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | p_info->deny_reason = QL_NW_CS_DOMAIN_NOT_AVAILABLE_DENY_REASON; |
| 203 | switch(reg_state) |
| 204 | { |
| 205 | case MBTK_NET_REG_STATE_HOME: |
| 206 | { |
| 207 | p_info->reg_state = QL_NW_SERVICE_FULL; |
| 208 | p_info->roaming = QL_NW_ROAM_STATE_OFF; |
| 209 | break; |
| 210 | } |
| 211 | case MBTK_NET_REG_STATE_DENIED: |
| 212 | { |
| 213 | p_info->reg_state = QL_NW_SERVICE_NONE; |
| 214 | p_info->roaming = QL_NW_ROAM_STATE_OFF; |
| 215 | p_info->deny_reason = QL_NW_CS_DOMAIN_NOT_AVAILABLE_DENY_REASON; //now not support |
| 216 | break; |
| 217 | } |
| 218 | case MBTK_NET_REG_STATE_ROAMING: |
| 219 | { |
| 220 | p_info->reg_state = QL_NW_SERVICE_FULL; |
| 221 | p_info->roaming = QL_NW_ROAM_STATE_ON; |
| 222 | break; |
| 223 | } |
| 224 | case MBTK_NET_REG_STATE_SMS_ONLY: |
| 225 | case MBTK_NET_REG_STATE_CSFB_HOME: |
| 226 | case MBTK_NET_REG_STATE_EMERGENCY_ONLY: |
| 227 | { |
| 228 | p_info->reg_state = QL_NW_SERVICE_LIMITED; |
| 229 | p_info->roaming = QL_NW_ROAM_STATE_OFF; |
| 230 | break; |
| 231 | } |
| 232 | case MBTK_NET_REG_STATE_ROAMING_SMS: |
| 233 | case MBTK_NET_REG_STATE_CSFB_ROAMING: |
| 234 | { |
| 235 | p_info->reg_state = QL_NW_SERVICE_LIMITED; |
| 236 | p_info->roaming = QL_NW_ROAM_STATE_ON; |
| 237 | break; |
| 238 | } |
| 239 | case MBTK_NET_REG_STATE_NON: |
| 240 | case MBTK_NET_REG_STATE_SEARCHING: |
| 241 | case MBTK_NET_REG_STATE_UNKNOWN: |
| 242 | case MBTK_NET_REG_STATE_ATTACHED_EMERGENCY: |
| 243 | default: |
| 244 | { |
| 245 | p_info->reg_state = QL_NW_SERVICE_NONE; |
| 246 | p_info->roaming = QL_NW_ROAM_STATE_OFF; |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | p_info->cid = reg.ci; |
| 252 | p_info->lac = reg.lac; |
| 253 | |
| 254 | return QL_ERR_OK; |
| 255 | } |
| 256 | |
| 257 | static int8_t rssi_convert_to_dBm(uint8 rssi) |
| 258 | { |
| 259 | if(rssi <= 31) |
| 260 | { |
| 261 | return rssi * 2 - 113; |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | return -125; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | static int16_t rsrp_convert_to_dBm(uint8 rsrp) |
| 270 | { |
| 271 | if(rsrp <= 96) |
| 272 | { |
| 273 | return rsrp - 140; |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | return -44; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | static int16_t rsrq_convert_to_dB(uint8 rsrq) |
| 282 | { |
| 283 | if(rsrq >= 1 && rsrq <= 34) |
| 284 | { |
| 285 | return (rsrq + 1) / 2 - 20; |
| 286 | } |
| 287 | else |
| 288 | { |
| 289 | return -20; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | static int16_t ecno_convert_to_dB(uint8 ecno) |
| 294 | { |
| 295 | if(ecno >= 48) |
| 296 | { |
| 297 | return 0; |
| 298 | } |
| 299 | else if(ecno == 255) |
| 300 | { |
| 301 | return 255; |
| 302 | } |
| 303 | else |
| 304 | { |
| 305 | return 48 - ecno; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | static QL_NW_SIGNAL_STRENGTH_LEVEL_E ql_rssi_convert_level(uint8 rssi) |
| 310 | { |
| 311 | //rssi 0 - 31,99 |
| 312 | if(rssi == 0 || rssi == 99) |
| 313 | { |
| 314 | return QL_NW_SIGNAL_STRENGTH_LEVEL_NONE; |
| 315 | } |
| 316 | else if(rssi >= 1 && rssi < 10) |
| 317 | { |
| 318 | return QL_NW_SIGNAL_STRENGTH_LEVEL_POOR; |
| 319 | } |
| 320 | else if(rssi >= 10 && rssi < 20) |
| 321 | { |
| 322 | return QL_NW_SIGNAL_STRENGTH_LEVEL_MODERATE; |
| 323 | } |
| 324 | else if(rssi >= 20 && rssi <= 30) |
| 325 | { |
| 326 | return QL_NW_SIGNAL_STRENGTH_LEVEL_GOOD; |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | return QL_NW_SIGNAL_STRENGTH_LEVEL_GREAT; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | static void ql_signal_state_change_cb(const void* data, int data_len) |
| 335 | { |
| 336 | if(data && data_len == 8) |
| 337 | { |
| 338 | uint8 *net_data = (uint8*)data; |
| 339 | mbtk_radio_technology_enum type = (mbtk_radio_technology_enum)net_data[0]; |
| 340 | QL_NW_LOGD("[%s] reg_type[%d].", __func__, type); |
| 341 | ql_nw_event_enum cmd = QL_NW_EVENT_SIGNAL_CB; |
| 342 | if(nw_handle->control[0] >= 0) |
| 343 | { |
| 344 | int ret = write(nw_handle->control[0], &cmd, MBTK_WRITE_EVENT_SIZE); |
| 345 | if(ret != MBTK_WRITE_EVENT_SIZE) |
| 346 | { |
| 347 | QL_NW_LOGE("[%s] write fail.[%d]", __func__, ret); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | else |
| 352 | { |
| 353 | QL_NW_LOGD("[%s] unknown data.", __func__); |
| 354 | } |
| 355 | |
| 356 | } |
| 357 | |
| 358 | static void ql_net_state_change_cb(const void* data, int data_len) |
| 359 | { |
| 360 | if(data) |
| 361 | { |
| 362 | ql_nw_event_enum cmd = QL_NW_EVENT_VOICE_CB; |
| 363 | if(nw_handle->control[0] >= 0) |
| 364 | { |
| 365 | int ret = write(nw_handle->control[0], &cmd, MBTK_WRITE_EVENT_SIZE); |
| 366 | if(ret != MBTK_WRITE_EVENT_SIZE) |
| 367 | { |
| 368 | QL_NW_LOGE("[%s] write fail.[%d]", __func__, ret); |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | else |
| 373 | { |
| 374 | QL_NW_LOGD("[%s] unknown data.", __func__); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | static void ql_nw_server_change_cb(const void* data, int data_len) |
| 379 | { |
| 380 | if(data_len != sizeof(int)) |
| 381 | { |
| 382 | QL_NW_LOGE("[%s] data_len[%d] than int[%d] fail. ", __func__, data_len, sizeof(int)); |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | int server_state = *(int *)data; |
| 387 | if(server_state == 1 && nw_handle->server_cb) |
| 388 | { |
| 389 | nw_handle->server_cb(QL_ERR_ABORTED); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | static int ql_epoll_register(int epoll_fd, int fd) |
| 395 | { |
| 396 | struct epoll_event ev; |
| 397 | int ret, flags; |
| 398 | |
| 399 | /* important: make the fd non-blocking */ |
| 400 | flags = fcntl(fd, F_GETFL); |
| 401 | fcntl(fd, F_SETFL, flags | O_NONBLOCK); |
| 402 | |
| 403 | ev.events = EPOLLIN; |
| 404 | ev.data.fd = fd; |
| 405 | |
| 406 | do |
| 407 | { |
| 408 | ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev); |
| 409 | if(ret < 0) |
| 410 | { |
| 411 | QL_NW_LOGE("[%s] epoll_ctl fail.[%s]", __func__, strerror(errno)); |
| 412 | } |
| 413 | } while (ret < 0 && errno == EINTR); |
| 414 | |
| 415 | return QL_ERR_OK; |
| 416 | } |
| 417 | |
| 418 | static void* ql_cb_thread(void* arg) |
| 419 | { |
| 420 | ql_nw_info_handle_t* info = (ql_nw_info_handle_t*)arg; |
| 421 | |
| 422 | if(info->control[0] < 0 && info->control[0] < 0) |
| 423 | { |
| 424 | if(socketpair(AF_LOCAL, SOCK_STREAM, 0, info->control ) < 0) |
| 425 | { |
| 426 | QL_NW_LOGE("[%s] control creat fail.", __func__); |
| 427 | return NULL; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | int ne = 0; |
| 432 | int nevents = 0; |
| 433 | int ret = 0; |
| 434 | struct epoll_event events[3]; |
| 435 | int control_fd = info->control[1]; |
| 436 | ql_nw_event_enum cmd = QL_NW_EVENT_THREAD_QUIT; |
| 437 | |
| 438 | //A maximum of three events can be processed simultaneously |
| 439 | int epoll_fd = epoll_create(3); |
| 440 | ql_epoll_register(epoll_fd, control_fd); |
| 441 | |
| 442 | QL_NW_LOGE("[%s] thread start run.", __func__); |
| 443 | while(1) |
| 444 | { |
| 445 | nevents = epoll_wait(epoll_fd, events, 3, -1); |
| 446 | if(nevents < 0) |
| 447 | { |
| 448 | if(errno != EINTR) |
| 449 | { |
| 450 | QL_NW_LOGE("[%s] epoll_wait fail.[%s]", __func__, strerror(errno)); |
| 451 | } |
| 452 | continue; |
| 453 | } |
| 454 | |
| 455 | for (ne = 0; ne < nevents; ne++) |
| 456 | { |
| 457 | if((events[ne].events & (EPOLLERR|EPOLLHUP)) != 0) |
| 458 | { |
| 459 | QL_NW_LOGE("[%s] EPOLLERR or EPOLLHUP event error.", __func__); |
| 460 | break; |
| 461 | } |
| 462 | |
| 463 | if ((events[ne].events & EPOLLIN) != 0) |
| 464 | { |
| 465 | if (events[ne].data.fd == control_fd) |
| 466 | { |
| 467 | ret = read(control_fd, &cmd, MBTK_READ_EVENT_SIZE); |
| 468 | if(ret != MBTK_READ_EVENT_SIZE) |
| 469 | { |
| 470 | QL_NW_LOGE("[%s] read fail.[%d]", __func__, ret); |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | switch(cmd) |
| 475 | { |
| 476 | case QL_NW_EVENT_THREAD_QUIT: |
| 477 | { |
| 478 | close(epoll_fd); |
| 479 | epoll_fd = -1; |
| 480 | if(info->control[0] >= 0) |
| 481 | { |
| 482 | close(info->control[0]); |
| 483 | info->control[0] = -1; |
| 484 | } |
| 485 | if(info->control[1] >= 0) |
| 486 | { |
| 487 | close(info->control[1]); |
| 488 | info->control[1] = -1; |
| 489 | } |
| 490 | QL_NW_LOGD("[%s] thread quit.", __func__); |
| 491 | return NULL; |
| 492 | } |
| 493 | case QL_NW_EVENT_SIGNAL_CB: |
| 494 | { |
| 495 | if(info->signal_cb) |
| 496 | { |
| 497 | ql_nw_signal_strength_info_t signal_info = {0}; |
| 498 | QL_NW_SIGNAL_STRENGTH_LEVEL_E level = QL_NW_SIGNAL_STRENGTH_LEVEL_MIN; |
| 499 | ql_nw_get_signal_strength(&signal_info, &level); |
| 500 | info->signal_cb(&signal_info, level); |
| 501 | } |
| 502 | break; |
| 503 | } |
| 504 | case QL_NW_EVENT_VOICE_CB: |
| 505 | { |
| 506 | if(info->voice_cb) |
| 507 | { |
| 508 | ql_nw_reg_status_info_t voice_reg_info = {0}; |
| 509 | ql_nw_get_voice_reg_status(&voice_reg_info); |
| 510 | info->voice_cb(&voice_reg_info); |
| 511 | } |
| 512 | break; |
| 513 | } |
| 514 | default: |
| 515 | { |
| 516 | QL_NW_LOGE("[%s] unknown event.[%d]", __func__, cmd); |
| 517 | break; |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | |
| 528 | static int ql_cb_thread_creat(ql_nw_info_handle_t *info) |
| 529 | { |
| 530 | if(info->cb_thread_id == 0) |
| 531 | { |
| 532 | pthread_attr_t thread_attr; |
| 533 | pthread_attr_init(&thread_attr); |
| 534 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 535 | { |
| 536 | QL_NW_LOGE("[%s] pthread_attr_setdetachstate fail.", __func__); |
| 537 | return QL_ERR_FAILED; |
| 538 | } |
| 539 | if(pthread_create(&(info->cb_thread_id), &thread_attr, ql_cb_thread, info)) |
| 540 | { |
| 541 | QL_NW_LOGE("[%s] pthread_create fail.[%ld]", __func__, info->cb_thread_id); |
| 542 | return QL_ERR_FAILED; |
| 543 | } |
| 544 | QL_NW_LOGD("[%s] pthread_create success.[%ld]", __func__, info->cb_thread_id); |
| 545 | } |
| 546 | |
| 547 | return QL_ERR_OK; |
| 548 | } |
| 549 | |
| 550 | static int ql_cb_thread_free(ql_nw_info_handle_t *info) |
| 551 | { |
| 552 | int ret = 0; |
| 553 | if(info->cb_thread_id != 0) |
| 554 | { |
| 555 | ql_nw_event_enum cmd = QL_NW_EVENT_THREAD_QUIT; |
| 556 | if(info->control[0] >= 0) |
| 557 | { |
| 558 | ret = write(info->control[0], &cmd, MBTK_WRITE_EVENT_SIZE); |
| 559 | if(ret != MBTK_WRITE_EVENT_SIZE) |
| 560 | { |
| 561 | QL_NW_LOGE("[%s] write fail.[%d]", __func__, ret); |
| 562 | return QL_ERR_FAILED; |
| 563 | } |
| 564 | } |
| 565 | info->cb_thread_id = 0; |
| 566 | QL_NW_LOGE("[%s] pthread quit success.", __func__); |
| 567 | } |
| 568 | |
| 569 | return QL_ERR_OK; |
| 570 | } |
| 571 | |
| 572 | /*----------------------------------------------NW FUNCTION--------------------------------------*/ |
| 573 | |
| 574 | /*-----------------------------------------------------------------------------------------------*/ |
| 575 | /** |
| 576 | @brief Initialize NW service. |
| 577 | @note You must call this function before other functions can be used in this module. |
| 578 | @return Whether the NW service was successfully intialized. |
| 579 | @retval QL_ERR_OK successful |
| 580 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry |
| 581 | @retval Other error code defined by ql_type.h |
| 582 | */ |
| 583 | /*-----------------------------------------------------------------------------------------------*/ |
| 584 | int ql_nw_init(void) |
| 585 | { |
| 586 | if(NULL == nw_handle) |
| 587 | { |
| 588 | nw_handle = (ql_nw_info_handle_t*)malloc(sizeof(ql_nw_info_handle_t)); |
| 589 | if(NULL == nw_handle) |
| 590 | { |
| 591 | QL_NW_LOGE("[%s] nw handle malloc fail.", __func__); |
| 592 | return QL_ERR_FAILED; |
| 593 | } |
| 594 | |
| 595 | nw_handle->handle = mbtk_ril_open(MBTK_AT_PORT_DEF); |
| 596 | if(NULL == nw_handle->handle) |
| 597 | { |
| 598 | QL_NW_LOGE("[%s] mbtk handle init fail.", __func__); |
| 599 | goto error_1; |
| 600 | } |
| 601 | |
| 602 | int ret = mbtk_signal_state_change_cb_reg(ql_signal_state_change_cb); |
| 603 | if(ret != MBTK_ERR_OK) |
| 604 | { |
| 605 | QL_NW_LOGE("[%s] set nw signal cb fail.[%d]", __func__, ret); |
| 606 | goto error_2; |
| 607 | } |
| 608 | |
| 609 | ret = mbtk_net_reg_state_change_cb_reg(ql_net_state_change_cb); |
| 610 | if(ret != MBTK_ERR_OK) |
| 611 | { |
| 612 | QL_NW_LOGE("[%s] set nw signal cb fail.[%d]", __func__, ret); |
| 613 | goto error_2; |
| 614 | } |
| 615 | |
| 616 | ret = mbtk_ril_ser_state_change_cb_reg(ql_nw_server_change_cb); |
| 617 | if(ret != MBTK_ERR_OK) |
| 618 | { |
| 619 | QL_NW_LOGE("[%s] set sim server cb fail.[%d]", __func__, ret); |
| 620 | goto error_2; |
| 621 | } |
| 622 | |
| 623 | nw_handle->signal_cb = NULL; |
| 624 | nw_handle->voice_cb = NULL; |
| 625 | nw_handle->control[0] = -1; |
| 626 | nw_handle->control[1] = -1; |
| 627 | nw_handle->cb_thread_id = 0; |
| 628 | } |
| 629 | |
| 630 | return QL_ERR_OK; |
| 631 | error_2: |
| 632 | if(nw_handle->handle) |
| 633 | { |
| 634 | mbtk_ril_close(MBTK_AT_PORT_DEF);; |
| 635 | nw_handle->handle = NULL; |
| 636 | } |
| 637 | error_1: |
| 638 | if(nw_handle) |
| 639 | { |
| 640 | free(nw_handle); |
| 641 | nw_handle = NULL; |
| 642 | } |
| 643 | return QL_ERR_FAILED; |
| 644 | } |
| 645 | |
| 646 | /*-----------------------------------------------------------------------------------------------*/ |
| 647 | /** |
| 648 | @brief Deinitializes NW service. |
| 649 | @return Whether the NW service was deinitialized successfully. |
| 650 | @retval QL_ERR_OK successful. |
| 651 | @retval Other error code defined by ql_type.h. |
| 652 | */ |
| 653 | /*-----------------------------------------------------------------------------------------------*/ |
| 654 | int ql_nw_deinit(void) |
| 655 | { |
| 656 | if(NULL == nw_handle) |
| 657 | { |
| 658 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 659 | return QL_ERR_NOT_INIT; |
| 660 | } |
| 661 | |
| 662 | int ret = 0; |
| 663 | nw_handle->voice_cb = NULL; |
| 664 | nw_handle->signal_cb = NULL; |
| 665 | |
| 666 | if(NULL != nw_handle->handle) |
| 667 | { |
| 668 | ret = mbtk_ril_close(MBTK_AT_PORT_DEF); |
| 669 | if(ret != MBTK_ERR_OK) |
| 670 | { |
| 671 | QL_NW_LOGE("[%s] mbtk handle deinit fail.[%d]", __func__, ret); |
| 672 | return QL_ERR_FAILED; |
| 673 | } |
| 674 | nw_handle->handle = NULL; |
| 675 | } |
| 676 | |
| 677 | ret = ql_cb_thread_free(nw_handle); |
| 678 | if(ret != QL_ERR_OK) |
| 679 | { |
| 680 | QL_NW_LOGE("[%s] cb thread free deinit fail.", __func__); |
| 681 | return QL_ERR_FAILED; |
| 682 | } |
| 683 | |
| 684 | free(nw_handle); |
| 685 | nw_handle = NULL; |
| 686 | |
| 687 | return QL_ERR_OK; |
| 688 | } |
| 689 | |
| 690 | /*-----------------------------------------------------------------------------------------------*/ |
| 691 | /** |
| 692 | @brief scan network status. |
| 693 | @param[out] async_index The index of request msg |
| 694 | @param[in] async_cb The callback function of request msg |
| 695 | @return Whether to successfully trigger the network scan operation |
| 696 | @retval QL_ERR_OK successful |
| 697 | @retval QL_ERR_NOT_INIT uninitialized |
| 698 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 699 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 700 | @retval Other error code defined by ql_type.h |
| 701 | */ |
| 702 | /*-----------------------------------------------------------------------------------------------*/ |
| 703 | int ql_nw_network_scan(int *async_index, ql_nw_network_scan_async_cb async_cb) |
| 704 | { |
| 705 | UNUSED(async_index); |
| 706 | UNUSED(async_cb); |
| 707 | |
| 708 | if(NULL == nw_handle) |
| 709 | { |
| 710 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 711 | return QL_ERR_NOT_INIT; |
| 712 | } |
| 713 | |
| 714 | return QL_ERR_OK; |
| 715 | } |
| 716 | |
| 717 | /*-----------------------------------------------------------------------------------------------*/ |
| 718 | /** |
| 719 | @brief set power mode. |
| 720 | @param[in] lower_mode, defined by QL_NW_LOWER_POWER_MASK_XXX |
| 721 | @return Whether to successfully set the power mode |
| 722 | @retval QL_ERR_OK successful |
| 723 | @retval QL_ERR_NOT_INIT uninitialized |
| 724 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 725 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 726 | @retval Other error code defined by ql_type.h |
| 727 | */ |
| 728 | /*-----------------------------------------------------------------------------------------------*/ |
| 729 | int ql_nw_set_power_mode(uint8_t lower_mode) |
| 730 | { |
| 731 | if(NULL == nw_handle) |
| 732 | { |
| 733 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 734 | return QL_ERR_NOT_INIT; |
| 735 | } |
| 736 | |
| 737 | uint32 mode = 0; |
| 738 | if((lower_mode & QL_NW_LOWER_POWER_MASK_NORMAL) == QL_NW_LOWER_POWER_MASK_NORMAL) |
| 739 | { |
| 740 | mode |= 0x1; |
| 741 | } |
| 742 | |
| 743 | if((lower_mode & QL_NW_LOWER_POWER_MASK_NETWORK) == QL_NW_LOWER_POWER_MASK_NETWORK) |
| 744 | { |
| 745 | mode |= 0x1; |
| 746 | } |
| 747 | |
| 748 | if((lower_mode & QL_NW_LOWER_POWER_MASK_SIM) == QL_NW_LOWER_POWER_MASK_SIM) |
| 749 | { |
| 750 | mode |= 0x2; |
| 751 | } |
| 752 | |
| 753 | if((lower_mode & QL_NW_LOWER_POWER_MASK_SMS) == QL_NW_LOWER_POWER_MASK_SMS) |
| 754 | { |
| 755 | mode |= 0x4; |
| 756 | } |
| 757 | |
| 758 | if((lower_mode & QL_NW_LOWER_POWER_MASK_VOICE) == QL_NW_LOWER_POWER_MASK_VOICE) |
| 759 | { |
| 760 | mode |= 0x8; |
| 761 | } |
| 762 | |
| 763 | int ret = 0; |
| 764 | ret = mbtk_wakeup_state_set(nw_handle->handle, mode); |
| 765 | if(ret != MBTK_ERR_OK) |
| 766 | { |
| 767 | QL_NW_LOGE("[%s] wakeup state set fail.[%d]", ret); |
| 768 | return QL_ERR_FAILED; |
| 769 | } |
| 770 | |
| 771 | return QL_ERR_OK; |
| 772 | } |
| 773 | |
| 774 | /*-----------------------------------------------------------------------------------------------*/ |
| 775 | /** |
| 776 | @brief set perferred NW mode and roaming indicator. |
| 777 | @param[in] p_info Pointer that point to ql_nw_pref_nwmode_roaming_info_t |
| 778 | @return Whether to successfully set nwmode and roaming |
| 779 | @retval QL_ERR_OK successful |
| 780 | @retval QL_ERR_NOT_INIT uninitialized |
| 781 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 782 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 783 | @retval Other error code defined by ql_type.h |
| 784 | */ |
| 785 | /*-----------------------------------------------------------------------------------------------*/ |
| 786 | int ql_nw_set_pref_nwmode_roaming(ql_nw_pref_nwmode_roaming_info_t *p_info) |
| 787 | { |
| 788 | UNUSED(p_info); |
| 789 | |
| 790 | if(NULL == nw_handle) |
| 791 | { |
| 792 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 793 | return QL_ERR_NOT_INIT; |
| 794 | } |
| 795 | |
| 796 | return QL_ERR_OK; |
| 797 | } |
| 798 | |
| 799 | /*-----------------------------------------------------------------------------------------------*/ |
| 800 | /** |
| 801 | @brief get perferred NW mode and roaming indicator. |
| 802 | @param[out] p_info Pointer that point to ql_nw_pref_nwmode_roaming_info_t |
| 803 | @return Whether to successfully get nwmode and roaming |
| 804 | @retval QL_ERR_OK successful |
| 805 | @retval QL_ERR_NOT_INIT uninitialized |
| 806 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 807 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 808 | @retval Other error code defined by ql_type.h |
| 809 | */ |
| 810 | /*-----------------------------------------------------------------------------------------------*/ |
| 811 | int ql_nw_get_pref_nwmode_roaming(ql_nw_pref_nwmode_roaming_info_t *p_info) |
| 812 | { |
| 813 | UNUSED(p_info); |
| 814 | |
| 815 | if(NULL == nw_handle) |
| 816 | { |
| 817 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 818 | return QL_ERR_NOT_INIT; |
| 819 | } |
| 820 | |
| 821 | return QL_ERR_OK; |
| 822 | } |
| 823 | |
| 824 | |
| 825 | /*-----------------------------------------------------------------------------------------------*/ |
| 826 | /** |
| 827 | @brief get mobile operator name. |
| 828 | @param[out] p_info Pointer that point to ql_nw_mobile_operator_name_info_t |
| 829 | @return Whether to successfully get the mobile operator name |
| 830 | @retval QL_ERR_OK successful |
| 831 | @retval QL_ERR_NOT_INIT uninitialized |
| 832 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 833 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 834 | @retval Other error code defined by ql_type.h |
| 835 | */ |
| 836 | /*-----------------------------------------------------------------------------------------------*/ |
| 837 | int ql_nw_get_mobile_operator_name(ql_nw_mobile_operator_name_info_t *p_info) |
| 838 | { |
| 839 | UNUSED(p_info); |
| 840 | |
| 841 | if(NULL == nw_handle) |
| 842 | { |
| 843 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 844 | return QL_ERR_NOT_INIT; |
| 845 | } |
| 846 | |
| 847 | return QL_ERR_OK; |
| 848 | } |
| 849 | |
| 850 | |
| 851 | /*-----------------------------------------------------------------------------------------------*/ |
| 852 | /** |
| 853 | @brief get cell information. |
| 854 | @param[out] p_info Pointer that point to ql_nw_cell_info_t |
| 855 | @return Whether to successfully get the cell information |
| 856 | @retval QL_ERR_OK successful |
| 857 | @retval QL_ERR_NOT_INIT uninitialized |
| 858 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 859 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 860 | @retval Other error code defined by ql_type.h |
| 861 | */ |
| 862 | /*-----------------------------------------------------------------------------------------------*/ |
| 863 | int ql_nw_get_cell_info(ql_nw_cell_info_t *p_info) |
| 864 | { |
| 865 | UNUSED(p_info); |
| 866 | |
| 867 | if(NULL == nw_handle) |
| 868 | { |
| 869 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 870 | return QL_ERR_NOT_INIT; |
| 871 | } |
| 872 | |
| 873 | return QL_ERR_OK; |
| 874 | } |
| 875 | |
| 876 | /*-----------------------------------------------------------------------------------------------*/ |
| 877 | /** |
| 878 | @brief get voice registration status. |
| 879 | @param[out] p_info Pointer that point to ql_nw_reg_status_info_t |
| 880 | @return Whether to successfully get the voice registration status |
| 881 | @retval QL_ERR_OK successful |
| 882 | @retval QL_ERR_NOT_INIT uninitialized |
| 883 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 884 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 885 | @retval Other error code defined by ql_type.h |
| 886 | */ |
| 887 | /*-----------------------------------------------------------------------------------------------*/ |
| 888 | int ql_nw_get_voice_reg_status(ql_nw_reg_status_info_t *p_info) |
| 889 | { |
| 890 | if(NULL == nw_handle) |
| 891 | { |
| 892 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 893 | return QL_ERR_NOT_INIT; |
| 894 | } |
| 895 | |
| 896 | if(NULL == p_info) |
| 897 | { |
| 898 | QL_NW_LOGE("[%s] p_info is NULL.", __func__); |
| 899 | return QL_ERR_INVALID_ARG; |
| 900 | } |
| 901 | |
| 902 | int ret = 0; |
| 903 | ql_nw_reg_status_info_t reg_status_info = {0}; |
| 904 | memset(®_status_info, 0x0, sizeof(ql_nw_reg_status_info_t)); |
| 905 | reg_status_info.tech_domain = QL_NW_TECH_DOMAIN_3GPP; //default |
| 906 | |
| 907 | //get radio_tech mcc mnc |
| 908 | ret = ql_get_cops_state(®_status_info, nw_handle); |
| 909 | if(ret != QL_ERR_OK) |
| 910 | { |
| 911 | QL_NW_LOGE("[%s] get cops state fail.[%d]", __func__, ret); |
| 912 | return QL_ERR_FAILED; |
| 913 | } |
| 914 | |
| 915 | //get roaming deny_reason reg_state cid lac |
| 916 | ret = ql_get_creg_state(®_status_info, nw_handle, QL_NW_REG_TYPE_VOICE); |
| 917 | if(ret != QL_ERR_OK) |
| 918 | { |
| 919 | QL_NW_LOGE("[%s] get creg fail.[%d]", __func__, ret); |
| 920 | return QL_ERR_FAILED; |
| 921 | } |
| 922 | |
| 923 | memcpy(p_info, ®_status_info, sizeof(ql_nw_reg_status_info_t)); |
| 924 | return QL_ERR_OK; |
| 925 | } |
| 926 | |
| 927 | |
| 928 | /*-----------------------------------------------------------------------------------------------*/ |
| 929 | /** |
| 930 | @brief get data registration status. |
| 931 | @param[out] p_info Pointer that point to ql_nw_reg_status_info_t |
| 932 | @return Whether to successfully get the data registration status |
| 933 | @retval QL_ERR_OK successful |
| 934 | @retval QL_ERR_NOT_INIT uninitialized |
| 935 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 936 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 937 | @retval Other error code defined by ql_type.h |
| 938 | */ |
| 939 | /*-----------------------------------------------------------------------------------------------*/ |
| 940 | int ql_nw_get_data_reg_status(ql_nw_reg_status_info_t *p_info) |
| 941 | { |
| 942 | if(NULL == nw_handle) |
| 943 | { |
| 944 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 945 | return QL_ERR_NOT_INIT; |
| 946 | } |
| 947 | |
| 948 | if(NULL == p_info) |
| 949 | { |
| 950 | QL_NW_LOGE("[%s] p_info is NULL.", __func__); |
| 951 | return QL_ERR_INVALID_ARG; |
| 952 | } |
| 953 | |
| 954 | int ret = 0; |
| 955 | ql_nw_reg_status_info_t reg_status_info = {0}; |
| 956 | memset(®_status_info, 0x0, sizeof(ql_nw_reg_status_info_t)); |
| 957 | reg_status_info.tech_domain = QL_NW_TECH_DOMAIN_3GPP; //default |
| 958 | |
| 959 | //get radio_tech mcc mnc |
| 960 | ret = ql_get_cops_state(®_status_info, nw_handle); |
| 961 | if(ret != QL_ERR_OK) |
| 962 | { |
| 963 | QL_NW_LOGE("[%s] get cops state fail.[%d]", __func__, ret); |
| 964 | return QL_ERR_FAILED; |
| 965 | } |
| 966 | |
| 967 | //get roaming deny_reason reg_state cid lac |
| 968 | ret = ql_get_creg_state(®_status_info, nw_handle, QL_NW_REG_TYPE_DATA); |
| 969 | if(ret != QL_ERR_OK) |
| 970 | { |
| 971 | QL_NW_LOGE("[%s] get creg fail.[%d]", __func__, ret); |
| 972 | return QL_ERR_FAILED; |
| 973 | } |
| 974 | |
| 975 | memcpy(p_info, ®_status_info, sizeof(ql_nw_reg_status_info_t)); |
| 976 | return QL_ERR_OK; |
| 977 | } |
| 978 | |
| 979 | /*-----------------------------------------------------------------------------------------------*/ |
| 980 | /** |
| 981 | @brief get current signal strength. |
| 982 | @param[out] p_info Pointer that point to ql_nw_signal_strength_info_t |
| 983 | @param[out] p_level: signal strength level |
| 984 | @return Whether to successfully get the signal strength |
| 985 | @retval QL_ERR_OK successful |
| 986 | @retval QL_ERR_NOT_INIT uninitialized |
| 987 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 988 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 989 | @retval Other error code defined by ql_type.h |
| 990 | */ |
| 991 | /*-----------------------------------------------------------------------------------------------*/ |
| 992 | int ql_nw_get_signal_strength(ql_nw_signal_strength_info_t *p_info, QL_NW_SIGNAL_STRENGTH_LEVEL_E* p_level) |
| 993 | { |
| 994 | if(NULL == nw_handle) |
| 995 | { |
| 996 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 997 | return QL_ERR_NOT_INIT; |
| 998 | } |
| 999 | |
| 1000 | if(NULL == p_info || NULL == p_level) |
| 1001 | { |
| 1002 | QL_NW_LOGE("[%s] param is NULL.", __func__); |
| 1003 | return QL_ERR_INVALID_ARG; |
| 1004 | } |
| 1005 | |
| 1006 | int ret = 0; |
| 1007 | mbtk_signal_info_t signal; |
| 1008 | memset(&signal, 0x0, sizeof(mbtk_signal_info_t)); |
| 1009 | ret = mbtk_net_signal_get(nw_handle->handle, &signal); |
| 1010 | if(ret != MBTK_ERR_OK) |
| 1011 | { |
| 1012 | QL_NW_LOGE("[%s] net signal get fail.[%d]", __func__, ret); |
| 1013 | return QL_ERR_FAILED; |
| 1014 | } |
| 1015 | |
| 1016 | memset(p_info, 0x0, sizeof(ql_nw_signal_strength_info_t)); |
| 1017 | |
| 1018 | switch(signal.type) |
| 1019 | { |
| 1020 | case MBTK_RADIO_TECH_GSM: |
| 1021 | case MBTK_RADIO_TECH_GSM_COMPACT: |
| 1022 | case MBTK_RADIO_TECH_GSM_EGPRS: |
| 1023 | { |
| 1024 | p_info->has_gsm = TRUE; |
| 1025 | p_info->gsm.rssi = rssi_convert_to_dBm(signal.rssi); |
| 1026 | break; |
| 1027 | } |
| 1028 | case MBTK_RADIO_TECH_E_UTRAN: |
| 1029 | { |
| 1030 | p_info->has_lte = TRUE; |
| 1031 | p_info->lte.rssi = rssi_convert_to_dBm(signal.rssi); |
| 1032 | p_info->lte.rsrq = rsrq_convert_to_dB(signal.rsrq); |
| 1033 | p_info->lte.rsrp = rsrp_convert_to_dBm(signal.rsrp); |
| 1034 | p_info->lte.snr = 0x7FFF;//->MBTK??????(?????rssnr,??INT_MAX:0x7FFFFFFFF?????),????0x7FFFFFFFF |
| 1035 | break; |
| 1036 | } |
| 1037 | case MBTK_RADIO_TECH_UTRAN: |
| 1038 | case MBTK_RADIO_TECH_UTRAN_HSDPA: |
| 1039 | case MBTK_RADIO_TECH_UTRAN_HSUPA: |
| 1040 | case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA: |
| 1041 | case MBTK_RADIO_TECH_UTRAN_HSPA: |
| 1042 | { |
| 1043 | p_info->has_wcdma = TRUE; |
| 1044 | p_info->wcdma.rssi = rssi_convert_to_dBm(signal.rssi); |
| 1045 | p_info->wcdma.ecio = ecno_convert_to_dB(signal.ecno); |
| 1046 | break; |
| 1047 | } |
| 1048 | default: |
| 1049 | { |
| 1050 | QL_NW_LOGE("[%s] unknown reg type.[%d]", __func__, signal.type); |
| 1051 | break; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | *p_level = ql_rssi_convert_level(signal.rssi); |
| 1056 | return QL_ERR_OK; |
| 1057 | } |
| 1058 | |
| 1059 | |
| 1060 | /*-----------------------------------------------------------------------------------------------*/ |
| 1061 | /** |
| 1062 | @brief get current cell acccess status. |
| 1063 | @param[out] p_info Pointer that point to QL_NW_CELL_ACCESS_STATE_TYPE_E |
| 1064 | @return Whether to successfully get the cell access status |
| 1065 | @retval QL_ERR_OK successful |
| 1066 | @retval QL_ERR_NOT_INIT uninitialized |
| 1067 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1068 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1069 | @retval Other error code defined by ql_type.h |
| 1070 | */ |
| 1071 | /*-----------------------------------------------------------------------------------------------*/ |
| 1072 | int ql_nw_get_cell_access_status(QL_NW_CELL_ACCESS_STATE_TYPE_E *p_info) |
| 1073 | { |
| 1074 | UNUSED(p_info); |
| 1075 | if(NULL == nw_handle) |
| 1076 | { |
| 1077 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1078 | return QL_ERR_NOT_INIT; |
| 1079 | } |
| 1080 | |
| 1081 | return QL_ERR_OK; |
| 1082 | } |
| 1083 | |
| 1084 | /*-----------------------------------------------------------------------------------------------*/ |
| 1085 | /** |
| 1086 | @brief get network time. |
| 1087 | @param[out] p_info Pointer that point to ql_nw_nitz_time_info_t |
| 1088 | @return Whether to successfully get the network time |
| 1089 | @retval QL_ERR_OK successful |
| 1090 | @retval QL_ERR_NOT_INIT uninitialized |
| 1091 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1092 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1093 | @retval Other error code defined by ql_type.h |
| 1094 | */ |
| 1095 | /*-----------------------------------------------------------------------------------------------*/ |
| 1096 | int ql_nw_get_nitz_time_info(ql_nw_nitz_time_info_t *p_info) |
| 1097 | { |
| 1098 | UNUSED(p_info); |
| 1099 | if(NULL == nw_handle) |
| 1100 | { |
| 1101 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1102 | return QL_ERR_NOT_INIT; |
| 1103 | } |
| 1104 | |
| 1105 | return QL_ERR_OK; |
| 1106 | } |
| 1107 | |
| 1108 | /*-----------------------------------------------------------------------------------------------*/ |
| 1109 | /** |
| 1110 | @brief register voice registration event. |
| 1111 | @param[in] cb_func Voice registration indication callback function |
| 1112 | @return Whether the voice registration event was successfully registered. |
| 1113 | @retval QL_ERR_OK successful |
| 1114 | @retval QL_ERR_NOT_INIT uninitialized |
| 1115 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1116 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1117 | @retval Other error code defined by ql_type.h |
| 1118 | */ |
| 1119 | /*-----------------------------------------------------------------------------------------------*/ |
| 1120 | int ql_nw_set_voice_reg_ind_cb(ql_nw_voice_reg_ind_cb cb_func) |
| 1121 | { |
| 1122 | if(NULL == nw_handle) |
| 1123 | { |
| 1124 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1125 | return QL_ERR_NOT_INIT; |
| 1126 | } |
| 1127 | |
| 1128 | int ret = QL_ERR_OK; |
| 1129 | if(NULL != cb_func) |
| 1130 | { |
| 1131 | ret = ql_cb_thread_creat(nw_handle); |
| 1132 | if(ret != QL_ERR_OK) |
| 1133 | { |
| 1134 | QL_NW_LOGE("[%s] cb thread creat fail.", __func__); |
| 1135 | } |
| 1136 | } |
| 1137 | else |
| 1138 | { |
| 1139 | ret = ql_cb_thread_free(nw_handle); |
| 1140 | if(ret != QL_ERR_OK) |
| 1141 | { |
| 1142 | QL_NW_LOGE("[%s] cb thread free deinit fail.", __func__); |
| 1143 | return QL_ERR_FAILED; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | nw_handle->voice_cb = cb_func; |
| 1148 | |
| 1149 | return QL_ERR_OK; |
| 1150 | } |
| 1151 | |
| 1152 | /*-----------------------------------------------------------------------------------------------*/ |
| 1153 | /** |
| 1154 | @brief register data registration event. |
| 1155 | @param[in] cb_func Data registration indication callback function |
| 1156 | @return Whether the data registration event was successfully registered. |
| 1157 | @retval QL_ERR_OK successful |
| 1158 | @retval QL_ERR_NOT_INIT uninitialized |
| 1159 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1160 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1161 | @retval Other error code defined by ql_type.h |
| 1162 | */ |
| 1163 | /*-----------------------------------------------------------------------------------------------*/ |
| 1164 | int ql_nw_set_data_reg_ind_cb(ql_nw_data_reg_ind_cb cb_func) |
| 1165 | { |
| 1166 | UNUSED(cb_func); |
| 1167 | if(NULL == nw_handle) |
| 1168 | { |
| 1169 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1170 | return QL_ERR_NOT_INIT; |
| 1171 | } |
| 1172 | |
| 1173 | return QL_ERR_OK; |
| 1174 | } |
| 1175 | |
| 1176 | /*-----------------------------------------------------------------------------------------------*/ |
| 1177 | /** |
| 1178 | @brief register signal strength event. |
| 1179 | @param[in] cb_func Signal strength indication callback function |
| 1180 | @return Whether the signal strength event was successfully registered |
| 1181 | @retval QL_ERR_OK successful |
| 1182 | @retval QL_ERR_NOT_INIT uninitialized |
| 1183 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1184 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1185 | @retval Other error code defined by ql_type.h |
| 1186 | */ |
| 1187 | /*-----------------------------------------------------------------------------------------------*/ |
| 1188 | int ql_nw_set_signal_strength_ind_cb(ql_nw_signal_strength_ind_cb cb_func) |
| 1189 | { |
| 1190 | if(NULL == nw_handle) |
| 1191 | { |
| 1192 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1193 | return QL_ERR_NOT_INIT; |
| 1194 | } |
| 1195 | |
| 1196 | int ret = QL_ERR_OK; |
| 1197 | if(NULL != cb_func) |
| 1198 | { |
| 1199 | ret = ql_cb_thread_creat(nw_handle); |
| 1200 | if(ret != QL_ERR_OK) |
| 1201 | { |
| 1202 | QL_NW_LOGE("[%s] cb thread creat fail.", __func__); |
| 1203 | } |
| 1204 | } |
| 1205 | else |
| 1206 | { |
| 1207 | ret = ql_cb_thread_free(nw_handle); |
| 1208 | if(ret != QL_ERR_OK) |
| 1209 | { |
| 1210 | QL_NW_LOGE("[%s] cb thread free deinit fail.", __func__); |
| 1211 | return QL_ERR_FAILED; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | nw_handle->signal_cb = cb_func; |
| 1216 | |
| 1217 | return QL_ERR_OK; |
| 1218 | } |
| 1219 | |
| 1220 | /*-----------------------------------------------------------------------------------------------*/ |
| 1221 | /** |
| 1222 | @brief register cell access status event. |
| 1223 | @param[in] cb_func Cell access status indication callback function |
| 1224 | @return Whether the cell access status event was successfully registered |
| 1225 | @retval QL_ERR_OK successful |
| 1226 | @retval QL_ERR_NOT_INIT uninitialized |
| 1227 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1228 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1229 | @retval Other error code defined by ql_type.h |
| 1230 | */ |
| 1231 | /*-----------------------------------------------------------------------------------------------*/ |
| 1232 | int ql_nw_set_cell_access_status_ind_cb(ql_nw_cell_access_status_ind_cb cb_func) |
| 1233 | { |
| 1234 | UNUSED(cb_func); |
| 1235 | if(NULL == nw_handle) |
| 1236 | { |
| 1237 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1238 | return QL_ERR_NOT_INIT; |
| 1239 | } |
| 1240 | |
| 1241 | return QL_ERR_OK; |
| 1242 | } |
| 1243 | |
| 1244 | /*-----------------------------------------------------------------------------------------------*/ |
| 1245 | /** |
| 1246 | @brief register network time event. |
| 1247 | @param[in] cb_func nitz time update indication callback function |
| 1248 | @return Whether the network time event was successfully registered |
| 1249 | @retval QL_ERR_OK successful |
| 1250 | @retval QL_ERR_NOT_INIT uninitialized |
| 1251 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1252 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1253 | @retval Other error code defined by ql_type.h |
| 1254 | */ |
| 1255 | /*-----------------------------------------------------------------------------------------------*/ |
| 1256 | int ql_nw_set_nitz_time_update_ind_cb(ql_nw_nitz_time_update_ind_cb cb_func) |
| 1257 | { |
| 1258 | UNUSED(cb_func); |
| 1259 | if(NULL == nw_handle) |
| 1260 | { |
| 1261 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1262 | return QL_ERR_NOT_INIT; |
| 1263 | } |
| 1264 | |
| 1265 | return QL_ERR_OK; |
| 1266 | } |
| 1267 | |
| 1268 | /*-----------------------------------------------------------------------------------------------*/ |
| 1269 | /** |
| 1270 | @brief register wea alert event. |
| 1271 | @param[in] cb_func wea alert indication callback function |
| 1272 | @return Whether the network time event was successfully registered |
| 1273 | @retval QL_ERR_OK successful |
| 1274 | @retval QL_ERR_NOT_INIT uninitialized |
| 1275 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1276 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1277 | @retval Other error code defined by ql_type.h |
| 1278 | */ |
| 1279 | /*-----------------------------------------------------------------------------------------------*/ |
| 1280 | int ql_nw_set_wea_alert_ind_cb(ql_nw_wea_reg_ind_cb cb_func) |
| 1281 | { |
| 1282 | UNUSED(cb_func); |
| 1283 | if(NULL == nw_handle) |
| 1284 | { |
| 1285 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1286 | return QL_ERR_NOT_INIT; |
| 1287 | } |
| 1288 | |
| 1289 | return QL_ERR_OK; |
| 1290 | } |
| 1291 | |
| 1292 | /*-----------------------------------------------------------------------------------------------*/ |
| 1293 | /** |
| 1294 | @brief register etws alert event. |
| 1295 | @param[in] cb_func etws alert indication callback function |
| 1296 | @return Whether the network time event was successfully registered |
| 1297 | @retval QL_ERR_OK successful |
| 1298 | @retval QL_ERR_NOT_INIT uninitialized |
| 1299 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1300 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1301 | @retval Other error code defined by ql_type.h |
| 1302 | */ |
| 1303 | /*-----------------------------------------------------------------------------------------------*/ |
| 1304 | int ql_nw_set_etws_alert_ind_cb(ql_nw_etws_reg_ind_cb cb_func) |
| 1305 | { |
| 1306 | UNUSED(cb_func); |
| 1307 | if(NULL == nw_handle) |
| 1308 | { |
| 1309 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1310 | return QL_ERR_NOT_INIT; |
| 1311 | } |
| 1312 | |
| 1313 | return QL_ERR_OK; |
| 1314 | } |
| 1315 | |
| 1316 | /*-----------------------------------------------------------------------------------------------*/ |
| 1317 | /** |
| 1318 | @brief set wea alert config. |
| 1319 | @param[in] item Items to set. |
| 1320 | @param[in] p_info Pointer that point to ql_nw_wea_config_t. |
| 1321 | @return Whether to successfully set the wea config. |
| 1322 | @retval QL_ERR_OK successful |
| 1323 | @retval QL_ERR_NOT_INIT uninitialized |
| 1324 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1325 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1326 | @retval Other error code defined by ql_type.h |
| 1327 | */ |
| 1328 | /*-----------------------------------------------------------------------------------------------*/ |
| 1329 | int ql_nw_set_wea_config(int item, ql_nw_wea_config_t *p_info) |
| 1330 | { |
| 1331 | UNUSED(p_info); |
| 1332 | if(NULL == nw_handle) |
| 1333 | { |
| 1334 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1335 | return QL_ERR_NOT_INIT; |
| 1336 | } |
| 1337 | |
| 1338 | return QL_ERR_OK; |
| 1339 | } |
| 1340 | |
| 1341 | /*-----------------------------------------------------------------------------------------------*/ |
| 1342 | /** |
| 1343 | @brief Gets wea config. |
| 1344 | @param[out] p_config wea config. |
| 1345 | @return Whether the wea config was successfully obtained. |
| 1346 | @retval QL_ERR_OK successful. |
| 1347 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 1348 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 1349 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 1350 | @retval Other error code defined by ql_type.h. |
| 1351 | */ |
| 1352 | /*-----------------------------------------------------------------------------------------------*/ |
| 1353 | int ql_nw_get_wea_config(ql_nw_wea_config_t *p_config) |
| 1354 | { |
| 1355 | UNUSED(p_config); |
| 1356 | if(NULL == nw_handle) |
| 1357 | { |
| 1358 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1359 | return QL_ERR_NOT_INIT; |
| 1360 | } |
| 1361 | |
| 1362 | return QL_ERR_OK; |
| 1363 | } |
| 1364 | |
| 1365 | /*-----------------------------------------------------------------------------------------------*/ |
| 1366 | /** |
| 1367 | @brief set etws alert config. |
| 1368 | @param[in] etws config. |
| 1369 | @return Whether to successfully set the etws config. |
| 1370 | @retval QL_ERR_OK successful |
| 1371 | @retval QL_ERR_NOT_INIT uninitialized |
| 1372 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1373 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1374 | @retval Other error code defined by ql_type.h |
| 1375 | */ |
| 1376 | /*-----------------------------------------------------------------------------------------------*/ |
| 1377 | int ql_nw_set_etws_config(uint8_t enable_etws) |
| 1378 | { |
| 1379 | UNUSED(enable_etws); |
| 1380 | if(NULL == nw_handle) |
| 1381 | { |
| 1382 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1383 | return QL_ERR_NOT_INIT; |
| 1384 | } |
| 1385 | |
| 1386 | return QL_ERR_OK; |
| 1387 | } |
| 1388 | |
| 1389 | /*-----------------------------------------------------------------------------------------------*/ |
| 1390 | /** |
| 1391 | @brief get etws alert config. |
| 1392 | @param[out] p_enable_etws Pointer. |
| 1393 | @return Whether to successfully set the etws config. |
| 1394 | @retval QL_ERR_OK successful |
| 1395 | @retval QL_ERR_NOT_INIT uninitialized |
| 1396 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1397 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1398 | @retval Other error code defined by ql_type.h |
| 1399 | */ |
| 1400 | /*-----------------------------------------------------------------------------------------------*/ |
| 1401 | int ql_nw_get_etws_config(uint8_t* p_enable_etws) |
| 1402 | { |
| 1403 | UNUSED(p_enable_etws); |
| 1404 | if(NULL == nw_handle) |
| 1405 | { |
| 1406 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1407 | return QL_ERR_NOT_INIT; |
| 1408 | } |
| 1409 | |
| 1410 | return QL_ERR_OK; |
| 1411 | } |
| 1412 | |
| 1413 | /*-----------------------------------------------------------------------------------------------*/ |
| 1414 | /** |
| 1415 | @brief bind subscription |
| 1416 | @param[in] sub_type subscription type |
| 1417 | @return Whether to successfully bind subscription. |
| 1418 | @retval QL_ERR_OK successful |
| 1419 | @retval QL_ERR_NOT_INIT uninitialized |
| 1420 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1421 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1422 | @retval Other error code defined by ql_type.h |
| 1423 | */ |
| 1424 | /*-----------------------------------------------------------------------------------------------*/ |
| 1425 | int ql_nw_bind_subscription(QL_NW_BIND_SUB_TYPE_E sub_type) |
| 1426 | { |
| 1427 | UNUSED(sub_type); |
| 1428 | if(NULL == nw_handle) |
| 1429 | { |
| 1430 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1431 | return QL_ERR_NOT_INIT; |
| 1432 | } |
| 1433 | |
| 1434 | return QL_ERR_OK; |
| 1435 | } |
| 1436 | |
| 1437 | /*-----------------------------------------------------------------------------------------------*/ |
| 1438 | /** |
| 1439 | @brief get high capability subscription. |
| 1440 | @param[out] p_high_cap pointer that point to QL_NW_BIND_SUB_TYPE_E |
| 1441 | @return Whether the high capability subscription was successfully obtained. |
| 1442 | @retval QL_ERR_OK successful |
| 1443 | @retval QL_ERR_NOT_INIT uninitialized |
| 1444 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1445 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1446 | @retval Other error code defined by ql_type.h |
| 1447 | */ |
| 1448 | /*-----------------------------------------------------------------------------------------------*/ |
| 1449 | int ql_nw_get_high_cap_sub(QL_NW_BIND_SUB_TYPE_E *p_high_cap) |
| 1450 | { |
| 1451 | UNUSED(p_high_cap); |
| 1452 | if(NULL == nw_handle) |
| 1453 | { |
| 1454 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1455 | return QL_ERR_NOT_INIT; |
| 1456 | } |
| 1457 | |
| 1458 | return QL_ERR_OK; |
| 1459 | } |
| 1460 | |
| 1461 | /*-----------------------------------------------------------------------------------------------*/ |
| 1462 | /** |
| 1463 | @brief set the SIM card index that can uniquely register to the 5G network. |
| 1464 | the main difference between high and non-high capability subscription is that high capability |
| 1465 | subscription can register to 5G network while non-high capability subscription can only |
| 1466 | register to LTE or GSM. |
| 1467 | @param[in] high_cap high capability subscription |
| 1468 | @return Whether to successfully set the high capability subscription. |
| 1469 | @retval QL_ERR_OK successful |
| 1470 | @retval QL_ERR_NOT_INIT uninitialized |
| 1471 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1472 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1473 | @retval Other error code defined by ql_type.h |
| 1474 | */ |
| 1475 | /*-----------------------------------------------------------------------------------------------*/ |
| 1476 | int ql_nw_set_high_cap_sub(QL_NW_BIND_SUB_TYPE_E high_cap) |
| 1477 | { |
| 1478 | UNUSED(high_cap); |
| 1479 | if(NULL == nw_handle) |
| 1480 | { |
| 1481 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1482 | return QL_ERR_NOT_INIT; |
| 1483 | } |
| 1484 | |
| 1485 | return QL_ERR_OK; |
| 1486 | } |
| 1487 | |
| 1488 | /*-----------------------------------------------------------------------------------------------*/ |
| 1489 | /** |
| 1490 | @brief Disable NR5G, NR5G_SA and NR5G_NSA can be disabled individually or together. |
| 1491 | @param[in] opt_mask Option mask value. Value: |
| 1492 | 0 - Do not disable NR5G |
| 1493 | QL_NW_NR5G_SO_SA - Disable NR5G SA |
| 1494 | QL_NW_NR5G_SO_NSA - Disable NR5G NSA |
| 1495 | @return Whether to successfully disable NR5G mode. |
| 1496 | @retval QL_ERR_OK successful |
| 1497 | @retval QL_ERR_NOT_INIT uninitialized |
| 1498 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 1499 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 1500 | @retval Other error code defined by ql_type.h |
| 1501 | */ |
| 1502 | /*-----------------------------------------------------------------------------------------------*/ |
| 1503 | int ql_nw_disable_nr5g(uint16_t opt_mask) |
| 1504 | { |
| 1505 | UNUSED(opt_mask); |
| 1506 | if(NULL == nw_handle) |
| 1507 | { |
| 1508 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1509 | return QL_ERR_NOT_INIT; |
| 1510 | } |
| 1511 | |
| 1512 | return QL_ERR_OK; |
| 1513 | } |
| 1514 | |
| 1515 | /*-----------------------------------------------------------------------------------------------*/ |
| 1516 | /** |
| 1517 | @brief Registration server error callback. Currently, only if the server exits abnormally, |
| 1518 | the callback function will be executed, and the error code is QL_ERR_ABORTED; |
| 1519 | @param[in] cb Callback function |
| 1520 | @return |
| 1521 | QL_ERR_OK - successful |
| 1522 | Other - error code defined by ql_type.h |
| 1523 | */ |
| 1524 | /*-----------------------------------------------------------------------------------------------*/ |
| 1525 | int ql_nw_set_service_error_cb(ql_nw_service_error_cb_f cb) |
| 1526 | { |
| 1527 | if(NULL == nw_handle) |
| 1528 | { |
| 1529 | QL_NW_LOGE("[%s] nw handle not init.", __func__); |
| 1530 | return QL_ERR_NOT_INIT; |
| 1531 | } |
| 1532 | |
| 1533 | nw_handle->server_cb = cb; |
| 1534 | |
| 1535 | return QL_ERR_OK; |
| 1536 | } |
| 1537 | |
| 1538 | |