b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 1 | /*-----------------------------------------------------------------------------------------------*/ |
| 2 | /** |
| 3 | @file ql_ms_sim.h |
| 4 | @brief subscriber identity module service API, support Dual Sim Dual Active(DSDA). |
| 5 | */ |
| 6 | /*-----------------------------------------------------------------------------------------------*/ |
| 7 | |
| 8 | /*------------------------------------------------------------------------------------------------- |
| 9 | Copyright (c) 2021 Quectel Wireless Solution, Co., Ltd. All Rights Reserved. |
| 10 | Quectel Wireless Solution Proprietary and Confidential. |
| 11 | -------------------------------------------------------------------------------------------------*/ |
| 12 | |
| 13 | /*------------------------------------------------------------------------------------------------- |
| 14 | EDIT HISTORY |
| 15 | This section contains comments describing changes made to the file. |
| 16 | Notice that changes are listed in reverse chronological order. |
| 17 | $Header: $ |
| 18 | when who what, where, why |
| 19 | -------- --- ---------------------------------------------------------- |
| 20 | 20200720 solomon.cui Created . |
| 21 | -------------------------------------------------------------------------------------------------*/ |
| 22 | #ifndef __QL_MS_SIM_H__ |
| 23 | #define __QL_MS_SIM_H__ |
| 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | #include "ql_type.h" |
| 30 | #include "ql_sim.h" |
| 31 | |
| 32 | typedef void (*ql_ms_sim_card_status_cb_f)(int sim_id, ql_sim_card_info_t *p_info); |
| 33 | |
| 34 | /*-----------------------------------------------------------------------------------------------*/ |
| 35 | /** |
| 36 | @brief Initializes SIM service. |
| 37 | @note You must call this function before other functions can be used in this module. |
| 38 | @return Whether the SIM service was intialized successfully. |
| 39 | @retval QL_ERR_OK successful. |
| 40 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 41 | @retval Other error code defined by ql_type.h. |
| 42 | */ |
| 43 | /*-----------------------------------------------------------------------------------------------*/ |
| 44 | int ql_ms_sim_init(void); |
| 45 | |
| 46 | /*-----------------------------------------------------------------------------------------------*/ |
| 47 | /** |
| 48 | @brief Deinitializes SIM service. |
| 49 | @return Whether the SIM service was deintialized successfully. |
| 50 | @retval QL_ERR_OK successful. |
| 51 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 52 | @retval Other error code defined by ql_type.h. |
| 53 | */ |
| 54 | /*-----------------------------------------------------------------------------------------------*/ |
| 55 | int ql_ms_sim_deinit(void); |
| 56 | |
| 57 | /*-----------------------------------------------------------------------------------------------*/ |
| 58 | /** |
| 59 | @brief Gets the IMSI (for 3GPP) or IMSI_M (for 3GPP2) from the SIM in ASCII form. |
| 60 | @param [in] sim_id sim_id to be used. |
| 61 | @param [in] app_type Application type. |
| 62 | @param [out] imsi Buffer to fill IMSI data. |
| 63 | @param [in] imsi_len Buffer length. |
| 64 | @return Whether the IMSI was successfully obtained. |
| 65 | @retval QL_ERR_OK successful. |
| 66 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 67 | @retval Other error code defined by ql_type.h. |
| 68 | */ |
| 69 | /*-----------------------------------------------------------------------------------------------*/ |
| 70 | int ql_ms_sim_get_imsi(int sim_id, QL_SIM_APP_TYPE_E app_type, char *imsi, int imsi_len); |
| 71 | |
| 72 | /*-----------------------------------------------------------------------------------------------*/ |
| 73 | /** |
| 74 | @brief Retrieves the Integrated Circuit Card ID (ICCID) stored on the card. |
| 75 | @param [in] sim_id sim_id to be used. |
| 76 | @param [out] iccid Buffer to fill ICCID data. |
| 77 | @param [in] iccid_len Buffer length. |
| 78 | @return Whether the ICCID was successfully obtained. |
| 79 | @retval QL_ERR_OK successful. |
| 80 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 81 | @retval Other error code defined by ql_type.h. |
| 82 | */ |
| 83 | /*-----------------------------------------------------------------------------------------------*/ |
| 84 | int ql_ms_sim_get_iccid(int sim_id, char *iccid, int iccid_len); |
| 85 | |
| 86 | /*-----------------------------------------------------------------------------------------------*/ |
| 87 | /** |
| 88 | @brief Retrieves the device phone number stored on the card. |
| 89 | @param [in] sim_id sim_id to be used. |
| 90 | @param [in] app_type Application type. |
| 91 | @param [out] phone_num Buffer to fill phone number. |
| 92 | @param [in] phone_num_len Buffer length. |
| 93 | @return Whether the phone number was successfully retrieved. |
| 94 | @retval QL_ERR_OK successful |
| 95 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry |
| 96 | @retval Other error code defined by ql_type.h |
| 97 | */ |
| 98 | /*-----------------------------------------------------------------------------------------------*/ |
| 99 | int ql_ms_sim_get_phone_num(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 100 | char *phone_num, int phone_num_len); |
| 101 | |
| 102 | /*-----------------------------------------------------------------------------------------------*/ |
| 103 | /** |
| 104 | @brief Retrieves the preferred operators stored on the card. |
| 105 | @param [in] sim_id sim_id to be used. |
| 106 | @param [in] list Buffer to hold operators |
| 107 | @note This function is only supported by 3GPP applications. |
| 108 | @return Whether the preferred operators were successfully retrieved. |
| 109 | @retval QL_ERR_OK successful |
| 110 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry |
| 111 | @retval Other error code defined by ql_type.h |
| 112 | */ |
| 113 | /*-----------------------------------------------------------------------------------------------*/ |
| 114 | int ql_ms_sim_get_operators(int sim_id, ql_sim_operator_list_t *list); |
| 115 | |
| 116 | /*-----------------------------------------------------------------------------------------------*/ |
| 117 | /** |
| 118 | @brief Enables the PIN on an application. |
| 119 | @param [in] sim_id sim_id to be used. |
| 120 | @param [in] app_type Application type. |
| 121 | @param [in] pin PIN to be used. |
| 122 | @param [in] pin_value PIN value. NULL terminated. |
| 123 | @return Whether the PIN was successfully enabled. |
| 124 | @retval QL_ERR_OK successful. |
| 125 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 126 | @retval Other error code defined by ql_type.h. |
| 127 | */ |
| 128 | /*-----------------------------------------------------------------------------------------------*/ |
| 129 | int ql_ms_sim_enable_pin(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 130 | QL_SIM_PIN_E pin, const char *pin_value); |
| 131 | |
| 132 | /*-----------------------------------------------------------------------------------------------*/ |
| 133 | /** |
| 134 | @brief Disables the PIN on an application. |
| 135 | @param [in] sim_id sim_id to be used. |
| 136 | @param [in] app_type Application type. |
| 137 | @param [in] pin PIN to be used. |
| 138 | @param [in] pin_value PIN value. NULL terminated. |
| 139 | @return Whether the PIN was successfully disabled. |
| 140 | @retval QL_ERR_OK successful. |
| 141 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 142 | @retval Other error code defined by ql_type.h. |
| 143 | */ |
| 144 | /*-----------------------------------------------------------------------------------------------*/ |
| 145 | int ql_ms_sim_disable_pin(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 146 | QL_SIM_PIN_E pin, const char *pin_value); |
| 147 | |
| 148 | /*-----------------------------------------------------------------------------------------------*/ |
| 149 | /** |
| 150 | @brief Verifies the PIN value of an application. |
| 151 | @param [in] sim_id sim_id to be used. |
| 152 | @param [in] app_type Application type. |
| 153 | @param [in] pin PIN to be used. |
| 154 | @param [in] pin_value PIN value. NULL terminated. |
| 155 | @note PIN must be enabled before calling this function. |
| 156 | @return Whether the PIN was successfully verified. |
| 157 | @retval QL_ERR_OK successful. |
| 158 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 159 | @retval Other error code defined by ql_type.h. |
| 160 | */ |
| 161 | /*-----------------------------------------------------------------------------------------------*/ |
| 162 | int ql_ms_sim_verify_pin(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 163 | QL_SIM_PIN_E pin, const char *pin_value); |
| 164 | |
| 165 | /*-----------------------------------------------------------------------------------------------*/ |
| 166 | /** |
| 167 | @brief Changes the PIN value of an application. |
| 168 | @param [in] sim_id sim_id to be used. |
| 169 | @param [in] app_type Application type. |
| 170 | @param [in] pin PIN to be used. |
| 171 | @param [in] old_pin_value Old PIN value. NULL terminated. |
| 172 | @param [in] new_pin_value New PIN value. NULL terminated. |
| 173 | @return Whether the PIN was successfully changed. |
| 174 | @retval QL_ERR_OK successful. |
| 175 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 176 | @retval Other error code defined by ql_type.h. |
| 177 | */ |
| 178 | /*-----------------------------------------------------------------------------------------------*/ |
| 179 | int ql_ms_sim_change_pin(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 180 | QL_SIM_PIN_E pin, const char *old_pin_value, const char *new_pin_value); |
| 181 | |
| 182 | /*-----------------------------------------------------------------------------------------------*/ |
| 183 | /** |
| 184 | @brief Unblocks a blocked PIN using the PUK code. |
| 185 | @param [in] sim_id sim_id to be used. |
| 186 | @param [in] app_type Application type. |
| 187 | @param [in] pin PIN to be used. |
| 188 | @param [in] puk_value PUK value. NULL terminated. |
| 189 | @param [in] pin_value New PIN value. NULL terminated. |
| 190 | @note The user must pass PUK1 to unblock PIN1 or PUK2 to unblock PIN2. |
| 191 | @return Whether the PIN was successfully unblocked. |
| 192 | @retval QL_ERR_OK successful. |
| 193 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 194 | @retval Other error code defined by ql_type.h. |
| 195 | */ |
| 196 | /*-----------------------------------------------------------------------------------------------*/ |
| 197 | int ql_ms_sim_unblock_pin(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 198 | QL_SIM_PIN_E pin, const char *puk_value, const char *pin_value); |
| 199 | |
| 200 | /*-----------------------------------------------------------------------------------------------*/ |
| 201 | /** |
| 202 | @brief Retrieves the card info stored on a card. |
| 203 | @param [in] sim_id sim_id to be used. |
| 204 | @param [out] p_info Pointer of ql_ms_sim_card_info_t. |
| 205 | @return Whether the card info was successfully retrieved. |
| 206 | @retval QL_ERR_OK successful. |
| 207 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 208 | @retval Other error code defined by ql_type.h. |
| 209 | */ |
| 210 | /*-----------------------------------------------------------------------------------------------*/ |
| 211 | int ql_ms_sim_get_card_info(int sim_id, ql_sim_card_info_t *p_info); |
| 212 | |
| 213 | /*-----------------------------------------------------------------------------------------------*/ |
| 214 | /** |
| 215 | @brief Reads data from a specific file on a specified application on the card. |
| 216 | @param [in] sim_id sim_id to be used. |
| 217 | @param [in] app_type Application type. |
| 218 | @param [inout] p_file Pointer of ql_ms_sim_file_t. |
| 219 | @return Whether the file was successfully read. |
| 220 | @retval QL_ERR_OK successful. |
| 221 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 222 | @retval Other error code defined by ql_type.h. |
| 223 | */ |
| 224 | /*-----------------------------------------------------------------------------------------------*/ |
| 225 | int ql_ms_sim_read_file(int sim_id, QL_SIM_APP_TYPE_E app_type, ql_sim_file_t *p_file); |
| 226 | |
| 227 | /*-----------------------------------------------------------------------------------------------*/ |
| 228 | /** |
| 229 | @brief Writes data to a specific file on a specified application on the card. |
| 230 | @param [in] sim_id sim_id to be used. |
| 231 | @param [in] app_type Application type. |
| 232 | @param [in] p_file Pointer of ql_ms_sim_file_t |
| 233 | @note The type of file is determined by the record number field, |
| 234 | which indicates a transparent file when zero and a record-based file otherwise. |
| 235 | @return Whether the file was successfully written. |
| 236 | @retval QL_ERR_OK successful. |
| 237 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 238 | @retval Other error code defined by ql_type.h. |
| 239 | */ |
| 240 | /*-----------------------------------------------------------------------------------------------*/ |
| 241 | int ql_ms_sim_write_file(int sim_id, QL_SIM_APP_TYPE_E app_type, ql_sim_file_t *p_file); |
| 242 | |
| 243 | /*-----------------------------------------------------------------------------------------------*/ |
| 244 | /** |
| 245 | @brief Retrieves the info of a specific file on a specified application on the card. |
| 246 | @param [in] sim_id sim_id to be used. |
| 247 | @param [in] app_type Application type. |
| 248 | @param [inout] p_info Pointer of ql_ms_sim_file_info_t. |
| 249 | @return Whether the file info was successfully retrieved. |
| 250 | @retval QL_ERR_OK successful. |
| 251 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 252 | @retval Other error code defined by ql_type.h. |
| 253 | */ |
| 254 | /*-----------------------------------------------------------------------------------------------*/ |
| 255 | int ql_ms_sim_get_file_info(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 256 | ql_sim_file_info_t *p_info); |
| 257 | |
| 258 | /*-----------------------------------------------------------------------------------------------*/ |
| 259 | /** |
| 260 | @brief Reads phone book on a specified application on the card. |
| 261 | @param [in] sim_id sim_id to be used. |
| 262 | @param [in] app_type Spplication type. |
| 263 | @param [in] pb_path Phone book path. NULL terminated. |
| 264 | @param [in] record_idx Record index to read. Starts from 1. |
| 265 | @param [out] p_record Pointer of ql_ms_sim_phone_book_record_t. |
| 266 | @return Whether the phone book record was successfully retrieved. |
| 267 | @retval QL_ERR_OK successful. |
| 268 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 269 | @retval Other error code defined by ql_type.h. |
| 270 | */ |
| 271 | /*-----------------------------------------------------------------------------------------------*/ |
| 272 | int ql_ms_sim_read_phone_book(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 273 | const char *pb_path, uint8_t record_idx, |
| 274 | ql_sim_phone_book_record_t *p_record); |
| 275 | |
| 276 | /*-----------------------------------------------------------------------------------------------*/ |
| 277 | /** |
| 278 | @brief Writes phone book on a specified application on the card. |
| 279 | @param [in] sim_id sim_id to be used. |
| 280 | @param [in] app_type Application type. |
| 281 | @param [in] pb_path Phone book path. NULL terminated. |
| 282 | @param [in] record_idx Record index to write. Starts from 1. |
| 283 | @param [in] p_record Pointer of ql_ms_sim_phone_book_record_t. |
| 284 | @note If p_record->name[0] = 0 and p_record->number[0] = 0, record will be deleted. |
| 285 | @return Whether the phone book record was successfully saved. |
| 286 | @retval QL_ERR_OK successful. |
| 287 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 288 | @retval Other error code defined by ql_type.h. |
| 289 | */ |
| 290 | /*-----------------------------------------------------------------------------------------------*/ |
| 291 | int ql_ms_sim_write_phone_book(int sim_id, QL_SIM_APP_TYPE_E app_type, |
| 292 | const char *pb_path, uint8_t record_idx, |
| 293 | ql_sim_phone_book_record_t *p_record); |
| 294 | |
| 295 | /*-----------------------------------------------------------------------------------------------*/ |
| 296 | /** |
| 297 | @brief Opens a logical channel on a UICC card. |
| 298 | @param [in] sim_id sim_id to be used. |
| 299 | @param [out] channel_id Channel opened. |
| 300 | @return Whether the logical channel was successfully opened. |
| 301 | @retval QL_ERR_OK successful. |
| 302 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 303 | @retval Other error code defined by ql_type.h. |
| 304 | */ |
| 305 | /*-----------------------------------------------------------------------------------------------*/ |
| 306 | int ql_ms_sim_open_logical_channel(int sim_id, uint8_t *channel_id); |
| 307 | |
| 308 | /*-----------------------------------------------------------------------------------------------*/ |
| 309 | /** |
| 310 | @brief Closes a logical channel on a UICC card. |
| 311 | @param [in] sim_id sim_id to be used. |
| 312 | @param [in] channel_id Channel to be closed. |
| 313 | @return Whether the logical channel was successfully closed. |
| 314 | @retval QL_ERR_OK successful. |
| 315 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 316 | @retval Other error code defined by ql_type.h. |
| 317 | */ |
| 318 | /*-----------------------------------------------------------------------------------------------*/ |
| 319 | int ql_ms_sim_close_logical_channel(int sim_id, uint8_t channel_id); |
| 320 | |
| 321 | /*-----------------------------------------------------------------------------------------------*/ |
| 322 | /** |
| 323 | @brief Sends an APDU to the card. |
| 324 | @param [in] sim_id sim_id to be used. |
| 325 | @param [in] channel_id Channel to be used. |
| 326 | @param [inout] p_apdu Pointer of ql_ms_sim_apdu_t. |
| 327 | @note You must call ql_ms_sim_open_logical_channel before sending an APDU. |
| 328 | @return Whether the APDU was successfully sent. |
| 329 | @retval QL_ERR_OK successful. |
| 330 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 331 | @retval Other error code defined by ql_type.h. |
| 332 | */ |
| 333 | /*-----------------------------------------------------------------------------------------------*/ |
| 334 | int ql_ms_sim_send_apdu(int sim_id, uint8_t channel_id, ql_sim_apdu_t *p_apdu); |
| 335 | |
| 336 | /*-----------------------------------------------------------------------------------------------*/ |
| 337 | /** |
| 338 | @brief Sets SIM card status callback handler |
| 339 | @param [in] sim_id sim_id to be used. |
| 340 | @param[in] cb call back handler. |
| 341 | @return Whether the card status callback handler was successfully set. |
| 342 | @retval QL_ERR_OK successful. |
| 343 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 344 | @retval Other error code defined by ql_type.h. |
| 345 | */ |
| 346 | /*-----------------------------------------------------------------------------------------------*/ |
| 347 | int ql_ms_sim_set_card_status_cb(int sim_id, ql_ms_sim_card_status_cb_f cb); |
| 348 | /*-----------------------------------------------------------------------------------------------*/ |
| 349 | /** |
| 350 | @brief Registration server error callback. Currently, only if the server exits abnormally, |
| 351 | the callback function will be executed, and the error code is QL_ERR_ABORTED; |
| 352 | @param[in] cb Callback function |
| 353 | @return |
| 354 | QL_ERR_OK - successful |
| 355 | Other - error code defined by ql_type.h |
| 356 | */ |
| 357 | /*-----------------------------------------------------------------------------------------------*/ |
| 358 | int ql_ms_sim_set_service_error_cb(ql_sim_service_error_cb_f cb); |
| 359 | |
| 360 | int ql_ms_sim_switch_slot(int sim_id, QL_SIM_PHY_SLOT_E phy_slot); |
| 361 | int ql_ms_sim_get_active_slots(int sim_id, ql_sim_active_slots_t *p_active_slots); |
| 362 | |
| 363 | #ifdef __cplusplus |
| 364 | } |
| 365 | #endif |
| 366 | |
| 367 | |
| 368 | #endif |
| 369 | |