blob: bb9f4716a17d1a3db90c52cdd31f9fc504b425c8 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001/*-----------------------------------------------------------------------------------------------*/
2/**
3 @file ql_sim.h
4 @brief SIM service API
5*/
6/*-----------------------------------------------------------------------------------------------*/
7
8/*-------------------------------------------------------------------------------------------------
9 Copyright (c) 2024 mobiletek Wireless Solution, Co., Ltd. All Rights Reserved.
10 mobiletek 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 20241022 yq.wang Created .
21-------------------------------------------------------------------------------------------------*/
22
23#ifndef __QL_SIM_H__
24#define __QL_SIM_H__
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <stdint.h>
31
32#define QL_SIM_IMSI_LENGTH 16 /**< Maximum length of IMSI data. */
33#define QL_SIM_ICCID_LENGTH 20 /**< Maximum length of ICCID data. */
34#define QL_SIM_PUK_LENGTH 8 /**< Maximum length of PUK data. */
35#define QL_SIM_NUM_OPERATOR_MAX 24 /**< Maximum number of operators */
36#define QL_SIM_PATH_MAX 20 /**< Maximum length of a full file path in ASCII format. */
37#define QL_SIM_DATA_MAX 4096 /**< Maximum size of data to be read/written. */
38#define QL_SIM_PIN_MAX 8 /**< Maximum length of PIN data. */
39#define QL_SIM_MAX_NUM_CARDS 2 /**< Maximum number of cards. */
40#define QL_SIM_PHONE_NUMBER_MAX 82 /**< Maximum phone number length. */
41#define QL_SIM_MCC_LENGHT 3 /**< Length of the MCC. */
42#define QL_SIM_MNC_MAX 3 /**< Maximum length of the MNC. */
43
44#define QL_SIM_PHONE_BOOK_NAME_MAX 15 /**< Maximum length of phone book user name. */
45#define QL_SIM_PHONE_BOOK_NUMBER_MAX 25 /**< Maximum length of phone book number. */
46
47#define QL_SIM_APDU_DATA_MAX 1024 /**< Maximum number of APDU data. */
48
49#define QL_SIM_PB_DEFAULT_PATH "3F007F106F3A" /**< Default phone book path. */
50
51/** Ligcial slot */
52/**> Currently only one active slot is supported, so slot should be always QL_SIM_SLOT_1.*/
53typedef enum
54{
55 QL_SIM_SLOT_INVALID = 0x000, /**< Invalid slot. */
56 QL_SIM_SLOT_1 = 0xB01, /**< Identify card in slot 1. */
57 QL_SIM_SLOT_2 = 0xB02, /**< Identify card in slot 2. */
58} QL_SIM_SLOT_E;
59
60/** Physical slot */
61typedef enum
62{
63 QL_SIM_PHY_SLOT_INVALID = 0x000, /**< Invalid slot. */
64 QL_SIM_PHY_SLOT_1 = 0xB01, /**< Identify card in slot 1. */
65 QL_SIM_PHY_SLOT_2 = 0xB02, /**< Identify card in slot 2. */
66} QL_SIM_PHY_SLOT_E;
67
68
69typedef enum
70{
71 QL_SIM_PIN_1 = 0xB01, /**< Level 1 user verification. */
72 QL_SIM_PIN_2 = 0xB02, /**< Level 2 user verification. */
73} QL_SIM_PIN_E;
74
75
76/** Application Type */
77typedef enum
78{
79 QL_SIM_APP_TYPE_UNKNOWN = 0xB00, /**< Unknown application type */
80 QL_SIM_APP_TYPE_3GPP = 0xB01, /**< Identify the SIM/USIM application on the card. */
81 QL_SIM_APP_TYPE_3GPP2 = 0xB02, /**< Identify the RUIM/CSIM application on the card. */
82 QL_SIM_APP_TYPE_ISIM = 0xB03, /**< Identify the ISIM application on the card. */
83} QL_SIM_APP_TYPE_E;
84
85typedef struct
86{
87 char mcc[QL_SIM_MCC_LENGHT]; /**< MCC value in ASCII characters.*/
88 uint8_t mnc_len; /**< The number of elements in the MNC, 2 or 3. */
89 char mnc[QL_SIM_MNC_MAX]; /**< MNC value in ASCII characters.*/
90} ql_sim_operator_t;
91
92typedef struct
93{
94 int len; /**< Length of actual operators */
95 ql_sim_operator_t operators[QL_SIM_NUM_OPERATOR_MAX];
96} ql_sim_operator_list_t;
97
98typedef enum {
99 /** Card state unknown. */
100 QL_SIM_CARD_STATE_UNKNOWN = 0xB01,
101 /** Card is absent. */
102 QL_SIM_CARD_STATE_ABSENT = 0xB02,
103 /** Card is present. */
104 QL_SIM_CARD_STATE_PRESENT = 0xB03,
105 /** Unknown error state. */
106 QL_SIM_CARD_STATE_ERROR_UNKNOWN = 0xB04,
107 /** Power down. */
108 QL_SIM_CARD_STATE_ERROR_POWER_DOWN = 0xB05,
109 /** Poll error. */
110 QL_SIM_CARD_STATE_ERROR_POLL_ERROR = 0xB06,
111 /** Failed to receive an answer to reset. */
112 QL_SIM_CARD_STATE_ERROR_NO_ATR_RECEIVED = 0xB07,
113 /** Voltage mismatch. */
114 QL_SIM_CARD_STATE_ERROR_VOLT_MISMATCH = 0xB08,
115 /** Parity error. */
116 QL_SIM_CARD_STATE_ERROR_PARITY_ERROR = 0xB09,
117 /** Card returned technical problems. */
118 QL_SIM_CARD_STATE_ERROR_SIM_TECHNICAL_PROBLEMS = 0xB0A,
119} QL_SIM_CARD_STATE_E; /**< Card state. */
120
121typedef enum {
122 QL_SIM_SUBSCRIPTION_NONE = 0xB00, /**< Nonprovisioning. */
123 QL_SIM_SUBSCRIPTION_PRI = 0xB01, /**< Primary provisioning subscription. */
124 QL_SIM_SUBSCRIPTION_SEC = 0xB02, /**< Secondary provisioning subscription. */
125} QL_SIM_SUBSCRIPTION_E;
126
127typedef enum
128{
129 QL_SIM_CARD_TYPE_UNKNOWN = 0xB00, /**< Unidentified card type. */
130 QL_SIM_CARD_TYPE_ICC = 0xB01, /**< Card of SIM or RUIM type. */
131 QL_SIM_CARD_TYPE_UICC = 0xB02, /**< Card of USIM or CSIM type. */
132} QL_SIM_CARD_TYPE_E;
133
134typedef enum {
135 QL_SIM_APP_STATE_UNKNOWN = 0xB00, /**< Application state unknown. */
136 QL_SIM_APP_STATE_DETECTED = 0xB01, /**< Detected state. */
137 QL_SIM_APP_STATE_PIN1_REQ = 0xB02, /**< PIN1 required. */
138 QL_SIM_APP_STATE_PUK1_REQ = 0xB03, /**< PUK1 required. */
139 QL_SIM_APP_STATE_INITALIZATING = 0xB04, /**< Initializing. */
140 QL_SIM_APP_STATE_PERSO_CK_REQ = 0xB05, /**< Personalization control key required. */
141 QL_SIM_APP_STATE_PERSO_PUK_REQ = 0xB06, /**< Personalization unblock key required. */
142 QL_SIM_APP_STATE_PERSO_PERMANENTLY_BLOCKED = 0xB07, /**< Personalization is permanently blocked. */
143 QL_SIM_APP_STATE_PIN1_PERM_BLOCKED = 0xB08, /**< PIN1 is permanently blocked. */
144 QL_SIM_APP_STATE_ILLEGAL = 0xB09, /**< Illegal application state. */
145 QL_SIM_APP_STATE_READY = 0xB0A, /**< Application ready state. */
146} QL_SIM_APP_STATE_E;
147
148typedef enum {
149 /** Unknown personalization feature. */
150 QL_SIM_PERSO_FEATURE_UNKNOWN = 0xB00,
151 /** Featurization based on 3GPP MCC and MNC. */
152 QL_SIM_PERSO_FEATURE_3GPP_NETWORK = 0xB01,
153 /** Featurization based on 3GPP MCC, MNC, and IMSI digits 6 and 7. */
154 QL_SIM_PERSO_FEATURE_3GPP_NETWORK_SUBSET = 0xB02,
155 /** Featurization based on 3GPP MCC, MNC, and GID1. */
156 QL_SIM_PERSO_FEATURE_3GPP_SERVICE_PROVIDER = 0xB03,
157 /** Featurization based on 3GPP MCC, MNC, GID1, and GID2. */
158 QL_SIM_PERSO_FEATURE_3GPP_CORPORATE = 0xB04,
159 /** Featurization based on the 3GPP IMSI. */
160 QL_SIM_PERSO_FEATURE_3GPP_SIM = 0xB05,
161 /** Featurization based on 3GPP2 MCC and MNC. */
162 QL_SIM_PERSO_FEATURE_3GPP2_NETWORK_TYPE_1 = 0xB06,
163 /** Featurization based on 3GPP2 IRM code. */
164 QL_SIM_PERSO_FEATURE_3GPP2_NETWORK_TYPE_2 = 0xB07,
165 /** Featurization based on 3GPP2 IMSI_M. */
166 QL_SIM_PERSO_FEATURE_3GPP2_RUIM = 0xB08,
167} QL_SIM_PERSO_FEATURE_E;
168
169typedef enum {
170 /** Unknown PIN state. */
171 QL_SIM_PIN_STATE_UNKNOWN = 0xB01,
172 /** PIN required, but has not been verified. */
173 QL_SIM_PIN_STATE_ENABLED_NOT_VERIFIED = 0xB02,
174 /** PIN required and has been verified. */
175 QL_SIM_PIN_STATE_ENABLED_VERIFIED = 0xB03,
176 /** PIN not required. */
177 QL_SIM_PIN_STATE_DISABLED = 0xB04,
178 /** PIN verification has failed too many times and is blocked. Recoverable through PUK verification. */
179 QL_SIM_PIN_STATE_BLOCKED = 0xB05,
180 /** PUK verification has failed too many times and is not recoverable. */
181 QL_SIM_PIN_STATE_PERMANENTLY_BLOCKED = 0xB06,
182 } QL_SIM_PIN_STATE_E;
183
184typedef struct {
185 /** Type of subscription (i.e., primary, secondary, etc.). */
186 QL_SIM_SUBSCRIPTION_E subscription; /**nonsupport*/
187 /** Current state of the application. */
188 QL_SIM_APP_STATE_E app_state;
189 /** Current personalization state and feature enabled. */
190 QL_SIM_PERSO_FEATURE_E perso_feature; /**nonsupport*/
191 /** Number of personalization retries. */
192 uint8_t perso_retries; /**nonsupport*/
193 /** Number of personalization unblock retries. */
194 uint8_t perso_unblock_retries; /**nonsupport*/
195 /** Current PIN 1 state. */
196 QL_SIM_PIN_STATE_E pin1_state; /**nonsupport*/
197 /** Number of PIN 1 retries. */
198 uint8_t pin1_num_retries;
199 /** Number of PUK 1 retries. */
200 uint8_t puk1_num_retries;
201 /** Current PIN 2 state. */
202 QL_SIM_PIN_STATE_E pin2_state; /**nonsupport*/
203 /** Number of PIN 2 retries. */
204 uint8_t pin2_num_retries;
205 /** Number of PUK 2 retries. */
206 uint8_t puk2_num_retries;
207}ql_sim_app_info_t; /* Type */
208
209typedef struct
210{
211 QL_SIM_CARD_STATE_E state;
212 QL_SIM_CARD_TYPE_E type;
213 ql_sim_app_info_t app_3gpp; /**< Stores 3GPP application information. */
214 ql_sim_app_info_t app_3gpp2; /**< Stores 3GPP2 application information. */
215 ql_sim_app_info_t app_isim; /**< Stores ISIM application information. */
216} ql_sim_card_info_t;
217
218typedef struct {
219 uint32_t path_len; /**< Must be set to the number of elements in the path. */
220 char path[QL_SIM_PATH_MAX]; /**< File path in ASCII characters. */
221 /** Offset is only required for write transparent file access where data length is indicated.*/
222 uint16_t offset;
223 /** Index of records involved in file access. A record index of 0 indicates transparent file access.*/
224 uint8_t record_idx;
225
226 /* == filled by caller when writing file == */
227 uint32_t data_len; /**< When reading file, it's the length of file data been read.
228 When writing file, it's the length of file data to be written. */
229 uint8_t data[QL_SIM_DATA_MAX];
230} ql_sim_file_t; /* Type */
231
232typedef enum {
233 QL_SIM_FILE_TYPE_UNKNOWN = 0xB00, /**< Unknown file type */
234 QL_SIM_FILE_TYPE_TRANSPARENT = 0xB01, /**< File structure consisting of a sequence of bytes. */
235 QL_SIM_FILE_TYPE_CYCLIC = 0xB02, /**< File structure consisting of a sequence of records,
236 each containing the same fixed size in
237 chronological order.Once all the records have been
238 used, the oldest data is overwritten. */
239 QL_SIM_FILE_TYPE_LINEAR_FIXED = 0xB03, /**< File structure consisting of a sequence of records,
240 each containing the same fixed size. */
241} QL_SIM_FILE_TYPE_E;
242
243
244typedef struct {
245 /* == filled by caller == */
246 uint32_t path_len; /**< Must be set to the number of elements in the path. */
247 char path[QL_SIM_PATH_MAX]; /**< File path in ASCII characters. */
248
249 /* == filled by callee == */
250 QL_SIM_FILE_TYPE_E file_type; /**< File type */
251 uint16_t file_size; /**< Size of transparent files.*/
252 uint16_t record_size; /**< Size of each cyclic or linear fixed file record.*/
253 uint16_t record_count; /**< Number of cyclic or linear fixed file records.*/
254} ql_sim_file_info_t; /* Type */
255
256typedef struct
257{
258 /** User name. Null-terminated */
259 char name[QL_SIM_PHONE_BOOK_NAME_MAX];
260 /** Phone number, a '+' can also be preappended to the number. Null-terminated. */
261 char number[QL_SIM_PHONE_BOOK_NUMBER_MAX];
262} ql_sim_phone_book_record_t;
263
264typedef struct
265{
266 uint32_t req_apdu_len; /**< Request APDU data length. */
267 uint8_t req_apdu[QL_SIM_APDU_DATA_MAX]; /**< Request APDU data. */
268
269 uint32_t resp_apdu_len; /**< Response APDU data length. */
270 uint8_t resp_apdu[QL_SIM_APDU_DATA_MAX]; /**< Response APDU data. */
271} ql_sim_apdu_t;
272
273typedef void (*ql_sim_card_status_cb_f)(QL_SIM_SLOT_E slot, ql_sim_card_info_t *p_info);
274
275typedef struct
276{
277 int active_slots_len;
278 QL_SIM_PHY_SLOT_E active_slots[QL_SIM_MAX_NUM_CARDS];
279} ql_sim_active_slots_t;
280
281typedef void (*ql_sim_service_error_cb_f)(int error);
282
283/*-----------------------------------------------------------------------------------------------*/
284/**
285 @brief Initializes SIM service.
286 @note You must call this function before other functions can be used in this module.
287 @return Whether the SIM service was intialized successfully.
288 @retval QL_ERR_OK successful.
289 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
290 @retval Other error code defined by ql_type.h.
291 */
292/*-----------------------------------------------------------------------------------------------*/
293int ql_sim_init(void);
294
295/*-----------------------------------------------------------------------------------------------*/
296/**
297 @brief Deinitializes SIM service.
298 @return Whether the SIM service was deintialized successfully.
299 @retval QL_ERR_OK successful.
300 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
301 @retval Other error code defined by ql_type.h.
302 */
303/*-----------------------------------------------------------------------------------------------*/
304int ql_sim_deinit(void);
305
306/*-----------------------------------------------------------------------------------------------*/
307/**
308 @brief Gets the IMSI (for 3GPP) or IMSI_M (for 3GPP2) from the SIM in ASCII form.
309 @param [in] slot Slot to be used.
310 @param [in] app_type Application type.
311 @param [out] imsi Buffer to fill IMSI data.
312 @param [in] imsi_len Buffer length.
313 @return Whether the IMSI was successfully obtained.
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/*-----------------------------------------------------------------------------------------------*/
319int ql_sim_get_imsi(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type, char *imsi, int imsi_len);
320
321/*-----------------------------------------------------------------------------------------------*/
322/**
323 @brief Retrieves the Integrated Circuit Card ID (ICCID) stored on the card.
324 @param [in] slot Slot to be used.
325 @param [out] iccid Buffer to fill ICCID data.
326 @param [in] iccid_len Buffer length.
327 @return Whether the ICCID was successfully obtained.
328 @retval QL_ERR_OK successful.
329 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
330 @retval Other error code defined by ql_type.h.
331 */
332/*-----------------------------------------------------------------------------------------------*/
333int ql_sim_get_iccid(QL_SIM_SLOT_E slot, char *iccid, int iccid_len);
334
335/*-----------------------------------------------------------------------------------------------*/
336/**
337 @brief Retrieves the device phone number stored on the card.
338 @param [in] slot Slot to be used.
339 @param [in] app_type Application type.
340 @param [out] phone_num Buffer to fill phone number.
341 @param [in] phone_num_len Buffer length.
342 @return Whether the phone number was successfully retrieved.
343 @retval QL_ERR_OK successful
344 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry
345 @retval Other error code defined by ql_type.h
346 */
347/*-----------------------------------------------------------------------------------------------*/
348int ql_sim_get_phone_num(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
349 char *phone_num, int phone_num_len);
350
351/*-----------------------------------------------------------------------------------------------*/
352/**
353 @brief Retrieves the preferred operators stored on the card.
354 @param [in] slot Slot to be used.
355 @param [in] list Buffer to hold operators
356 @note This function is only supported by 3GPP applications.
357 @return Whether the preferred operators were successfully retrieved.
358 @retval QL_ERR_OK successful
359 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry
360 @retval Other error code defined by ql_type.h
361 */
362/*-----------------------------------------------------------------------------------------------*/
363int ql_sim_get_operators(QL_SIM_SLOT_E slot, ql_sim_operator_list_t *list);
364
365/*-----------------------------------------------------------------------------------------------*/
366/**
367 @brief Enables the PIN on an application.
368 @param [in] slot Slot to be used.
369 @param [in] app_type Application type.
370 @param [in] pin PIN to be used.
371 @param [in] pin_value PIN value. NULL terminated.
372 @return Whether the PIN was successfully enabled.
373 @retval QL_ERR_OK successful.
374 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
375 @retval Other error code defined by ql_type.h.
376 */
377/*-----------------------------------------------------------------------------------------------*/
378int ql_sim_enable_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
379 QL_SIM_PIN_E pin, const char *pin_value);
380
381/*-----------------------------------------------------------------------------------------------*/
382/**
383 @brief Disables the PIN on an application.
384 @param [in] slot Slot to be used.
385 @param [in] app_type Application type.
386 @param [in] pin PIN to be used.
387 @param [in] pin_value PIN value. NULL terminated.
388 @return Whether the PIN was successfully disabled.
389 @retval QL_ERR_OK successful.
390 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
391 @retval Other error code defined by ql_type.h.
392 */
393/*-----------------------------------------------------------------------------------------------*/
394int ql_sim_disable_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
395 QL_SIM_PIN_E pin, const char *pin_value);
396
397/*-----------------------------------------------------------------------------------------------*/
398/**
399 @brief Verifies the PIN value of an application.
400 @param [in] slot Slot to be used.
401 @param [in] app_type Application type.
402 @param [in] pin PIN to be used.
403 @param [in] pin_value PIN value. NULL terminated.
404 @note PIN must be enabled before calling this function.
405 @return Whether the PIN was successfully verified.
406 @retval QL_ERR_OK successful.
407 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
408 @retval Other error code defined by ql_type.h.
409 */
410/*-----------------------------------------------------------------------------------------------*/
411int ql_sim_verify_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
412 QL_SIM_PIN_E pin, const char *pin_value);
413
414/*-----------------------------------------------------------------------------------------------*/
415/**
416 @brief Changes the PIN value of an application.
417 @param [in] slot Slot to be used.
418 @param [in] app_type Application type.
419 @param [in] pin PIN to be used.
420 @param [in] old_pin_value Old PIN value. NULL terminated.
421 @param [in] new_pin_value New PIN value. NULL terminated.
422 @return Whether the PIN was successfully changed.
423 @retval QL_ERR_OK successful.
424 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
425 @retval Other error code defined by ql_type.h.
426 */
427/*-----------------------------------------------------------------------------------------------*/
428int ql_sim_change_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
429 QL_SIM_PIN_E pin, const char *old_pin_value, const char *new_pin_value);
430
431/*-----------------------------------------------------------------------------------------------*/
432/**
433 @brief Unblocks a blocked PIN using the PUK code.
434 @param [in] slot Slot to be used.
435 @param [in] app_type Application type.
436 @param [in] pin PIN to be used.
437 @param [in] puk_value PUK value. NULL terminated.
438 @param [in] pin_value New PIN value. NULL terminated.
439 @note The user must pass PUK1 to unblock PIN1 or PUK2 to unblock PIN2.
440 @return Whether the PIN was successfully unblocked.
441 @retval QL_ERR_OK successful.
442 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
443 @retval Other error code defined by ql_type.h.
444 */
445/*-----------------------------------------------------------------------------------------------*/
446int ql_sim_unblock_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
447 QL_SIM_PIN_E pin, const char *puk_value, const char *pin_value);
448
449/*-----------------------------------------------------------------------------------------------*/
450/**
451 @brief Retrieves the card info stored on a card.
452 @param [in] slot Slot to be used.
453 @param [out] p_info Pointer of ql_sim_card_info_t.
454 @return Whether the card info was successfully retrieved.
455 @retval QL_ERR_OK successful.
456 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
457 @retval Other error code defined by ql_type.h.
458 */
459/*-----------------------------------------------------------------------------------------------*/
460int ql_sim_get_card_info(QL_SIM_SLOT_E slot, ql_sim_card_info_t *p_info);
461
462/*-----------------------------------------------------------------------------------------------*/
463/**
464 @brief Reads data from a specific file on a specified application on the card.
465 @param [in] slot Slot to be used.
466 @param [in] app_type Application type.
467 @param [inout] p_file Pointer of ql_sim_file_t.
468 @return Whether the file was successfully read.
469 @retval QL_ERR_OK successful.
470 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
471 @retval Other error code defined by ql_type.h.
472 */
473/*-----------------------------------------------------------------------------------------------*/
474int ql_sim_read_file(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type, ql_sim_file_t *p_file);
475
476/*-----------------------------------------------------------------------------------------------*/
477/**
478 @brief Writes data to a specific file on a specified application on the card.
479 @param [in] slot Slot to be used.
480 @param [in] app_type Application type.
481 @param [in] p_file Pointer of ql_sim_file_t
482 @note The type of file is determined by the record number field,
483 which indicates a transparent file when zero and a record-based file otherwise.
484 @return Whether the file was successfully written.
485 @retval QL_ERR_OK successful.
486 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
487 @retval Other error code defined by ql_type.h.
488 */
489/*-----------------------------------------------------------------------------------------------*/
490int ql_sim_write_file(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type, ql_sim_file_t *p_file);
491
492/*-----------------------------------------------------------------------------------------------*/
493/**
494 @brief Retrieves the info of a specific file on a specified application on the card.
495 @param [in] slot Slot to be used.
496 @param [in] app_type Application type.
497 @param [inout] p_info Pointer of ql_sim_file_info_t.
498 @return Whether the file info was successfully retrieved.
499 @retval QL_ERR_OK successful.
500 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
501 @retval Other error code defined by ql_type.h.
502 */
503/*-----------------------------------------------------------------------------------------------*/
504int ql_sim_get_file_info(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
505 ql_sim_file_info_t *p_info);
506
507/*-----------------------------------------------------------------------------------------------*/
508/**
509 @brief Reads phone book on a specified application on the card.
510 @param [in] slot Slot to be used.
511 @param [in] app_type Spplication type.
512 @param [in] pb_path Phone book path. NULL terminated.
513 @param [in] record_idx Record index to read. Starts from 1.
514 @param [out] p_record Pointer of ql_sim_phone_book_record_t.
515 @return Whether the phone book record was successfully retrieved.
516 @retval QL_ERR_OK successful.
517 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
518 @retval Other error code defined by ql_type.h.
519 */
520/*-----------------------------------------------------------------------------------------------*/
521int ql_sim_read_phone_book(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
522 const char *pb_path, uint8_t record_idx,
523 ql_sim_phone_book_record_t *p_record);
524
525/*-----------------------------------------------------------------------------------------------*/
526/**
527 @brief Writes phone book on a specified application on the card.
528 @param [in] slot Slot to be used.
529 @param [in] app_type Application type.
530 @param [in] pb_path Phone book path. NULL terminated.
531 @param [in] record_idx Record index to write. Starts from 1.
532 @param [in] p_record Pointer of ql_sim_phone_book_record_t.
533 @note If p_record->name[0] = 0 and p_record->number[0] = 0, record will be deleted.
534 @return Whether the phone book record was successfully saved.
535 @retval QL_ERR_OK successful.
536 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
537 @retval Other error code defined by ql_type.h.
538 */
539/*-----------------------------------------------------------------------------------------------*/
540int ql_sim_write_phone_book(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
541 const char *pb_path, uint8_t record_idx,
542 ql_sim_phone_book_record_t *p_record);
543
544/*-----------------------------------------------------------------------------------------------*/
545/**
546 @brief Opens a logical channel on a UICC card.
547 @param [in] slot Slot to be used.
548 @param [out] channel_id Channel opened.
549 @return Whether the logical channel was successfully opened.
550 @retval QL_ERR_OK successful.
551 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
552 @retval Other error code defined by ql_type.h.
553 */
554/*-----------------------------------------------------------------------------------------------*/
555int ql_sim_open_logical_channel(QL_SIM_SLOT_E slot, uint8_t *channel_id);
556
557/*-----------------------------------------------------------------------------------------------*/
558/**
559 @brief Closes a logical channel on a UICC card.
560 @param [in] slot Slot to be used.
561 @param [in] channel_id Channel to be closed.
562 @return Whether the logical channel was successfully closed.
563 @retval QL_ERR_OK successful.
564 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
565 @retval Other error code defined by ql_type.h.
566 */
567/*-----------------------------------------------------------------------------------------------*/
568int ql_sim_close_logical_channel(QL_SIM_SLOT_E slot, uint8_t channel_id);
569
570/*-----------------------------------------------------------------------------------------------*/
571/**
572 @brief Sends an APDU to the card.
573 @param [in] slot Slot to be used.
574 @param [in] channel_id Channel to be used.
575 @param [inout] p_apdu Pointer of ql_sim_apdu_t.
576 @note You must call ql_sim_open_logical_channel before sending an APDU.
577 @return Whether the APDU was successfully sent.
578 @retval QL_ERR_OK successful.
579 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
580 @retval Other error code defined by ql_type.h.
581 */
582/*-----------------------------------------------------------------------------------------------*/
583int ql_sim_send_apdu(QL_SIM_SLOT_E slot, uint8_t channel_id, ql_sim_apdu_t *p_apdu);
584
585/*-----------------------------------------------------------------------------------------------*/
586/**
587 @brief Sets SIM card status callback handler
588 @param[in] cb call back handler.
589 @return Whether the card status callback handler was successfully set.
590 @retval QL_ERR_OK successful.
591 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
592 @retval Other error code defined by ql_type.h.
593 */
594/*-----------------------------------------------------------------------------------------------*/
595int ql_sim_set_card_status_cb(ql_sim_card_status_cb_f cb);
596
597/*-----------------------------------------------------------------------------------------------*/
598/**
599 @brief Switches slot.
600 @param [in] log_slot Logical slot to be switched.
601 @param [in] phy_slot Physical slot to be switched.
602 @return Whether the slot was successfully switched.
603 @retval QL_ERR_OK successful.
604 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
605 @retval Other error code defined by ql_type.h.
606 */
607/*-----------------------------------------------------------------------------------------------*/
608int ql_sim_switch_slot(QL_SIM_SLOT_E log_slot, QL_SIM_PHY_SLOT_E phy_slot);
609
610/*-----------------------------------------------------------------------------------------------*/
611/**
612 @brief Gets active slots.
613 @param [Out] p_active_slots Active slots.
614 @return Whether the active slots were successfully obtained.
615 @retval QL_ERR_OK successful.
616 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
617 @retval Other error code defined by ql_type.h.
618 */
619/*-----------------------------------------------------------------------------------------------*/
620int ql_sim_get_active_slots(ql_sim_active_slots_t *p_active_slots);
621
622/*-----------------------------------------------------------------------------------------------*/
623/**
624 @brief Registration server error callback. Currently, only if the server exits abnormally,
625 the callback function will be executed, and the error code is QL_ERR_ABORTED;
626 @param[in] cb Callback function
627 @return
628 QL_ERR_OK - successful
629 Other - error code defined by ql_type.h
630 */
631/*-----------------------------------------------------------------------------------------------*/
632int ql_sim_set_service_error_cb(ql_sim_service_error_cb_f cb);
633
634//int ql_sim_switch_slot(QL_SIM_SLOT_E log_slot, QL_SIM_PHY_SLOT_E phy_slot);
635//int ql_sim_get_active_slots(ql_sim_active_slots_t *p_active_slots);
636
637#ifdef __cplusplus
638}
639#endif
640
641#endif /* __QL_SIM_H__ */
642