b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 1 | /*-----------------------------------------------------------------------------------------------*/ |
| 2 | /** |
| 3 | @file ql_dm.h |
| 4 | @brief device management API |
| 5 | */ |
| 6 | /*-----------------------------------------------------------------------------------------------*/ |
| 7 | |
| 8 | /*------------------------------------------------------------------------------------------------- |
| 9 | Copyright (c) 2019 Quectel Wireless Solution, Co., Ltd. All Rights Reserved. |
| 10 | Quectel 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 | 20200316 stan.li Optimize the ql_dm_get_modem_state interface |
| 21 | 20191224 stan.li Add radio on/off API |
| 22 | 20190625 stan.li Created . |
| 23 | -------------------------------------------------------------------------------------------------*/ |
| 24 | |
| 25 | |
| 26 | #ifdef __cplusplus |
| 27 | extern "C" { |
| 28 | #endif |
| 29 | |
| 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <stdbool.h> |
| 33 | #include <pthread.h> |
| 34 | |
| 35 | #include "mbtk_ril_api.h" |
| 36 | #include "ql_type.h" |
| 37 | #include "ql_dm.h" |
| 38 | |
| 39 | |
| 40 | |
| 41 | #define LYNQ_AIR_PLANE_MODE_ON 4 //at+cfun = 4 |
| 42 | #define LYNQ_AIR_PLANE_MODE_OFF 1 // at+cfun = 1 |
| 43 | |
| 44 | |
b.liu | b17525e | 2025-05-14 17:22:29 +0800 | [diff] [blame] | 45 | |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 46 | #define MBTK_RILD_ERR -1 |
| 47 | #define IMEI_VALID 1 |
| 48 | |
| 49 | static mbtk_ril_handle* ql_info_handle = NULL; |
| 50 | static mbtk_ril_handle* g_md_version_handle = NULL; |
| 51 | |
| 52 | static ql_dm_air_plane_mode_ind_cb g_air_plane_mode_cb = NULL; |
| 53 | static ql_dm_service_error_cb_f global_dm_error_cb = NULL; |
| 54 | static ql_dm_modem_state_ind_cb global_dm_modem_cb = NULL; |
| 55 | |
| 56 | |
| 57 | static pthread_t g_air_plane_mode_thread; |
| 58 | static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 59 | static pthread_cond_t g_cond = PTHREAD_COND_INITIALIZER; |
| 60 | static bool g_thread_running = false; |
| 61 | |
| 62 | |
| 63 | static void mbtk_send_singnal() |
| 64 | { |
| 65 | pthread_mutex_lock(&g_mutex); |
| 66 | pthread_cond_signal(&g_cond); |
| 67 | pthread_mutex_unlock(&g_mutex); |
| 68 | |
| 69 | } |
| 70 | |
| 71 | static void mbtk_dm_set_service_error_func(const void* data,int data_len) |
| 72 | { |
| 73 | if(data !=NULL && data_len == sizeof(int)) |
| 74 | { |
| 75 | const int *state = (const int*)(data); |
| 76 | if(*state) |
| 77 | { |
| 78 | if(global_dm_error_cb) |
| 79 | { |
| 80 | global_dm_error_cb(MBTK_RILD_ERR); |
| 81 | } |
| 82 | |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | } |
| 87 | |
| 88 | static void mbtk_modem_state_change_cb(const void* data, int data_len) |
| 89 | { |
| 90 | uint8 *ptr = (uint8*)data; |
| 91 | if(global_dm_modem_cb) |
| 92 | { |
| 93 | global_dm_modem_cb(*ptr); |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | |
| 98 | void* air_plane_mode_monitor(void* arg) |
| 99 | { |
| 100 | int ql_info = 0; |
| 101 | int ret = -1; |
| 102 | mbtk_radio_state_enum mbtk_info; |
| 103 | |
| 104 | while (g_thread_running) |
| 105 | { |
| 106 | pthread_mutex_lock(&g_mutex); |
| 107 | pthread_cond_wait(&g_cond, &g_mutex); |
| 108 | ret = mbtk_radio_state_get(ql_info_handle, &mbtk_info); |
| 109 | if (ret != 0) |
| 110 | { |
| 111 | LOGE("mbtk_radio_state_get fail."); |
| 112 | return NULL; |
| 113 | } |
| 114 | |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 115 | if(mbtk_info == MBTK_RADIO_STATE_FULL_FUNC) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 116 | { |
| 117 | ql_info = QL_DM_AIR_PLANE_MODE_OFF; |
| 118 | } |
| 119 | |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 120 | if(mbtk_info == MBTK_RADIO_STATE_DIS_RF) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 121 | { |
| 122 | ql_info = QL_DM_AIR_PLANE_MODE_ON; |
| 123 | } |
| 124 | |
b.liu | b17525e | 2025-05-14 17:22:29 +0800 | [diff] [blame] | 125 | if(mbtk_info != MBTK_RADIO_STATE_FULL_FUNC && mbtk_info !=MBTK_RADIO_STATE_DIS_RF) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 126 | { |
| 127 | |
| 128 | ql_info = QL_DM_AIR_PLANE_MODE_UNKNOWN; |
| 129 | } |
| 130 | |
| 131 | if(g_air_plane_mode_cb) |
| 132 | { |
| 133 | |
| 134 | g_air_plane_mode_cb(ql_info); |
| 135 | } |
| 136 | |
| 137 | pthread_mutex_unlock(&g_mutex); |
| 138 | } |
| 139 | |
| 140 | return NULL; |
| 141 | } |
| 142 | |
| 143 | /*-----------------------------------------------------------------------------------------------*/ |
| 144 | /** |
| 145 | @brief Initialize DM service. |
| 146 | @note You must call this function before other functions can be used in this module. |
| 147 | @return Whether the DM service was successfully intialized. |
| 148 | @retval QL_ERR_OK successful. |
| 149 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 150 | @retval Other error code defined by ql_type.h. |
| 151 | */ |
| 152 | /*-----------------------------------------------------------------------------------------------*/ |
| 153 | |
| 154 | int ql_dm_init(void) |
| 155 | { |
| 156 | |
| 157 | if(ql_info_handle == NULL) |
| 158 | { |
| 159 | |
| 160 | mbtk_log_init("syslog", "QL_DM"); |
| 161 | |
| 162 | ql_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF); |
| 163 | if(ql_info_handle) |
| 164 | { |
| 165 | |
| 166 | return QL_ERR_OK; |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | LOGE("mbtk_info_handle_get() fail."); |
| 171 | return QL_ERR_FAILED; |
| 172 | } |
| 173 | |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | LOGE("No need init again"); |
| 178 | return QL_ERR_FAILED; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /*-----------------------------------------------------------------------------------------------*/ |
| 183 | /** |
| 184 | @brief Denitialize DM service. |
| 185 | @return Whether the DM service was successfully deintialized. |
| 186 | @retval QL_ERR_OK successful. |
| 187 | @retval Other error code defined by ql_type.h. |
| 188 | */ |
| 189 | /*-----------------------------------------------------------------------------------------------*/ |
| 190 | int ql_dm_deinit(void) |
| 191 | { |
| 192 | if(ql_info_handle) |
| 193 | { |
| 194 | |
| 195 | int ret = mbtk_ril_close(MBTK_AT_PORT_DEF); |
| 196 | if(ret != 0) |
| 197 | { |
| 198 | LOGE("mbtk_info_handle_free fail."); |
| 199 | return QL_ERR_FAILED; |
| 200 | } |
| 201 | else |
| 202 | { |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 203 | ql_info_handle = NULL; |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 204 | LOGI("mbtk_info_handle_free success"); |
| 205 | return QL_ERR_OK; |
| 206 | } |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | LOGE("DM not inited."); |
| 211 | return QL_ERR_NOT_INIT; |
| 212 | } |
| 213 | |
| 214 | } |
| 215 | |
| 216 | /*-----------------------------------------------------------------------------------------------*/ |
| 217 | /** |
| 218 | @brief get device software version. |
| 219 | @param[out] soft_ver Return software version |
| 220 | @param[in] soft_ver_len The length of soft_ver |
| 221 | @return Whether to successfully get the software version |
| 222 | @retval QL_ERR_OK successful |
| 223 | @retval QL_ERR_NOT_INIT uninitialized |
| 224 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 225 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 226 | @retval Other error code defined by ql_type.h |
| 227 | */ |
| 228 | /*-----------------------------------------------------------------------------------------------*/ |
| 229 | |
| 230 | int ql_dm_get_software_version(char *soft_ver, int soft_ver_len) |
| 231 | { |
| 232 | |
| 233 | int ret = -1; |
| 234 | if(soft_ver == NULL || soft_ver_len <= 0) |
| 235 | { |
| 236 | LOGE("Bad parameters "); |
| 237 | return QL_ERR_FAILED; |
| 238 | } |
| 239 | if(ql_info_handle != NULL) |
| 240 | { |
| 241 | |
| 242 | ret = mbtk_version_get(ql_info_handle,soft_ver); |
| 243 | if(ret != 0) |
| 244 | { |
| 245 | LOGE("ql_dm_get_software_version error."); |
| 246 | return QL_ERR_FAILED; |
| 247 | } |
| 248 | } |
| 249 | else |
| 250 | { |
| 251 | mbtk_ril_handle* mbtk_info_handle = NULL; |
| 252 | mbtk_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF); |
| 253 | if(mbtk_info_handle == NULL) |
| 254 | { |
| 255 | LOGE("mbtk_info_handle_get fail."); |
| 256 | return QL_ERR_FAILED; |
| 257 | } |
| 258 | ret = mbtk_version_get(mbtk_info_handle,soft_ver); |
| 259 | if(ret != 0) |
| 260 | { |
| 261 | LOGE("ql_dm_get_software_version error."); |
| 262 | |
| 263 | } |
| 264 | ret = mbtk_ril_close(MBTK_AT_PORT_DEF); |
| 265 | if(ret != 0) |
| 266 | { |
| 267 | LOGE("mbtk_info_handle_free fail."); |
| 268 | return QL_ERR_FAILED; |
| 269 | } |
| 270 | |
| 271 | } |
| 272 | return QL_ERR_OK; |
| 273 | |
| 274 | |
| 275 | } |
| 276 | |
| 277 | /*-----------------------------------------------------------------------------------------------*/ |
| 278 | /** |
| 279 | @brief get modem state. |
| 280 | @details QL_DM_MODEM_STATE_ONLINE,if modem starts normally. |
| 281 | @details QL_DM_MODEM_STATE_OFFLINE,in modem starts abnormally. |
| 282 | @details QL_DM_MODEM_STATE_UNKNOWN,unknown error. |
| 283 | @param[out] modem_state The state of modem |
| 284 | @return Whether to successfully get the modem state |
| 285 | @retval QL_ERR_OK successful |
| 286 | @retval QL_ERR_NOT_INIT uninitialized |
| 287 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 288 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 289 | @retval Other error code defined by ql_type.h |
| 290 | */ |
| 291 | /*-----------------------------------------------------------------------------------------------*/ |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 292 | int ql_dm_get_modem_state(QL_DM_MODEM_STATE_TYPE_E *modem_state) |
| 293 | { |
b.liu | b17525e | 2025-05-14 17:22:29 +0800 | [diff] [blame] | 294 | int ret = -1; |
| 295 | mbtk_radio_state_enum tmp_rf; |
| 296 | if(ql_info_handle == NULL) |
| 297 | { |
| 298 | LOGE("DM no init"); |
| 299 | return QL_ERR_NOT_INIT; |
| 300 | } |
| 301 | ret = mbtk_radio_state_get(ql_info_handle, &tmp_rf); |
| 302 | if (ret != 0) |
| 303 | { |
| 304 | LOGE("mbtk_radio_state_get fail."); |
| 305 | return QL_ERR_FAILED; |
| 306 | } |
| 307 | |
| 308 | if(tmp_rf == 0 ) |
| 309 | { |
| 310 | *modem_state = QL_DM_MODEM_STATE_OFFLINE; |
| 311 | } |
| 312 | else if(tmp_rf == 1) |
| 313 | { |
| 314 | *modem_state = QL_DM_MODEM_STATE_ONLINE; |
| 315 | } |
| 316 | else |
| 317 | { |
| 318 | *modem_state = QL_DM_MODEM_STATE_UNKNOWN; |
| 319 | } |
| 320 | |
| 321 | return QL_ERR_OK; |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 322 | |
| 323 | } |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 324 | |
| 325 | /*-----------------------------------------------------------------------------------------------*/ |
| 326 | /** |
| 327 | @brief register modem state event. |
| 328 | @param[in] cb_func modem state indication callback function |
| 329 | @return Whether the modem state event was successfully registered. |
| 330 | @retval QL_ERR_OK successful |
| 331 | @retval QL_ERR_NOT_INIT uninitialized |
| 332 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 333 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 334 | @retval Other error code defined by ql_type.h |
| 335 | */ |
| 336 | /*-----------------------------------------------------------------------------------------------*/ |
| 337 | |
| 338 | int ql_dm_set_modem_state_change_ind_cb(ql_dm_modem_state_ind_cb cb_func) |
| 339 | { |
| 340 | |
| 341 | int ret =-1; |
| 342 | |
| 343 | global_dm_modem_cb = cb_func; |
| 344 | |
| 345 | if(ql_info_handle != NULL) |
| 346 | { |
| 347 | |
| 348 | ret = mbtk_radio_state_change_cb_reg(mbtk_modem_state_change_cb); |
| 349 | if(ret != 0) |
| 350 | { |
| 351 | LOGE("call mbtk_radio_state_change_cb_reg failed"); |
| 352 | return QL_ERR_FAILED; |
| 353 | } |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | if(g_md_version_handle == NULL) |
| 358 | { |
| 359 | g_md_version_handle = mbtk_ril_open(MBTK_AT_PORT_DEF); |
| 360 | if(g_md_version_handle == NULL) |
| 361 | { |
| 362 | LOGE("g_md_version_handle get fail."); |
| 363 | return QL_ERR_FAILED; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | ret = mbtk_radio_state_change_cb_reg(mbtk_modem_state_change_cb); |
| 368 | if(ret != 0) |
| 369 | { |
| 370 | |
| 371 | ret = mbtk_ril_close(MBTK_AT_PORT_DEF); |
| 372 | if(ret < 0) |
| 373 | { |
| 374 | LOGE("mbtk_info_handle_free fail."); |
| 375 | return QL_ERR_FAILED; |
| 376 | } |
| 377 | |
| 378 | LOGE("call mbtk_radio_state_change_cb_reg failed"); |
| 379 | return QL_ERR_FAILED; |
| 380 | } |
| 381 | |
| 382 | } |
| 383 | |
| 384 | return QL_ERR_OK; |
| 385 | } |
| 386 | |
| 387 | /*-----------------------------------------------------------------------------------------------*/ |
| 388 | /** |
| 389 | @brief get module temperature. |
| 390 | @param[out] temperature The current temperature |
| 391 | @return Whether to successfully get the temperature |
| 392 | @retval QL_ERR_OK successful |
| 393 | @retval QL_ERR_NOT_INIT uninitialized |
| 394 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 395 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 396 | @retval Other error code defined by ql_type.h |
| 397 | */ |
| 398 | /*-----------------------------------------------------------------------------------------------*/ |
| 399 | int ql_dm_get_temperature(float *temperature); |
| 400 | |
| 401 | |
| 402 | /*-----------------------------------------------------------------------------------------------*/ |
| 403 | /** |
| 404 | @brief get device serial numbers. |
| 405 | @param[out] p_info Pointer that point to ql_dm_device_serial_numbers_info_t |
| 406 | @return Whether to successfully get the serial numbers |
| 407 | @retval QL_ERR_OK successful |
| 408 | @retval QL_ERR_NOT_INIT uninitialized |
| 409 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 410 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 411 | @retval Other error code defined by ql_type.h |
| 412 | */ |
| 413 | /*-----------------------------------------------------------------------------------------------*/ |
| 414 | int ql_dm_get_device_serial_numbers(ql_dm_device_serial_numbers_info_t *p_info) |
| 415 | { |
| 416 | int ret = -1; |
| 417 | if(ql_info_handle == NULL ) |
| 418 | { |
| 419 | LOGE("DM no init"); |
| 420 | return QL_ERR_NOT_INIT; |
| 421 | } |
| 422 | |
| 423 | ret = mbtk_imei_get(ql_info_handle, p_info->imei); |
| 424 | if(ret != 0) |
| 425 | { |
| 426 | LOGE("Error : %d\n", ret); |
| 427 | return QL_ERR_FAILED; |
| 428 | } |
| 429 | if(strlen(p_info->imei) > 0) |
| 430 | { |
| 431 | p_info->imei_valid = IMEI_VALID; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | return QL_ERR_OK; |
| 436 | |
| 437 | } |
| 438 | |
| 439 | /*-----------------------------------------------------------------------------------------------*/ |
| 440 | /** |
| 441 | @brief get device firmware revision identification. |
| 442 | @param[out] firmware_rev_id Return device firmware revision id |
| 443 | @param[in] firmware_rev_id_len The length of firmware_rev_id |
| 444 | @return Whether to successfully get the firmware revision id |
| 445 | @retval QL_ERR_OK successful |
| 446 | @retval QL_ERR_NOT_INIT uninitialized |
| 447 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 448 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 449 | @retval Other error code defined by ql_type.h |
| 450 | */ |
| 451 | /*-----------------------------------------------------------------------------------------------*/ |
| 452 | int ql_dm_get_device_firmware_rev_id(char *firmware_rev_id, int firmware_rev_id_len) |
| 453 | { |
| 454 | int ret = -1; |
| 455 | |
| 456 | if(ql_info_handle == NULL) |
| 457 | { |
| 458 | LOGE("DM no init"); |
| 459 | return QL_ERR_NOT_INIT; |
| 460 | } |
| 461 | |
l.yang | 15056cf | 2025-05-13 03:20:32 -0700 | [diff] [blame] | 462 | ret = mbtk_get_modem_version(ql_info_handle, (void *)firmware_rev_id); |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 463 | //mbtk_v2 do not have function |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 464 | if(ret < 0) |
| 465 | { |
| 466 | LOGE("get modem version failed"); |
| 467 | return QL_ERR_FAILED; |
| 468 | } |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | /*-----------------------------------------------------------------------------------------------*/ |
| 473 | /** |
| 474 | @brief get air plane mode. |
| 475 | @param[out] p_info Pointer that point to QL_DM_AIR_PLANE_MODE_TYPE_E |
| 476 | @return Whether to successfully get the air plane mode |
| 477 | @retval QL_ERR_OK successful |
| 478 | @retval QL_ERR_NOT_INIT uninitialized |
| 479 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 480 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 481 | @retval Other error code defined by ql_type.h |
| 482 | */ |
| 483 | /*-----------------------------------------------------------------------------------------------*/ |
| 484 | int ql_dm_get_air_plane_mode(QL_DM_AIR_PLANE_MODE_TYPE_E *p_info) |
| 485 | { |
| 486 | |
| 487 | int ret = -1; |
| 488 | mbtk_radio_state_enum tmp_rf; |
| 489 | if(ql_info_handle == NULL) |
| 490 | { |
| 491 | LOGE("DM no init"); |
| 492 | return QL_ERR_NOT_INIT; |
| 493 | } |
| 494 | ret = mbtk_radio_state_get(ql_info_handle, &tmp_rf); |
| 495 | if (ret != 0) |
| 496 | { |
| 497 | LOGE("mbtk_radio_state_get fail."); |
| 498 | return QL_ERR_FAILED; |
| 499 | } |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 500 | if(tmp_rf == MBTK_RADIO_STATE_FULL_FUNC ) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 501 | { |
| 502 | *p_info = QL_DM_AIR_PLANE_MODE_OFF; |
| 503 | } |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 504 | else if(tmp_rf == MBTK_RADIO_STATE_DIS_RF || tmp_rf == MBTK_RADIO_STATE_MINI_FUNC) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 505 | { |
| 506 | *p_info = QL_DM_AIR_PLANE_MODE_ON; |
| 507 | } |
| 508 | |
| 509 | return 0; |
| 510 | |
| 511 | } |
| 512 | |
| 513 | /*-----------------------------------------------------------------------------------------------*/ |
| 514 | /** |
| 515 | @brief set air plane mode. |
| 516 | @param[in] air_plane_mode 1:ON, 2:OFF |
| 517 | @return Whether to successfully set the air plane mode |
| 518 | @retval QL_ERR_OK successful |
| 519 | @retval QL_ERR_NOT_INIT uninitialized |
| 520 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 521 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 522 | @retval Other error code defined by ql_type.h |
| 523 | */ |
| 524 | /*-----------------------------------------------------------------------------------------------*/ |
| 525 | |
| 526 | |
| 527 | int ql_dm_set_air_plane_mode(QL_DM_AIR_PLANE_MODE_TYPE_E air_plane_mode) |
| 528 | { |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 529 | //mbtk_radio_state_enum radio = MBTK_RADIO_STATE_MINI_FUNC; |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 530 | int reset = 0; |
| 531 | int rf_mode = -1; |
| 532 | int ret = -1; |
| 533 | |
| 534 | if(ql_info_handle == NULL) |
| 535 | { |
| 536 | LOGE("DM no init"); |
| 537 | return QL_ERR_NOT_INIT; |
| 538 | } |
| 539 | if(air_plane_mode == QL_DM_AIR_PLANE_MODE_ON) |
| 540 | { |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 541 | rf_mode = MBTK_RADIO_STATE_DIS_RF; |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | if(air_plane_mode == QL_DM_AIR_PLANE_MODE_OFF) |
| 545 | { |
| 546 | rf_mode = LYNQ_AIR_PLANE_MODE_OFF; |
| 547 | |
| 548 | } |
| 549 | |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 550 | if (rf_mode != MBTK_RADIO_STATE_DIS_RF && rf_mode != MBTK_RADIO_STATE_FULL_FUNC) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 551 | { |
| 552 | LOGE("Input mode is error!"); |
| 553 | return QL_ERR_OP_UNSUPPORTED; |
| 554 | } |
| 555 | |
| 556 | |
l.yang | 860a8e7 | 2025-05-13 01:55:38 -0700 | [diff] [blame] | 557 | ret = mbtk_radio_state_set(ql_info_handle, rf_mode, reset); |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 558 | if(ret != 0) |
| 559 | { |
| 560 | LOGE("ql_dm_set_air_plane_mode failed"); |
| 561 | } |
| 562 | mbtk_send_singnal(); |
| 563 | return QL_ERR_OK; |
| 564 | |
| 565 | |
| 566 | } |
| 567 | /*-----------------------------------------------------------------------------------------------*/ |
| 568 | /** |
| 569 | @brief register air plane mode event. |
| 570 | @param[in] cb_func Air plane mode indication callback function |
| 571 | @return Whether the air plane mode event was successfully registered. |
| 572 | @retval QL_ERR_OK successful |
| 573 | @retval QL_ERR_NOT_INIT uninitialized |
| 574 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 575 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 576 | @retval Other error code defined by ql_type.h |
| 577 | */ |
| 578 | /*-----------------------------------------------------------------------------------------------*/ |
| 579 | |
| 580 | int ql_dm_set_air_plane_mode_ind_cb(ql_dm_air_plane_mode_ind_cb cb_func) |
| 581 | { |
| 582 | if(ql_info_handle == NULL) |
| 583 | { |
| 584 | LOGE("No init "); |
| 585 | return QL_ERR_NOT_INIT; |
| 586 | } |
| 587 | |
| 588 | g_air_plane_mode_cb = cb_func; |
| 589 | |
| 590 | if (!g_thread_running) |
| 591 | { |
| 592 | g_thread_running = true; |
| 593 | if (pthread_create(&g_air_plane_mode_thread, NULL, air_plane_mode_monitor, NULL) != 0) |
| 594 | { |
| 595 | LOGE("Failed to create air plane mode monitor thread"); |
| 596 | g_thread_running = false; |
| 597 | return QL_ERR_FAILED; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | return QL_ERR_OK; |
| 602 | } |
| 603 | |
| 604 | |
| 605 | /*-----------------------------------------------------------------------------------------------*/ |
| 606 | /** |
| 607 | @brief get cpu occupancy. |
| 608 | @param[out] cpu_occupancy The percentage of cpu occupancy |
| 609 | @return Whether to successfully get the cpu occupancy |
| 610 | @retval QL_ERR_OK successful |
| 611 | @retval QL_ERR_NOT_INIT uninitialized |
| 612 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 613 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 614 | @retval Other error code defined by ql_type.h |
| 615 | */ |
| 616 | /*-----------------------------------------------------------------------------------------------*/ |
| 617 | int ql_dm_get_cpu_occupancy(float *cpu_occupancy); |
| 618 | |
| 619 | |
| 620 | /*-----------------------------------------------------------------------------------------------*/ |
| 621 | /** |
| 622 | @brief get mem usage. |
| 623 | @param[out] mem_use The percentage of mem usage |
| 624 | @return Whether to successfully get the memory usage |
| 625 | @retval QL_ERR_OK successful |
| 626 | @retval QL_ERR_NOT_INIT uninitialized |
| 627 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 628 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 629 | @retval Other error code defined by ql_type.h |
| 630 | */ |
| 631 | /*-----------------------------------------------------------------------------------------------*/ |
| 632 | int ql_dm_get_mem_usage(float *mem_use); |
| 633 | |
| 634 | |
| 635 | /*-----------------------------------------------------------------------------------------------*/ |
| 636 | /** |
| 637 | @brief get NV item value. |
| 638 | @param[in] nv_item_name The NV item name that is either NV item id or NV item path |
| 639 | @param[out] nv_item_value The NV value buf of nv_item_name |
| 640 | param[in] nv_item_value_len The length of nv_item_value |
| 641 | param[out] nv_len The real length of nv_item_name |
| 642 | @return Whether to successfully get the NV value |
| 643 | @retval QL_ERR_OK successful |
| 644 | @retval QL_ERR_NOT_INIT uninitialized |
| 645 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 646 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 647 | @retval Other error code defined by ql_type.h |
| 648 | */ |
| 649 | /*-----------------------------------------------------------------------------------------------*/ |
| 650 | int ql_dm_get_nv_item_value(char *nv_item_name, unsigned char *nv_item_value, int nv_item_value_len, |
| 651 | int *nv_len); |
| 652 | |
| 653 | /*-----------------------------------------------------------------------------------------------*/ |
| 654 | /** |
| 655 | @brief set NV item value. |
| 656 | @param[in] nv_item_name The NV item name that is either NV item id or NV item path |
| 657 | @param[in] nv_item_value The NV value of nv_item_name |
| 658 | @param[in] nv_item_value_len The length of nv_item_value |
| 659 | param[out] nv_len The real length of nv_item_name |
| 660 | @return Whether to successfully set the NV value |
| 661 | @retval QL_ERR_OK successful |
| 662 | @retval QL_ERR_NOT_INIT uninitialized |
| 663 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 664 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 665 | @retval Other error code defined by ql_type.h |
| 666 | */ |
| 667 | /*-----------------------------------------------------------------------------------------------*/ |
| 668 | int ql_dm_set_nv_item_value(char *nv_item_name, unsigned char *nv_item_value, int nv_item_value_len, |
| 669 | int *nv_len); |
| 670 | |
| 671 | |
| 672 | /*-----------------------------------------------------------------------------------------------*/ |
| 673 | /** |
| 674 | @brief set radio on, its function is the same as at+cfun=1. |
| 675 | @return Whether to successfully set the radio on |
| 676 | @retval QL_ERR_OK successful |
| 677 | @retval QL_ERR_NOT_INIT uninitialized |
| 678 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 679 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 680 | @retval Other error code defined by ql_type.h |
| 681 | */ |
| 682 | /*-----------------------------------------------------------------------------------------------*/ |
| 683 | int ql_dm_set_radio_on(void); |
| 684 | |
| 685 | /*-----------------------------------------------------------------------------------------------*/ |
| 686 | /** |
| 687 | @brief set radio off, its function is the same as at+cfun=0. |
| 688 | @return Whether to successfully set the radio off |
| 689 | @retval QL_ERR_OK successful |
| 690 | @retval QL_ERR_NOT_INIT uninitialized |
| 691 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 692 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 693 | @retval Other error code defined by ql_type.h |
| 694 | */ |
| 695 | /*-----------------------------------------------------------------------------------------------*/ |
| 696 | int ql_dm_set_radio_off(void); |
| 697 | |
| 698 | /*-----------------------------------------------------------------------------------------------*/ |
| 699 | /** |
| 700 | @brief get modem mem and CPU utilization. |
| 701 | @param[out] mem_use The percentage of modem utilization |
| 702 | @return Whether to successfully get the modem utilization |
| 703 | @retval QL_ERR_OK successful |
| 704 | @retval QL_ERR_NOT_INIT uninitialized |
| 705 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 706 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 707 | @retval Other error code defined by ql_type.h |
| 708 | */ |
| 709 | /*-----------------------------------------------------------------------------------------------*/ |
| 710 | int ql_dm_get_modem_cpu_occupancy(float *cpu_occupancy); |
| 711 | |
| 712 | /*-----------------------------------------------------------------------------------------------*/ |
| 713 | /** |
| 714 | @brief get modem mem utilization. |
| 715 | @param[out] mem_use The percentage of modem utilization |
| 716 | @return Whether to successfully get the modem utilization |
| 717 | @retval QL_ERR_OK successful |
| 718 | @retval QL_ERR_NOT_INIT uninitialized |
| 719 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 720 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 721 | @retval Other error code defined by ql_type.h |
| 722 | */ |
| 723 | /*-----------------------------------------------------------------------------------------------*/ |
| 724 | int ql_dm_get_modem_mem_usage(float *mem_use); |
| 725 | |
| 726 | /*-----------------------------------------------------------------------------------------------*/ |
| 727 | /** |
| 728 | @brief get QOOS enable state |
| 729 | @param[out] enable The enable state of QOOS |
| 730 | @return Whether to successfully get the QOOS enable state |
| 731 | @retval QL_ERR_OK successful |
| 732 | @retval QL_ERR_NOT_INIT uninitialized |
| 733 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 734 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 735 | @retval Other error code defined by ql_type.h |
| 736 | */ |
| 737 | /*-----------------------------------------------------------------------------------------------*/ |
| 738 | int ql_dm_get_qoos_enable(char *enable); |
| 739 | |
| 740 | /*-----------------------------------------------------------------------------------------------*/ |
| 741 | /** |
| 742 | @brief set QOOS enable state |
| 743 | @param[in] enable The enable state of QOOS |
| 744 | @return Whether to successfully set the QOOS enable state |
| 745 | @retval QL_ERR_OK successful |
| 746 | @retval QL_ERR_NOT_INIT uninitialized |
| 747 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 748 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 749 | @retval Other error code defined by ql_type.h |
| 750 | */ |
| 751 | /*-----------------------------------------------------------------------------------------------*/ |
| 752 | int ql_dm_set_qoos_enable(char enable); |
| 753 | |
| 754 | /*-----------------------------------------------------------------------------------------------*/ |
| 755 | /** |
| 756 | @brief get QOOS configuration |
| 757 | @param[out] config The configuration of QOOS |
| 758 | @return Whether to successfully get the QOOS configuration |
| 759 | @retval QL_ERR_OK successful |
| 760 | @retval QL_ERR_NOT_INIT uninitialized |
| 761 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 762 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 763 | @retval Other error code defined by ql_type.h |
| 764 | */ |
| 765 | /*-----------------------------------------------------------------------------------------------*/ |
| 766 | //int ql_dm_get_qoos_config(ql_dm_qoos_config_t *config); |
| 767 | |
| 768 | /*-----------------------------------------------------------------------------------------------*/ |
| 769 | /** |
| 770 | @brief set QOOS configuration |
| 771 | @param[in] config The configuration of QOOS |
| 772 | @return Whether to successfully set the QOOS configuration |
| 773 | @retval QL_ERR_OK successful |
| 774 | @retval QL_ERR_NOT_INIT uninitialized |
| 775 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 776 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 777 | @retval Other error code defined by ql_type.h |
| 778 | */ |
| 779 | /*-----------------------------------------------------------------------------------------------*/ |
| 780 | //int ql_dm_set_qoos_config(ql_dm_qoos_config_t config); |
| 781 | |
| 782 | /*-----------------------------------------------------------------------------------------------*/ |
| 783 | /** |
| 784 | @brief get MSSR(Modem SubSysem Reset) level. |
| 785 | @param[out] p_level The MSSR level |
| 786 | @return Whether to successfully get the MSSR level |
| 787 | @retval QL_ERR_OK successful |
| 788 | @retval QL_ERR_NOT_INIT uninitialized |
| 789 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 790 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 791 | @retval Other error code defined by ql_type.h |
| 792 | */ |
| 793 | /*-----------------------------------------------------------------------------------------------*/ |
| 794 | int ql_dm_get_mssr_level(int *p_level); |
| 795 | |
| 796 | /*-----------------------------------------------------------------------------------------------*/ |
| 797 | /** |
| 798 | @brief set MSSR(Modem SubSysem Reset) level. |
| 799 | @param[in] level The MSSR level |
| 800 | @return Whether to successfully set the MSSR level |
| 801 | @retval QL_ERR_OK successful |
| 802 | @retval QL_ERR_NOT_INIT uninitialized |
| 803 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 804 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 805 | @retval Other error code defined by ql_type.h |
| 806 | */ |
| 807 | /*-----------------------------------------------------------------------------------------------*/ |
| 808 | int ql_dm_set_mssr_level(int level); |
| 809 | |
| 810 | |
| 811 | /*-----------------------------------------------------------------------------------------------*/ |
| 812 | /** |
| 813 | @brief bind subscription |
| 814 | @param[in] sub_type subscription type |
| 815 | @return Whether to successfully bind subscription. |
| 816 | @retval QL_ERR_OK successful |
| 817 | @retval QL_ERR_NOT_INIT uninitialized |
| 818 | @retval QL_ERR_SERVICE_NOT_READY service is not ready |
| 819 | @retval QL_ERR_INVALID_ARG Invalid arguments |
| 820 | @retval Other error code defined by ql_type.h |
| 821 | */ |
| 822 | /*-----------------------------------------------------------------------------------------------*/ |
| 823 | int ql_dm_bind_subscription(QL_DM_BIND_SUB_TYPE_E sub_type); |
| 824 | |
| 825 | /*-----------------------------------------------------------------------------------------------*/ |
| 826 | /** |
| 827 | @brief Registration server error callback. Currently, only if the server exits abnormally, |
| 828 | the callback function will be executed, and the error code is QL_ERR_ABORTED; |
| 829 | @param[in] cb Callback function |
| 830 | @return |
| 831 | QL_ERR_OK - successful |
| 832 | Other - error code defined by ql_type.h |
| 833 | */ |
| 834 | /*-----------------------------------------------------------------------------------------------*/ |
| 835 | int ql_dm_set_service_error_cb(ql_dm_service_error_cb_f cb) |
| 836 | { |
| 837 | int ret = -1; |
| 838 | if(ql_info_handle == NULL) |
| 839 | { |
| 840 | LOGE("DM no init "); |
| 841 | return QL_ERR_NOT_INIT; |
| 842 | |
| 843 | } |
| 844 | global_dm_error_cb = cb; |
| 845 | ret = mbtk_ril_ser_state_change_cb_reg(mbtk_dm_set_service_error_func); |
| 846 | if(ret != 0) |
| 847 | { |
| 848 | LOGE("call mbtk_ril_server_state_change_reg failed"); |
| 849 | return QL_ERR_FAILED; |
| 850 | } |
| 851 | |
| 852 | return QL_ERR_OK; |
| 853 | } |
| 854 | /*-----------------------------------------------------------------------------------------------*/ |
| 855 | /** |
| 856 | @brief Get module the last time shutdown reason |
| 857 | @param[out] shutdown_reason the shutdown reason |
| 858 | @return |
| 859 | QL_ERR_OK - successful |
| 860 | Other - error code defined by ql_type.h |
| 861 | */ |
| 862 | /*-----------------------------------------------------------------------------------------------*/ |
| 863 | int ql_dm_get_shutdown_reason(QL_DM_SHUTDOWN_REASON_E *shutdown_reason); |
| 864 | |
| 865 | /*-----------------------------------------------------------------------------------------------*/ |
| 866 | /** |
| 867 | @brief Get module this time bootup reason |
| 868 | @param[out] bootup_reason the bootup reason |
| 869 | @return |
| 870 | QL_ERR_OK - successful |
| 871 | Other - error code defined by ql_type.h |
| 872 | */ |
| 873 | /*-----------------------------------------------------------------------------------------------*/ |
| 874 | int ql_dm_get_bootup_reason(QL_DM_BOOT_UP_REASON_E *bootup_reason); |
| 875 | |
| 876 | /*-----------------------------------------------------------------------------------------------*/ |
| 877 | /** |
| 878 | @brief set oos config |
| 879 | @param[out] oos param |
| 880 | @return |
| 881 | QL_ERR_OK - successful |
| 882 | Other - error code defined by ql_type.h |
| 883 | */ |
| 884 | /*-----------------------------------------------------------------------------------------------*/ |
| 885 | int ql_dm_set_qoos_config(int p1, int p2, int p3); |
| 886 | |
| 887 | |
| 888 | /*-----------------------------------------------------------------------------------------------*/ |
| 889 | /** |
| 890 | @brief get oos config |
| 891 | @param[out] oos param |
| 892 | @return |
| 893 | QL_ERR_OK - successful |
| 894 | Other - error code defined by ql_type.h |
| 895 | */ |
| 896 | /*-----------------------------------------------------------------------------------------------*/ |
| 897 | int ql_dm_get_qoos_config(int *p1, int *p2, int *p3); |
| 898 | |
| 899 | /*-----------------------------------------------------------------------------------------------*/ |
| 900 | /** |
| 901 | @brief set oos enable |
| 902 | @param[out] oos param |
| 903 | @return |
| 904 | QL_ERR_OK - successful |
| 905 | Other - error code defined by ql_type.h |
| 906 | */ |
| 907 | /*-----------------------------------------------------------------------------------------------*/ |
| 908 | int ql_dm_set_qoos_enable(char enable); |
| 909 | #ifdef __cplusplus |
| 910 | } |
| 911 | #endif |
| 912 | |
| 913 | |
| 914 | |