blob: b613a1ab2fdbee13f7058824240bae1ccaf4c04f [file] [log] [blame]
b.liu68a94c92025-05-24 12:53:41 +08001#include "gsw_nw_interface.h"
2#include <dlfcn.h>
3#include <time.h>
4#include <pthread.h>
q.huang66b79162025-06-27 17:45:34 +08005#include <cutils/properties.h>
cz.lif4a9a932025-06-05 11:37:59 +08006#define SIG_TIMER 5
q.huang66b79162025-06-27 17:45:34 +08007#define MODEM_TIMER 5
8
b.liu68a94c92025-05-24 12:53:41 +08009//mbtk include
10#define LYNQ_AIR_PLANE_MODE_OFF 1 //at+cfun = 1
11#define LYNQ_AIR_PLANE_MODE_ON 4 // at+cfun = 4
12#define LYNQ_AIR_CFUN_MODE_OFF 0 // at+cfun = 0
13
14#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
15
16#define FPLMN_STRING_LENGTH 120
17#define ENTRY_LENGTH 6
18#define FPLMN_ARRAY_SIZE (FPLMN_STRING_LENGTH / 6) + 1
19
q.huang238b22a2025-06-10 14:36:59 +080020#define MBTK_ERR_OK 0
xf.li56b78fb2025-06-13 03:29:21 -070021#define GSW_IMEI_LENGTH 15+1
q.huang238b22a2025-06-10 14:36:59 +080022
q.huangfa0a0a32025-06-12 17:07:23 +080023#define INT_32_MAX (0x7FFFFFFF)
24
q.huang238b22a2025-06-10 14:36:59 +080025
b.liu68a94c92025-05-24 12:53:41 +080026#ifndef FALSE
27#define FALSE (0)
28#endif
29
30
31#ifndef TRUE
32#define TRUE (!FALSE)
33#endif
34
35typedef unsigned int uint32;
36typedef unsigned char uint8;
q.huang861c07d2025-06-24 16:54:58 +080037typedef signed char int8;
b.liu68a94c92025-05-24 12:53:41 +080038typedef unsigned short uint16;
39typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
40
q.huang66b79162025-06-27 17:45:34 +080041#define MBTK_READY_UCI "persist.mbtk.sdk.state"
42#define MBTK_READY_STRING_SIZE_MAX (3+1)
43
44
45typedef enum{
46 MBTK_READY_INIT = -1,
47 MBTK_READY_SUCCESS,
48 MBTK_READY_MODEM_FAIL,
49 MBTK_READY_RESPONSE_FAIL,
50 MBTK_READY_SOCKET_FAIL,
51 MBTK_READY_RIL_FAIL
52}mbtk_ready_status_type;
53
54bool str_empty(const void *str);
55
b.liu68a94c92025-05-24 12:53:41 +080056typedef enum
57{
58 MBTK_DEV_MODEM_MIN_FUN, //Modem 最小功能
59 MBTK_DEV_MODEM_FULL_FUN, //Modem 全功能
60 MBTK_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS = 3, //Modem 禁用射频接收电路
61 MBTK_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS, //Modem禁用射频发射和接收电路
62 MBTK_DEV_MODEM_DISABLE_SIM, //Modem 禁用(U)SIM 卡
63 MBTK_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE, //Modem 完全禁用辅助接收
64}MBTK_DEV_MODEM_FUNCTION;
65
66typedef enum
67{
68 MBTK_CELL_TYPE_GSM = 0,
69 MBTK_CELL_TYPE_UMTS,
70 MBTK_CELL_TYPE_LTE
71} mbtk_cell_type_enum;
72
73typedef struct
74{
75 MBTK_DEV_MODEM_FUNCTION fun;
76 int rst;
77} mbtk_modem_info_t;
78
79typedef struct
80{
81 int client_fd;
82 pthread_t read_thread_id;
83 int exit_fd[2];
84 bool is_waitting;
85 pthread_cond_t cond;
86 pthread_mutex_t mutex;
87
88 pthread_mutex_t send_mutex;
89
90 // Temp response data.
91 uint16 info_err;
92 uint16 data_len;
93 void *data;
94
95 //mbtk wyq for server_ready_status add start
96 char server_ready_status;
97 //mbtk wyq for server_ready_status add end
98
99 mbtk_info_callback_func net_state_cb;
100 mbtk_info_callback_func call_state_cb;
101 mbtk_info_callback_func sms_state_cb;
102 mbtk_info_callback_func radio_state_cb;
103 mbtk_info_callback_func sim_state_cb;
104 mbtk_info_callback_func pdp_state_cb;
105 //add signal by xr
106 mbtk_info_callback_func signal_state_cb;
107} mbtk_info_handle_t;
108
109
110
111typedef struct
112{
q.huang638d5872025-06-21 13:44:43 +0800113 // NR server cell:
114 // NR cell:
b.liu68a94c92025-05-24 12:53:41 +0800115 // LTE server cell: tac, PCI, dlEuarfcn, ulEuarfcn, band
116 // LTE cell: phyCellId,euArfcn,rsrp,rsrq
117 // WCDMA server cell: lac, ci, arfcn
118 // WCDMA cell: lac, ci, arfcn
119 // GSM server cell: lac, ci, arfcn, bsic
120 // GSM cell:
q.huang638d5872025-06-21 13:44:43 +0800121 uint32 value1; //tac
122 uint32 value2; //pci
123 uint32 value3; //dlEuarfcn
124 uint32 value4; //bler
125 uint32 value5; //band
126 uint32 value6; //mcc
127 uint32 value7; //mnc
128 uint32 value8; //rsrp
129 uint32 value9; //rsrq
130 uint32 value10; //cell identiy
131 uint32 value11; //sinr
132 uint32 value12; //is tdd
133 uint32 value13;
134 uint32 value14;
135 uint32 value15;
b.liu68a94c92025-05-24 12:53:41 +0800136} __attribute__((packed)) mbtk_cell_info_t;
137
138
b.liu68a94c92025-05-24 12:53:41 +0800139typedef struct
140{
141 uint8 net_pref; // mbtk_net_pref_enum
142 uint16 gsm_band; // mbtk_gsm_band_enum
143 uint16 umts_band; // mbtk_umts_band_enum
144 uint32 tdlte_band; // mbtk_tdlte_band_enum
145 uint32 fddlte_band; // mbtk_fddlte_band_enum
146 uint32 lte_ext_band; // mbtk_lte_ext_band_enum
147} __attribute__((packed)) mbtk_band_info_t;
148
149typedef struct list_arraynode
150{
151 void *data;
152 struct list_arraynode *next;
153} list_arraynode_t;
154
155typedef struct list_treenode
156{
157 list_arraynode_t *data;
158 int count;
159 struct list_treenode *left;
160 struct list_treenode *right;
161} list_treenode_t;
162
163typedef int (*list_sort_func)(void *data1, void *data2);
164typedef void (*list_free_func)(void *data);
165
166typedef struct list_node
167{
168 uint32 size;
169 list_sort_func sort_func;
170 list_free_func free_func;
171
172 uint32 cur_index;
173 list_arraynode_t *cur_array_data;
174
175 list_arraynode_t array_data;
176 list_treenode_t tree_data;
177} list_node_t;
178
179/*
1800: GSM
1811: GSM Compact
1822: UTRAN
1833: GSM w/EGPRS
1844: UTRAN w/HSDPA
1855: UTRAN w/HSUPA
1866: UTRAN w/HSDPA and HSUPA
1877: E-UTRAN
1888: UTRAN HSPA+
189*/
190typedef enum {
191 MBTK_RADIO_TECH_GSM = 0,
192 MBTK_RADIO_TECH_GSM_COMPACT,
193 MBTK_RADIO_TECH_UTRAN,
194 MBTK_RADIO_TECH_GSM_EGPRS,
195 MBTK_RADIO_TECH_UTRAN_HSDPA,
196 MBTK_RADIO_TECH_UTRAN_HSUPA,
197 MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA,
198 MBTK_RADIO_TECH_E_UTRAN, // LTE
199 MBTK_RADIO_TECH_UTRAN_HSPA
200} mbtk_radio_technology_enum;
201
202typedef struct
203{
204 /*
205 0: automatic
206 1: manual
207 */
208 uint8 net_sel_mode;
209 /*
210 0: GSM
211 1: GSM Compact
212 2: UTRAN
213 3: GSM w/EGPRS
214 4: UTRAN w/HSDPA
215 5: UTRAN w/HSUPA
216 6: UTRAN w/HSDPA and HSUPA
217 7: E-UTRAN
218 8: UTRAN HSPA+
219 0xFF: Unused
220 */
221 uint8 net_type;
222 //uint8 plmn[10]; // 46000
223 /*
224 0: unknown
225 1: available
226 2: current
227 3: forbidden
228 */
229 uint8 net_state;
230 uint32 plmn;
231} __attribute__((packed)) mbtk_net_info_t;
232
233
234typedef enum
235{
236 MBTK_NET_REG_STATE_NON = 0,
237 MBTK_NET_REG_STATE_HOME,
238 MBTK_NET_REG_STATE_SEARCHING,
239 MBTK_NET_REG_STATE_DENIED,
240 MBTK_NET_REG_STATE_UNKNOWN,
241 MBTK_NET_REG_STATE_ROAMING,
242 MBTK_NET_REG_STATE_SMS_ONLY,
243 MBTK_NET_REG_STATE_ROAMING_SMS,
244 MBTK_NET_REG_STATE_ATTACHED_EMERGENCY,
245 MBTK_NET_REG_STATE_CSFB_HOME,
246 MBTK_NET_REG_STATE_CSFB_ROAMING,
247 MBTK_NET_REG_STATE_EMERGENCY_ONLY
248} mbtk_net_reg_state_enum;
249
250typedef struct
251{
252 uint8 call_state;// mbtk_net_reg_state_enum
253 uint8 data_state;// mbtk_net_reg_state_enum
254 uint8 ims_state;// mbtk_net_reg_state_enum
255 uint8 type; // mbtk_radio_technology_enum
256 uint16 lac;
257 uint32 ci;
258} __attribute__((packed)) mbtk_net_reg_info_t;
259
260typedef struct
261{
262 uint8 type; // mbtk_radio_technology_enum
263 uint8 rssi; // 0: 113 dBm or less
264 // 1: 111 dBm
265 // 2��30: 109��53 dBm
266 // 31: 51 dBm or greater
267 // 99: not known or not detectable
268 uint8 rxlev;// 0:rssi < -110 dBm
269 // 1: -110 dBm �� rssi < -109 dBm
270 // 2: -109 dBm �� rssi < -108 dBm
271 // ......
272 // 61: -50 dBm �� rssi < -49 dBm
273 // 62: -49 dBm �� rssi < -48 dBm
274 // 63: -48 dBm �� rssi
275 // 99: not known or not detectable
276 uint8 ber; // 0...7 as RXQUAL values in the table in 3GPP TS 45.008 [20] subclause 8.2.4
277 // 99 not known or not detectable
278 uint8 rscp; // 0: rscp < -120 dBm
279 // 1: -120 dBm �� rscp < -119 dBm
280 // 2: -119 dBm �� rscp < -118 dBm
281 // ......
282 // 94: -27 dBm �� rscp < -26 dBm
283 // 95: -26 dBm �� rscp < -25 dBm
284 // 96: - 25 dBm �� rscp
285 // 255: not known or not detectable
286 uint8 ecno; // 0: Ec/Io < -24 dB
287 // 1: -24 dB �� Ec/Io < -23.5 dB
288 // 2: -23.5 dB �� Ec/Io < -23 dB
289 // ......
290 // 47: -1 dB �� Ec/Io < -0.5 dB
291 // 48: -0.5 dB �� Ec/Io < 0 dB
292 // 49: 0 dB �� Ec/Io
293 // 255: not known or not detectable
294 uint8 rsrq; // 0: rsrq < -19.5 dB
295 // 1: -19.5 dB �� rsrq < -19 dB
296 // 2: -19 dB �� rsrq < -18.5 dB
297 // ......
298 // 32: -4 dB �� rsrq < -3.5 dB
299 // 33: -3.5 dB �� rsrq < -3 dB
300 // 34: -3 dB �� rsrq
301 // 255: not known or not detectable
302 uint8 rsrp; // 0: rsrp < -140 dBm
303 // 1: -140 dBm �� rsrp < -139 dBm
304 // 2: -139 dBm �� rsrp < -138 dBm
305 // ......
306 // 95: -46 dBm �� rsrp < -45 dBm
307 // 96: -45 dBm �� rsrp < -44 dBm
308 // 97: -44 dBm �� rsrp
309 // 255: not known or not detectable
q.huang861c07d2025-06-24 16:54:58 +0800310 int8 sinr; //-20-35 dbm
b.liu68a94c92025-05-24 12:53:41 +0800311} __attribute__((packed)) mbtk_signal_info_t;
312
313typedef struct{
314 uint8_t mode;
315 uint32_t oosPhase[3]; //单位为秒
316} mbtk_oos_info;
317
318typedef struct
319{
320 /* Configuration parameters for MCM network full band network scan when OOS (out of service)*/
321 int t_min;
322 int t_step;
323 int t_max;
324}GSW_NW_OOS_CONFIG_INFO_T;
325
b.liu68a94c92025-05-24 12:53:41 +0800326#define lib_mbtk_path "/lib/libmbtk_lib.so"
327mbtk_info_handle_t* nw_info_handle = NULL;
328
q.huang638d5872025-06-21 13:44:43 +0800329static GSW_NW_ServingInfoHandlePtr serving_cb=NULL;
330static GSW_NW_SigInfoHandlePtr sig_cb=NULL;
331static GSW_NW_RejectCauseHandlePtr reject_cb=NULL;
332static GSW_NW_ModemStateHandlePtr modem_cb=NULL;
333static GSW_NW_AirplaneModeHandlePtr airplane_cb=NULL;
b.liu68a94c92025-05-24 12:53:41 +0800334
335static void *dlHandle_mbtk;
336int nw_init_flag = 0;
337int mode = -1;
338int fplmn_max_length = 0;
339
340gsw_nw_plmn_list_t gsw_nw_plmn_list;
341char fplmn_array[FPLMN_ARRAY_SIZE][7];
342int fplmn_index = 0;
343
344static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
345static int (*mbtk_info_handle_free)(mbtk_info_handle_t** handle);
346int (*mbtk_net_sel_mode_get)(mbtk_info_handle_t* handle, mbtk_net_info_t *net);
347int (*mbtk_net_reg_get)(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg);
348int (*mbtk_cell_get)(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list);
349int (*mbtk_get_modem_fun)(mbtk_info_handle_t* handle, int* fun);
350static int (*mbtk_set_modem_fun)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info);
351int (*mbtk_current_band_get)(mbtk_info_handle_t* handle, mbtk_band_info_t *band);
352int (*mbtk_current_band_set)(mbtk_info_handle_t* handle, const mbtk_band_info_t *band);
353int (*mbtk_net_signal_get)(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal);
354int (*mbtk_wakeup_state_set)(mbtk_info_handle_t* handle, uint32 wakeup_state);
355int (*mbtk_signal_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
356int (*mbtk_net_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
357int (*mbtk_fplmn_get)(mbtk_info_handle_t *handle, void *fplmn);
358int (*mbtk_fplmn_set)(mbtk_info_handle_t *handle, void *fplmn);
359int (*mbtk_radio_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
360int (*mbtk_oos_get)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);
361int (*mbtk_oos_set)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);
q.huang238b22a2025-06-10 14:36:59 +0800362int (*mbtk_imei_get)(mbtk_info_handle_t* handle, void *imei);
363
b.liu68a94c92025-05-24 12:53:41 +0800364
365static void (*mbtk_log)(int level, const char *format, ...);
366static void (*mbtk_log_init)(char *path, char *tag);
367
368#ifndef LOG_ERR_LEVEL
369#define LOG_ERR_LEVEL 3 /* error conditions */
370#endif
371#ifndef LOG_WARN_LEVEL
372#define LOG_WARN_LEVEL 4 /* warning conditions */
373#endif
374#ifndef LOG_INFO_LEVEL
375#define LOG_INFO_LEVEL 6 /* informational */
376#endif
377#ifndef LOG_DEBUG_LEVEL
378#define LOG_DEBUG_LEVEL 7 /* debug-level messages */
379#endif
380#ifndef LOG_VERBOSE_LEVEL
381#define LOG_VERBOSE_LEVEL 8
382#endif
383
l.yang6a42e4d2025-05-28 01:04:20 -0700384#define GSW_NW "[HAL][GSW_NW]"
385
b.liu68a94c92025-05-24 12:53:41 +0800386#define LOGV(fmt, args ...) \
387 do{ \
388 char *file_ptr_1001 = __FILE__; \
389 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
390 char line_1001[10] = {0}; \
391 sprintf(line_1001, "%d", __LINE__); \
392 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
393 if(*ptr_1001 == '/') \
394 break; \
395 ptr_1001--; \
396 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700397 mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_NW"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800398 } while(0)
399
400#define LOGI(fmt, args...) \
401 do{ \
402 char *file_ptr_1001 = __FILE__; \
403 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
404 char line_1001[10] = {0}; \
405 sprintf(line_1001, "%d", __LINE__); \
406 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
407 if(*ptr_1001 == '/') \
408 break; \
409 ptr_1001--; \
410 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700411 mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_NW"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800412 } while(0)
413
414#define LOGD(fmt, args...) \
415 do{ \
416 char *file_ptr_1001 = __FILE__; \
417 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
418 char line_1001[10] = {0}; \
419 sprintf(line_1001, "%d", __LINE__); \
420 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
421 if(*ptr_1001 == '/') \
422 break; \
423 ptr_1001--; \
424 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700425 mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_NW"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800426 } while(0)
427
428#define LOGW(fmt, args...) \
429 do{ \
430 char *file_ptr_1001 = __FILE__; \
431 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
432 char line_1001[10] = {0}; \
433 sprintf(line_1001, "%d", __LINE__); \
434 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
435 if(*ptr_1001 == '/') \
436 break; \
437 ptr_1001--; \
438 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700439 mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_NW"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800440 } while(0)
441
442#define LOGE(fmt, args...) \
443 do{ \
q.huangfa0a0a32025-06-12 17:07:23 +0800444 char *file_ptr_1001 = __FILE__; \
b.liu68a94c92025-05-24 12:53:41 +0800445 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
446 char line_1001[10] = {0}; \
447 sprintf(line_1001, "%d", __LINE__); \
448 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
449 if(*ptr_1001 == '/') \
450 break; \
451 ptr_1001--; \
452 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700453 mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_NW"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800454 } while(0)
455
456
457
458typedef struct
459{
460 char *lynq_operator_l;
461 char *lynq_operator_s;
462 uint32 lynq_mcc_mnc;
463} lynq_operator_mcc_mnc_t;
464
465static lynq_operator_mcc_mnc_t lynq_operator_mcc_mnc[] =
466{
467 {"China Mobile","CMCC",46000},
468 {"China Unicom","CU",46001},
469 {"China Mobile","CMCC",46002},
470 {"China Telecom","CT",46003},
471 {"China Mobile","CMCC",46004},
472 {"China Telecom","CT",46005},
473 {"China Unicom","CU",46006},
474 {"China Mobile","CMCC",46007},
475 {"China Mobile","CMCC",46008},
476 {"China Unicom","CU",46009},
477 {"China Telecom","CT",46011}
478};
479
480
481//GSW include
482typedef enum prefer_mode
483{
484 GSW_PREFER_MODE_GSW = 1, /**<2G only*/
485 GSW_PREFER_MODE_WCDMA = 2, /**< 3G only*/
486 GSW_PREFER_MODE_WCDMA_GSM = 3, /**< 3G/2G*/
487 GSW_PREFER_MODE_LTE = 4, /**< 4G only*/
488 GSW_PREFER_MODE_NR5G = 5, /**< 5G only*/
489 GSW_PREFER_MODE_NR5G_LTE = 8, /**< 5G/4G*/
490 GSW_PREFER_MODE_LTE_WCDMA_GSM = 9, /**< 4G/3G/2G*/
491 GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM = 32, /**< 5G/4G/3G/2G*/
492} PREFER_MODE_E;
493
494static int mbtk_nw_api_import()
495{
496 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
497 if (dlHandle_mbtk == NULL)
498 {
xy.heb41615b2025-05-28 16:33:20 +0800499 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800500 }
501
502 mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
503 if (mbtk_log_init == NULL)
504 {
xy.heb41615b2025-05-28 16:33:20 +0800505 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800506 }
507
508 mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
509 if (mbtk_log == NULL)
510 {
xy.heb41615b2025-05-28 16:33:20 +0800511 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800512 }
513
514 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
515 if (mbtk_info_handle_get == NULL)
516 {
517 LOGE("mbtk_info_handle_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800518 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800519 }
520
521 mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free");
522 if (mbtk_info_handle_free == NULL)
523 {
524 LOGE("mbtk_info_handle_free dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800525 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800526 }
527
528 mbtk_net_sel_mode_get = (int (*)(mbtk_info_handle_t* handle, mbtk_net_info_t *net))dlsym(dlHandle_mbtk, "mbtk_net_sel_mode_get");
529 if (mbtk_net_sel_mode_get == NULL)
530 {
531 LOGE("mbtk_net_sel_mode_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800532 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800533 }
534
535 mbtk_net_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_net_reg_get");
536 if (mbtk_net_reg_get == NULL)
537 {
538 LOGE("mbtk_net_reg_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800539 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800540 }
541
542 mbtk_get_modem_fun = (int (*)(mbtk_info_handle_t* handle, int* fun))dlsym(dlHandle_mbtk, "mbtk_get_modem_fun");
543 if (mbtk_get_modem_fun == NULL)
544 {
545 LOGE("mbtk_get_modem_fun dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800546 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800547 }
548
549 mbtk_set_modem_fun = (int (*)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info))dlsym(dlHandle_mbtk, "mbtk_set_modem_fun");
550 if (mbtk_set_modem_fun == NULL)
551 {
552 LOGE("mbtk_set_modem_fun dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800553 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800554 }
555
556 mbtk_current_band_get = (int (*)(mbtk_info_handle_t* handle, mbtk_band_info_t *band))dlsym(dlHandle_mbtk, "mbtk_current_band_get");
557 if (mbtk_current_band_get == NULL)
558 {
559 LOGE("mbtk_current_band_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800560 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800561 }
562
563 mbtk_current_band_set = (int (*)(mbtk_info_handle_t* handle, const mbtk_band_info_t *band))dlsym(dlHandle_mbtk, "mbtk_current_band_set");
564 if (mbtk_current_band_set == NULL)
565 {
566 LOGE("mbtk_current_band_set dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800567 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800568 }
569
570 mbtk_net_signal_get = (int (*)(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal))dlsym(dlHandle_mbtk, "mbtk_net_signal_get");
571 if (mbtk_net_signal_get == NULL)
572 {
573 LOGE("mbtk_net_signal_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800574 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800575 }
576
577 mbtk_wakeup_state_set = (int (*)(mbtk_info_handle_t* handle, uint32 wakeup_state))dlsym(dlHandle_mbtk, "mbtk_wakeup_state_set");
578 if (mbtk_wakeup_state_set == NULL)
579 {
580 LOGE("mbtk_wakeup_state_set dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800581 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800582 }
583
584 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");
585 if (mbtk_cell_get == NULL)
586 {
587 LOGE("mbtk_cell_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800588 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800589 }
590
591 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");
592 if (mbtk_signal_state_change_cb_reg == NULL)
593 {
594 LOGE("mbtk_signal_state_change_cb_reg dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800595 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800596 }
597
598 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");
599 if (mbtk_net_state_change_cb_reg == NULL)
600 {
601 LOGE("mbtk_net_state_change_cb_reg dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800602 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800603 }
604
605 mbtk_fplmn_get = (int(*)(mbtk_info_handle_t *handle, void *fplmn))dlsym(dlHandle_mbtk, "mbtk_fplmn_get");
606 if (mbtk_fplmn_get == NULL)
607 {
608 LOGE("mbtk_fplmn_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800609 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800610 }
611
612 mbtk_fplmn_set = (int(*)(mbtk_info_handle_t *handle, void *fplmn))dlsym(dlHandle_mbtk, "mbtk_fplmn_set");
613 if (mbtk_fplmn_set == NULL)
614 {
615 LOGE("mbtk_fplmn_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800616 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800617 }
618
619 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");
620 if (mbtk_radio_state_change_cb_reg == NULL)
621 {
622 LOGE("mbtk_radio_state_change_cb_reg dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800623 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800624 }
625
626 mbtk_oos_get = (int (*)(mbtk_info_handle_t* handle, mbtk_oos_info *oos))dlsym(dlHandle_mbtk, "mbtk_oos_get");
627 if (mbtk_oos_get == NULL)
628 {
629 LOGE("mbtk_oos_get dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800630 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800631 }
632
633 mbtk_oos_set = (int (*)(mbtk_info_handle_t* handle, mbtk_oos_info *oos))dlsym(dlHandle_mbtk, "mbtk_oos_set");
634 if (mbtk_oos_set == NULL)
635 {
636 LOGE("mbtk_oos_set dlsym fail\n");
xy.heb41615b2025-05-28 16:33:20 +0800637 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800638 }
q.huang238b22a2025-06-10 14:36:59 +0800639
640 mbtk_imei_get = (int (*)(mbtk_info_handle_t* handle, void *imei))dlsym(dlHandle_mbtk, "mbtk_imei_get");
641 if (mbtk_imei_get == NULL)
642 {
643 LOGE("mbtk_imei_get dlsym fail\n");
644 return GSW_HAL_NORMAL_FAIL;
645 }
b.liu68a94c92025-05-24 12:53:41 +0800646
647 return GSW_HAL_SUCCESS;
648}
649
650void list_first(list_node_t *list)
651{
652 if (list) {
653 list->cur_index = 0;
654 list->cur_array_data = list->array_data.next;
655 }
656}
657
658void* list_next(list_node_t *list)
659{
660 if (list) {
661 list_arraynode_t *node = list->cur_array_data;
662 if (node) {
663 LOGE("node is not null\n");
664 list->cur_array_data = list->cur_array_data->next;
665 list->cur_index++;
666 return node->data;
667 } else {
668 LOGE("node is null\n");
669 return NULL;
670 }
671 } else {
672 LOGE("list is null\n");
673 return NULL;
674 }
675}
676
677void list_free(list_node_t *list)
678{
679 if (list) {
680 list_arraynode_t *node = &(list->array_data); // Head node
681 list_arraynode_t *node_temp = NULL;
682 while (node->next) {
683 node_temp = node->next;
684 node->next = node->next->next;
685
686 if (list->free_func) {
687 list->free_func(node_temp->data);
688 } else {
689 free(node_temp->data);
690 }
691 free(node_temp);
692 }
693 free(list);
694 }
695}
696
q.huang861c07d2025-06-24 16:54:58 +0800697#if 0
q.huang638d5872025-06-21 13:44:43 +0800698static int32_t gsm_rssi_convert_to_dBm(uint8 rssi)
699{
700 if(rssi <= 31)
701 {
702 return rssi * 2 - 113; //0 map -113
703 //31 map -51
704 }
705 else
706 {
707 return INT_32_MAX;
708 }
709}
q.huang861c07d2025-06-24 16:54:58 +0800710#endif
q.huang638d5872025-06-21 13:44:43 +0800711
q.huangfa0a0a32025-06-12 17:07:23 +0800712static int32_t rscp_convert_to_minus_dBm(uint8 rscp)
b.liu68a94c92025-05-24 12:53:41 +0800713{
q.huangfa0a0a32025-06-12 17:07:23 +0800714 if(rscp <= 96)
b.liu68a94c92025-05-24 12:53:41 +0800715 {
q.huangfa0a0a32025-06-12 17:07:23 +0800716 return 121-rscp; // 96 map 25
717 // 0 map -121, below -120
b.liu68a94c92025-05-24 12:53:41 +0800718 }
b.liu68a94c92025-05-24 12:53:41 +0800719 else
720 {
q.huangfa0a0a32025-06-12 17:07:23 +0800721 return INT_32_MAX;
b.liu68a94c92025-05-24 12:53:41 +0800722 }
723}
724
q.huangfa0a0a32025-06-12 17:07:23 +0800725static int32_t rsrp_convert_to_minus_dBm(uint8 rsrp)
b.liu68a94c92025-05-24 12:53:41 +0800726{
q.huangfa0a0a32025-06-12 17:07:23 +0800727 if(rsrp <= 97)
b.liu68a94c92025-05-24 12:53:41 +0800728 {
q.huangfa0a0a32025-06-12 17:07:23 +0800729 return 141-rsrp; // 97 map 44
730 // 0 map 141 below 140
b.liu68a94c92025-05-24 12:53:41 +0800731 }
732 else
733 {
q.huangfa0a0a32025-06-12 17:07:23 +0800734 return INT_32_MAX;
b.liu68a94c92025-05-24 12:53:41 +0800735 }
736}
737
q.huangfa0a0a32025-06-12 17:07:23 +0800738static int32_t rsrq_convert_to_minus_dB(uint8 rsrq)
b.liu68a94c92025-05-24 12:53:41 +0800739{
q.huangfa0a0a32025-06-12 17:07:23 +0800740 if(rsrq <= 34)
b.liu68a94c92025-05-24 12:53:41 +0800741 {
q.huangfa0a0a32025-06-12 17:07:23 +0800742 return (40-rsrq)/2; //=20-rsrq / 2;
743 // 34 map 3
744 // 0 map 20
b.liu68a94c92025-05-24 12:53:41 +0800745 }
746 else
747 {
q.huangfa0a0a32025-06-12 17:07:23 +0800748 return INT_32_MAX;
b.liu68a94c92025-05-24 12:53:41 +0800749 }
750}
751
q.huang861c07d2025-06-24 16:54:58 +0800752static int32_t sinr_convert_to_10_times_dB(int8 sinr)
q.huang638d5872025-06-21 13:44:43 +0800753{
754 if(sinr <=35 && sinr>=-20)
755 {
756 return sinr*10; //35 map 350 db
757 // -20 map -2000 db
758 }
759 else
760 {
761 return INT_32_MAX;
762 }
763}
764
765
766static int32_t rscp_minus_dbm_convert_to_rssi_dBm(int32_t rscp)
767{
768 if(rscp!=INT_32_MAX)
769 {
770 return -rscp;
771 }
772 else
773 {
774 return INT_32_MAX;
775 }
776}
777
778static int32_t rsrp_minus_dbm_convert_to_rssi_dBm(int32_t rsrp)
779{
780 if(rsrp!=INT_32_MAX)
781 {
782 return -rsrp;
783 }
784 else
785 {
786 return INT_32_MAX;
787 }
788}
789
q.huang861c07d2025-06-24 16:54:58 +0800790static int32_t rxlev_convert_to_rssi_dBm(uint8 rxlev)
791{
792 if(rxlev<=63)
793 {
794 return rxlev-111; //0 map -111, below -110
795 // 63 map -48
796 }
797 else
798 {
799 return INT_32_MAX;
800 }
801
802}
b.liu68a94c92025-05-24 12:53:41 +0800803
q.huangfa0a0a32025-06-12 17:07:23 +0800804//int ecno; /**< Valid values are positive integers. This value is the actual Ec/Io multiplied
805// * by -10. Example: If the actual Ec/Io is -12.5 dB, then this response value
806// * will be 125.*/
807//uint8 ecno; // 0: Ec/Io < -24 dB
808 // 1: -24 dB �� Ec/Io < -23.5 dB
809 // 2: -23.5 dB �� Ec/Io < -23 dB
810 // ......
811 // 47: -1 dB �� Ec/Io < -0.5 dB
812 // 48: -0.5 dB �� Ec/Io < 0 dB
813 // 49: 0 dB �� Ec/Io
814 // 255: not known or not detectabl
815static int32_t ecno_convert_to_minus_10_times_dB(uint8 ecno)
b.liu68a94c92025-05-24 12:53:41 +0800816{
q.huangfa0a0a32025-06-12 17:07:23 +0800817 if(ecno <=49)
b.liu68a94c92025-05-24 12:53:41 +0800818 {
q.huangfa0a0a32025-06-12 17:07:23 +0800819 return 245-ecno*5; //49 map 0 db
820 // 1 map 240 db
821 // 0 map 245 below 240
b.liu68a94c92025-05-24 12:53:41 +0800822 }
q.huangfa0a0a32025-06-12 17:07:23 +0800823 else
b.liu68a94c92025-05-24 12:53:41 +0800824 {
q.huangfa0a0a32025-06-12 17:07:23 +0800825 return INT_32_MAX;
b.liu68a94c92025-05-24 12:53:41 +0800826 }
827}
828
b.liu68a94c92025-05-24 12:53:41 +0800829
b.liu68a94c92025-05-24 12:53:41 +0800830
q.huangfa0a0a32025-06-12 17:07:23 +0800831/* change realCsq to level */
832static int rscpToLevel(int rscp)
b.liu68a94c92025-05-24 12:53:41 +0800833{
q.huangfa0a0a32025-06-12 17:07:23 +0800834
835 if (rscp < -110) {
b.liu68a94c92025-05-24 12:53:41 +0800836 return 0;
q.huangfa0a0a32025-06-12 17:07:23 +0800837 } else if (rscp <= -95) {
838 return rscp+111; // to 16
839 } else if (rscp >=-93 && rscp <=-90) {
840 return rscp+110; // to 20
841 } else if (rscp >=-89 && rscp <=-59) {
842 return (rscp+152)/3; // =(rscp+89)/3+21 to 31
843 } else if (rscp ==- 94) { // Geely requirement, -94 map 16
844 return 16;
845 } else if(rscp <= -25) {
846 return 31;
b.liu68a94c92025-05-24 12:53:41 +0800847 }
q.huangfa0a0a32025-06-12 17:07:23 +0800848 return 99;
b.liu68a94c92025-05-24 12:53:41 +0800849}
850
q.huangfa0a0a32025-06-12 17:07:23 +0800851static int rsrpToLevel(int rsrp)
852{
853 if (rsrp < -130) {
854 return 0;
855 } else if (rsrp <= -118) {
856 return (rsrp+132)/2; // to 7
857 } else if (rsrp <=-109) {
858 return rsrp+125; // to 16
859 } else if (rsrp <=-103) {
860 return (rsrp+141)/2; // =(rsrp+109)/2+16 to 19
861 } else if (rsrp <=- 85) {
862 return (rsrp+160)/3; // =(rsrp+103)/3+19 to 25
863 } else if(rsrp <= -55) {
864 return (rsrp+210)/5; // =(rsrp+85)/5+25 to 31
865 } else if(rsrp <=-44)
866 {
867 return 31;
868 }
869 return 99;
870}
871
q.huang861c07d2025-06-24 16:54:58 +0800872//uint8 rssi; // 0: 113 dBm or less
873 // 1: 111 dBm
874 // 2��30: 109��53 dBm
875 // 31: 51 dBm or greater
876 // 99: not known or not detectable
877//uint8 rxlev;// 0:rssi < -110 dBm
878 // 1: -110 dBm �� rssi < -109 dBm
879 // 2: -109 dBm �� rssi < -108 dBm
880 // 60 ......
881 // 61: -50 dBm �� rssi < -49 dBm
882 // 62: -49 dBm �� rssi < -48 dBm
883 // 63: -48 dBm �� rssi
884 // 99: not known or not detectable
q.huangfa0a0a32025-06-12 17:07:23 +0800885
q.huang861c07d2025-06-24 16:54:58 +0800886/* change realCsq to level */
887static int rxlevToLevel(uint8 rxlev)
888{
889 if (rxlev <=60) {
890 return (rxlev+3)/2; // =(rxlev+1)/2+1,
891 // 0 map 1
892 // 1,2 map 2
893 // 59,60 map 31
894 }
895 else if(rxlev <=63)
896 {
897 return 31;
898 }
899 return 99;
900}
b.liu68a94c92025-05-24 12:53:41 +0800901
902static int convert_reg_state(int reg_state_t)
903{
904 LOGD("reg_state_t = %d\n",reg_state_t);
905 int reg_state = 0;
906
907 switch (reg_state_t)
908 {
909 case MBTK_NET_REG_STATE_NON:
910 {
911 reg_state = GSW_NETWORK_REG_NOT_REGISTERED;
912 break;
913 }
914 case MBTK_NET_REG_STATE_HOME:
915 {
916 reg_state = GSW_NETWORK_REG_REGISTERED;
917 break;
918 }
919 case MBTK_NET_REG_STATE_SEARCHING:
920 {
921 reg_state = GSW_NETWORK_REG_NOT_REGISTERED_SEARCHING;
922 break;
923 }
924 case MBTK_NET_REG_STATE_DENIED:
925 {
926 reg_state = GSW_NETWORK_REG_REGISTRATION_DENIED;
927 break;
928 }
929 case MBTK_NET_REG_STATE_UNKNOWN:
930 {
931 reg_state = GSW_NETWORK_REG_REGISTRATION_UNKNOWN;
932 break;
933 }
934 case MBTK_NET_REG_STATE_ROAMING:
935 {
936 reg_state = GSW_NETWORK_REG_REGISTRATION_ROAMING;
937 break;
938 }
939 case MBTK_NET_REG_STATE_SMS_ONLY:
940 case MBTK_NET_REG_STATE_ROAMING_SMS:
941 case MBTK_NET_REG_STATE_ATTACHED_EMERGENCY:
942 case MBTK_NET_REG_STATE_CSFB_HOME:
943 case MBTK_NET_REG_STATE_CSFB_ROAMING:
944 case MBTK_NET_REG_STATE_EMERGENCY_ONLY:
945 {
946 reg_state = GSW_NETWORK_REG_LIMITED_SERVICE;
947 break;
948 }
949 }
950
951 return reg_state;
952}
953
954
955static int convert_net_mode(int net_mode)
956{
957 LOGD("net_mode = %d\n",net_mode);
958 switch(net_mode)
959 {
960 case MBTK_RADIO_TECH_GSM:
961 case MBTK_RADIO_TECH_GSM_COMPACT:
962 case MBTK_RADIO_TECH_GSM_EGPRS:
963 {
964 return GSW_NETWORK_RADIO_GSM;
965 }
966 case MBTK_RADIO_TECH_UTRAN:
967 case MBTK_RADIO_TECH_UTRAN_HSDPA:
968 case MBTK_RADIO_TECH_UTRAN_HSUPA:
969 case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
970 case MBTK_RADIO_TECH_UTRAN_HSPA:
971 {
972 return GSW_NETWORK_RADIO_UMTS;
973 }
974 case MBTK_RADIO_TECH_E_UTRAN:
975 {
976 return GSW_NETWORK_RADIO_LTE;
977 }
978
979 default:
980 {
981 return GSW_NETWORK_RADIO_NO_SVC;
982 }
983 }
984
985 return GSW_NETWORK_RADIO_NO_SVC;
986}
987
988static int convert_mbtk_net_config(int config)
989{
990 int net_pref = -1;
991
992 switch(config)
993 {
994 case GSW_PREFER_MODE_GSW:
995 {
996 net_pref = 0;
997 break;
998 }
999
1000 case GSW_PREFER_MODE_WCDMA:
1001 {
1002 net_pref = 1;
1003 break;
1004 }
1005
1006 case GSW_PREFER_MODE_WCDMA_GSM:
1007 {
1008 net_pref = 2;
1009 break;
1010 }
1011
1012 case GSW_PREFER_MODE_LTE:
1013 case GSW_PREFER_MODE_NR5G:
1014 case GSW_PREFER_MODE_NR5G_LTE:
1015 {
1016 net_pref = 5;
1017 break;
1018 }
1019
1020 case GSW_PREFER_MODE_LTE_WCDMA_GSM:
1021 case GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM:
1022 {
1023 net_pref = 15;
1024 break;
1025 }
1026 }
1027
1028 return net_pref;
1029}
1030
1031
1032static int convert_gsw_net_config(int config)
1033{
1034 int net_config = -1;
q.huang72680852025-06-11 13:42:21 +08001035 LOGD("config = %d\n",config);
b.liu68a94c92025-05-24 12:53:41 +08001036
1037 switch (config)
1038 {
1039 case 0:
1040 {
1041 net_config = GSW_PREFER_MODE_GSW;
1042 break;
1043 }
1044
1045 case 1:
1046 {
1047 net_config = GSW_PREFER_MODE_WCDMA;
1048 break;
1049 }
1050
1051 case 2:
1052 {
1053 net_config = GSW_PREFER_MODE_WCDMA_GSM;
1054 break;
1055 }
1056
1057 case 5:
1058 {
1059 net_config = GSW_PREFER_MODE_LTE;
1060 break;
1061 }
1062
1063 case 15:
1064 {
1065 net_config = GSW_PREFER_MODE_LTE_WCDMA_GSM;
1066 break;
1067 }
1068 }
1069
1070 return net_config;
1071}
1072
1073//64F010 -> 46001 (64->46,F0->0,10->01)
1074static void transform_fplmn_str_to_plmn(char *entry)
1075{
1076 if (strncmp(entry, "FFFFFF", ENTRY_LENGTH) == 0) {
1077 return; //if FFFFFF,means invalid fplmn, do nothing
1078 }
1079
1080 char temp = entry[0];
1081 entry[0] = entry[1];
1082 entry[1] = temp;
1083
1084 temp = entry[ENTRY_LENGTH - 2];
1085 entry[ENTRY_LENGTH - 2] = entry[ENTRY_LENGTH - 1];
1086 entry[ENTRY_LENGTH - 1] = temp;
1087
1088 memmove(entry + 2, entry + 3, ENTRY_LENGTH - 2);
1089
1090 LOGE("after transform_fplmn_str_to_plmn: %s\n", entry);
1091
1092 //valid fplmn
1093 fplmn_index++;
1094}
1095
1096static void extract_mcc_mnc(char *entry, char *mcc, char *mnc)
1097{
1098 strncpy(mcc,entry,3);
1099 mcc[3] = '\0';
1100 strncpy(mnc,entry + 3,2);
1101 mnc[2] = '\0';
1102
1103 LOGE("entry = %s, mcc = %s, mnc = %s\n", entry, mcc, mnc);
1104}
1105
1106
1107static void update_fplmn_list(char *fplmn_str)
1108{
1109 LOGE("fplmn_str = %s\n",fplmn_str);
1110 char temp_fplmn_array[FPLMN_ARRAY_SIZE][7];
1111 memset(fplmn_array, 0, sizeof(fplmn_array));
1112 memset(temp_fplmn_array, 0, sizeof(temp_fplmn_array));
1113 fplmn_index = 0;
1114 int array_length = 0;
1115
1116 for (int i = 0; i < strlen(fplmn_str); i += 6) {
1117
1118 int length = (i + 6 < strlen(fplmn_str)) ? 6 : strlen(fplmn_str) - i;
1119 strncpy(temp_fplmn_array[array_length], fplmn_str + i, length);
1120 temp_fplmn_array[array_length][length] = '\0';
1121 array_length++;
1122 if (i + 6 >= strlen(fplmn_str)) {
1123 break;
1124 }
1125 }
1126
1127 for (int i = 0; i < array_length; i++) {
1128 LOGE("array[%d] = %s\n", i, temp_fplmn_array[i]);
1129 transform_fplmn_str_to_plmn(temp_fplmn_array[i]);
1130 strncpy(fplmn_array[i], temp_fplmn_array[i], ENTRY_LENGTH);
1131 LOGE("fplmn_array[%d] = %s\n", i, fplmn_array[i]);
1132 }
1133
1134}
1135
1136static void format_plmn(char *result, char *plmn_entry)
1137{
1138 strncpy(result, plmn_entry, strlen(plmn_entry));
1139 LOGE("result = %s, numStr = %s\n",result, plmn_entry);
1140
1141 if (strlen(result) >= 2) {
1142 char temp = result[0];
1143 result[0] = result[1];
1144 result[1] = temp;
1145 }
1146
1147 LOGE("1.result = %s\n",result);
1148
1149 if (strlen(result) >= 3) {
1150 memmove(&result[3], &result[2], strlen(result) - 2 + 1);
1151 result[2] = 'F';
1152 }
1153
1154 LOGE("2.result = %s\n",result);
1155
1156 if (strlen(result) >= 2) {
1157 char temp = result[strlen(result) - 1];
1158 result[strlen(result) - 1] = result[strlen(result) - 2];
1159 result[strlen(result) - 2] = temp;
1160 }
1161
1162 LOGE("3.result = %s\n",result);
1163}
1164
1165
1166static void convert_plmn_to_fplmn_str(char *fplmn_str)
1167{
1168 char temp_fplmn_str[128] = {0};
1169 char temp[20]; // 临时存储单个格式化后的数字
1170 int index = 0;
1171
1172 for (int i = 0; i < fplmn_index; i++) {
1173 memset(temp, 0x0, sizeof(temp));
1174 format_plmn(temp, fplmn_array[i]);
1175 strcat(temp_fplmn_str, temp);
1176 index += strlen(temp);
1177 }
1178
1179 while(index < (6 * fplmn_max_length))
1180 {
1181 temp_fplmn_str[index++] = 'F';
1182 }
1183
1184 // 修剪或截断formattedNumbers,确保它不超过6 * fplmn_max_length个字符
1185 if (index > (6 * fplmn_max_length)) {
1186 temp_fplmn_str[(6 * fplmn_max_length)] = '\0';
1187 }
1188
1189 LOGE("%s\n", temp_fplmn_str);
1190 strncpy(fplmn_str, temp_fplmn_str, strlen(temp_fplmn_str));
1191 LOGE("fplmn_str = %s\n", fplmn_str);
1192}
1193
1194static int check_index(char *mcc, char *mnc)
1195{
1196 int i = 0;
1197
1198 for(i = 0; i < fplmn_index; i++)
1199 {
1200 if(strncmp(fplmn_array[i], mcc, 3) == 0 && strncmp(fplmn_array[i] + 3, mnc, 2) == 0)
1201 {
1202 LOGE("index = %d\n", i);
1203 return i;
1204 }
1205 }
1206
1207 LOGE("not find\n");
1208 return -1;
1209}
1210
1211static void remove_fplmn(int index)
1212{
1213 int write_index = 0;
1214 for (int i = 0; i < fplmn_index; i++) {
1215 if (i != index) {
1216 strncpy(fplmn_array[write_index++], fplmn_array[i], ENTRY_LENGTH);
1217 }
1218 }
1219 fplmn_index--;
1220}
1221
q.huangfa0a0a32025-06-12 17:07:23 +08001222static void convert_mbtk_sig_info_to_gsw_sig_info(const mbtk_signal_info_t* signal, signalStrength_t* sig_strength)
1223{
1224 LOGD("signal->type=%d", signal->type);
1225 memset(sig_strength,0,sizeof (signalStrength_t));
1226 switch(signal->type)
1227 {
1228 case MBTK_RADIO_TECH_E_UTRAN:
1229 {
1230 LOGI("rsrp = %d",signal->rsrp);
1231 sig_strength->lte_sig_valid = 1;
q.huangc8b93122025-06-17 17:46:05 +08001232 sig_strength->rsrp = rsrp_convert_to_minus_dBm(signal->rsrp);
1233 sig_strength->rsrq = rsrq_convert_to_minus_dB(signal->rsrq);
q.huang638d5872025-06-21 13:44:43 +08001234 sig_strength->rssi = rsrp_minus_dbm_convert_to_rssi_dBm(sig_strength->rsrp);
q.huang861c07d2025-06-24 16:54:58 +08001235 sig_strength->rssnr= sinr_convert_to_10_times_dB(signal->sinr);
q.huangfa0a0a32025-06-12 17:07:23 +08001236 break;
1237 }
1238 case MBTK_RADIO_TECH_UTRAN:
1239 case MBTK_RADIO_TECH_UTRAN_HSDPA:
1240 case MBTK_RADIO_TECH_UTRAN_HSUPA:
1241 case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
1242 case MBTK_RADIO_TECH_UTRAN_HSPA:
1243 {
1244 LOGI("rscp = %d",signal->rscp);
1245 sig_strength->wcdma_sig_valid = 1;
1246 sig_strength->rscp = rscp_convert_to_minus_dBm(signal->rscp);
1247 sig_strength->ecno = ecno_convert_to_minus_10_times_dB(signal->ecno);
q.huang638d5872025-06-21 13:44:43 +08001248 sig_strength->rssi = rscp_minus_dbm_convert_to_rssi_dBm(sig_strength->rscp);
q.huangfa0a0a32025-06-12 17:07:23 +08001249 break;
1250 }
1251 case MBTK_RADIO_TECH_GSM:
1252 case MBTK_RADIO_TECH_GSM_COMPACT:
1253 case MBTK_RADIO_TECH_GSM_EGPRS:
1254 {
q.huang861c07d2025-06-24 16:54:58 +08001255 LOGI("g rxlev = %d",signal->rxlev);
q.huangfa0a0a32025-06-12 17:07:23 +08001256 sig_strength->gw_sig_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08001257 sig_strength->rssi = rxlev_convert_to_rssi_dBm(signal->rxlev);
q.huangfa0a0a32025-06-12 17:07:23 +08001258 break;
1259 }
1260 default:
1261 {
1262 LOGE("[%s] unknown reg type.[%d]", __func__, signal->type);
1263 }
1264 }
1265
1266}
1267
q.huang66b79162025-06-27 17:45:34 +08001268/*
1269typedef enum{
1270 MBTK_READY_INIT = -1,
1271 MBTK_READY_SUCCESS,
1272 MBTK_READY_MODEM_FAIL,
1273 MBTK_READY_RESPONSE_FAIL,
1274 MBTK_READY_SOCKET_FAIL,
1275 MBTK_READY_RIL_FAIL
1276}mbtk_ready_status_type;
1277
1278typedef enum gsw_hal_nw_mode_state_type
1279{
1280 GSW_MODEM_STATE_UNKNOWN = 0,
1281 GSW_MODEM_STATE_ONLINE,
1282 GSW_MODEM_STATE_OFFLINE,
1283 GSW_SDK_STATE_SERVICE_DOWN,
1284 GSW_SDK_STATE_SERVICE_UP,// service down->up 需要routectl 重启
1285 GSW_SDK_STATE_GPS_DOWN,
1286 GSW_SDK_STATE_GPS_UP,
1287} gsw_mode_state_e;
1288
1289*/
1290
1291static void convert_uci_to_gsw_modem_state(int uci, int *state)
1292{
1293 switch(uci)
1294 {
1295 case MBTK_READY_SUCCESS:
1296 *state=GSW_MODEM_STATE_ONLINE;
1297 return;
1298 case MBTK_READY_INIT:
1299 *state=GSW_MODEM_STATE_UNKNOWN;
1300 return;
1301 }
1302 *state=GSW_MODEM_STATE_OFFLINE;
1303 return;
1304}
1305
1306
1307
1308
1309
q.huangfa0a0a32025-06-12 17:07:23 +08001310
b.liu68a94c92025-05-24 12:53:41 +08001311static void gsw_serving_info_callback_thread()
1312{
1313 GSW_NW_SERVING_INFO *serving_info = (GSW_NW_SERVING_INFO*)malloc(sizeof(GSW_NW_SERVING_INFO));
1314 memset(serving_info, 0x0, sizeof(GSW_NW_SERVING_INFO));
1315 int ret = -1;
1316 ret = gsw_get_nwinfo(serving_info);
1317 if(ret != 0)
1318 {
1319 LOGE("gsw_get_nwinfo failed\n");
1320 free(serving_info);
1321 return;
1322 }
1323
1324 if(serving_cb)
1325 {
1326 serving_cb(*serving_info);
1327 free(serving_info);
1328 }
1329}
1330
1331static void gsw_serving_info_callback(const void* data, int data_len)
1332{
1333 LOGE("gsw_serving_info_callback start\n");
1334
1335 if(data && data_len > 0)
1336 {
1337 pthread_t thread;
1338 pthread_create(&thread, NULL, (void*)gsw_serving_info_callback_thread, NULL);
1339 }
1340
1341 else
1342 {
1343 LOGE("data is NULL\n");
1344 return;
1345 }
1346
1347}
1348
q.huangfa0a0a32025-06-12 17:07:23 +08001349/*typedef struct
1350{
13510 mbtk_radio_technology_enum type : 8; // mbtk_radio_technology_enum
13521 uint8 rssi; // 0: 113 dBm or less
1353 // 1: 111 dBm
1354 // 2��30: 109��53 dBm
1355 // 31: 51 dBm or greater
1356 // 99: not known or not detectable
13572 uint8 rxlev;// 0:rssi < -110 dBm
1358 // 1: -110 dBm �� rssi < -109 dBm
1359 // 2: -109 dBm �� rssi < -108 dBm
1360 // ......
1361 // 61: -50 dBm �� rssi < -49 dBm
1362 // 62: -49 dBm �� rssi < -48 dBm
1363 // 63: -48 dBm �� rssi
1364 // 99: not known or not detectable
13653 uint8 ber; // 0...7 as RXQUAL values in the table in 3GPP TS 45.008 [20] subclause 8.2.4
1366 // 99 not known or not detectable
13674 uint8 rscp; // 0: rscp < -120 dBm
1368 // 1: -120 dBm �� rscp < -119 dBm
1369 // 2: -119 dBm �� rscp < -118 dBm
1370 // ......
1371 // 94: -27 dBm �� rscp < -26 dBm
1372 // 95: -26 dBm �� rscp < -25 dBm
1373 // 96: - 25 dBm �� rscp
1374 // 255: not known or not detectable
13755 uint8 ecno; // 0: Ec/Io < -24 dB
1376 // 1: -24 dB �� Ec/Io < -23.5 dB
1377 // 2: -23.5 dB �� Ec/Io < -23 dB
1378 // ......
1379 // 47: -1 dB �� Ec/Io < -0.5 dB
1380 // 48: -0.5 dB �� Ec/Io < 0 dB
1381 // 49: 0 dB �� Ec/Io
1382 // 255: not known or not detectable
13836 uint8 rsrq; // 0: rsrq < -19.5 dB
1384 // 1: -19.5 dB �� rsrq < -19 dB
1385 // 2: -19 dB �� rsrq < -18.5 dB
1386 // ......
1387 // 32: -4 dB �� rsrq < -3.5 dB
1388 // 33: -3.5 dB �� rsrq < -3 dB
1389 // 34: -3 dB �� rsrq
1390 // 255: not known or not detectable
13917 uint8 rsrp; // 0: rsrp < -140 dBm
1392 // 1: -140 dBm �� rsrp < -139 dBm
1393 // 2: -139 dBm �� rsrp < -138 dBm
1394 // ......
1395 // 95: -46 dBm �� rsrp < -45 dBm
1396 // 96: -45 dBm �� rsrp < -44 dBm
1397 // 97: -44 dBm �� rsrp
1398 // 255: not known or not detectable
13998 uint8 ss_rsrq; // 0: ss_rsrq < -43 dB
1400 // 1: -43 dB <= ss_rsrq < -42.5 dB
1401 // 2: -42.5 dB <= ss_rsrq < -42 dB
1402 // ......
1403 // 125: 19 dB <= ss_rsrq < 19.5 dB
1404 // 126: 19.5 dB <= ss_rsrq < 20 dB
1405 // 255: not known or not detectable
1406 uint8 ss_rsrp; // 0: ss_rsrp < -156 dBm
1407 // 1: -156 dBm <= ss_rsrp < -155 dBm
1408 // 2: -155 dBm <= ss_rsrp < -154 dBm
1409 // ......
1410 // 125: -32 dBm <= ss_rsrp < -31 dBm
1411 // 126: -31 dBm <= ss_rsrp
1412 // 255: not known or not detectable
1413 uint8 ss_sinr; // 0: ss_sinr < -23 dB
1414 // 1: -23 dB  ss_sinr < -22.5 dB
1415 // 2: -22.5 dB  ss_sinr < -22 dB
1416 // ......
1417 // 125: 39 dB  ss_sinr < 39.5 dBm
1418 // 126: 39.5 dB  ss_sinr < 40 dB
1419 // 127: 40 dB  ss_sinr
1420 // 255: not known or not detectable
1421} __attribute__((packed)) mbtk_signal_info_t;
1422*/
b.liu68a94c92025-05-24 12:53:41 +08001423static void gsw_sig_info_callback(const void* data, int data_len)
1424{
q.huangfa0a0a32025-06-12 17:07:23 +08001425 if(data && (data_len >= sizeof (mbtk_signal_info_t)))
b.liu68a94c92025-05-24 12:53:41 +08001426 {
b.liu68a94c92025-05-24 12:53:41 +08001427 signalStrength_t sig_strength;
q.huangfa0a0a32025-06-12 17:07:23 +08001428 convert_mbtk_sig_info_to_gsw_sig_info(( const mbtk_signal_info_t*) data,&sig_strength);
1429
b.liu68a94c92025-05-24 12:53:41 +08001430 if(sig_cb != NULL)
1431 {
1432 sig_cb(sig_strength);
1433 }
1434 }
b.liu68a94c92025-05-24 12:53:41 +08001435 else
1436 {
q.huangfa0a0a32025-06-12 17:07:23 +08001437 LOGE("data is NULL or data len %d error",data_len);
b.liu68a94c92025-05-24 12:53:41 +08001438 }
1439}
1440
q.huangc8b93122025-06-17 17:46:05 +08001441static void gsw_operating_mode_event_callback(const void* data, int data_len)
b.liu68a94c92025-05-24 12:53:41 +08001442{
q.huangc8b93122025-06-17 17:46:05 +08001443 LOGE("gsw_operating_mode_event_callback start\n");
b.liu68a94c92025-05-24 12:53:41 +08001444
q.huangc8b93122025-06-17 17:46:05 +08001445
b.liu68a94c92025-05-24 12:53:41 +08001446 if(data && data_len > 0)
1447 {
q.huangc8b93122025-06-17 17:46:05 +08001448 const uint8 *cfun_state = (const uint8*)data;
1449 LOGE("gsw_operating_mode_event_callback,data = %d\n", *cfun_state);
1450 if(airplane_cb != NULL)
b.liu68a94c92025-05-24 12:53:41 +08001451 {
q.huangc8b93122025-06-17 17:46:05 +08001452 airplane_cb(*cfun_state);
b.liu68a94c92025-05-24 12:53:41 +08001453 }
1454 }
1455
1456}
1457
q.huangc8b93122025-06-17 17:46:05 +08001458
b.liu68a94c92025-05-24 12:53:41 +08001459static void gsw_reject_callback(GSW_NW_RADIO_ACCESS_TECH_E rat, GSW_SERVICE_DOMAIN_E domain, int cause)
1460{
1461 LOGE("gsw_reject_callback start,rat = %d,domain = %d,cause = %d\n",rat,domain,cause);
1462
1463 GSW_NW_REJ_CAUSE_E *rej_cause = (GSW_NW_REJ_CAUSE_E*)malloc(sizeof(GSW_NW_REJ_CAUSE_E));
1464 memset(rej_cause, 0x0, sizeof(GSW_NW_REJ_CAUSE_E));
1465
1466 rej_cause->rej_cause = cause;
1467 rej_cause->rej_rat = rat;
1468 rej_cause->rej_domain = domain;
1469
1470 if(reject_cb != NULL)
1471 {
1472 LOGE("reject_cb is not NULL\n");
1473 reject_cb(rej_cause);
1474 }
1475 else
1476 {
1477 LOGE("reject_cb is NULL\n");
1478 }
1479
1480 free(rej_cause);
1481 LOGE("gsw_reject_callback end\n");
1482}
1483
xy.hec89938f2025-05-29 14:08:47 +08001484void gsw_sig_info_timer()
1485{
xy.hec89938f2025-05-29 14:08:47 +08001486 if(nw_init_flag == 0 || nw_info_handle == NULL)
1487 {
1488 return;
1489 }
1490
1491 mbtk_signal_info_t signal;
1492 signalStrength_t sig_strength;
1493
1494 while(nw_init_flag)
1495 {
q.huangfa0a0a32025-06-12 17:07:23 +08001496 int ret = mbtk_net_signal_get(nw_info_handle, &signal);
xy.hec89938f2025-05-29 14:08:47 +08001497 if(ret != 0)
1498 {
q.huangfa0a0a32025-06-12 17:07:23 +08001499 LOGE("mbtk_net_signal_get fail, ret is %d\n",ret);
q.huang66b79162025-06-27 17:45:34 +08001500
xy.hec89938f2025-05-29 14:08:47 +08001501 }
xy.hec89938f2025-05-29 14:08:47 +08001502 else
1503 {
q.huangfa0a0a32025-06-12 17:07:23 +08001504 convert_mbtk_sig_info_to_gsw_sig_info(&signal,&sig_strength);
q.huang66b79162025-06-27 17:45:34 +08001505 if(sig_cb != NULL)
1506 {
1507 sig_cb(sig_strength);
1508 }
xy.hec89938f2025-05-29 14:08:47 +08001509 }
xy.hec89938f2025-05-29 14:08:47 +08001510 sleep(SIG_TIMER);
1511 }
1512}
1513
q.huang66b79162025-06-27 17:45:34 +08001514int gsw_get_modem_state(int *state)
1515{
1516 char buf[MBTK_READY_STRING_SIZE_MAX];
1517 if(property_get(MBTK_READY_UCI, buf, "") > 0 && !str_empty(buf))
1518 {
1519 int uci_value=atoi(buf);
1520 convert_uci_to_gsw_modem_state(uci_value,state);
1521 return GSW_HAL_SUCCESS;
1522 }
1523 return GSW_HAL_NORMAL_FAIL;
1524}
1525
1526int g_mode_state=((int)(GSW_MODEM_STATE_UNKNOWN))-1;
1527void gsw_modem_state_timer()
1528{
1529 while(nw_init_flag)
1530 {
1531 if(modem_cb != NULL)
1532 {
1533 int state;
1534 int ret = gsw_get_modem_state(&state);
1535 if(ret != 0)
1536 {
1537 LOGE("gsw_get_modem_state fail, ret is %d",ret);
1538 }
1539 else if(state!=g_mode_state)
1540 {
1541 LOGE("modem state changed from %d to %d",g_mode_state,state);
1542 g_mode_state=state;
1543 modem_cb(state);
1544 }
1545 }
1546 sleep(MODEM_TIMER);
1547 }
1548}
1549
1550
b.liu68a94c92025-05-24 12:53:41 +08001551
1552/**
1553 * @brief SDK interface to call back serving info
1554 * @param [in] handle_ptr
1555 * @retval 0: success
1556 * @retval other: fail
1557 */
1558int gsw_reg_serving_info_callback(GSW_NW_ServingInfoHandlePtr handle_ptr)
1559{
1560 if (nw_init_flag == 0 || nw_info_handle == NULL)
1561 {
xy.heb41615b2025-05-28 16:33:20 +08001562 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001563 }
1564
1565 if(handle_ptr == NULL)
1566 {
1567 LOGE("handle_ptr is NULL\n");
xy.heb41615b2025-05-28 16:33:20 +08001568 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001569 }
1570
1571 serving_cb = handle_ptr;
1572
1573 return GSW_HAL_SUCCESS;
1574
1575}
1576
1577
1578/**
1579 * @brief SDK interface to call back sig info
1580 * @param [in] handle_ptr
1581 * @retval 0: success
1582 * @retval other: fail
1583 */
1584int gsw_reg_sig_info_callback(GSW_NW_SigInfoHandlePtr handle_ptr)
1585{
1586 if (nw_init_flag == 0 || nw_info_handle == NULL)
1587 {
xy.heb41615b2025-05-28 16:33:20 +08001588 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001589 }
1590
1591 if(handle_ptr == NULL)
1592 {
1593 LOGE("handle_ptr is NULL\n");
q.huang66b79162025-06-27 17:45:34 +08001594 sig_cb=NULL;
1595 return GSW_HAL_SUCCESS;
b.liu68a94c92025-05-24 12:53:41 +08001596 }
1597
1598 sig_cb = handle_ptr;
1599
1600 return GSW_HAL_SUCCESS;
1601
1602}
1603
1604
1605/**
1606 * @brief SDK interface to call back rej cause
1607 * @param [in] handle_ptr
1608 * @retval 0: success
1609 * @retval other: fail
1610 */
1611int gsw_reg_rej_cause_callback(GSW_NW_RejectCauseHandlePtr handle_ptr)
1612{
1613 if (nw_init_flag == 0 || nw_info_handle == NULL)
1614 {
xy.heb41615b2025-05-28 16:33:20 +08001615 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001616 }
1617
1618 if(handle_ptr == NULL)
1619 {
1620 LOGE("handle_ptr is NULL\n");
xy.heb41615b2025-05-28 16:33:20 +08001621 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001622 }
1623
1624 reject_cb = handle_ptr;
1625
1626 return GSW_HAL_SUCCESS;
1627}
1628
1629
1630/**
1631 * @brief network sdk init
1632 * @param [in] token usr id define by who use
1633 * @retval 0: success
1634 * @retval other: fail
1635 */
1636int gsw_nw_sdk_init(int token)
1637{
1638 int ret = -1;
xy.hec89938f2025-05-29 14:08:47 +08001639 pthread_t nw_info_thread;
b.liu68a94c92025-05-24 12:53:41 +08001640
1641 if (nw_init_flag == 1 && nw_info_handle != NULL)
1642 {
1643 return GSW_HAL_SUCCESS;
1644 }
1645
1646 ret = mbtk_nw_api_import();
1647 if (ret != 0)
1648 {
1649 LOGE("mbtk_nw_api_import fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001650 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001651 }
1652
1653 nw_info_handle = mbtk_info_handle_get();
1654
1655 if (nw_info_handle == NULL)
1656 {
1657 LOGE("mbtk_info_handle_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001658 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001659 }
1660
1661 char fplmn[256] = {0};
1662 ret = mbtk_fplmn_get(nw_info_handle, fplmn);
1663 if(ret != 0)
1664 {
1665 LOGE("mbtk_fplmn_get failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08001666 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001667 }
1668 fplmn_max_length = (strlen(fplmn)/6);
1669 LOGE("fplmn = %s, fplmn_max_length = %d\n",fplmn,fplmn_max_length);
1670 ret = mbtk_signal_state_change_cb_reg(nw_info_handle, gsw_sig_info_callback);
1671
1672 if (ret != 0)
1673 {
1674 LOGE("mbtk_signal_state_change_cb_reg fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001675 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001676 }
1677
1678 ret = mbtk_net_state_change_cb_reg(nw_info_handle, gsw_serving_info_callback);
1679 if (ret != 0)
1680 {
1681 LOGE("mbtk_net_state_change_cb_reg fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001682 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001683 }
1684
q.huang66b79162025-06-27 17:45:34 +08001685 nw_init_flag = 1;
1686
xy.hec89938f2025-05-29 14:08:47 +08001687 ret = pthread_create(&nw_info_thread, NULL, (void*)gsw_sig_info_timer, NULL);
1688 if (ret != 0)
1689 {
q.huang66b79162025-06-27 17:45:34 +08001690 LOGE("pthread_create fail,ret is %d", ret);
1691 nw_init_flag = 0;
1692 return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;
xy.hec89938f2025-05-29 14:08:47 +08001693 }
1694
q.huang66b79162025-06-27 17:45:34 +08001695
1696 ret = pthread_create(&nw_info_thread, NULL, (void*)gsw_modem_state_timer, NULL);
1697 if (ret != 0)
1698 {
1699 LOGE("pthread_create fail 2,ret is %d", ret);
1700 nw_init_flag = 0;
1701 return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;
1702 }
b.liu68a94c92025-05-24 12:53:41 +08001703
1704 return GSW_HAL_SUCCESS;
1705}
1706
1707
1708/**
1709 * @brief network sdk deinit
1710 * @param
1711 * @retval 0: success
1712 * @retval other: fail
1713 */
1714int gsw_nw_sdk_deinit(void)
1715{
1716 int ret = -1;
1717
1718 if (nw_init_flag == 0 || nw_info_handle == NULL)
1719 {
xy.heb41615b2025-05-28 16:33:20 +08001720 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001721 }
1722
1723 ret = mbtk_info_handle_free(&nw_info_handle);
1724 if(ret != GSW_HAL_SUCCESS)
1725 {
1726 LOGE("mbtk_info_handle_free fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001727 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001728 }
1729
1730 dlclose(dlHandle_mbtk);
1731 nw_info_handle = NULL;
1732 nw_init_flag = 0;
1733
1734 return GSW_HAL_SUCCESS;
1735
1736}
1737
1738
1739/**
1740 * @brief get current network reg info
1741 * @param [out] serving_info struct for network info
1742 * include regstate ps_state opreator name mcc mcn etc
1743 * @retval 0: success
1744 * @retval other: fail
1745 */
1746int gsw_get_nwinfo(GSW_NW_SERVING_INFO *serving_info)
1747{
1748
1749 int ret = -1;
b.liu68a94c92025-05-24 12:53:41 +08001750 if (nw_init_flag == 0 || nw_info_handle == NULL)
1751 {
q.huang238b22a2025-06-10 14:36:59 +08001752 printf("nw_sdk_deinit not init\n");
xy.heb41615b2025-05-28 16:33:20 +08001753 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001754 }
1755
1756 LOGE("mbtk_net_reg_get start \n");
1757 //regstate
1758 mbtk_net_reg_info_t reg;
1759 memset(&reg, 0x0, sizeof(mbtk_net_reg_info_t));
1760 ret = mbtk_net_reg_get(nw_info_handle, &reg);
1761 if(ret)
1762 {
1763 LOGE("mbtk_net_reg_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001764 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001765 }
1766
1767 LOGE("convert_cs_reg_state\n");
1768 //cs_state
1769 serving_info->reg_state = convert_reg_state(reg.call_state);
1770 LOGE("convert_ps_reg_state\n");
1771 //ps_state
1772 serving_info->ps_state = convert_reg_state(reg.data_state);
1773 LOGE("convert_rat_mode\n");
1774 //reg_rat
1775 serving_info->reg_rat = convert_net_mode(reg.type);
1776 //srv_domain
1777 if(serving_info->reg_state == GSW_NETWORK_REG_REGISTERED || serving_info->reg_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
1778 {
1779 if(serving_info->ps_state == GSW_NETWORK_REG_REGISTERED || serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
1780 {
1781 serving_info->srv_domain = GSW_SRV_DOMAIN_CS_PS;
1782 }
1783
1784 else
1785 {
1786 serving_info->srv_domain = GSW_SRV_DOMAIN_CS_ONLY;
1787 }
1788 }
1789
1790 else if (serving_info->ps_state == GSW_NETWORK_REG_REGISTERED || serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
1791 {
1792 serving_info->srv_domain = GSW_SRV_DOMAIN_PS_ONLY;
1793 }
1794
1795 else
1796 {
1797 serving_info->srv_domain = GSW_SRV_DOMAIN_NO_SVC;
1798 //if ps and cs is both not registed, reg_rat seted to GSW_NETWORK_RADIO_NO_SVC
1799 serving_info->reg_rat = GSW_NETWORK_RADIO_NO_SVC;
1800 }
1801
1802 LOGD("roaming_ind\n");
1803 //roaming_ind
1804 if(serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
1805 {
1806 serving_info->roaming_ind = GSW_NETWORK_ROAMING_ON;
1807 }
1808 else
1809 {
1810 serving_info->roaming_ind = GSW_NETWORK_ROAMING_OFF;
1811 }
1812
1813 LOGD("reject\n");
1814 //reject
1815 if(serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_DENIED || serving_info->reg_state == GSW_NETWORK_REG_REGISTRATION_DENIED)
1816 {
1817 LOGD("reject_callback\n");
1818 gsw_reject_callback(serving_info->reg_rat,serving_info->srv_domain,99);
1819 }
1820
1821 LOGD("reg_plmn / operator name\n");
1822 //reg_plmn / operator name
1823 mbtk_net_info_t net;
1824 memset(&net, 0x0, sizeof(mbtk_net_info_t));
1825 LOGD("mbtk_net_sel_mode_get start \n");
1826 ret = mbtk_net_sel_mode_get(nw_info_handle, &net);
1827 LOGD("mbtk_net_sel_mode_get end \n");
1828 if(ret == 0 && net.plmn > 0)
1829 {
1830 int i = 0;
1831
1832 LOGD("start to find mcc");
1833 while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))
1834 {
1835 if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)
1836 {
1837 LOGD("find mcc\n");
1838 break;
1839 }
1840 i++;
1841 }
1842
1843
1844 if(i == ARRAY_SIZE(lynq_operator_mcc_mnc))
1845 {
1846 LOGD("not find mcc");
1847 strcpy(serving_info->operator_name, "unknown");
1848 sprintf(serving_info->reg_plmn, "%d", net.plmn);
1849 }
1850
1851 else
1852 {
1853 LOGD("find mcc\n");
1854 strcpy(serving_info->operator_name, lynq_operator_mcc_mnc[i].lynq_operator_l);
1855 sprintf(serving_info->reg_plmn, "%d", net.plmn);
1856 }
1857
1858 LOGE("operator_name = %s\n", serving_info->operator_name);
1859 LOGE("reg_plmn = %s\n", serving_info->reg_plmn);
1860 }
1861
1862
1863 LOGD("get cell id/tac/lac/sid/nid\n");
1864 //cell id/tac/lac/sid/nid
1865 mbtk_cell_type_enum cell_type;
b.liu68a94c92025-05-24 12:53:41 +08001866 list_node_t* cell_list = NULL;
1867
1868 LOGD("mbtk_cell_get start\n");
1869 ret = mbtk_cell_get(nw_info_handle, &cell_type, &cell_list);
1870 if(ret != 0 || cell_list == NULL)
1871 {
1872 LOGE("mbtk_cell_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001873 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001874 }
1875 else
1876 {
1877 LOGE("mbtk_cell_get end,start to get node\n");
1878 list_first(cell_list);
1879 LOGE("list_first end\n");
1880 mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);
1881 if(cell)
1882 {
1883 LOGE("cell is not null,value2 = %u\n",cell->value2);
1884 switch(cell_type)
1885 {
1886 case MBTK_CELL_TYPE_LTE:
1887 {
1888 LOGE("is lte\n");
1889 //LOGE("LTE : tac=%x, PCI=%x, dlEuarfcn=%x, ulEuarfcn=%x, band=%x\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
1890 LOGE("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
1891 snprintf(serving_info->tac,sizeof(serving_info->tac),"%d",cell->value1);
1892 strcpy(serving_info->lac,"");
q.huangc8b93122025-06-17 17:46:05 +08001893 snprintf(serving_info->cell_id,sizeof(serving_info->cell_id),"%d",cell->value10);
b.liu68a94c92025-05-24 12:53:41 +08001894 break;
1895 }
1896
1897 case MBTK_CELL_TYPE_GSM:
1898 {
1899 LOGE("is gsm\n");
1900 LOGE("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
1901 sprintf(serving_info->lac,"%d",cell->value1);
1902 memset(serving_info->tac,0,sizeof(serving_info->tac));
1903 sprintf(serving_info->cell_id,"%d",cell->value2);
1904 break;
1905 }
1906 case MBTK_CELL_TYPE_UMTS:
1907 {
1908 LOGE("is wcdma\n");
1909 LOGE("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
1910 sprintf(serving_info->lac,"%d",cell->value1);
1911 memset(serving_info->tac,0,sizeof(serving_info->tac));
1912 sprintf(serving_info->cell_id,"%d",cell->value2);
1913 break;
1914 }
1915
1916 default:
1917 break;
1918 }
1919 }
1920 else
1921 {
1922 LOGE("cell is null\n");
1923 }
1924 }
1925
1926 //not support now
1927 serving_info->sid = 0;
1928 serving_info->nid = 0;
1929
1930 return GSW_HAL_SUCCESS;
1931}
1932
1933
1934/**
1935 * @brief get current network type
1936 * @param [out] netype as GSW_NW_RADIO_ACCESS_TECH_E type
1937 * @retval 0: success
1938 * @retval other: fail
1939 */
1940int gsw_get_netype(int *netype)
1941{
1942 int ret = -1;
1943
1944 if (nw_init_flag == 0 || nw_info_handle == NULL)
1945 {
xy.heb41615b2025-05-28 16:33:20 +08001946 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001947 }
1948
1949 //regstate
1950 mbtk_net_reg_info_t reg;
1951 ret = mbtk_net_reg_get(nw_info_handle, &reg);
1952 if(ret)
1953 {
1954 LOGE("mbtk_net_reg_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001955 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001956 }
1957
1958 if(reg.data_state == MBTK_NET_REG_STATE_HOME || reg.data_state == MBTK_NET_REG_STATE_ROAMING)
1959 {
1960 *netype = convert_net_mode(reg.type);
1961 }
1962 else
1963 {
1964 *netype = GSW_NETWORK_RADIO_NO_SVC;
1965 }
1966
1967 return GSW_HAL_SUCCESS;
1968}
1969
1970
1971/**
1972 * @brief get radio opmode, as open and close airplane mode
1973 * @param [out] op_mode 1 is radio on, 0 is radio off
1974 * @retval 0: success
1975 * @retval other: fail
1976 */
1977int gsw_get_opmode(int *op_mode)
1978{
1979 int tmp_rf = -1;
1980 int ret = -1;
1981 if (nw_init_flag == 0 || nw_info_handle == NULL)
1982 {
xy.heb41615b2025-05-28 16:33:20 +08001983 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001984 }
1985
1986 ret = mbtk_get_modem_fun(nw_info_handle, &tmp_rf);
1987 if (ret != 0)
1988 {
1989 LOGE("mbtk_get_modem_fun fail\n");
xy.heb41615b2025-05-28 16:33:20 +08001990 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001991 }
1992 if(tmp_rf == LYNQ_AIR_CFUN_MODE_OFF)
1993 {
1994 *op_mode = GSW_OP_MODE_LPM;
1995 }
1996
1997 if(tmp_rf == LYNQ_AIR_PLANE_MODE_ON)
1998 {
1999 *op_mode = GSW_OP_MODE_OFFLINE;
2000 }
2001
2002 if(tmp_rf == LYNQ_AIR_PLANE_MODE_OFF)
2003 {
2004 *op_mode = GSW_OP_MODE_ONLINE;
2005 }
2006
2007 return GSW_HAL_SUCCESS;
2008}
2009
2010
2011
2012/**
2013 * @brief set radio opmode, as open and close airplane mode
2014 * @param [in] op_mode 1 is radio on, 0 is radio off
2015 * @retval 0: success
2016 * @retval other: fail
2017 */
2018int gsw_set_opmode(int op_mode)
2019{
2020 mbtk_modem_info_t info;
2021 int rf_mode = -1;
2022 int ret = -1;
2023
2024 if (nw_init_flag == 0 || nw_info_handle == NULL)
2025 {
xy.heb41615b2025-05-28 16:33:20 +08002026 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002027 }
2028
2029 if(op_mode == GSW_OP_MODE_LPM)
2030 {
2031 rf_mode = LYNQ_AIR_CFUN_MODE_OFF;
2032 }
2033
2034 if(op_mode == GSW_OP_MODE_ONLINE)
2035 {
2036 rf_mode = LYNQ_AIR_PLANE_MODE_OFF;
2037 }
2038
2039 if(op_mode == GSW_OP_MODE_OFFLINE)
2040 {
2041 rf_mode = LYNQ_AIR_PLANE_MODE_ON;
2042 }
2043
2044 if (rf_mode != LYNQ_AIR_PLANE_MODE_ON && rf_mode != LYNQ_AIR_PLANE_MODE_OFF && rf_mode != LYNQ_AIR_CFUN_MODE_OFF)
2045 {
2046 LOGE("Input mode is error!\n");
xy.heb41615b2025-05-28 16:33:20 +08002047 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002048 }
2049
2050 info.fun = rf_mode;
2051 info.rst = 0;
2052 ret = mbtk_set_modem_fun(nw_info_handle, &info);
2053 if (ret != 0)
2054 {
2055 LOGE("gsw_set_opmode fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002056 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002057 }
2058
2059 return GSW_HAL_SUCCESS;
2060
2061}
2062
2063
2064/**
2065 * @brief get network mode preference of mdm search network scale
2066 * @param [out] mode_pref net_work pref mode:
2067 * enum prefer_mode
2068 * @retval 0: success
2069 * @retval other: fail
2070 */
2071int gsw_get_mode_preference(int *mode_pref)
2072{
2073 if (nw_init_flag == 0 || nw_info_handle == NULL)
2074 {
xy.heb41615b2025-05-28 16:33:20 +08002075 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002076 }
2077
2078 int ret = -1;
2079 mbtk_band_info_t band;
2080 memset(&band, 0, sizeof(mbtk_band_info_t));
2081
2082 ret = mbtk_current_band_get(nw_info_handle, &band);
2083 if(ret != 0)
2084 {
2085 LOGE("mbtk_current_band_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002086 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002087 }
2088
2089 *mode_pref = convert_gsw_net_config(band.net_pref);
2090 LOGE("band.net_pref = %d\n", *mode_pref);
2091 if(*mode_pref <= 0)
2092 {
2093 LOGE("no support mode\n");
xy.heb41615b2025-05-28 16:33:20 +08002094 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002095 }
2096 return GSW_HAL_SUCCESS;
2097
2098
2099}
2100
2101/**
2102 * @brief set network mode preference of mdm search network scale
2103 * @param [in] mode_pref net_work pref mode:
2104 * enum prefer_mode
2105 * @retval 0: success
2106 * @retval other: fail
2107 */
2108int gsw_set_mode_preference(int mode_pref)
2109{
2110 if (nw_init_flag == 0 || nw_info_handle == NULL)
2111 {
xy.heb41615b2025-05-28 16:33:20 +08002112 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002113 }
2114
2115 int ret = -1;
2116
2117 mbtk_band_info_t band;
2118 memset(&band, 0, sizeof(mbtk_band_info_t));
2119
2120 band.net_pref = convert_mbtk_net_config(mode_pref);
2121 LOGE("band.net_pref = %d\n", band.net_pref);
2122
2123 if(band.net_pref < 0)
2124 {
2125 LOGE("no support mode\n");
xy.heb41615b2025-05-28 16:33:20 +08002126 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002127 }
2128
2129 ret = mbtk_current_band_set(nw_info_handle, &band);
2130 if(ret != 0)
2131 {
2132 LOGE("mbtk_current_band_set fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002133 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002134 }
2135
2136 return GSW_HAL_SUCCESS;
2137}
2138
2139/**
2140 * @brief get signal csq value
2141 * @param [out] csq_value csq of signalstrengh 0 - 31, 99 invalid
2142 * @retval 0: success
2143 * @retval other: fail
2144 */
2145int gsw_get_sig_info(int *csq_value)
2146{
b.liu68a94c92025-05-24 12:53:41 +08002147 if (nw_init_flag == 0 || nw_info_handle == NULL)
2148 {
xy.heb41615b2025-05-28 16:33:20 +08002149 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002150 }
2151
2152 mbtk_signal_info_t signal;
q.huangfa0a0a32025-06-12 17:07:23 +08002153 int ret = mbtk_net_signal_get(nw_info_handle, &signal);
b.liu68a94c92025-05-24 12:53:41 +08002154 if(ret != 0)
2155 {
2156 LOGE("mbtk_net_signal_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002157 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002158 }
2159
2160 LOGD("signal.type=%d\n", signal.type);
2161 switch(signal.type)
2162 {
q.huangfa0a0a32025-06-12 17:07:23 +08002163
b.liu68a94c92025-05-24 12:53:41 +08002164 case MBTK_RADIO_TECH_E_UTRAN:
2165 {
q.huangfa0a0a32025-06-12 17:07:23 +08002166 LOGD("lte rsrp = %d dbm",signal.rsrp-141);
2167 *csq_value = rsrpToLevel(signal.rsrp-141);
b.liu68a94c92025-05-24 12:53:41 +08002168 break;
2169 }
2170 case MBTK_RADIO_TECH_UTRAN:
2171 case MBTK_RADIO_TECH_UTRAN_HSDPA:
2172 case MBTK_RADIO_TECH_UTRAN_HSUPA:
2173 case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
2174 case MBTK_RADIO_TECH_UTRAN_HSPA:
2175 {
q.huangfa0a0a32025-06-12 17:07:23 +08002176 LOGD("w rscp = %d dbm",signal.rscp-121);
2177 *csq_value = rscpToLevel(signal.rscp-121);
2178 break;
2179 }
2180 case MBTK_RADIO_TECH_GSM:
2181 case MBTK_RADIO_TECH_GSM_COMPACT:
2182 case MBTK_RADIO_TECH_GSM_EGPRS:
2183 {
q.huang861c07d2025-06-24 16:54:58 +08002184 LOGD("gsm rxlev = %d (0-63)",signal.rxlev);
2185 *csq_value = rxlevToLevel(signal.rxlev);
b.liu68a94c92025-05-24 12:53:41 +08002186 break;
2187 }
2188 default:
2189 {
q.huangfa0a0a32025-06-12 17:07:23 +08002190 LOGE("[%s] unknown reg type.[%d]", __func__, signal.type);
xy.heb41615b2025-05-28 16:33:20 +08002191 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002192 }
2193 }
2194 return GSW_HAL_SUCCESS;
2195}
2196
2197/**
2198 * @brief set nework power mode, for tcam enter standby or exit standby
2199 * @param [in] mode TRUE(1) when enter standby, FALSE(0) after wake up
2200 * @retval 0: success
2201 * @retval other: fail
2202 */
2203int gsw_network_set_power_mode(char mode)
2204{
2205 int ret = -1;
2206
2207 if (nw_init_flag == 0 || nw_info_handle == NULL)
2208 {
xy.heb41615b2025-05-28 16:33:20 +08002209 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002210 }
2211
2212 if(mode != 0 && mode != 1)
2213 {
2214 LOGE("Input mode is error!\n");
xy.heb41615b2025-05-28 16:33:20 +08002215 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002216 }
2217
2218 if(mode == 1)
2219 {
2220 mode = 6;
2221 }
2222
2223 ret = mbtk_wakeup_state_set(nw_info_handle, mode);
2224 if(ret != 0)
2225 {
2226 LOGE("mbtk_wakeup_state_set fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002227 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002228 }
2229
2230 return GSW_HAL_SUCCESS;
2231
2232
2233
2234}
2235
2236/**
2237 * @brief convert rsrp rscp rssi to csq value.
2238 * @param [in] netType signal radio tech 2 means 2G 3 mens 3G,4 is 4G,5 is 5G
2239 * @param [in] sigvalue input signal_strength for different nettype
2240 * rsrp for 4G/5G, rscp for 3G, rssi for 2G
2241
2242 * @retval csq
2243 * @retval other: fail
2244 */
2245int gsw_sigInfo_to_csq(int netType, int sigValue)
2246{
q.huang238b22a2025-06-10 14:36:59 +08002247 if (nw_init_flag == 0 || nw_info_handle == NULL)
2248 {
2249 return GSW_HAL_NORMAL_FAIL;
2250 }
b.liu68a94c92025-05-24 12:53:41 +08002251 switch(netType)
q.huangfa0a0a32025-06-12 17:07:23 +08002252 {
2253 case 4:
b.liu68a94c92025-05-24 12:53:41 +08002254 {
q.huangfa0a0a32025-06-12 17:07:23 +08002255 return rsrpToLevel(sigValue);
2256 }
2257 case 3: //WCDMA
b.liu68a94c92025-05-24 12:53:41 +08002258 {
q.huangfa0a0a32025-06-12 17:07:23 +08002259 return rscpToLevel(sigValue);
2260 }
2261 case 2: //GSM
b.liu68a94c92025-05-24 12:53:41 +08002262 {
q.huangfa0a0a32025-06-12 17:07:23 +08002263 return sigValue;
b.liu68a94c92025-05-24 12:53:41 +08002264 }
2265
2266 default:
2267 {
2268 LOGE("parameter error\n");
xy.heb41615b2025-05-28 16:33:20 +08002269 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002270 }
2271 }
2272}
2273
2274/*
2275 * @brief get mobile operator name
2276 @param [out] nw_operator_name_infos get the long and short operator name info
2277 @retval 0: success
2278 @retval 0: other: fail
2279 */
2280int gsw_get_mobile_operator_name(gsw_mobile_operator_name *nw_operator_name_infos)
2281{
2282 char OperatorFN[128];
2283 char OperatorSH[128];
2284 char temp[12] = {0};
2285 mbtk_net_info_t net;
2286
2287 if (nw_init_flag == 0 || nw_info_handle == NULL)
2288 {
xy.heb41615b2025-05-28 16:33:20 +08002289 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002290 }
2291
2292 if(!mbtk_net_sel_mode_get(nw_info_handle, &net) && net.plmn > 0)
2293 {
2294 LOGE("Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);
2295 int i = 0;
2296 while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))
2297 {
2298 if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)
2299 break;
2300 i++;
2301 }
2302
2303 if(i == ARRAY_SIZE(lynq_operator_mcc_mnc)) // No found mcc&mnc
2304 {
2305 strcpy(OperatorFN, "UNKNOWN");
2306 strcpy(OperatorSH, "UNKNOWN");
2307 }
2308 else
2309 {
2310 strcpy(OperatorFN, lynq_operator_mcc_mnc[i].lynq_operator_l);
2311 strcpy(OperatorSH, lynq_operator_mcc_mnc[i].lynq_operator_s);
2312
2313 memset(temp,0,12);
2314 memset(nw_operator_name_infos->mcc,0,4);
2315 sprintf(temp, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)/100);
2316 strncpy(nw_operator_name_infos->mcc, temp, strlen(temp));
2317
2318 memset(temp,0,12);
2319 memset(nw_operator_name_infos->mnc,0,4);
2320 sprintf(temp, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)%100);
2321 strncpy(nw_operator_name_infos->mnc, temp, strlen(temp));
2322 }
2323
2324 memset(nw_operator_name_infos->long_eons,0,128);
2325 memcpy(nw_operator_name_infos->long_eons,OperatorFN,strlen(OperatorFN));
2326 memset(nw_operator_name_infos->short_eons,0,128);
2327 memcpy(nw_operator_name_infos->short_eons,OperatorSH,strlen(OperatorSH));
2328
2329 return GSW_HAL_SUCCESS;
2330 }
2331
2332 else
2333 {
2334 LOGE("mbtk_net_sel_mode_get fail\n");
xy.heb41615b2025-05-28 16:33:20 +08002335 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002336 }
2337
2338 return GSW_HAL_SUCCESS;
2339}
2340
2341
2342/*
2343 * @brief get current serving cell info
2344 * @param cell_info: [out] struct for current cell info
2345 * include earfcn mcc mnc pci psc tac lac etc.
2346 * @return int: 0 is success, other failed
2347 */
2348int gsw_get_cell_info(GSW_NW_CELL_INFO *cell_info)
2349{
b.liu68a94c92025-05-24 12:53:41 +08002350
2351 if (nw_init_flag == 0 || nw_info_handle == NULL)
2352 {
q.huang238b22a2025-06-10 14:36:59 +08002353 printf("nw_sdk_deinit not init\n");
xy.heb41615b2025-05-28 16:33:20 +08002354 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002355 }
2356
2357 list_node_t* cell_list = NULL;
b.liu68a94c92025-05-24 12:53:41 +08002358 mbtk_cell_type_enum type;
q.huang638d5872025-06-21 13:44:43 +08002359 int ret = mbtk_cell_get(nw_info_handle, &type, &cell_list);
b.liu68a94c92025-05-24 12:53:41 +08002360 if(ret || cell_list == NULL) {
2361 LOGE("mbtk_cell_get failed : %d\n", ret);
q.huang638d5872025-06-21 13:44:43 +08002362 list_free(cell_list);
2363 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002364 } else {
q.huang638d5872025-06-21 13:44:43 +08002365 memset(cell_info,0,sizeof(GSW_NW_CELL_INFO));
b.liu68a94c92025-05-24 12:53:41 +08002366 list_first(cell_list);
2367 mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);
2368 if(cell) { // Current server cell.
2369 switch(type)
2370 {
2371 case 0:
2372 {
2373 LOGD("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
q.huang638d5872025-06-21 13:44:43 +08002374 char gsm_temp[12];
b.liu68a94c92025-05-24 12:53:41 +08002375
2376 cell_info->rat = GSW_NETWORK_RADIO_GSM;
2377
2378 cell_info->mcc_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08002379 snprintf(gsm_temp, sizeof(gsm_temp) ,"%X", cell->value5);
b.liu68a94c92025-05-24 12:53:41 +08002380 strncpy(cell_info->mcc, gsm_temp, sizeof(cell_info->mcc));
2381
b.liu68a94c92025-05-24 12:53:41 +08002382 cell_info->mnc_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08002383 snprintf(gsm_temp, sizeof(gsm_temp) ,"%X", cell->value6);
b.liu68a94c92025-05-24 12:53:41 +08002384 strncpy(cell_info->mnc, gsm_temp, sizeof(cell_info->mnc));
2385
2386 cell_info->cell_id_valid = 1;
2387 cell_info->cell_id = cell->value2;
2388
2389 cell_info->lac_valid = 1;
2390 cell_info->lac = cell->value1;
2391
2392 cell_info->arfcn_valid = 1;
2393 cell_info->arfcn = cell->value3;
q.huang861c07d2025-06-24 16:54:58 +08002394
2395 cell_info->rssi=rxlev_convert_to_rssi_dBm(cell->value7);
2396 cell_info->rssi_valid = (cell_info->rssi!=INT_32_MAX);
b.liu68a94c92025-05-24 12:53:41 +08002397 break;
2398 }
2399
2400 case 1:
2401 {
2402 LOGD("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
q.huang638d5872025-06-21 13:44:43 +08002403 char wcdma_temp[12];
b.liu68a94c92025-05-24 12:53:41 +08002404
2405 cell_info->rat = GSW_NETWORK_RADIO_UMTS;
2406
2407 cell_info->mcc_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08002408 snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%X", cell->value4);
b.liu68a94c92025-05-24 12:53:41 +08002409 strncpy(cell_info->mcc, wcdma_temp, sizeof(cell_info->mcc));
2410
b.liu68a94c92025-05-24 12:53:41 +08002411 cell_info->mnc_valid = 1;
q.huang861c07d2025-06-24 16:54:58 +08002412 snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%X", cell->value5);
b.liu68a94c92025-05-24 12:53:41 +08002413 strncpy(cell_info->mnc, wcdma_temp, sizeof(cell_info->mnc));
2414
2415 cell_info->lac_valid = 1;
2416 cell_info->lac = cell->value1;
2417
2418 cell_info->cell_id_valid = 1;
2419 cell_info->cell_id = cell->value2;
2420
2421 cell_info->uarfcn_valid = 1;
2422 cell_info->uarfcn = cell->value3;
2423
2424 cell_info->psc_valid = 1;
2425 cell_info->psc = cell->value6;
2426 break;
2427 }
2428
2429 case 2:
2430 {
2431 LOGE("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 +08002432
q.huang638d5872025-06-21 13:44:43 +08002433 char lte_temp[12];
b.liu68a94c92025-05-24 12:53:41 +08002434 cell_info->rat = GSW_NETWORK_RADIO_LTE;
2435
2436 cell_info->mcc_valid = 1;
2437 snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);
2438 strncpy(cell_info->mcc, lte_temp, sizeof(cell_info->mcc));
2439
b.liu68a94c92025-05-24 12:53:41 +08002440 cell_info->mnc_valid = 1;
2441 snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);
2442 strncpy(cell_info->mnc, lte_temp, sizeof(cell_info->mnc));
2443
2444 cell_info->tac_valid = 1;
2445 cell_info->tac = cell->value1;
2446
2447 cell_info->pci_valid = 1;
2448 cell_info->pci = cell->value2;
2449
2450 cell_info->earfcn_valid = 1;
2451 cell_info->earfcn = cell->value3;
2452
2453 cell_info->bler_valid = 1;
2454 cell_info->bler = cell->value4;
2455
2456 cell_info->band_valid = 1;
2457 cell_info->band = cell->value5;
2458
q.huang638d5872025-06-21 13:44:43 +08002459 cell_info->rssnr = sinr_convert_to_10_times_dB(cell->value11);
2460 cell_info->rssnr_valid=(cell_info->rssnr!=INT_32_MAX);
b.liu68a94c92025-05-24 12:53:41 +08002461
q.huang638d5872025-06-21 13:44:43 +08002462 cell_info->lteMode_valid = 1;
2463 cell_info->lteMode =(!(cell->value12));
2464
2465
2466 cell_info->rsrp = rsrp_convert_to_minus_dBm(cell->value8);
2467 cell_info->rsrp_valid = (cell_info->rsrp!=INT_32_MAX);
2468
2469 cell_info->rsrq = rsrq_convert_to_minus_dB(cell->value9);
2470 cell_info->rsrq_valid = (cell_info->rsrq!=INT_32_MAX);
b.liu68a94c92025-05-24 12:53:41 +08002471
2472 cell_info->cell_id_valid = 1;
2473 cell_info->cell_id = cell->value10;
2474
q.huang638d5872025-06-21 13:44:43 +08002475 cell_info->rssi=rsrp_minus_dbm_convert_to_rssi_dBm(cell_info->rsrp);
2476 cell_info->rssi_valid = (cell_info->rssi!=INT_32_MAX);
2477
b.liu68a94c92025-05-24 12:53:41 +08002478 break;
2479 }
2480
2481 default:
2482 break;
2483 }
2484 }
q.huang638d5872025-06-21 13:44:43 +08002485 int neibor_count = 0;
b.liu68a94c92025-05-24 12:53:41 +08002486 while ((cell = (mbtk_cell_info_t*) list_next(cell_list)) && neibor_count < 5)
2487 {
2488 switch(type)
2489 {
2490 //GSM
2491 case 0:
2492 {
2493
2494 }
2495 //WCDMA
2496 case 1:
2497 {
2498 LOGE("CELL : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
2499
2500 //cell_info->ext_info[neibor_count]->lac = cell->value1;
2501
2502 cell_info->ext_info[neibor_count].cell_id_valid = 1;
2503 cell_info->ext_info[neibor_count].cell_id = cell->value2;
2504
2505 cell_info->ext_info[neibor_count].arfcn_valid = 1;
2506 cell_info->ext_info[neibor_count].arfcn = cell->value3;
2507
2508 cell_info->ext_info[neibor_count].rat = cell_info->rat = GSW_NETWORK_RADIO_UMTS;
2509
2510 neibor_count++;
2511
2512 }
2513 //LTE
2514 case 2:
2515 {
2516 LOGE("CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
2517 char lte_temp[12] = {0};
2518 cell_info->ext_info[neibor_count].rat = GSW_NETWORK_RADIO_LTE;
2519
q.huang638d5872025-06-21 13:44:43 +08002520
b.liu68a94c92025-05-24 12:53:41 +08002521 cell_info->ext_info[neibor_count].pci = cell->value1;
2522 cell_info->ext_info[neibor_count].pci_valid = 1;
2523
2524 cell_info->ext_info[neibor_count].arfcn = cell->value2;
2525 cell_info->ext_info[neibor_count].arfcn_valid = 1;
2526
q.huang638d5872025-06-21 13:44:43 +08002527 cell_info->ext_info[neibor_count].rsrp = rsrp_convert_to_minus_dBm(cell->value3);
2528 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 +08002529
q.huang638d5872025-06-21 13:44:43 +08002530 cell_info->ext_info[neibor_count].rsrq = rsrq_convert_to_minus_dB(cell->value4);
2531 cell_info->ext_info[neibor_count].rsrq_valid = (cell_info->ext_info[neibor_count].rsrq!=INT_32_MAX);
2532
2533 if(cell->value7!=INT_32_MAX)
2534 {
2535 cell_info->ext_info[neibor_count].cell_id = cell->value5;
2536 cell_info->ext_info[neibor_count].cell_id_valid = 1;
2537
2538 snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);
2539 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 +08002540
b.liu68a94c92025-05-24 12:53:41 +08002541
q.huang638d5872025-06-21 13:44:43 +08002542 snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);
2543 strncpy(cell_info->ext_info[neibor_count].mnc, lte_temp, sizeof(cell_info->ext_info[neibor_count].mnc));
2544
2545
2546 //value 8 is tac
b.liu68a94c92025-05-24 12:53:41 +08002547
q.huang638d5872025-06-21 13:44:43 +08002548 cell_info->ext_info[neibor_count].band = cell->value9;
2549 cell_info->ext_info[neibor_count].band_valid = 1;
2550
2551 cell_info->ext_info[neibor_count].rssi=rsrp_minus_dbm_convert_to_rssi_dBm(cell_info->ext_info[neibor_count].rsrp);
2552 cell_info->ext_info[neibor_count].rssi_valid = (cell_info->ext_info[neibor_count].rssi!=INT_32_MAX);
2553 }
b.liu68a94c92025-05-24 12:53:41 +08002554
2555 neibor_count++;
2556 }
2557
2558 default:
2559 break;
2560 }
2561 }
q.huang638d5872025-06-21 13:44:43 +08002562 cell_info->ext_info_len=neibor_count;
b.liu68a94c92025-05-24 12:53:41 +08002563 }
2564 list_free(cell_list);
2565
2566 return GSW_HAL_SUCCESS;
2567}
2568
2569/*
2570 * @brief set modem status event callback
2571 @param [in] handle_ptr callback function address
2572 @retval 0: success
2573 @retval 0: other: fail
2574 */
2575int gsw_reg_set_modem_status_event_callback(GSW_NW_ModemStateHandlePtr handle_ptr)
2576{
2577
2578 if (nw_init_flag == 0 || nw_info_handle == NULL)
2579 {
xy.heb41615b2025-05-28 16:33:20 +08002580 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002581 }
2582
b.liu68a94c92025-05-24 12:53:41 +08002583 if(handle_ptr == NULL)
2584 {
2585 LOGE("handle_ptr is NULL\n");
q.huang66b79162025-06-27 17:45:34 +08002586 modem_cb=NULL;
2587 return GSW_HAL_SUCCESS;
b.liu68a94c92025-05-24 12:53:41 +08002588 }
2589
2590 modem_cb = handle_ptr;
2591
b.liu68a94c92025-05-24 12:53:41 +08002592 return GSW_HAL_SUCCESS;
2593
2594}
2595
2596
2597/*
2598 * @brief get PLMNs from the FPLMN list
2599 * @param [inout] plmn_list:
2600 * @retval 0: success
2601 * @retval other: fail
2602 */
2603int gsw_get_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
2604{
2605 if (nw_init_flag == 0 || nw_info_handle == NULL)
2606 {
xy.heb41615b2025-05-28 16:33:20 +08002607 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002608 }
2609
2610 int ret = -1;
2611 char fplmn[256] = {0};
2612 LOGE("mbtk_fplmn_get enter\n");
2613 ret = mbtk_fplmn_get(nw_info_handle, fplmn);
2614 LOGE("mbtk_fplmn_get exit\n");
2615 if(ret != 0)
2616 {
2617 LOGE("mbtk_fplmn_get failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002618 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002619 }
2620
2621 update_fplmn_list(fplmn);
2622 for(int i = 0; i < fplmn_index; i++)
2623 {
2624 if(strcmp(fplmn_array[i],"FFFFFF") == 0)
2625 {
2626 continue;
2627 }
2628 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);
2629 LOGE("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);
2630 plmn_list->plmn_list_len++;
2631 }
2632
2633 LOGE("fplmn = %s\n", fplmn);
2634 return GSW_HAL_SUCCESS;
2635}
2636
2637/*
2638 * @brief add PLMNs from the plmn_list to the FPLMN list
2639 * @param [in] plmn_list:
2640 * @retval 0: success
2641 * @retval other: fail
2642 */
2643int gsw_add_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
2644{
2645
2646 if (nw_init_flag == 0 || nw_info_handle == NULL)
2647 {
xy.heb41615b2025-05-28 16:33:20 +08002648 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002649 }
2650
2651 if(plmn_list->plmn_list_len >= fplmn_max_length)
2652 {
2653 LOGE("can't save all the plmn\n");
xy.heb41615b2025-05-28 16:33:20 +08002654 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002655 }
2656
2657 int i = 0;
2658 int index = -1;
2659
2660 for(i = 0; i < plmn_list->plmn_list_len; i++)
2661 {
2662 index = check_index(plmn_list->plmn_list[i].mcc, plmn_list->plmn_list[i].mnc);
2663
2664 if(index == -1)
2665 {
2666 LOGE("no this PLMN, add it\n");
2667 if((fplmn_index + plmn_list->plmn_list_len) > fplmn_max_length)
2668 {
2669 LOGE("can't save all the plmn\n");
xy.heb41615b2025-05-28 16:33:20 +08002670 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002671 }
2672
2673 else
2674 {
2675 memcpy(fplmn_array[fplmn_index], plmn_list->plmn_list[i].mcc, 3);
2676 memcpy(fplmn_array[fplmn_index] + 3, plmn_list->plmn_list[i].mnc, 2);
2677 fplmn_array[fplmn_index][5] = '\0';
2678 LOGE("fplmn_array[%d] = %s\n", fplmn_index, fplmn_array[fplmn_index]);
2679 fplmn_index++;
2680 }
2681 }
2682
2683 else
2684 {
2685 LOGE("already have this PLMN, don't add it\n");
2686 }
2687 }
2688
2689 char fplmn_str[256] = {0};
2690 convert_plmn_to_fplmn_str(fplmn_str);
2691
2692 LOGE("fplmn_str = %s\n", fplmn_str);
2693
2694 int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
2695 if(ret != 0)
2696 {
2697 LOGE("mbtk_fplmn_set failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002698 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002699 }
2700
2701 LOGE("gsw_add_forbidden_networks exit\n");
2702 return GSW_HAL_SUCCESS;
2703}
2704
2705/*
2706 * @brief Remove PLMNs from the plmn_list from the FPLMN list
2707 * @param [in] plmn_list:
2708 * @retval 0: success
2709 * @retval other: fail
2710 */
2711int gsw_remove_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
2712{
b.liu68a94c92025-05-24 12:53:41 +08002713 if (nw_init_flag == 0 || nw_info_handle == NULL)
2714 {
q.huangfa0a0a32025-06-12 17:07:23 +08002715 printf("nw sdk has not init\n");
xy.heb41615b2025-05-28 16:33:20 +08002716 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002717 }
2718
2719 int i = 0;
2720 int index = -1;
2721
2722 for(i = 0; i < plmn_list->plmn_list_len; i++)
2723 {
2724 index = check_index(plmn_list->plmn_list[i].mcc, plmn_list->plmn_list[i].mnc);
2725 if(index != -1)
2726 {
2727 remove_fplmn(index);
2728 }
2729 else
2730 {
2731 LOGE("no this PLMN, can't remove it\n");
2732 }
2733 }
2734
2735 for(i = 0; i < fplmn_index; i++)
2736 {
2737 LOGE("fplmn_array[%d] = %s\n", i, fplmn_array[i]);
2738 }
2739
2740 char fplmn_str[256] = {0};
2741 convert_plmn_to_fplmn_str(fplmn_str);
2742 LOGE("fplmn_str = %s\n", fplmn_str);
2743
2744 int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
2745 if(ret != 0)
2746 {
2747 LOGE("mbtk_fplmn_set failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002748 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002749 }
2750
2751 LOGE("gsw_remove_forbidden_networks exit\n");
2752 return GSW_HAL_SUCCESS;
2753}
2754
2755/*
2756 * @brief clear FPLMN list
2757 * @param
2758 * @retval 0: success
2759 * @retval other: fail
2760 */
2761int gsw_clear_forbidden_networks(void)
2762{
2763 if (nw_init_flag == 0 || nw_info_handle == NULL)
2764 {
xy.heb41615b2025-05-28 16:33:20 +08002765 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002766 }
2767
2768 char fplmn_str[FPLMN_STRING_LENGTH+1];
2769 memset(fplmn_str, 'F', (6 * fplmn_max_length));
2770 fplmn_str[(6 * fplmn_max_length)] = '\0';
2771
2772 LOGE("%s\n", fplmn_str);
2773 int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
2774 if(ret != 0)
2775 {
2776 LOGE("mbtk_fplmn_set failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002777 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002778 }
2779
2780 return GSW_HAL_SUCCESS;
2781}
2782
2783/*
2784 * @brief get oos config
2785 * @param [in] oos_config
2786 * @retval 0: success
2787 * @retval other: fail
2788 */
2789int gsw_oos_config_get(GSW_NW_OOS_CONFIG_INFO_T *pt_info)
2790{
2791 if (nw_init_flag == 0 || nw_info_handle == NULL)
2792 {
xy.heb41615b2025-05-28 16:33:20 +08002793 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002794 }
2795
2796 if(pt_info == NULL)
2797 {
2798 LOGE("pt_info is null\n");
xy.heb41615b2025-05-28 16:33:20 +08002799 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002800 }
2801
2802 int ret = -1;
2803
2804 mbtk_oos_info oos_info;
2805 memset(&oos_info, 0x00, sizeof(mbtk_oos_info));
2806
2807 ret = mbtk_oos_get(nw_info_handle, &oos_info);
2808 if(ret != 0)
2809 {
2810 LOGE("mbtk_oos_get failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002811 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002812 }
2813
2814 if(oos_info.mode == 0)
2815 {
2816 pt_info->t_min = 0;
2817 pt_info->t_step = 0;
2818 pt_info->t_max = 0;
2819 }
2820
2821 else
2822 {
2823 pt_info->t_min = (int)oos_info.oosPhase[0];
2824 pt_info->t_step = (int)oos_info.oosPhase[1];
2825 pt_info->t_max = (int)oos_info.oosPhase[2];
2826 }
2827
2828 return GSW_HAL_SUCCESS;
2829}
2830
2831
2832/*
2833 * @brief set oos config
2834 * @param [in] oos_config
2835 * @retval 0: success
2836 * @retval other: fail
2837 */
2838int gsw_oos_config_set(GSW_NW_OOS_CONFIG_INFO_T *pt_info)
2839{
2840 if (nw_init_flag == 0 || nw_info_handle == NULL)
2841 {
xy.heb41615b2025-05-28 16:33:20 +08002842 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002843 }
2844
2845 if(pt_info == NULL)
2846 {
2847 LOGE("pt_info is null\n");
xy.heb41615b2025-05-28 16:33:20 +08002848 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002849 }
2850
2851 int ret = -1;
2852 mbtk_oos_info oos_info;
2853 memset(&oos_info, 0x00, sizeof(mbtk_oos_info));
2854
2855 if (pt_info->t_min < 0 || pt_info->t_step < 0 || pt_info->t_max < 0)
2856 {
2857 LOGE("gsw_oos_config_set set time < 0 ");
xy.heb41615b2025-05-28 16:33:20 +08002858 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002859 }
2860 else if ((pt_info->t_min > 0 && pt_info->t_min <= 255) && pt_info->t_step == 0 && pt_info->t_max == 0)
2861 {
2862 oos_info.mode = 1;
2863 oos_info.oosPhase[0] = pt_info->t_min;
2864 }
2865 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)
2866 {
2867 oos_info.mode = 1;
2868 oos_info.oosPhase[0] = pt_info->t_min;
2869 oos_info.oosPhase[1] = pt_info->t_step;
2870 }
2871 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))
2872 {
2873 oos_info.mode = 1;
2874 oos_info.oosPhase[0] = pt_info->t_min;
2875 oos_info.oosPhase[1] = pt_info->t_step;
2876 oos_info.oosPhase[2] = pt_info->t_max;
2877 }
2878 else if (pt_info->t_min == 0 && pt_info->t_step == 0 && pt_info->t_max == 0)
2879 {
2880 oos_info.mode = 0;
2881 }
2882 else
2883 {
2884 LOGE("gsw_oos_config_set set Format err");
xy.heb41615b2025-05-28 16:33:20 +08002885 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002886 }
2887
2888 ret = mbtk_oos_set(nw_info_handle, &oos_info);
2889 if(ret != 0)
2890 {
2891 LOGE("mbtk_oos_set failed : %d\n",ret);
xy.heb41615b2025-05-28 16:33:20 +08002892 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08002893 }
2894
2895 return GSW_HAL_SUCCESS;
2896}
2897
q.huang238b22a2025-06-10 14:36:59 +08002898/**
2899 * @brief get imei function
2900 * @param [in] len imei length,max is 20
2901 * @param [out] imei return imei from this func
2902 * @retval 0: success
2903 * @retval other: fail
2904 */
2905int gsw_get_imei(int len, char *imei)
2906{
q.huang238b22a2025-06-10 14:36:59 +08002907 if (nw_init_flag == 0 || nw_info_handle == NULL)
2908 {
2909 printf("nw sdk has been deinit\n");
2910 return GSW_HAL_NORMAL_FAIL;
2911 }
2912
2913 if(imei == NULL)
2914 {
2915 LOGE("imei is NULL.");
2916 return GSW_HAL_ARG_INVALID;
2917 }
2918
2919 if(len < GSW_IMEI_LENGTH)
2920 {
2921 LOGE("imei len is too short,len = %d\n", len);
2922 return GSW_HAL_NORMAL_FAIL;
2923 }
2924
q.huang861c07d2025-06-24 16:54:58 +08002925 int ret = mbtk_imei_get(nw_info_handle, (void *)imei);
q.huang238b22a2025-06-10 14:36:59 +08002926 if(ret != MBTK_ERR_OK)
2927 {
2928 LOGE("[gsw_nw] mbtk_imei_get fail [err = %d].", ret);
2929 return GSW_HAL_NORMAL_FAIL;
2930 }
2931
2932 return GSW_HAL_SUCCESS;
2933}
2934
2935/**
2936 * @brief reset modem stack only, notice: after use this method, all ril sdk
2937 * need restart by app, means network, sim, sms, data need deinit then init!
2938 * @param
2939 * @retval 0: success
2940 * @retval other: fail
2941 */
2942int gsw_reset_modem(void)
2943{
2944 int ret = -1;
2945 if (nw_init_flag == 0 || nw_info_handle == NULL)
2946 {
2947 printf("nw sdk has been deinit\n");
2948 return GSW_HAL_NORMAL_FAIL;
2949 }
2950 mbtk_modem_info_t info;
2951 info.fun = MBTK_DEV_MODEM_MIN_FUN;
2952 info.rst = 0;
2953
2954 ret = mbtk_set_modem_fun(nw_info_handle, &info);
2955 if(ret)
2956 {
2957 LOGE("[gsw_nw] mbtk_set_modem_fun 0 fail [err = %d].", ret);
2958 return GSW_HAL_NORMAL_FAIL;
2959 }
2960
2961 sleep(1);
2962
2963 info.fun = MBTK_DEV_MODEM_FULL_FUN;
2964 ret = mbtk_set_modem_fun(nw_info_handle, &info);
2965 if(ret)
2966 {
2967 LOGE("[gsw_nw] mbtk_set_modem_fun 1 fail [err = %d].", ret);
2968 return GSW_HAL_NORMAL_FAIL;
2969 }
2970 return GSW_HAL_SUCCESS;
2971}
b.liu68a94c92025-05-24 12:53:41 +08002972
q.huangc8b93122025-06-17 17:46:05 +08002973int gsw_reg_operating_mode_callback(GSW_NW_AirplaneModeHandlePtr handle_ptr)
2974{
2975 if (nw_init_flag == 0 || nw_info_handle == NULL)
2976 {
2977 return GSW_HAL_NORMAL_FAIL;
2978 }
2979
2980 if(handle_ptr == NULL)
2981 {
2982 LOGE("handle_ptr is NULL\n");
2983 return GSW_HAL_NORMAL_FAIL;
2984 }
2985
2986 airplane_cb = handle_ptr;
2987
2988 int ret = mbtk_radio_state_change_cb_reg(nw_info_handle,gsw_operating_mode_event_callback);
2989 if(ret != 0)
2990 {
2991 LOGE("mbtk_radio_state_change_cb_reg failed : %d\n", ret);
2992 airplane_cb=NULL;
2993 return GSW_HAL_NORMAL_FAIL;
2994 }
2995
2996 return GSW_HAL_SUCCESS;
2997
2998}
2999