blob: f49e6114287ca378e375e8861932e14ced57934c [file] [log] [blame]
b.liu4e243dc2023-11-27 11:20:00 +08001#ifndef __LYNQ_QSER_SIM__
2#define __LYNQ_QSER_SIM__
3#ifdef __cplusplus
4extern "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
12typedef enum
13{
14 E_QSER_SUCCESS = 0, /**< Success. */
15 E_QSER_ERROR_BADPARM = 4, /**< Bad parameter. */
16}E_QSER_ERROR_CODE_T;
17
18typedef uint32_t sim_client_handle_type;
19
20typedef 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
26typedef 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
34typedef 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
wangyouqiang3e3bf922024-01-05 15:38:34 +080040#define QSER_SIM_PIN_LEN_MAX 8 + 1 /** Maximum length of PIN data. */
b.liu4e243dc2023-11-27 11:20:00 +080041
42typedef 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
48typedef 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. */
61typedef 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. */
74typedef 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. */
85typedef QSER_SIM_VERIFY_PIN_INFO_T QSER_SIM_ENABLE_PIN_INFO_T; //Same
86
87/** Disables the PIN of an application, */
88typedef QSER_SIM_VERIFY_PIN_INFO_T QSER_SIM_DISABLE_PIN_INFO_T; //Same
89
90
91typedef 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
104typedef 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
118typedef 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
125typedef 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
132typedef 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
147typedef 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
157typedef 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
172typedef 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
179typedef 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
b.liu8583dce2024-04-03 13:30:08 +0800186typedef QSER_SIM_CARD_STATUS_INFO_T* QSER_SIM_MsgRef;
187/* Callback function registered to qser_sms_addrxmsghandler, msgRef contains the detail msg infor */
188typedef void (*QSER_SIM_RxMsgHandlerFunc_t)(QSER_SIM_MsgRef msgRef);
189
190
b.liu4e243dc2023-11-27 11:20:00 +0800191int qser_sim_client_init(sim_client_handle_type *ph_sim);
192
193int qser_sim_client_deinit(sim_client_handle_type h_sim);
194
195/*===========================================================================
196
197 FUNCTION: qser_sim_getimsi
198
199===========================================================================*/
200/*
201 @brief
202 Function sends a command to the modem to retrieve the IMSI (for 3GPP)
203 or IMSI_M (for 3GPP2) from the SIM in ASCII form
204
205 @return
206 void
207*/
208/*=========================================================================*/
209int qser_sim_getimsi(
210 sim_client_handle_type h_sim,
211 QSER_SIM_APP_ID_INFO_T *pt_info, ///< [IN] The SIM identifier info.
212 char *imsi, ///< [OUT] IMSI buffer
213 size_t imsiLen ///< [IN] IMSI buffer length
214);
215
216
217/*===========================================================================
218
219 FUNCTION: qser_sim_geticcid
220
221===========================================================================*/
222/*
223 @brief
224 Function sends a command to the modem to retrieve the ICCID from
225 SIM in ASCII form
226
227 @return
228 int
229*/
230/*=========================================================================*/
231int qser_sim_geticcid
232(
233 sim_client_handle_type h_sim,
234 QSER_SIM_SLOT_ID_TYPE_T simId, ///< [IN] The SIM identifier.
235 char *iccid, ///< [OUT] ICCID
236 size_t iccidLen ///< [IN] ICCID buffer length
237);
238
239
240/*===========================================================================
241
242 FUNCTION: qser_sim_getphonenumber
243
244===========================================================================*/
245/*
246 @brief
247 Function sends a command to the modem to retrieve the device phone
248 number from MSISDN (for 3GPP) or MDN (for 3GPP2) from the SIM in
249 ASCII form
250
251 @return
252 int
253*/
254/*=========================================================================*/
255int qser_sim_getphonenumber
256(
257 sim_client_handle_type h_sim,
258 QSER_SIM_APP_ID_INFO_T *pt_info, ///< [IN] The SIM identifier.
259 char *phone_num, ///< [OUT] phone number
260 size_t phoneLen ///< [IN] phone number buffer length
261);
262
263/*===========================================================================
264
265 FUNCTION: qser_sim_verifypin
266
267===========================================================================*/
268/*
269 @brief
270 Function sends a command to the modem to verify either PIN1 or PIN2
271
272 @return
273 int
274*/
275/*=========================================================================*/
276int qser_sim_verifypin
277(
278 sim_client_handle_type h_sim,
279 QSER_SIM_VERIFY_PIN_INFO_T *pt_info ///< [IN] Verify PIN infor
280);
281
282
283/*===========================================================================
284
285 FUNCTION: qser_sim_changepin
286
287===========================================================================*/
288/*
289 @brief
290 Function sends a command to the modem to change the value of
291 either PIN1 or PIN2
292
293 @return
294 int
295*/
296/*=========================================================================*/
297int qser_sim_changepin
298(
299 sim_client_handle_type h_sim,
300 QSER_SIM_CHANGE_PIN_INFO_T *pt_info ///< [IN] Change PIN infor
301);
302
303
304/*===========================================================================
305
306 FUNCTION: qser_sim_unblockpin
307
308===========================================================================*/
309/*
310 @brief
311 Function sends a command to the modem to unblock a PIN1 or PIN2 that
312 has been blocked
313
314 @return
315 int
316*/
317/*=========================================================================*/
318int qser_sim_unblockpin
319(
320 sim_client_handle_type h_sim,
321 QSER_SIM_UNBLOCK_PIN_INFO_T *pt_info ///< [IN] Unblock PIN infor
322);
323
324/*===========================================================================
325
326 FUNCTION: qser_sim_enablepin
327
328===========================================================================*/
329/*
330 @brief
331 Function sends a command to the modem to enable PIN1 or PIN2
332
333 @return
334 int
335*/
336/*=========================================================================*/
337int qser_sim_enablepin
338(
339 sim_client_handle_type h_sim,
340 QSER_SIM_ENABLE_PIN_INFO_T *pt_info ///< [IN] Enable PIN infor
341);
342
343/*===========================================================================
344
345 FUNCTION: qser_sim_disablepin
346
347===========================================================================*/
348/*
349 @brief
350 Function sends a command to the modem to disable PIN1 or PIN2
351
352 @return
353 int
354*/
355/*=========================================================================*/
356int qser_sim_disablepin
357(
358 sim_client_handle_type h_sim,
359 QSER_SIM_DISABLE_PIN_INFO_T *pt_info ///< [IN] Disable PIN infor
360);
361
362
363/*===========================================================================
364
365 FUNCTION: qser_sim_getcardstatus
366
367===========================================================================*/
368/*
369 @brief
370 Function retrieves the server cached card status informations and
371 sends the information to the client
372
373 @return
374 int
375*/
376/*=========================================================================*/
377int qser_sim_getcardstatus
378(
379 sim_client_handle_type h_sim,
380 QSER_SIM_SLOT_ID_TYPE_T simId, ///< [IN] The SIM identifier.
381 QSER_SIM_CARD_STATUS_INFO_T *pt_info ///< [OUT] Cart status infor output
382);
383
wangyouqiang3e3bf922024-01-05 15:38:34 +0800384/*===========================================================================
b.liu4e243dc2023-11-27 11:20:00 +0800385
wangyouqiang3e3bf922024-01-05 15:38:34 +0800386 FUNCTION: qser_sim_getimei
387
388===========================================================================*/
389/*
390 @brief
391 get imei
392
393 @return
394 int
395*/
396/*=========================================================================*/
b.liu8583dce2024-04-03 13:30:08 +0800397int qser_sim_getimei(sim_client_handle_type h_sim, char *imei);
398int qser_get_imei_and_sv(sim_client_handle_type h_sim,char *imei, char*sv);
399
wangyouqiang3e3bf922024-01-05 15:38:34 +0800400
401/*===========================================================================
402
403 FUNCTION: qser_get_imei_and_sv
404
405===========================================================================*/
406/*
407 @brief
408 get imei and sv
409
410 @return
411 int
412*/
413/*=========================================================================*/
414int qser_get_imei_and_sv
415(
416 sim_client_handle_type h_sim,
417 char *imei, char*sv
418);
419
420/*===========================================================================
421
422 FUNCTION: qser_reset_modem
423
424===========================================================================*/
425/*
426 @brief
427 reboot modem
428
429 @return
430 int
431*/
432/*=========================================================================*/
b.liu8583dce2024-04-03 13:30:08 +0800433int qser_reset_modem(sim_client_handle_type h_sim);
434
wangyouqiang3e3bf922024-01-05 15:38:34 +0800435
436/*===========================================================================
437
438 FUNCTION: qser_reset_modem
439
440===========================================================================*/
441/*
442 @brief
443 reboot modem
444
445 @return
446 int
447*/
448/*=========================================================================*/
b.liu8583dce2024-04-03 13:30:08 +0800449int qser_get_version(sim_client_handle_type h_sim, char *buf);
450
wangyouqiang3e3bf922024-01-05 15:38:34 +0800451
452/*===========================================================================
453
454 FUNCTION: qser_reset_modem
455
456===========================================================================*/
457/*
458 @brief
459 reboot modem
460
461 @return
462 int
463*/
464/*=========================================================================*/
b.liu8583dce2024-04-03 13:30:08 +0800465int qser_reset_sim(sim_client_handle_type h_sim);
466
467int qser_sim_addrxmsghandler(QSER_SIM_RxMsgHandlerFunc_t handlerPtr);
468
b.liu4e243dc2023-11-27 11:20:00 +0800469#ifdef __cplusplus
470}
471#endif
472
473#endif