blob: 7824fe8448e13628029e9918cea3f83fc31ee8b6 [file] [log] [blame]
hong.liud2417072025-06-27 07:10:37 -07001#include <stdbool.h>
b.liu68a94c92025-05-24 12:53:41 +08002#include <dlfcn.h>
3#include <time.h>
4#include <pthread.h>
hong.liud2417072025-06-27 07:10:37 -07005#include "gsw_nw_interface.h"
q.huang934ec0e2025-07-22 19:56:59 +08006#include "gsw_log_interface.h"
7
cz.lif4a9a932025-06-05 11:37:59 +08008#define SIG_TIMER 5
q.huang66b79162025-06-27 17:45:34 +08009#define MODEM_TIMER 5
q.huang934ec0e2025-07-22 19:56:59 +080010#define SERVING_TIMER 5
11
q.huang66b79162025-06-27 17:45:34 +080012
b.liu68a94c92025-05-24 12:53:41 +080013//mbtk include
14#define LYNQ_AIR_PLANE_MODE_OFF 1 //at+cfun = 1
15#define LYNQ_AIR_PLANE_MODE_ON 4 // at+cfun = 4
16#define LYNQ_AIR_CFUN_MODE_OFF 0 // at+cfun = 0
17
18#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
19
20#define FPLMN_STRING_LENGTH 120
21#define ENTRY_LENGTH 6
22#define FPLMN_ARRAY_SIZE (FPLMN_STRING_LENGTH / 6) + 1
23
q.huang238b22a2025-06-10 14:36:59 +080024#define MBTK_ERR_OK 0
xf.li56b78fb2025-06-13 03:29:21 -070025#define GSW_IMEI_LENGTH 15+1
q.huang238b22a2025-06-10 14:36:59 +080026
q.huangfa0a0a32025-06-12 17:07:23 +080027#define INT_32_MAX (0x7FFFFFFF)
q.huang2dbc0bc2025-08-06 10:36:24 +080028#define INVALID_AT_SIGNAL_LEVEL (99)
q.huangfa0a0a32025-06-12 17:07:23 +080029
q.huang238b22a2025-06-10 14:36:59 +080030
b.liu68a94c92025-05-24 12:53:41 +080031#ifndef FALSE
32#define FALSE (0)
33#endif
34
35
36#ifndef TRUE
37#define TRUE (!FALSE)
38#endif
39
40typedef unsigned int uint32;
41typedef unsigned char uint8;
q.huang861c07d2025-06-24 16:54:58 +080042typedef signed char int8;
b.liu68a94c92025-05-24 12:53:41 +080043typedef unsigned short uint16;
44typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
45
q.huangdaa16d42025-07-03 14:32:48 +080046//#define MBTK_READY_UCI "persist.mbtk.sdk.state"
rx.xieaad2b6f2025-08-01 00:55:33 -070047#define SDK_READY_CMD "uci get lynq_uci.sdk_ready"
q.huang66b79162025-06-27 17:45:34 +080048#define MBTK_READY_STRING_SIZE_MAX (3+1)
49
50
51typedef enum{
52 MBTK_READY_INIT = -1,
53 MBTK_READY_SUCCESS,
54 MBTK_READY_MODEM_FAIL,
55 MBTK_READY_RESPONSE_FAIL,
56 MBTK_READY_SOCKET_FAIL,
57 MBTK_READY_RIL_FAIL
58}mbtk_ready_status_type;
59
b.liu68a94c92025-05-24 12:53:41 +080060typedef enum
61{
62 MBTK_DEV_MODEM_MIN_FUN, //Modem 最小功能
63 MBTK_DEV_MODEM_FULL_FUN, //Modem 全功能
64 MBTK_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS = 3, //Modem 禁用射频接收电路
65 MBTK_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS, //Modem禁用射频发射和接收电路
66 MBTK_DEV_MODEM_DISABLE_SIM, //Modem 禁用(U)SIM 卡
67 MBTK_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE, //Modem 完全禁用辅助接收
68}MBTK_DEV_MODEM_FUNCTION;
69
70typedef enum
71{
72 MBTK_CELL_TYPE_GSM = 0,
73 MBTK_CELL_TYPE_UMTS,
74 MBTK_CELL_TYPE_LTE
75} mbtk_cell_type_enum;
76
77typedef struct
78{
79 MBTK_DEV_MODEM_FUNCTION fun;
80 int rst;
81} mbtk_modem_info_t;
82
83typedef struct
84{
85 int client_fd;
86 pthread_t read_thread_id;
87 int exit_fd[2];
88 bool is_waitting;
89 pthread_cond_t cond;
90 pthread_mutex_t mutex;
91
92 pthread_mutex_t send_mutex;
93
94 // Temp response data.
95 uint16 info_err;
96 uint16 data_len;
97 void *data;
98
99 //mbtk wyq for server_ready_status add start
100 char server_ready_status;
101 //mbtk wyq for server_ready_status add end
102
103 mbtk_info_callback_func net_state_cb;
104 mbtk_info_callback_func call_state_cb;
105 mbtk_info_callback_func sms_state_cb;
106 mbtk_info_callback_func radio_state_cb;
107 mbtk_info_callback_func sim_state_cb;
108 mbtk_info_callback_func pdp_state_cb;
109 //add signal by xr
110 mbtk_info_callback_func signal_state_cb;
111} mbtk_info_handle_t;
112
113
114
115typedef struct
116{
q.huang638d5872025-06-21 13:44:43 +0800117 // NR server cell:
118 // NR cell:
b.liu68a94c92025-05-24 12:53:41 +0800119 // LTE server cell: tac, PCI, dlEuarfcn, ulEuarfcn, band
120 // LTE cell: phyCellId,euArfcn,rsrp,rsrq
121 // WCDMA server cell: lac, ci, arfcn
122 // WCDMA cell: lac, ci, arfcn
123 // GSM server cell: lac, ci, arfcn, bsic
124 // GSM cell:
q.huang638d5872025-06-21 13:44:43 +0800125 uint32 value1; //tac
126 uint32 value2; //pci
127 uint32 value3; //dlEuarfcn
128 uint32 value4; //bler
129 uint32 value5; //band
130 uint32 value6; //mcc
131 uint32 value7; //mnc
132 uint32 value8; //rsrp
133 uint32 value9; //rsrq
134 uint32 value10; //cell identiy
135 uint32 value11; //sinr
136 uint32 value12; //is tdd
137 uint32 value13;
138 uint32 value14;
139 uint32 value15;
b.liu68a94c92025-05-24 12:53:41 +0800140} __attribute__((packed)) mbtk_cell_info_t;
141
b.liu68a94c92025-05-24 12:53:41 +0800142typedef struct
143{
144 uint8 net_pref; // mbtk_net_pref_enum
145 uint16 gsm_band; // mbtk_gsm_band_enum
146 uint16 umts_band; // mbtk_umts_band_enum
147 uint32 tdlte_band; // mbtk_tdlte_band_enum
148 uint32 fddlte_band; // mbtk_fddlte_band_enum
149 uint32 lte_ext_band; // mbtk_lte_ext_band_enum
150} __attribute__((packed)) mbtk_band_info_t;
151
152typedef struct list_arraynode
153{
154 void *data;
155 struct list_arraynode *next;
156} list_arraynode_t;
157
158typedef struct list_treenode
159{
160 list_arraynode_t *data;
161 int count;
162 struct list_treenode *left;
163 struct list_treenode *right;
164} list_treenode_t;
165
166typedef int (*list_sort_func)(void *data1, void *data2);
167typedef void (*list_free_func)(void *data);
168
169typedef struct list_node
170{
171 uint32 size;
172 list_sort_func sort_func;
173 list_free_func free_func;
174
175 uint32 cur_index;
176 list_arraynode_t *cur_array_data;
177
178 list_arraynode_t array_data;
179 list_treenode_t tree_data;
180} list_node_t;
181
182/*
1830: GSM
1841: GSM Compact
1852: UTRAN
1863: GSM w/EGPRS
1874: UTRAN w/HSDPA
1885: UTRAN w/HSUPA
1896: UTRAN w/HSDPA and HSUPA
1907: E-UTRAN
1918: UTRAN HSPA+
192*/
193typedef enum {
194 MBTK_RADIO_TECH_GSM = 0,
195 MBTK_RADIO_TECH_GSM_COMPACT,
196 MBTK_RADIO_TECH_UTRAN,
197 MBTK_RADIO_TECH_GSM_EGPRS,
198 MBTK_RADIO_TECH_UTRAN_HSDPA,
199 MBTK_RADIO_TECH_UTRAN_HSUPA,
200 MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA,
201 MBTK_RADIO_TECH_E_UTRAN, // LTE
202 MBTK_RADIO_TECH_UTRAN_HSPA
203} mbtk_radio_technology_enum;
204
205typedef struct
206{
207 /*
208 0: automatic
209 1: manual
210 */
211 uint8 net_sel_mode;
212 /*
213 0: GSM
214 1: GSM Compact
215 2: UTRAN
216 3: GSM w/EGPRS
217 4: UTRAN w/HSDPA
218 5: UTRAN w/HSUPA
219 6: UTRAN w/HSDPA and HSUPA
220 7: E-UTRAN
221 8: UTRAN HSPA+
222 0xFF: Unused
223 */
224 uint8 net_type;
225 //uint8 plmn[10]; // 46000
226 /*
227 0: unknown
228 1: available
229 2: current
230 3: forbidden
231 */
232 uint8 net_state;
233 uint32 plmn;
234} __attribute__((packed)) mbtk_net_info_t;
235
236
237typedef enum
238{
239 MBTK_NET_REG_STATE_NON = 0,
240 MBTK_NET_REG_STATE_HOME,
241 MBTK_NET_REG_STATE_SEARCHING,
242 MBTK_NET_REG_STATE_DENIED,
243 MBTK_NET_REG_STATE_UNKNOWN,
244 MBTK_NET_REG_STATE_ROAMING,
245 MBTK_NET_REG_STATE_SMS_ONLY,
246 MBTK_NET_REG_STATE_ROAMING_SMS,
247 MBTK_NET_REG_STATE_ATTACHED_EMERGENCY,
248 MBTK_NET_REG_STATE_CSFB_HOME,
249 MBTK_NET_REG_STATE_CSFB_ROAMING,
250 MBTK_NET_REG_STATE_EMERGENCY_ONLY
251} mbtk_net_reg_state_enum;
252
253typedef struct
254{
255 uint8 call_state;// mbtk_net_reg_state_enum
256 uint8 data_state;// mbtk_net_reg_state_enum
257 uint8 ims_state;// mbtk_net_reg_state_enum
258 uint8 type; // mbtk_radio_technology_enum
259 uint16 lac;
260 uint32 ci;
261} __attribute__((packed)) mbtk_net_reg_info_t;
262
263typedef struct
264{
265 uint8 type; // mbtk_radio_technology_enum
266 uint8 rssi; // 0: 113 dBm or less
267 // 1: 111 dBm
268 // 2��30: 109��53 dBm
269 // 31: 51 dBm or greater
270 // 99: not known or not detectable
271 uint8 rxlev;// 0:rssi < -110 dBm
272 // 1: -110 dBm �� rssi < -109 dBm
273 // 2: -109 dBm �� rssi < -108 dBm
274 // ......
275 // 61: -50 dBm �� rssi < -49 dBm
276 // 62: -49 dBm �� rssi < -48 dBm
277 // 63: -48 dBm �� rssi
278 // 99: not known or not detectable
279 uint8 ber; // 0...7 as RXQUAL values in the table in 3GPP TS 45.008 [20] subclause 8.2.4
280 // 99 not known or not detectable
281 uint8 rscp; // 0: rscp < -120 dBm
282 // 1: -120 dBm �� rscp < -119 dBm
283 // 2: -119 dBm �� rscp < -118 dBm
284 // ......
285 // 94: -27 dBm �� rscp < -26 dBm
286 // 95: -26 dBm �� rscp < -25 dBm
287 // 96: - 25 dBm �� rscp
288 // 255: not known or not detectable
289 uint8 ecno; // 0: Ec/Io < -24 dB
290 // 1: -24 dB �� Ec/Io < -23.5 dB
291 // 2: -23.5 dB �� Ec/Io < -23 dB
292 // ......
293 // 47: -1 dB �� Ec/Io < -0.5 dB
294 // 48: -0.5 dB �� Ec/Io < 0 dB
295 // 49: 0 dB �� Ec/Io
296 // 255: not known or not detectable
297 uint8 rsrq; // 0: rsrq < -19.5 dB
298 // 1: -19.5 dB �� rsrq < -19 dB
299 // 2: -19 dB �� rsrq < -18.5 dB
300 // ......
301 // 32: -4 dB �� rsrq < -3.5 dB
302 // 33: -3.5 dB �� rsrq < -3 dB
303 // 34: -3 dB �� rsrq
304 // 255: not known or not detectable
305 uint8 rsrp; // 0: rsrp < -140 dBm
306 // 1: -140 dBm �� rsrp < -139 dBm
307 // 2: -139 dBm �� rsrp < -138 dBm
308 // ......
309 // 95: -46 dBm �� rsrp < -45 dBm
310 // 96: -45 dBm �� rsrp < -44 dBm
311 // 97: -44 dBm �� rsrp
312 // 255: not known or not detectable
q.huang861c07d2025-06-24 16:54:58 +0800313 int8 sinr; //-20-35 dbm
b.liu68a94c92025-05-24 12:53:41 +0800314} __attribute__((packed)) mbtk_signal_info_t;
315
316typedef struct{
317 uint8_t mode;
318 uint32_t oosPhase[3]; //单位为秒
319} mbtk_oos_info;
320
321typedef struct
322{
323 /* Configuration parameters for MCM network full band network scan when OOS (out of service)*/
324 int t_min;
325 int t_step;
326 int t_max;
327}GSW_NW_OOS_CONFIG_INFO_T;
328
b.liu68a94c92025-05-24 12:53:41 +0800329#define lib_mbtk_path "/lib/libmbtk_lib.so"
330mbtk_info_handle_t* nw_info_handle = NULL;
331
q.huang638d5872025-06-21 13:44:43 +0800332static GSW_NW_ServingInfoHandlePtr serving_cb=NULL;
333static GSW_NW_SigInfoHandlePtr sig_cb=NULL;
334static GSW_NW_RejectCauseHandlePtr reject_cb=NULL;
335static GSW_NW_ModemStateHandlePtr modem_cb=NULL;
336static GSW_NW_AirplaneModeHandlePtr airplane_cb=NULL;
b.liu68a94c92025-05-24 12:53:41 +0800337
338static void *dlHandle_mbtk;
339int nw_init_flag = 0;
340int mode = -1;
341int fplmn_max_length = 0;
342
343gsw_nw_plmn_list_t gsw_nw_plmn_list;
344char fplmn_array[FPLMN_ARRAY_SIZE][7];
345int fplmn_index = 0;
346
347static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
348static int (*mbtk_info_handle_free)(mbtk_info_handle_t** handle);
349int (*mbtk_net_sel_mode_get)(mbtk_info_handle_t* handle, mbtk_net_info_t *net);
350int (*mbtk_net_reg_get)(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg);
351int (*mbtk_cell_get)(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list);
352int (*mbtk_get_modem_fun)(mbtk_info_handle_t* handle, int* fun);
353static int (*mbtk_set_modem_fun)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info);
354int (*mbtk_current_band_get)(mbtk_info_handle_t* handle, mbtk_band_info_t *band);
355int (*mbtk_current_band_set)(mbtk_info_handle_t* handle, const mbtk_band_info_t *band);
356int (*mbtk_net_signal_get)(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal);
357int (*mbtk_wakeup_state_set)(mbtk_info_handle_t* handle, uint32 wakeup_state);
358int (*mbtk_signal_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
359int (*mbtk_net_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
360int (*mbtk_fplmn_get)(mbtk_info_handle_t *handle, void *fplmn);
361int (*mbtk_fplmn_set)(mbtk_info_handle_t *handle, void *fplmn);
362int (*mbtk_radio_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
363int (*mbtk_oos_get)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);
364int (*mbtk_oos_set)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);
q.huang238b22a2025-06-10 14:36:59 +0800365int (*mbtk_imei_get)(mbtk_info_handle_t* handle, void *imei);
q.huangdaa16d42025-07-03 14:32:48 +0800366bool (*str_empty)(const void *str);
q.huang238b22a2025-06-10 14:36:59 +0800367
b.liu68a94c92025-05-24 12:53:41 +0800368
l.yang6a42e4d2025-05-28 01:04:20 -0700369#define GSW_NW "[HAL][GSW_NW]"
370
b.liu68a94c92025-05-24 12:53:41 +0800371typedef struct
372{
373 char *lynq_operator_l;
374 char *lynq_operator_s;
375 uint32 lynq_mcc_mnc;
376} lynq_operator_mcc_mnc_t;
377
378static lynq_operator_mcc_mnc_t lynq_operator_mcc_mnc[] =
379{
380 {"China Mobile","CMCC",46000},
381 {"China Unicom","CU",46001},
382 {"China Mobile","CMCC",46002},
383 {"China Telecom","CT",46003},
384 {"China Mobile","CMCC",46004},
385 {"China Telecom","CT",46005},
386 {"China Unicom","CU",46006},
387 {"China Mobile","CMCC",46007},
388 {"China Mobile","CMCC",46008},
389 {"China Unicom","CU",46009},
390 {"China Telecom","CT",46011}
391};
392
393
394//GSW include
395typedef enum prefer_mode
396{
397 GSW_PREFER_MODE_GSW = 1, /**<2G only*/
398 GSW_PREFER_MODE_WCDMA = 2, /**< 3G only*/
399 GSW_PREFER_MODE_WCDMA_GSM = 3, /**< 3G/2G*/
400 GSW_PREFER_MODE_LTE = 4, /**< 4G only*/
401 GSW_PREFER_MODE_NR5G = 5, /**< 5G only*/
402 GSW_PREFER_MODE_NR5G_LTE = 8, /**< 5G/4G*/
403 GSW_PREFER_MODE_LTE_WCDMA_GSM = 9, /**< 4G/3G/2G*/
404 GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM = 32, /**< 5G/4G/3G/2G*/
405} PREFER_MODE_E;
406
q.huang81905ea2025-07-25 20:19:41 +0800407#define NW_THEAD_NUM (3)
408
b.liu68a94c92025-05-24 12:53:41 +0800409static int mbtk_nw_api_import()
410{
411 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
412 if (dlHandle_mbtk == NULL)
413 {
xy.heb41615b2025-05-28 16:33:20 +0800414 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800415 }
q.huang934ec0e2025-07-22 19:56:59 +0800416
b.liu68a94c92025-05-24 12:53:41 +0800417 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
418 if (mbtk_info_handle_get == NULL)
419 {
q.huang934ec0e2025-07-22 19:56:59 +0800420 LOGE(GSW_NW,"mbtk_info_handle_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800421 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800422 }
423
424 mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free");
425 if (mbtk_info_handle_free == NULL)
426 {
q.huang934ec0e2025-07-22 19:56:59 +0800427 LOGE(GSW_NW,"mbtk_info_handle_free dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800428 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800429 }
430
431 mbtk_net_sel_mode_get = (int (*)(mbtk_info_handle_t* handle, mbtk_net_info_t *net))dlsym(dlHandle_mbtk, "mbtk_net_sel_mode_get");
432 if (mbtk_net_sel_mode_get == NULL)
433 {
q.huang934ec0e2025-07-22 19:56:59 +0800434 LOGE(GSW_NW,"mbtk_net_sel_mode_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800435 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800436 }
437
438 mbtk_net_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_net_reg_get");
439 if (mbtk_net_reg_get == NULL)
440 {
q.huang934ec0e2025-07-22 19:56:59 +0800441 LOGE(GSW_NW,"mbtk_net_reg_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800442 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800443 }
444
445 mbtk_get_modem_fun = (int (*)(mbtk_info_handle_t* handle, int* fun))dlsym(dlHandle_mbtk, "mbtk_get_modem_fun");
446 if (mbtk_get_modem_fun == NULL)
447 {
q.huang934ec0e2025-07-22 19:56:59 +0800448 LOGE(GSW_NW,"mbtk_get_modem_fun dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800449 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800450 }
451
452 mbtk_set_modem_fun = (int (*)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info))dlsym(dlHandle_mbtk, "mbtk_set_modem_fun");
453 if (mbtk_set_modem_fun == NULL)
454 {
q.huang934ec0e2025-07-22 19:56:59 +0800455 LOGE(GSW_NW,"mbtk_set_modem_fun dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800456 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800457 }
458
459 mbtk_current_band_get = (int (*)(mbtk_info_handle_t* handle, mbtk_band_info_t *band))dlsym(dlHandle_mbtk, "mbtk_current_band_get");
460 if (mbtk_current_band_get == NULL)
461 {
q.huang934ec0e2025-07-22 19:56:59 +0800462 LOGE(GSW_NW,"mbtk_current_band_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800463 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800464 }
465
466 mbtk_current_band_set = (int (*)(mbtk_info_handle_t* handle, const mbtk_band_info_t *band))dlsym(dlHandle_mbtk, "mbtk_current_band_set");
467 if (mbtk_current_band_set == NULL)
468 {
q.huang934ec0e2025-07-22 19:56:59 +0800469 LOGE(GSW_NW,"mbtk_current_band_set dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800470 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800471 }
472
473 mbtk_net_signal_get = (int (*)(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal))dlsym(dlHandle_mbtk, "mbtk_net_signal_get");
474 if (mbtk_net_signal_get == NULL)
475 {
q.huang934ec0e2025-07-22 19:56:59 +0800476 LOGE(GSW_NW,"mbtk_net_signal_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800477 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800478 }
479
480 mbtk_wakeup_state_set = (int (*)(mbtk_info_handle_t* handle, uint32 wakeup_state))dlsym(dlHandle_mbtk, "mbtk_wakeup_state_set");
481 if (mbtk_wakeup_state_set == NULL)
482 {
q.huang934ec0e2025-07-22 19:56:59 +0800483 LOGE(GSW_NW,"mbtk_wakeup_state_set dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800484 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800485 }
486
487 mbtk_cell_get = (int (*)(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list))dlsym(dlHandle_mbtk, "mbtk_cell_get");
488 if (mbtk_cell_get == NULL)
489 {
q.huang934ec0e2025-07-22 19:56:59 +0800490 LOGE(GSW_NW,"mbtk_cell_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800491 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800492 }
493
494 mbtk_signal_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_signal_state_change_cb_reg");
495 if (mbtk_signal_state_change_cb_reg == NULL)
496 {
q.huang934ec0e2025-07-22 19:56:59 +0800497 LOGE(GSW_NW,"mbtk_signal_state_change_cb_reg dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800498 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800499 }
500
501 mbtk_net_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_net_state_change_cb_reg");
502 if (mbtk_net_state_change_cb_reg == NULL)
503 {
q.huang934ec0e2025-07-22 19:56:59 +0800504 LOGE(GSW_NW,"mbtk_net_state_change_cb_reg dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800505 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800506 }
507
508 mbtk_fplmn_get = (int(*)(mbtk_info_handle_t *handle, void *fplmn))dlsym(dlHandle_mbtk, "mbtk_fplmn_get");
509 if (mbtk_fplmn_get == NULL)
510 {
q.huang934ec0e2025-07-22 19:56:59 +0800511 LOGE(GSW_NW,"mbtk_fplmn_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800512 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800513 }
514
515 mbtk_fplmn_set = (int(*)(mbtk_info_handle_t *handle, void *fplmn))dlsym(dlHandle_mbtk, "mbtk_fplmn_set");
516 if (mbtk_fplmn_set == NULL)
517 {
q.huang934ec0e2025-07-22 19:56:59 +0800518 LOGE(GSW_NW,"mbtk_fplmn_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800519 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800520 }
521
522 mbtk_radio_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_radio_state_change_cb_reg");
523 if (mbtk_radio_state_change_cb_reg == NULL)
524 {
q.huang934ec0e2025-07-22 19:56:59 +0800525 LOGE(GSW_NW,"mbtk_radio_state_change_cb_reg dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800526 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800527 }
528
529 mbtk_oos_get = (int (*)(mbtk_info_handle_t* handle, mbtk_oos_info *oos))dlsym(dlHandle_mbtk, "mbtk_oos_get");
530 if (mbtk_oos_get == NULL)
531 {
q.huang934ec0e2025-07-22 19:56:59 +0800532 LOGE(GSW_NW,"mbtk_oos_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800533 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800534 }
535
536 mbtk_oos_set = (int (*)(mbtk_info_handle_t* handle, mbtk_oos_info *oos))dlsym(dlHandle_mbtk, "mbtk_oos_set");
537 if (mbtk_oos_set == NULL)
538 {
q.huang934ec0e2025-07-22 19:56:59 +0800539 LOGE(GSW_NW,"mbtk_oos_set dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800540 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800541 }
q.huang238b22a2025-06-10 14:36:59 +0800542
543 mbtk_imei_get = (int (*)(mbtk_info_handle_t* handle, void *imei))dlsym(dlHandle_mbtk, "mbtk_imei_get");
544 if (mbtk_imei_get == NULL)
545 {
q.huang934ec0e2025-07-22 19:56:59 +0800546 LOGE(GSW_NW,"mbtk_imei_get dlsym fail\n");
q.huang238b22a2025-06-10 14:36:59 +0800547 return GSW_HAL_NORMAL_FAIL;
548 }
q.huangdaa16d42025-07-03 14:32:48 +0800549
550 str_empty = (bool (*)(const void *str))dlsym(dlHandle_mbtk, "str_empty");
551 if (str_empty == NULL)
552 {
q.huang934ec0e2025-07-22 19:56:59 +0800553 LOGE(GSW_NW,"str_empty dlsym fail\n");
q.huangdaa16d42025-07-03 14:32:48 +0800554 return GSW_HAL_NORMAL_FAIL;
555 }
b.liu68a94c92025-05-24 12:53:41 +0800556
557 return GSW_HAL_SUCCESS;
558}
559
560void list_first(list_node_t *list)
561{
562 if (list) {
563 list->cur_index = 0;
564 list->cur_array_data = list->array_data.next;
565 }
566}
567
568void* list_next(list_node_t *list)
569{
570 if (list) {
571 list_arraynode_t *node = list->cur_array_data;
572 if (node) {
q.huang934ec0e2025-07-22 19:56:59 +0800573 LOGE(GSW_NW,"node is not null\n");
b.liu68a94c92025-05-24 12:53:41 +0800574 list->cur_array_data = list->cur_array_data->next;
575 list->cur_index++;
576 return node->data;
577 } else {
q.huang934ec0e2025-07-22 19:56:59 +0800578 LOGE(GSW_NW,"node is null\n");
b.liu68a94c92025-05-24 12:53:41 +0800579 return NULL;
580 }
581 } else {
q.huang934ec0e2025-07-22 19:56:59 +0800582 LOGE(GSW_NW,"list is null\n");
b.liu68a94c92025-05-24 12:53:41 +0800583 return NULL;
584 }
585}
586
587void list_free(list_node_t *list)
588{
589 if (list) {
590 list_arraynode_t *node = &(list->array_data); // Head node
591 list_arraynode_t *node_temp = NULL;
592 while (node->next) {
593 node_temp = node->next;
594 node->next = node->next->next;
595
596 if (list->free_func) {
597 list->free_func(node_temp->data);
598 } else {
599 free(node_temp->data);
600 }
601 free(node_temp);
602 }
603 free(list);
604 }
605}
606
q.huang861c07d2025-06-24 16:54:58 +0800607#if 0
q.huang638d5872025-06-21 13:44:43 +0800608static int32_t gsm_rssi_convert_to_dBm(uint8 rssi)
609{
610 if(rssi <= 31)
611 {
612 return rssi * 2 - 113; //0 map -113
613 //31 map -51
614 }
615 else
616 {
617 return INT_32_MAX;
618 }
619}
q.huang861c07d2025-06-24 16:54:58 +0800620#endif
q.huang638d5872025-06-21 13:44:43 +0800621
q.huangfa0a0a32025-06-12 17:07:23 +0800622static int32_t rscp_convert_to_minus_dBm(uint8 rscp)
b.liu68a94c92025-05-24 12:53:41 +0800623{
q.huangfa0a0a32025-06-12 17:07:23 +0800624 if(rscp <= 96)
b.liu68a94c92025-05-24 12:53:41 +0800625 {
q.huangfa0a0a32025-06-12 17:07:23 +0800626 return 121-rscp; // 96 map 25
627 // 0 map -121, below -120
b.liu68a94c92025-05-24 12:53:41 +0800628 }
b.liu68a94c92025-05-24 12:53:41 +0800629 else
630 {
q.huangfa0a0a32025-06-12 17:07:23 +0800631 return INT_32_MAX;
b.liu68a94c92025-05-24 12:53:41 +0800632 }
633}
634
q.huangfa0a0a32025-06-12 17:07:23 +0800635static int32_t rsrp_convert_to_minus_dBm(uint8 rsrp)
b.liu68a94c92025-05-24 12:53:41 +0800636{
q.huangfa0a0a32025-06-12 17:07:23 +0800637 if(rsrp <= 97)
b.liu68a94c92025-05-24 12:53:41 +0800638 {
q.huangfa0a0a32025-06-12 17:07:23 +0800639 return 141-rsrp; // 97 map 44
640 // 0 map 141 below 140
b.liu68a94c92025-05-24 12:53:41 +0800641 }
642 else
643 {
q.huangfa0a0a32025-06-12 17:07:23 +0800644 return INT_32_MAX;
b.liu68a94c92025-05-24 12:53:41 +0800645 }
646}
647
q.huangfa0a0a32025-06-12 17:07:23 +0800648static int32_t rsrq_convert_to_minus_dB(uint8 rsrq)
b.liu68a94c92025-05-24 12:53:41 +0800649{
q.huangfa0a0a32025-06-12 17:07:23 +0800650 if(rsrq <= 34)
b.liu68a94c92025-05-24 12:53:41 +0800651 {
q.huangfa0a0a32025-06-12 17:07:23 +0800652 return (40-rsrq)/2; //=20-rsrq / 2;
653 // 34 map 3
654 // 0 map 20
b.liu68a94c92025-05-24 12:53:41 +0800655 }
656 else
657 {
q.huangfa0a0a32025-06-12 17:07:23 +0800658 return INT_32_MAX;
b.liu68a94c92025-05-24 12:53:41 +0800659 }
660}
661
q.huang861c07d2025-06-24 16:54:58 +0800662static int32_t sinr_convert_to_10_times_dB(int8 sinr)
q.huang638d5872025-06-21 13:44:43 +0800663{
664 if(sinr <=35 && sinr>=-20)
665 {
666 return sinr*10; //35 map 350 db
667 // -20 map -2000 db
668 }
669 else
670 {
671 return INT_32_MAX;
672 }
673}
674
q.huangfa0a0a32025-06-12 17:07:23 +0800675//int ecno; /**< Valid values are positive integers. This value is the actual Ec/Io multiplied
676// * by -10. Example: If the actual Ec/Io is -12.5 dB, then this response value
677// * will be 125.*/
678//uint8 ecno; // 0: Ec/Io < -24 dB
679 // 1: -24 dB �� Ec/Io < -23.5 dB
680 // 2: -23.5 dB �� Ec/Io < -23 dB
681 // ......
682 // 47: -1 dB �� Ec/Io < -0.5 dB
683 // 48: -0.5 dB �� Ec/Io < 0 dB
684 // 49: 0 dB �� Ec/Io
685 // 255: not known or not detectabl
686static int32_t ecno_convert_to_minus_10_times_dB(uint8 ecno)
b.liu68a94c92025-05-24 12:53:41 +0800687{
q.huangfa0a0a32025-06-12 17:07:23 +0800688 if(ecno <=49)
b.liu68a94c92025-05-24 12:53:41 +0800689 {
q.huangfa0a0a32025-06-12 17:07:23 +0800690 return 245-ecno*5; //49 map 0 db
691 // 1 map 240 db
692 // 0 map 245 below 240
b.liu68a94c92025-05-24 12:53:41 +0800693 }
q.huangfa0a0a32025-06-12 17:07:23 +0800694 else
b.liu68a94c92025-05-24 12:53:41 +0800695 {
q.huangfa0a0a32025-06-12 17:07:23 +0800696 return INT_32_MAX;
b.liu68a94c92025-05-24 12:53:41 +0800697 }
698}
699
b.liu68a94c92025-05-24 12:53:41 +0800700
b.liu68a94c92025-05-24 12:53:41 +0800701
q.huangfa0a0a32025-06-12 17:07:23 +0800702/* change realCsq to level */
703static int rscpToLevel(int rscp)
b.liu68a94c92025-05-24 12:53:41 +0800704{
q.huangfa0a0a32025-06-12 17:07:23 +0800705
706 if (rscp < -110) {
b.liu68a94c92025-05-24 12:53:41 +0800707 return 0;
q.huangfa0a0a32025-06-12 17:07:23 +0800708 } else if (rscp <= -95) {
709 return rscp+111; // to 16
710 } else if (rscp >=-93 && rscp <=-90) {
711 return rscp+110; // to 20
712 } else if (rscp >=-89 && rscp <=-59) {
713 return (rscp+152)/3; // =(rscp+89)/3+21 to 31
714 } else if (rscp ==- 94) { // Geely requirement, -94 map 16
715 return 16;
716 } else if(rscp <= -25) {
717 return 31;
b.liu68a94c92025-05-24 12:53:41 +0800718 }
q.huangfa0a0a32025-06-12 17:07:23 +0800719 return 99;
b.liu68a94c92025-05-24 12:53:41 +0800720}
721
q.huangfa0a0a32025-06-12 17:07:23 +0800722static int rsrpToLevel(int rsrp)
723{
724 if (rsrp < -130) {
725 return 0;
726 } else if (rsrp <= -118) {
727 return (rsrp+132)/2; // to 7
728 } else if (rsrp <=-109) {
729 return rsrp+125; // to 16
730 } else if (rsrp <=-103) {
731 return (rsrp+141)/2; // =(rsrp+109)/2+16 to 19
732 } else if (rsrp <=- 85) {
733 return (rsrp+160)/3; // =(rsrp+103)/3+19 to 25
734 } else if(rsrp <= -55) {
735 return (rsrp+210)/5; // =(rsrp+85)/5+25 to 31
736 } else if(rsrp <=-44)
737 {
738 return 31;
739 }
740 return 99;
741}
742
q.huang861c07d2025-06-24 16:54:58 +0800743//uint8 rssi; // 0: 113 dBm or less
744 // 1: 111 dBm
745 // 2��30: 109��53 dBm
746 // 31: 51 dBm or greater
747 // 99: not known or not detectable
748//uint8 rxlev;// 0:rssi < -110 dBm
749 // 1: -110 dBm �� rssi < -109 dBm
750 // 2: -109 dBm �� rssi < -108 dBm
751 // 60 ......
752 // 61: -50 dBm �� rssi < -49 dBm
753 // 62: -49 dBm �� rssi < -48 dBm
754 // 63: -48 dBm �� rssi
755 // 99: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +0800756
q.huang861c07d2025-06-24 16:54:58 +0800757/* change realCsq to level */
758static int rxlevToLevel(uint8 rxlev)
759{
760 if (rxlev <=60) {
761 return (rxlev+3)/2; // =(rxlev+1)/2+1,
762 // 0 map 1
763 // 1,2 map 2
764 // 59,60 map 31
765 }
766 else if(rxlev <=63)
767 {
768 return 31;
769 }
q.huang2dbc0bc2025-08-06 10:36:24 +0800770 return INVALID_AT_SIGNAL_LEVEL;
q.huang861c07d2025-06-24 16:54:58 +0800771}
b.liu68a94c92025-05-24 12:53:41 +0800772
773static int convert_reg_state(int reg_state_t)
774{
q.huang934ec0e2025-07-22 19:56:59 +0800775 LOGD(GSW_NW,"reg_state_t = %d\n",reg_state_t);
b.liu68a94c92025-05-24 12:53:41 +0800776 int reg_state = 0;
777
778 switch (reg_state_t)
779 {
780 case MBTK_NET_REG_STATE_NON:
781 {
782 reg_state = GSW_NETWORK_REG_NOT_REGISTERED;
783 break;
784 }
785 case MBTK_NET_REG_STATE_HOME:
786 {
787 reg_state = GSW_NETWORK_REG_REGISTERED;
788 break;
789 }
790 case MBTK_NET_REG_STATE_SEARCHING:
791 {
792 reg_state = GSW_NETWORK_REG_NOT_REGISTERED_SEARCHING;
793 break;
794 }
795 case MBTK_NET_REG_STATE_DENIED:
796 {
797 reg_state = GSW_NETWORK_REG_REGISTRATION_DENIED;
798 break;
799 }
800 case MBTK_NET_REG_STATE_UNKNOWN:
801 {
802 reg_state = GSW_NETWORK_REG_REGISTRATION_UNKNOWN;
803 break;
804 }
805 case MBTK_NET_REG_STATE_ROAMING:
806 {
807 reg_state = GSW_NETWORK_REG_REGISTRATION_ROAMING;
808 break;
809 }
810 case MBTK_NET_REG_STATE_SMS_ONLY:
811 case MBTK_NET_REG_STATE_ROAMING_SMS:
812 case MBTK_NET_REG_STATE_ATTACHED_EMERGENCY:
813 case MBTK_NET_REG_STATE_CSFB_HOME:
814 case MBTK_NET_REG_STATE_CSFB_ROAMING:
815 case MBTK_NET_REG_STATE_EMERGENCY_ONLY:
816 {
817 reg_state = GSW_NETWORK_REG_LIMITED_SERVICE;
818 break;
819 }
820 }
821
822 return reg_state;
823}
824
825
826static int convert_net_mode(int net_mode)
827{
q.huang934ec0e2025-07-22 19:56:59 +0800828 LOGD(GSW_NW,"net_mode = %d\n",net_mode);
b.liu68a94c92025-05-24 12:53:41 +0800829 switch(net_mode)
830 {
831 case MBTK_RADIO_TECH_GSM:
832 case MBTK_RADIO_TECH_GSM_COMPACT:
833 case MBTK_RADIO_TECH_GSM_EGPRS:
834 {
835 return GSW_NETWORK_RADIO_GSM;
836 }
837 case MBTK_RADIO_TECH_UTRAN:
838 case MBTK_RADIO_TECH_UTRAN_HSDPA:
839 case MBTK_RADIO_TECH_UTRAN_HSUPA:
840 case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
841 case MBTK_RADIO_TECH_UTRAN_HSPA:
842 {
843 return GSW_NETWORK_RADIO_UMTS;
844 }
845 case MBTK_RADIO_TECH_E_UTRAN:
846 {
847 return GSW_NETWORK_RADIO_LTE;
848 }
849
850 default:
851 {
852 return GSW_NETWORK_RADIO_NO_SVC;
853 }
854 }
855
856 return GSW_NETWORK_RADIO_NO_SVC;
857}
858
859static int convert_mbtk_net_config(int config)
860{
861 int net_pref = -1;
862
863 switch(config)
864 {
865 case GSW_PREFER_MODE_GSW:
866 {
867 net_pref = 0;
868 break;
869 }
870
871 case GSW_PREFER_MODE_WCDMA:
872 {
873 net_pref = 1;
874 break;
875 }
876
877 case GSW_PREFER_MODE_WCDMA_GSM:
878 {
879 net_pref = 2;
880 break;
881 }
882
883 case GSW_PREFER_MODE_LTE:
884 case GSW_PREFER_MODE_NR5G:
885 case GSW_PREFER_MODE_NR5G_LTE:
886 {
887 net_pref = 5;
888 break;
889 }
890
891 case GSW_PREFER_MODE_LTE_WCDMA_GSM:
892 case GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM:
893 {
894 net_pref = 15;
895 break;
896 }
897 }
898
899 return net_pref;
900}
901
902
903static int convert_gsw_net_config(int config)
904{
905 int net_config = -1;
q.huang934ec0e2025-07-22 19:56:59 +0800906 LOGD(GSW_NW,"config = %d\n",config);
b.liu68a94c92025-05-24 12:53:41 +0800907
908 switch (config)
909 {
910 case 0:
911 {
912 net_config = GSW_PREFER_MODE_GSW;
913 break;
914 }
915
916 case 1:
917 {
918 net_config = GSW_PREFER_MODE_WCDMA;
919 break;
920 }
921
922 case 2:
923 {
924 net_config = GSW_PREFER_MODE_WCDMA_GSM;
925 break;
926 }
927
928 case 5:
929 {
930 net_config = GSW_PREFER_MODE_LTE;
931 break;
932 }
933
934 case 15:
935 {
936 net_config = GSW_PREFER_MODE_LTE_WCDMA_GSM;
937 break;
938 }
939 }
940
941 return net_config;
942}
943
944//64F010 -> 46001 (64->46,F0->0,10->01)
945static void transform_fplmn_str_to_plmn(char *entry)
946{
947 if (strncmp(entry, "FFFFFF", ENTRY_LENGTH) == 0) {
948 return; //if FFFFFF,means invalid fplmn, do nothing
949 }
950
951 char temp = entry[0];
952 entry[0] = entry[1];
953 entry[1] = temp;
954
955 temp = entry[ENTRY_LENGTH - 2];
956 entry[ENTRY_LENGTH - 2] = entry[ENTRY_LENGTH - 1];
957 entry[ENTRY_LENGTH - 1] = temp;
958
959 memmove(entry + 2, entry + 3, ENTRY_LENGTH - 2);
960
q.huang934ec0e2025-07-22 19:56:59 +0800961 LOGE(GSW_NW,"after transform_fplmn_str_to_plmn: %s\n", entry);
b.liu68a94c92025-05-24 12:53:41 +0800962
963 //valid fplmn
964 fplmn_index++;
965}
966
967static void extract_mcc_mnc(char *entry, char *mcc, char *mnc)
968{
969 strncpy(mcc,entry,3);
970 mcc[3] = '\0';
971 strncpy(mnc,entry + 3,2);
972 mnc[2] = '\0';
973
q.huang934ec0e2025-07-22 19:56:59 +0800974 LOGE(GSW_NW,"entry = %s, mcc = %s, mnc = %s\n", entry, mcc, mnc);
b.liu68a94c92025-05-24 12:53:41 +0800975}
976
977
978static void update_fplmn_list(char *fplmn_str)
979{
q.huang934ec0e2025-07-22 19:56:59 +0800980 LOGE(GSW_NW,"fplmn_str = %s\n",fplmn_str);
b.liu68a94c92025-05-24 12:53:41 +0800981 char temp_fplmn_array[FPLMN_ARRAY_SIZE][7];
982 memset(fplmn_array, 0, sizeof(fplmn_array));
983 memset(temp_fplmn_array, 0, sizeof(temp_fplmn_array));
984 fplmn_index = 0;
985 int array_length = 0;
986
987 for (int i = 0; i < strlen(fplmn_str); i += 6) {
988
989 int length = (i + 6 < strlen(fplmn_str)) ? 6 : strlen(fplmn_str) - i;
990 strncpy(temp_fplmn_array[array_length], fplmn_str + i, length);
991 temp_fplmn_array[array_length][length] = '\0';
992 array_length++;
993 if (i + 6 >= strlen(fplmn_str)) {
994 break;
995 }
996 }
997
998 for (int i = 0; i < array_length; i++) {
q.huang934ec0e2025-07-22 19:56:59 +0800999 LOGE(GSW_NW,"array[%d] = %s\n", i, temp_fplmn_array[i]);
b.liu68a94c92025-05-24 12:53:41 +08001000 transform_fplmn_str_to_plmn(temp_fplmn_array[i]);
1001 strncpy(fplmn_array[i], temp_fplmn_array[i], ENTRY_LENGTH);
q.huang934ec0e2025-07-22 19:56:59 +08001002 LOGE(GSW_NW,"fplmn_array[%d] = %s\n", i, fplmn_array[i]);
b.liu68a94c92025-05-24 12:53:41 +08001003 }
1004
1005}
1006
1007static void format_plmn(char *result, char *plmn_entry)
1008{
1009 strncpy(result, plmn_entry, strlen(plmn_entry));
q.huang934ec0e2025-07-22 19:56:59 +08001010 LOGE(GSW_NW,"result = %s, numStr = %s\n",result, plmn_entry);
b.liu68a94c92025-05-24 12:53:41 +08001011
1012 if (strlen(result) >= 2) {
1013 char temp = result[0];
1014 result[0] = result[1];
1015 result[1] = temp;
1016 }
1017
q.huang934ec0e2025-07-22 19:56:59 +08001018 LOGE(GSW_NW,"1.result = %s\n",result);
b.liu68a94c92025-05-24 12:53:41 +08001019
1020 if (strlen(result) >= 3) {
1021 memmove(&result[3], &result[2], strlen(result) - 2 + 1);
1022 result[2] = 'F';
1023 }
1024
q.huang934ec0e2025-07-22 19:56:59 +08001025 LOGE(GSW_NW,"2.result = %s\n",result);
b.liu68a94c92025-05-24 12:53:41 +08001026
1027 if (strlen(result) >= 2) {
1028 char temp = result[strlen(result) - 1];
1029 result[strlen(result) - 1] = result[strlen(result) - 2];
1030 result[strlen(result) - 2] = temp;
1031 }
1032
q.huang934ec0e2025-07-22 19:56:59 +08001033 LOGE(GSW_NW,"3.result = %s\n",result);
b.liu68a94c92025-05-24 12:53:41 +08001034}
1035
1036
1037static void convert_plmn_to_fplmn_str(char *fplmn_str)
1038{
1039 char temp_fplmn_str[128] = {0};
1040 char temp[20]; // 临时存储单个格式化后的数字
1041 int index = 0;
1042
1043 for (int i = 0; i < fplmn_index; i++) {
1044 memset(temp, 0x0, sizeof(temp));
1045 format_plmn(temp, fplmn_array[i]);
1046 strcat(temp_fplmn_str, temp);
1047 index += strlen(temp);
1048 }
1049
1050 while(index < (6 * fplmn_max_length))
1051 {
1052 temp_fplmn_str[index++] = 'F';
1053 }
1054
1055 // 修剪或截断formattedNumbers,确保它不超过6 * fplmn_max_length个字符
1056 if (index > (6 * fplmn_max_length)) {
1057 temp_fplmn_str[(6 * fplmn_max_length)] = '\0';
1058 }
1059
q.huang934ec0e2025-07-22 19:56:59 +08001060 LOGE(GSW_NW,"%s\n", temp_fplmn_str);
b.liu68a94c92025-05-24 12:53:41 +08001061 strncpy(fplmn_str, temp_fplmn_str, strlen(temp_fplmn_str));
q.huang934ec0e2025-07-22 19:56:59 +08001062 LOGE(GSW_NW,"fplmn_str = %s\n", fplmn_str);
b.liu68a94c92025-05-24 12:53:41 +08001063}
1064
1065static int check_index(char *mcc, char *mnc)
1066{
1067 int i = 0;
1068
1069 for(i = 0; i < fplmn_index; i++)
1070 {
1071 if(strncmp(fplmn_array[i], mcc, 3) == 0 && strncmp(fplmn_array[i] + 3, mnc, 2) == 0)
1072 {
q.huang934ec0e2025-07-22 19:56:59 +08001073 LOGE(GSW_NW,"index = %d\n", i);
b.liu68a94c92025-05-24 12:53:41 +08001074 return i;
1075 }
1076 }
1077
q.huang934ec0e2025-07-22 19:56:59 +08001078 LOGE(GSW_NW,"not find\n");
b.liu68a94c92025-05-24 12:53:41 +08001079 return -1;
1080}
1081
1082static void remove_fplmn(int index)
1083{
1084 int write_index = 0;
1085 for (int i = 0; i < fplmn_index; i++) {
1086 if (i != index) {
1087 strncpy(fplmn_array[write_index++], fplmn_array[i], ENTRY_LENGTH);
1088 }
1089 }
1090 fplmn_index--;
1091}
1092
q.huangfa0a0a32025-06-12 17:07:23 +08001093static void convert_mbtk_sig_info_to_gsw_sig_info(const mbtk_signal_info_t* signal, signalStrength_t* sig_strength)
1094{
q.huang934ec0e2025-07-22 19:56:59 +08001095 LOGD(GSW_NW,"signal->type=%d", signal->type);
q.huangfa0a0a32025-06-12 17:07:23 +08001096 memset(sig_strength,0,sizeof (signalStrength_t));
1097 switch(signal->type)
1098 {
1099 case MBTK_RADIO_TECH_E_UTRAN:
1100 {
q.huang934ec0e2025-07-22 19:56:59 +08001101 LOGI(GSW_NW,"rsrp = %d",signal->rsrp);
q.huangfa0a0a32025-06-12 17:07:23 +08001102 sig_strength->lte_sig_valid = 1;
q.huangc8b93122025-06-17 17:46:05 +08001103 sig_strength->rsrp = rsrp_convert_to_minus_dBm(signal->rsrp);
1104 sig_strength->rsrq = rsrq_convert_to_minus_dB(signal->rsrq);
q.huang861c07d2025-06-24 16:54:58 +08001105 sig_strength->rssnr= sinr_convert_to_10_times_dB(signal->sinr);
q.huangfa0a0a32025-06-12 17:07:23 +08001106 break;
1107 }
1108 case MBTK_RADIO_TECH_UTRAN:
1109 case MBTK_RADIO_TECH_UTRAN_HSDPA:
1110 case MBTK_RADIO_TECH_UTRAN_HSUPA:
1111 case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
1112 case MBTK_RADIO_TECH_UTRAN_HSPA:
1113 {
q.huang934ec0e2025-07-22 19:56:59 +08001114 LOGI(GSW_NW,"rscp = %d",signal->rscp);
q.huangfa0a0a32025-06-12 17:07:23 +08001115 sig_strength->wcdma_sig_valid = 1;
1116 sig_strength->rscp = rscp_convert_to_minus_dBm(signal->rscp);
q.huang2dbc0bc2025-08-06 10:36:24 +08001117 sig_strength->ecno = ecno_convert_to_minus_10_times_dB(signal->ecno);
q.huangfa0a0a32025-06-12 17:07:23 +08001118 break;
1119 }
1120 case MBTK_RADIO_TECH_GSM:
1121 case MBTK_RADIO_TECH_GSM_COMPACT:
1122 case MBTK_RADIO_TECH_GSM_EGPRS:
1123 {
q.huang934ec0e2025-07-22 19:56:59 +08001124 LOGI(GSW_NW,"g rxlev = %d",signal->rxlev);
q.huangfa0a0a32025-06-12 17:07:23 +08001125 sig_strength->gw_sig_valid = 1;
q.huang2dbc0bc2025-08-06 10:36:24 +08001126 sig_strength->rssi = rxlevToLevel(signal->rxlev);
q.huangfa0a0a32025-06-12 17:07:23 +08001127 break;
1128 }
1129 default:
1130 {
q.huang934ec0e2025-07-22 19:56:59 +08001131 LOGE(GSW_NW,"[%s] unknown reg type.[%d]", __func__, signal->type);
q.huangfa0a0a32025-06-12 17:07:23 +08001132 }
1133 }
1134
1135}
1136
q.huang66b79162025-06-27 17:45:34 +08001137/*
q.huang934ec0e2025-07-22 19:56:59 +08001138typedef enum{
1139 MBTK_READY_INIT = -1,
1140 MBTK_READY_SUCCESS,
1141 MBTK_READY_MODEM_FAIL,
1142 MBTK_READY_RESPONSE_FAIL,
1143 MBTK_READY_SOCKET_FAIL,
1144 MBTK_READY_RIL_FAIL
q.huang66b79162025-06-27 17:45:34 +08001145}mbtk_ready_status_type;
1146
q.huang934ec0e2025-07-22 19:56:59 +08001147typedef enum gsw_hal_nw_mode_state_type
1148{
1149 GSW_MODEM_STATE_UNKNOWN = 0,
1150 GSW_MODEM_STATE_ONLINE,
1151 GSW_MODEM_STATE_OFFLINE,
1152 GSW_SDK_STATE_SERVICE_DOWN,
1153 GSW_SDK_STATE_SERVICE_UP,// service down->up 需要routectl 重启
1154 GSW_SDK_STATE_GPS_DOWN,
1155 GSW_SDK_STATE_GPS_UP,
q.huang66b79162025-06-27 17:45:34 +08001156} gsw_mode_state_e;
1157
1158*/
1159
q.huang66b79162025-06-27 17:45:34 +08001160
b.liu68a94c92025-05-24 12:53:41 +08001161static void gsw_serving_info_callback_thread()
1162{
q.huang934ec0e2025-07-22 19:56:59 +08001163 GSW_NW_SERVING_INFO serving_info;
1164 int ret = gsw_get_nwinfo(&serving_info);
b.liu68a94c92025-05-24 12:53:41 +08001165 if(ret != 0)
1166 {
q.huang934ec0e2025-07-22 19:56:59 +08001167 LOGE(GSW_NW,"cb gsw_get_nwinfo failed");
b.liu68a94c92025-05-24 12:53:41 +08001168 return;
1169 }
1170
q.huang934ec0e2025-07-22 19:56:59 +08001171 if(serving_cb!=NULL)
b.liu68a94c92025-05-24 12:53:41 +08001172 {
q.huang934ec0e2025-07-22 19:56:59 +08001173 LOGE(GSW_NW,"serving cb called");
1174 serving_cb(serving_info);
1175 }
1176 else
1177 {
1178 LOGE(GSW_NW,"serving cb is NULL");
b.liu68a94c92025-05-24 12:53:41 +08001179 }
1180}
1181
1182static void gsw_serving_info_callback(const void* data, int data_len)
q.huang934ec0e2025-07-22 19:56:59 +08001183{
1184 if (nw_init_flag == 0)
b.liu68a94c92025-05-24 12:53:41 +08001185 {
q.huang934ec0e2025-07-22 19:56:59 +08001186 printf("%s, nw not init\n",__func__);
b.liu68a94c92025-05-24 12:53:41 +08001187 return;
1188 }
q.huang934ec0e2025-07-22 19:56:59 +08001189
1190 pthread_t thread;
1191 int ret=pthread_create(&thread, NULL, (void*)gsw_serving_info_callback_thread, NULL);
1192 if(ret==0)
1193 {
1194 pthread_detach(thread);
1195 }
1196 else
1197 {
1198 LOGE(GSW_NW,"create thread fail, ret is %d",ret);
1199 }
b.liu68a94c92025-05-24 12:53:41 +08001200}
1201
q.huang934ec0e2025-07-22 19:56:59 +08001202
q.huangfa0a0a32025-06-12 17:07:23 +08001203/*typedef struct
q.huang934ec0e2025-07-22 19:56:59 +08001204{
q.huangfa0a0a32025-06-12 17:07:23 +080012050 mbtk_radio_technology_enum type : 8; // mbtk_radio_technology_enum
12061 uint8 rssi; // 0: 113 dBm or less
q.huang934ec0e2025-07-22 19:56:59 +08001207 // 1: 111 dBm
1208 // 2��30: 109��53 dBm
1209 // 31: 51 dBm or greater
1210 // 99: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +080012112 uint8 rxlev;// 0:rssi < -110 dBm
q.huang934ec0e2025-07-22 19:56:59 +08001212 // 1: -110 dBm �� rssi < -109 dBm
1213 // 2: -109 dBm �� rssi < -108 dBm
1214 // ......
1215 // 61: -50 dBm �� rssi < -49 dBm
1216 // 62: -49 dBm �� rssi < -48 dBm
1217 // 63: -48 dBm �� rssi
1218 // 99: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +080012193 uint8 ber; // 0...7 as RXQUAL values in the table in 3GPP TS 45.008 [20] subclause 8.2.4
q.huang934ec0e2025-07-22 19:56:59 +08001220 // 99 not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +080012214 uint8 rscp; // 0: rscp < -120 dBm
q.huang934ec0e2025-07-22 19:56:59 +08001222 // 1: -120 dBm �� rscp < -119 dBm
1223 // 2: -119 dBm �� rscp < -118 dBm
1224 // ......
1225 // 94: -27 dBm �� rscp < -26 dBm
1226 // 95: -26 dBm �� rscp < -25 dBm
1227 // 96: - 25 dBm �� rscp
1228 // 255: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +080012295 uint8 ecno; // 0: Ec/Io < -24 dB
q.huang934ec0e2025-07-22 19:56:59 +08001230 // 1: -24 dB �� Ec/Io < -23.5 dB
1231 // 2: -23.5 dB �� Ec/Io < -23 dB
1232 // ......
1233 // 47: -1 dB �� Ec/Io < -0.5 dB
1234 // 48: -0.5 dB �� Ec/Io < 0 dB
1235 // 49: 0 dB �� Ec/Io
1236 // 255: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +080012376 uint8 rsrq; // 0: rsrq < -19.5 dB
q.huang934ec0e2025-07-22 19:56:59 +08001238 // 1: -19.5 dB �� rsrq < -19 dB
1239 // 2: -19 dB �� rsrq < -18.5 dB
1240 // ......
1241 // 32: -4 dB �� rsrq < -3.5 dB
1242 // 33: -3.5 dB �� rsrq < -3 dB
1243 // 34: -3 dB �� rsrq
1244 // 255: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +080012457 uint8 rsrp; // 0: rsrp < -140 dBm
q.huang934ec0e2025-07-22 19:56:59 +08001246 // 1: -140 dBm �� rsrp < -139 dBm
1247 // 2: -139 dBm �� rsrp < -138 dBm
1248 // ......
1249 // 95: -46 dBm �� rsrp < -45 dBm
1250 // 96: -45 dBm �� rsrp < -44 dBm
1251 // 97: -44 dBm �� rsrp
1252 // 255: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +080012538 uint8 ss_rsrq; // 0: ss_rsrq < -43 dB
q.huang934ec0e2025-07-22 19:56:59 +08001254 // 1: -43 dB <= ss_rsrq < -42.5 dB
1255 // 2: -42.5 dB <= ss_rsrq < -42 dB
1256 // ......
1257 // 125: 19 dB <= ss_rsrq < 19.5 dB
1258 // 126: 19.5 dB <= ss_rsrq < 20 dB
1259 // 255: not known or not detectable
1260 uint8 ss_rsrp; // 0: ss_rsrp < -156 dBm
1261 // 1: -156 dBm <= ss_rsrp < -155 dBm
1262 // 2: -155 dBm <= ss_rsrp < -154 dBm
1263 // ......
1264 // 125: -32 dBm <= ss_rsrp < -31 dBm
1265 // 126: -31 dBm <= ss_rsrp
1266 // 255: not known or not detectable
1267 uint8 ss_sinr; // 0: ss_sinr < -23 dB
1268 // 1: -23 dB  ss_sinr < -22.5 dB
1269 // 2: -22.5 dB  ss_sinr < -22 dB
1270 // ......
1271 // 125: 39 dB  ss_sinr < 39.5 dBm
1272 // 126: 39.5 dB  ss_sinr < 40 dB
1273 // 127: 40 dB  ss_sinr
1274 // 255: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +08001275} __attribute__((packed)) mbtk_signal_info_t;
1276*/
b.liu68a94c92025-05-24 12:53:41 +08001277static void gsw_sig_info_callback(const void* data, int data_len)
1278{
q.huang934ec0e2025-07-22 19:56:59 +08001279 if (nw_init_flag == 0)
1280 {
1281 printf("%s, nw not init\n",__func__);
1282 return;
1283 }
1284
q.huangfa0a0a32025-06-12 17:07:23 +08001285 if(data && (data_len >= sizeof (mbtk_signal_info_t)))
b.liu68a94c92025-05-24 12:53:41 +08001286 {
b.liu68a94c92025-05-24 12:53:41 +08001287 signalStrength_t sig_strength;
q.huangfa0a0a32025-06-12 17:07:23 +08001288 convert_mbtk_sig_info_to_gsw_sig_info(( const mbtk_signal_info_t*) data,&sig_strength);
1289
b.liu68a94c92025-05-24 12:53:41 +08001290 if(sig_cb != NULL)
1291 {
1292 sig_cb(sig_strength);
1293 }
1294 }
b.liu68a94c92025-05-24 12:53:41 +08001295 else
1296 {
q.huang934ec0e2025-07-22 19:56:59 +08001297 LOGE(GSW_NW,"data is NULL or data len %d error",data_len);
b.liu68a94c92025-05-24 12:53:41 +08001298 }
1299}
1300
q.huangc8b93122025-06-17 17:46:05 +08001301static void gsw_operating_mode_event_callback(const void* data, int data_len)
b.liu68a94c92025-05-24 12:53:41 +08001302{
q.huang934ec0e2025-07-22 19:56:59 +08001303 if (nw_init_flag == 0)
1304 {
1305 printf("%s nw not init\n",__func__);
1306 return;
1307 }
1308
1309 LOGE(GSW_NW,"gsw_operating_mode_event_callback start\n");
b.liu68a94c92025-05-24 12:53:41 +08001310
q.huangc8b93122025-06-17 17:46:05 +08001311
b.liu68a94c92025-05-24 12:53:41 +08001312 if(data && data_len > 0)
1313 {
q.huangc8b93122025-06-17 17:46:05 +08001314 const uint8 *cfun_state = (const uint8*)data;
q.huang934ec0e2025-07-22 19:56:59 +08001315 LOGE(GSW_NW,"gsw_operating_mode_event_callback,data = %d\n", *cfun_state);
q.huangc8b93122025-06-17 17:46:05 +08001316 if(airplane_cb != NULL)
b.liu68a94c92025-05-24 12:53:41 +08001317 {
q.huangc8b93122025-06-17 17:46:05 +08001318 airplane_cb(*cfun_state);
b.liu68a94c92025-05-24 12:53:41 +08001319 }
1320 }
1321
1322}
1323
q.huangdaa16d42025-07-03 14:32:48 +08001324
b.liu68a94c92025-05-24 12:53:41 +08001325static void gsw_reject_callback(GSW_NW_RADIO_ACCESS_TECH_E rat, GSW_SERVICE_DOMAIN_E domain, int cause)
1326{
q.huang934ec0e2025-07-22 19:56:59 +08001327 if (nw_init_flag == 0)
1328 {
1329 printf("%s nw not init\n",__func__);
1330 return;
1331 }
b.liu68a94c92025-05-24 12:53:41 +08001332
q.huang934ec0e2025-07-22 19:56:59 +08001333 LOGE(GSW_NW,"gsw_reject_callback start,rat = %d,domain = %d,cause = %d\n",rat,domain,cause);
b.liu68a94c92025-05-24 12:53:41 +08001334
1335 if(reject_cb != NULL)
1336 {
q.huang934ec0e2025-07-22 19:56:59 +08001337 GSW_NW_REJ_CAUSE_E rej_cause;
1338 rej_cause.rej_cause = cause;
1339 rej_cause.rej_rat = rat;
1340 rej_cause.rej_domain = domain;
1341
1342 LOGE(GSW_NW,"reject_cb called\n");
1343 reject_cb(&rej_cause);
b.liu68a94c92025-05-24 12:53:41 +08001344 }
1345 else
1346 {
q.huang934ec0e2025-07-22 19:56:59 +08001347 LOGE(GSW_NW,"reject_cb is NULL\n");
1348 }
1349}
1350
1351void gsw_serving_info_timer()
1352{
1353 if(nw_init_flag == 0 || nw_info_handle == NULL)
1354 {
1355 return;
b.liu68a94c92025-05-24 12:53:41 +08001356 }
1357
q.huang934ec0e2025-07-22 19:56:59 +08001358 while(nw_init_flag)
1359 {
1360 gsw_serving_info_callback_thread();
1361 sleep(SERVING_TIMER);
1362 }
b.liu68a94c92025-05-24 12:53:41 +08001363}
1364
xy.hec89938f2025-05-29 14:08:47 +08001365void gsw_sig_info_timer()
1366{
xy.hec89938f2025-05-29 14:08:47 +08001367 if(nw_init_flag == 0 || nw_info_handle == NULL)
1368 {
1369 return;
1370 }
1371
1372 mbtk_signal_info_t signal;
1373 signalStrength_t sig_strength;
1374
1375 while(nw_init_flag)
1376 {
q.huangfa0a0a32025-06-12 17:07:23 +08001377 int ret = mbtk_net_signal_get(nw_info_handle, &signal);
xy.hec89938f2025-05-29 14:08:47 +08001378 if(ret != 0)
1379 {
q.huang934ec0e2025-07-22 19:56:59 +08001380 LOGE(GSW_NW,"mbtk_net_signal_get fail, ret is %d\n",ret);
q.huang47a9bf12025-08-06 20:24:12 +08001381 memset((void*) &sig_strength,0,sizeof (sig_strength));
xy.hec89938f2025-05-29 14:08:47 +08001382 }
xy.hec89938f2025-05-29 14:08:47 +08001383 else
1384 {
q.huangfa0a0a32025-06-12 17:07:23 +08001385 convert_mbtk_sig_info_to_gsw_sig_info(&signal,&sig_strength);
q.huang47a9bf12025-08-06 20:24:12 +08001386 }
1387 if(sig_cb != NULL)
1388 {
1389 sig_cb(sig_strength);
xy.hec89938f2025-05-29 14:08:47 +08001390 }
xy.hec89938f2025-05-29 14:08:47 +08001391 sleep(SIG_TIMER);
1392 }
1393}
1394
q.huangdaa16d42025-07-03 14:32:48 +08001395int get_sdk_ready()
1396{
1397 char buffer[MBTK_READY_STRING_SIZE_MAX];
1398 FILE *fp = popen(SDK_READY_CMD, "r");
1399 if(NULL == fp)
1400 {
q.huang934ec0e2025-07-22 19:56:59 +08001401 LOGE(GSW_NW,"popen sdk ready fail");
q.huangdaa16d42025-07-03 14:32:48 +08001402 return -1;
1403 }
1404 memset(buffer,0,sizeof(buffer));
1405 if(fgets(buffer, sizeof(buffer), fp) == NULL)
1406 {
1407 pclose(fp);
q.huang934ec0e2025-07-22 19:56:59 +08001408 LOGE(GSW_NW,"fgets failed:");
q.huangdaa16d42025-07-03 14:32:48 +08001409 return -1;
1410 }
1411 pclose(fp);
q.huang934ec0e2025-07-22 19:56:59 +08001412 LOGE(GSW_NW,"get_sdk_ready:%s",buffer);
q.huangdaa16d42025-07-03 14:32:48 +08001413 return atoi(buffer);
1414}
1415
rx.xieaad2b6f2025-08-01 00:55:33 -07001416static int g_modem_state = ((int)(GSW_MODEM_STATE_UNKNOWN)) - 1;
1417static int g_gnss_state = ((int)(GSW_MODEM_STATE_UNKNOWN)) - 1;
q.huang66b79162025-06-27 17:45:34 +08001418
q.huang66b79162025-06-27 17:45:34 +08001419void gsw_modem_state_timer()
rx.xieaad2b6f2025-08-01 00:55:33 -07001420{
1421 int modem_state;
1422 int gnss_state;
1423
1424 while (nw_init_flag)
q.huang66b79162025-06-27 17:45:34 +08001425 {
rx.xieaad2b6f2025-08-01 00:55:33 -07001426 int uci_value = get_sdk_ready();
1427 if (uci_value < 0)
q.huang66b79162025-06-27 17:45:34 +08001428 {
rx.xieaad2b6f2025-08-01 00:55:33 -07001429 modem_state = GSW_MODEM_STATE_UNKNOWN;
1430 gnss_state = GSW_SDK_STATE_GPS_DOWN;
1431 }
1432 else
1433 {
1434 if ((uci_value & 0x0F) == 0)
q.huang66b79162025-06-27 17:45:34 +08001435 {
rx.xieaad2b6f2025-08-01 00:55:33 -07001436 modem_state = GSW_MODEM_STATE_ONLINE;
1437 }
1438 else if (uci_value > 0 && uci_value <= 15)
q.huang66b79162025-06-27 17:45:34 +08001439 {
rx.xieaad2b6f2025-08-01 00:55:33 -07001440 modem_state = GSW_MODEM_STATE_OFFLINE;
q.huang66b79162025-06-27 17:45:34 +08001441 }
rx.xieaad2b6f2025-08-01 00:55:33 -07001442 else
1443 {
1444 modem_state = GSW_MODEM_STATE_UNKNOWN;
1445 }
1446
1447 if (uci_value & (1 << 4))
1448 {
1449 gnss_state = GSW_SDK_STATE_GPS_DOWN;
1450 }
1451 else
1452 {
1453 gnss_state = GSW_SDK_STATE_GPS_UP;
1454 }
1455 }
1456
1457 if (modem_cb != NULL)
1458 {
1459
1460 if (modem_state != g_modem_state)
1461 {
1462 LOGE(GSW_NW, "Modem state changed from %d to %d", g_modem_state, modem_state);
1463 modem_cb(modem_state);
1464 g_modem_state = modem_state;
1465 }
1466
1467 if (gnss_state != g_gnss_state)
1468 {
1469 LOGE(GSW_NW, "GNSS state changed from %d to %d", g_gnss_state, gnss_state);
1470 modem_cb(gnss_state);
1471 g_gnss_state = gnss_state;
1472 }
1473 }
1474 sleep(MODEM_TIMER);
q.huang66b79162025-06-27 17:45:34 +08001475 }
1476}
1477
1478
b.liu68a94c92025-05-24 12:53:41 +08001479
1480/**
1481 * @brief SDK interface to call back serving info
1482 * @param [in] handle_ptr
1483 * @retval 0: success
1484 * @retval other: fail
1485 */
1486int gsw_reg_serving_info_callback(GSW_NW_ServingInfoHandlePtr handle_ptr)
1487{
1488 if (nw_init_flag == 0 || nw_info_handle == NULL)
1489 {
xy.heb41615b2025-05-28 16:33:20 +08001490 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001491 }
1492
q.huang934ec0e2025-07-22 19:56:59 +08001493 void* cb_func;
b.liu68a94c92025-05-24 12:53:41 +08001494 if(handle_ptr == NULL)
1495 {
q.huang934ec0e2025-07-22 19:56:59 +08001496 LOGE(GSW_NW,"serving info handle_ptr is NULL\n");
1497 cb_func=NULL;
1498 }
1499 else
1500 {
1501 cb_func=(void*) gsw_serving_info_callback;
1502 }
1503
1504 int ret = mbtk_net_state_change_cb_reg(nw_info_handle, cb_func);
1505 if (ret != 0)
1506 {
1507 LOGW(GSW_NW,"mbtk_net_state_change_cb_reg fail, ret is %d",ret);
xy.heb41615b2025-05-28 16:33:20 +08001508 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001509 }
q.huang934ec0e2025-07-22 19:56:59 +08001510 serving_cb=handle_ptr;
b.liu68a94c92025-05-24 12:53:41 +08001511 return GSW_HAL_SUCCESS;
b.liu68a94c92025-05-24 12:53:41 +08001512}
1513
1514
1515/**
1516 * @brief SDK interface to call back sig info
1517 * @param [in] handle_ptr
1518 * @retval 0: success
1519 * @retval other: fail
1520 */
1521int gsw_reg_sig_info_callback(GSW_NW_SigInfoHandlePtr handle_ptr)
1522{
1523 if (nw_init_flag == 0 || nw_info_handle == NULL)
1524 {
xy.heb41615b2025-05-28 16:33:20 +08001525 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001526 }
q.huang81905ea2025-07-25 20:19:41 +08001527
q.huang934ec0e2025-07-22 19:56:59 +08001528 void* cb_func;
b.liu68a94c92025-05-24 12:53:41 +08001529 if(handle_ptr == NULL)
1530 {
q.huang934ec0e2025-07-22 19:56:59 +08001531 LOGE(GSW_NW,"serving info handle_ptr is NULL\n");
1532 cb_func=NULL;
1533 }
1534 else
1535 {
1536 cb_func=(void*) gsw_sig_info_callback;
1537 }
1538
1539 int ret = mbtk_signal_state_change_cb_reg(nw_info_handle, cb_func);
1540
1541 if (ret != 0)
1542 {
1543 LOGE(GSW_NW,"mbtk_signal_state_change_cb_reg fail, ret is %d", ret);
1544 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001545 }
1546
1547 sig_cb = handle_ptr;
1548
1549 return GSW_HAL_SUCCESS;
1550
1551}
1552
1553
1554/**
1555 * @brief SDK interface to call back rej cause
1556 * @param [in] handle_ptr
1557 * @retval 0: success
1558 * @retval other: fail
1559 */
1560int gsw_reg_rej_cause_callback(GSW_NW_RejectCauseHandlePtr handle_ptr)
1561{
1562 if (nw_init_flag == 0 || nw_info_handle == NULL)
1563 {
xy.heb41615b2025-05-28 16:33:20 +08001564 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001565 }
1566
1567 if(handle_ptr == NULL)
1568 {
q.huang934ec0e2025-07-22 19:56:59 +08001569 LOGE(GSW_NW,"rej cause handle_ptr is NULL\n");
b.liu68a94c92025-05-24 12:53:41 +08001570 }
1571
1572 reject_cb = handle_ptr;
1573
1574 return GSW_HAL_SUCCESS;
1575}
1576
q.huang81905ea2025-07-25 20:19:41 +08001577static void gsw_un_reg_all()
1578{
1579 gsw_reg_serving_info_callback(NULL);
1580 gsw_reg_sig_info_callback(NULL);
1581 gsw_reg_operating_mode_callback(NULL);
1582 gsw_reg_set_modem_status_event_callback(NULL);
1583 gsw_reg_rej_cause_callback(NULL);
1584}
1585
1586pthread_t s_tid[NW_THEAD_NUM] = {-1,-1,-1};
1587void* s_thread_func[NW_THEAD_NUM]={
1588 (void*)gsw_sig_info_timer,
1589 (void*)gsw_modem_state_timer,
1590 (void*)gsw_serving_info_timer
1591 };
1592
1593static void gsw_close_all_thread()
1594{
1595 int i,ret;
1596
1597
1598 nw_init_flag=0;
1599
1600/* had better not use thread cancel, maybe handle->send_mutex is locked now, cancel will not release this mutex
1601 for(i=0; i<NW_THEAD_NUM; i++)
1602 {
1603 if(s_tid[i]!=-1)
1604 {
1605 ret = pthread_cancel(s_tid[i]);
1606 LOGE(GSW_NW,"pthread %d cancel, ret is %d",i, ret);
1607 }
1608 }
1609*/
1610
1611 for(i=0;i<NW_THEAD_NUM;i++)
1612 {
1613 if(s_tid[i]!=-1)
1614 {
1615 ret = pthread_join(s_tid[i],NULL);
1616 LOGE(GSW_NW,"pthread %d join, ret is %d",i, ret);
1617 s_tid[i]=-1;
1618 }
1619 }
1620}
1621
1622static int gsw_start_all_thread()
1623{
1624 int i,ret;
1625 for(i=0; i<NW_THEAD_NUM;i++)
1626 {
1627 ret = pthread_create(&(s_tid[i]), NULL,s_thread_func[i], NULL);
1628 if (ret != 0)
1629 {
1630 LOGE(GSW_NW,"pthread_create fail %d,ret is %d",i,ret);
1631 gsw_close_all_thread();
1632 return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;
1633 }
1634 }
1635
1636 return GSW_HAL_SUCCESS;
1637
1638}
1639
1640
b.liu68a94c92025-05-24 12:53:41 +08001641
1642/**
1643 * @brief network sdk init
1644 * @param [in] token usr id define by who use
1645 * @retval 0: success
1646 * @retval other: fail
1647 */
1648int gsw_nw_sdk_init(int token)
1649{
b.liu68a94c92025-05-24 12:53:41 +08001650 if (nw_init_flag == 1 && nw_info_handle != NULL)
1651 {
1652 return GSW_HAL_SUCCESS;
1653 }
1654
q.huang81905ea2025-07-25 20:19:41 +08001655 int ret = mbtk_nw_api_import();
b.liu68a94c92025-05-24 12:53:41 +08001656 if (ret != 0)
1657 {
q.huang81905ea2025-07-25 20:19:41 +08001658 printf("mbtk_nw_api_import fail");
xy.heb41615b2025-05-28 16:33:20 +08001659 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001660 }
1661
1662 nw_info_handle = mbtk_info_handle_get();
1663
1664 if (nw_info_handle == NULL)
1665 {
q.huang81905ea2025-07-25 20:19:41 +08001666 LOGE(GSW_NW,"mbtk_info_handle_get fail");
xy.heb41615b2025-05-28 16:33:20 +08001667 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001668 }
1669
1670 char fplmn[256] = {0};
1671 ret = mbtk_fplmn_get(nw_info_handle, fplmn);
1672 if(ret != 0)
1673 {
q.huang81905ea2025-07-25 20:19:41 +08001674 LOGE(GSW_NW,"mbtk_fplmn_get failed, ret is %d",ret);
xy.heb41615b2025-05-28 16:33:20 +08001675 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001676 }
1677 fplmn_max_length = (strlen(fplmn)/6);
q.huang81905ea2025-07-25 20:19:41 +08001678 LOGE(GSW_NW,"fplmn = %s, fplmn_max_length = %d",fplmn,fplmn_max_length);
b.liu68a94c92025-05-24 12:53:41 +08001679
q.huang66b79162025-06-27 17:45:34 +08001680 nw_init_flag = 1;
q.huang81905ea2025-07-25 20:19:41 +08001681 ret=gsw_start_all_thread();
q.huang66b79162025-06-27 17:45:34 +08001682
q.huang81905ea2025-07-25 20:19:41 +08001683 if(ret != 0)
xy.hec89938f2025-05-29 14:08:47 +08001684 {
q.huang81905ea2025-07-25 20:19:41 +08001685 nw_init_flag = 0;
1686 LOGE(GSW_NW,"gsw_start_all_thread failed , ret is %d",ret);
1687 return GSW_HAL_NORMAL_FAIL;
xy.hec89938f2025-05-29 14:08:47 +08001688 }
1689
q.huang81905ea2025-07-25 20:19:41 +08001690 LOGE(GSW_NW,"gsw nw init suc");
b.liu68a94c92025-05-24 12:53:41 +08001691
1692 return GSW_HAL_SUCCESS;
1693}
1694
1695
1696/**
1697 * @brief network sdk deinit
1698 * @param
1699 * @retval 0: success
1700 * @retval other: fail
1701 */
1702int gsw_nw_sdk_deinit(void)
1703{
1704 int ret = -1;
1705
1706 if (nw_init_flag == 0 || nw_info_handle == NULL)
1707 {
xy.heb41615b2025-05-28 16:33:20 +08001708 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001709 }
1710
q.huang81905ea2025-07-25 20:19:41 +08001711 gsw_un_reg_all();// had better un-reg before thread close
1712 gsw_close_all_thread();//in it, nw_init_flag=0 and cb unreg
1713
b.liu68a94c92025-05-24 12:53:41 +08001714 ret = mbtk_info_handle_free(&nw_info_handle);
1715 if(ret != GSW_HAL_SUCCESS)
1716 {
q.huang81905ea2025-07-25 20:19:41 +08001717 LOGE(GSW_NW,"mbtk_info_handle_free fail");
xy.heb41615b2025-05-28 16:33:20 +08001718 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001719 }
1720
1721 dlclose(dlHandle_mbtk);
1722 nw_info_handle = NULL;
q.huang81905ea2025-07-25 20:19:41 +08001723
1724 LOGE(GSW_NW,"gsw_nw_sdk_deinit suc");
b.liu68a94c92025-05-24 12:53:41 +08001725
1726 return GSW_HAL_SUCCESS;
1727
1728}
1729
1730
1731/**
1732 * @brief get current network reg info
1733 * @param [out] serving_info struct for network info
1734 * include regstate ps_state opreator name mcc mcn etc
1735 * @retval 0: success
1736 * @retval other: fail
1737 */
1738int gsw_get_nwinfo(GSW_NW_SERVING_INFO *serving_info)
1739{
1740
1741 int ret = -1;
b.liu68a94c92025-05-24 12:53:41 +08001742 if (nw_init_flag == 0 || nw_info_handle == NULL)
1743 {
q.huang238b22a2025-06-10 14:36:59 +08001744 printf("nw_sdk_deinit not init\n");
xy.heb41615b2025-05-28 16:33:20 +08001745 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001746 }
1747
q.huang934ec0e2025-07-22 19:56:59 +08001748 LOGE(GSW_NW,"mbtk_net_reg_get start \n");
b.liu68a94c92025-05-24 12:53:41 +08001749 //regstate
1750 mbtk_net_reg_info_t reg;
b.liu68a94c92025-05-24 12:53:41 +08001751 ret = mbtk_net_reg_get(nw_info_handle, &reg);
1752 if(ret)
1753 {
q.huang934ec0e2025-07-22 19:56:59 +08001754 LOGE(GSW_NW,"mbtk_net_reg_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001755 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001756 }
1757
q.huang934ec0e2025-07-22 19:56:59 +08001758 LOGE(GSW_NW,"convert_cs_reg_state\n");
b.liu68a94c92025-05-24 12:53:41 +08001759 //cs_state
1760 serving_info->reg_state = convert_reg_state(reg.call_state);
q.huang934ec0e2025-07-22 19:56:59 +08001761 LOGE(GSW_NW,"convert_ps_reg_state\n");
b.liu68a94c92025-05-24 12:53:41 +08001762 //ps_state
1763 serving_info->ps_state = convert_reg_state(reg.data_state);
q.huang934ec0e2025-07-22 19:56:59 +08001764 LOGE(GSW_NW,"convert_rat_mode\n");
b.liu68a94c92025-05-24 12:53:41 +08001765 //reg_rat
1766 serving_info->reg_rat = convert_net_mode(reg.type);
1767 //srv_domain
1768 if(serving_info->reg_state == GSW_NETWORK_REG_REGISTERED || serving_info->reg_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
1769 {
1770 if(serving_info->ps_state == GSW_NETWORK_REG_REGISTERED || serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
1771 {
1772 serving_info->srv_domain = GSW_SRV_DOMAIN_CS_PS;
1773 }
1774
1775 else
1776 {
1777 serving_info->srv_domain = GSW_SRV_DOMAIN_CS_ONLY;
1778 }
1779 }
1780
1781 else if (serving_info->ps_state == GSW_NETWORK_REG_REGISTERED || serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
1782 {
1783 serving_info->srv_domain = GSW_SRV_DOMAIN_PS_ONLY;
1784 }
1785
1786 else
1787 {
1788 serving_info->srv_domain = GSW_SRV_DOMAIN_NO_SVC;
1789 //if ps and cs is both not registed, reg_rat seted to GSW_NETWORK_RADIO_NO_SVC
1790 serving_info->reg_rat = GSW_NETWORK_RADIO_NO_SVC;
1791 }
1792
q.huang934ec0e2025-07-22 19:56:59 +08001793 LOGD(GSW_NW,"roaming_ind\n");
b.liu68a94c92025-05-24 12:53:41 +08001794 //roaming_ind
1795 if(serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
1796 {
1797 serving_info->roaming_ind = GSW_NETWORK_ROAMING_ON;
1798 }
1799 else
1800 {
1801 serving_info->roaming_ind = GSW_NETWORK_ROAMING_OFF;
1802 }
1803
q.huang934ec0e2025-07-22 19:56:59 +08001804 LOGD(GSW_NW,"reject\n");
b.liu68a94c92025-05-24 12:53:41 +08001805 //reject
1806 if(serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_DENIED || serving_info->reg_state == GSW_NETWORK_REG_REGISTRATION_DENIED)
1807 {
q.huang934ec0e2025-07-22 19:56:59 +08001808 LOGD(GSW_NW,"reject_callback\n");
b.liu68a94c92025-05-24 12:53:41 +08001809 gsw_reject_callback(serving_info->reg_rat,serving_info->srv_domain,99);
1810 }
1811
q.huang934ec0e2025-07-22 19:56:59 +08001812 LOGD(GSW_NW,"reg_plmn / operator name\n");
b.liu68a94c92025-05-24 12:53:41 +08001813 //reg_plmn / operator name
1814 mbtk_net_info_t net;
q.huang934ec0e2025-07-22 19:56:59 +08001815 LOGD(GSW_NW,"mbtk_net_sel_mode_get start \n");
b.liu68a94c92025-05-24 12:53:41 +08001816 ret = mbtk_net_sel_mode_get(nw_info_handle, &net);
q.huang934ec0e2025-07-22 19:56:59 +08001817 LOGD(GSW_NW,"mbtk_net_sel_mode_get end \n");
b.liu68a94c92025-05-24 12:53:41 +08001818 if(ret == 0 && net.plmn > 0)
1819 {
1820 int i = 0;
1821
q.huang934ec0e2025-07-22 19:56:59 +08001822 LOGD(GSW_NW,"start to find mcc");
b.liu68a94c92025-05-24 12:53:41 +08001823 while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))
1824 {
1825 if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)
1826 {
q.huang934ec0e2025-07-22 19:56:59 +08001827 LOGD(GSW_NW,"find mcc\n");
b.liu68a94c92025-05-24 12:53:41 +08001828 break;
1829 }
1830 i++;
1831 }
1832
1833
1834 if(i == ARRAY_SIZE(lynq_operator_mcc_mnc))
1835 {
q.huang934ec0e2025-07-22 19:56:59 +08001836 LOGD(GSW_NW,"not find mcc");
b.liu68a94c92025-05-24 12:53:41 +08001837 strcpy(serving_info->operator_name, "unknown");
hong.liud2417072025-06-27 07:10:37 -07001838 sprintf(serving_info->reg_plmn, "%u", net.plmn);
b.liu68a94c92025-05-24 12:53:41 +08001839 }
1840
1841 else
1842 {
q.huang934ec0e2025-07-22 19:56:59 +08001843 LOGD(GSW_NW,"find mcc\n");
b.liu68a94c92025-05-24 12:53:41 +08001844 strcpy(serving_info->operator_name, lynq_operator_mcc_mnc[i].lynq_operator_l);
hong.liud2417072025-06-27 07:10:37 -07001845 sprintf(serving_info->reg_plmn, "%u", net.plmn);
b.liu68a94c92025-05-24 12:53:41 +08001846 }
1847
q.huang934ec0e2025-07-22 19:56:59 +08001848 LOGE(GSW_NW,"operator_name = %s\n", serving_info->operator_name);
1849 LOGE(GSW_NW,"reg_plmn = %s\n", serving_info->reg_plmn);
b.liu68a94c92025-05-24 12:53:41 +08001850 }
1851
1852
q.huang934ec0e2025-07-22 19:56:59 +08001853 LOGD(GSW_NW,"get cell id/tac/lac/sid/nid\n");
b.liu68a94c92025-05-24 12:53:41 +08001854 //cell id/tac/lac/sid/nid
1855 mbtk_cell_type_enum cell_type;
b.liu68a94c92025-05-24 12:53:41 +08001856 list_node_t* cell_list = NULL;
1857
q.huang934ec0e2025-07-22 19:56:59 +08001858 LOGD(GSW_NW,"mbtk_cell_get start\n");
b.liu68a94c92025-05-24 12:53:41 +08001859 ret = mbtk_cell_get(nw_info_handle, &cell_type, &cell_list);
1860 if(ret != 0 || cell_list == NULL)
1861 {
q.huang934ec0e2025-07-22 19:56:59 +08001862 LOGE(GSW_NW,"mbtk_cell_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001863 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001864 }
1865 else
1866 {
q.huang934ec0e2025-07-22 19:56:59 +08001867 LOGE(GSW_NW,"mbtk_cell_get end,start to get node\n");
b.liu68a94c92025-05-24 12:53:41 +08001868 list_first(cell_list);
q.huang934ec0e2025-07-22 19:56:59 +08001869 LOGE(GSW_NW,"list_first end\n");
b.liu68a94c92025-05-24 12:53:41 +08001870 mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);
1871 if(cell)
1872 {
q.huang934ec0e2025-07-22 19:56:59 +08001873 LOGE(GSW_NW,"cell is not null,value2 = %u\n",cell->value2);
b.liu68a94c92025-05-24 12:53:41 +08001874 switch(cell_type)
1875 {
1876 case MBTK_CELL_TYPE_LTE:
1877 {
q.huang934ec0e2025-07-22 19:56:59 +08001878 LOGE(GSW_NW,"is lte\n");
1879 //LOGE(GSW_NW,"LTE : tac=%x, PCI=%x, dlEuarfcn=%x, ulEuarfcn=%x, band=%x\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
1880 LOGE(GSW_NW,"LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
hong.liud2417072025-06-27 07:10:37 -07001881 snprintf(serving_info->tac,sizeof(serving_info->tac),"%u",cell->value1);
b.liu68a94c92025-05-24 12:53:41 +08001882 strcpy(serving_info->lac,"");
hong.liud2417072025-06-27 07:10:37 -07001883 snprintf(serving_info->cell_id,sizeof(serving_info->cell_id),"%u",cell->value10);
b.liu68a94c92025-05-24 12:53:41 +08001884 break;
1885 }
1886
1887 case MBTK_CELL_TYPE_GSM:
1888 {
q.huang934ec0e2025-07-22 19:56:59 +08001889 LOGE(GSW_NW,"is gsm\n");
1890 LOGE(GSW_NW,"GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
hong.liud2417072025-06-27 07:10:37 -07001891 sprintf(serving_info->lac,"%u",cell->value1);
b.liu68a94c92025-05-24 12:53:41 +08001892 memset(serving_info->tac,0,sizeof(serving_info->tac));
hong.liud2417072025-06-27 07:10:37 -07001893 sprintf(serving_info->cell_id,"%u",cell->value2);
b.liu68a94c92025-05-24 12:53:41 +08001894 break;
1895 }
1896 case MBTK_CELL_TYPE_UMTS:
1897 {
q.huang934ec0e2025-07-22 19:56:59 +08001898 LOGE(GSW_NW,"is wcdma\n");
1899 LOGE(GSW_NW,"UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
hong.liud2417072025-06-27 07:10:37 -07001900 sprintf(serving_info->lac,"%u",cell->value1);
b.liu68a94c92025-05-24 12:53:41 +08001901 memset(serving_info->tac,0,sizeof(serving_info->tac));
hong.liud2417072025-06-27 07:10:37 -07001902 sprintf(serving_info->cell_id,"%u",cell->value2);
b.liu68a94c92025-05-24 12:53:41 +08001903 break;
1904 }
1905
1906 default:
1907 break;
1908 }
1909 }
1910 else
1911 {
q.huang934ec0e2025-07-22 19:56:59 +08001912 LOGE(GSW_NW,"cell is null\n");
b.liu68a94c92025-05-24 12:53:41 +08001913 }
1914 }
1915
1916 //not support now
1917 serving_info->sid = 0;
1918 serving_info->nid = 0;
1919
1920 return GSW_HAL_SUCCESS;
1921}
1922
1923
1924/**
1925 * @brief get current network type
1926 * @param [out] netype as GSW_NW_RADIO_ACCESS_TECH_E type
1927 * @retval 0: success
1928 * @retval other: fail
1929 */
hong.liud2417072025-06-27 07:10:37 -07001930int gsw_get_netype(int32_t *netype)
b.liu68a94c92025-05-24 12:53:41 +08001931{
1932 int ret = -1;
1933
1934 if (nw_init_flag == 0 || nw_info_handle == NULL)
1935 {
xy.heb41615b2025-05-28 16:33:20 +08001936 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001937 }
1938
1939 //regstate
1940 mbtk_net_reg_info_t reg;
1941 ret = mbtk_net_reg_get(nw_info_handle, &reg);
1942 if(ret)
1943 {
q.huang934ec0e2025-07-22 19:56:59 +08001944 LOGE(GSW_NW,"mbtk_net_reg_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001945 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001946 }
1947
1948 if(reg.data_state == MBTK_NET_REG_STATE_HOME || reg.data_state == MBTK_NET_REG_STATE_ROAMING)
1949 {
1950 *netype = convert_net_mode(reg.type);
1951 }
1952 else
1953 {
1954 *netype = GSW_NETWORK_RADIO_NO_SVC;
1955 }
1956
1957 return GSW_HAL_SUCCESS;
1958}
1959
1960
1961/**
1962 * @brief get radio opmode, as open and close airplane mode
1963 * @param [out] op_mode 1 is radio on, 0 is radio off
1964 * @retval 0: success
1965 * @retval other: fail
1966 */
1967int gsw_get_opmode(int *op_mode)
1968{
1969 int tmp_rf = -1;
1970 int ret = -1;
1971 if (nw_init_flag == 0 || nw_info_handle == NULL)
1972 {
xy.heb41615b2025-05-28 16:33:20 +08001973 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001974 }
1975
1976 ret = mbtk_get_modem_fun(nw_info_handle, &tmp_rf);
1977 if (ret != 0)
1978 {
q.huang934ec0e2025-07-22 19:56:59 +08001979 LOGE(GSW_NW,"mbtk_get_modem_fun fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001980 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001981 }
1982 if(tmp_rf == LYNQ_AIR_CFUN_MODE_OFF)
1983 {
1984 *op_mode = GSW_OP_MODE_LPM;
1985 }
1986
1987 if(tmp_rf == LYNQ_AIR_PLANE_MODE_ON)
1988 {
1989 *op_mode = GSW_OP_MODE_OFFLINE;
1990 }
1991
1992 if(tmp_rf == LYNQ_AIR_PLANE_MODE_OFF)
1993 {
1994 *op_mode = GSW_OP_MODE_ONLINE;
1995 }
1996
1997 return GSW_HAL_SUCCESS;
1998}
1999
2000
2001
2002/**
2003 * @brief set radio opmode, as open and close airplane mode
2004 * @param [in] op_mode 1 is radio on, 0 is radio off
2005 * @retval 0: success
2006 * @retval other: fail
2007 */
hong.liud2417072025-06-27 07:10:37 -07002008int gsw_set_opmode(int32_t op_mode)
b.liu68a94c92025-05-24 12:53:41 +08002009{
2010 mbtk_modem_info_t info;
2011 int rf_mode = -1;
2012 int ret = -1;
2013
2014 if (nw_init_flag == 0 || nw_info_handle == NULL)
2015 {
xy.heb41615b2025-05-28 16:33:20 +08002016 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002017 }
2018
2019 if(op_mode == GSW_OP_MODE_LPM)
2020 {
2021 rf_mode = LYNQ_AIR_CFUN_MODE_OFF;
2022 }
2023
2024 if(op_mode == GSW_OP_MODE_ONLINE)
2025 {
2026 rf_mode = LYNQ_AIR_PLANE_MODE_OFF;
2027 }
2028
2029 if(op_mode == GSW_OP_MODE_OFFLINE)
2030 {
2031 rf_mode = LYNQ_AIR_PLANE_MODE_ON;
2032 }
2033
2034 if (rf_mode != LYNQ_AIR_PLANE_MODE_ON && rf_mode != LYNQ_AIR_PLANE_MODE_OFF && rf_mode != LYNQ_AIR_CFUN_MODE_OFF)
2035 {
q.huang934ec0e2025-07-22 19:56:59 +08002036 LOGE(GSW_NW,"Input mode is error!\n");
xy.heb41615b2025-05-28 16:33:20 +08002037 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002038 }
2039
2040 info.fun = rf_mode;
2041 info.rst = 0;
2042 ret = mbtk_set_modem_fun(nw_info_handle, &info);
2043 if (ret != 0)
2044 {
q.huang934ec0e2025-07-22 19:56:59 +08002045 LOGE(GSW_NW,"gsw_set_opmode fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002046 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002047 }
2048
2049 return GSW_HAL_SUCCESS;
2050
2051}
2052
2053
2054/**
2055 * @brief get network mode preference of mdm search network scale
2056 * @param [out] mode_pref net_work pref mode:
2057 * enum prefer_mode
2058 * @retval 0: success
2059 * @retval other: fail
2060 */
hong.liud2417072025-06-27 07:10:37 -07002061int gsw_get_mode_preference(int32_t *mode_pref)
b.liu68a94c92025-05-24 12:53:41 +08002062{
2063 if (nw_init_flag == 0 || nw_info_handle == NULL)
2064 {
xy.heb41615b2025-05-28 16:33:20 +08002065 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002066 }
2067
2068 int ret = -1;
2069 mbtk_band_info_t band;
2070 memset(&band, 0, sizeof(mbtk_band_info_t));
2071
2072 ret = mbtk_current_band_get(nw_info_handle, &band);
2073 if(ret != 0)
2074 {
q.huang934ec0e2025-07-22 19:56:59 +08002075 LOGE(GSW_NW,"mbtk_current_band_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002076 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002077 }
2078
2079 *mode_pref = convert_gsw_net_config(band.net_pref);
q.huang934ec0e2025-07-22 19:56:59 +08002080 LOGE(GSW_NW,"band.net_pref = %d\n", *mode_pref);
b.liu68a94c92025-05-24 12:53:41 +08002081 if(*mode_pref <= 0)
2082 {
q.huang934ec0e2025-07-22 19:56:59 +08002083 LOGE(GSW_NW,"no support mode\n");
xy.heb41615b2025-05-28 16:33:20 +08002084 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002085 }
2086 return GSW_HAL_SUCCESS;
2087
2088
2089}
2090
2091/**
2092 * @brief set network mode preference of mdm search network scale
2093 * @param [in] mode_pref net_work pref mode:
2094 * enum prefer_mode
2095 * @retval 0: success
2096 * @retval other: fail
2097 */
hong.liud2417072025-06-27 07:10:37 -07002098int gsw_set_mode_preference(int32_t mode_pref)
b.liu68a94c92025-05-24 12:53:41 +08002099{
2100 if (nw_init_flag == 0 || nw_info_handle == NULL)
2101 {
xy.heb41615b2025-05-28 16:33:20 +08002102 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002103 }
2104
2105 int ret = -1;
2106
2107 mbtk_band_info_t band;
2108 memset(&band, 0, sizeof(mbtk_band_info_t));
2109
2110 band.net_pref = convert_mbtk_net_config(mode_pref);
q.huang934ec0e2025-07-22 19:56:59 +08002111 LOGE(GSW_NW,"band.net_pref = %d\n", band.net_pref);
b.liu68a94c92025-05-24 12:53:41 +08002112
2113 if(band.net_pref < 0)
2114 {
q.huang934ec0e2025-07-22 19:56:59 +08002115 LOGE(GSW_NW,"no support mode\n");
xy.heb41615b2025-05-28 16:33:20 +08002116 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002117 }
2118
2119 ret = mbtk_current_band_set(nw_info_handle, &band);
2120 if(ret != 0)
2121 {
q.huang934ec0e2025-07-22 19:56:59 +08002122 LOGE(GSW_NW,"mbtk_current_band_set fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002123 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002124 }
2125
2126 return GSW_HAL_SUCCESS;
2127}
2128
2129/**
2130 * @brief get signal csq value
2131 * @param [out] csq_value csq of signalstrengh 0 - 31, 99 invalid
2132 * @retval 0: success
2133 * @retval other: fail
2134 */
hong.liud2417072025-06-27 07:10:37 -07002135int gsw_get_sig_info(int32_t *csq_value)
b.liu68a94c92025-05-24 12:53:41 +08002136{
b.liu68a94c92025-05-24 12:53:41 +08002137 if (nw_init_flag == 0 || nw_info_handle == NULL)
2138 {
xy.heb41615b2025-05-28 16:33:20 +08002139 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002140 }
2141
q.huangdaa16d42025-07-03 14:32:48 +08002142 mbtk_signal_info_t signal;
q.huangfa0a0a32025-06-12 17:07:23 +08002143 int ret = mbtk_net_signal_get(nw_info_handle, &signal);
b.liu68a94c92025-05-24 12:53:41 +08002144 if(ret != 0)
2145 {
q.huang934ec0e2025-07-22 19:56:59 +08002146 LOGE(GSW_NW,"mbtk_net_signal_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002147 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002148 }
2149
q.huang934ec0e2025-07-22 19:56:59 +08002150 LOGD(GSW_NW,"signal.type=%d\n", signal.type);
b.liu68a94c92025-05-24 12:53:41 +08002151 switch(signal.type)
2152 {
q.huangfa0a0a32025-06-12 17:07:23 +08002153
b.liu68a94c92025-05-24 12:53:41 +08002154 case MBTK_RADIO_TECH_E_UTRAN:
2155 {
q.huang934ec0e2025-07-22 19:56:59 +08002156 LOGD(GSW_NW,"lte rsrp = %d dbm",signal.rsrp-141);
q.huangfa0a0a32025-06-12 17:07:23 +08002157 *csq_value = rsrpToLevel(signal.rsrp-141);
b.liu68a94c92025-05-24 12:53:41 +08002158 break;
2159 }
2160 case MBTK_RADIO_TECH_UTRAN:
2161 case MBTK_RADIO_TECH_UTRAN_HSDPA:
2162 case MBTK_RADIO_TECH_UTRAN_HSUPA:
2163 case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
2164 case MBTK_RADIO_TECH_UTRAN_HSPA:
2165 {
q.huang934ec0e2025-07-22 19:56:59 +08002166 LOGD(GSW_NW,"w rscp = %d dbm",signal.rscp-121);
q.huangfa0a0a32025-06-12 17:07:23 +08002167 *csq_value = rscpToLevel(signal.rscp-121);
2168 break;
2169 }
2170 case MBTK_RADIO_TECH_GSM:
2171 case MBTK_RADIO_TECH_GSM_COMPACT:
2172 case MBTK_RADIO_TECH_GSM_EGPRS:
2173 {
q.huang934ec0e2025-07-22 19:56:59 +08002174 LOGD(GSW_NW,"gsm rxlev = %d (0-63)",signal.rxlev);
q.huang861c07d2025-06-24 16:54:58 +08002175 *csq_value = rxlevToLevel(signal.rxlev);
b.liu68a94c92025-05-24 12:53:41 +08002176 break;
2177 }
2178 default:
2179 {
q.huang934ec0e2025-07-22 19:56:59 +08002180 LOGE(GSW_NW,"[%s] unknown reg type.[%d]", __func__, signal.type);
xy.heb41615b2025-05-28 16:33:20 +08002181 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002182 }
2183 }
2184 return GSW_HAL_SUCCESS;
2185}
2186
2187/**
2188 * @brief set nework power mode, for tcam enter standby or exit standby
2189 * @param [in] mode TRUE(1) when enter standby, FALSE(0) after wake up
2190 * @retval 0: success
2191 * @retval other: fail
2192 */
lichengzhang0ba58962025-07-15 17:39:03 +08002193
2194int gsw_nw_power_mode = 0;
b.liu68a94c92025-05-24 12:53:41 +08002195int gsw_network_set_power_mode(char mode)
2196{
lichengzhang640b4f82025-07-21 16:19:33 +08002197 int ret = -1;
2198 if (nw_init_flag == 0)//nw_info_handle == NULL Don't need
b.liu68a94c92025-05-24 12:53:41 +08002199 {
xy.heb41615b2025-05-28 16:33:20 +08002200 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002201 }
2202
2203 if(mode != 0 && mode != 1)
2204 {
q.huang934ec0e2025-07-22 19:56:59 +08002205 LOGE(GSW_NW,"Input mode is error!\n");
xy.heb41615b2025-05-28 16:33:20 +08002206 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002207 }
2208
2209 if(mode == 1)
lichengzhang0ba58962025-07-15 17:39:03 +08002210 gsw_nw_power_mode = 3;
2211 else
2212 gsw_nw_power_mode = 1;
q.huang934ec0e2025-07-22 19:56:59 +08002213
2214 LOGE(GSW_NW,"mode is %d\n",gsw_nw_power_mode);
lichengzhang640b4f82025-07-21 16:19:33 +08002215 ret = mbtk_wakeup_state_set(nw_info_handle, gsw_nw_power_mode);
2216 if(ret != 0)
2217 {
q.huang934ec0e2025-07-22 19:56:59 +08002218 LOGE(GSW_NW,"mbtk_wakeup_state_set fail\n");
lichengzhang640b4f82025-07-21 16:19:33 +08002219 return GSW_HAL_NORMAL_FAIL;
2220 }
b.liu68a94c92025-05-24 12:53:41 +08002221
2222 return GSW_HAL_SUCCESS;
2223
b.liu68a94c92025-05-24 12:53:41 +08002224}
2225
2226/**
2227 * @brief convert rsrp rscp rssi to csq value.
2228 * @param [in] netType signal radio tech 2 means 2G 3 mens 3G,4 is 4G,5 is 5G
2229 * @param [in] sigvalue input signal_strength for different nettype
2230 * rsrp for 4G/5G, rscp for 3G, rssi for 2G
2231
2232 * @retval csq
2233 * @retval other: fail
2234 */
hong.liud2417072025-06-27 07:10:37 -07002235int gsw_sigInfo_to_csq(int32_t netType, int32_t sigValue)
b.liu68a94c92025-05-24 12:53:41 +08002236{
q.huang238b22a2025-06-10 14:36:59 +08002237 if (nw_init_flag == 0 || nw_info_handle == NULL)
2238 {
2239 return GSW_HAL_NORMAL_FAIL;
2240 }
b.liu68a94c92025-05-24 12:53:41 +08002241 switch(netType)
q.huangfa0a0a32025-06-12 17:07:23 +08002242 {
2243 case 4:
b.liu68a94c92025-05-24 12:53:41 +08002244 {
q.huang2dbc0bc2025-08-06 10:36:24 +08002245 return rsrpToLevel(-sigValue);
q.huangfa0a0a32025-06-12 17:07:23 +08002246 }
2247 case 3: //WCDMA
b.liu68a94c92025-05-24 12:53:41 +08002248 {
q.huang2dbc0bc2025-08-06 10:36:24 +08002249 return rscpToLevel(-sigValue);
q.huangfa0a0a32025-06-12 17:07:23 +08002250 }
2251 case 2: //GSM
b.liu68a94c92025-05-24 12:53:41 +08002252 {
q.huangfa0a0a32025-06-12 17:07:23 +08002253 return sigValue;
b.liu68a94c92025-05-24 12:53:41 +08002254 }
2255
2256 default:
2257 {
q.huang934ec0e2025-07-22 19:56:59 +08002258 LOGE(GSW_NW,"parameter error\n");
xy.heb41615b2025-05-28 16:33:20 +08002259 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002260 }
2261 }
2262}
2263
2264/*
2265 * @brief get mobile operator name
2266 @param [out] nw_operator_name_infos get the long and short operator name info
2267 @retval 0: success
2268 @retval 0: other: fail
2269 */
2270int gsw_get_mobile_operator_name(gsw_mobile_operator_name *nw_operator_name_infos)
2271{
2272 char OperatorFN[128];
2273 char OperatorSH[128];
hong.liud2417072025-06-27 07:10:37 -07002274 char temp[12];
b.liu68a94c92025-05-24 12:53:41 +08002275 mbtk_net_info_t net;
2276
2277 if (nw_init_flag == 0 || nw_info_handle == NULL)
2278 {
xy.heb41615b2025-05-28 16:33:20 +08002279 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002280 }
2281
2282 if(!mbtk_net_sel_mode_get(nw_info_handle, &net) && net.plmn > 0)
2283 {
q.huang934ec0e2025-07-22 19:56:59 +08002284 LOGE(GSW_NW,"Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);
b.liu68a94c92025-05-24 12:53:41 +08002285 int i = 0;
2286 while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))
2287 {
2288 if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)
2289 break;
2290 i++;
2291 }
2292
2293 if(i == ARRAY_SIZE(lynq_operator_mcc_mnc)) // No found mcc&mnc
2294 {
2295 strcpy(OperatorFN, "UNKNOWN");
2296 strcpy(OperatorSH, "UNKNOWN");
2297 }
2298 else
2299 {
2300 strcpy(OperatorFN, lynq_operator_mcc_mnc[i].lynq_operator_l);
2301 strcpy(OperatorSH, lynq_operator_mcc_mnc[i].lynq_operator_s);
2302
q.huangdaa16d42025-07-03 14:32:48 +08002303
hong.liud2417072025-06-27 07:10:37 -07002304 sprintf(temp, "%u", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)/100);
b.liu68a94c92025-05-24 12:53:41 +08002305 strncpy(nw_operator_name_infos->mcc, temp, strlen(temp));
2306
q.huangdaa16d42025-07-03 14:32:48 +08002307
hong.liud2417072025-06-27 07:10:37 -07002308 sprintf(temp, "%u", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)%100);
b.liu68a94c92025-05-24 12:53:41 +08002309 strncpy(nw_operator_name_infos->mnc, temp, strlen(temp));
2310 }
2311
2312 memset(nw_operator_name_infos->long_eons,0,128);
2313 memcpy(nw_operator_name_infos->long_eons,OperatorFN,strlen(OperatorFN));
2314 memset(nw_operator_name_infos->short_eons,0,128);
2315 memcpy(nw_operator_name_infos->short_eons,OperatorSH,strlen(OperatorSH));
2316
2317 return GSW_HAL_SUCCESS;
2318 }
2319
2320 else
2321 {
q.huang934ec0e2025-07-22 19:56:59 +08002322 LOGE(GSW_NW,"mbtk_net_sel_mode_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002323 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002324 }
2325
2326 return GSW_HAL_SUCCESS;
2327}
2328
2329
2330/*
2331 * @brief get current serving cell info
2332 * @param cell_info: [out] struct for current cell info
2333 * include earfcn mcc mnc pci psc tac lac etc.
2334 * @return int: 0 is success, other failed
2335 */
2336int gsw_get_cell_info(GSW_NW_CELL_INFO *cell_info)
2337{
b.liu68a94c92025-05-24 12:53:41 +08002338
2339 if (nw_init_flag == 0 || nw_info_handle == NULL)
2340 {
q.huang238b22a2025-06-10 14:36:59 +08002341 printf("nw_sdk_deinit not init\n");
xy.heb41615b2025-05-28 16:33:20 +08002342 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002343 }
2344
2345 list_node_t* cell_list = NULL;
b.liu68a94c92025-05-24 12:53:41 +08002346 mbtk_cell_type_enum type;
q.huang638d5872025-06-21 13:44:43 +08002347 int ret = mbtk_cell_get(nw_info_handle, &type, &cell_list);
b.liu68a94c92025-05-24 12:53:41 +08002348 if(ret || cell_list == NULL) {
q.huang934ec0e2025-07-22 19:56:59 +08002349 LOGE(GSW_NW,"mbtk_cell_get failed : %d\n", ret);
q.huang638d5872025-06-21 13:44:43 +08002350 list_free(cell_list);
2351 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002352 } else {
q.huang638d5872025-06-21 13:44:43 +08002353 memset(cell_info,0,sizeof(GSW_NW_CELL_INFO));
b.liu68a94c92025-05-24 12:53:41 +08002354 list_first(cell_list);
2355 mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);
2356 if(cell) { // Current server cell.
2357 switch(type)
2358 {
2359 case 0:
2360 {
q.huang934ec0e2025-07-22 19:56:59 +08002361 LOGD(GSW_NW,"GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
q.huangdaa16d42025-07-03 14:32:48 +08002362 char gsm_temp[12];
b.liu68a94c92025-05-24 12:53:41 +08002363
2364 cell_info->rat = GSW_NETWORK_RADIO_GSM;
2365
2366 cell_info->mcc_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08002367 snprintf(gsm_temp, sizeof(gsm_temp) ,"%X", cell->value5);
b.liu68a94c92025-05-24 12:53:41 +08002368 strncpy(cell_info->mcc, gsm_temp, sizeof(cell_info->mcc));
2369
b.liu68a94c92025-05-24 12:53:41 +08002370 cell_info->mnc_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08002371 snprintf(gsm_temp, sizeof(gsm_temp) ,"%X", cell->value6);
b.liu68a94c92025-05-24 12:53:41 +08002372 strncpy(cell_info->mnc, gsm_temp, sizeof(cell_info->mnc));
2373
2374 cell_info->cell_id_valid = 1;
2375 cell_info->cell_id = cell->value2;
2376
2377 cell_info->lac_valid = 1;
2378 cell_info->lac = cell->value1;
2379
2380 cell_info->arfcn_valid = 1;
2381 cell_info->arfcn = cell->value3;
q.huang861c07d2025-06-24 16:54:58 +08002382
q.huang2dbc0bc2025-08-06 10:36:24 +08002383 cell_info->rssi=rxlevToLevel(cell->value7);
2384 cell_info->rssi_valid = (cell_info->rssi!=INVALID_AT_SIGNAL_LEVEL);
b.liu68a94c92025-05-24 12:53:41 +08002385 break;
2386 }
2387
2388 case 1:
2389 {
q.huang934ec0e2025-07-22 19:56:59 +08002390 LOGD(GSW_NW,"UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
q.huangdaa16d42025-07-03 14:32:48 +08002391 char wcdma_temp[12];
b.liu68a94c92025-05-24 12:53:41 +08002392
2393 cell_info->rat = GSW_NETWORK_RADIO_UMTS;
2394
2395 cell_info->mcc_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08002396 snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%X", cell->value4);
b.liu68a94c92025-05-24 12:53:41 +08002397 strncpy(cell_info->mcc, wcdma_temp, sizeof(cell_info->mcc));
2398
b.liu68a94c92025-05-24 12:53:41 +08002399 cell_info->mnc_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08002400 snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%X", cell->value5);
b.liu68a94c92025-05-24 12:53:41 +08002401 strncpy(cell_info->mnc, wcdma_temp, sizeof(cell_info->mnc));
2402
2403 cell_info->lac_valid = 1;
2404 cell_info->lac = cell->value1;
2405
2406 cell_info->cell_id_valid = 1;
2407 cell_info->cell_id = cell->value2;
2408
2409 cell_info->uarfcn_valid = 1;
2410 cell_info->uarfcn = cell->value3;
2411
2412 cell_info->psc_valid = 1;
2413 cell_info->psc = cell->value6;
2414 break;
2415 }
2416
2417 case 2:
2418 {
q.huang934ec0e2025-07-22 19:56:59 +08002419 LOGE(GSW_NW,"LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
b.liu68a94c92025-05-24 12:53:41 +08002420
q.huangdaa16d42025-07-03 14:32:48 +08002421 char lte_temp[12];
b.liu68a94c92025-05-24 12:53:41 +08002422 cell_info->rat = GSW_NETWORK_RADIO_LTE;
2423
2424 cell_info->mcc_valid = 1;
2425 snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);
2426 strncpy(cell_info->mcc, lte_temp, sizeof(cell_info->mcc));
2427
b.liu68a94c92025-05-24 12:53:41 +08002428 cell_info->mnc_valid = 1;
2429 snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);
2430 strncpy(cell_info->mnc, lte_temp, sizeof(cell_info->mnc));
2431
2432 cell_info->tac_valid = 1;
2433 cell_info->tac = cell->value1;
2434
2435 cell_info->pci_valid = 1;
2436 cell_info->pci = cell->value2;
2437
2438 cell_info->earfcn_valid = 1;
2439 cell_info->earfcn = cell->value3;
2440
2441 cell_info->bler_valid = 1;
2442 cell_info->bler = cell->value4;
2443
2444 cell_info->band_valid = 1;
2445 cell_info->band = cell->value5;
2446
q.huang638d5872025-06-21 13:44:43 +08002447 cell_info->rssnr = sinr_convert_to_10_times_dB(cell->value11);
2448 cell_info->rssnr_valid=(cell_info->rssnr!=INT_32_MAX);
b.liu68a94c92025-05-24 12:53:41 +08002449
q.huang638d5872025-06-21 13:44:43 +08002450 cell_info->lteMode_valid = 1;
2451 cell_info->lteMode =(!(cell->value12));
2452
2453
2454 cell_info->rsrp = rsrp_convert_to_minus_dBm(cell->value8);
2455 cell_info->rsrp_valid = (cell_info->rsrp!=INT_32_MAX);
2456
2457 cell_info->rsrq = rsrq_convert_to_minus_dB(cell->value9);
2458 cell_info->rsrq_valid = (cell_info->rsrq!=INT_32_MAX);
b.liu68a94c92025-05-24 12:53:41 +08002459
2460 cell_info->cell_id_valid = 1;
2461 cell_info->cell_id = cell->value10;
2462
2463 break;
2464 }
2465
2466 default:
2467 break;
2468 }
2469 }
q.huang638d5872025-06-21 13:44:43 +08002470 int neibor_count = 0;
b.liu68a94c92025-05-24 12:53:41 +08002471 while ((cell = (mbtk_cell_info_t*) list_next(cell_list)) && neibor_count < 5)
2472 {
2473 switch(type)
2474 {
2475 //GSM
2476 case 0:
2477 {
2478
2479 }
2480 //WCDMA
2481 case 1:
2482 {
q.huang934ec0e2025-07-22 19:56:59 +08002483 LOGE(GSW_NW,"CELL : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
b.liu68a94c92025-05-24 12:53:41 +08002484
2485 //cell_info->ext_info[neibor_count]->lac = cell->value1;
2486
2487 cell_info->ext_info[neibor_count].cell_id_valid = 1;
2488 cell_info->ext_info[neibor_count].cell_id = cell->value2;
2489
2490 cell_info->ext_info[neibor_count].arfcn_valid = 1;
2491 cell_info->ext_info[neibor_count].arfcn = cell->value3;
2492
2493 cell_info->ext_info[neibor_count].rat = cell_info->rat = GSW_NETWORK_RADIO_UMTS;
2494
2495 neibor_count++;
2496
2497 }
2498 //LTE
2499 case 2:
2500 {
q.huang934ec0e2025-07-22 19:56:59 +08002501 LOGE(GSW_NW,"CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
b.liu68a94c92025-05-24 12:53:41 +08002502 char lte_temp[12] = {0};
2503 cell_info->ext_info[neibor_count].rat = GSW_NETWORK_RADIO_LTE;
2504
q.huangdaa16d42025-07-03 14:32:48 +08002505
b.liu68a94c92025-05-24 12:53:41 +08002506 cell_info->ext_info[neibor_count].pci = cell->value1;
2507 cell_info->ext_info[neibor_count].pci_valid = 1;
2508
2509 cell_info->ext_info[neibor_count].arfcn = cell->value2;
2510 cell_info->ext_info[neibor_count].arfcn_valid = 1;
2511
q.huang638d5872025-06-21 13:44:43 +08002512 cell_info->ext_info[neibor_count].rsrp = rsrp_convert_to_minus_dBm(cell->value3);
2513 cell_info->ext_info[neibor_count].rsrp_valid = (cell_info->ext_info[neibor_count].rsrp!=INT_32_MAX);
b.liu68a94c92025-05-24 12:53:41 +08002514
q.huang638d5872025-06-21 13:44:43 +08002515 cell_info->ext_info[neibor_count].rsrq = rsrq_convert_to_minus_dB(cell->value4);
2516 cell_info->ext_info[neibor_count].rsrq_valid = (cell_info->ext_info[neibor_count].rsrq!=INT_32_MAX);
2517
2518 if(cell->value7!=INT_32_MAX)
2519 {
2520 cell_info->ext_info[neibor_count].cell_id = cell->value5;
2521 cell_info->ext_info[neibor_count].cell_id_valid = 1;
2522
2523 snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);
2524 strncpy(cell_info->ext_info[neibor_count].mcc, lte_temp, sizeof(cell_info->ext_info[neibor_count].mcc));
b.liu68a94c92025-05-24 12:53:41 +08002525
b.liu68a94c92025-05-24 12:53:41 +08002526
q.huang638d5872025-06-21 13:44:43 +08002527 snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);
2528 strncpy(cell_info->ext_info[neibor_count].mnc, lte_temp, sizeof(cell_info->ext_info[neibor_count].mnc));
2529
2530
2531 //value 8 is tac
b.liu68a94c92025-05-24 12:53:41 +08002532
q.huang638d5872025-06-21 13:44:43 +08002533 cell_info->ext_info[neibor_count].band = cell->value9;
2534 cell_info->ext_info[neibor_count].band_valid = 1;
q.huang638d5872025-06-21 13:44:43 +08002535 }
b.liu68a94c92025-05-24 12:53:41 +08002536
2537 neibor_count++;
2538 }
2539
2540 default:
2541 break;
2542 }
2543 }
q.huang638d5872025-06-21 13:44:43 +08002544 cell_info->ext_info_len=neibor_count;
b.liu68a94c92025-05-24 12:53:41 +08002545 }
2546 list_free(cell_list);
2547
2548 return GSW_HAL_SUCCESS;
2549}
2550
2551/*
2552 * @brief set modem status event callback
2553 @param [in] handle_ptr callback function address
2554 @retval 0: success
2555 @retval 0: other: fail
2556 */
2557int gsw_reg_set_modem_status_event_callback(GSW_NW_ModemStateHandlePtr handle_ptr)
2558{
2559
2560 if (nw_init_flag == 0 || nw_info_handle == NULL)
2561 {
xy.heb41615b2025-05-28 16:33:20 +08002562 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002563 }
2564
b.liu68a94c92025-05-24 12:53:41 +08002565 if(handle_ptr == NULL)
2566 {
q.huang934ec0e2025-07-22 19:56:59 +08002567 LOGE(GSW_NW,"reg modem state cb, handle_ptr is NULL\n");
b.liu68a94c92025-05-24 12:53:41 +08002568 }
2569
2570 modem_cb = handle_ptr;
2571
b.liu68a94c92025-05-24 12:53:41 +08002572 return GSW_HAL_SUCCESS;
b.liu68a94c92025-05-24 12:53:41 +08002573}
2574
2575
2576/*
2577 * @brief get PLMNs from the FPLMN list
2578 * @param [inout] plmn_list:
2579 * @retval 0: success
2580 * @retval other: fail
2581 */
2582int gsw_get_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
2583{
2584 if (nw_init_flag == 0 || nw_info_handle == NULL)
2585 {
xy.heb41615b2025-05-28 16:33:20 +08002586 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002587 }
2588
2589 int ret = -1;
2590 char fplmn[256] = {0};
q.huang934ec0e2025-07-22 19:56:59 +08002591 LOGE(GSW_NW,"mbtk_fplmn_get enter\n");
b.liu68a94c92025-05-24 12:53:41 +08002592 ret = mbtk_fplmn_get(nw_info_handle, fplmn);
q.huang934ec0e2025-07-22 19:56:59 +08002593 LOGE(GSW_NW,"mbtk_fplmn_get exit\n");
b.liu68a94c92025-05-24 12:53:41 +08002594 if(ret != 0)
2595 {
q.huang934ec0e2025-07-22 19:56:59 +08002596 LOGE(GSW_NW,"mbtk_fplmn_get failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002597 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002598 }
2599
2600 update_fplmn_list(fplmn);
2601 for(int i = 0; i < fplmn_index; i++)
2602 {
2603 if(strcmp(fplmn_array[i],"FFFFFF") == 0)
2604 {
2605 continue;
2606 }
2607 extract_mcc_mnc(fplmn_array[i], plmn_list->plmn_list[plmn_list->plmn_list_len].mcc, plmn_list->plmn_list[plmn_list->plmn_list_len].mnc);
q.huang934ec0e2025-07-22 19:56:59 +08002608 LOGE(GSW_NW,"mcc = %s, mnc = %s\n", plmn_list->plmn_list[plmn_list->plmn_list_len].mcc, plmn_list->plmn_list[plmn_list->plmn_list_len].mnc);
b.liu68a94c92025-05-24 12:53:41 +08002609 plmn_list->plmn_list_len++;
2610 }
2611
q.huang934ec0e2025-07-22 19:56:59 +08002612 LOGE(GSW_NW,"fplmn = %s\n", fplmn);
b.liu68a94c92025-05-24 12:53:41 +08002613 return GSW_HAL_SUCCESS;
2614}
2615
2616/*
2617 * @brief add PLMNs from the plmn_list to the FPLMN list
2618 * @param [in] plmn_list:
2619 * @retval 0: success
2620 * @retval other: fail
2621 */
2622int gsw_add_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
2623{
2624
2625 if (nw_init_flag == 0 || nw_info_handle == NULL)
2626 {
xy.heb41615b2025-05-28 16:33:20 +08002627 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002628 }
2629
2630 if(plmn_list->plmn_list_len >= fplmn_max_length)
2631 {
q.huang934ec0e2025-07-22 19:56:59 +08002632 LOGE(GSW_NW,"can't save all the plmn\n");
xy.heb41615b2025-05-28 16:33:20 +08002633 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002634 }
2635
2636 int i = 0;
2637 int index = -1;
2638
2639 for(i = 0; i < plmn_list->plmn_list_len; i++)
2640 {
2641 index = check_index(plmn_list->plmn_list[i].mcc, plmn_list->plmn_list[i].mnc);
2642
2643 if(index == -1)
2644 {
q.huang934ec0e2025-07-22 19:56:59 +08002645 LOGE(GSW_NW,"no this PLMN, add it\n");
b.liu68a94c92025-05-24 12:53:41 +08002646 if((fplmn_index + plmn_list->plmn_list_len) > fplmn_max_length)
2647 {
q.huang934ec0e2025-07-22 19:56:59 +08002648 LOGE(GSW_NW,"can't save all the plmn\n");
xy.heb41615b2025-05-28 16:33:20 +08002649 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002650 }
2651
2652 else
2653 {
2654 memcpy(fplmn_array[fplmn_index], plmn_list->plmn_list[i].mcc, 3);
2655 memcpy(fplmn_array[fplmn_index] + 3, plmn_list->plmn_list[i].mnc, 2);
2656 fplmn_array[fplmn_index][5] = '\0';
q.huang934ec0e2025-07-22 19:56:59 +08002657 LOGE(GSW_NW,"fplmn_array[%d] = %s\n", fplmn_index, fplmn_array[fplmn_index]);
b.liu68a94c92025-05-24 12:53:41 +08002658 fplmn_index++;
2659 }
2660 }
2661
2662 else
2663 {
q.huang934ec0e2025-07-22 19:56:59 +08002664 LOGE(GSW_NW,"already have this PLMN, don't add it\n");
b.liu68a94c92025-05-24 12:53:41 +08002665 }
2666 }
2667
2668 char fplmn_str[256] = {0};
2669 convert_plmn_to_fplmn_str(fplmn_str);
2670
q.huang934ec0e2025-07-22 19:56:59 +08002671 LOGE(GSW_NW,"fplmn_str = %s\n", fplmn_str);
b.liu68a94c92025-05-24 12:53:41 +08002672
2673 int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
2674 if(ret != 0)
2675 {
q.huang934ec0e2025-07-22 19:56:59 +08002676 LOGE(GSW_NW,"mbtk_fplmn_set failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002677 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002678 }
2679
q.huang934ec0e2025-07-22 19:56:59 +08002680 LOGE(GSW_NW,"gsw_add_forbidden_networks exit\n");
b.liu68a94c92025-05-24 12:53:41 +08002681 return GSW_HAL_SUCCESS;
2682}
2683
2684/*
2685 * @brief Remove PLMNs from the plmn_list from the FPLMN list
2686 * @param [in] plmn_list:
2687 * @retval 0: success
2688 * @retval other: fail
2689 */
2690int gsw_remove_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
2691{
b.liu68a94c92025-05-24 12:53:41 +08002692 if (nw_init_flag == 0 || nw_info_handle == NULL)
2693 {
q.huangfa0a0a32025-06-12 17:07:23 +08002694 printf("nw sdk has not init\n");
xy.heb41615b2025-05-28 16:33:20 +08002695 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002696 }
2697
2698 int i = 0;
2699 int index = -1;
2700
2701 for(i = 0; i < plmn_list->plmn_list_len; i++)
2702 {
2703 index = check_index(plmn_list->plmn_list[i].mcc, plmn_list->plmn_list[i].mnc);
2704 if(index != -1)
2705 {
2706 remove_fplmn(index);
2707 }
2708 else
2709 {
q.huang934ec0e2025-07-22 19:56:59 +08002710 LOGE(GSW_NW,"no this PLMN, can't remove it\n");
b.liu68a94c92025-05-24 12:53:41 +08002711 }
2712 }
2713
2714 for(i = 0; i < fplmn_index; i++)
2715 {
q.huang934ec0e2025-07-22 19:56:59 +08002716 LOGE(GSW_NW,"fplmn_array[%d] = %s\n", i, fplmn_array[i]);
b.liu68a94c92025-05-24 12:53:41 +08002717 }
2718
2719 char fplmn_str[256] = {0};
2720 convert_plmn_to_fplmn_str(fplmn_str);
q.huang934ec0e2025-07-22 19:56:59 +08002721 LOGE(GSW_NW,"fplmn_str = %s\n", fplmn_str);
b.liu68a94c92025-05-24 12:53:41 +08002722
2723 int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
2724 if(ret != 0)
2725 {
q.huang934ec0e2025-07-22 19:56:59 +08002726 LOGE(GSW_NW,"mbtk_fplmn_set failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002727 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002728 }
2729
q.huang934ec0e2025-07-22 19:56:59 +08002730 LOGE(GSW_NW,"gsw_remove_forbidden_networks exit\n");
b.liu68a94c92025-05-24 12:53:41 +08002731 return GSW_HAL_SUCCESS;
2732}
2733
2734/*
2735 * @brief clear FPLMN list
2736 * @param
2737 * @retval 0: success
2738 * @retval other: fail
2739 */
2740int gsw_clear_forbidden_networks(void)
2741{
2742 if (nw_init_flag == 0 || nw_info_handle == NULL)
2743 {
xy.heb41615b2025-05-28 16:33:20 +08002744 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002745 }
2746
2747 char fplmn_str[FPLMN_STRING_LENGTH+1];
2748 memset(fplmn_str, 'F', (6 * fplmn_max_length));
2749 fplmn_str[(6 * fplmn_max_length)] = '\0';
2750
q.huang934ec0e2025-07-22 19:56:59 +08002751 LOGE(GSW_NW,"%s\n", fplmn_str);
b.liu68a94c92025-05-24 12:53:41 +08002752 int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
2753 if(ret != 0)
2754 {
q.huang934ec0e2025-07-22 19:56:59 +08002755 LOGE(GSW_NW,"mbtk_fplmn_set failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002756 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002757 }
2758
2759 return GSW_HAL_SUCCESS;
2760}
2761
2762/*
2763 * @brief get oos config
2764 * @param [in] oos_config
2765 * @retval 0: success
2766 * @retval other: fail
2767 */
2768int gsw_oos_config_get(GSW_NW_OOS_CONFIG_INFO_T *pt_info)
2769{
2770 if (nw_init_flag == 0 || nw_info_handle == NULL)
2771 {
xy.heb41615b2025-05-28 16:33:20 +08002772 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002773 }
2774
2775 if(pt_info == NULL)
2776 {
q.huang934ec0e2025-07-22 19:56:59 +08002777 LOGE(GSW_NW,"pt_info is null\n");
xy.heb41615b2025-05-28 16:33:20 +08002778 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002779 }
2780
2781 int ret = -1;
2782
2783 mbtk_oos_info oos_info;
2784 memset(&oos_info, 0x00, sizeof(mbtk_oos_info));
2785
2786 ret = mbtk_oos_get(nw_info_handle, &oos_info);
2787 if(ret != 0)
2788 {
q.huang934ec0e2025-07-22 19:56:59 +08002789 LOGE(GSW_NW,"mbtk_oos_get failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002790 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002791 }
2792
2793 if(oos_info.mode == 0)
2794 {
2795 pt_info->t_min = 0;
2796 pt_info->t_step = 0;
2797 pt_info->t_max = 0;
2798 }
2799
2800 else
2801 {
2802 pt_info->t_min = (int)oos_info.oosPhase[0];
2803 pt_info->t_step = (int)oos_info.oosPhase[1];
2804 pt_info->t_max = (int)oos_info.oosPhase[2];
2805 }
2806
2807 return GSW_HAL_SUCCESS;
2808}
2809
2810
2811/*
2812 * @brief set oos config
2813 * @param [in] oos_config
2814 * @retval 0: success
2815 * @retval other: fail
2816 */
2817int gsw_oos_config_set(GSW_NW_OOS_CONFIG_INFO_T *pt_info)
2818{
2819 if (nw_init_flag == 0 || nw_info_handle == NULL)
2820 {
xy.heb41615b2025-05-28 16:33:20 +08002821 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002822 }
2823
2824 if(pt_info == NULL)
2825 {
q.huang934ec0e2025-07-22 19:56:59 +08002826 LOGE(GSW_NW,"pt_info is null\n");
xy.heb41615b2025-05-28 16:33:20 +08002827 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002828 }
2829
2830 int ret = -1;
2831 mbtk_oos_info oos_info;
2832 memset(&oos_info, 0x00, sizeof(mbtk_oos_info));
2833
2834 if (pt_info->t_min < 0 || pt_info->t_step < 0 || pt_info->t_max < 0)
2835 {
q.huang934ec0e2025-07-22 19:56:59 +08002836 LOGE(GSW_NW,"gsw_oos_config_set set time < 0 ");
xy.heb41615b2025-05-28 16:33:20 +08002837 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002838 }
2839 else if ((pt_info->t_min > 0 && pt_info->t_min <= 255) && pt_info->t_step == 0 && pt_info->t_max == 0)
2840 {
2841 oos_info.mode = 1;
2842 oos_info.oosPhase[0] = pt_info->t_min;
2843 }
2844 else if ((pt_info->t_min > 0 && pt_info->t_min <= 255) && (pt_info->t_step > 0 && pt_info->t_step <= 255) && pt_info->t_max == 0)
2845 {
2846 oos_info.mode = 1;
2847 oos_info.oosPhase[0] = pt_info->t_min;
2848 oos_info.oosPhase[1] = pt_info->t_step;
2849 }
2850 else if ((pt_info->t_min > 0 && pt_info->t_min <= 255) && (pt_info->t_step > 0 && pt_info->t_step <= 255) && (pt_info->t_max > 0 && pt_info->t_max <= 255))
2851 {
2852 oos_info.mode = 1;
2853 oos_info.oosPhase[0] = pt_info->t_min;
2854 oos_info.oosPhase[1] = pt_info->t_step;
2855 oos_info.oosPhase[2] = pt_info->t_max;
2856 }
2857 else if (pt_info->t_min == 0 && pt_info->t_step == 0 && pt_info->t_max == 0)
2858 {
2859 oos_info.mode = 0;
2860 }
2861 else
2862 {
q.huang934ec0e2025-07-22 19:56:59 +08002863 LOGE(GSW_NW,"gsw_oos_config_set set Format err");
xy.heb41615b2025-05-28 16:33:20 +08002864 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002865 }
2866
2867 ret = mbtk_oos_set(nw_info_handle, &oos_info);
2868 if(ret != 0)
2869 {
q.huang934ec0e2025-07-22 19:56:59 +08002870 LOGE(GSW_NW,"mbtk_oos_set failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002871 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002872 }
2873
2874 return GSW_HAL_SUCCESS;
2875}
2876
q.huang238b22a2025-06-10 14:36:59 +08002877/**
2878 * @brief get imei function
2879 * @param [in] len imei length,max is 20
2880 * @param [out] imei return imei from this func
2881 * @retval 0: success
2882 * @retval other: fail
2883 */
2884int gsw_get_imei(int len, char *imei)
2885{
q.huang238b22a2025-06-10 14:36:59 +08002886 if (nw_init_flag == 0 || nw_info_handle == NULL)
2887 {
2888 printf("nw sdk has been deinit\n");
2889 return GSW_HAL_NORMAL_FAIL;
2890 }
2891
2892 if(imei == NULL)
2893 {
q.huang934ec0e2025-07-22 19:56:59 +08002894 LOGE(GSW_NW,"imei is NULL.");
q.huang238b22a2025-06-10 14:36:59 +08002895 return GSW_HAL_ARG_INVALID;
2896 }
2897
2898 if(len < GSW_IMEI_LENGTH)
2899 {
q.huang934ec0e2025-07-22 19:56:59 +08002900 LOGE(GSW_NW,"imei len is too short,len = %d\n", len);
q.huang238b22a2025-06-10 14:36:59 +08002901 return GSW_HAL_NORMAL_FAIL;
2902 }
2903
q.huang861c07d2025-06-24 16:54:58 +08002904 int ret = mbtk_imei_get(nw_info_handle, (void *)imei);
q.huang238b22a2025-06-10 14:36:59 +08002905 if(ret != MBTK_ERR_OK)
2906 {
q.huang934ec0e2025-07-22 19:56:59 +08002907 LOGE(GSW_NW,"[gsw_nw] mbtk_imei_get fail [err = %d].", ret);
q.huang238b22a2025-06-10 14:36:59 +08002908 return GSW_HAL_NORMAL_FAIL;
2909 }
2910
2911 return GSW_HAL_SUCCESS;
2912}
2913
2914/**
2915 * @brief reset modem stack only, notice: after use this method, all ril sdk
2916 * need restart by app, means network, sim, sms, data need deinit then init!
2917 * @param
2918 * @retval 0: success
2919 * @retval other: fail
2920 */
2921int gsw_reset_modem(void)
2922{
2923 int ret = -1;
2924 if (nw_init_flag == 0 || nw_info_handle == NULL)
2925 {
2926 printf("nw sdk has been deinit\n");
2927 return GSW_HAL_NORMAL_FAIL;
2928 }
2929 mbtk_modem_info_t info;
2930 info.fun = MBTK_DEV_MODEM_MIN_FUN;
2931 info.rst = 0;
2932
2933 ret = mbtk_set_modem_fun(nw_info_handle, &info);
2934 if(ret)
2935 {
q.huang934ec0e2025-07-22 19:56:59 +08002936 LOGE(GSW_NW,"[gsw_nw] mbtk_set_modem_fun 0 fail [err = %d].", ret);
q.huang238b22a2025-06-10 14:36:59 +08002937 return GSW_HAL_NORMAL_FAIL;
2938 }
2939
2940 sleep(1);
2941
2942 info.fun = MBTK_DEV_MODEM_FULL_FUN;
2943 ret = mbtk_set_modem_fun(nw_info_handle, &info);
2944 if(ret)
2945 {
q.huang934ec0e2025-07-22 19:56:59 +08002946 LOGE(GSW_NW,"[gsw_nw] mbtk_set_modem_fun 1 fail [err = %d].", ret);
q.huang238b22a2025-06-10 14:36:59 +08002947 return GSW_HAL_NORMAL_FAIL;
2948 }
2949 return GSW_HAL_SUCCESS;
2950}
b.liu68a94c92025-05-24 12:53:41 +08002951
q.huangc8b93122025-06-17 17:46:05 +08002952int gsw_reg_operating_mode_callback(GSW_NW_AirplaneModeHandlePtr handle_ptr)
2953{
2954 if (nw_init_flag == 0 || nw_info_handle == NULL)
2955 {
2956 return GSW_HAL_NORMAL_FAIL;
2957 }
q.huang934ec0e2025-07-22 19:56:59 +08002958
2959 void* cb_func;
q.huangc8b93122025-06-17 17:46:05 +08002960 if(handle_ptr == NULL)
2961 {
q.huang934ec0e2025-07-22 19:56:59 +08002962 LOGE(GSW_NW,"reg airplane mode cb is NULL");
2963 cb_func=NULL;
q.huangc8b93122025-06-17 17:46:05 +08002964 }
q.huang934ec0e2025-07-22 19:56:59 +08002965 else
2966 {
2967 cb_func=(void*) gsw_operating_mode_event_callback;
q.huangc8b93122025-06-17 17:46:05 +08002968 }
q.huangc8b93122025-06-17 17:46:05 +08002969
q.huang934ec0e2025-07-22 19:56:59 +08002970 int ret = mbtk_radio_state_change_cb_reg(nw_info_handle, cb_func);
2971
2972 if (ret != 0)
2973 {
2974 LOGE(GSW_NW,"mbtk_radio_state_change_cb_reg fail, ret is %d",ret);
2975 return GSW_HAL_NORMAL_FAIL;
2976 }
2977
2978 airplane_cb = handle_ptr;
2979
2980 if(airplane_cb !=NULL)
2981 {
2982 int opmode;
2983 ret = gsw_get_opmode(&opmode);
2984 if(ret == 0)
2985 {
2986 airplane_cb(opmode);
2987 }
2988 else
2989 {
2990 LOGE(GSW_NW,"gsw_get_opmode fail, ret is%d", ret);
2991 }
2992 }
2993
2994 return GSW_HAL_SUCCESS;
q.huangc8b93122025-06-17 17:46:05 +08002995}
2996
hong.liud2417072025-06-27 07:10:37 -07002997int gsw_get_apn_reserved_id(const char *apn)
2998{
2999 return 0;
3000}
3001
3002int gsw_set_apn_reserved_id(int reserved_id, const char *apn)
3003{
3004 return 0;
3005}
3006
3007int gsw_data_call_clear_session(int linkid, Link_Info_s *LinkInf)
3008{
3009 return 0;
3010}
3011
3012void *gsw_onUnsolicited(void *arg)
3013{
3014 return 0;
3015}
3016
3017int gsw_sdk_init(void)
3018{
3019 return 0;
3020}
3021
3022int gsw_get_modem_state_exp(void)
3023{
3024 return 0;
3025}