b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <stdbool.h> |
| 4 | #include <dlfcn.h> |
| 5 | #include <stdint.h> |
| 6 | #include <string.h> |
| 7 | #include <pthread.h> |
| 8 | |
| 9 | //mbtk include |
| 10 | |
| 11 | typedef unsigned int uint32; |
| 12 | typedef unsigned char uint8; |
| 13 | typedef unsigned short uint16; |
| 14 | typedef void (*mbtk_info_callback_func)(const void* data, int data_len); |
| 15 | |
| 16 | typedef struct |
| 17 | { |
| 18 | int client_fd; |
| 19 | pthread_t read_thread_id; |
| 20 | int exit_fd[2]; |
| 21 | bool is_waitting; |
| 22 | pthread_cond_t cond; |
| 23 | pthread_mutex_t mutex; |
| 24 | |
| 25 | pthread_mutex_t send_mutex; |
| 26 | |
| 27 | // Temp response data. |
| 28 | uint16 info_err; |
| 29 | uint16 data_len; |
| 30 | void *data; |
| 31 | |
| 32 | //mbtk wyq for server_ready_status add start |
| 33 | char server_ready_status; |
| 34 | //mbtk wyq for server_ready_status add end |
| 35 | |
| 36 | mbtk_info_callback_func net_state_cb; |
| 37 | mbtk_info_callback_func call_state_cb; |
| 38 | mbtk_info_callback_func sms_state_cb; |
| 39 | mbtk_info_callback_func radio_state_cb; |
| 40 | mbtk_info_callback_func sim_state_cb; |
| 41 | mbtk_info_callback_func pdp_state_cb; |
| 42 | //add signal by xr |
| 43 | mbtk_info_callback_func signal_state_cb; |
| 44 | } mbtk_info_handle_t; |
| 45 | |
| 46 | typedef enum { |
| 47 | MBTK_SIM_ABSENT = 0, |
| 48 | MBTK_SIM_NOT_READY = 1, |
| 49 | MBTK_SIM_READY = 2, |
| 50 | MBTK_SIM_PIN = 3, |
| 51 | MBTK_SIM_PUK = 4, |
| 52 | MBTK_SIM_NETWORK_PERSONALIZATION = 5 |
| 53 | } mbtk_sim_state_enum; |
| 54 | |
| 55 | typedef enum |
| 56 | { |
| 57 | MBTK_DEV_MODEM_MIN_FUN, //Modem 最小功能 |
| 58 | MBTK_DEV_MODEM_FULL_FUN, //Modem 全功能 |
| 59 | MBTK_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS = 3, //Modem 禁用射频接收电路 |
| 60 | MBTK_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS, //Modem禁用射频发射和接收电路 |
| 61 | MBTK_DEV_MODEM_DISABLE_SIM, //Modem 禁用(U)SIM 卡 |
| 62 | MBTK_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE, //Modem 完全禁用辅助接收 |
| 63 | }MBTK_DEV_MODEM_FUNCTION; |
| 64 | |
| 65 | typedef struct |
| 66 | { |
| 67 | MBTK_DEV_MODEM_FUNCTION fun; |
| 68 | int rst; |
| 69 | } mbtk_modem_info_t; |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | //gsw include |
| 75 | #define GSW_HAL_SUCCESS 0 |
| 76 | #define GSW_HAL_FAIL -1 |
| 77 | #define GSW_HAL_MEM_INVAILD -2 |
| 78 | #define GSW_SIM_ICCID_LENGTH 20+1 |
| 79 | #define GSW_SIM_IMSI_LENGTH 20+1 |
| 80 | #define GSW_SIM_MSISDN_LENGTH 20+1 |
| 81 | #define GSW_SIM_IMEI_LENGTH 20+1 |
| 82 | |
| 83 | typedef enum sim_status |
| 84 | { |
| 85 | SIM_STATUS_ABSENT = 0, /**< sim absent*/ |
| 86 | SIM_STATUS_PRESENT = 1, /**< sim present mtk as ready*/ |
| 87 | SIM_STATUS_ERROR = 2, /**< sim error*/ |
| 88 | SIM_STATUS_READY = 3, /**< sim state ready mtk no this value*/ |
| 89 | SIM_STATUS_PIN = 4, /**< pinlock status*/ |
| 90 | } sim_status_e_type; |
| 91 | |
| 92 | |
| 93 | int (*gsw_sim_sdk_init)(int32_t token); |
| 94 | int (*gsw_sim_sdk_deinit)(void); |
| 95 | int (*gsw_get_sim_status)(int32_t *sim_state); |
| 96 | int (*gsw_get_sim_iccid)(int32_t len, int8_t *iccid); |
| 97 | int (*gsw_get_sim_imsi)(int32_t len, int8_t *imsi); |
| 98 | int (*gsw_get_sim_msisdn)(int32_t len, int8_t *msisdn); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 99 | int (*gsw_set_sim_power_down)(void); |
| 100 | int (*gsw_set_sim_power_up)(void); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 101 | |
| 102 | #define lib_gsw_sim_path "/lib/libgsw_lib.so" |
| 103 | static void *dlHandle_sim = NULL; |
| 104 | |
| 105 | |
| 106 | static int gsw_sim_api_import() |
| 107 | { |
| 108 | dlHandle_sim = dlopen(lib_gsw_sim_path, RTLD_NOW); |
| 109 | if (dlHandle_sim == NULL) { |
| 110 | printf("dlopen gsw_sim_sdk_init fail\n"); |
| 111 | return GSW_HAL_FAIL; |
| 112 | } |
| 113 | |
| 114 | gsw_sim_sdk_init = (int(*)(int32_t token))dlsym(dlHandle_sim, "gsw_sim_sdk_init"); |
| 115 | if (gsw_sim_sdk_init == NULL) { |
| 116 | printf("dlsym gsw_sim_sdk_init fail\n"); |
| 117 | return GSW_HAL_FAIL; |
| 118 | } |
| 119 | |
| 120 | gsw_sim_sdk_deinit = (int(*)(void))dlsym(dlHandle_sim, "gsw_sim_sdk_deinit"); |
| 121 | if (gsw_sim_sdk_deinit == NULL) { |
| 122 | printf("dlsym gsw_sim_sdk_deinit fail\n"); |
| 123 | return GSW_HAL_FAIL; |
| 124 | } |
| 125 | |
| 126 | gsw_get_sim_status = (int(*)(int32_t *sim_state))dlsym(dlHandle_sim, "gsw_get_sim_status"); |
| 127 | if (gsw_get_sim_status == NULL) { |
| 128 | printf("dlsym gsw_get_sim_status fail\n"); |
| 129 | return GSW_HAL_FAIL; |
| 130 | } |
| 131 | |
| 132 | gsw_get_sim_iccid = (int(*)(int32_t len, int8_t *iccid))dlsym(dlHandle_sim, "gsw_get_sim_iccid"); |
| 133 | if (gsw_get_sim_iccid == NULL) { |
| 134 | printf("dlsym gsw_get_sim_iccid fail\n"); |
| 135 | return GSW_HAL_FAIL; |
| 136 | } |
| 137 | |
| 138 | gsw_get_sim_imsi = (int(*)(int32_t len, int8_t *imsi))dlsym(dlHandle_sim, "gsw_get_sim_imsi"); |
| 139 | if (gsw_get_sim_imsi == NULL) { |
| 140 | printf("dlsym gsw_get_sim_imsi fail\n"); |
| 141 | return GSW_HAL_FAIL; |
| 142 | } |
| 143 | |
| 144 | gsw_get_sim_msisdn = (int(*)(int32_t len, int8_t *msisdn))dlsym(dlHandle_sim,"gsw_get_sim_msisdn"); |
| 145 | if (gsw_get_sim_msisdn == NULL) { |
| 146 | printf("dlsym gsw_get_sim_msisdn fail\n"); |
| 147 | return GSW_HAL_FAIL; |
q.huang | 238b22a | 2025-06-10 14:36:59 +0800 | [diff] [blame] | 148 | } |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 149 | |
| 150 | gsw_set_sim_power_down = (int(*)(void))dlsym(dlHandle_sim,"gsw_set_sim_power_down"); |
| 151 | if (gsw_set_sim_power_down == NULL) { |
| 152 | printf("dlsym gsw_set_sim_power_down fail\n"); |
| 153 | return GSW_HAL_FAIL; |
| 154 | } |
| 155 | |
| 156 | gsw_set_sim_power_up = (int(*)(void))dlsym(dlHandle_sim,"gsw_set_sim_power_up"); |
| 157 | if (gsw_set_sim_power_up == NULL) { |
| 158 | printf("dlsym gsw_set_sim_power_up fail\n"); |
| 159 | return GSW_HAL_FAIL; |
| 160 | } |
q.huang | 238b22a | 2025-06-10 14:36:59 +0800 | [diff] [blame] | 161 | |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 162 | return GSW_HAL_SUCCESS; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | |
| 167 | int main() |
| 168 | { |
| 169 | char operator[10]; |
| 170 | int opt; |
| 171 | int ret = -1; |
| 172 | |
| 173 | gsw_sim_api_import(); |
| 174 | |
| 175 | while(1) |
| 176 | { |
| 177 | printf("-1.exit\n"); |
| 178 | printf("1.sim init\n"); |
| 179 | printf("2.sim deinit\n"); |
| 180 | printf("3.imsi : Get IMSI.\n"); |
| 181 | printf("4.iccid : Get ICCID.\n"); |
| 182 | printf("5.msisdn : Get phone number.\n"); |
| 183 | printf("6.sim states\n"); |
| 184 | printf("7.sim power_down\n"); |
| 185 | printf("8.sim power_up\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 186 | printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:"); |
| 187 | |
| 188 | char* temp = NULL; |
| 189 | memset(operator, 0, sizeof(operator)); |
| 190 | temp = fgets(operator, sizeof(operator), stdin); |
| 191 | fflush(stdin); |
| 192 | |
| 193 | printf("temp = %s",temp); |
| 194 | opt = atoi(operator); |
| 195 | switch(opt) |
| 196 | { |
| 197 | case -1: |
| 198 | { |
| 199 | printf("exit\n"); |
| 200 | return 0; |
| 201 | } |
| 202 | //gsw_sim_sdk_init |
| 203 | case 1: |
| 204 | { |
| 205 | printf("sdk_init\n"); |
| 206 | ret = gsw_sim_sdk_init(123); |
| 207 | if(ret == 0) |
| 208 | { |
| 209 | printf("gsw_sim_sdk_init success\n"); |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | printf("gsw_sim_sdk_init fail,ret = %d\n",ret); |
| 214 | } |
| 215 | break; |
| 216 | } |
| 217 | |
| 218 | //sim deinit |
| 219 | case 2: |
| 220 | { |
| 221 | printf("sim deinit\n"); |
| 222 | ret = gsw_sim_sdk_deinit(); |
| 223 | if(ret == 0) |
| 224 | { |
| 225 | printf("gsw_sim_sdk_deinit success\n"); |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | printf("gsw_sim_sdk_deinit fail,ret = %d\n",ret); |
| 230 | } |
| 231 | break; |
| 232 | } |
| 233 | |
| 234 | //imsi |
| 235 | case 3: |
| 236 | { |
| 237 | char imsi[GSW_SIM_IMEI_LENGTH] = {0}; |
| 238 | ret = gsw_get_sim_imsi(GSW_SIM_IMEI_LENGTH, (int8_t *)imsi); |
| 239 | if(ret == 0) |
| 240 | { |
| 241 | printf("gsw_get_sim_imsi success, imsi = %s\n",imsi); |
| 242 | } |
| 243 | else |
| 244 | { |
| 245 | printf("gsw_get_sim_imsi fail,ret = %d\n",ret); |
| 246 | } |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | //iccid |
| 251 | case 4: |
| 252 | { |
| 253 | char iccid[GSW_SIM_ICCID_LENGTH] = {0}; |
| 254 | ret = gsw_get_sim_iccid(GSW_SIM_ICCID_LENGTH, (int8_t *)iccid); |
| 255 | if(ret == 0) |
| 256 | { |
| 257 | printf("gsw_get_sim_iccid success, iccid = %s\n",iccid); |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | printf("gsw_get_sim_iccid fail,ret = %d\n",ret); |
| 262 | } |
| 263 | break; |
| 264 | } |
| 265 | |
| 266 | //msisdn |
| 267 | case 5: |
| 268 | { |
| 269 | char msisdn[GSW_SIM_MSISDN_LENGTH] = {0}; |
| 270 | ret = gsw_get_sim_msisdn(GSW_SIM_MSISDN_LENGTH, (int8_t *)msisdn); |
| 271 | if(ret == 0) |
| 272 | { |
| 273 | printf("gsw_get_sim_msisdn success, msisdn = %s\n",msisdn); |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | printf("gsw_get_sim_msisdn fail,ret = %d\n",ret); |
| 278 | } |
| 279 | break; |
| 280 | } |
| 281 | //sim states |
| 282 | case 6: |
| 283 | { |
| 284 | int sim_state; |
| 285 | printf("start gsw_get_sim_status\n"); |
| 286 | ret = gsw_get_sim_status(&sim_state); |
| 287 | printf("end gsw_get_sim_status\n"); |
| 288 | if(ret == 0) |
| 289 | { |
| 290 | printf("gsw_get_sim_status success,sim_state = %d\n",sim_state); |
| 291 | } |
| 292 | else |
| 293 | { |
| 294 | printf("gsw_get_sim_status fail,ret = %d\n",ret); |
| 295 | } |
| 296 | break; |
| 297 | } |
| 298 | |
| 299 | //sim power_down |
| 300 | case 7: |
| 301 | { |
| 302 | ret = gsw_set_sim_power_down(); |
| 303 | if(ret == 0) |
| 304 | { |
| 305 | printf("gsw_set_sim_power_down success\n"); |
| 306 | } |
| 307 | else |
| 308 | { |
| 309 | printf("gsw_set_sim_power_down fail,ret = %d\n",ret); |
| 310 | } |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | //sim power_up |
| 315 | case 8: |
| 316 | { |
| 317 | ret = gsw_set_sim_power_up(); |
| 318 | if(ret == 0) |
| 319 | { |
| 320 | printf("gsw_set_sim_power_up success\n"); |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | printf("gsw_set_sim_power_up fail,ret = %d\n",ret); |
| 325 | } |
| 326 | break; |
q.huang | 238b22a | 2025-06-10 14:36:59 +0800 | [diff] [blame] | 327 | } |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 328 | default : |
| 329 | { |
| 330 | printf("error cmd.\n"); |
| 331 | continue; |
| 332 | } |
| 333 | |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | } |