b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame^] | 1 | #include "lynq_qser_sim.h" |
| 2 | #include "mbtk_type.h" |
| 3 | #include "mbtk_info_api.h" |
| 4 | |
| 5 | /****************************DEFINE***************************************/ |
| 6 | #define QSER_RESULT_SUCCESS 0 |
| 7 | #define QSER_RESULT_FAIL -1 |
| 8 | |
| 9 | #define QSER_IMEI_SV_VERSION "01" |
| 10 | |
| 11 | /****************************DEFINE***************************************/ |
| 12 | |
| 13 | /****************************VARIABLE***************************************/ |
| 14 | extern mbtk_info_handle_t* qser_info_handle; |
| 15 | extern int qser_info_handle_num; |
| 16 | static bool inited = FALSE; |
| 17 | static uint qser_h_sim = 0x5F6F7F8F; |
| 18 | static QSER_SIM_RxMsgHandlerFunc_t qser_sim_state_cb = NULL; |
| 19 | static bool qser_sim_cb_state = false; |
| 20 | /****************************VARIABLE***************************************/ |
| 21 | |
| 22 | /******************************FUNC*****************************************/ |
| 23 | void qser_sim_state_change_cb(const void* data, int data_len) |
| 24 | { |
| 25 | uint8 *ptr = (uint8*)data; |
| 26 | LOGE("[qser_sim] SIM state : %d\n", *ptr); |
| 27 | QSER_SIM_CARD_STATUS_INFO_T qser_sim_statue = {0}; |
| 28 | if(*ptr == 0) |
| 29 | { |
| 30 | qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_ABSENT; |
| 31 | } |
| 32 | else if(*ptr == 1) |
| 33 | { |
| 34 | qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_PRESENT; |
| 35 | } |
| 36 | else if(*ptr == 18) |
| 37 | { |
| 38 | qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_ABSENT; |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_UNKNOWN; |
| 43 | } |
| 44 | if(qser_sim_state_cb != NULL) |
| 45 | { |
| 46 | qser_sim_state_cb(&qser_sim_statue); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /******************************FUNC*****************************************/ |
| 51 | |
| 52 | /****************************API***************************************/ |
| 53 | int qser_sim_client_init(sim_client_handle_type *ph_sim) |
| 54 | { |
| 55 | //UNUSED(ph_sim); |
| 56 | if(ph_sim == NULL) |
| 57 | { |
| 58 | LOGE("[qser_sim] ph_sim is NULL."); |
| 59 | return QSER_RESULT_FAIL; |
| 60 | } |
| 61 | |
| 62 | if(!inited && qser_info_handle == NULL) |
| 63 | { |
| 64 | qser_info_handle = mbtk_info_handle_get(); |
| 65 | if(qser_info_handle) |
| 66 | { |
| 67 | qser_info_handle_num++; |
| 68 | inited = TRUE; |
| 69 | //mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | LOGE("[qser_sim] mbtk_info_handle_get() fail."); |
| 74 | return QSER_RESULT_FAIL; |
| 75 | } |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | if(!inited) |
| 80 | { |
| 81 | qser_info_handle_num++; |
| 82 | inited = TRUE; |
| 83 | //mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb); |
| 84 | } |
| 85 | } |
| 86 | *ph_sim = qser_h_sim; |
| 87 | |
| 88 | LOGE("[qser_sim] mbtk_info_handle_get() success."); |
| 89 | return QSER_RESULT_SUCCESS; |
| 90 | } |
| 91 | |
| 92 | int qser_sim_getimsi(sim_client_handle_type h_sim, QSER_SIM_APP_ID_INFO_T *pt_info,char *imsi,size_t imsiLen) |
| 93 | { |
| 94 | //UNUSED(h_sim); |
| 95 | UNUSED(pt_info); |
| 96 | //UNUSED(imsi); |
| 97 | //UNUSED(imsiLen); |
| 98 | |
| 99 | if(h_sim != qser_h_sim) |
| 100 | { |
| 101 | LOGE("[qser_sim] h_sim is error."); |
| 102 | return QSER_RESULT_FAIL; |
| 103 | } |
| 104 | |
| 105 | if(qser_info_handle == NULL) |
| 106 | { |
| 107 | LOGE("[qser_sim] handle is NULL."); |
| 108 | return QSER_RESULT_FAIL; |
| 109 | } |
| 110 | |
| 111 | if(imsi == NULL || imsiLen < 15) |
| 112 | { |
| 113 | LOGE("[qser_sim] imsi is NULL."); |
| 114 | return QSER_RESULT_FAIL; |
| 115 | } |
| 116 | |
| 117 | memset(imsi,0,imsiLen); |
| 118 | int err = mbtk_imsi_get(qser_info_handle, imsi); |
| 119 | if(err) |
| 120 | { |
| 121 | LOGE("[qser_sim] mbtk_imsi_get is fail."); |
| 122 | return QSER_RESULT_FAIL; |
| 123 | } |
| 124 | |
| 125 | if(strlen(imsi) > imsiLen) |
| 126 | { |
| 127 | LOGE("[qser_sim] get datalength out of range."); |
| 128 | return QSER_RESULT_FAIL; |
| 129 | } |
| 130 | |
| 131 | return QSER_RESULT_SUCCESS; |
| 132 | } |
| 133 | |
| 134 | int qser_sim_geticcid(sim_client_handle_type h_sim,QSER_SIM_SLOT_ID_TYPE_T simId,char *iccid, size_t iccidLen) |
| 135 | { |
| 136 | //UNUSED(h_sim); |
| 137 | UNUSED(simId); |
| 138 | //UNUSED(iccid); |
| 139 | //UNUSED(iccidLen); |
| 140 | |
| 141 | if(h_sim != qser_h_sim) |
| 142 | { |
| 143 | LOGE("[qser_sim] h_sim is error."); |
| 144 | return QSER_RESULT_FAIL; |
| 145 | } |
| 146 | |
| 147 | if(qser_info_handle == NULL) |
| 148 | { |
| 149 | LOGE("[qser_sim] handle is NULL."); |
| 150 | return QSER_RESULT_FAIL; |
| 151 | } |
| 152 | |
| 153 | if(iccid == NULL || iccidLen < QSER_SIM_ICCID_LEN_MAX) |
| 154 | { |
| 155 | LOGE("[qser_sim] iccid is NULL."); |
| 156 | return QSER_RESULT_FAIL; |
| 157 | } |
| 158 | |
| 159 | memset(iccid, 0, iccidLen); |
| 160 | int err = mbtk_iccid_get(qser_info_handle, iccid); |
| 161 | if(err) |
| 162 | { |
| 163 | LOGE("[qser_sim] mbtk_iccid_get is fail."); |
| 164 | return QSER_RESULT_FAIL; |
| 165 | } |
| 166 | |
| 167 | if(strlen(iccid) > iccidLen) |
| 168 | { |
| 169 | LOGE("[qser_sim] get datalength out of range."); |
| 170 | return QSER_RESULT_FAIL; |
| 171 | } |
| 172 | |
| 173 | return QSER_RESULT_SUCCESS; |
| 174 | } |
| 175 | |
| 176 | int qser_sim_getphonenumber(sim_client_handle_type h_sim,QSER_SIM_APP_ID_INFO_T *pt_info, char*phone_num, size_t phoneLen) |
| 177 | { |
| 178 | //UNUSED(h_sim); |
| 179 | UNUSED(pt_info); |
| 180 | //UNUSED(phone_num); |
| 181 | //UNUSED(phoneLen); |
| 182 | |
| 183 | if(h_sim != qser_h_sim) |
| 184 | { |
| 185 | LOGE("[qser_sim] h_sim is error."); |
| 186 | return QSER_RESULT_FAIL; |
| 187 | } |
| 188 | |
| 189 | if(qser_info_handle == NULL) |
| 190 | { |
| 191 | LOGE("[qser_sim] handle is NULL."); |
| 192 | return QSER_RESULT_FAIL; |
| 193 | } |
| 194 | |
| 195 | if(phone_num == NULL || phoneLen < 11) |
| 196 | { |
| 197 | LOGE("[qser_sim] phone_num is NULL."); |
| 198 | return QSER_RESULT_FAIL; |
| 199 | } |
| 200 | |
| 201 | memset(phone_num, 0, phoneLen); |
| 202 | int err = mbtk_phone_number_get(qser_info_handle, phone_num); |
| 203 | if(err) |
| 204 | { |
| 205 | LOGE("[qser_sim] mbtk_phone_number_get is fail."); |
| 206 | return QSER_RESULT_FAIL; |
| 207 | } |
| 208 | |
| 209 | if(strlen(phone_num) > phoneLen) |
| 210 | { |
| 211 | LOGE("[qser_sim] get datalength out of range."); |
| 212 | return QSER_RESULT_FAIL; |
| 213 | } |
| 214 | |
| 215 | return QSER_RESULT_SUCCESS; |
| 216 | } |
| 217 | |
| 218 | int qser_sim_verifypin(sim_client_handle_type h_sim,QSER_SIM_VERIFY_PIN_INFO_T *pt_info) |
| 219 | { |
| 220 | //UNUSED(h_sim); |
| 221 | //UNUSED(pt_info); |
| 222 | |
| 223 | if(h_sim != qser_h_sim) |
| 224 | { |
| 225 | LOGE("[qser_sim] h_sim is error."); |
| 226 | return QSER_RESULT_FAIL; |
| 227 | } |
| 228 | |
| 229 | if(qser_info_handle == NULL) |
| 230 | { |
| 231 | LOGE("[qser_sim] handle is NULL."); |
| 232 | return QSER_RESULT_FAIL; |
| 233 | } |
| 234 | |
| 235 | if(pt_info == NULL) |
| 236 | { |
| 237 | LOGE("[qser_sim] pt_info is NULL."); |
| 238 | return QSER_RESULT_FAIL; |
| 239 | } |
| 240 | |
| 241 | int err = mbtk_verify_pin(qser_info_handle, pt_info->pin_value); |
| 242 | if(err) |
| 243 | { |
| 244 | LOGE("[qser_sim] mbtk_verify_pin is fail."); |
| 245 | return QSER_RESULT_FAIL; |
| 246 | } |
| 247 | |
| 248 | return QSER_RESULT_SUCCESS; |
| 249 | } |
| 250 | |
| 251 | int qser_sim_changepin(sim_client_handle_type h_sim,QSER_SIM_CHANGE_PIN_INFO_T *pt_info) |
| 252 | { |
| 253 | //UNUSED(h_sim); |
| 254 | //UNUSED(pt_info); |
| 255 | |
| 256 | if(h_sim != qser_h_sim) |
| 257 | { |
| 258 | LOGE("[qser_sim] h_sim is error."); |
| 259 | return QSER_RESULT_FAIL; |
| 260 | } |
| 261 | |
| 262 | if(qser_info_handle == NULL) |
| 263 | { |
| 264 | LOGE("[qser_sim] handle is NULL."); |
| 265 | return QSER_RESULT_FAIL; |
| 266 | } |
| 267 | |
| 268 | if(pt_info == NULL) |
| 269 | { |
| 270 | LOGE("[qser_sim] pt_info is NULL."); |
| 271 | return QSER_RESULT_FAIL; |
| 272 | } |
| 273 | |
| 274 | mbtk_change_pin_info pin_info = {0}; |
| 275 | memcpy(pin_info.old_pin_value, pt_info->old_pin_value, pt_info->old_pin_value_len); |
| 276 | memcpy(pin_info.new_pin_value, pt_info->new_pin_value, pt_info->new_pin_value_len); |
| 277 | int err = mbtk_change_pin(qser_info_handle, &pin_info); |
| 278 | if(err) |
| 279 | { |
| 280 | LOGE("[qser_sim] mbtk_change_pin is fail."); |
| 281 | return QSER_RESULT_FAIL; |
| 282 | } |
| 283 | |
| 284 | return QSER_RESULT_SUCCESS; |
| 285 | } |
| 286 | |
| 287 | int qser_sim_unblockpin(sim_client_handle_type h_sim, QSER_SIM_UNBLOCK_PIN_INFO_T *pt_info) |
| 288 | { |
| 289 | //UNUSED(h_sim); |
| 290 | //UNUSED(pt_info); |
| 291 | |
| 292 | if(h_sim != qser_h_sim) |
| 293 | { |
| 294 | LOGE("[qser_sim] h_sim is error."); |
| 295 | return QSER_RESULT_FAIL; |
| 296 | } |
| 297 | |
| 298 | if(qser_info_handle == NULL) |
| 299 | { |
| 300 | LOGE("[qser_sim] handle is NULL."); |
| 301 | return QSER_RESULT_FAIL; |
| 302 | } |
| 303 | |
| 304 | if(pt_info == NULL) |
| 305 | { |
| 306 | LOGE("[qser_sim] pt_info is NULL."); |
| 307 | return QSER_RESULT_FAIL; |
| 308 | } |
| 309 | |
| 310 | mbtk_unlock_pin_info puk_pin_info = {0}; |
| 311 | memcpy(puk_pin_info.pin_value, pt_info->new_pin_value, pt_info->new_pin_value_len); |
| 312 | memcpy(puk_pin_info.puk_value, pt_info->puk_value, pt_info->puk_value_len); |
| 313 | int err = mbtk_unlock_pin(qser_info_handle, &puk_pin_info); |
| 314 | if(err) |
| 315 | { |
| 316 | LOGE("[qser_sim] mbtk_unlock_pin is fail."); |
| 317 | return QSER_RESULT_FAIL; |
| 318 | } |
| 319 | |
| 320 | return QSER_RESULT_SUCCESS; |
| 321 | } |
| 322 | |
| 323 | int qser_sim_enablepin(sim_client_handle_type h_sim, QSER_SIM_ENABLE_PIN_INFO_T *pt_info) |
| 324 | { |
| 325 | //UNUSED(h_sim); |
| 326 | //UNUSED(pt_info); |
| 327 | |
| 328 | if(h_sim != qser_h_sim) |
| 329 | { |
| 330 | LOGE("[qser_sim] h_sim is error."); |
| 331 | return QSER_RESULT_FAIL; |
| 332 | } |
| 333 | |
| 334 | if(qser_info_handle == NULL) |
| 335 | { |
| 336 | LOGE("[qser_sim] handle is NULL."); |
| 337 | return QSER_RESULT_FAIL; |
| 338 | } |
| 339 | |
| 340 | if(pt_info == NULL) |
| 341 | { |
| 342 | LOGE("[qser_sim] pt_info is NULL."); |
| 343 | return QSER_RESULT_FAIL; |
| 344 | } |
| 345 | |
| 346 | mbtk_enable_pin_info pin_info = {0}; |
| 347 | memcpy(pin_info.pin_value, pt_info->pin_value, pt_info->pin_value_len); |
| 348 | pin_info.enable = 1; |
| 349 | int err = mbtk_enable_pin(qser_info_handle, &pin_info); |
| 350 | if(err) |
| 351 | { |
| 352 | LOGE("[qser_sim] mbtk_enable_pin is fail."); |
| 353 | return QSER_RESULT_FAIL; |
| 354 | } |
| 355 | |
| 356 | return QSER_RESULT_SUCCESS; |
| 357 | } |
| 358 | |
| 359 | int qser_sim_disablepin(sim_client_handle_type h_sim, QSER_SIM_DISABLE_PIN_INFO_T *pt_info) |
| 360 | { |
| 361 | //UNUSED(h_sim); |
| 362 | //UNUSED(pt_info); |
| 363 | |
| 364 | if(h_sim != qser_h_sim) |
| 365 | { |
| 366 | LOGE("[qser_sim] h_sim is error."); |
| 367 | return QSER_RESULT_FAIL; |
| 368 | } |
| 369 | |
| 370 | if(qser_info_handle == NULL) |
| 371 | { |
| 372 | LOGE("[qser_sim] handle is NULL."); |
| 373 | return QSER_RESULT_FAIL; |
| 374 | } |
| 375 | |
| 376 | if(pt_info == NULL) |
| 377 | { |
| 378 | LOGE("[qser_sim] pt_info is NULL."); |
| 379 | return QSER_RESULT_FAIL; |
| 380 | } |
| 381 | |
| 382 | mbtk_enable_pin_info pin_info = {0}; |
| 383 | memcpy(pin_info.pin_value, pt_info->pin_value, pt_info->pin_value_len); |
| 384 | pin_info.enable = 0; |
| 385 | int err = mbtk_enable_pin(qser_info_handle, &pin_info); |
| 386 | if(err) |
| 387 | { |
| 388 | LOGE("[qser_sim] mbtk_enable_pin is fail."); |
| 389 | return QSER_RESULT_FAIL; |
| 390 | } |
| 391 | |
| 392 | return QSER_RESULT_SUCCESS; |
| 393 | } |
| 394 | |
| 395 | int qser_sim_getcardstatus(sim_client_handle_type h_sim,QSER_SIM_SLOT_ID_TYPE_T simId,QSER_SIM_CARD_STATUS_INFO_T *pt_info) |
| 396 | { |
| 397 | //UNUSED(h_sim); |
| 398 | //UNUSED(simId); |
| 399 | //UNUSED(pt_info); |
| 400 | |
| 401 | if(h_sim != qser_h_sim) |
| 402 | { |
| 403 | LOGE("[qser_sim] h_sim is error."); |
| 404 | return QSER_RESULT_FAIL; |
| 405 | } |
| 406 | |
| 407 | if(qser_info_handle == NULL) |
| 408 | { |
| 409 | LOGE("[qser_sim] handle is NULL."); |
| 410 | return QSER_RESULT_FAIL; |
| 411 | } |
| 412 | |
| 413 | if(pt_info == NULL) |
| 414 | { |
| 415 | LOGE("[qser_sim] pt_info is NULL."); |
| 416 | return QSER_RESULT_FAIL; |
| 417 | } |
| 418 | |
| 419 | mbtk_sim_state_enum sim; |
| 420 | mbtk_sim_card_type_enum sim_card_type; |
| 421 | mbtk_pin_puk_last_times qser_last_times = {0}; |
| 422 | int err = mbtk_sim_state_get(qser_info_handle, &sim); |
| 423 | if(err) |
| 424 | { |
| 425 | LOGE("[qser_sim] mbtk_sim_state_get fail [err = %d].", err); |
| 426 | return QSER_RESULT_FAIL; |
| 427 | } |
| 428 | else |
| 429 | { |
| 430 | LOGE("[qser_sim] sim = %d.", sim); |
| 431 | memset(pt_info, 0x0, sizeof(QSER_SIM_CARD_STATUS_INFO_T)); |
| 432 | switch (sim) |
| 433 | { |
| 434 | case 0: //ABSENT |
| 435 | pt_info->e_card_state = QSER_SIM_CARD_STATE_ABSENT; |
| 436 | break; |
| 437 | case 1: //NOT READY |
| 438 | pt_info->e_card_state = QSER_SIM_CARD_STATE_ABSENT; |
| 439 | break; |
| 440 | case 2: //READY |
| 441 | pt_info->e_card_state = QSER_SIM_CARD_STATE_PRESENT; |
| 442 | break; |
| 443 | case 3: //SIM PIN |
| 444 | pt_info->e_card_state = QSER_SIM_CARD_STATE_PRESENT; |
| 445 | break; |
| 446 | case 4: //SIM PUK |
| 447 | pt_info->e_card_state = QSER_SIM_CARD_STATE_PRESENT; |
| 448 | break; |
| 449 | case 5: //NETWORK |
| 450 | pt_info->e_card_state = QSER_SIM_CARD_STATE_ERROR_SIM_TECHNICAL_PROBLEMS; |
| 451 | break; |
| 452 | default: |
| 453 | pt_info->e_card_state = QSER_SIM_CARD_STATE_UNKNOWN; |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | err = mbtk_sim_card_type_get(qser_info_handle, &sim_card_type); |
| 459 | if(err) |
| 460 | { |
| 461 | LOGE("[qser_sim] mbtk_sim_state_get fail [err = %d].", err); |
| 462 | return QSER_RESULT_FAIL; |
| 463 | } |
| 464 | else |
| 465 | { |
| 466 | if(sim_card_type == 0 || sim_card_type == 2) |
| 467 | pt_info->e_card_type = QSER_SIM_CARD_TYPE_ICC; |
| 468 | else if(sim_card_type == 1 || sim_card_type == 3) |
| 469 | pt_info->e_card_type = QSER_SIM_CARD_TYPE_UICC; |
| 470 | else |
| 471 | pt_info->e_card_type = QSER_SIM_CARD_TYPE_UNKNOWN; |
| 472 | } |
| 473 | |
| 474 | err = mbtk_pin_last_num_get(qser_info_handle, &qser_last_times); |
| 475 | if(err) |
| 476 | { |
| 477 | LOGE("[qser_sim] mbtk_sim_state_get fail [err = %d].", err); |
| 478 | return QSER_RESULT_FAIL; |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | pt_info->card_app_info.app_3gpp.pin1_num_retries = qser_last_times.p1_retry; |
| 483 | pt_info->card_app_info.app_3gpp.pin2_num_retries = qser_last_times.p2_retry; |
| 484 | pt_info->card_app_info.app_3gpp.puk1_num_retries = qser_last_times.puk1_retry; |
| 485 | pt_info->card_app_info.app_3gpp.puk2_num_retries = qser_last_times.puk2_retry; |
| 486 | } |
| 487 | |
| 488 | return QSER_RESULT_SUCCESS; |
| 489 | } |
| 490 | |
| 491 | int qser_sim_getimei(sim_client_handle_type h_sim, char *imei) |
| 492 | { |
| 493 | //UNUSED(h_sim); |
| 494 | //UNUSED(imei); |
| 495 | |
| 496 | if(h_sim != qser_h_sim) |
| 497 | { |
| 498 | LOGE("[qser_sim] h_sim is error."); |
| 499 | return QSER_RESULT_FAIL; |
| 500 | } |
| 501 | |
| 502 | if(qser_info_handle == NULL) |
| 503 | { |
| 504 | LOGE("[qser_sim] handle is NULL."); |
| 505 | return QSER_RESULT_FAIL; |
| 506 | } |
| 507 | |
| 508 | if(imei == NULL) |
| 509 | { |
| 510 | LOGE("[qser_sim] imei is NULL."); |
| 511 | return QSER_RESULT_FAIL; |
| 512 | } |
| 513 | |
| 514 | int err = mbtk_imei_get(qser_info_handle, imei); |
| 515 | if(err) |
| 516 | { |
| 517 | LOGE("[qser_sim] mbtk_imei_get Error : %d\n", err); |
| 518 | return QSER_RESULT_FAIL; |
| 519 | } |
| 520 | return QSER_RESULT_SUCCESS; |
| 521 | } |
| 522 | |
| 523 | int qser_get_imei_and_sv(sim_client_handle_type h_sim,char *imei, char*sv) |
| 524 | { |
| 525 | //UNUSED(h_sim); |
| 526 | //UNUSED(imei); |
| 527 | //UNUSED(sv); |
| 528 | if(h_sim != qser_h_sim) |
| 529 | { |
| 530 | LOGE("[qser_sim] h_sim is error."); |
| 531 | return QSER_RESULT_FAIL; |
| 532 | } |
| 533 | |
| 534 | if(qser_info_handle == NULL) |
| 535 | { |
| 536 | LOGE("[qser_sim] handle is NULL."); |
| 537 | return QSER_RESULT_FAIL; |
| 538 | } |
| 539 | |
| 540 | if(imei == NULL || sv == NULL) |
| 541 | { |
| 542 | LOGE("[qser_sim] param is NULL."); |
| 543 | return QSER_RESULT_FAIL; |
| 544 | } |
| 545 | |
| 546 | int err = mbtk_imei_get(qser_info_handle, imei); |
| 547 | if(err) |
| 548 | { |
| 549 | LOGE("[qser_sim] mbtk_imei_get Error: %d\n", err); |
| 550 | return QSER_RESULT_FAIL; |
| 551 | } |
| 552 | |
| 553 | memcpy(sv, QSER_IMEI_SV_VERSION, strlen(QSER_IMEI_SV_VERSION)); |
| 554 | |
| 555 | return QSER_RESULT_SUCCESS; |
| 556 | } |
| 557 | |
| 558 | int qser_reset_modem(sim_client_handle_type h_sim) |
| 559 | { |
| 560 | //UNUSED(h_sim); |
| 561 | |
| 562 | if(h_sim != qser_h_sim) |
| 563 | { |
| 564 | LOGE("[qser_sim] h_sim is error."); |
| 565 | return QSER_RESULT_FAIL; |
| 566 | } |
| 567 | |
| 568 | if(qser_info_handle == NULL) |
| 569 | { |
| 570 | LOGE("[qser_sim] handle is NULL."); |
| 571 | return QSER_RESULT_FAIL; |
| 572 | } |
| 573 | |
| 574 | for(int cid =0; cid < MBTK_APN_CID_MAX; cid++) |
| 575 | { |
| 576 | mbtk_data_call_stop(qser_info_handle, cid, 1); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | //mbtk_system_reboot(0); |
| 581 | mbtk_modem_info_t info; |
| 582 | info.fun = MBTK_DEV_MODEM_MIN_FUN; |
| 583 | info.rst = 0; |
| 584 | int err = mbtk_set_modem_fun(qser_info_handle, &info); |
| 585 | if(err) |
| 586 | { |
| 587 | LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err); |
| 588 | return QSER_RESULT_FAIL; |
| 589 | } |
| 590 | |
| 591 | info.fun = MBTK_DEV_MODEM_FULL_FUN; |
| 592 | err = mbtk_set_modem_fun(qser_info_handle, &info); |
| 593 | if(err) |
| 594 | { |
| 595 | LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err); |
| 596 | return QSER_RESULT_FAIL; |
| 597 | } |
| 598 | return QSER_RESULT_SUCCESS; |
| 599 | } |
| 600 | |
| 601 | int qser_get_version(sim_client_handle_type h_sim, char *buf) |
| 602 | { |
| 603 | //UNUSED(h_sim); |
| 604 | //UNUSED(buf); |
| 605 | |
| 606 | if(h_sim != qser_h_sim) |
| 607 | { |
| 608 | LOGE("[qser_sim] h_sim is error."); |
| 609 | return QSER_RESULT_FAIL; |
| 610 | } |
| 611 | |
| 612 | if(qser_info_handle == NULL) |
| 613 | { |
| 614 | LOGE("[qser_sim] handle is NULL."); |
| 615 | return QSER_RESULT_FAIL; |
| 616 | } |
| 617 | |
| 618 | if(buf == NULL) |
| 619 | { |
| 620 | LOGE("[qser_sim] buf is NULL."); |
| 621 | return QSER_RESULT_FAIL; |
| 622 | } |
| 623 | |
| 624 | int err = mbtk_version_get(qser_info_handle, buf); |
| 625 | if(err) |
| 626 | { |
| 627 | LOGE("[qser_sim] mbtk_version_get Error : %d\n", err); |
| 628 | return QSER_RESULT_FAIL; |
| 629 | } |
| 630 | return QSER_RESULT_SUCCESS; |
| 631 | } |
| 632 | |
| 633 | int qser_reset_sim(sim_client_handle_type h_sim) |
| 634 | { |
| 635 | //UNUSED(h_sim); |
| 636 | |
| 637 | if(h_sim != qser_h_sim) |
| 638 | { |
| 639 | LOGE("[qser_sim] h_sim is error."); |
| 640 | return QSER_RESULT_FAIL; |
| 641 | } |
| 642 | |
| 643 | if(qser_info_handle == NULL) |
| 644 | { |
| 645 | LOGE("[qser_sim] handle is NULL."); |
| 646 | return QSER_RESULT_FAIL; |
| 647 | } |
| 648 | |
| 649 | //mbtk_sim_power_set(0); |
| 650 | //sleep(1); |
| 651 | //mbtk_sim_power_set(1); |
| 652 | mbtk_modem_info_t info; |
| 653 | info.fun = MBTK_DEV_MODEM_DISABLE_SIM; |
| 654 | info.rst = 0; |
| 655 | int err = mbtk_set_modem_fun(qser_info_handle, &info); |
| 656 | if(err) |
| 657 | { |
| 658 | LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err); |
| 659 | return QSER_RESULT_FAIL; |
| 660 | } |
| 661 | |
| 662 | info.fun = MBTK_DEV_MODEM_FULL_FUN; |
| 663 | err = mbtk_set_modem_fun(qser_info_handle, &info); |
| 664 | if(err) |
| 665 | { |
| 666 | LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err); |
| 667 | return QSER_RESULT_FAIL; |
| 668 | } |
| 669 | return QSER_RESULT_SUCCESS; |
| 670 | } |
| 671 | |
| 672 | int qser_sim_addrxmsghandler(QSER_SIM_RxMsgHandlerFunc_t handlerPtr) |
| 673 | { |
| 674 | if(qser_info_handle == NULL) |
| 675 | { |
| 676 | LOGE("[qser_sim] handle is NULL."); |
| 677 | return QSER_RESULT_FAIL; |
| 678 | } |
| 679 | |
| 680 | if(handlerPtr == NULL) |
| 681 | { |
| 682 | LOGE("[qser_sim] param is NULL."); |
| 683 | qser_sim_state_cb = NULL; |
| 684 | return QSER_RESULT_SUCCESS; |
| 685 | } |
| 686 | |
| 687 | qser_sim_state_cb = handlerPtr; |
| 688 | if(!qser_sim_cb_state) |
| 689 | { |
| 690 | int ret = mbtk_sim_state_change_cb_reg(qser_info_handle, qser_sim_state_change_cb); |
| 691 | if(ret != 0) |
| 692 | { |
| 693 | LOGE("[qser_sim] set cb fail."); |
| 694 | qser_sim_state_cb = NULL; |
| 695 | return QSER_RESULT_FAIL; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | return QSER_RESULT_SUCCESS; |
| 700 | } |
| 701 | |
| 702 | |
| 703 | int qser_sim_client_deinit(sim_client_handle_type h_sim) |
| 704 | { |
| 705 | //UNUSED(h_sim); |
| 706 | if(h_sim != qser_h_sim) |
| 707 | { |
| 708 | LOGE("[qser_sim] h_sim is error."); |
| 709 | return QSER_RESULT_FAIL; |
| 710 | } |
| 711 | |
| 712 | if(qser_info_handle) |
| 713 | { |
| 714 | LOGE("[qser_sim] qser_info_handle_num = %d", qser_info_handle_num); |
| 715 | if(qser_info_handle_num == 1) |
| 716 | { // 最后一个引用,可释放。 |
| 717 | int ret = mbtk_info_handle_free(&qser_info_handle); |
| 718 | if(ret) |
| 719 | { |
| 720 | LOGE("[qser_sim] mbtk_info_handle_free() fail."); |
| 721 | return QSER_RESULT_FAIL; |
| 722 | } |
| 723 | else |
| 724 | { |
| 725 | qser_info_handle_num = 0; |
| 726 | qser_info_handle = NULL; |
| 727 | qser_sim_state_cb = NULL; |
| 728 | inited = FALSE; |
| 729 | } |
| 730 | } |
| 731 | else |
| 732 | { |
| 733 | qser_info_handle_num--; |
| 734 | qser_sim_state_cb = NULL; |
| 735 | } |
| 736 | } |
| 737 | else |
| 738 | { |
| 739 | LOGE("[qser_sim] handle not inited."); |
| 740 | return QSER_RESULT_FAIL; |
| 741 | } |
| 742 | |
| 743 | return QSER_RESULT_SUCCESS; |
| 744 | } |
| 745 | /****************************API***************************************/ |
| 746 | |