b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame^] | 1 | #ifndef __LYNQ_QSER_SIM__ |
| 2 | #define __LYNQ_QSER_SIM__ |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | #include <stdint.h> |
| 7 | #include "mbtk_type.h" |
| 8 | |
| 9 | #define QSER_SIM_IMSI_LEN_MAX 16 /** Maximum length of IMSI data. */ |
| 10 | #define QSER_SIM_ICCID_LEN_MAX 20 /** Maximum length of ICCID data. */ |
| 11 | |
| 12 | typedef enum |
| 13 | { |
| 14 | E_QSER_SUCCESS = 0, /**< Success. */ |
| 15 | E_QSER_ERROR_BADPARM = 4, /**< Bad parameter. */ |
| 16 | }E_QSER_ERROR_CODE_T; |
| 17 | |
| 18 | typedef uint32_t sim_client_handle_type; |
| 19 | |
| 20 | typedef enum |
| 21 | { |
| 22 | QSER_SIM_SLOT_ID_1 = 0xB01, /**< Identify card in slot 1. */ |
| 23 | QSER_SIM_SLOT_ID_2 = 0xB02, /**< Identify card in slot 2. */ |
| 24 | }QSER_SIM_SLOT_ID_TYPE_T; |
| 25 | |
| 26 | typedef enum |
| 27 | { |
| 28 | QSER_SIM_APP_TYPE_UNKNOWN = 0xB00, /**< Unknown application type */ |
| 29 | QSER_SIM_APP_TYPE_3GPP = 0xB01, /**< Identify the SIM/USIM application on the card. */ |
| 30 | QSER_SIM_APP_TYPE_3GPP2 = 0xB02, /**< Identify the RUIM/CSIM application on the card. */ |
| 31 | QSER_SIM_APP_TYPE_ISIM = 0xB03, /**< Identify the ISIM application on the card. */ |
| 32 | }QSER_SIM_APP_TYPE_T; |
| 33 | |
| 34 | typedef struct |
| 35 | { |
| 36 | QSER_SIM_SLOT_ID_TYPE_T e_slot_id; /**< Indicates the slot to be used. */ |
| 37 | QSER_SIM_APP_TYPE_T e_app; /**< Indicates the type of the application. */ |
| 38 | }QSER_SIM_APP_ID_INFO_T; /* Type */ |
| 39 | |
| 40 | #define QSER_SIM_PIN_LEN_MAX 8 /** Maximum length of PIN data. */ |
| 41 | |
| 42 | typedef enum |
| 43 | { |
| 44 | QSER_SIM_PIN_ID_1 = 0xB01, /**< Level 1 user verification. */ |
| 45 | QSER_SIM_PIN_ID_2 = 0xB02, /**< Level 2 user verification. */ |
| 46 | }QSER_SIM_PIN_ID_TYPE_T; |
| 47 | |
| 48 | typedef struct |
| 49 | { |
| 50 | QSER_SIM_APP_ID_INFO_T app_info; /**< Application identification information. */ |
| 51 | QSER_SIM_PIN_ID_TYPE_T pin_id; /**< PIN ID. */ |
| 52 | uint32_t pin_value_len; /**< Must be set to the number of elements in pin_value. */ |
| 53 | char pin_value[QSER_SIM_PIN_LEN_MAX]; /* Value of the PIN */ |
| 54 | }QSER_SIM_VERIFY_PIN_INFO_T; |
| 55 | |
| 56 | /** Changes the PIN value of an application. The application must pass both the |
| 57 | new and the old values of the PIN to complete the operation. |
| 58 | The same PIN can be used by multiple sessions (i.e., the PIN is shared |
| 59 | between GSM and RUIM in an ICC card). The PIN is automatically verified |
| 60 | for all the sessions when the command is executed. */ |
| 61 | typedef struct |
| 62 | { |
| 63 | QSER_SIM_APP_ID_INFO_T app_info; /**< Application identification information. */ |
| 64 | QSER_SIM_PIN_ID_TYPE_T pin_id; /**< PIN ID. */ |
| 65 | uint32_t old_pin_value_len; /**< Must be set to the number of elements in old_pin_value. */ |
| 66 | char old_pin_value[QSER_SIM_PIN_LEN_MAX]; /**< Value of the old PIN as a sequence of ASCII characters. */ |
| 67 | uint32_t new_pin_value_len; /**< Must be set to the number of elements in new_pin_value. */ |
| 68 | char new_pin_value[QSER_SIM_PIN_LEN_MAX]; /**< Value of the new PIN as a sequence of ASCII characters. */ |
| 69 | }QSER_SIM_CHANGE_PIN_INFO_T; |
| 70 | |
| 71 | /** Unblocks a blocked PIN using the PUK code. The client must pass PUK1 to unblock PIN1 or PUK2 to unblock PIN2. |
| 72 | The same PIN can be used by multiple sessions (i.e., the PIN is shared between GSM and RUIM in an ICC card). |
| 73 | The PIN is automatically verified for all the sessions when the command is executed. */ |
| 74 | typedef struct |
| 75 | { |
| 76 | QSER_SIM_APP_ID_INFO_T app_info; /**< Application identification information. */ |
| 77 | QSER_SIM_PIN_ID_TYPE_T pin_id; /**< PIN ID. */ |
| 78 | uint32_t puk_value_len; /**< Must be set to the number of elements in puk_value. */ |
| 79 | char puk_value[QSER_SIM_PIN_LEN_MAX]; /**< Value of the PUK as a sequence of ASCII characters. */ |
| 80 | uint32_t new_pin_value_len; /**< Must be set to the number of elements in new_pin_value. */ |
| 81 | char new_pin_value[QSER_SIM_PIN_LEN_MAX]; /**< Value of the new PIN as a sequence of ASCII characters. */ |
| 82 | }QSER_SIM_UNBLOCK_PIN_INFO_T; |
| 83 | |
| 84 | /** Enables the PIN on an application. */ |
| 85 | typedef QSER_SIM_VERIFY_PIN_INFO_T QSER_SIM_ENABLE_PIN_INFO_T; //Same |
| 86 | |
| 87 | /** Disables the PIN of an application, */ |
| 88 | typedef QSER_SIM_VERIFY_PIN_INFO_T QSER_SIM_DISABLE_PIN_INFO_T; //Same |
| 89 | |
| 90 | |
| 91 | typedef enum |
| 92 | { |
| 93 | QSER_SIM_PERSO_FEATURE_TYPE_UNKNOWN = 0xB00, /**< Unknown personalization feature. */ |
| 94 | QSER_SIM_PERSO_FEATURE_TYPE_3GPP_NETWORK = 0xB01, /**< Featurization based on 3GPP MCC and MNC. */ |
| 95 | QSER_SIM_PERSO_FEATURE_TYPE_3GPP_NETWORK_SUBSET = 0xB02, /**< Featurization based on 3GPP MCC, MNC, and IMSI digits 6 and 7. */ |
| 96 | QSER_SIM_PERSO_FEATURE_TYPE_3GPP_SERVICE_PROVIDER = 0xB03, /**< Featurization based on 3GPP MCC, MNC, and GID1. */ |
| 97 | QSER_SIM_PERSO_FEATURE_TYPE_3GPP_CORPORATE = 0xB04, /**< Featurization based on 3GPP MCC, MNC, GID1, and GID2. */ |
| 98 | QSER_SIM_PERSO_FEATURE_TYPE_3GPP_SIM = 0xB05, /**< Featurization based on the 3GPP IMSI. */ |
| 99 | QSER_SIM_PERSO_FEATURE_TYPE_3GPP2_NETWORK_TYPE_1 = 0xB06, /**< Featurization based on 3GPP2 MCC and MNC. */ |
| 100 | QSER_SIM_PERSO_FEATURE_TYPE_3GPP2_NETWORK_TYPE_2 = 0xB07, /**< Featurization based on 3GPP2 IRM code. */ |
| 101 | QSER_SIM_PERSO_FEATURE_TYPE_3GPP2_RUIM = 0xB08, /**< Featurization based on 3GPP2 IMSI_M. */ |
| 102 | }QSER_SIM_PERSO_FEATURE_TYPE_T; |
| 103 | |
| 104 | typedef enum |
| 105 | { |
| 106 | QSER_SIM_CARD_STATE_UNKNOWN = 0xB01, /**< Card state unknown. */ |
| 107 | QSER_SIM_CARD_STATE_ABSENT = 0xB02, /**< Card is absent. */ |
| 108 | QSER_SIM_CARD_STATE_PRESENT = 0xB03, /**< Card is present. */ |
| 109 | QSER_SIM_CARD_STATE_ERROR_UNKNOWN = 0xB04, /**< Unknown error state. */ |
| 110 | QSER_SIM_CARD_STATE_ERROR_POWER_DOWN = 0xB05, /**< Power down. */ |
| 111 | QSER_SIM_CARD_STATE_ERROR_POLL_ERROR = 0xB06, /**< Poll error. */ |
| 112 | QSER_SIM_CARD_STATE_ERROR_NO_ATR_RECEIVED = 0xB07, /**< Failed to receive an answer to reset. */ |
| 113 | QSER_SIM_CARD_STATE_ERROR_VOLT_MISMATCH = 0xB08, /**< Voltage mismatch. */ |
| 114 | QSER_SIM_CARD_STATE_ERROR_PARITY_ERROR = 0xB09, /**< Parity error. */ |
| 115 | QSER_SIM_CARD_STATE_ERROR_SIM_TECHNICAL_PROBLEMS= 0xB0A, /**< Card returned technical problems. */ |
| 116 | }QSER_SIM_CARD_STATE_TYPE_T; /**< Card state. */ |
| 117 | |
| 118 | typedef enum |
| 119 | { |
| 120 | QSER_SIM_CARD_TYPE_UNKNOWN = 0xB00, /**< Unidentified card type. */ |
| 121 | QSER_SIM_CARD_TYPE_ICC = 0xB01, /**< Card of SIM or RUIM type. */ |
| 122 | QSER_SIM_CARD_TYPE_UICC = 0xB02, /**< Card of USIM or CSIM type. */ |
| 123 | }QSER_SIM_CARD_TYPE_T; |
| 124 | |
| 125 | typedef enum |
| 126 | { |
| 127 | QSER_SIM_PROV_STATE_NONE = 0xB00, /**< Nonprovisioning. */ |
| 128 | QSER_SIM_PROV_STATE_PRI = 0xB01, /**< Primary provisioning subscription. */ |
| 129 | QSER_SIM_PROV_STATE_SEC = 0xB02, /**< Secondary provisioning subscription. */ |
| 130 | }QSER_SIM_SUBSCRIPTION_TYPE_T; |
| 131 | |
| 132 | typedef enum |
| 133 | { |
| 134 | QSER_SIM_APP_STATE_UNKNOWN = 0xB00, /**< Application state unknown. */ |
| 135 | QSER_SIM_APP_STATE_DETECTED = 0xB01, /**< Detected state. */ |
| 136 | QSER_SIM_APP_STATE_PIN1_REQ = 0xB02, /**< PIN1 required. */ |
| 137 | QSER_SIM_APP_STATE_PUK1_REQ = 0xB03, /**< PUK1 required. */ |
| 138 | QSER_SIM_APP_STATE_INITALIZATING = 0xB04, /**< Initializing. */ |
| 139 | QSER_SIM_APP_STATE_PERSO_CK_REQ = 0xB05, /**< Personalization control key required. */ |
| 140 | QSER_SIM_APP_STATE_PERSO_PUK_REQ = 0xB06, /**< Personalization unblock key required. */ |
| 141 | QSER_SIM_APP_STATE_PERSO_PERMANENTLY_BLOCKED= 0xB07, /**< Personalization is permanently blocked. */ |
| 142 | QSER_SIM_APP_STATE_PIN1_PERM_BLOCKED = 0xB08, /**< PIN1 is permanently blocked. */ |
| 143 | QSER_SIM_APP_STATE_ILLEGAL = 0xB09, /**< Illegal application state. */ |
| 144 | QSER_SIM_APP_STATE_READY = 0xB0A, /**< Application ready state. @newpage */ |
| 145 | }QSER_SIM_APP_STATE_TYPE_T; |
| 146 | |
| 147 | typedef enum |
| 148 | { |
| 149 | QSER_SIM_PIN_STATE_UNKNOWN = 0xB01, /**< Unknown PIN state. */ |
| 150 | QSER_SIM_PIN_STATE_ENABLED_NOT_VERIFIED = 0xB02, /**< PIN required, but has not been verified. */ |
| 151 | QSER_SIM_PIN_STATE_ENABLED_VERIFIED = 0xB03, /**< PIN required and has been verified. */ |
| 152 | QSER_SIM_PIN_STATE_DISABLED = 0xB04, /**< PIN not required. */ |
| 153 | QSER_SIM_PIN_STATE_BLOCKED = 0xB05, /**< PIN verification has failed too many times and is blocked. Recoverable through PUK verification. */ |
| 154 | QSER_SIM_PIN_STATE_PERMANENTLY_BLOCKED = 0xB06, /**< PUK verification has failed too many times and is not recoverable. */ |
| 155 | }QSER_SIM_PIN_STATE_TYPE_T; |
| 156 | |
| 157 | typedef struct |
| 158 | { |
| 159 | QSER_SIM_SUBSCRIPTION_TYPE_T subscription; /**< Type of subscription (i.e., primary, secondary, etc.). */ |
| 160 | QSER_SIM_APP_STATE_TYPE_T app_state; /**< Current state of the application. */ |
| 161 | QSER_SIM_PERSO_FEATURE_TYPE_T perso_feature; /**< Current personalization state and feature enabled. */ |
| 162 | uint8_t perso_retries; /**< Number of personalization retries. */ |
| 163 | uint8_t perso_unblock_retries; /**< Number of personalization unblock retries. */ |
| 164 | QSER_SIM_PIN_STATE_TYPE_T pin1_state; /**< Current PIN 1 state. */ |
| 165 | uint8_t pin1_num_retries; /**< Number of PIN 1 retries. */ |
| 166 | uint8_t puk1_num_retries; /**< Number of PUK 1 retries. */ |
| 167 | QSER_SIM_PIN_STATE_TYPE_T pin2_state; /**< Current PIN 2 state. */ |
| 168 | uint8_t pin2_num_retries; /**< Number of PIN 2 retries. */ |
| 169 | uint8_t puk2_num_retries; /**< Number of PUK 2 retries. */ |
| 170 | }QSER_SIM_CARD_APP_INFO_T; |
| 171 | |
| 172 | typedef struct |
| 173 | { |
| 174 | QSER_SIM_CARD_APP_INFO_T app_3gpp; /**< Stores 3GPP application information. */ |
| 175 | QSER_SIM_CARD_APP_INFO_T app_3gpp2; /**< Stores 3GPP2 application information. */ |
| 176 | QSER_SIM_CARD_APP_INFO_T app_isim; /**< Stores ISIM application information. */ |
| 177 | }QSER_SIM_CARD_ALL_APP_INFO_T; |
| 178 | |
| 179 | typedef struct |
| 180 | { |
| 181 | QSER_SIM_CARD_STATE_TYPE_T e_card_state;/**< Current card and card error state. */ |
| 182 | QSER_SIM_CARD_TYPE_T e_card_type; /**< Card type. */ |
| 183 | QSER_SIM_CARD_ALL_APP_INFO_T card_app_info; /**< Stores all relevant application information. */ |
| 184 | }QSER_SIM_CARD_STATUS_INFO_T; |
| 185 | |
| 186 | int qser_sim_client_init(sim_client_handle_type *ph_sim); |
| 187 | |
| 188 | int qser_sim_client_deinit(sim_client_handle_type h_sim); |
| 189 | |
| 190 | /*=========================================================================== |
| 191 | |
| 192 | FUNCTION: qser_sim_getimsi |
| 193 | |
| 194 | ===========================================================================*/ |
| 195 | /* |
| 196 | @brief |
| 197 | Function sends a command to the modem to retrieve the IMSI (for 3GPP) |
| 198 | or IMSI_M (for 3GPP2) from the SIM in ASCII form |
| 199 | |
| 200 | @return |
| 201 | void |
| 202 | */ |
| 203 | /*=========================================================================*/ |
| 204 | int qser_sim_getimsi( |
| 205 | sim_client_handle_type h_sim, |
| 206 | QSER_SIM_APP_ID_INFO_T *pt_info, ///< [IN] The SIM identifier info. |
| 207 | char *imsi, ///< [OUT] IMSI buffer |
| 208 | size_t imsiLen ///< [IN] IMSI buffer length |
| 209 | ); |
| 210 | |
| 211 | |
| 212 | /*=========================================================================== |
| 213 | |
| 214 | FUNCTION: qser_sim_geticcid |
| 215 | |
| 216 | ===========================================================================*/ |
| 217 | /* |
| 218 | @brief |
| 219 | Function sends a command to the modem to retrieve the ICCID from |
| 220 | SIM in ASCII form |
| 221 | |
| 222 | @return |
| 223 | int |
| 224 | */ |
| 225 | /*=========================================================================*/ |
| 226 | int qser_sim_geticcid |
| 227 | ( |
| 228 | sim_client_handle_type h_sim, |
| 229 | QSER_SIM_SLOT_ID_TYPE_T simId, ///< [IN] The SIM identifier. |
| 230 | char *iccid, ///< [OUT] ICCID |
| 231 | size_t iccidLen ///< [IN] ICCID buffer length |
| 232 | ); |
| 233 | |
| 234 | |
| 235 | /*=========================================================================== |
| 236 | |
| 237 | FUNCTION: qser_sim_getphonenumber |
| 238 | |
| 239 | ===========================================================================*/ |
| 240 | /* |
| 241 | @brief |
| 242 | Function sends a command to the modem to retrieve the device phone |
| 243 | number from MSISDN (for 3GPP) or MDN (for 3GPP2) from the SIM in |
| 244 | ASCII form |
| 245 | |
| 246 | @return |
| 247 | int |
| 248 | */ |
| 249 | /*=========================================================================*/ |
| 250 | int qser_sim_getphonenumber |
| 251 | ( |
| 252 | sim_client_handle_type h_sim, |
| 253 | QSER_SIM_APP_ID_INFO_T *pt_info, ///< [IN] The SIM identifier. |
| 254 | char *phone_num, ///< [OUT] phone number |
| 255 | size_t phoneLen ///< [IN] phone number buffer length |
| 256 | ); |
| 257 | |
| 258 | /*=========================================================================== |
| 259 | |
| 260 | FUNCTION: qser_sim_verifypin |
| 261 | |
| 262 | ===========================================================================*/ |
| 263 | /* |
| 264 | @brief |
| 265 | Function sends a command to the modem to verify either PIN1 or PIN2 |
| 266 | |
| 267 | @return |
| 268 | int |
| 269 | */ |
| 270 | /*=========================================================================*/ |
| 271 | int qser_sim_verifypin |
| 272 | ( |
| 273 | sim_client_handle_type h_sim, |
| 274 | QSER_SIM_VERIFY_PIN_INFO_T *pt_info ///< [IN] Verify PIN infor |
| 275 | ); |
| 276 | |
| 277 | |
| 278 | /*=========================================================================== |
| 279 | |
| 280 | FUNCTION: qser_sim_changepin |
| 281 | |
| 282 | ===========================================================================*/ |
| 283 | /* |
| 284 | @brief |
| 285 | Function sends a command to the modem to change the value of |
| 286 | either PIN1 or PIN2 |
| 287 | |
| 288 | @return |
| 289 | int |
| 290 | */ |
| 291 | /*=========================================================================*/ |
| 292 | int qser_sim_changepin |
| 293 | ( |
| 294 | sim_client_handle_type h_sim, |
| 295 | QSER_SIM_CHANGE_PIN_INFO_T *pt_info ///< [IN] Change PIN infor |
| 296 | ); |
| 297 | |
| 298 | |
| 299 | /*=========================================================================== |
| 300 | |
| 301 | FUNCTION: qser_sim_unblockpin |
| 302 | |
| 303 | ===========================================================================*/ |
| 304 | /* |
| 305 | @brief |
| 306 | Function sends a command to the modem to unblock a PIN1 or PIN2 that |
| 307 | has been blocked |
| 308 | |
| 309 | @return |
| 310 | int |
| 311 | */ |
| 312 | /*=========================================================================*/ |
| 313 | int qser_sim_unblockpin |
| 314 | ( |
| 315 | sim_client_handle_type h_sim, |
| 316 | QSER_SIM_UNBLOCK_PIN_INFO_T *pt_info ///< [IN] Unblock PIN infor |
| 317 | ); |
| 318 | |
| 319 | /*=========================================================================== |
| 320 | |
| 321 | FUNCTION: qser_sim_enablepin |
| 322 | |
| 323 | ===========================================================================*/ |
| 324 | /* |
| 325 | @brief |
| 326 | Function sends a command to the modem to enable PIN1 or PIN2 |
| 327 | |
| 328 | @return |
| 329 | int |
| 330 | */ |
| 331 | /*=========================================================================*/ |
| 332 | int qser_sim_enablepin |
| 333 | ( |
| 334 | sim_client_handle_type h_sim, |
| 335 | QSER_SIM_ENABLE_PIN_INFO_T *pt_info ///< [IN] Enable PIN infor |
| 336 | ); |
| 337 | |
| 338 | /*=========================================================================== |
| 339 | |
| 340 | FUNCTION: qser_sim_disablepin |
| 341 | |
| 342 | ===========================================================================*/ |
| 343 | /* |
| 344 | @brief |
| 345 | Function sends a command to the modem to disable PIN1 or PIN2 |
| 346 | |
| 347 | @return |
| 348 | int |
| 349 | */ |
| 350 | /*=========================================================================*/ |
| 351 | int qser_sim_disablepin |
| 352 | ( |
| 353 | sim_client_handle_type h_sim, |
| 354 | QSER_SIM_DISABLE_PIN_INFO_T *pt_info ///< [IN] Disable PIN infor |
| 355 | ); |
| 356 | |
| 357 | |
| 358 | /*=========================================================================== |
| 359 | |
| 360 | FUNCTION: qser_sim_getcardstatus |
| 361 | |
| 362 | ===========================================================================*/ |
| 363 | /* |
| 364 | @brief |
| 365 | Function retrieves the server cached card status informations and |
| 366 | sends the information to the client |
| 367 | |
| 368 | @return |
| 369 | int |
| 370 | */ |
| 371 | /*=========================================================================*/ |
| 372 | int qser_sim_getcardstatus |
| 373 | ( |
| 374 | sim_client_handle_type h_sim, |
| 375 | QSER_SIM_SLOT_ID_TYPE_T simId, ///< [IN] The SIM identifier. |
| 376 | QSER_SIM_CARD_STATUS_INFO_T *pt_info ///< [OUT] Cart status infor output |
| 377 | ); |
| 378 | |
| 379 | |
| 380 | #ifdef __cplusplus |
| 381 | } |
| 382 | #endif |
| 383 | |
| 384 | #endif |