Fix mbtk from v1265 GSW

Change-Id: I5d8d395616f284bc74c8b9448cfa347164b5a668
diff --git a/mbtk/libgsw_lib/gsw_nw.c b/mbtk/libgsw_lib/gsw_nw.c
new file mode 100755
index 0000000..e485574
--- /dev/null
+++ b/mbtk/libgsw_lib/gsw_nw.c
@@ -0,0 +1,2572 @@
+#include "gsw_nw_interface.h"

+#include <dlfcn.h>

+#include <time.h>

+#include <pthread.h>

+

+//mbtk include

+#define LYNQ_AIR_PLANE_MODE_OFF      1    //at+cfun = 1

+#define LYNQ_AIR_PLANE_MODE_ON     4   // at+cfun = 4

+#define LYNQ_AIR_CFUN_MODE_OFF     0   // at+cfun = 0

+

+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

+

+#define FPLMN_STRING_LENGTH 120

+#define ENTRY_LENGTH 6

+#define FPLMN_ARRAY_SIZE (FPLMN_STRING_LENGTH / 6) + 1

+

+#ifndef FALSE

+#define FALSE   (0)

+#endif

+ 

+ 

+#ifndef TRUE

+#define TRUE    (!FALSE)

+#endif

+

+typedef unsigned int uint32;

+typedef unsigned char uint8;

+typedef unsigned short uint16;

+typedef void (*mbtk_info_callback_func)(const void* data, int data_len);

+

+typedef enum

+{

+    MBTK_DEV_MODEM_MIN_FUN,                                   //Modem 最小功能

+    MBTK_DEV_MODEM_FULL_FUN,                                  //Modem 全功能

+    MBTK_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS = 3,           //Modem 禁用射频接收电路

+    MBTK_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS,  //Modem禁用射频发射和接收电路

+    MBTK_DEV_MODEM_DISABLE_SIM,                               //Modem 禁用(U)SIM 卡

+    MBTK_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE,           //Modem 完全禁用辅助接收

+}MBTK_DEV_MODEM_FUNCTION;

+

+typedef enum

+{

+    MBTK_CELL_TYPE_GSM = 0,

+    MBTK_CELL_TYPE_UMTS,

+    MBTK_CELL_TYPE_LTE

+} mbtk_cell_type_enum;

+

+typedef struct

+{

+    MBTK_DEV_MODEM_FUNCTION fun;

+    int rst;

+} mbtk_modem_info_t;

+

+typedef struct

+{

+    int client_fd;

+    pthread_t read_thread_id;

+    int exit_fd[2];

+    bool is_waitting;

+    pthread_cond_t cond;

+    pthread_mutex_t mutex;

+

+    pthread_mutex_t send_mutex;

+

+    // Temp response data.

+    uint16 info_err;

+    uint16 data_len;

+    void *data;

+

+    //mbtk wyq for server_ready_status add start

+    char server_ready_status;

+    //mbtk wyq for server_ready_status add end

+

+    mbtk_info_callback_func net_state_cb;

+    mbtk_info_callback_func call_state_cb;

+    mbtk_info_callback_func sms_state_cb;

+    mbtk_info_callback_func radio_state_cb;

+    mbtk_info_callback_func sim_state_cb;

+    mbtk_info_callback_func pdp_state_cb;

+    //add signal by xr

+    mbtk_info_callback_func signal_state_cb;

+} mbtk_info_handle_t;

+

+

+

+typedef struct

+{

+    // LTE server cell: tac, PCI, dlEuarfcn, ulEuarfcn, band

+    // LTE cell: phyCellId,euArfcn,rsrp,rsrq

+    // WCDMA server cell: lac, ci, arfcn

+    // WCDMA cell: lac, ci, arfcn

+    // GSM server cell: lac, ci, arfcn, bsic

+    // GSM cell:

+    uint32 value1;

+    uint32 value2;

+    uint32 value3;

+    uint32 value4;

+    uint32 value5;

+	uint32 value6;

+    uint32 value7;

+    uint32 value8;

+    uint32 value9;

+    uint32 value10;

+} __attribute__((packed)) mbtk_cell_info_t;

+

+

+

+

+

+typedef struct

+{

+    uint8 net_pref;     // mbtk_net_pref_enum

+    uint16 gsm_band;    // mbtk_gsm_band_enum

+    uint16 umts_band;   // mbtk_umts_band_enum

+    uint32 tdlte_band;  // mbtk_tdlte_band_enum

+    uint32 fddlte_band; // mbtk_fddlte_band_enum

+    uint32 lte_ext_band; // mbtk_lte_ext_band_enum

+} __attribute__((packed)) mbtk_band_info_t;

+

+typedef struct list_arraynode

+{

+    void *data;

+    struct list_arraynode *next;

+} list_arraynode_t;

+

+typedef struct list_treenode

+{

+    list_arraynode_t *data;

+    int count;

+    struct list_treenode *left;

+    struct list_treenode *right;

+} list_treenode_t;

+

+typedef int (*list_sort_func)(void *data1, void *data2);

+typedef void (*list_free_func)(void *data);

+

+typedef struct list_node

+{

+    uint32 size;

+    list_sort_func sort_func;

+    list_free_func free_func;

+

+    uint32 cur_index;

+    list_arraynode_t *cur_array_data;

+

+    list_arraynode_t array_data;

+    list_treenode_t tree_data;

+} list_node_t;

+

+/*

+0: GSM

+1: GSM Compact

+2: UTRAN

+3: GSM w/EGPRS

+4: UTRAN w/HSDPA

+5: UTRAN w/HSUPA

+6: UTRAN w/HSDPA and HSUPA

+7: E-UTRAN

+8: UTRAN HSPA+

+*/

+typedef enum {

+    MBTK_RADIO_TECH_GSM = 0,

+    MBTK_RADIO_TECH_GSM_COMPACT,

+    MBTK_RADIO_TECH_UTRAN,

+    MBTK_RADIO_TECH_GSM_EGPRS,

+    MBTK_RADIO_TECH_UTRAN_HSDPA,

+    MBTK_RADIO_TECH_UTRAN_HSUPA,

+    MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA,

+    MBTK_RADIO_TECH_E_UTRAN,      // LTE

+    MBTK_RADIO_TECH_UTRAN_HSPA

+} mbtk_radio_technology_enum;

+

+typedef struct

+{

+    /*

+    0: automatic

+    1: manual

+    */

+    uint8 net_sel_mode;

+    /*

+    0: GSM

+    1: GSM Compact

+    2: UTRAN

+    3: GSM w/EGPRS

+    4: UTRAN w/HSDPA

+    5: UTRAN w/HSUPA

+    6: UTRAN w/HSDPA and HSUPA

+    7: E-UTRAN

+    8: UTRAN HSPA+

+    0xFF: Unused

+    */

+    uint8 net_type;

+    //uint8 plmn[10]; // 46000

+    /*

+    0: unknown

+    1: available

+    2: current

+    3: forbidden

+    */

+    uint8 net_state;

+    uint32 plmn;

+} __attribute__((packed)) mbtk_net_info_t;

+

+

+typedef enum

+{

+    MBTK_NET_REG_STATE_NON = 0,

+    MBTK_NET_REG_STATE_HOME,

+    MBTK_NET_REG_STATE_SEARCHING,

+    MBTK_NET_REG_STATE_DENIED,

+    MBTK_NET_REG_STATE_UNKNOWN,

+    MBTK_NET_REG_STATE_ROAMING,

+    MBTK_NET_REG_STATE_SMS_ONLY,

+    MBTK_NET_REG_STATE_ROAMING_SMS,

+    MBTK_NET_REG_STATE_ATTACHED_EMERGENCY,

+    MBTK_NET_REG_STATE_CSFB_HOME,

+    MBTK_NET_REG_STATE_CSFB_ROAMING,

+    MBTK_NET_REG_STATE_EMERGENCY_ONLY

+} mbtk_net_reg_state_enum;

+

+typedef struct

+{

+    uint8 call_state;// mbtk_net_reg_state_enum

+    uint8 data_state;// mbtk_net_reg_state_enum

+    uint8 ims_state;// mbtk_net_reg_state_enum

+    uint8 type; // mbtk_radio_technology_enum

+    uint16 lac;

+    uint32 ci;

+} __attribute__((packed)) mbtk_net_reg_info_t;

+

+typedef struct

+{

+    uint8 type; // mbtk_radio_technology_enum

+    uint8 rssi; // 0: 113 dBm or less

+                // 1: 111 dBm

+                // 2��30: 109��53 dBm

+                // 31: 51 dBm or greater

+                // 99: not known or not detectable

+    uint8 rxlev;// 0:rssi < -110 dBm

+                // 1: -110 dBm �� rssi < -109 dBm

+                // 2: -109 dBm �� rssi < -108 dBm

+                // ......

+                // 61: -50 dBm �� rssi < -49 dBm

+                // 62: -49 dBm �� rssi < -48 dBm

+                // 63: -48 dBm �� rssi

+                // 99: not known or not detectable

+    uint8 ber;  // 0...7 as RXQUAL values in the table in 3GPP TS 45.008 [20] subclause 8.2.4

+                // 99 not known or not detectable

+    uint8 rscp; // 0: rscp < -120 dBm

+                // 1: -120 dBm �� rscp < -119 dBm

+                // 2: -119 dBm �� rscp < -118 dBm

+                // ......

+                // 94: -27 dBm �� rscp < -26 dBm

+                // 95: -26 dBm �� rscp < -25 dBm

+                // 96: - 25 dBm �� rscp

+                // 255: not known or not detectable

+    uint8 ecno; // 0: Ec/Io < -24 dB

+                // 1: -24 dB �� Ec/Io < -23.5 dB

+                // 2: -23.5 dB �� Ec/Io < -23 dB

+                // ......

+                // 47: -1 dB �� Ec/Io < -0.5 dB

+                // 48: -0.5 dB �� Ec/Io < 0 dB

+                // 49: 0 dB �� Ec/Io

+                // 255: not known or not detectable

+    uint8 rsrq; // 0: rsrq < -19.5 dB

+                // 1: -19.5 dB �� rsrq < -19 dB

+                // 2: -19 dB �� rsrq < -18.5 dB

+                // ......

+                // 32: -4 dB �� rsrq < -3.5 dB

+                // 33: -3.5 dB �� rsrq < -3 dB

+                // 34: -3 dB �� rsrq

+                // 255: not known or not detectable

+    uint8 rsrp; // 0: rsrp < -140 dBm

+                // 1: -140 dBm �� rsrp < -139 dBm

+                // 2: -139 dBm �� rsrp < -138 dBm

+                // ......

+                // 95: -46 dBm �� rsrp < -45 dBm

+                // 96: -45 dBm �� rsrp < -44 dBm

+                // 97: -44 dBm �� rsrp

+                // 255: not known or not detectable

+} __attribute__((packed)) mbtk_signal_info_t;

+

+typedef struct{

+    uint8_t         mode;

+    uint32_t        oosPhase[3];   //单位为秒

+} mbtk_oos_info;

+

+typedef struct

+{

+    /*    Configuration parameters for MCM network full band network scan when OOS (out of service)*/

+    int t_min;

+    int t_step;

+    int t_max;

+}GSW_NW_OOS_CONFIG_INFO_T;

+

+

+#define GSW_HAL_FAIL GSW_HAL_NORMAL_FAIL

+#define GSW_HAL_MEM_INVAILD GSW_HAL_ARG_INVALID

+#define lib_mbtk_path "/lib/libmbtk_lib.so"

+mbtk_info_handle_t*       nw_info_handle = NULL;

+

+static GSW_NW_ServingInfoHandlePtr serving_cb;

+static GSW_NW_SigInfoHandlePtr sig_cb;

+static GSW_NW_RejectCauseHandlePtr reject_cb;

+static GSW_NW_ModemStateHandlePtr modem_cb;

+

+static void *dlHandle_mbtk;

+int nw_init_flag = 0;

+int mode = -1;

+int fplmn_max_length = 0;

+

+gsw_nw_plmn_list_t gsw_nw_plmn_list;

+char fplmn_array[FPLMN_ARRAY_SIZE][7];

+int fplmn_index = 0;

+

+static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);

+static int (*mbtk_info_handle_free)(mbtk_info_handle_t** handle);

+int (*mbtk_net_sel_mode_get)(mbtk_info_handle_t* handle, mbtk_net_info_t *net);

+int (*mbtk_net_reg_get)(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg);

+int (*mbtk_cell_get)(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list);

+int (*mbtk_get_modem_fun)(mbtk_info_handle_t* handle, int* fun);

+static int (*mbtk_set_modem_fun)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info);

+int (*mbtk_current_band_get)(mbtk_info_handle_t* handle, mbtk_band_info_t *band);

+int (*mbtk_current_band_set)(mbtk_info_handle_t* handle, const mbtk_band_info_t *band);

+int (*mbtk_net_signal_get)(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal);

+int (*mbtk_wakeup_state_set)(mbtk_info_handle_t* handle, uint32 wakeup_state);

+int (*mbtk_signal_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);

+int (*mbtk_net_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);

+int (*mbtk_fplmn_get)(mbtk_info_handle_t *handle, void *fplmn);

+int (*mbtk_fplmn_set)(mbtk_info_handle_t *handle, void *fplmn);

+int (*mbtk_radio_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);

+int (*mbtk_oos_get)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);

+int (*mbtk_oos_set)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);

+

+static void (*mbtk_log)(int level, const char *format, ...);

+static void (*mbtk_log_init)(char *path, char *tag);

+

+#ifndef LOG_ERR_LEVEL

+#define LOG_ERR_LEVEL  3      /* error conditions */

+#endif

+#ifndef LOG_WARN_LEVEL

+#define LOG_WARN_LEVEL 4   /* warning conditions */

+#endif

+#ifndef LOG_INFO_LEVEL

+#define LOG_INFO_LEVEL 6      /* informational */

+#endif

+#ifndef LOG_DEBUG_LEVEL

+#define LOG_DEBUG_LEVEL 7     /* debug-level messages */

+#endif

+#ifndef LOG_VERBOSE_LEVEL

+#define LOG_VERBOSE_LEVEL 8

+#endif

+

+#define LOGV(fmt, args ...) \

+    do{ \

+        char *file_ptr_1001 = __FILE__; \

+        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \

+        char line_1001[10] = {0}; \

+        sprintf(line_1001, "%d", __LINE__); \

+        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \

+            if(*ptr_1001 == '/') \

+                 break; \

+            ptr_1001--; \

+        } \

+        mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \

+    } while(0)

+

+#define LOGI(fmt, args...) \

+    do{ \

+        char *file_ptr_1001 = __FILE__; \

+        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \

+        char line_1001[10] = {0}; \

+        sprintf(line_1001, "%d", __LINE__); \

+        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \

+            if(*ptr_1001 == '/') \

+                 break; \

+            ptr_1001--; \

+        } \

+        mbtk_log(LOG_INFO_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \

+    } while(0)

+

+#define LOGD(fmt, args...) \

+    do{ \

+        char *file_ptr_1001 = __FILE__; \

+        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \

+        char line_1001[10] = {0}; \

+        sprintf(line_1001, "%d", __LINE__); \

+        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \

+            if(*ptr_1001 == '/') \

+                 break; \

+            ptr_1001--; \

+        } \

+        mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \

+    } while(0)

+

+#define LOGW(fmt, args...) \

+    do{ \

+        char *file_ptr_1001 = __FILE__; \

+        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \

+        char line_1001[10] = {0}; \

+        sprintf(line_1001, "%d", __LINE__); \

+        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \

+            if(*ptr_1001 == '/') \

+                 break; \

+            ptr_1001--; \

+        } \

+        mbtk_log(LOG_WARN_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \

+    } while(0)

+

+#define LOGE(fmt, args...) \

+    do{ \

+		char *file_ptr_1001 = __FILE__; \

+        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \

+        char line_1001[10] = {0}; \

+        sprintf(line_1001, "%d", __LINE__); \

+        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \

+            if(*ptr_1001 == '/') \

+                 break; \

+            ptr_1001--; \

+        } \

+        mbtk_log(LOG_ERR_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \

+    } while(0)

+

+

+

+typedef struct

+{

+    char *lynq_operator_l;

+    char *lynq_operator_s;

+    uint32 lynq_mcc_mnc;

+} lynq_operator_mcc_mnc_t;

+

+static lynq_operator_mcc_mnc_t lynq_operator_mcc_mnc[] =

+{

+    {"China Mobile","CMCC",46000},

+    {"China Unicom","CU",46001},

+    {"China Mobile","CMCC",46002},

+    {"China Telecom","CT",46003},

+    {"China Mobile","CMCC",46004},

+    {"China Telecom","CT",46005},

+    {"China Unicom","CU",46006},

+    {"China Mobile","CMCC",46007},

+    {"China Mobile","CMCC",46008},

+    {"China Unicom","CU",46009},

+    {"China Telecom","CT",46011}

+};

+

+

+//GSW include

+typedef enum prefer_mode

+{

+    GSW_PREFER_MODE_GSW    = 1,   /**<2G only*/

+    GSW_PREFER_MODE_WCDMA    = 2,   /**< 3G only*/ 

+    GSW_PREFER_MODE_WCDMA_GSM    = 3,   /**< 3G/2G*/

+    GSW_PREFER_MODE_LTE    = 4,   /**< 4G only*/

+    GSW_PREFER_MODE_NR5G    = 5,   /**< 5G only*/

+    GSW_PREFER_MODE_NR5G_LTE    = 8,   /**< 5G/4G*/

+    GSW_PREFER_MODE_LTE_WCDMA_GSM    = 9,   /**< 4G/3G/2G*/

+    GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM    = 32,   /**<  5G/4G/3G/2G*/

+} PREFER_MODE_E;

+

+static int mbtk_nw_api_import()

+{

+    dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);

+    if (dlHandle_mbtk == NULL) 

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");

+    if (mbtk_log_init == NULL) 

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");

+    if (mbtk_log == NULL) 

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");

+    if (mbtk_info_handle_get == NULL) 

+    {

+        LOGE("mbtk_info_handle_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free");

+    if (mbtk_info_handle_free == NULL) 

+    {

+        LOGE("mbtk_info_handle_free dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_net_sel_mode_get = (int (*)(mbtk_info_handle_t* handle, mbtk_net_info_t *net))dlsym(dlHandle_mbtk, "mbtk_net_sel_mode_get");

+    if (mbtk_net_sel_mode_get == NULL) 

+    {

+        LOGE("mbtk_net_sel_mode_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_net_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_net_reg_get");

+    if (mbtk_net_reg_get == NULL) 

+    {

+        LOGE("mbtk_net_reg_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_get_modem_fun = (int (*)(mbtk_info_handle_t* handle, int* fun))dlsym(dlHandle_mbtk, "mbtk_get_modem_fun");

+    if (mbtk_get_modem_fun == NULL) 

+    {

+        LOGE("mbtk_get_modem_fun dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_set_modem_fun = (int (*)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info))dlsym(dlHandle_mbtk, "mbtk_set_modem_fun");

+    if (mbtk_set_modem_fun == NULL) 

+    {

+        LOGE("mbtk_set_modem_fun dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_current_band_get = (int (*)(mbtk_info_handle_t* handle, mbtk_band_info_t *band))dlsym(dlHandle_mbtk, "mbtk_current_band_get");

+    if (mbtk_current_band_get == NULL) 

+    {

+        LOGE("mbtk_current_band_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_current_band_set = (int (*)(mbtk_info_handle_t* handle, const mbtk_band_info_t *band))dlsym(dlHandle_mbtk, "mbtk_current_band_set");

+    if (mbtk_current_band_set == NULL) 

+    {

+        LOGE("mbtk_current_band_set dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_net_signal_get = (int (*)(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal))dlsym(dlHandle_mbtk, "mbtk_net_signal_get");

+    if (mbtk_net_signal_get == NULL) 

+    {

+        LOGE("mbtk_net_signal_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_wakeup_state_set = (int (*)(mbtk_info_handle_t* handle, uint32 wakeup_state))dlsym(dlHandle_mbtk, "mbtk_wakeup_state_set");

+    if (mbtk_wakeup_state_set == NULL) 

+    {

+        LOGE("mbtk_wakeup_state_set dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    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");

+    if (mbtk_cell_get == NULL) 

+    {

+        LOGE("mbtk_cell_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    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");

+    if (mbtk_signal_state_change_cb_reg == NULL) 

+    {

+        LOGE("mbtk_signal_state_change_cb_reg dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    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");

+    if (mbtk_net_state_change_cb_reg == NULL) 

+    {

+        LOGE("mbtk_net_state_change_cb_reg dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_fplmn_get = (int(*)(mbtk_info_handle_t *handle, void *fplmn))dlsym(dlHandle_mbtk, "mbtk_fplmn_get");

+    if (mbtk_fplmn_get == NULL) 

+    {

+        LOGE("mbtk_fplmn_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_fplmn_set = (int(*)(mbtk_info_handle_t *handle, void *fplmn))dlsym(dlHandle_mbtk, "mbtk_fplmn_set");

+    if (mbtk_fplmn_set == NULL) 

+    {

+        LOGE("mbtk_fplmn_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    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");

+    if (mbtk_radio_state_change_cb_reg == NULL) 

+    {

+        LOGE("mbtk_radio_state_change_cb_reg dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_oos_get = (int (*)(mbtk_info_handle_t* handle, mbtk_oos_info *oos))dlsym(dlHandle_mbtk, "mbtk_oos_get");

+    if (mbtk_oos_get == NULL) 

+    {

+        LOGE("mbtk_oos_get dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_oos_set = (int (*)(mbtk_info_handle_t* handle, mbtk_oos_info *oos))dlsym(dlHandle_mbtk, "mbtk_oos_set");

+    if (mbtk_oos_set == NULL) 

+    {

+        LOGE("mbtk_oos_set dlsym fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    return GSW_HAL_SUCCESS;

+}

+

+void list_first(list_node_t *list)

+{

+    if (list) {

+        list->cur_index = 0;

+        list->cur_array_data = list->array_data.next;

+    }

+}

+

+void* list_next(list_node_t *list)

+{

+    if (list) {

+        list_arraynode_t *node = list->cur_array_data;

+        if (node) {

+            LOGE("node is not null\n");

+            list->cur_array_data = list->cur_array_data->next;

+            list->cur_index++;

+            return node->data;

+        } else {

+            LOGE("node is null\n");

+            return NULL;

+        }

+    } else {

+        LOGE("list is null\n");

+        return NULL;

+    }

+}

+

+void list_free(list_node_t *list)

+{

+    if (list) {

+        list_arraynode_t *node = &(list->array_data); // Head node

+        list_arraynode_t *node_temp = NULL;

+        while (node->next) {

+            node_temp = node->next;

+            node->next = node->next->next;

+

+            if (list->free_func) {

+                list->free_func(node_temp->data);

+            } else {

+                free(node_temp->data);

+            }

+            free(node_temp);

+        }

+        free(list);

+    }

+}

+

+static int gsw_rssi_to_csq(int rssi)

+{

+    LOGD("rssi = %d\n",rssi);

+    if(rssi >= -113 && rssi <= -51)

+    {

+        return (rssi + 113) / 2;

+    }

+

+    else

+    {

+        return 99;

+    }

+}

+

+static int gsw_rscp_to_csq(int rscp)

+{

+    LOGD("rscp = %d\n",rscp);

+    if(rscp <= -25 && rscp > -120)

+    {

+        return rscp + 120;

+    }

+    else

+    {

+        return 255;

+    }

+

+}

+

+static int gsw_rsrp_to_csq(int rsrp)

+{

+    LOGD("rsrp = %d\n",rsrp);

+

+    if(rsrp <= -44 && rsrp > -140)

+    {

+        return rsrp + 140;

+    }

+

+    else

+    {

+        return 255;

+    }

+}

+

+static int rscp_convert_to_dBm(int rscp)

+{

+    if(rscp <= 96 && rscp >= 0)

+    {

+        return rscp - 120;

+    }

+    else

+    {

+        return -25; 

+    }

+}

+

+

+static int8_t rssi_convert_to_dBm(uint8 rssi)

+{

+    if(rssi <= 31)

+    {

+        return rssi * 2 - 113;

+    }

+    else

+    {

+        return -125;

+    }

+}

+

+static int16_t rsrp_convert_to_dBm(uint8 rsrp)

+{

+    if(rsrp <= 96)

+    {

+        return rsrp - 140;

+    }

+    else

+    {

+        return -44;

+    }

+}

+

+static int16_t rsrq_convert_to_dB(uint8 rsrq)

+{

+    if(rsrq >= 1 && rsrq <= 34)

+    {

+        return (rsrq + 1) / 2 - 20;

+    }

+    else

+    {

+        return  -20; 

+    }

+}

+

+static int16_t ecno_convert_to_dB(uint8 ecno)

+{

+    if(ecno >= 48)

+    {

+        return 0;

+    }

+    else if(ecno == 255)

+    {

+        return 255;

+    }

+    else

+    {

+        return 48 - ecno;

+    }

+}

+

+

+static int convert_reg_state(int reg_state_t)

+{

+    LOGD("reg_state_t = %d\n",reg_state_t);

+    int reg_state = 0;

+

+    switch (reg_state_t)

+    {

+        case MBTK_NET_REG_STATE_NON:

+        {

+            reg_state = GSW_NETWORK_REG_NOT_REGISTERED;

+            break;

+        }

+        case MBTK_NET_REG_STATE_HOME:

+        {

+            reg_state = GSW_NETWORK_REG_REGISTERED;

+            break;

+        }

+        case MBTK_NET_REG_STATE_SEARCHING:

+        {

+            reg_state = GSW_NETWORK_REG_NOT_REGISTERED_SEARCHING;

+            break;

+        }

+        case MBTK_NET_REG_STATE_DENIED:

+        {

+            reg_state = GSW_NETWORK_REG_REGISTRATION_DENIED;

+            break;

+        }

+        case MBTK_NET_REG_STATE_UNKNOWN:

+        {

+            reg_state = GSW_NETWORK_REG_REGISTRATION_UNKNOWN;

+            break;

+        }

+        case MBTK_NET_REG_STATE_ROAMING:

+        {

+            reg_state = GSW_NETWORK_REG_REGISTRATION_ROAMING;

+            break;

+        }

+        case MBTK_NET_REG_STATE_SMS_ONLY:

+        case MBTK_NET_REG_STATE_ROAMING_SMS:

+        case MBTK_NET_REG_STATE_ATTACHED_EMERGENCY:

+        case MBTK_NET_REG_STATE_CSFB_HOME:

+        case MBTK_NET_REG_STATE_CSFB_ROAMING:

+        case MBTK_NET_REG_STATE_EMERGENCY_ONLY:

+        {

+            reg_state = GSW_NETWORK_REG_LIMITED_SERVICE;

+            break;

+        }

+    }

+

+    return reg_state;

+}

+

+

+static int convert_net_mode(int net_mode)

+{

+    LOGD("net_mode = %d\n",net_mode);

+    switch(net_mode)

+    {

+        case MBTK_RADIO_TECH_GSM:

+        case MBTK_RADIO_TECH_GSM_COMPACT:

+        case MBTK_RADIO_TECH_GSM_EGPRS:

+        {

+            return GSW_NETWORK_RADIO_GSM;

+        }

+        case MBTK_RADIO_TECH_UTRAN:

+        case MBTK_RADIO_TECH_UTRAN_HSDPA:

+        case MBTK_RADIO_TECH_UTRAN_HSUPA:

+        case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:

+        case MBTK_RADIO_TECH_UTRAN_HSPA:

+        {

+            return GSW_NETWORK_RADIO_UMTS;

+        }

+        case MBTK_RADIO_TECH_E_UTRAN:

+        {

+            return GSW_NETWORK_RADIO_LTE;

+        }

+        

+        default:

+        {

+            return GSW_NETWORK_RADIO_NO_SVC;

+        }

+    }

+

+    return GSW_NETWORK_RADIO_NO_SVC;

+}

+

+static int convert_mbtk_net_config(int config)

+{

+    int net_pref = -1;

+

+    switch(config)

+    {

+        case GSW_PREFER_MODE_GSW:

+        {

+            net_pref = 0;

+            break;

+        }

+        

+        case GSW_PREFER_MODE_WCDMA:

+        {

+            net_pref = 1;

+            break;

+        }

+

+        case GSW_PREFER_MODE_WCDMA_GSM:

+        {

+            net_pref = 2;

+            break;

+        }

+

+        case GSW_PREFER_MODE_LTE:

+        case GSW_PREFER_MODE_NR5G:

+        case GSW_PREFER_MODE_NR5G_LTE:

+        {

+            net_pref = 5;

+            break;

+        }

+

+        case GSW_PREFER_MODE_LTE_WCDMA_GSM:

+        case GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM:

+        {

+            net_pref = 15;

+            break;

+        }

+    }

+

+    return net_pref;

+}

+

+

+static int convert_gsw_net_config(int config)

+{

+    int net_config = -1;

+    LOGD("config = %d\n");

+

+    switch (config)

+    {

+        case 0:

+        {

+            net_config = GSW_PREFER_MODE_GSW;

+            break;

+        }

+

+        case 1:

+        {

+            net_config = GSW_PREFER_MODE_WCDMA;

+            break;

+        }

+

+        case 2:

+        {

+            net_config = GSW_PREFER_MODE_WCDMA_GSM;

+            break;

+        }

+

+        case 5:

+        {

+            net_config = GSW_PREFER_MODE_LTE;

+            break;

+        }

+

+        case 15:

+        {

+            net_config = GSW_PREFER_MODE_LTE_WCDMA_GSM;

+            break;

+        }

+    }

+

+    return net_config;

+}

+

+//64F010 -> 46001 (64->46,F0->0,10->01)

+static void transform_fplmn_str_to_plmn(char *entry)

+{

+    if (strncmp(entry, "FFFFFF", ENTRY_LENGTH) == 0) {

+        return; //if FFFFFF,means invalid fplmn, do nothing

+    }

+

+    char temp = entry[0];

+    entry[0] = entry[1];

+    entry[1] = temp;

+

+    temp = entry[ENTRY_LENGTH - 2];

+    entry[ENTRY_LENGTH - 2] = entry[ENTRY_LENGTH - 1];

+    entry[ENTRY_LENGTH - 1] = temp;

+

+    memmove(entry + 2, entry + 3, ENTRY_LENGTH - 2);

+

+    LOGE("after transform_fplmn_str_to_plmn: %s\n", entry);

+

+    //valid fplmn

+    fplmn_index++;

+}

+

+static void extract_mcc_mnc(char *entry, char *mcc, char *mnc)

+{

+    strncpy(mcc,entry,3);

+    mcc[3] = '\0';

+    strncpy(mnc,entry + 3,2);

+    mnc[2] = '\0';

+

+    LOGE("entry = %s, mcc = %s, mnc = %s\n", entry, mcc, mnc);

+}

+

+

+static void update_fplmn_list(char *fplmn_str)

+{

+    LOGE("fplmn_str = %s\n",fplmn_str);

+    char temp_fplmn_array[FPLMN_ARRAY_SIZE][7];

+    memset(fplmn_array, 0, sizeof(fplmn_array));

+    memset(temp_fplmn_array, 0, sizeof(temp_fplmn_array));

+    fplmn_index = 0;

+    int array_length = 0;

+

+    for (int i = 0; i < strlen(fplmn_str); i += 6) {

+        

+        int length = (i + 6 < strlen(fplmn_str)) ? 6 : strlen(fplmn_str) - i;

+        strncpy(temp_fplmn_array[array_length], fplmn_str + i, length);

+        temp_fplmn_array[array_length][length] = '\0'; 

+        array_length++;

+        if (i + 6 >= strlen(fplmn_str)) {

+            break;

+        }

+    }

+

+    for (int i = 0; i < array_length; i++) {

+        LOGE("array[%d] = %s\n", i, temp_fplmn_array[i]);

+        transform_fplmn_str_to_plmn(temp_fplmn_array[i]);

+        strncpy(fplmn_array[i], temp_fplmn_array[i], ENTRY_LENGTH);

+        LOGE("fplmn_array[%d] = %s\n", i, fplmn_array[i]);

+    }

+

+}

+

+static void format_plmn(char *result, char *plmn_entry)

+{

+    strncpy(result, plmn_entry, strlen(plmn_entry));

+    LOGE("result = %s, numStr = %s\n",result, plmn_entry);

+

+    if (strlen(result) >= 2) {

+        char temp = result[0];

+        result[0] = result[1];

+        result[1] = temp;

+    }

+    

+    LOGE("1.result = %s\n",result);

+

+    if (strlen(result) >= 3) {

+        memmove(&result[3], &result[2], strlen(result) - 2 + 1);

+        result[2] = 'F';

+    }

+

+    LOGE("2.result = %s\n",result);

+

+    if (strlen(result) >= 2) {

+        char temp = result[strlen(result) - 1];

+        result[strlen(result) - 1] = result[strlen(result) - 2];

+        result[strlen(result) - 2] = temp;

+    }

+

+    LOGE("3.result = %s\n",result);

+}

+

+

+static void convert_plmn_to_fplmn_str(char *fplmn_str)

+{

+    char temp_fplmn_str[128] = {0};

+    char temp[20]; // 临时存储单个格式化后的数字

+    int index = 0;

+

+    for (int i = 0; i < fplmn_index; i++) {

+        memset(temp, 0x0, sizeof(temp));

+        format_plmn(temp, fplmn_array[i]);

+        strcat(temp_fplmn_str, temp);

+        index += strlen(temp);

+    }

+

+    while(index < (6 * fplmn_max_length))

+    {

+        temp_fplmn_str[index++] = 'F';

+    }

+

+    // 修剪或截断formattedNumbers,确保它不超过6 * fplmn_max_length个字符

+    if (index > (6 * fplmn_max_length)) {

+        temp_fplmn_str[(6 * fplmn_max_length)] = '\0';

+    }

+

+    LOGE("%s\n", temp_fplmn_str);

+    strncpy(fplmn_str, temp_fplmn_str, strlen(temp_fplmn_str));

+    LOGE("fplmn_str = %s\n", fplmn_str);

+}

+

+static int check_index(char *mcc, char *mnc)

+{

+    int i = 0;

+

+    for(i = 0; i < fplmn_index; i++)

+    {

+        if(strncmp(fplmn_array[i], mcc, 3) == 0 && strncmp(fplmn_array[i] + 3, mnc, 2) == 0)

+        {

+            LOGE("index = %d\n", i);

+            return i;

+        }

+    }

+

+    LOGE("not find\n");

+    return -1;

+}

+

+static void remove_fplmn(int index)

+{

+    int write_index = 0;

+    for (int i = 0; i < fplmn_index; i++) {

+        if (i != index) {

+            strncpy(fplmn_array[write_index++], fplmn_array[i], ENTRY_LENGTH);

+        }

+    }

+    fplmn_index--;

+}

+

+static void gsw_serving_info_callback_thread()

+{

+    GSW_NW_SERVING_INFO *serving_info = (GSW_NW_SERVING_INFO*)malloc(sizeof(GSW_NW_SERVING_INFO));

+    memset(serving_info, 0x0, sizeof(GSW_NW_SERVING_INFO));

+    int ret = -1;

+    ret = gsw_get_nwinfo(serving_info);

+    if(ret != 0)

+    {

+        LOGE("gsw_get_nwinfo failed\n");

+        free(serving_info);

+        return; 

+    }

+

+    if(serving_cb)

+    {

+        serving_cb(*serving_info);

+        free(serving_info);

+    }

+}

+

+static void gsw_serving_info_callback(const void* data, int data_len)

+{

+    LOGE("gsw_serving_info_callback start\n");

+

+    if(data && data_len > 0)

+    {

+        pthread_t thread;

+        pthread_create(&thread, NULL, (void*)gsw_serving_info_callback_thread, NULL);

+    }

+

+    else

+    {

+        LOGE("data is NULL\n");

+        return;

+    }

+

+}

+

+static void gsw_sig_info_callback(const void* data, int data_len)

+{

+    LOGE("gsw_sig_info_callback start\n");

+

+    if(data && data_len == 8)

+    {

+        uint8 *net_data = (uint8*)data;

+        mbtk_radio_technology_enum type = (mbtk_radio_technology_enum)net_data[0];

+

+        signalStrength_t sig_strength;

+        memset(&sig_strength, 0x0, sizeof(signalStrength_t));

+

+        sig_strength.gw_sig_valid = 0;

+        sig_strength.wcdma_sig_valid = 0;

+        sig_strength.lte_sig_valid = 0;

+        sig_strength.nr_sig_valid = 0;

+

+        if(type == MBTK_RADIO_TECH_GSM || type == MBTK_RADIO_TECH_GSM_COMPACT || \

+           type == MBTK_RADIO_TECH_GSM_EGPRS)              //GSM

+        {

+            sig_strength.gw_sig_valid = 1;

+            sig_strength.rssi = rssi_convert_to_dBm(net_data[1]);

+        }

+

+        else if(type == MBTK_RADIO_TECH_E_UTRAN) 

+        {

+            sig_strength.lte_sig_valid = 1;

+            sig_strength.rsrp = rsrp_convert_to_dBm(net_data[7]);

+            sig_strength.rsrq = rsrq_convert_to_dB(net_data[6]);

+            sig_strength.rssnr = -99;

+        }

+

+        else if (type == MBTK_RADIO_TECH_UTRAN || type == MBTK_RADIO_TECH_UTRAN_HSDPA || \

+                 type == MBTK_RADIO_TECH_UTRAN_HSUPA || type == MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA ||  \

+                 type == MBTK_RADIO_TECH_UTRAN_HSPA )//WCDMA

+        {

+            sig_strength.wcdma_sig_valid = 1;

+            sig_strength.rscp = rssi_convert_to_dBm(net_data[1]);

+            sig_strength.ecno = ecno_convert_to_dB(net_data[5]);

+        }

+

+        if(sig_cb != NULL)

+        {

+            sig_cb(sig_strength);

+        }

+    }

+

+    else

+    {

+        LOGE("data is NULL\n");

+    }

+}

+

+static void gsw_modem_status_event_callback(const void* data, int data_len)

+{

+    LOGE("gsw_modem_status_event_callback start\n");

+

+    gsw_mode_state_e state = GSW_MODEM_STATE_UNKNOWN;

+

+    if(data && data_len > 0)

+    {

+        uint8 *net_data = (uint8*)data;

+        LOGE("gsw_modem_status_event_callback,data = %d\n", *net_data);

+        if(*net_data == 1)

+        {

+            state = GSW_MODEM_STATE_ONLINE;

+        }

+        else if(*net_data == 0)

+        {

+            state = GSW_MODEM_STATE_OFFLINE;

+        }

+

+        if(modem_cb != NULL)

+        {

+            modem_cb(state);

+        }

+    }

+

+}

+

+static void gsw_reject_callback(GSW_NW_RADIO_ACCESS_TECH_E rat, GSW_SERVICE_DOMAIN_E domain, int cause)

+{

+    LOGE("gsw_reject_callback start,rat = %d,domain = %d,cause = %d\n",rat,domain,cause);

+

+    GSW_NW_REJ_CAUSE_E *rej_cause = (GSW_NW_REJ_CAUSE_E*)malloc(sizeof(GSW_NW_REJ_CAUSE_E));

+    memset(rej_cause, 0x0, sizeof(GSW_NW_REJ_CAUSE_E));

+    

+    rej_cause->rej_cause = cause;

+    rej_cause->rej_rat = rat;

+    rej_cause->rej_domain = domain;

+

+    if(reject_cb != NULL)

+    {

+        LOGE("reject_cb is not NULL\n");

+        reject_cb(rej_cause);

+    }

+    else

+    {

+        LOGE("reject_cb is NULL\n");

+    }

+

+    free(rej_cause);

+    LOGE("gsw_reject_callback end\n");

+}

+

+

+

+/**

+ * @brief SDK interface to call back serving info

+ * @param  [in] handle_ptr 

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_reg_serving_info_callback(GSW_NW_ServingInfoHandlePtr handle_ptr)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(handle_ptr == NULL)

+    {

+        LOGE("handle_ptr is NULL\n");

+        return GSW_HAL_FAIL;

+    }

+

+    serving_cb = handle_ptr;

+

+    return GSW_HAL_SUCCESS;

+

+}

+

+

+/**

+ * @brief SDK interface to call back sig info

+ * @param  [in] handle_ptr 

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_reg_sig_info_callback(GSW_NW_SigInfoHandlePtr handle_ptr)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(handle_ptr == NULL)

+    {

+        LOGE("handle_ptr is NULL\n");

+        return GSW_HAL_FAIL;

+    }

+

+    sig_cb = handle_ptr;

+

+    return GSW_HAL_SUCCESS;

+

+}

+

+

+/**

+ * @brief SDK interface to call back rej cause

+ * @param  [in] handle_ptr 

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_reg_rej_cause_callback(GSW_NW_RejectCauseHandlePtr handle_ptr)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(handle_ptr == NULL)

+    {

+        LOGE("handle_ptr is NULL\n");

+        return GSW_HAL_FAIL;

+    }

+

+    reject_cb = handle_ptr;

+

+    return GSW_HAL_SUCCESS;

+}

+

+

+/**

+ * @brief network sdk init

+ * @param  [in] token usr id define by who use

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_nw_sdk_init(int token)

+{

+    int ret = -1;

+

+    if (nw_init_flag == 1 && nw_info_handle != NULL)

+    {

+        return GSW_HAL_SUCCESS;

+    }

+

+    ret = mbtk_nw_api_import();

+    if (ret != 0)

+    {

+        LOGE("mbtk_nw_api_import fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    nw_info_handle = mbtk_info_handle_get();

+

+    if (nw_info_handle == NULL)

+    {

+        LOGE("mbtk_info_handle_get fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    char fplmn[256] = {0};

+    ret = mbtk_fplmn_get(nw_info_handle, fplmn);

+    if(ret != 0)

+    {

+        LOGE("mbtk_fplmn_get failed : %d\n",ret);

+        return GSW_HAL_FAIL;

+    }

+    fplmn_max_length = (strlen(fplmn)/6);

+    LOGE("fplmn = %s, fplmn_max_length = %d\n",fplmn,fplmn_max_length);

+    ret = mbtk_signal_state_change_cb_reg(nw_info_handle, gsw_sig_info_callback);

+

+    if (ret != 0)

+    {

+        LOGE("mbtk_signal_state_change_cb_reg fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    ret = mbtk_net_state_change_cb_reg(nw_info_handle, gsw_serving_info_callback);

+    if (ret != 0)

+    {

+        LOGE("mbtk_net_state_change_cb_reg fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    nw_init_flag = 1;

+

+    return GSW_HAL_SUCCESS;

+}

+

+

+/**

+ * @brief network sdk deinit

+ * @param 

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_nw_sdk_deinit(void)

+{

+    int ret = -1;

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    ret = mbtk_info_handle_free(&nw_info_handle);

+    if(ret != GSW_HAL_SUCCESS)

+    {

+        LOGE("mbtk_info_handle_free fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    dlclose(dlHandle_mbtk);

+    nw_info_handle = NULL;

+    nw_init_flag = 0;

+

+    return GSW_HAL_SUCCESS;

+

+}

+

+

+/**

+ * @brief get current network reg info

+ * @param  [out] serving_info struct for network info

+ * include regstate ps_state opreator name mcc mcn etc

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_get_nwinfo(GSW_NW_SERVING_INFO *serving_info)

+{

+

+    int ret = -1;

+    LOGE("gsw_get_nwinfo start\n");

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        LOGE("nw_sdk_deinit not init\n");

+        return GSW_HAL_FAIL;

+    }

+

+    LOGE("mbtk_net_reg_get start \n");

+    //regstate

+    mbtk_net_reg_info_t reg;

+    memset(&reg, 0x0, sizeof(mbtk_net_reg_info_t));

+    ret = mbtk_net_reg_get(nw_info_handle, &reg);

+    if(ret)

+    {

+        LOGE("mbtk_net_reg_get fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    LOGE("convert_cs_reg_state\n");

+    //cs_state

+    serving_info->reg_state = convert_reg_state(reg.call_state);

+    LOGE("convert_ps_reg_state\n");

+    //ps_state

+    serving_info->ps_state = convert_reg_state(reg.data_state);

+    LOGE("convert_rat_mode\n");

+    //reg_rat

+    serving_info->reg_rat = convert_net_mode(reg.type);

+    //srv_domain

+    if(serving_info->reg_state == GSW_NETWORK_REG_REGISTERED || serving_info->reg_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)

+    {

+        if(serving_info->ps_state == GSW_NETWORK_REG_REGISTERED || serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)

+        {

+            serving_info->srv_domain = GSW_SRV_DOMAIN_CS_PS;

+        }

+

+        else

+        {

+            serving_info->srv_domain = GSW_SRV_DOMAIN_CS_ONLY;

+        }

+    }

+

+    else if (serving_info->ps_state == GSW_NETWORK_REG_REGISTERED || serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)

+    {

+        serving_info->srv_domain = GSW_SRV_DOMAIN_PS_ONLY;

+    }

+

+    else

+    {

+        serving_info->srv_domain = GSW_SRV_DOMAIN_NO_SVC;

+        //if ps and cs is both not registed, reg_rat seted to GSW_NETWORK_RADIO_NO_SVC

+        serving_info->reg_rat = GSW_NETWORK_RADIO_NO_SVC;

+    }

+

+    LOGD("roaming_ind\n");

+    //roaming_ind

+    if(serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)

+    {

+        serving_info->roaming_ind = GSW_NETWORK_ROAMING_ON;

+    }

+    else

+    {

+        serving_info->roaming_ind = GSW_NETWORK_ROAMING_OFF;

+    }

+

+    LOGD("reject\n");

+    //reject

+    if(serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_DENIED || serving_info->reg_state == GSW_NETWORK_REG_REGISTRATION_DENIED)

+    {

+        LOGD("reject_callback\n");

+        gsw_reject_callback(serving_info->reg_rat,serving_info->srv_domain,99);

+    }

+

+    LOGD("reg_plmn / operator name\n");

+    //reg_plmn / operator name

+    mbtk_net_info_t net;

+    memset(&net, 0x0, sizeof(mbtk_net_info_t));

+    LOGD("mbtk_net_sel_mode_get start \n");

+    ret = mbtk_net_sel_mode_get(nw_info_handle, &net);

+    LOGD("mbtk_net_sel_mode_get end \n");

+    if(ret == 0 && net.plmn > 0)

+    {

+        int i = 0;

+

+        LOGD("start to find mcc");

+        while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))

+        {

+            if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)

+            {

+                LOGD("find mcc\n");

+                break;

+            }

+            i++;

+        }

+

+

+        if(i == ARRAY_SIZE(lynq_operator_mcc_mnc))

+        {

+            LOGD("not find mcc");

+            strcpy(serving_info->operator_name, "unknown");

+            sprintf(serving_info->reg_plmn, "%d", net.plmn);

+        }

+

+        else

+        {

+            LOGD("find mcc\n");

+            strcpy(serving_info->operator_name, lynq_operator_mcc_mnc[i].lynq_operator_l);

+            sprintf(serving_info->reg_plmn, "%d", net.plmn);

+        }

+

+        LOGE("operator_name = %s\n", serving_info->operator_name);

+        LOGE("reg_plmn = %s\n", serving_info->reg_plmn);

+    }

+

+

+    LOGD("get cell id/tac/lac/sid/nid\n");

+    //cell id/tac/lac/sid/nid

+    mbtk_cell_type_enum cell_type;

+    if(serving_info->reg_rat == GSW_NETWORK_RADIO_GSM)

+    {

+        cell_type = MBTK_CELL_TYPE_GSM;

+    }

+    else if(serving_info->reg_rat == GSW_NETWORK_RADIO_UMTS)

+    {

+        cell_type = MBTK_CELL_TYPE_UMTS;

+    }

+    else

+    {

+        cell_type = MBTK_CELL_TYPE_LTE;

+    }

+

+    list_node_t* cell_list = NULL;

+    

+    LOGD("mbtk_cell_get start\n");

+    ret = mbtk_cell_get(nw_info_handle, &cell_type, &cell_list);

+    if(ret != 0 || cell_list == NULL)

+    {

+        LOGE("mbtk_cell_get fail\n");

+        return GSW_HAL_FAIL;

+    }

+    else

+    {

+        LOGE("mbtk_cell_get end,start to get node\n");

+        list_first(cell_list);

+        LOGE("list_first end\n");

+        mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);

+        if(cell)

+        {

+            LOGE("cell is not null,value2 = %u\n",cell->value2);

+            switch(cell_type)

+            {

+                case MBTK_CELL_TYPE_LTE:

+                {

+                    LOGE("is lte\n");

+                    //LOGE("LTE : tac=%x, PCI=%x, dlEuarfcn=%x, ulEuarfcn=%x, band=%x\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);

+                    LOGE("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);

+                    snprintf(serving_info->tac,sizeof(serving_info->tac),"%d",cell->value1);

+                    strcpy(serving_info->lac,"");

+                    snprintf(serving_info->cell_id,sizeof(serving_info->cell_id),"%d",cell->value8);

+                    break;

+                }

+

+                case MBTK_CELL_TYPE_GSM:

+                {

+                    LOGE("is gsm\n");

+                    LOGE("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);

+                    sprintf(serving_info->lac,"%d",cell->value1);

+                    memset(serving_info->tac,0,sizeof(serving_info->tac));

+                    sprintf(serving_info->cell_id,"%d",cell->value2);

+                    break;

+                }    

+                case MBTK_CELL_TYPE_UMTS:

+                {

+                    LOGE("is wcdma\n");

+                    LOGE("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);

+                    sprintf(serving_info->lac,"%d",cell->value1);

+                    memset(serving_info->tac,0,sizeof(serving_info->tac));

+                    sprintf(serving_info->cell_id,"%d",cell->value2);

+                    break;

+                }

+                

+                default:

+                    break;

+            }

+        }

+        else

+        {

+            LOGE("cell is null\n");

+        }

+    }

+

+    //not support now

+    serving_info->sid = 0;

+    serving_info->nid = 0;

+

+    return GSW_HAL_SUCCESS;

+}

+

+

+/**

+ * @brief get current network type

+ * @param  [out] netype as GSW_NW_RADIO_ACCESS_TECH_E type

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_get_netype(int *netype)

+{

+    int ret = -1;

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    //regstate

+    mbtk_net_reg_info_t reg;

+    ret = mbtk_net_reg_get(nw_info_handle, &reg);

+    if(ret)

+    {

+        LOGE("mbtk_net_reg_get fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    if(reg.data_state == MBTK_NET_REG_STATE_HOME || reg.data_state == MBTK_NET_REG_STATE_ROAMING)

+    {

+        *netype = convert_net_mode(reg.type);

+    }

+    else

+    {

+        *netype = GSW_NETWORK_RADIO_NO_SVC;

+    }

+

+    return GSW_HAL_SUCCESS;

+}

+

+

+/**

+ * @brief get radio opmode, as open and close airplane mode

+ * @param  [out] op_mode 1 is radio on, 0 is radio off

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_get_opmode(int *op_mode)

+{

+    int tmp_rf = -1;

+    int ret = -1;

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    ret = mbtk_get_modem_fun(nw_info_handle, &tmp_rf);

+    if (ret != 0)

+    {

+        LOGE("mbtk_get_modem_fun fail\n");

+        return GSW_HAL_FAIL;

+    }

+    if(tmp_rf == LYNQ_AIR_CFUN_MODE_OFF)

+    {

+        *op_mode = GSW_OP_MODE_LPM;

+    }

+

+    if(tmp_rf == LYNQ_AIR_PLANE_MODE_ON)

+    {

+        *op_mode = GSW_OP_MODE_OFFLINE;

+    }

+

+    if(tmp_rf == LYNQ_AIR_PLANE_MODE_OFF)

+    {

+        *op_mode = GSW_OP_MODE_ONLINE;

+    }

+

+    return GSW_HAL_SUCCESS;

+}

+

+

+

+/**

+ * @brief set radio opmode, as open and close airplane mode

+ * @param  [in] op_mode 1 is radio on, 0 is radio off

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_set_opmode(int op_mode)

+{

+    mbtk_modem_info_t info;

+    int rf_mode = -1;

+    int ret = -1;

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(op_mode == GSW_OP_MODE_LPM)

+    {

+        rf_mode = LYNQ_AIR_CFUN_MODE_OFF;

+    }

+

+    if(op_mode == GSW_OP_MODE_ONLINE)

+    {

+        rf_mode = LYNQ_AIR_PLANE_MODE_OFF;

+    }

+

+    if(op_mode == GSW_OP_MODE_OFFLINE)

+    {

+        rf_mode = LYNQ_AIR_PLANE_MODE_ON;

+    }

+

+    if (rf_mode != LYNQ_AIR_PLANE_MODE_ON && rf_mode != LYNQ_AIR_PLANE_MODE_OFF && rf_mode != LYNQ_AIR_CFUN_MODE_OFF) 

+    {

+        LOGE("Input mode is error!\n");

+        return GSW_HAL_FAIL;

+    }

+

+    info.fun = rf_mode;

+    info.rst = 0;

+    ret = mbtk_set_modem_fun(nw_info_handle, &info);

+    if (ret != 0)

+    {

+        LOGE("gsw_set_opmode fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    return GSW_HAL_SUCCESS;

+

+}

+

+

+/**

+ * @brief get network mode preference of mdm search network scale

+ * @param  [out] mode_pref net_work pref mode:

+ *    enum prefer_mode

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_get_mode_preference(int *mode_pref)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    int ret = -1;

+    mbtk_band_info_t band;

+    memset(&band, 0, sizeof(mbtk_band_info_t));

+

+    ret = mbtk_current_band_get(nw_info_handle, &band);

+    if(ret != 0)

+    {

+        LOGE("mbtk_current_band_get fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    *mode_pref = convert_gsw_net_config(band.net_pref);

+    LOGE("band.net_pref = %d\n", *mode_pref);

+    if(*mode_pref <= 0)

+    {

+        LOGE("no support mode\n");

+        return GSW_HAL_FAIL;

+    }

+    return GSW_HAL_SUCCESS;

+

+

+}

+

+/**

+ * @brief set network mode preference of mdm search network scale

+ * @param  [in] mode_pref net_work pref mode:

+ *     enum prefer_mode

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_set_mode_preference(int mode_pref)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    int ret = -1;

+

+    mbtk_band_info_t band;

+    memset(&band, 0, sizeof(mbtk_band_info_t));

+

+    band.net_pref = convert_mbtk_net_config(mode_pref);

+    LOGE("band.net_pref = %d\n", band.net_pref);

+

+    if(band.net_pref < 0)

+    {

+        LOGE("no support mode\n");

+        return GSW_HAL_FAIL;

+    }

+

+    ret = mbtk_current_band_set(nw_info_handle, &band);

+    if(ret != 0)

+    {

+        LOGE("mbtk_current_band_set fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    return GSW_HAL_SUCCESS;

+}

+

+/**

+ * @brief get signal csq value

+ * @param  [out] csq_value csq of signalstrengh 0 - 31, 99 invalid

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_get_sig_info(int *csq_value)

+{

+    int ret = -1;

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    mbtk_signal_info_t signal;

+    memset(&signal, 0x0, sizeof(mbtk_signal_info_t));

+    ret = mbtk_net_signal_get(nw_info_handle, &signal);

+    if(ret != 0)

+    {

+        LOGE("mbtk_net_signal_get fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    LOGD("signal.type=%d\n", signal.type);

+    switch(signal.type)

+    {

+        case MBTK_RADIO_TECH_GSM:

+        case MBTK_RADIO_TECH_GSM_COMPACT:

+        case MBTK_RADIO_TECH_GSM_EGPRS:

+        {

+            LOGD("rssi = %d\n",signal.rssi);

+            *csq_value = rssi_convert_to_dBm(signal.rssi);

+            break;

+        }

+        case MBTK_RADIO_TECH_E_UTRAN:

+        {

+            LOGD("rsrp = %d\n",signal.rsrp);

+            *csq_value = rsrp_convert_to_dBm(signal.rsrp);

+            break;

+        }

+        case MBTK_RADIO_TECH_UTRAN:

+        case MBTK_RADIO_TECH_UTRAN_HSDPA:

+        case MBTK_RADIO_TECH_UTRAN_HSUPA:

+        case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:

+        case MBTK_RADIO_TECH_UTRAN_HSPA:

+        {

+            LOGD("rscp = %d\n",signal.rscp);

+            *csq_value = rscp_convert_to_dBm(signal.rscp);

+            break;

+        }

+        default:

+        {

+            LOGD("[%s] unknown reg type.[%d]\n", __func__, signal.type);

+            return GSW_HAL_FAIL;

+        }

+    }

+    return GSW_HAL_SUCCESS;

+}

+

+/**

+ * @brief set nework power mode, for tcam enter standby or exit standby

+ * @param  [in] mode TRUE(1) when enter standby, FALSE(0) after wake up

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_network_set_power_mode(char mode)

+{

+    int ret = -1;

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(mode != 0 && mode != 1)

+    {

+        LOGE("Input mode is error!\n");

+        return GSW_HAL_FAIL;

+    }

+

+    if(mode == 1)

+    {

+        mode = 6;

+    }

+

+    ret = mbtk_wakeup_state_set(nw_info_handle, mode);

+    if(ret != 0)

+    {

+        LOGE("mbtk_wakeup_state_set fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    return GSW_HAL_SUCCESS;

+

+

+

+}

+

+/**

+ * @brief convert rsrp rscp rssi to csq value.

+ * @param  [in] netType signal radio tech 2 means 2G 3 mens 3G,4 is 4G,5 is 5G

+ * @param  [in] sigvalue input signal_strength for different nettype

+ * rsrp  for 4G/5G, rscp for 3G, rssi for 2G

+

+ * @retval csq

+ * @retval other: fail

+ */

+int gsw_sigInfo_to_csq(int netType, int sigValue)

+{

+    switch(netType)

+    {

+        case 1:

+        case 2:

+        case 3:

+        case 4:        //GSM

+        {

+            return gsw_rssi_to_csq(sigValue);

+        }

+            

+        case 5:        //WCDMA

+        {

+            return gsw_rscp_to_csq(sigValue);

+        }

+            

+        case 6:        //LTE

+        {

+            return gsw_rsrp_to_csq(sigValue);

+        }

+            

+        default:

+        {

+            LOGE("parameter error\n");

+            return GSW_HAL_FAIL;

+        }

+    }

+}

+

+/*

+ * @brief get mobile operator name

+   @param [out] nw_operator_name_infos get the long and short operator name info 

+   @retval 0: success

+   @retval 0: other: fail

+ */

+int gsw_get_mobile_operator_name(gsw_mobile_operator_name *nw_operator_name_infos)

+{

+    char OperatorFN[128];

+    char OperatorSH[128];

+    char temp[12] = {0};

+    mbtk_net_info_t net;

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(!mbtk_net_sel_mode_get(nw_info_handle, &net) && net.plmn > 0)

+    {

+        LOGE("Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);

+        int i = 0;

+        while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))

+        {

+            if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)

+                break;

+            i++;

+        }

+

+        if(i == ARRAY_SIZE(lynq_operator_mcc_mnc))   // No found mcc&mnc

+        {

+            strcpy(OperatorFN, "UNKNOWN");

+            strcpy(OperatorSH, "UNKNOWN");

+        }

+        else

+        {

+            strcpy(OperatorFN, lynq_operator_mcc_mnc[i].lynq_operator_l);

+            strcpy(OperatorSH, lynq_operator_mcc_mnc[i].lynq_operator_s);

+

+            memset(temp,0,12);

+            memset(nw_operator_name_infos->mcc,0,4);

+            sprintf(temp, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)/100);

+            strncpy(nw_operator_name_infos->mcc, temp, strlen(temp));

+

+            memset(temp,0,12);

+            memset(nw_operator_name_infos->mnc,0,4);

+            sprintf(temp, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)%100);

+            strncpy(nw_operator_name_infos->mnc, temp, strlen(temp));

+        }

+

+        memset(nw_operator_name_infos->long_eons,0,128);

+        memcpy(nw_operator_name_infos->long_eons,OperatorFN,strlen(OperatorFN));

+        memset(nw_operator_name_infos->short_eons,0,128);

+        memcpy(nw_operator_name_infos->short_eons,OperatorSH,strlen(OperatorSH));

+        

+        return GSW_HAL_SUCCESS;

+    }

+

+    else

+    {

+        LOGE("mbtk_net_sel_mode_get fail\n");

+        return GSW_HAL_FAIL;

+    }

+

+    return GSW_HAL_SUCCESS;

+}

+

+

+/*

+ * @brief get current serving cell info

+ * @param cell_info: [out] struct for current cell info

+ * include earfcn mcc mnc pci psc tac lac etc.

+ * @return int: 0 is success, other failed

+ */

+int gsw_get_cell_info(GSW_NW_CELL_INFO *cell_info)

+{

+    int ret = -1;

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        LOGE("nw_sdk_deinit not init\n");

+        return GSW_HAL_FAIL;

+    }

+

+    list_node_t* cell_list = NULL;

+    int neibor_count = 0;

+    mbtk_cell_type_enum type;

+    ret = mbtk_cell_get(nw_info_handle, &type, &cell_list);

+    if(ret || cell_list == NULL) {

+        LOGE("mbtk_cell_get failed : %d\n", ret);

+    } else {

+        list_first(cell_list);

+        mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);

+        if(cell) { // Current server cell.

+            switch(type)

+            {

+                case 0:

+                {

+                    LOGD("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);

+                    char gsm_temp[12] = {0};

+

+                    cell_info->rat = GSW_NETWORK_RADIO_GSM;

+

+                    cell_info->mcc_valid = 1;

+                    snprintf(gsm_temp, sizeof(gsm_temp) ,"%d", cell->value5);

+                    strncpy(cell_info->mcc, gsm_temp, sizeof(cell_info->mcc));

+

+                    memset(gsm_temp, 0, sizeof(gsm_temp));

+

+                    cell_info->mnc_valid = 1;

+                    snprintf(gsm_temp, sizeof(gsm_temp) ,"%d", cell->value6);

+                    strncpy(cell_info->mnc, gsm_temp, sizeof(cell_info->mnc));

+

+                    cell_info->cell_id_valid = 1;

+                    cell_info->cell_id = cell->value2;

+

+                    cell_info->lac_valid = 1;

+                    cell_info->lac = cell->value1;

+

+                    cell_info->arfcn_valid = 1;

+                    cell_info->arfcn = cell->value3;

+                    

+                    break;

+                }

+                    

+                case 1:

+                {

+                    LOGD("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);

+                    char wcdma_temp[12] = {0};

+

+                    cell_info->rat = GSW_NETWORK_RADIO_UMTS;

+

+                    cell_info->mcc_valid = 1;

+                    snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%d", cell->value4);

+                    strncpy(cell_info->mcc, wcdma_temp, sizeof(cell_info->mcc));

+

+                    memset(wcdma_temp, 0, sizeof(wcdma_temp));

+

+                    cell_info->mnc_valid = 1;

+                    snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%d", cell->value5);

+                    strncpy(cell_info->mnc, wcdma_temp, sizeof(cell_info->mnc));

+

+                    cell_info->lac_valid = 1;

+                    cell_info->lac = cell->value1;

+

+                    cell_info->cell_id_valid = 1;

+                    cell_info->cell_id = cell->value2;

+

+                    cell_info->uarfcn_valid = 1;

+                    cell_info->uarfcn = cell->value3;

+

+                    cell_info->psc_valid = 1;

+                    cell_info->psc = cell->value6;

+                    break;

+                }

+                    

+                case 2:

+                {

+                    LOGE("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);

+                    

+                    char lte_temp[12] = {0};

+

+                    cell_info->rat = GSW_NETWORK_RADIO_LTE;

+

+                    cell_info->mcc_valid = 1;

+                    snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);

+                    strncpy(cell_info->mcc, lte_temp, sizeof(cell_info->mcc));

+

+                    memset(lte_temp, 0, sizeof(lte_temp));

+

+                    cell_info->mnc_valid = 1;

+                    snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);

+                    strncpy(cell_info->mnc, lte_temp, sizeof(cell_info->mnc));

+

+                    cell_info->tac_valid = 1;

+                    cell_info->tac = cell->value1;

+

+                    cell_info->pci_valid = 1;

+                    cell_info->pci = cell->value2;

+

+                    cell_info->earfcn_valid = 1;

+                    cell_info->earfcn = cell->value3;

+

+                    cell_info->bler_valid = 1;

+                    cell_info->bler = cell->value4;

+

+                    cell_info->band_valid = 1;

+                    cell_info->band = cell->value5;

+

+                    cell_info->rsrp_valid = 1;

+                    cell_info->rsrp = cell->value8;

+

+                    cell_info->rsrq_valid = 1;

+                    cell_info->rsrq = cell->value9;

+

+                    cell_info->cell_id_valid = 1;

+                    cell_info->cell_id = cell->value10;

+

+                    break;

+                }

+

+                default:

+                    break;

+            }

+        }

+

+        while ((cell = (mbtk_cell_info_t*) list_next(cell_list)) && neibor_count < 5)

+        {

+            switch(type)

+            {

+                //GSM

+                case 0:

+                {

+

+                }

+                //WCDMA

+                case 1:

+                {

+                    LOGE("CELL : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);

+

+                    //cell_info->ext_info[neibor_count]->lac = cell->value1;

+

+                    cell_info->ext_info[neibor_count].cell_id_valid = 1;

+                    cell_info->ext_info[neibor_count].cell_id = cell->value2;

+

+                    cell_info->ext_info[neibor_count].arfcn_valid = 1;

+                    cell_info->ext_info[neibor_count].arfcn = cell->value3;

+

+                    cell_info->ext_info[neibor_count].rat = cell_info->rat = GSW_NETWORK_RADIO_UMTS;

+

+                    neibor_count++;

+

+                }

+                //LTE

+                case 2:

+                {

+                    LOGE("CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);

+                    char lte_temp[12] = {0};

+                    cell_info->ext_info[neibor_count].rat = GSW_NETWORK_RADIO_LTE;

+

+                    snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);

+                    strncpy(cell_info->ext_info[neibor_count].mcc, lte_temp, sizeof(cell_info->mcc));

+

+                    memset(lte_temp, 0, sizeof(lte_temp));

+

+                    snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);

+                    strncpy(cell_info->ext_info[neibor_count].mnc, lte_temp, sizeof(cell_info->mnc));

+

+                    cell_info->ext_info[neibor_count].pci = cell->value1;

+                    cell_info->ext_info[neibor_count].pci_valid = 1;

+

+                    cell_info->ext_info[neibor_count].arfcn = cell->value2;

+                    cell_info->ext_info[neibor_count].arfcn_valid = 1;

+

+                    cell_info->ext_info[neibor_count].rsrp = cell->value3;

+                    cell_info->ext_info[neibor_count].rsrp_valid = 1;

+

+                    cell_info->ext_info[neibor_count].rsrq = cell->value4;

+                    cell_info->ext_info[neibor_count].rsrq_valid = 1;

+

+                    cell_info->ext_info[neibor_count].cell_id = cell->value5;

+                    cell_info->ext_info[neibor_count].cell_id_valid = 1;

+

+                    cell_info->ext_info[neibor_count].band = cell->value9;

+                    cell_info->ext_info[neibor_count].band_valid = 1;

+

+                    cell_info->ext_info[neibor_count].rssi = cell->value10;

+                    cell_info->ext_info[neibor_count].rssi_valid = 1;

+

+                    neibor_count++;

+                }

+

+                default:

+                    break;

+            }

+        }

+    }

+    list_free(cell_list);

+

+    return GSW_HAL_SUCCESS;

+}

+

+/*

+ * @brief set modem status event callback

+   @param [in] handle_ptr callback function address

+   @retval 0: success

+   @retval 0: other: fail

+ */

+int gsw_reg_set_modem_status_event_callback(GSW_NW_ModemStateHandlePtr handle_ptr)

+{

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    int ret = -1;

+

+    if(handle_ptr == NULL)

+    {

+        LOGE("handle_ptr is NULL\n");

+        return GSW_HAL_FAIL;

+    }

+

+    modem_cb = handle_ptr;

+

+    ret = mbtk_radio_state_change_cb_reg(nw_info_handle,gsw_modem_status_event_callback);

+    if(ret != 0)

+    {

+        LOGE("mbtk_radio_state_change_cb_reg failed : %d\n", ret);

+        return GSW_HAL_FAIL;

+    }

+

+    return GSW_HAL_SUCCESS;

+

+}

+

+

+/*

+ * @brief get PLMNs from the FPLMN list

+ * @param [inout] plmn_list: 

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_get_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    int ret = -1;

+    char fplmn[256] = {0};

+    LOGE("mbtk_fplmn_get enter\n");

+    ret = mbtk_fplmn_get(nw_info_handle, fplmn);

+    LOGE("mbtk_fplmn_get exit\n");

+    if(ret != 0)

+    {

+        LOGE("mbtk_fplmn_get failed : %d\n",ret);

+        return GSW_HAL_FAIL;

+    }

+

+    update_fplmn_list(fplmn);

+    for(int i = 0; i < fplmn_index; i++)

+    {

+        if(strcmp(fplmn_array[i],"FFFFFF") == 0)

+        {

+            continue;

+        }

+        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);

+        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);

+        plmn_list->plmn_list_len++;

+    }

+

+    LOGE("fplmn = %s\n", fplmn);

+    return GSW_HAL_SUCCESS;

+}

+

+/*

+ * @brief add PLMNs from the plmn_list to the FPLMN list

+ * @param [in] plmn_list: 

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_add_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)

+{

+

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(plmn_list->plmn_list_len >= fplmn_max_length)

+    {

+        LOGE("can't save all the plmn\n");

+        return GSW_HAL_FAIL;

+    }

+

+    int i = 0;

+    int index = -1;

+

+    for(i = 0; i < plmn_list->plmn_list_len; i++)

+    {

+        index = check_index(plmn_list->plmn_list[i].mcc, plmn_list->plmn_list[i].mnc);

+

+        if(index == -1)

+        {

+            LOGE("no this PLMN, add it\n");

+            if((fplmn_index + plmn_list->plmn_list_len) > fplmn_max_length)

+            {

+                LOGE("can't save all the plmn\n");

+                return GSW_HAL_FAIL;

+            }

+

+            else

+            {

+                memcpy(fplmn_array[fplmn_index], plmn_list->plmn_list[i].mcc, 3);

+                memcpy(fplmn_array[fplmn_index] + 3, plmn_list->plmn_list[i].mnc, 2);

+                fplmn_array[fplmn_index][5] = '\0';

+                LOGE("fplmn_array[%d] = %s\n", fplmn_index, fplmn_array[fplmn_index]);

+                fplmn_index++;

+            }

+        }

+

+        else

+        {

+            LOGE("already have this PLMN, don't add it\n");

+        }

+    }

+

+    char fplmn_str[256] = {0};

+    convert_plmn_to_fplmn_str(fplmn_str);

+

+    LOGE("fplmn_str = %s\n", fplmn_str);

+

+    int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);

+    if(ret != 0)

+    {

+        LOGE("mbtk_fplmn_set failed : %d\n",ret);

+        return GSW_HAL_FAIL;

+    }

+

+    LOGE("gsw_add_forbidden_networks exit\n");

+    return GSW_HAL_SUCCESS;

+}

+

+/*

+ * @brief Remove PLMNs from the plmn_list from the FPLMN list

+ * @param [in] plmn_list: 

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_remove_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)

+{

+    LOGE("gsw_remove_forbidden_networks enter\n");

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    int i = 0;

+    int index = -1;

+

+    for(i = 0; i < plmn_list->plmn_list_len; i++)

+    {

+        index = check_index(plmn_list->plmn_list[i].mcc, plmn_list->plmn_list[i].mnc);

+        if(index != -1)

+        {

+            remove_fplmn(index);

+        }

+        else

+        {

+            LOGE("no this PLMN, can't remove it\n");

+        }

+    }

+

+    for(i = 0; i < fplmn_index; i++)

+    {

+        LOGE("fplmn_array[%d] = %s\n", i, fplmn_array[i]);

+    }

+

+    char fplmn_str[256] = {0};

+    convert_plmn_to_fplmn_str(fplmn_str);

+    LOGE("fplmn_str = %s\n", fplmn_str);

+

+    int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);

+    if(ret != 0)

+    {

+        LOGE("mbtk_fplmn_set failed : %d\n",ret);

+        return GSW_HAL_FAIL;

+    }

+

+    LOGE("gsw_remove_forbidden_networks exit\n");

+    return GSW_HAL_SUCCESS;

+}

+

+/*

+ * @brief clear FPLMN list

+ * @param

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_clear_forbidden_networks(void)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    char fplmn_str[FPLMN_STRING_LENGTH+1]; 

+    memset(fplmn_str, 'F', (6 * fplmn_max_length));

+    fplmn_str[(6 * fplmn_max_length)] = '\0'; 

+

+    LOGE("%s\n", fplmn_str);

+    int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);

+    if(ret != 0)

+    {

+        LOGE("mbtk_fplmn_set failed : %d\n",ret);

+        return GSW_HAL_FAIL;

+    }

+

+    return GSW_HAL_SUCCESS;

+}

+

+/*

+ * @brief get oos config

+ * @param [in] oos_config

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_oos_config_get(GSW_NW_OOS_CONFIG_INFO_T *pt_info)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(pt_info == NULL)

+    {

+        LOGE("pt_info is null\n");

+        return GSW_HAL_FAIL;

+    }

+

+    int ret = -1;

+

+    mbtk_oos_info oos_info;

+    memset(&oos_info, 0x00, sizeof(mbtk_oos_info));

+

+    ret = mbtk_oos_get(nw_info_handle, &oos_info);

+    if(ret != 0)

+    {

+        LOGE("mbtk_oos_get failed : %d\n",ret);

+        return GSW_HAL_FAIL;

+    }

+

+    if(oos_info.mode == 0)

+    {

+        pt_info->t_min = 0;

+        pt_info->t_step = 0;

+        pt_info->t_max = 0;

+    }

+

+    else

+    {

+        pt_info->t_min = (int)oos_info.oosPhase[0];

+        pt_info->t_step = (int)oos_info.oosPhase[1];

+        pt_info->t_max = (int)oos_info.oosPhase[2];

+    }

+

+    return GSW_HAL_SUCCESS;

+}

+

+

+/*

+ * @brief set oos config

+ * @param [in] oos_config

+ * @retval 0: success

+ * @retval other: fail

+ */

+int gsw_oos_config_set(GSW_NW_OOS_CONFIG_INFO_T *pt_info)

+{

+    if (nw_init_flag == 0 || nw_info_handle == NULL)

+    {

+        return GSW_HAL_FAIL;

+    }

+

+    if(pt_info == NULL)

+    {

+        LOGE("pt_info is null\n");

+        return GSW_HAL_FAIL;

+    }

+

+    int ret = -1;

+    mbtk_oos_info oos_info;

+    memset(&oos_info, 0x00, sizeof(mbtk_oos_info));

+

+    if (pt_info->t_min < 0 || pt_info->t_step < 0 || pt_info->t_max < 0)

+    {

+        LOGE("gsw_oos_config_set set time < 0 ");

+        return GSW_HAL_FAIL;

+    }

+    else if ((pt_info->t_min > 0 && pt_info->t_min <= 255) && pt_info->t_step == 0 && pt_info->t_max == 0)

+    {

+        oos_info.mode = 1;

+        oos_info.oosPhase[0] = pt_info->t_min;

+    }

+    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)

+    {

+        oos_info.mode = 1;

+        oos_info.oosPhase[0] = pt_info->t_min;

+        oos_info.oosPhase[1] = pt_info->t_step;

+    }

+    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))

+    {

+        oos_info.mode = 1;

+        oos_info.oosPhase[0] = pt_info->t_min;

+        oos_info.oosPhase[1] = pt_info->t_step;

+        oos_info.oosPhase[2] = pt_info->t_max;

+    }

+    else if (pt_info->t_min == 0 && pt_info->t_step == 0 && pt_info->t_max == 0)

+    {

+        oos_info.mode = 0;

+    }

+    else

+    {

+        LOGE("gsw_oos_config_set set Format err");

+        return GSW_HAL_FAIL;

+    }

+

+    ret = mbtk_oos_set(nw_info_handle, &oos_info);

+    if(ret != 0)

+    {

+        LOGE("mbtk_oos_set failed : %d\n",ret);

+        return GSW_HAL_FAIL;

+    }

+

+    return GSW_HAL_SUCCESS;

+}

+

+

+