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