b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1 | #include "gsw_nw_interface.h"
|
| 2 | #include <dlfcn.h>
|
| 3 | #include <time.h>
|
| 4 | #include <pthread.h>
|
| 5 |
|
| 6 | //mbtk include
|
| 7 | #define LYNQ_AIR_PLANE_MODE_OFF 1 //at+cfun = 1
|
| 8 | #define LYNQ_AIR_PLANE_MODE_ON 4 // at+cfun = 4
|
| 9 | #define LYNQ_AIR_CFUN_MODE_OFF 0 // at+cfun = 0
|
| 10 |
|
| 11 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
| 12 |
|
| 13 | #define FPLMN_STRING_LENGTH 120
|
| 14 | #define ENTRY_LENGTH 6
|
| 15 | #define FPLMN_ARRAY_SIZE (FPLMN_STRING_LENGTH / 6) + 1
|
| 16 |
|
| 17 | #ifndef FALSE
|
| 18 | #define FALSE (0)
|
| 19 | #endif
|
| 20 |
|
| 21 |
|
| 22 | #ifndef TRUE
|
| 23 | #define TRUE (!FALSE)
|
| 24 | #endif
|
| 25 |
|
| 26 | typedef unsigned int uint32;
|
| 27 | typedef unsigned char uint8;
|
| 28 | typedef unsigned short uint16;
|
| 29 | typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
|
| 30 |
|
| 31 | typedef enum
|
| 32 | {
|
| 33 | MBTK_DEV_MODEM_MIN_FUN, //Modem 最小功能
|
| 34 | MBTK_DEV_MODEM_FULL_FUN, //Modem 全功能
|
| 35 | MBTK_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS = 3, //Modem 禁用射频接收电路
|
| 36 | MBTK_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS, //Modem禁用射频发射和接收电路
|
| 37 | MBTK_DEV_MODEM_DISABLE_SIM, //Modem 禁用(U)SIM 卡
|
| 38 | MBTK_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE, //Modem 完全禁用辅助接收
|
| 39 | }MBTK_DEV_MODEM_FUNCTION;
|
| 40 |
|
| 41 | typedef enum
|
| 42 | {
|
| 43 | MBTK_CELL_TYPE_GSM = 0,
|
| 44 | MBTK_CELL_TYPE_UMTS,
|
| 45 | MBTK_CELL_TYPE_LTE
|
| 46 | } mbtk_cell_type_enum;
|
| 47 |
|
| 48 | typedef struct
|
| 49 | {
|
| 50 | MBTK_DEV_MODEM_FUNCTION fun;
|
| 51 | int rst;
|
| 52 | } mbtk_modem_info_t;
|
| 53 |
|
| 54 | typedef struct
|
| 55 | {
|
| 56 | int client_fd;
|
| 57 | pthread_t read_thread_id;
|
| 58 | int exit_fd[2];
|
| 59 | bool is_waitting;
|
| 60 | pthread_cond_t cond;
|
| 61 | pthread_mutex_t mutex;
|
| 62 |
|
| 63 | pthread_mutex_t send_mutex;
|
| 64 |
|
| 65 | // Temp response data.
|
| 66 | uint16 info_err;
|
| 67 | uint16 data_len;
|
| 68 | void *data;
|
| 69 |
|
| 70 | //mbtk wyq for server_ready_status add start
|
| 71 | char server_ready_status;
|
| 72 | //mbtk wyq for server_ready_status add end
|
| 73 |
|
| 74 | mbtk_info_callback_func net_state_cb;
|
| 75 | mbtk_info_callback_func call_state_cb;
|
| 76 | mbtk_info_callback_func sms_state_cb;
|
| 77 | mbtk_info_callback_func radio_state_cb;
|
| 78 | mbtk_info_callback_func sim_state_cb;
|
| 79 | mbtk_info_callback_func pdp_state_cb;
|
| 80 | //add signal by xr
|
| 81 | mbtk_info_callback_func signal_state_cb;
|
| 82 | } mbtk_info_handle_t;
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 | typedef struct
|
| 87 | {
|
| 88 | // LTE server cell: tac, PCI, dlEuarfcn, ulEuarfcn, band
|
| 89 | // LTE cell: phyCellId,euArfcn,rsrp,rsrq
|
| 90 | // WCDMA server cell: lac, ci, arfcn
|
| 91 | // WCDMA cell: lac, ci, arfcn
|
| 92 | // GSM server cell: lac, ci, arfcn, bsic
|
| 93 | // GSM cell:
|
| 94 | uint32 value1;
|
| 95 | uint32 value2;
|
| 96 | uint32 value3;
|
| 97 | uint32 value4;
|
| 98 | uint32 value5;
|
| 99 | uint32 value6;
|
| 100 | uint32 value7;
|
| 101 | uint32 value8;
|
| 102 | uint32 value9;
|
| 103 | uint32 value10;
|
| 104 | } __attribute__((packed)) mbtk_cell_info_t;
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 | typedef struct
|
| 111 | {
|
| 112 | uint8 net_pref; // mbtk_net_pref_enum
|
| 113 | uint16 gsm_band; // mbtk_gsm_band_enum
|
| 114 | uint16 umts_band; // mbtk_umts_band_enum
|
| 115 | uint32 tdlte_band; // mbtk_tdlte_band_enum
|
| 116 | uint32 fddlte_band; // mbtk_fddlte_band_enum
|
| 117 | uint32 lte_ext_band; // mbtk_lte_ext_band_enum
|
| 118 | } __attribute__((packed)) mbtk_band_info_t;
|
| 119 |
|
| 120 | typedef struct list_arraynode
|
| 121 | {
|
| 122 | void *data;
|
| 123 | struct list_arraynode *next;
|
| 124 | } list_arraynode_t;
|
| 125 |
|
| 126 | typedef struct list_treenode
|
| 127 | {
|
| 128 | list_arraynode_t *data;
|
| 129 | int count;
|
| 130 | struct list_treenode *left;
|
| 131 | struct list_treenode *right;
|
| 132 | } list_treenode_t;
|
| 133 |
|
| 134 | typedef int (*list_sort_func)(void *data1, void *data2);
|
| 135 | typedef void (*list_free_func)(void *data);
|
| 136 |
|
| 137 | typedef struct list_node
|
| 138 | {
|
| 139 | uint32 size;
|
| 140 | list_sort_func sort_func;
|
| 141 | list_free_func free_func;
|
| 142 |
|
| 143 | uint32 cur_index;
|
| 144 | list_arraynode_t *cur_array_data;
|
| 145 |
|
| 146 | list_arraynode_t array_data;
|
| 147 | list_treenode_t tree_data;
|
| 148 | } list_node_t;
|
| 149 |
|
| 150 | /*
|
| 151 | 0: GSM
|
| 152 | 1: GSM Compact
|
| 153 | 2: UTRAN
|
| 154 | 3: GSM w/EGPRS
|
| 155 | 4: UTRAN w/HSDPA
|
| 156 | 5: UTRAN w/HSUPA
|
| 157 | 6: UTRAN w/HSDPA and HSUPA
|
| 158 | 7: E-UTRAN
|
| 159 | 8: UTRAN HSPA+
|
| 160 | */
|
| 161 | typedef enum {
|
| 162 | MBTK_RADIO_TECH_GSM = 0,
|
| 163 | MBTK_RADIO_TECH_GSM_COMPACT,
|
| 164 | MBTK_RADIO_TECH_UTRAN,
|
| 165 | MBTK_RADIO_TECH_GSM_EGPRS,
|
| 166 | MBTK_RADIO_TECH_UTRAN_HSDPA,
|
| 167 | MBTK_RADIO_TECH_UTRAN_HSUPA,
|
| 168 | MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA,
|
| 169 | MBTK_RADIO_TECH_E_UTRAN, // LTE
|
| 170 | MBTK_RADIO_TECH_UTRAN_HSPA
|
| 171 | } mbtk_radio_technology_enum;
|
| 172 |
|
| 173 | typedef struct
|
| 174 | {
|
| 175 | /*
|
| 176 | 0: automatic
|
| 177 | 1: manual
|
| 178 | */
|
| 179 | uint8 net_sel_mode;
|
| 180 | /*
|
| 181 | 0: GSM
|
| 182 | 1: GSM Compact
|
| 183 | 2: UTRAN
|
| 184 | 3: GSM w/EGPRS
|
| 185 | 4: UTRAN w/HSDPA
|
| 186 | 5: UTRAN w/HSUPA
|
| 187 | 6: UTRAN w/HSDPA and HSUPA
|
| 188 | 7: E-UTRAN
|
| 189 | 8: UTRAN HSPA+
|
| 190 | 0xFF: Unused
|
| 191 | */
|
| 192 | uint8 net_type;
|
| 193 | //uint8 plmn[10]; // 46000
|
| 194 | /*
|
| 195 | 0: unknown
|
| 196 | 1: available
|
| 197 | 2: current
|
| 198 | 3: forbidden
|
| 199 | */
|
| 200 | uint8 net_state;
|
| 201 | uint32 plmn;
|
| 202 | } __attribute__((packed)) mbtk_net_info_t;
|
| 203 |
|
| 204 |
|
| 205 | typedef enum
|
| 206 | {
|
| 207 | MBTK_NET_REG_STATE_NON = 0,
|
| 208 | MBTK_NET_REG_STATE_HOME,
|
| 209 | MBTK_NET_REG_STATE_SEARCHING,
|
| 210 | MBTK_NET_REG_STATE_DENIED,
|
| 211 | MBTK_NET_REG_STATE_UNKNOWN,
|
| 212 | MBTK_NET_REG_STATE_ROAMING,
|
| 213 | MBTK_NET_REG_STATE_SMS_ONLY,
|
| 214 | MBTK_NET_REG_STATE_ROAMING_SMS,
|
| 215 | MBTK_NET_REG_STATE_ATTACHED_EMERGENCY,
|
| 216 | MBTK_NET_REG_STATE_CSFB_HOME,
|
| 217 | MBTK_NET_REG_STATE_CSFB_ROAMING,
|
| 218 | MBTK_NET_REG_STATE_EMERGENCY_ONLY
|
| 219 | } mbtk_net_reg_state_enum;
|
| 220 |
|
| 221 | typedef struct
|
| 222 | {
|
| 223 | uint8 call_state;// mbtk_net_reg_state_enum
|
| 224 | uint8 data_state;// mbtk_net_reg_state_enum
|
| 225 | uint8 ims_state;// mbtk_net_reg_state_enum
|
| 226 | uint8 type; // mbtk_radio_technology_enum
|
| 227 | uint16 lac;
|
| 228 | uint32 ci;
|
| 229 | } __attribute__((packed)) mbtk_net_reg_info_t;
|
| 230 |
|
| 231 | typedef struct
|
| 232 | {
|
| 233 | uint8 type; // mbtk_radio_technology_enum
|
| 234 | uint8 rssi; // 0: 113 dBm or less
|
| 235 | // 1: 111 dBm
|
| 236 | // 2��30: 109��53 dBm
|
| 237 | // 31: 51 dBm or greater
|
| 238 | // 99: not known or not detectable
|
| 239 | uint8 rxlev;// 0:rssi < -110 dBm
|
| 240 | // 1: -110 dBm �� rssi < -109 dBm
|
| 241 | // 2: -109 dBm �� rssi < -108 dBm
|
| 242 | // ......
|
| 243 | // 61: -50 dBm �� rssi < -49 dBm
|
| 244 | // 62: -49 dBm �� rssi < -48 dBm
|
| 245 | // 63: -48 dBm �� rssi
|
| 246 | // 99: not known or not detectable
|
| 247 | uint8 ber; // 0...7 as RXQUAL values in the table in 3GPP TS 45.008 [20] subclause 8.2.4
|
| 248 | // 99 not known or not detectable
|
| 249 | uint8 rscp; // 0: rscp < -120 dBm
|
| 250 | // 1: -120 dBm �� rscp < -119 dBm
|
| 251 | // 2: -119 dBm �� rscp < -118 dBm
|
| 252 | // ......
|
| 253 | // 94: -27 dBm �� rscp < -26 dBm
|
| 254 | // 95: -26 dBm �� rscp < -25 dBm
|
| 255 | // 96: - 25 dBm �� rscp
|
| 256 | // 255: not known or not detectable
|
| 257 | uint8 ecno; // 0: Ec/Io < -24 dB
|
| 258 | // 1: -24 dB �� Ec/Io < -23.5 dB
|
| 259 | // 2: -23.5 dB �� Ec/Io < -23 dB
|
| 260 | // ......
|
| 261 | // 47: -1 dB �� Ec/Io < -0.5 dB
|
| 262 | // 48: -0.5 dB �� Ec/Io < 0 dB
|
| 263 | // 49: 0 dB �� Ec/Io
|
| 264 | // 255: not known or not detectable
|
| 265 | uint8 rsrq; // 0: rsrq < -19.5 dB
|
| 266 | // 1: -19.5 dB �� rsrq < -19 dB
|
| 267 | // 2: -19 dB �� rsrq < -18.5 dB
|
| 268 | // ......
|
| 269 | // 32: -4 dB �� rsrq < -3.5 dB
|
| 270 | // 33: -3.5 dB �� rsrq < -3 dB
|
| 271 | // 34: -3 dB �� rsrq
|
| 272 | // 255: not known or not detectable
|
| 273 | uint8 rsrp; // 0: rsrp < -140 dBm
|
| 274 | // 1: -140 dBm �� rsrp < -139 dBm
|
| 275 | // 2: -139 dBm �� rsrp < -138 dBm
|
| 276 | // ......
|
| 277 | // 95: -46 dBm �� rsrp < -45 dBm
|
| 278 | // 96: -45 dBm �� rsrp < -44 dBm
|
| 279 | // 97: -44 dBm �� rsrp
|
| 280 | // 255: not known or not detectable
|
| 281 | } __attribute__((packed)) mbtk_signal_info_t;
|
| 282 |
|
| 283 | typedef struct{
|
| 284 | uint8_t mode;
|
| 285 | uint32_t oosPhase[3]; //单位为秒
|
| 286 | } mbtk_oos_info;
|
| 287 |
|
| 288 | typedef struct
|
| 289 | {
|
| 290 | /* Configuration parameters for MCM network full band network scan when OOS (out of service)*/
|
| 291 | int t_min;
|
| 292 | int t_step;
|
| 293 | int t_max;
|
| 294 | }GSW_NW_OOS_CONFIG_INFO_T;
|
| 295 |
|
| 296 |
|
| 297 | #define GSW_HAL_FAIL GSW_HAL_NORMAL_FAIL
|
| 298 | #define GSW_HAL_MEM_INVAILD GSW_HAL_ARG_INVALID
|
| 299 | #define lib_mbtk_path "/lib/libmbtk_lib.so"
|
| 300 | mbtk_info_handle_t* nw_info_handle = NULL;
|
| 301 |
|
| 302 | static GSW_NW_ServingInfoHandlePtr serving_cb;
|
| 303 | static GSW_NW_SigInfoHandlePtr sig_cb;
|
| 304 | static GSW_NW_RejectCauseHandlePtr reject_cb;
|
| 305 | static GSW_NW_ModemStateHandlePtr modem_cb;
|
| 306 |
|
| 307 | static void *dlHandle_mbtk;
|
| 308 | int nw_init_flag = 0;
|
| 309 | int mode = -1;
|
| 310 | int fplmn_max_length = 0;
|
| 311 |
|
| 312 | gsw_nw_plmn_list_t gsw_nw_plmn_list;
|
| 313 | char fplmn_array[FPLMN_ARRAY_SIZE][7];
|
| 314 | int fplmn_index = 0;
|
| 315 |
|
| 316 | static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
|
| 317 | static int (*mbtk_info_handle_free)(mbtk_info_handle_t** handle);
|
| 318 | int (*mbtk_net_sel_mode_get)(mbtk_info_handle_t* handle, mbtk_net_info_t *net);
|
| 319 | int (*mbtk_net_reg_get)(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg);
|
| 320 | int (*mbtk_cell_get)(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list);
|
| 321 | int (*mbtk_get_modem_fun)(mbtk_info_handle_t* handle, int* fun);
|
| 322 | static int (*mbtk_set_modem_fun)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info);
|
| 323 | int (*mbtk_current_band_get)(mbtk_info_handle_t* handle, mbtk_band_info_t *band);
|
| 324 | int (*mbtk_current_band_set)(mbtk_info_handle_t* handle, const mbtk_band_info_t *band);
|
| 325 | int (*mbtk_net_signal_get)(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal);
|
| 326 | int (*mbtk_wakeup_state_set)(mbtk_info_handle_t* handle, uint32 wakeup_state);
|
| 327 | int (*mbtk_signal_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
|
| 328 | int (*mbtk_net_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
|
| 329 | int (*mbtk_fplmn_get)(mbtk_info_handle_t *handle, void *fplmn);
|
| 330 | int (*mbtk_fplmn_set)(mbtk_info_handle_t *handle, void *fplmn);
|
| 331 | int (*mbtk_radio_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
|
| 332 | int (*mbtk_oos_get)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);
|
| 333 | int (*mbtk_oos_set)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);
|
| 334 |
|
| 335 | static void (*mbtk_log)(int level, const char *format, ...);
|
| 336 | static void (*mbtk_log_init)(char *path, char *tag);
|
| 337 |
|
| 338 | #ifndef LOG_ERR_LEVEL
|
| 339 | #define LOG_ERR_LEVEL 3 /* error conditions */
|
| 340 | #endif
|
| 341 | #ifndef LOG_WARN_LEVEL
|
| 342 | #define LOG_WARN_LEVEL 4 /* warning conditions */
|
| 343 | #endif
|
| 344 | #ifndef LOG_INFO_LEVEL
|
| 345 | #define LOG_INFO_LEVEL 6 /* informational */
|
| 346 | #endif
|
| 347 | #ifndef LOG_DEBUG_LEVEL
|
| 348 | #define LOG_DEBUG_LEVEL 7 /* debug-level messages */
|
| 349 | #endif
|
| 350 | #ifndef LOG_VERBOSE_LEVEL
|
| 351 | #define LOG_VERBOSE_LEVEL 8
|
| 352 | #endif
|
| 353 |
|
| 354 | #define LOGV(fmt, args ...) \
|
| 355 | do{ \
|
| 356 | char *file_ptr_1001 = __FILE__; \
|
| 357 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 358 | char line_1001[10] = {0}; \
|
| 359 | sprintf(line_1001, "%d", __LINE__); \
|
| 360 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 361 | if(*ptr_1001 == '/') \
|
| 362 | break; \
|
| 363 | ptr_1001--; \
|
| 364 | } \
|
| 365 | mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
|
| 366 | } while(0)
|
| 367 |
|
| 368 | #define LOGI(fmt, args...) \
|
| 369 | do{ \
|
| 370 | char *file_ptr_1001 = __FILE__; \
|
| 371 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 372 | char line_1001[10] = {0}; \
|
| 373 | sprintf(line_1001, "%d", __LINE__); \
|
| 374 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 375 | if(*ptr_1001 == '/') \
|
| 376 | break; \
|
| 377 | ptr_1001--; \
|
| 378 | } \
|
| 379 | mbtk_log(LOG_INFO_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
|
| 380 | } while(0)
|
| 381 |
|
| 382 | #define LOGD(fmt, args...) \
|
| 383 | do{ \
|
| 384 | char *file_ptr_1001 = __FILE__; \
|
| 385 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 386 | char line_1001[10] = {0}; \
|
| 387 | sprintf(line_1001, "%d", __LINE__); \
|
| 388 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 389 | if(*ptr_1001 == '/') \
|
| 390 | break; \
|
| 391 | ptr_1001--; \
|
| 392 | } \
|
| 393 | mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
|
| 394 | } while(0)
|
| 395 |
|
| 396 | #define LOGW(fmt, args...) \
|
| 397 | do{ \
|
| 398 | char *file_ptr_1001 = __FILE__; \
|
| 399 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 400 | char line_1001[10] = {0}; \
|
| 401 | sprintf(line_1001, "%d", __LINE__); \
|
| 402 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 403 | if(*ptr_1001 == '/') \
|
| 404 | break; \
|
| 405 | ptr_1001--; \
|
| 406 | } \
|
| 407 | mbtk_log(LOG_WARN_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
|
| 408 | } while(0)
|
| 409 |
|
| 410 | #define LOGE(fmt, args...) \
|
| 411 | do{ \
|
| 412 | char *file_ptr_1001 = __FILE__; \
|
| 413 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 414 | char line_1001[10] = {0}; \
|
| 415 | sprintf(line_1001, "%d", __LINE__); \
|
| 416 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 417 | if(*ptr_1001 == '/') \
|
| 418 | break; \
|
| 419 | ptr_1001--; \
|
| 420 | } \
|
| 421 | mbtk_log(LOG_ERR_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
|
| 422 | } while(0)
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 | typedef struct
|
| 427 | {
|
| 428 | char *lynq_operator_l;
|
| 429 | char *lynq_operator_s;
|
| 430 | uint32 lynq_mcc_mnc;
|
| 431 | } lynq_operator_mcc_mnc_t;
|
| 432 |
|
| 433 | static lynq_operator_mcc_mnc_t lynq_operator_mcc_mnc[] =
|
| 434 | {
|
| 435 | {"China Mobile","CMCC",46000},
|
| 436 | {"China Unicom","CU",46001},
|
| 437 | {"China Mobile","CMCC",46002},
|
| 438 | {"China Telecom","CT",46003},
|
| 439 | {"China Mobile","CMCC",46004},
|
| 440 | {"China Telecom","CT",46005},
|
| 441 | {"China Unicom","CU",46006},
|
| 442 | {"China Mobile","CMCC",46007},
|
| 443 | {"China Mobile","CMCC",46008},
|
| 444 | {"China Unicom","CU",46009},
|
| 445 | {"China Telecom","CT",46011}
|
| 446 | };
|
| 447 |
|
| 448 |
|
| 449 | //GSW include
|
| 450 | typedef enum prefer_mode
|
| 451 | {
|
| 452 | GSW_PREFER_MODE_GSW = 1, /**<2G only*/
|
| 453 | GSW_PREFER_MODE_WCDMA = 2, /**< 3G only*/
|
| 454 | GSW_PREFER_MODE_WCDMA_GSM = 3, /**< 3G/2G*/
|
| 455 | GSW_PREFER_MODE_LTE = 4, /**< 4G only*/
|
| 456 | GSW_PREFER_MODE_NR5G = 5, /**< 5G only*/
|
| 457 | GSW_PREFER_MODE_NR5G_LTE = 8, /**< 5G/4G*/
|
| 458 | GSW_PREFER_MODE_LTE_WCDMA_GSM = 9, /**< 4G/3G/2G*/
|
| 459 | GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM = 32, /**< 5G/4G/3G/2G*/
|
| 460 | } PREFER_MODE_E;
|
| 461 |
|
| 462 | static int mbtk_nw_api_import()
|
| 463 | {
|
| 464 | dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
|
| 465 | if (dlHandle_mbtk == NULL)
|
| 466 | {
|
| 467 | return GSW_HAL_FAIL;
|
| 468 | }
|
| 469 |
|
| 470 | mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
|
| 471 | if (mbtk_log_init == NULL)
|
| 472 | {
|
| 473 | return GSW_HAL_FAIL;
|
| 474 | }
|
| 475 |
|
| 476 | mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
|
| 477 | if (mbtk_log == NULL)
|
| 478 | {
|
| 479 | return GSW_HAL_FAIL;
|
| 480 | }
|
| 481 |
|
| 482 | mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
|
| 483 | if (mbtk_info_handle_get == NULL)
|
| 484 | {
|
| 485 | LOGE("mbtk_info_handle_get dlsym fail\n");
|
| 486 | return GSW_HAL_FAIL;
|
| 487 | }
|
| 488 |
|
| 489 | mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free");
|
| 490 | if (mbtk_info_handle_free == NULL)
|
| 491 | {
|
| 492 | LOGE("mbtk_info_handle_free dlsym fail\n");
|
| 493 | return GSW_HAL_FAIL;
|
| 494 | }
|
| 495 |
|
| 496 | mbtk_net_sel_mode_get = (int (*)(mbtk_info_handle_t* handle, mbtk_net_info_t *net))dlsym(dlHandle_mbtk, "mbtk_net_sel_mode_get");
|
| 497 | if (mbtk_net_sel_mode_get == NULL)
|
| 498 | {
|
| 499 | LOGE("mbtk_net_sel_mode_get dlsym fail\n");
|
| 500 | return GSW_HAL_FAIL;
|
| 501 | }
|
| 502 |
|
| 503 | mbtk_net_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_net_reg_get");
|
| 504 | if (mbtk_net_reg_get == NULL)
|
| 505 | {
|
| 506 | LOGE("mbtk_net_reg_get dlsym fail\n");
|
| 507 | return GSW_HAL_FAIL;
|
| 508 | }
|
| 509 |
|
| 510 | mbtk_get_modem_fun = (int (*)(mbtk_info_handle_t* handle, int* fun))dlsym(dlHandle_mbtk, "mbtk_get_modem_fun");
|
| 511 | if (mbtk_get_modem_fun == NULL)
|
| 512 | {
|
| 513 | LOGE("mbtk_get_modem_fun dlsym fail\n");
|
| 514 | return GSW_HAL_FAIL;
|
| 515 | }
|
| 516 |
|
| 517 | mbtk_set_modem_fun = (int (*)(mbtk_info_handle_t* handle, mbtk_modem_info_t *info))dlsym(dlHandle_mbtk, "mbtk_set_modem_fun");
|
| 518 | if (mbtk_set_modem_fun == NULL)
|
| 519 | {
|
| 520 | LOGE("mbtk_set_modem_fun dlsym fail\n");
|
| 521 | return GSW_HAL_FAIL;
|
| 522 | }
|
| 523 |
|
| 524 | mbtk_current_band_get = (int (*)(mbtk_info_handle_t* handle, mbtk_band_info_t *band))dlsym(dlHandle_mbtk, "mbtk_current_band_get");
|
| 525 | if (mbtk_current_band_get == NULL)
|
| 526 | {
|
| 527 | LOGE("mbtk_current_band_get dlsym fail\n");
|
| 528 | return GSW_HAL_FAIL;
|
| 529 | }
|
| 530 |
|
| 531 | mbtk_current_band_set = (int (*)(mbtk_info_handle_t* handle, const mbtk_band_info_t *band))dlsym(dlHandle_mbtk, "mbtk_current_band_set");
|
| 532 | if (mbtk_current_band_set == NULL)
|
| 533 | {
|
| 534 | LOGE("mbtk_current_band_set dlsym fail\n");
|
| 535 | return GSW_HAL_FAIL;
|
| 536 | }
|
| 537 |
|
| 538 | mbtk_net_signal_get = (int (*)(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal))dlsym(dlHandle_mbtk, "mbtk_net_signal_get");
|
| 539 | if (mbtk_net_signal_get == NULL)
|
| 540 | {
|
| 541 | LOGE("mbtk_net_signal_get dlsym fail\n");
|
| 542 | return GSW_HAL_FAIL;
|
| 543 | }
|
| 544 |
|
| 545 | mbtk_wakeup_state_set = (int (*)(mbtk_info_handle_t* handle, uint32 wakeup_state))dlsym(dlHandle_mbtk, "mbtk_wakeup_state_set");
|
| 546 | if (mbtk_wakeup_state_set == NULL)
|
| 547 | {
|
| 548 | LOGE("mbtk_wakeup_state_set dlsym fail\n");
|
| 549 | return GSW_HAL_FAIL;
|
| 550 | }
|
| 551 |
|
| 552 | 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");
|
| 553 | if (mbtk_cell_get == NULL)
|
| 554 | {
|
| 555 | LOGE("mbtk_cell_get dlsym fail\n");
|
| 556 | return GSW_HAL_FAIL;
|
| 557 | }
|
| 558 |
|
| 559 | 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");
|
| 560 | if (mbtk_signal_state_change_cb_reg == NULL)
|
| 561 | {
|
| 562 | LOGE("mbtk_signal_state_change_cb_reg dlsym fail\n");
|
| 563 | return GSW_HAL_FAIL;
|
| 564 | }
|
| 565 |
|
| 566 | 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");
|
| 567 | if (mbtk_net_state_change_cb_reg == NULL)
|
| 568 | {
|
| 569 | LOGE("mbtk_net_state_change_cb_reg dlsym fail\n");
|
| 570 | return GSW_HAL_FAIL;
|
| 571 | }
|
| 572 |
|
| 573 | mbtk_fplmn_get = (int(*)(mbtk_info_handle_t *handle, void *fplmn))dlsym(dlHandle_mbtk, "mbtk_fplmn_get");
|
| 574 | if (mbtk_fplmn_get == NULL)
|
| 575 | {
|
| 576 | LOGE("mbtk_fplmn_get dlsym fail\n");
|
| 577 | return GSW_HAL_FAIL;
|
| 578 | }
|
| 579 |
|
| 580 | mbtk_fplmn_set = (int(*)(mbtk_info_handle_t *handle, void *fplmn))dlsym(dlHandle_mbtk, "mbtk_fplmn_set");
|
| 581 | if (mbtk_fplmn_set == NULL)
|
| 582 | {
|
| 583 | LOGE("mbtk_fplmn_get dlsym fail\n");
|
| 584 | return GSW_HAL_FAIL;
|
| 585 | }
|
| 586 |
|
| 587 | 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");
|
| 588 | if (mbtk_radio_state_change_cb_reg == NULL)
|
| 589 | {
|
| 590 | LOGE("mbtk_radio_state_change_cb_reg dlsym fail\n");
|
| 591 | return GSW_HAL_FAIL;
|
| 592 | }
|
| 593 |
|
| 594 | mbtk_oos_get = (int (*)(mbtk_info_handle_t* handle, mbtk_oos_info *oos))dlsym(dlHandle_mbtk, "mbtk_oos_get");
|
| 595 | if (mbtk_oos_get == NULL)
|
| 596 | {
|
| 597 | LOGE("mbtk_oos_get dlsym fail\n");
|
| 598 | return GSW_HAL_FAIL;
|
| 599 | }
|
| 600 |
|
| 601 | mbtk_oos_set = (int (*)(mbtk_info_handle_t* handle, mbtk_oos_info *oos))dlsym(dlHandle_mbtk, "mbtk_oos_set");
|
| 602 | if (mbtk_oos_set == NULL)
|
| 603 | {
|
| 604 | LOGE("mbtk_oos_set dlsym fail\n");
|
| 605 | return GSW_HAL_FAIL;
|
| 606 | }
|
| 607 |
|
| 608 | return GSW_HAL_SUCCESS;
|
| 609 | }
|
| 610 |
|
| 611 | void list_first(list_node_t *list)
|
| 612 | {
|
| 613 | if (list) {
|
| 614 | list->cur_index = 0;
|
| 615 | list->cur_array_data = list->array_data.next;
|
| 616 | }
|
| 617 | }
|
| 618 |
|
| 619 | void* list_next(list_node_t *list)
|
| 620 | {
|
| 621 | if (list) {
|
| 622 | list_arraynode_t *node = list->cur_array_data;
|
| 623 | if (node) {
|
| 624 | LOGE("node is not null\n");
|
| 625 | list->cur_array_data = list->cur_array_data->next;
|
| 626 | list->cur_index++;
|
| 627 | return node->data;
|
| 628 | } else {
|
| 629 | LOGE("node is null\n");
|
| 630 | return NULL;
|
| 631 | }
|
| 632 | } else {
|
| 633 | LOGE("list is null\n");
|
| 634 | return NULL;
|
| 635 | }
|
| 636 | }
|
| 637 |
|
| 638 | void list_free(list_node_t *list)
|
| 639 | {
|
| 640 | if (list) {
|
| 641 | list_arraynode_t *node = &(list->array_data); // Head node
|
| 642 | list_arraynode_t *node_temp = NULL;
|
| 643 | while (node->next) {
|
| 644 | node_temp = node->next;
|
| 645 | node->next = node->next->next;
|
| 646 |
|
| 647 | if (list->free_func) {
|
| 648 | list->free_func(node_temp->data);
|
| 649 | } else {
|
| 650 | free(node_temp->data);
|
| 651 | }
|
| 652 | free(node_temp);
|
| 653 | }
|
| 654 | free(list);
|
| 655 | }
|
| 656 | }
|
| 657 |
|
| 658 | static int gsw_rssi_to_csq(int rssi)
|
| 659 | {
|
| 660 | LOGD("rssi = %d\n",rssi);
|
| 661 | if(rssi >= -113 && rssi <= -51)
|
| 662 | {
|
| 663 | return (rssi + 113) / 2;
|
| 664 | }
|
| 665 |
|
| 666 | else
|
| 667 | {
|
| 668 | return 99;
|
| 669 | }
|
| 670 | }
|
| 671 |
|
| 672 | static int gsw_rscp_to_csq(int rscp)
|
| 673 | {
|
| 674 | LOGD("rscp = %d\n",rscp);
|
| 675 | if(rscp <= -25 && rscp > -120)
|
| 676 | {
|
| 677 | return rscp + 120;
|
| 678 | }
|
| 679 | else
|
| 680 | {
|
| 681 | return 255;
|
| 682 | }
|
| 683 |
|
| 684 | }
|
| 685 |
|
| 686 | static int gsw_rsrp_to_csq(int rsrp)
|
| 687 | {
|
| 688 | LOGD("rsrp = %d\n",rsrp);
|
| 689 |
|
| 690 | if(rsrp <= -44 && rsrp > -140)
|
| 691 | {
|
| 692 | return rsrp + 140;
|
| 693 | }
|
| 694 |
|
| 695 | else
|
| 696 | {
|
| 697 | return 255;
|
| 698 | }
|
| 699 | }
|
| 700 |
|
| 701 | static int rscp_convert_to_dBm(int rscp)
|
| 702 | {
|
| 703 | if(rscp <= 96 && rscp >= 0)
|
| 704 | {
|
| 705 | return rscp - 120;
|
| 706 | }
|
| 707 | else
|
| 708 | {
|
| 709 | return -25;
|
| 710 | }
|
| 711 | }
|
| 712 |
|
| 713 |
|
| 714 | static int8_t rssi_convert_to_dBm(uint8 rssi)
|
| 715 | {
|
| 716 | if(rssi <= 31)
|
| 717 | {
|
| 718 | return rssi * 2 - 113;
|
| 719 | }
|
| 720 | else
|
| 721 | {
|
| 722 | return -125;
|
| 723 | }
|
| 724 | }
|
| 725 |
|
| 726 | static int16_t rsrp_convert_to_dBm(uint8 rsrp)
|
| 727 | {
|
| 728 | if(rsrp <= 96)
|
| 729 | {
|
| 730 | return rsrp - 140;
|
| 731 | }
|
| 732 | else
|
| 733 | {
|
| 734 | return -44;
|
| 735 | }
|
| 736 | }
|
| 737 |
|
| 738 | static int16_t rsrq_convert_to_dB(uint8 rsrq)
|
| 739 | {
|
| 740 | if(rsrq >= 1 && rsrq <= 34)
|
| 741 | {
|
| 742 | return (rsrq + 1) / 2 - 20;
|
| 743 | }
|
| 744 | else
|
| 745 | {
|
| 746 | return -20;
|
| 747 | }
|
| 748 | }
|
| 749 |
|
| 750 | static int16_t ecno_convert_to_dB(uint8 ecno)
|
| 751 | {
|
| 752 | if(ecno >= 48)
|
| 753 | {
|
| 754 | return 0;
|
| 755 | }
|
| 756 | else if(ecno == 255)
|
| 757 | {
|
| 758 | return 255;
|
| 759 | }
|
| 760 | else
|
| 761 | {
|
| 762 | return 48 - ecno;
|
| 763 | }
|
| 764 | }
|
| 765 |
|
| 766 |
|
| 767 | static int convert_reg_state(int reg_state_t)
|
| 768 | {
|
| 769 | LOGD("reg_state_t = %d\n",reg_state_t);
|
| 770 | int reg_state = 0;
|
| 771 |
|
| 772 | switch (reg_state_t)
|
| 773 | {
|
| 774 | case MBTK_NET_REG_STATE_NON:
|
| 775 | {
|
| 776 | reg_state = GSW_NETWORK_REG_NOT_REGISTERED;
|
| 777 | break;
|
| 778 | }
|
| 779 | case MBTK_NET_REG_STATE_HOME:
|
| 780 | {
|
| 781 | reg_state = GSW_NETWORK_REG_REGISTERED;
|
| 782 | break;
|
| 783 | }
|
| 784 | case MBTK_NET_REG_STATE_SEARCHING:
|
| 785 | {
|
| 786 | reg_state = GSW_NETWORK_REG_NOT_REGISTERED_SEARCHING;
|
| 787 | break;
|
| 788 | }
|
| 789 | case MBTK_NET_REG_STATE_DENIED:
|
| 790 | {
|
| 791 | reg_state = GSW_NETWORK_REG_REGISTRATION_DENIED;
|
| 792 | break;
|
| 793 | }
|
| 794 | case MBTK_NET_REG_STATE_UNKNOWN:
|
| 795 | {
|
| 796 | reg_state = GSW_NETWORK_REG_REGISTRATION_UNKNOWN;
|
| 797 | break;
|
| 798 | }
|
| 799 | case MBTK_NET_REG_STATE_ROAMING:
|
| 800 | {
|
| 801 | reg_state = GSW_NETWORK_REG_REGISTRATION_ROAMING;
|
| 802 | break;
|
| 803 | }
|
| 804 | case MBTK_NET_REG_STATE_SMS_ONLY:
|
| 805 | case MBTK_NET_REG_STATE_ROAMING_SMS:
|
| 806 | case MBTK_NET_REG_STATE_ATTACHED_EMERGENCY:
|
| 807 | case MBTK_NET_REG_STATE_CSFB_HOME:
|
| 808 | case MBTK_NET_REG_STATE_CSFB_ROAMING:
|
| 809 | case MBTK_NET_REG_STATE_EMERGENCY_ONLY:
|
| 810 | {
|
| 811 | reg_state = GSW_NETWORK_REG_LIMITED_SERVICE;
|
| 812 | break;
|
| 813 | }
|
| 814 | }
|
| 815 |
|
| 816 | return reg_state;
|
| 817 | }
|
| 818 |
|
| 819 |
|
| 820 | static int convert_net_mode(int net_mode)
|
| 821 | {
|
| 822 | LOGD("net_mode = %d\n",net_mode);
|
| 823 | switch(net_mode)
|
| 824 | {
|
| 825 | case MBTK_RADIO_TECH_GSM:
|
| 826 | case MBTK_RADIO_TECH_GSM_COMPACT:
|
| 827 | case MBTK_RADIO_TECH_GSM_EGPRS:
|
| 828 | {
|
| 829 | return GSW_NETWORK_RADIO_GSM;
|
| 830 | }
|
| 831 | case MBTK_RADIO_TECH_UTRAN:
|
| 832 | case MBTK_RADIO_TECH_UTRAN_HSDPA:
|
| 833 | case MBTK_RADIO_TECH_UTRAN_HSUPA:
|
| 834 | case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
|
| 835 | case MBTK_RADIO_TECH_UTRAN_HSPA:
|
| 836 | {
|
| 837 | return GSW_NETWORK_RADIO_UMTS;
|
| 838 | }
|
| 839 | case MBTK_RADIO_TECH_E_UTRAN:
|
| 840 | {
|
| 841 | return GSW_NETWORK_RADIO_LTE;
|
| 842 | }
|
| 843 |
|
| 844 | default:
|
| 845 | {
|
| 846 | return GSW_NETWORK_RADIO_NO_SVC;
|
| 847 | }
|
| 848 | }
|
| 849 |
|
| 850 | return GSW_NETWORK_RADIO_NO_SVC;
|
| 851 | }
|
| 852 |
|
| 853 | static int convert_mbtk_net_config(int config)
|
| 854 | {
|
| 855 | int net_pref = -1;
|
| 856 |
|
| 857 | switch(config)
|
| 858 | {
|
| 859 | case GSW_PREFER_MODE_GSW:
|
| 860 | {
|
| 861 | net_pref = 0;
|
| 862 | break;
|
| 863 | }
|
| 864 |
|
| 865 | case GSW_PREFER_MODE_WCDMA:
|
| 866 | {
|
| 867 | net_pref = 1;
|
| 868 | break;
|
| 869 | }
|
| 870 |
|
| 871 | case GSW_PREFER_MODE_WCDMA_GSM:
|
| 872 | {
|
| 873 | net_pref = 2;
|
| 874 | break;
|
| 875 | }
|
| 876 |
|
| 877 | case GSW_PREFER_MODE_LTE:
|
| 878 | case GSW_PREFER_MODE_NR5G:
|
| 879 | case GSW_PREFER_MODE_NR5G_LTE:
|
| 880 | {
|
| 881 | net_pref = 5;
|
| 882 | break;
|
| 883 | }
|
| 884 |
|
| 885 | case GSW_PREFER_MODE_LTE_WCDMA_GSM:
|
| 886 | case GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM:
|
| 887 | {
|
| 888 | net_pref = 15;
|
| 889 | break;
|
| 890 | }
|
| 891 | }
|
| 892 |
|
| 893 | return net_pref;
|
| 894 | }
|
| 895 |
|
| 896 |
|
| 897 | static int convert_gsw_net_config(int config)
|
| 898 | {
|
| 899 | int net_config = -1;
|
| 900 | LOGD("config = %d\n");
|
| 901 |
|
| 902 | switch (config)
|
| 903 | {
|
| 904 | case 0:
|
| 905 | {
|
| 906 | net_config = GSW_PREFER_MODE_GSW;
|
| 907 | break;
|
| 908 | }
|
| 909 |
|
| 910 | case 1:
|
| 911 | {
|
| 912 | net_config = GSW_PREFER_MODE_WCDMA;
|
| 913 | break;
|
| 914 | }
|
| 915 |
|
| 916 | case 2:
|
| 917 | {
|
| 918 | net_config = GSW_PREFER_MODE_WCDMA_GSM;
|
| 919 | break;
|
| 920 | }
|
| 921 |
|
| 922 | case 5:
|
| 923 | {
|
| 924 | net_config = GSW_PREFER_MODE_LTE;
|
| 925 | break;
|
| 926 | }
|
| 927 |
|
| 928 | case 15:
|
| 929 | {
|
| 930 | net_config = GSW_PREFER_MODE_LTE_WCDMA_GSM;
|
| 931 | break;
|
| 932 | }
|
| 933 | }
|
| 934 |
|
| 935 | return net_config;
|
| 936 | }
|
| 937 |
|
| 938 | //64F010 -> 46001 (64->46,F0->0,10->01)
|
| 939 | static void transform_fplmn_str_to_plmn(char *entry)
|
| 940 | {
|
| 941 | if (strncmp(entry, "FFFFFF", ENTRY_LENGTH) == 0) {
|
| 942 | return; //if FFFFFF,means invalid fplmn, do nothing
|
| 943 | }
|
| 944 |
|
| 945 | char temp = entry[0];
|
| 946 | entry[0] = entry[1];
|
| 947 | entry[1] = temp;
|
| 948 |
|
| 949 | temp = entry[ENTRY_LENGTH - 2];
|
| 950 | entry[ENTRY_LENGTH - 2] = entry[ENTRY_LENGTH - 1];
|
| 951 | entry[ENTRY_LENGTH - 1] = temp;
|
| 952 |
|
| 953 | memmove(entry + 2, entry + 3, ENTRY_LENGTH - 2);
|
| 954 |
|
| 955 | LOGE("after transform_fplmn_str_to_plmn: %s\n", entry);
|
| 956 |
|
| 957 | //valid fplmn
|
| 958 | fplmn_index++;
|
| 959 | }
|
| 960 |
|
| 961 | static void extract_mcc_mnc(char *entry, char *mcc, char *mnc)
|
| 962 | {
|
| 963 | strncpy(mcc,entry,3);
|
| 964 | mcc[3] = '\0';
|
| 965 | strncpy(mnc,entry + 3,2);
|
| 966 | mnc[2] = '\0';
|
| 967 |
|
| 968 | LOGE("entry = %s, mcc = %s, mnc = %s\n", entry, mcc, mnc);
|
| 969 | }
|
| 970 |
|
| 971 |
|
| 972 | static void update_fplmn_list(char *fplmn_str)
|
| 973 | {
|
| 974 | LOGE("fplmn_str = %s\n",fplmn_str);
|
| 975 | char temp_fplmn_array[FPLMN_ARRAY_SIZE][7];
|
| 976 | memset(fplmn_array, 0, sizeof(fplmn_array));
|
| 977 | memset(temp_fplmn_array, 0, sizeof(temp_fplmn_array));
|
| 978 | fplmn_index = 0;
|
| 979 | int array_length = 0;
|
| 980 |
|
| 981 | for (int i = 0; i < strlen(fplmn_str); i += 6) {
|
| 982 |
|
| 983 | int length = (i + 6 < strlen(fplmn_str)) ? 6 : strlen(fplmn_str) - i;
|
| 984 | strncpy(temp_fplmn_array[array_length], fplmn_str + i, length);
|
| 985 | temp_fplmn_array[array_length][length] = '\0';
|
| 986 | array_length++;
|
| 987 | if (i + 6 >= strlen(fplmn_str)) {
|
| 988 | break;
|
| 989 | }
|
| 990 | }
|
| 991 |
|
| 992 | for (int i = 0; i < array_length; i++) {
|
| 993 | LOGE("array[%d] = %s\n", i, temp_fplmn_array[i]);
|
| 994 | transform_fplmn_str_to_plmn(temp_fplmn_array[i]);
|
| 995 | strncpy(fplmn_array[i], temp_fplmn_array[i], ENTRY_LENGTH);
|
| 996 | LOGE("fplmn_array[%d] = %s\n", i, fplmn_array[i]);
|
| 997 | }
|
| 998 |
|
| 999 | }
|
| 1000 |
|
| 1001 | static void format_plmn(char *result, char *plmn_entry)
|
| 1002 | {
|
| 1003 | strncpy(result, plmn_entry, strlen(plmn_entry));
|
| 1004 | LOGE("result = %s, numStr = %s\n",result, plmn_entry);
|
| 1005 |
|
| 1006 | if (strlen(result) >= 2) {
|
| 1007 | char temp = result[0];
|
| 1008 | result[0] = result[1];
|
| 1009 | result[1] = temp;
|
| 1010 | }
|
| 1011 |
|
| 1012 | LOGE("1.result = %s\n",result);
|
| 1013 |
|
| 1014 | if (strlen(result) >= 3) {
|
| 1015 | memmove(&result[3], &result[2], strlen(result) - 2 + 1);
|
| 1016 | result[2] = 'F';
|
| 1017 | }
|
| 1018 |
|
| 1019 | LOGE("2.result = %s\n",result);
|
| 1020 |
|
| 1021 | if (strlen(result) >= 2) {
|
| 1022 | char temp = result[strlen(result) - 1];
|
| 1023 | result[strlen(result) - 1] = result[strlen(result) - 2];
|
| 1024 | result[strlen(result) - 2] = temp;
|
| 1025 | }
|
| 1026 |
|
| 1027 | LOGE("3.result = %s\n",result);
|
| 1028 | }
|
| 1029 |
|
| 1030 |
|
| 1031 | static void convert_plmn_to_fplmn_str(char *fplmn_str)
|
| 1032 | {
|
| 1033 | char temp_fplmn_str[128] = {0};
|
| 1034 | char temp[20]; // 临时存储单个格式化后的数字
|
| 1035 | int index = 0;
|
| 1036 |
|
| 1037 | for (int i = 0; i < fplmn_index; i++) {
|
| 1038 | memset(temp, 0x0, sizeof(temp));
|
| 1039 | format_plmn(temp, fplmn_array[i]);
|
| 1040 | strcat(temp_fplmn_str, temp);
|
| 1041 | index += strlen(temp);
|
| 1042 | }
|
| 1043 |
|
| 1044 | while(index < (6 * fplmn_max_length))
|
| 1045 | {
|
| 1046 | temp_fplmn_str[index++] = 'F';
|
| 1047 | }
|
| 1048 |
|
| 1049 | // 修剪或截断formattedNumbers,确保它不超过6 * fplmn_max_length个字符
|
| 1050 | if (index > (6 * fplmn_max_length)) {
|
| 1051 | temp_fplmn_str[(6 * fplmn_max_length)] = '\0';
|
| 1052 | }
|
| 1053 |
|
| 1054 | LOGE("%s\n", temp_fplmn_str);
|
| 1055 | strncpy(fplmn_str, temp_fplmn_str, strlen(temp_fplmn_str));
|
| 1056 | LOGE("fplmn_str = %s\n", fplmn_str);
|
| 1057 | }
|
| 1058 |
|
| 1059 | static int check_index(char *mcc, char *mnc)
|
| 1060 | {
|
| 1061 | int i = 0;
|
| 1062 |
|
| 1063 | for(i = 0; i < fplmn_index; i++)
|
| 1064 | {
|
| 1065 | if(strncmp(fplmn_array[i], mcc, 3) == 0 && strncmp(fplmn_array[i] + 3, mnc, 2) == 0)
|
| 1066 | {
|
| 1067 | LOGE("index = %d\n", i);
|
| 1068 | return i;
|
| 1069 | }
|
| 1070 | }
|
| 1071 |
|
| 1072 | LOGE("not find\n");
|
| 1073 | return -1;
|
| 1074 | }
|
| 1075 |
|
| 1076 | static void remove_fplmn(int index)
|
| 1077 | {
|
| 1078 | int write_index = 0;
|
| 1079 | for (int i = 0; i < fplmn_index; i++) {
|
| 1080 | if (i != index) {
|
| 1081 | strncpy(fplmn_array[write_index++], fplmn_array[i], ENTRY_LENGTH);
|
| 1082 | }
|
| 1083 | }
|
| 1084 | fplmn_index--;
|
| 1085 | }
|
| 1086 |
|
| 1087 | static void gsw_serving_info_callback_thread()
|
| 1088 | {
|
| 1089 | GSW_NW_SERVING_INFO *serving_info = (GSW_NW_SERVING_INFO*)malloc(sizeof(GSW_NW_SERVING_INFO));
|
| 1090 | memset(serving_info, 0x0, sizeof(GSW_NW_SERVING_INFO));
|
| 1091 | int ret = -1;
|
| 1092 | ret = gsw_get_nwinfo(serving_info);
|
| 1093 | if(ret != 0)
|
| 1094 | {
|
| 1095 | LOGE("gsw_get_nwinfo failed\n");
|
| 1096 | free(serving_info);
|
| 1097 | return;
|
| 1098 | }
|
| 1099 |
|
| 1100 | if(serving_cb)
|
| 1101 | {
|
| 1102 | serving_cb(*serving_info);
|
| 1103 | free(serving_info);
|
| 1104 | }
|
| 1105 | }
|
| 1106 |
|
| 1107 | static void gsw_serving_info_callback(const void* data, int data_len)
|
| 1108 | {
|
| 1109 | LOGE("gsw_serving_info_callback start\n");
|
| 1110 |
|
| 1111 | if(data && data_len > 0)
|
| 1112 | {
|
| 1113 | pthread_t thread;
|
| 1114 | pthread_create(&thread, NULL, (void*)gsw_serving_info_callback_thread, NULL);
|
| 1115 | }
|
| 1116 |
|
| 1117 | else
|
| 1118 | {
|
| 1119 | LOGE("data is NULL\n");
|
| 1120 | return;
|
| 1121 | }
|
| 1122 |
|
| 1123 | }
|
| 1124 |
|
| 1125 | static void gsw_sig_info_callback(const void* data, int data_len)
|
| 1126 | {
|
| 1127 | LOGE("gsw_sig_info_callback start\n");
|
| 1128 |
|
| 1129 | if(data && data_len == 8)
|
| 1130 | {
|
| 1131 | uint8 *net_data = (uint8*)data;
|
| 1132 | mbtk_radio_technology_enum type = (mbtk_radio_technology_enum)net_data[0];
|
| 1133 |
|
| 1134 | signalStrength_t sig_strength;
|
| 1135 | memset(&sig_strength, 0x0, sizeof(signalStrength_t));
|
| 1136 |
|
| 1137 | sig_strength.gw_sig_valid = 0;
|
| 1138 | sig_strength.wcdma_sig_valid = 0;
|
| 1139 | sig_strength.lte_sig_valid = 0;
|
| 1140 | sig_strength.nr_sig_valid = 0;
|
| 1141 |
|
| 1142 | if(type == MBTK_RADIO_TECH_GSM || type == MBTK_RADIO_TECH_GSM_COMPACT || \
|
| 1143 | type == MBTK_RADIO_TECH_GSM_EGPRS) //GSM
|
| 1144 | {
|
| 1145 | sig_strength.gw_sig_valid = 1;
|
| 1146 | sig_strength.rssi = rssi_convert_to_dBm(net_data[1]);
|
| 1147 | }
|
| 1148 |
|
| 1149 | else if(type == MBTK_RADIO_TECH_E_UTRAN)
|
| 1150 | {
|
| 1151 | sig_strength.lte_sig_valid = 1;
|
| 1152 | sig_strength.rsrp = rsrp_convert_to_dBm(net_data[7]);
|
| 1153 | sig_strength.rsrq = rsrq_convert_to_dB(net_data[6]);
|
| 1154 | sig_strength.rssnr = -99;
|
| 1155 | }
|
| 1156 |
|
| 1157 | else if (type == MBTK_RADIO_TECH_UTRAN || type == MBTK_RADIO_TECH_UTRAN_HSDPA || \
|
| 1158 | type == MBTK_RADIO_TECH_UTRAN_HSUPA || type == MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA || \
|
| 1159 | type == MBTK_RADIO_TECH_UTRAN_HSPA )//WCDMA
|
| 1160 | {
|
| 1161 | sig_strength.wcdma_sig_valid = 1;
|
| 1162 | sig_strength.rscp = rssi_convert_to_dBm(net_data[1]);
|
| 1163 | sig_strength.ecno = ecno_convert_to_dB(net_data[5]);
|
| 1164 | }
|
| 1165 |
|
| 1166 | if(sig_cb != NULL)
|
| 1167 | {
|
| 1168 | sig_cb(sig_strength);
|
| 1169 | }
|
| 1170 | }
|
| 1171 |
|
| 1172 | else
|
| 1173 | {
|
| 1174 | LOGE("data is NULL\n");
|
| 1175 | }
|
| 1176 | }
|
| 1177 |
|
| 1178 | static void gsw_modem_status_event_callback(const void* data, int data_len)
|
| 1179 | {
|
| 1180 | LOGE("gsw_modem_status_event_callback start\n");
|
| 1181 |
|
| 1182 | gsw_mode_state_e state = GSW_MODEM_STATE_UNKNOWN;
|
| 1183 |
|
| 1184 | if(data && data_len > 0)
|
| 1185 | {
|
| 1186 | uint8 *net_data = (uint8*)data;
|
| 1187 | LOGE("gsw_modem_status_event_callback,data = %d\n", *net_data);
|
| 1188 | if(*net_data == 1)
|
| 1189 | {
|
| 1190 | state = GSW_MODEM_STATE_ONLINE;
|
| 1191 | }
|
| 1192 | else if(*net_data == 0)
|
| 1193 | {
|
| 1194 | state = GSW_MODEM_STATE_OFFLINE;
|
| 1195 | }
|
| 1196 |
|
| 1197 | if(modem_cb != NULL)
|
| 1198 | {
|
| 1199 | modem_cb(state);
|
| 1200 | }
|
| 1201 | }
|
| 1202 |
|
| 1203 | }
|
| 1204 |
|
| 1205 | static void gsw_reject_callback(GSW_NW_RADIO_ACCESS_TECH_E rat, GSW_SERVICE_DOMAIN_E domain, int cause)
|
| 1206 | {
|
| 1207 | LOGE("gsw_reject_callback start,rat = %d,domain = %d,cause = %d\n",rat,domain,cause);
|
| 1208 |
|
| 1209 | GSW_NW_REJ_CAUSE_E *rej_cause = (GSW_NW_REJ_CAUSE_E*)malloc(sizeof(GSW_NW_REJ_CAUSE_E));
|
| 1210 | memset(rej_cause, 0x0, sizeof(GSW_NW_REJ_CAUSE_E));
|
| 1211 |
|
| 1212 | rej_cause->rej_cause = cause;
|
| 1213 | rej_cause->rej_rat = rat;
|
| 1214 | rej_cause->rej_domain = domain;
|
| 1215 |
|
| 1216 | if(reject_cb != NULL)
|
| 1217 | {
|
| 1218 | LOGE("reject_cb is not NULL\n");
|
| 1219 | reject_cb(rej_cause);
|
| 1220 | }
|
| 1221 | else
|
| 1222 | {
|
| 1223 | LOGE("reject_cb is NULL\n");
|
| 1224 | }
|
| 1225 |
|
| 1226 | free(rej_cause);
|
| 1227 | LOGE("gsw_reject_callback end\n");
|
| 1228 | }
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 | /**
|
| 1233 | * @brief SDK interface to call back serving info
|
| 1234 | * @param [in] handle_ptr
|
| 1235 | * @retval 0: success
|
| 1236 | * @retval other: fail
|
| 1237 | */
|
| 1238 | int gsw_reg_serving_info_callback(GSW_NW_ServingInfoHandlePtr handle_ptr)
|
| 1239 | {
|
| 1240 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1241 | {
|
| 1242 | return GSW_HAL_FAIL;
|
| 1243 | }
|
| 1244 |
|
| 1245 | if(handle_ptr == NULL)
|
| 1246 | {
|
| 1247 | LOGE("handle_ptr is NULL\n");
|
| 1248 | return GSW_HAL_FAIL;
|
| 1249 | }
|
| 1250 |
|
| 1251 | serving_cb = handle_ptr;
|
| 1252 |
|
| 1253 | return GSW_HAL_SUCCESS;
|
| 1254 |
|
| 1255 | }
|
| 1256 |
|
| 1257 |
|
| 1258 | /**
|
| 1259 | * @brief SDK interface to call back sig info
|
| 1260 | * @param [in] handle_ptr
|
| 1261 | * @retval 0: success
|
| 1262 | * @retval other: fail
|
| 1263 | */
|
| 1264 | int gsw_reg_sig_info_callback(GSW_NW_SigInfoHandlePtr handle_ptr)
|
| 1265 | {
|
| 1266 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1267 | {
|
| 1268 | return GSW_HAL_FAIL;
|
| 1269 | }
|
| 1270 |
|
| 1271 | if(handle_ptr == NULL)
|
| 1272 | {
|
| 1273 | LOGE("handle_ptr is NULL\n");
|
| 1274 | return GSW_HAL_FAIL;
|
| 1275 | }
|
| 1276 |
|
| 1277 | sig_cb = handle_ptr;
|
| 1278 |
|
| 1279 | return GSW_HAL_SUCCESS;
|
| 1280 |
|
| 1281 | }
|
| 1282 |
|
| 1283 |
|
| 1284 | /**
|
| 1285 | * @brief SDK interface to call back rej cause
|
| 1286 | * @param [in] handle_ptr
|
| 1287 | * @retval 0: success
|
| 1288 | * @retval other: fail
|
| 1289 | */
|
| 1290 | int gsw_reg_rej_cause_callback(GSW_NW_RejectCauseHandlePtr handle_ptr)
|
| 1291 | {
|
| 1292 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1293 | {
|
| 1294 | return GSW_HAL_FAIL;
|
| 1295 | }
|
| 1296 |
|
| 1297 | if(handle_ptr == NULL)
|
| 1298 | {
|
| 1299 | LOGE("handle_ptr is NULL\n");
|
| 1300 | return GSW_HAL_FAIL;
|
| 1301 | }
|
| 1302 |
|
| 1303 | reject_cb = handle_ptr;
|
| 1304 |
|
| 1305 | return GSW_HAL_SUCCESS;
|
| 1306 | }
|
| 1307 |
|
| 1308 |
|
| 1309 | /**
|
| 1310 | * @brief network sdk init
|
| 1311 | * @param [in] token usr id define by who use
|
| 1312 | * @retval 0: success
|
| 1313 | * @retval other: fail
|
| 1314 | */
|
| 1315 | int gsw_nw_sdk_init(int token)
|
| 1316 | {
|
| 1317 | int ret = -1;
|
| 1318 |
|
| 1319 | if (nw_init_flag == 1 && nw_info_handle != NULL)
|
| 1320 | {
|
| 1321 | return GSW_HAL_SUCCESS;
|
| 1322 | }
|
| 1323 |
|
| 1324 | ret = mbtk_nw_api_import();
|
| 1325 | if (ret != 0)
|
| 1326 | {
|
| 1327 | LOGE("mbtk_nw_api_import fail\n");
|
| 1328 | return GSW_HAL_FAIL;
|
| 1329 | }
|
| 1330 |
|
| 1331 | nw_info_handle = mbtk_info_handle_get();
|
| 1332 |
|
| 1333 | if (nw_info_handle == NULL)
|
| 1334 | {
|
| 1335 | LOGE("mbtk_info_handle_get fail\n");
|
| 1336 | return GSW_HAL_FAIL;
|
| 1337 | }
|
| 1338 |
|
| 1339 | char fplmn[256] = {0};
|
| 1340 | ret = mbtk_fplmn_get(nw_info_handle, fplmn);
|
| 1341 | if(ret != 0)
|
| 1342 | {
|
| 1343 | LOGE("mbtk_fplmn_get failed : %d\n",ret);
|
| 1344 | return GSW_HAL_FAIL;
|
| 1345 | }
|
| 1346 | fplmn_max_length = (strlen(fplmn)/6);
|
| 1347 | LOGE("fplmn = %s, fplmn_max_length = %d\n",fplmn,fplmn_max_length);
|
| 1348 | ret = mbtk_signal_state_change_cb_reg(nw_info_handle, gsw_sig_info_callback);
|
| 1349 |
|
| 1350 | if (ret != 0)
|
| 1351 | {
|
| 1352 | LOGE("mbtk_signal_state_change_cb_reg fail\n");
|
| 1353 | return GSW_HAL_FAIL;
|
| 1354 | }
|
| 1355 |
|
| 1356 | ret = mbtk_net_state_change_cb_reg(nw_info_handle, gsw_serving_info_callback);
|
| 1357 | if (ret != 0)
|
| 1358 | {
|
| 1359 | LOGE("mbtk_net_state_change_cb_reg fail\n");
|
| 1360 | return GSW_HAL_FAIL;
|
| 1361 | }
|
| 1362 |
|
| 1363 | nw_init_flag = 1;
|
| 1364 |
|
| 1365 | return GSW_HAL_SUCCESS;
|
| 1366 | }
|
| 1367 |
|
| 1368 |
|
| 1369 | /**
|
| 1370 | * @brief network sdk deinit
|
| 1371 | * @param
|
| 1372 | * @retval 0: success
|
| 1373 | * @retval other: fail
|
| 1374 | */
|
| 1375 | int gsw_nw_sdk_deinit(void)
|
| 1376 | {
|
| 1377 | int ret = -1;
|
| 1378 |
|
| 1379 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1380 | {
|
| 1381 | return GSW_HAL_FAIL;
|
| 1382 | }
|
| 1383 |
|
| 1384 | ret = mbtk_info_handle_free(&nw_info_handle);
|
| 1385 | if(ret != GSW_HAL_SUCCESS)
|
| 1386 | {
|
| 1387 | LOGE("mbtk_info_handle_free fail\n");
|
| 1388 | return GSW_HAL_FAIL;
|
| 1389 | }
|
| 1390 |
|
| 1391 | dlclose(dlHandle_mbtk);
|
| 1392 | nw_info_handle = NULL;
|
| 1393 | nw_init_flag = 0;
|
| 1394 |
|
| 1395 | return GSW_HAL_SUCCESS;
|
| 1396 |
|
| 1397 | }
|
| 1398 |
|
| 1399 |
|
| 1400 | /**
|
| 1401 | * @brief get current network reg info
|
| 1402 | * @param [out] serving_info struct for network info
|
| 1403 | * include regstate ps_state opreator name mcc mcn etc
|
| 1404 | * @retval 0: success
|
| 1405 | * @retval other: fail
|
| 1406 | */
|
| 1407 | int gsw_get_nwinfo(GSW_NW_SERVING_INFO *serving_info)
|
| 1408 | {
|
| 1409 |
|
| 1410 | int ret = -1;
|
| 1411 | LOGE("gsw_get_nwinfo start\n");
|
| 1412 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1413 | {
|
| 1414 | LOGE("nw_sdk_deinit not init\n");
|
| 1415 | return GSW_HAL_FAIL;
|
| 1416 | }
|
| 1417 |
|
| 1418 | LOGE("mbtk_net_reg_get start \n");
|
| 1419 | //regstate
|
| 1420 | mbtk_net_reg_info_t reg;
|
| 1421 | memset(®, 0x0, sizeof(mbtk_net_reg_info_t));
|
| 1422 | ret = mbtk_net_reg_get(nw_info_handle, ®);
|
| 1423 | if(ret)
|
| 1424 | {
|
| 1425 | LOGE("mbtk_net_reg_get fail\n");
|
| 1426 | return GSW_HAL_FAIL;
|
| 1427 | }
|
| 1428 |
|
| 1429 | LOGE("convert_cs_reg_state\n");
|
| 1430 | //cs_state
|
| 1431 | serving_info->reg_state = convert_reg_state(reg.call_state);
|
| 1432 | LOGE("convert_ps_reg_state\n");
|
| 1433 | //ps_state
|
| 1434 | serving_info->ps_state = convert_reg_state(reg.data_state);
|
| 1435 | LOGE("convert_rat_mode\n");
|
| 1436 | //reg_rat
|
| 1437 | serving_info->reg_rat = convert_net_mode(reg.type);
|
| 1438 | //srv_domain
|
| 1439 | if(serving_info->reg_state == GSW_NETWORK_REG_REGISTERED || serving_info->reg_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
|
| 1440 | {
|
| 1441 | if(serving_info->ps_state == GSW_NETWORK_REG_REGISTERED || serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
|
| 1442 | {
|
| 1443 | serving_info->srv_domain = GSW_SRV_DOMAIN_CS_PS;
|
| 1444 | }
|
| 1445 |
|
| 1446 | else
|
| 1447 | {
|
| 1448 | serving_info->srv_domain = GSW_SRV_DOMAIN_CS_ONLY;
|
| 1449 | }
|
| 1450 | }
|
| 1451 |
|
| 1452 | else if (serving_info->ps_state == GSW_NETWORK_REG_REGISTERED || serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
|
| 1453 | {
|
| 1454 | serving_info->srv_domain = GSW_SRV_DOMAIN_PS_ONLY;
|
| 1455 | }
|
| 1456 |
|
| 1457 | else
|
| 1458 | {
|
| 1459 | serving_info->srv_domain = GSW_SRV_DOMAIN_NO_SVC;
|
| 1460 | //if ps and cs is both not registed, reg_rat seted to GSW_NETWORK_RADIO_NO_SVC
|
| 1461 | serving_info->reg_rat = GSW_NETWORK_RADIO_NO_SVC;
|
| 1462 | }
|
| 1463 |
|
| 1464 | LOGD("roaming_ind\n");
|
| 1465 | //roaming_ind
|
| 1466 | if(serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_ROAMING)
|
| 1467 | {
|
| 1468 | serving_info->roaming_ind = GSW_NETWORK_ROAMING_ON;
|
| 1469 | }
|
| 1470 | else
|
| 1471 | {
|
| 1472 | serving_info->roaming_ind = GSW_NETWORK_ROAMING_OFF;
|
| 1473 | }
|
| 1474 |
|
| 1475 | LOGD("reject\n");
|
| 1476 | //reject
|
| 1477 | if(serving_info->ps_state == GSW_NETWORK_REG_REGISTRATION_DENIED || serving_info->reg_state == GSW_NETWORK_REG_REGISTRATION_DENIED)
|
| 1478 | {
|
| 1479 | LOGD("reject_callback\n");
|
| 1480 | gsw_reject_callback(serving_info->reg_rat,serving_info->srv_domain,99);
|
| 1481 | }
|
| 1482 |
|
| 1483 | LOGD("reg_plmn / operator name\n");
|
| 1484 | //reg_plmn / operator name
|
| 1485 | mbtk_net_info_t net;
|
| 1486 | memset(&net, 0x0, sizeof(mbtk_net_info_t));
|
| 1487 | LOGD("mbtk_net_sel_mode_get start \n");
|
| 1488 | ret = mbtk_net_sel_mode_get(nw_info_handle, &net);
|
| 1489 | LOGD("mbtk_net_sel_mode_get end \n");
|
| 1490 | if(ret == 0 && net.plmn > 0)
|
| 1491 | {
|
| 1492 | int i = 0;
|
| 1493 |
|
| 1494 | LOGD("start to find mcc");
|
| 1495 | while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))
|
| 1496 | {
|
| 1497 | if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)
|
| 1498 | {
|
| 1499 | LOGD("find mcc\n");
|
| 1500 | break;
|
| 1501 | }
|
| 1502 | i++;
|
| 1503 | }
|
| 1504 |
|
| 1505 |
|
| 1506 | if(i == ARRAY_SIZE(lynq_operator_mcc_mnc))
|
| 1507 | {
|
| 1508 | LOGD("not find mcc");
|
| 1509 | strcpy(serving_info->operator_name, "unknown");
|
| 1510 | sprintf(serving_info->reg_plmn, "%d", net.plmn);
|
| 1511 | }
|
| 1512 |
|
| 1513 | else
|
| 1514 | {
|
| 1515 | LOGD("find mcc\n");
|
| 1516 | strcpy(serving_info->operator_name, lynq_operator_mcc_mnc[i].lynq_operator_l);
|
| 1517 | sprintf(serving_info->reg_plmn, "%d", net.plmn);
|
| 1518 | }
|
| 1519 |
|
| 1520 | LOGE("operator_name = %s\n", serving_info->operator_name);
|
| 1521 | LOGE("reg_plmn = %s\n", serving_info->reg_plmn);
|
| 1522 | }
|
| 1523 |
|
| 1524 |
|
| 1525 | LOGD("get cell id/tac/lac/sid/nid\n");
|
| 1526 | //cell id/tac/lac/sid/nid
|
| 1527 | mbtk_cell_type_enum cell_type;
|
| 1528 | if(serving_info->reg_rat == GSW_NETWORK_RADIO_GSM)
|
| 1529 | {
|
| 1530 | cell_type = MBTK_CELL_TYPE_GSM;
|
| 1531 | }
|
| 1532 | else if(serving_info->reg_rat == GSW_NETWORK_RADIO_UMTS)
|
| 1533 | {
|
| 1534 | cell_type = MBTK_CELL_TYPE_UMTS;
|
| 1535 | }
|
| 1536 | else
|
| 1537 | {
|
| 1538 | cell_type = MBTK_CELL_TYPE_LTE;
|
| 1539 | }
|
| 1540 |
|
| 1541 | list_node_t* cell_list = NULL;
|
| 1542 |
|
| 1543 | LOGD("mbtk_cell_get start\n");
|
| 1544 | ret = mbtk_cell_get(nw_info_handle, &cell_type, &cell_list);
|
| 1545 | if(ret != 0 || cell_list == NULL)
|
| 1546 | {
|
| 1547 | LOGE("mbtk_cell_get fail\n");
|
| 1548 | return GSW_HAL_FAIL;
|
| 1549 | }
|
| 1550 | else
|
| 1551 | {
|
| 1552 | LOGE("mbtk_cell_get end,start to get node\n");
|
| 1553 | list_first(cell_list);
|
| 1554 | LOGE("list_first end\n");
|
| 1555 | mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);
|
| 1556 | if(cell)
|
| 1557 | {
|
| 1558 | LOGE("cell is not null,value2 = %u\n",cell->value2);
|
| 1559 | switch(cell_type)
|
| 1560 | {
|
| 1561 | case MBTK_CELL_TYPE_LTE:
|
| 1562 | {
|
| 1563 | LOGE("is lte\n");
|
| 1564 | //LOGE("LTE : tac=%x, PCI=%x, dlEuarfcn=%x, ulEuarfcn=%x, band=%x\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
|
| 1565 | LOGE("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
|
| 1566 | snprintf(serving_info->tac,sizeof(serving_info->tac),"%d",cell->value1);
|
| 1567 | strcpy(serving_info->lac,"");
|
| 1568 | snprintf(serving_info->cell_id,sizeof(serving_info->cell_id),"%d",cell->value8);
|
| 1569 | break;
|
| 1570 | }
|
| 1571 |
|
| 1572 | case MBTK_CELL_TYPE_GSM:
|
| 1573 | {
|
| 1574 | LOGE("is gsm\n");
|
| 1575 | LOGE("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
|
| 1576 | sprintf(serving_info->lac,"%d",cell->value1);
|
| 1577 | memset(serving_info->tac,0,sizeof(serving_info->tac));
|
| 1578 | sprintf(serving_info->cell_id,"%d",cell->value2);
|
| 1579 | break;
|
| 1580 | }
|
| 1581 | case MBTK_CELL_TYPE_UMTS:
|
| 1582 | {
|
| 1583 | LOGE("is wcdma\n");
|
| 1584 | LOGE("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
|
| 1585 | sprintf(serving_info->lac,"%d",cell->value1);
|
| 1586 | memset(serving_info->tac,0,sizeof(serving_info->tac));
|
| 1587 | sprintf(serving_info->cell_id,"%d",cell->value2);
|
| 1588 | break;
|
| 1589 | }
|
| 1590 |
|
| 1591 | default:
|
| 1592 | break;
|
| 1593 | }
|
| 1594 | }
|
| 1595 | else
|
| 1596 | {
|
| 1597 | LOGE("cell is null\n");
|
| 1598 | }
|
| 1599 | }
|
| 1600 |
|
| 1601 | //not support now
|
| 1602 | serving_info->sid = 0;
|
| 1603 | serving_info->nid = 0;
|
| 1604 |
|
| 1605 | return GSW_HAL_SUCCESS;
|
| 1606 | }
|
| 1607 |
|
| 1608 |
|
| 1609 | /**
|
| 1610 | * @brief get current network type
|
| 1611 | * @param [out] netype as GSW_NW_RADIO_ACCESS_TECH_E type
|
| 1612 | * @retval 0: success
|
| 1613 | * @retval other: fail
|
| 1614 | */
|
| 1615 | int gsw_get_netype(int *netype)
|
| 1616 | {
|
| 1617 | int ret = -1;
|
| 1618 |
|
| 1619 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1620 | {
|
| 1621 | return GSW_HAL_FAIL;
|
| 1622 | }
|
| 1623 |
|
| 1624 | //regstate
|
| 1625 | mbtk_net_reg_info_t reg;
|
| 1626 | ret = mbtk_net_reg_get(nw_info_handle, ®);
|
| 1627 | if(ret)
|
| 1628 | {
|
| 1629 | LOGE("mbtk_net_reg_get fail\n");
|
| 1630 | return GSW_HAL_FAIL;
|
| 1631 | }
|
| 1632 |
|
| 1633 | if(reg.data_state == MBTK_NET_REG_STATE_HOME || reg.data_state == MBTK_NET_REG_STATE_ROAMING)
|
| 1634 | {
|
| 1635 | *netype = convert_net_mode(reg.type);
|
| 1636 | }
|
| 1637 | else
|
| 1638 | {
|
| 1639 | *netype = GSW_NETWORK_RADIO_NO_SVC;
|
| 1640 | }
|
| 1641 |
|
| 1642 | return GSW_HAL_SUCCESS;
|
| 1643 | }
|
| 1644 |
|
| 1645 |
|
| 1646 | /**
|
| 1647 | * @brief get radio opmode, as open and close airplane mode
|
| 1648 | * @param [out] op_mode 1 is radio on, 0 is radio off
|
| 1649 | * @retval 0: success
|
| 1650 | * @retval other: fail
|
| 1651 | */
|
| 1652 | int gsw_get_opmode(int *op_mode)
|
| 1653 | {
|
| 1654 | int tmp_rf = -1;
|
| 1655 | int ret = -1;
|
| 1656 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1657 | {
|
| 1658 | return GSW_HAL_FAIL;
|
| 1659 | }
|
| 1660 |
|
| 1661 | ret = mbtk_get_modem_fun(nw_info_handle, &tmp_rf);
|
| 1662 | if (ret != 0)
|
| 1663 | {
|
| 1664 | LOGE("mbtk_get_modem_fun fail\n");
|
| 1665 | return GSW_HAL_FAIL;
|
| 1666 | }
|
| 1667 | if(tmp_rf == LYNQ_AIR_CFUN_MODE_OFF)
|
| 1668 | {
|
| 1669 | *op_mode = GSW_OP_MODE_LPM;
|
| 1670 | }
|
| 1671 |
|
| 1672 | if(tmp_rf == LYNQ_AIR_PLANE_MODE_ON)
|
| 1673 | {
|
| 1674 | *op_mode = GSW_OP_MODE_OFFLINE;
|
| 1675 | }
|
| 1676 |
|
| 1677 | if(tmp_rf == LYNQ_AIR_PLANE_MODE_OFF)
|
| 1678 | {
|
| 1679 | *op_mode = GSW_OP_MODE_ONLINE;
|
| 1680 | }
|
| 1681 |
|
| 1682 | return GSW_HAL_SUCCESS;
|
| 1683 | }
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 | /**
|
| 1688 | * @brief set radio opmode, as open and close airplane mode
|
| 1689 | * @param [in] op_mode 1 is radio on, 0 is radio off
|
| 1690 | * @retval 0: success
|
| 1691 | * @retval other: fail
|
| 1692 | */
|
| 1693 | int gsw_set_opmode(int op_mode)
|
| 1694 | {
|
| 1695 | mbtk_modem_info_t info;
|
| 1696 | int rf_mode = -1;
|
| 1697 | int ret = -1;
|
| 1698 |
|
| 1699 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1700 | {
|
| 1701 | return GSW_HAL_FAIL;
|
| 1702 | }
|
| 1703 |
|
| 1704 | if(op_mode == GSW_OP_MODE_LPM)
|
| 1705 | {
|
| 1706 | rf_mode = LYNQ_AIR_CFUN_MODE_OFF;
|
| 1707 | }
|
| 1708 |
|
| 1709 | if(op_mode == GSW_OP_MODE_ONLINE)
|
| 1710 | {
|
| 1711 | rf_mode = LYNQ_AIR_PLANE_MODE_OFF;
|
| 1712 | }
|
| 1713 |
|
| 1714 | if(op_mode == GSW_OP_MODE_OFFLINE)
|
| 1715 | {
|
| 1716 | rf_mode = LYNQ_AIR_PLANE_MODE_ON;
|
| 1717 | }
|
| 1718 |
|
| 1719 | if (rf_mode != LYNQ_AIR_PLANE_MODE_ON && rf_mode != LYNQ_AIR_PLANE_MODE_OFF && rf_mode != LYNQ_AIR_CFUN_MODE_OFF)
|
| 1720 | {
|
| 1721 | LOGE("Input mode is error!\n");
|
| 1722 | return GSW_HAL_FAIL;
|
| 1723 | }
|
| 1724 |
|
| 1725 | info.fun = rf_mode;
|
| 1726 | info.rst = 0;
|
| 1727 | ret = mbtk_set_modem_fun(nw_info_handle, &info);
|
| 1728 | if (ret != 0)
|
| 1729 | {
|
| 1730 | LOGE("gsw_set_opmode fail\n");
|
| 1731 | return GSW_HAL_FAIL;
|
| 1732 | }
|
| 1733 |
|
| 1734 | return GSW_HAL_SUCCESS;
|
| 1735 |
|
| 1736 | }
|
| 1737 |
|
| 1738 |
|
| 1739 | /**
|
| 1740 | * @brief get network mode preference of mdm search network scale
|
| 1741 | * @param [out] mode_pref net_work pref mode:
|
| 1742 | * enum prefer_mode
|
| 1743 | * @retval 0: success
|
| 1744 | * @retval other: fail
|
| 1745 | */
|
| 1746 | int gsw_get_mode_preference(int *mode_pref)
|
| 1747 | {
|
| 1748 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1749 | {
|
| 1750 | return GSW_HAL_FAIL;
|
| 1751 | }
|
| 1752 |
|
| 1753 | int ret = -1;
|
| 1754 | mbtk_band_info_t band;
|
| 1755 | memset(&band, 0, sizeof(mbtk_band_info_t));
|
| 1756 |
|
| 1757 | ret = mbtk_current_band_get(nw_info_handle, &band);
|
| 1758 | if(ret != 0)
|
| 1759 | {
|
| 1760 | LOGE("mbtk_current_band_get fail\n");
|
| 1761 | return GSW_HAL_FAIL;
|
| 1762 | }
|
| 1763 |
|
| 1764 | *mode_pref = convert_gsw_net_config(band.net_pref);
|
| 1765 | LOGE("band.net_pref = %d\n", *mode_pref);
|
| 1766 | if(*mode_pref <= 0)
|
| 1767 | {
|
| 1768 | LOGE("no support mode\n");
|
| 1769 | return GSW_HAL_FAIL;
|
| 1770 | }
|
| 1771 | return GSW_HAL_SUCCESS;
|
| 1772 |
|
| 1773 |
|
| 1774 | }
|
| 1775 |
|
| 1776 | /**
|
| 1777 | * @brief set network mode preference of mdm search network scale
|
| 1778 | * @param [in] mode_pref net_work pref mode:
|
| 1779 | * enum prefer_mode
|
| 1780 | * @retval 0: success
|
| 1781 | * @retval other: fail
|
| 1782 | */
|
| 1783 | int gsw_set_mode_preference(int mode_pref)
|
| 1784 | {
|
| 1785 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1786 | {
|
| 1787 | return GSW_HAL_FAIL;
|
| 1788 | }
|
| 1789 |
|
| 1790 | int ret = -1;
|
| 1791 |
|
| 1792 | mbtk_band_info_t band;
|
| 1793 | memset(&band, 0, sizeof(mbtk_band_info_t));
|
| 1794 |
|
| 1795 | band.net_pref = convert_mbtk_net_config(mode_pref);
|
| 1796 | LOGE("band.net_pref = %d\n", band.net_pref);
|
| 1797 |
|
| 1798 | if(band.net_pref < 0)
|
| 1799 | {
|
| 1800 | LOGE("no support mode\n");
|
| 1801 | return GSW_HAL_FAIL;
|
| 1802 | }
|
| 1803 |
|
| 1804 | ret = mbtk_current_band_set(nw_info_handle, &band);
|
| 1805 | if(ret != 0)
|
| 1806 | {
|
| 1807 | LOGE("mbtk_current_band_set fail\n");
|
| 1808 | return GSW_HAL_FAIL;
|
| 1809 | }
|
| 1810 |
|
| 1811 | return GSW_HAL_SUCCESS;
|
| 1812 | }
|
| 1813 |
|
| 1814 | /**
|
| 1815 | * @brief get signal csq value
|
| 1816 | * @param [out] csq_value csq of signalstrengh 0 - 31, 99 invalid
|
| 1817 | * @retval 0: success
|
| 1818 | * @retval other: fail
|
| 1819 | */
|
| 1820 | int gsw_get_sig_info(int *csq_value)
|
| 1821 | {
|
| 1822 | int ret = -1;
|
| 1823 |
|
| 1824 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1825 | {
|
| 1826 | return GSW_HAL_FAIL;
|
| 1827 | }
|
| 1828 |
|
| 1829 | mbtk_signal_info_t signal;
|
| 1830 | memset(&signal, 0x0, sizeof(mbtk_signal_info_t));
|
| 1831 | ret = mbtk_net_signal_get(nw_info_handle, &signal);
|
| 1832 | if(ret != 0)
|
| 1833 | {
|
| 1834 | LOGE("mbtk_net_signal_get fail\n");
|
| 1835 | return GSW_HAL_FAIL;
|
| 1836 | }
|
| 1837 |
|
| 1838 | LOGD("signal.type=%d\n", signal.type);
|
| 1839 | switch(signal.type)
|
| 1840 | {
|
| 1841 | case MBTK_RADIO_TECH_GSM:
|
| 1842 | case MBTK_RADIO_TECH_GSM_COMPACT:
|
| 1843 | case MBTK_RADIO_TECH_GSM_EGPRS:
|
| 1844 | {
|
| 1845 | LOGD("rssi = %d\n",signal.rssi);
|
| 1846 | *csq_value = rssi_convert_to_dBm(signal.rssi);
|
| 1847 | break;
|
| 1848 | }
|
| 1849 | case MBTK_RADIO_TECH_E_UTRAN:
|
| 1850 | {
|
| 1851 | LOGD("rsrp = %d\n",signal.rsrp);
|
| 1852 | *csq_value = rsrp_convert_to_dBm(signal.rsrp);
|
| 1853 | break;
|
| 1854 | }
|
| 1855 | case MBTK_RADIO_TECH_UTRAN:
|
| 1856 | case MBTK_RADIO_TECH_UTRAN_HSDPA:
|
| 1857 | case MBTK_RADIO_TECH_UTRAN_HSUPA:
|
| 1858 | case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
|
| 1859 | case MBTK_RADIO_TECH_UTRAN_HSPA:
|
| 1860 | {
|
| 1861 | LOGD("rscp = %d\n",signal.rscp);
|
| 1862 | *csq_value = rscp_convert_to_dBm(signal.rscp);
|
| 1863 | break;
|
| 1864 | }
|
| 1865 | default:
|
| 1866 | {
|
| 1867 | LOGD("[%s] unknown reg type.[%d]\n", __func__, signal.type);
|
| 1868 | return GSW_HAL_FAIL;
|
| 1869 | }
|
| 1870 | }
|
| 1871 | return GSW_HAL_SUCCESS;
|
| 1872 | }
|
| 1873 |
|
| 1874 | /**
|
| 1875 | * @brief set nework power mode, for tcam enter standby or exit standby
|
| 1876 | * @param [in] mode TRUE(1) when enter standby, FALSE(0) after wake up
|
| 1877 | * @retval 0: success
|
| 1878 | * @retval other: fail
|
| 1879 | */
|
| 1880 | int gsw_network_set_power_mode(char mode)
|
| 1881 | {
|
| 1882 | int ret = -1;
|
| 1883 |
|
| 1884 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1885 | {
|
| 1886 | return GSW_HAL_FAIL;
|
| 1887 | }
|
| 1888 |
|
| 1889 | if(mode != 0 && mode != 1)
|
| 1890 | {
|
| 1891 | LOGE("Input mode is error!\n");
|
| 1892 | return GSW_HAL_FAIL;
|
| 1893 | }
|
| 1894 |
|
| 1895 | if(mode == 1)
|
| 1896 | {
|
| 1897 | mode = 6;
|
| 1898 | }
|
| 1899 |
|
| 1900 | ret = mbtk_wakeup_state_set(nw_info_handle, mode);
|
| 1901 | if(ret != 0)
|
| 1902 | {
|
| 1903 | LOGE("mbtk_wakeup_state_set fail\n");
|
| 1904 | return GSW_HAL_FAIL;
|
| 1905 | }
|
| 1906 |
|
| 1907 | return GSW_HAL_SUCCESS;
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 | }
|
| 1912 |
|
| 1913 | /**
|
| 1914 | * @brief convert rsrp rscp rssi to csq value.
|
| 1915 | * @param [in] netType signal radio tech 2 means 2G 3 mens 3G,4 is 4G,5 is 5G
|
| 1916 | * @param [in] sigvalue input signal_strength for different nettype
|
| 1917 | * rsrp for 4G/5G, rscp for 3G, rssi for 2G
|
| 1918 |
|
| 1919 | * @retval csq
|
| 1920 | * @retval other: fail
|
| 1921 | */
|
| 1922 | int gsw_sigInfo_to_csq(int netType, int sigValue)
|
| 1923 | {
|
| 1924 | switch(netType)
|
| 1925 | {
|
| 1926 | case 1:
|
| 1927 | case 2:
|
| 1928 | case 3:
|
| 1929 | case 4: //GSM
|
| 1930 | {
|
| 1931 | return gsw_rssi_to_csq(sigValue);
|
| 1932 | }
|
| 1933 |
|
| 1934 | case 5: //WCDMA
|
| 1935 | {
|
| 1936 | return gsw_rscp_to_csq(sigValue);
|
| 1937 | }
|
| 1938 |
|
| 1939 | case 6: //LTE
|
| 1940 | {
|
| 1941 | return gsw_rsrp_to_csq(sigValue);
|
| 1942 | }
|
| 1943 |
|
| 1944 | default:
|
| 1945 | {
|
| 1946 | LOGE("parameter error\n");
|
| 1947 | return GSW_HAL_FAIL;
|
| 1948 | }
|
| 1949 | }
|
| 1950 | }
|
| 1951 |
|
| 1952 | /*
|
| 1953 | * @brief get mobile operator name
|
| 1954 | @param [out] nw_operator_name_infos get the long and short operator name info
|
| 1955 | @retval 0: success
|
| 1956 | @retval 0: other: fail
|
| 1957 | */
|
| 1958 | int gsw_get_mobile_operator_name(gsw_mobile_operator_name *nw_operator_name_infos)
|
| 1959 | {
|
| 1960 | char OperatorFN[128];
|
| 1961 | char OperatorSH[128];
|
| 1962 | char temp[12] = {0};
|
| 1963 | mbtk_net_info_t net;
|
| 1964 |
|
| 1965 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 1966 | {
|
| 1967 | return GSW_HAL_FAIL;
|
| 1968 | }
|
| 1969 |
|
| 1970 | if(!mbtk_net_sel_mode_get(nw_info_handle, &net) && net.plmn > 0)
|
| 1971 | {
|
| 1972 | LOGE("Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);
|
| 1973 | int i = 0;
|
| 1974 | while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))
|
| 1975 | {
|
| 1976 | if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)
|
| 1977 | break;
|
| 1978 | i++;
|
| 1979 | }
|
| 1980 |
|
| 1981 | if(i == ARRAY_SIZE(lynq_operator_mcc_mnc)) // No found mcc&mnc
|
| 1982 | {
|
| 1983 | strcpy(OperatorFN, "UNKNOWN");
|
| 1984 | strcpy(OperatorSH, "UNKNOWN");
|
| 1985 | }
|
| 1986 | else
|
| 1987 | {
|
| 1988 | strcpy(OperatorFN, lynq_operator_mcc_mnc[i].lynq_operator_l);
|
| 1989 | strcpy(OperatorSH, lynq_operator_mcc_mnc[i].lynq_operator_s);
|
| 1990 |
|
| 1991 | memset(temp,0,12);
|
| 1992 | memset(nw_operator_name_infos->mcc,0,4);
|
| 1993 | sprintf(temp, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)/100);
|
| 1994 | strncpy(nw_operator_name_infos->mcc, temp, strlen(temp));
|
| 1995 |
|
| 1996 | memset(temp,0,12);
|
| 1997 | memset(nw_operator_name_infos->mnc,0,4);
|
| 1998 | sprintf(temp, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)%100);
|
| 1999 | strncpy(nw_operator_name_infos->mnc, temp, strlen(temp));
|
| 2000 | }
|
| 2001 |
|
| 2002 | memset(nw_operator_name_infos->long_eons,0,128);
|
| 2003 | memcpy(nw_operator_name_infos->long_eons,OperatorFN,strlen(OperatorFN));
|
| 2004 | memset(nw_operator_name_infos->short_eons,0,128);
|
| 2005 | memcpy(nw_operator_name_infos->short_eons,OperatorSH,strlen(OperatorSH));
|
| 2006 |
|
| 2007 | return GSW_HAL_SUCCESS;
|
| 2008 | }
|
| 2009 |
|
| 2010 | else
|
| 2011 | {
|
| 2012 | LOGE("mbtk_net_sel_mode_get fail\n");
|
| 2013 | return GSW_HAL_FAIL;
|
| 2014 | }
|
| 2015 |
|
| 2016 | return GSW_HAL_SUCCESS;
|
| 2017 | }
|
| 2018 |
|
| 2019 |
|
| 2020 | /*
|
| 2021 | * @brief get current serving cell info
|
| 2022 | * @param cell_info: [out] struct for current cell info
|
| 2023 | * include earfcn mcc mnc pci psc tac lac etc.
|
| 2024 | * @return int: 0 is success, other failed
|
| 2025 | */
|
| 2026 | int gsw_get_cell_info(GSW_NW_CELL_INFO *cell_info)
|
| 2027 | {
|
| 2028 | int ret = -1;
|
| 2029 |
|
| 2030 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 2031 | {
|
| 2032 | LOGE("nw_sdk_deinit not init\n");
|
| 2033 | return GSW_HAL_FAIL;
|
| 2034 | }
|
| 2035 |
|
| 2036 | list_node_t* cell_list = NULL;
|
| 2037 | int neibor_count = 0;
|
| 2038 | mbtk_cell_type_enum type;
|
| 2039 | ret = mbtk_cell_get(nw_info_handle, &type, &cell_list);
|
| 2040 | if(ret || cell_list == NULL) {
|
| 2041 | LOGE("mbtk_cell_get failed : %d\n", ret);
|
| 2042 | } else {
|
| 2043 | list_first(cell_list);
|
| 2044 | mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);
|
| 2045 | if(cell) { // Current server cell.
|
| 2046 | switch(type)
|
| 2047 | {
|
| 2048 | case 0:
|
| 2049 | {
|
| 2050 | LOGD("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
|
| 2051 | char gsm_temp[12] = {0};
|
| 2052 |
|
| 2053 | cell_info->rat = GSW_NETWORK_RADIO_GSM;
|
| 2054 |
|
| 2055 | cell_info->mcc_valid = 1;
|
| 2056 | snprintf(gsm_temp, sizeof(gsm_temp) ,"%d", cell->value5);
|
| 2057 | strncpy(cell_info->mcc, gsm_temp, sizeof(cell_info->mcc));
|
| 2058 |
|
| 2059 | memset(gsm_temp, 0, sizeof(gsm_temp));
|
| 2060 |
|
| 2061 | cell_info->mnc_valid = 1;
|
| 2062 | snprintf(gsm_temp, sizeof(gsm_temp) ,"%d", cell->value6);
|
| 2063 | strncpy(cell_info->mnc, gsm_temp, sizeof(cell_info->mnc));
|
| 2064 |
|
| 2065 | cell_info->cell_id_valid = 1;
|
| 2066 | cell_info->cell_id = cell->value2;
|
| 2067 |
|
| 2068 | cell_info->lac_valid = 1;
|
| 2069 | cell_info->lac = cell->value1;
|
| 2070 |
|
| 2071 | cell_info->arfcn_valid = 1;
|
| 2072 | cell_info->arfcn = cell->value3;
|
| 2073 |
|
| 2074 | break;
|
| 2075 | }
|
| 2076 |
|
| 2077 | case 1:
|
| 2078 | {
|
| 2079 | LOGD("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
|
| 2080 | char wcdma_temp[12] = {0};
|
| 2081 |
|
| 2082 | cell_info->rat = GSW_NETWORK_RADIO_UMTS;
|
| 2083 |
|
| 2084 | cell_info->mcc_valid = 1;
|
| 2085 | snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%d", cell->value4);
|
| 2086 | strncpy(cell_info->mcc, wcdma_temp, sizeof(cell_info->mcc));
|
| 2087 |
|
| 2088 | memset(wcdma_temp, 0, sizeof(wcdma_temp));
|
| 2089 |
|
| 2090 | cell_info->mnc_valid = 1;
|
| 2091 | snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%d", cell->value5);
|
| 2092 | strncpy(cell_info->mnc, wcdma_temp, sizeof(cell_info->mnc));
|
| 2093 |
|
| 2094 | cell_info->lac_valid = 1;
|
| 2095 | cell_info->lac = cell->value1;
|
| 2096 |
|
| 2097 | cell_info->cell_id_valid = 1;
|
| 2098 | cell_info->cell_id = cell->value2;
|
| 2099 |
|
| 2100 | cell_info->uarfcn_valid = 1;
|
| 2101 | cell_info->uarfcn = cell->value3;
|
| 2102 |
|
| 2103 | cell_info->psc_valid = 1;
|
| 2104 | cell_info->psc = cell->value6;
|
| 2105 | break;
|
| 2106 | }
|
| 2107 |
|
| 2108 | case 2:
|
| 2109 | {
|
| 2110 | LOGE("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
|
| 2111 |
|
| 2112 | char lte_temp[12] = {0};
|
| 2113 |
|
| 2114 | cell_info->rat = GSW_NETWORK_RADIO_LTE;
|
| 2115 |
|
| 2116 | cell_info->mcc_valid = 1;
|
| 2117 | snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);
|
| 2118 | strncpy(cell_info->mcc, lte_temp, sizeof(cell_info->mcc));
|
| 2119 |
|
| 2120 | memset(lte_temp, 0, sizeof(lte_temp));
|
| 2121 |
|
| 2122 | cell_info->mnc_valid = 1;
|
| 2123 | snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);
|
| 2124 | strncpy(cell_info->mnc, lte_temp, sizeof(cell_info->mnc));
|
| 2125 |
|
| 2126 | cell_info->tac_valid = 1;
|
| 2127 | cell_info->tac = cell->value1;
|
| 2128 |
|
| 2129 | cell_info->pci_valid = 1;
|
| 2130 | cell_info->pci = cell->value2;
|
| 2131 |
|
| 2132 | cell_info->earfcn_valid = 1;
|
| 2133 | cell_info->earfcn = cell->value3;
|
| 2134 |
|
| 2135 | cell_info->bler_valid = 1;
|
| 2136 | cell_info->bler = cell->value4;
|
| 2137 |
|
| 2138 | cell_info->band_valid = 1;
|
| 2139 | cell_info->band = cell->value5;
|
| 2140 |
|
| 2141 | cell_info->rsrp_valid = 1;
|
| 2142 | cell_info->rsrp = cell->value8;
|
| 2143 |
|
| 2144 | cell_info->rsrq_valid = 1;
|
| 2145 | cell_info->rsrq = cell->value9;
|
| 2146 |
|
| 2147 | cell_info->cell_id_valid = 1;
|
| 2148 | cell_info->cell_id = cell->value10;
|
| 2149 |
|
| 2150 | break;
|
| 2151 | }
|
| 2152 |
|
| 2153 | default:
|
| 2154 | break;
|
| 2155 | }
|
| 2156 | }
|
| 2157 |
|
| 2158 | while ((cell = (mbtk_cell_info_t*) list_next(cell_list)) && neibor_count < 5)
|
| 2159 | {
|
| 2160 | switch(type)
|
| 2161 | {
|
| 2162 | //GSM
|
| 2163 | case 0:
|
| 2164 | {
|
| 2165 |
|
| 2166 | }
|
| 2167 | //WCDMA
|
| 2168 | case 1:
|
| 2169 | {
|
| 2170 | LOGE("CELL : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
|
| 2171 |
|
| 2172 | //cell_info->ext_info[neibor_count]->lac = cell->value1;
|
| 2173 |
|
| 2174 | cell_info->ext_info[neibor_count].cell_id_valid = 1;
|
| 2175 | cell_info->ext_info[neibor_count].cell_id = cell->value2;
|
| 2176 |
|
| 2177 | cell_info->ext_info[neibor_count].arfcn_valid = 1;
|
| 2178 | cell_info->ext_info[neibor_count].arfcn = cell->value3;
|
| 2179 |
|
| 2180 | cell_info->ext_info[neibor_count].rat = cell_info->rat = GSW_NETWORK_RADIO_UMTS;
|
| 2181 |
|
| 2182 | neibor_count++;
|
| 2183 |
|
| 2184 | }
|
| 2185 | //LTE
|
| 2186 | case 2:
|
| 2187 | {
|
| 2188 | LOGE("CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);
|
| 2189 | char lte_temp[12] = {0};
|
| 2190 | cell_info->ext_info[neibor_count].rat = GSW_NETWORK_RADIO_LTE;
|
| 2191 |
|
| 2192 | snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);
|
| 2193 | strncpy(cell_info->ext_info[neibor_count].mcc, lte_temp, sizeof(cell_info->mcc));
|
| 2194 |
|
| 2195 | memset(lte_temp, 0, sizeof(lte_temp));
|
| 2196 |
|
| 2197 | snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);
|
| 2198 | strncpy(cell_info->ext_info[neibor_count].mnc, lte_temp, sizeof(cell_info->mnc));
|
| 2199 |
|
| 2200 | cell_info->ext_info[neibor_count].pci = cell->value1;
|
| 2201 | cell_info->ext_info[neibor_count].pci_valid = 1;
|
| 2202 |
|
| 2203 | cell_info->ext_info[neibor_count].arfcn = cell->value2;
|
| 2204 | cell_info->ext_info[neibor_count].arfcn_valid = 1;
|
| 2205 |
|
| 2206 | cell_info->ext_info[neibor_count].rsrp = cell->value3;
|
| 2207 | cell_info->ext_info[neibor_count].rsrp_valid = 1;
|
| 2208 |
|
| 2209 | cell_info->ext_info[neibor_count].rsrq = cell->value4;
|
| 2210 | cell_info->ext_info[neibor_count].rsrq_valid = 1;
|
| 2211 |
|
| 2212 | cell_info->ext_info[neibor_count].cell_id = cell->value5;
|
| 2213 | cell_info->ext_info[neibor_count].cell_id_valid = 1;
|
| 2214 |
|
| 2215 | cell_info->ext_info[neibor_count].band = cell->value9;
|
| 2216 | cell_info->ext_info[neibor_count].band_valid = 1;
|
| 2217 |
|
| 2218 | cell_info->ext_info[neibor_count].rssi = cell->value10;
|
| 2219 | cell_info->ext_info[neibor_count].rssi_valid = 1;
|
| 2220 |
|
| 2221 | neibor_count++;
|
| 2222 | }
|
| 2223 |
|
| 2224 | default:
|
| 2225 | break;
|
| 2226 | }
|
| 2227 | }
|
| 2228 | }
|
| 2229 | list_free(cell_list);
|
| 2230 |
|
| 2231 | return GSW_HAL_SUCCESS;
|
| 2232 | }
|
| 2233 |
|
| 2234 | /*
|
| 2235 | * @brief set modem status event callback
|
| 2236 | @param [in] handle_ptr callback function address
|
| 2237 | @retval 0: success
|
| 2238 | @retval 0: other: fail
|
| 2239 | */
|
| 2240 | int gsw_reg_set_modem_status_event_callback(GSW_NW_ModemStateHandlePtr handle_ptr)
|
| 2241 | {
|
| 2242 |
|
| 2243 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 2244 | {
|
| 2245 | return GSW_HAL_FAIL;
|
| 2246 | }
|
| 2247 |
|
| 2248 | int ret = -1;
|
| 2249 |
|
| 2250 | if(handle_ptr == NULL)
|
| 2251 | {
|
| 2252 | LOGE("handle_ptr is NULL\n");
|
| 2253 | return GSW_HAL_FAIL;
|
| 2254 | }
|
| 2255 |
|
| 2256 | modem_cb = handle_ptr;
|
| 2257 |
|
| 2258 | ret = mbtk_radio_state_change_cb_reg(nw_info_handle,gsw_modem_status_event_callback);
|
| 2259 | if(ret != 0)
|
| 2260 | {
|
| 2261 | LOGE("mbtk_radio_state_change_cb_reg failed : %d\n", ret);
|
| 2262 | return GSW_HAL_FAIL;
|
| 2263 | }
|
| 2264 |
|
| 2265 | return GSW_HAL_SUCCESS;
|
| 2266 |
|
| 2267 | }
|
| 2268 |
|
| 2269 |
|
| 2270 | /*
|
| 2271 | * @brief get PLMNs from the FPLMN list
|
| 2272 | * @param [inout] plmn_list:
|
| 2273 | * @retval 0: success
|
| 2274 | * @retval other: fail
|
| 2275 | */
|
| 2276 | int gsw_get_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
|
| 2277 | {
|
| 2278 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 2279 | {
|
| 2280 | return GSW_HAL_FAIL;
|
| 2281 | }
|
| 2282 |
|
| 2283 | int ret = -1;
|
| 2284 | char fplmn[256] = {0};
|
| 2285 | LOGE("mbtk_fplmn_get enter\n");
|
| 2286 | ret = mbtk_fplmn_get(nw_info_handle, fplmn);
|
| 2287 | LOGE("mbtk_fplmn_get exit\n");
|
| 2288 | if(ret != 0)
|
| 2289 | {
|
| 2290 | LOGE("mbtk_fplmn_get failed : %d\n",ret);
|
| 2291 | return GSW_HAL_FAIL;
|
| 2292 | }
|
| 2293 |
|
| 2294 | update_fplmn_list(fplmn);
|
| 2295 | for(int i = 0; i < fplmn_index; i++)
|
| 2296 | {
|
| 2297 | if(strcmp(fplmn_array[i],"FFFFFF") == 0)
|
| 2298 | {
|
| 2299 | continue;
|
| 2300 | }
|
| 2301 | 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);
|
| 2302 | 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);
|
| 2303 | plmn_list->plmn_list_len++;
|
| 2304 | }
|
| 2305 |
|
| 2306 | LOGE("fplmn = %s\n", fplmn);
|
| 2307 | return GSW_HAL_SUCCESS;
|
| 2308 | }
|
| 2309 |
|
| 2310 | /*
|
| 2311 | * @brief add PLMNs from the plmn_list to the FPLMN list
|
| 2312 | * @param [in] plmn_list:
|
| 2313 | * @retval 0: success
|
| 2314 | * @retval other: fail
|
| 2315 | */
|
| 2316 | int gsw_add_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
|
| 2317 | {
|
| 2318 |
|
| 2319 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 2320 | {
|
| 2321 | return GSW_HAL_FAIL;
|
| 2322 | }
|
| 2323 |
|
| 2324 | if(plmn_list->plmn_list_len >= fplmn_max_length)
|
| 2325 | {
|
| 2326 | LOGE("can't save all the plmn\n");
|
| 2327 | return GSW_HAL_FAIL;
|
| 2328 | }
|
| 2329 |
|
| 2330 | int i = 0;
|
| 2331 | int index = -1;
|
| 2332 |
|
| 2333 | for(i = 0; i < plmn_list->plmn_list_len; i++)
|
| 2334 | {
|
| 2335 | index = check_index(plmn_list->plmn_list[i].mcc, plmn_list->plmn_list[i].mnc);
|
| 2336 |
|
| 2337 | if(index == -1)
|
| 2338 | {
|
| 2339 | LOGE("no this PLMN, add it\n");
|
| 2340 | if((fplmn_index + plmn_list->plmn_list_len) > fplmn_max_length)
|
| 2341 | {
|
| 2342 | LOGE("can't save all the plmn\n");
|
| 2343 | return GSW_HAL_FAIL;
|
| 2344 | }
|
| 2345 |
|
| 2346 | else
|
| 2347 | {
|
| 2348 | memcpy(fplmn_array[fplmn_index], plmn_list->plmn_list[i].mcc, 3);
|
| 2349 | memcpy(fplmn_array[fplmn_index] + 3, plmn_list->plmn_list[i].mnc, 2);
|
| 2350 | fplmn_array[fplmn_index][5] = '\0';
|
| 2351 | LOGE("fplmn_array[%d] = %s\n", fplmn_index, fplmn_array[fplmn_index]);
|
| 2352 | fplmn_index++;
|
| 2353 | }
|
| 2354 | }
|
| 2355 |
|
| 2356 | else
|
| 2357 | {
|
| 2358 | LOGE("already have this PLMN, don't add it\n");
|
| 2359 | }
|
| 2360 | }
|
| 2361 |
|
| 2362 | char fplmn_str[256] = {0};
|
| 2363 | convert_plmn_to_fplmn_str(fplmn_str);
|
| 2364 |
|
| 2365 | LOGE("fplmn_str = %s\n", fplmn_str);
|
| 2366 |
|
| 2367 | int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
|
| 2368 | if(ret != 0)
|
| 2369 | {
|
| 2370 | LOGE("mbtk_fplmn_set failed : %d\n",ret);
|
| 2371 | return GSW_HAL_FAIL;
|
| 2372 | }
|
| 2373 |
|
| 2374 | LOGE("gsw_add_forbidden_networks exit\n");
|
| 2375 | return GSW_HAL_SUCCESS;
|
| 2376 | }
|
| 2377 |
|
| 2378 | /*
|
| 2379 | * @brief Remove PLMNs from the plmn_list from the FPLMN list
|
| 2380 | * @param [in] plmn_list:
|
| 2381 | * @retval 0: success
|
| 2382 | * @retval other: fail
|
| 2383 | */
|
| 2384 | int gsw_remove_forbidden_networks(gsw_nw_plmn_list_t *plmn_list)
|
| 2385 | {
|
| 2386 | LOGE("gsw_remove_forbidden_networks enter\n");
|
| 2387 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 2388 | {
|
| 2389 | return GSW_HAL_FAIL;
|
| 2390 | }
|
| 2391 |
|
| 2392 | int i = 0;
|
| 2393 | int index = -1;
|
| 2394 |
|
| 2395 | for(i = 0; i < plmn_list->plmn_list_len; i++)
|
| 2396 | {
|
| 2397 | index = check_index(plmn_list->plmn_list[i].mcc, plmn_list->plmn_list[i].mnc);
|
| 2398 | if(index != -1)
|
| 2399 | {
|
| 2400 | remove_fplmn(index);
|
| 2401 | }
|
| 2402 | else
|
| 2403 | {
|
| 2404 | LOGE("no this PLMN, can't remove it\n");
|
| 2405 | }
|
| 2406 | }
|
| 2407 |
|
| 2408 | for(i = 0; i < fplmn_index; i++)
|
| 2409 | {
|
| 2410 | LOGE("fplmn_array[%d] = %s\n", i, fplmn_array[i]);
|
| 2411 | }
|
| 2412 |
|
| 2413 | char fplmn_str[256] = {0};
|
| 2414 | convert_plmn_to_fplmn_str(fplmn_str);
|
| 2415 | LOGE("fplmn_str = %s\n", fplmn_str);
|
| 2416 |
|
| 2417 | int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
|
| 2418 | if(ret != 0)
|
| 2419 | {
|
| 2420 | LOGE("mbtk_fplmn_set failed : %d\n",ret);
|
| 2421 | return GSW_HAL_FAIL;
|
| 2422 | }
|
| 2423 |
|
| 2424 | LOGE("gsw_remove_forbidden_networks exit\n");
|
| 2425 | return GSW_HAL_SUCCESS;
|
| 2426 | }
|
| 2427 |
|
| 2428 | /*
|
| 2429 | * @brief clear FPLMN list
|
| 2430 | * @param
|
| 2431 | * @retval 0: success
|
| 2432 | * @retval other: fail
|
| 2433 | */
|
| 2434 | int gsw_clear_forbidden_networks(void)
|
| 2435 | {
|
| 2436 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 2437 | {
|
| 2438 | return GSW_HAL_FAIL;
|
| 2439 | }
|
| 2440 |
|
| 2441 | char fplmn_str[FPLMN_STRING_LENGTH+1];
|
| 2442 | memset(fplmn_str, 'F', (6 * fplmn_max_length));
|
| 2443 | fplmn_str[(6 * fplmn_max_length)] = '\0';
|
| 2444 |
|
| 2445 | LOGE("%s\n", fplmn_str);
|
| 2446 | int ret = mbtk_fplmn_set(nw_info_handle, fplmn_str);
|
| 2447 | if(ret != 0)
|
| 2448 | {
|
| 2449 | LOGE("mbtk_fplmn_set failed : %d\n",ret);
|
| 2450 | return GSW_HAL_FAIL;
|
| 2451 | }
|
| 2452 |
|
| 2453 | return GSW_HAL_SUCCESS;
|
| 2454 | }
|
| 2455 |
|
| 2456 | /*
|
| 2457 | * @brief get oos config
|
| 2458 | * @param [in] oos_config
|
| 2459 | * @retval 0: success
|
| 2460 | * @retval other: fail
|
| 2461 | */
|
| 2462 | int gsw_oos_config_get(GSW_NW_OOS_CONFIG_INFO_T *pt_info)
|
| 2463 | {
|
| 2464 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 2465 | {
|
| 2466 | return GSW_HAL_FAIL;
|
| 2467 | }
|
| 2468 |
|
| 2469 | if(pt_info == NULL)
|
| 2470 | {
|
| 2471 | LOGE("pt_info is null\n");
|
| 2472 | return GSW_HAL_FAIL;
|
| 2473 | }
|
| 2474 |
|
| 2475 | int ret = -1;
|
| 2476 |
|
| 2477 | mbtk_oos_info oos_info;
|
| 2478 | memset(&oos_info, 0x00, sizeof(mbtk_oos_info));
|
| 2479 |
|
| 2480 | ret = mbtk_oos_get(nw_info_handle, &oos_info);
|
| 2481 | if(ret != 0)
|
| 2482 | {
|
| 2483 | LOGE("mbtk_oos_get failed : %d\n",ret);
|
| 2484 | return GSW_HAL_FAIL;
|
| 2485 | }
|
| 2486 |
|
| 2487 | if(oos_info.mode == 0)
|
| 2488 | {
|
| 2489 | pt_info->t_min = 0;
|
| 2490 | pt_info->t_step = 0;
|
| 2491 | pt_info->t_max = 0;
|
| 2492 | }
|
| 2493 |
|
| 2494 | else
|
| 2495 | {
|
| 2496 | pt_info->t_min = (int)oos_info.oosPhase[0];
|
| 2497 | pt_info->t_step = (int)oos_info.oosPhase[1];
|
| 2498 | pt_info->t_max = (int)oos_info.oosPhase[2];
|
| 2499 | }
|
| 2500 |
|
| 2501 | return GSW_HAL_SUCCESS;
|
| 2502 | }
|
| 2503 |
|
| 2504 |
|
| 2505 | /*
|
| 2506 | * @brief set oos config
|
| 2507 | * @param [in] oos_config
|
| 2508 | * @retval 0: success
|
| 2509 | * @retval other: fail
|
| 2510 | */
|
| 2511 | int gsw_oos_config_set(GSW_NW_OOS_CONFIG_INFO_T *pt_info)
|
| 2512 | {
|
| 2513 | if (nw_init_flag == 0 || nw_info_handle == NULL)
|
| 2514 | {
|
| 2515 | return GSW_HAL_FAIL;
|
| 2516 | }
|
| 2517 |
|
| 2518 | if(pt_info == NULL)
|
| 2519 | {
|
| 2520 | LOGE("pt_info is null\n");
|
| 2521 | return GSW_HAL_FAIL;
|
| 2522 | }
|
| 2523 |
|
| 2524 | int ret = -1;
|
| 2525 | mbtk_oos_info oos_info;
|
| 2526 | memset(&oos_info, 0x00, sizeof(mbtk_oos_info));
|
| 2527 |
|
| 2528 | if (pt_info->t_min < 0 || pt_info->t_step < 0 || pt_info->t_max < 0)
|
| 2529 | {
|
| 2530 | LOGE("gsw_oos_config_set set time < 0 ");
|
| 2531 | return GSW_HAL_FAIL;
|
| 2532 | }
|
| 2533 | else if ((pt_info->t_min > 0 && pt_info->t_min <= 255) && pt_info->t_step == 0 && pt_info->t_max == 0)
|
| 2534 | {
|
| 2535 | oos_info.mode = 1;
|
| 2536 | oos_info.oosPhase[0] = pt_info->t_min;
|
| 2537 | }
|
| 2538 | 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)
|
| 2539 | {
|
| 2540 | oos_info.mode = 1;
|
| 2541 | oos_info.oosPhase[0] = pt_info->t_min;
|
| 2542 | oos_info.oosPhase[1] = pt_info->t_step;
|
| 2543 | }
|
| 2544 | 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))
|
| 2545 | {
|
| 2546 | oos_info.mode = 1;
|
| 2547 | oos_info.oosPhase[0] = pt_info->t_min;
|
| 2548 | oos_info.oosPhase[1] = pt_info->t_step;
|
| 2549 | oos_info.oosPhase[2] = pt_info->t_max;
|
| 2550 | }
|
| 2551 | else if (pt_info->t_min == 0 && pt_info->t_step == 0 && pt_info->t_max == 0)
|
| 2552 | {
|
| 2553 | oos_info.mode = 0;
|
| 2554 | }
|
| 2555 | else
|
| 2556 | {
|
| 2557 | LOGE("gsw_oos_config_set set Format err");
|
| 2558 | return GSW_HAL_FAIL;
|
| 2559 | }
|
| 2560 |
|
| 2561 | ret = mbtk_oos_set(nw_info_handle, &oos_info);
|
| 2562 | if(ret != 0)
|
| 2563 | {
|
| 2564 | LOGE("mbtk_oos_set failed : %d\n",ret);
|
| 2565 | return GSW_HAL_FAIL;
|
| 2566 | }
|
| 2567 |
|
| 2568 | return GSW_HAL_SUCCESS;
|
| 2569 | }
|
| 2570 |
|
| 2571 |
|
| 2572 |
|