blob: 34c5c370ec126751c67490edcf928a64c81584eb [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*******************************************************************************
2 * Copyright (C) 2007, ZTE Corporation.
3 *
4 * File Name: uicc_api.h
5 * File Mark:
6 * Description: Provide UICC module Function prototype declaration
7* and type declaration.
8 * Others:
9 * Version: 1.0
10 * Author: wangxia
11 * Date: 2008-4-18
12 * History 1:
13 * Date:
14 * Version:
15 * Author:
16 * Modification:
17 * History 2:
18 ********************************************************************************/
19
20#ifndef _DRVS_UICC_H
21#define _DRVS_UICC_H
22
23/****************************************************************************
24* Include files
25****************************************************************************/
26#include "pub.h"
27
28/****************************************************************************
29* Macros
30****************************************************************************/
31//#define SOC_USIM
32
33#define DRV_UICC_NOF_CLASSES 5 /*!< The number of specified card classes (A,B,C,D & E) */
34/****************************************************************************
35* Types
36****************************************************************************/
37typedef enum
38{
39 DRV_UICC_TRANSFER_SUCCEEDED,
40 DRV_UICC_TRANSFER_FAILED
41} T_ZDrvUicc_ApduReselt;
42
43/**
44 * \enum T_ZDrvUicc_ResetResult
45 * Response cause for function \ref UICC_reset.
46 */
47typedef enum
48{
49 DRV_UICC_ACTIVATION_SUCCEEDED,
50 DRV_UICC_ACTIVATION_FAILED,
51 DRV_UICC_REJECT_CARD
52} T_ZDrvUicc_ResetResult;
53
54/**
55 * \enum T_ZDrvUicc_CloseResult
56 * Response cause for function \ref UICC_close.
57 */
58typedef enum
59{
60 DRV_UICC_DEACTIVATION_SUCCEEDED,
61 DRV_UICC_DEACTIVATION_FAILED,
62 DRV_UICC_ALREADY_DEACTIVATED
63} T_ZDrvUicc_CloseResult;
64
65/**
66 * \enum T_ZDrvUicc_SetInOutCallBack
67 * Response cause for callback function \ref UICC_set_inout_callback.
68 */
69typedef enum
70{
71 DRV_CALLBACK_FUNCTION_SET, /*!< Callback function registered. */
72 DRV_CALLBACK_NOT_AVAILABLE /*!< Callback function NOT registered (or not supported). */
73} T_ZDrvUicc_SetInOutCallBack;
74
75/**
76 * \enum T_ZDrvUicc_CardSelector
77 * Card selector.
78 */
79typedef enum
80{
81 DRV_UICC_PRIMARY_CARD,
82 DRV_UICC_SECONDARY_CARD_1,
83 DRV_UICC_SECONDARY_CARD_2
84} T_ZDrvUicc_CardSelector;
85
86/**
87 * \enum T_ZDrvUicc_CommandCase
88 * Command case indicator.
89 */
90typedef enum
91{
92 DRV_UICC_CMD_CASE_1, /*!< No Tx nor Tx command. */
93 DRV_UICC_CMD_CASE_2, /*!< Rx command. */
94 DRV_UICC_CMD_CASE_3, /*!< Tx command. */
95 DRV_UICC_CMD_CASE_4 /*!< Tx and Rx command. */
96} T_ZDrvUicc_CommandCase;
97
98/**
99 * \enum T_ZDrvUicc_ResetMode
100 * Reset indicator.
101 */
102typedef enum
103{
104 DRV_UICC_COLD_RESET, /*!< Cold Reset. */
105 DRV_UICC_WARM_RESET /*!< Warm Reset (reset with RST line only). */
106} T_ZDrvUicc_ResetMode;
107
108/**
109 * \enum T_ZDrvUicc_VoltageClass
110 * Voltage CLASS selector.
111 */
112typedef enum
113{
114 DRV_UICC_CLASS_A, /*!< 5v */
115 DRV_UICC_CLASS_B, /*!< 3v */
116 DRV_UICC_CLASS_C, /*!< 1.8v */
117 DRV_UICC_CLASS_D, /*!< RFU */
118 DRV_UICC_CLASS_E /*!< RFU */
119}T_ZDrvUicc_VoltageClass;
120
121/**
122 * \enum T_ZDrvUicc_ClockStopMode
123 * Clock stop level indicator.
124 */
125typedef enum
126{
127 DRV_UICC_CLOCK_STOP_ALLOWED, /*!< Clock Stop NOT allowed. */
128 DRV_UICC_NO_PREFERRED_LEVEL, /*!< Clock allowed, no preferred level requiered. */
129 DRV_UICC_HIGH_LEVEL_PREFERRED, /*!< Clock allowed, High level preferred. */
130 DRV_UICC_LOW_LEVEL_PREFERRED, /*!< Clock allowed, Low level preferred. */
131 DRV_UICC_CLOCK_STOP_NOT_ALLOWED,/*!< Clock Stop NOT allowed. */
132 DRV_UICC_CLOCK_STOP_ONLY_HIGH, /*!< Clock Stop NOT allowed, unless at High level. */
133 DRV_UICC_CLOCK_STOP_ONLY_LOW /*!< Clock Stop NOT allowed, unless at Low level. */
134}T_ZDrvUicc_ClockStopMode;
135
136/**
137 * \enum T_ZDrvUicc_Protocol
138 * Protocol selector.
139 */
140typedef enum
141{
142 DRV_UICC_T_0, /*!< T=0 Protocol. */
143 DRV_UICC_T_1 /*!< T=1 Protocol. */
144}T_ZDrvUicc_Protocol;
145
146/**
147 * \enum T_ZDrvUicc_ComConvention
148 * Communication convention indicator.
149 */
150typedef enum
151{
152 DRV_UICC_DIRECT, /*!< Direct communication convention. */
153 DRV_UICC_INVERSE /*!< Inverse communication convention. */
154}T_ZDrvUicc_ComConvention;
155
156/**
157 * \enum T_ZDrvUicc_CardAction
158 * Card In/Out indicator.
159 */
160typedef enum
161{
162 DRV_CARD_INSERTED,
163 DRV_CARD_REMOVED
164} T_ZDrvUicc_CardAction;
165/**
166 * \}
167 */
168
169
170 /**
171 * \struct T_ZDrvUicc_ApduHeader
172 * Structure holding the APDU command header.
173 */
174typedef struct
175{
176 UINT8 cla; /*!< Command CLAss. */
177 UINT8 ins; /*!< Command INStruction. */
178 UINT8 p1; /*!< Command Parameter. */
179 UINT8 p2; /*!< Command Parameter. */
180 UINT16 lc; /*!< Tx-size. */
181 UINT16 le; /*!< Rx-Size. */
182} T_ZDrvUicc_ApduHeader;
183
184
185/**
186 * \struct T_ZDrvUicc_ApduFooter
187 * Structure holding the APDU command response 'header'.
188 */
189typedef struct
190{
191 UINT16 luicc; /*!< Actual Rx-size recived. */
192 UINT8 sw1; /*!< Received Status Word SW1. */
193 UINT8 sw2; /*!< Received Status Word SW2. */
194} T_ZDrvUicc_ApduFooter;
195
196
197/**
198 * \enum T_ZDrvUicc_CardType
199 * card type.
200 */
201typedef enum
202{
203 DRV_UICC_CARD_TYPE_2G,
204 DRV_UICC_CARD_TYPE_3G,
205
206 UICC_MAX
207 }T_ZDrvUicc_CardType;
208
209
210
211/**
212 * \struct T_ZDrvUicc_VoltageControl
213 * Voltage control structure.
214 */
215typedef struct
216{
217 T_ZDrvUicc_VoltageClass used_voltage; /*!< Actual used voltage class/level. */
218 BOOL voltage_settled; /*!< Indicates if the voltages level has
219 been settled. This can only happen
220 if the card did indicate the voltage
221 capabilities in the ATR string. */
222} T_ZDrvUicc_VoltageControl;
223
224/**
225 * \struct T_ZDrvUicc_Characteristics
226 * Protocol characteristics structure.
227 */
228typedef struct
229{
230 T_ZDrvUicc_Protocol protocol; /*!< Protocol supported and used. */
231 UINT8 f_used; /*!< The used clock rate convention factor (F). */
232 UINT8 f_offered; /*!< The offered clock rate convention factor (F). */
233 UINT8 d_used; /*!< The used baud rate adjustment factor (D). */
234 UINT8 d_offered; /*!< The offered baud rate adjustment factor (D). */
235 T_ZDrvUicc_ComConvention com_convention; /*!< The supported and used communication convention. */
236} T_ZDrvUicc_Characteristics;
237
238/**
239 * \struct T_ZDrvUicc_ElectricalProfile
240 * Electrical Baseband characteristics structure.
241 */
242typedef struct
243{
244 BOOL class_supported; /*!< Indicates if the class is supported or not. */
245 UINT16 voltage_level; /*!< Holds the voltage level given in millivolts [mV]. E.g. 1800 is
246 equivalent to 1.8v). */
247 UINT16 max_current; /*!< The maximum allowed current consumption at this voltage_level
248 given in micro Ampere (uA). E.g. 15500 is equivalent to 15.5mA. */
249} T_ZDrvUicc_ElectricalProfile;
250
251/**
252 * \struct T_ZDrvUicc_ClockProfile
253 * Baseband Clock characteristics.
254 */
255typedef struct
256{
257 UINT8 min_clock_freq; /*!< The minimum clock frequency supported by the HW. */
258 UINT8 max_clock_freq; /*!< The maximum clock frequency supported by the HW. If only
259 one frequency is supported, the min. and max. values will
260 be identical. The frequency resolution is 0.1 MHz i.e. 21h
261 is equivalent to 3.3MHz. */
262}T_ZDrvUicc_ClockProfile;
263
264/**
265 * \struct T_ZDrvUicc_HwProfile
266 * Baseband Clock characteristics.
267 */
268typedef struct
269{
270 UINT8 nof_card_slots_supported;
271 /*!< Number of card reader slots supported by HW.\n
272 * 1: Only primary slot (uicc_primary_card)\n
273 * 2: Primary and ONE additional slot (uicc_secondary_card_1)\n
274 * 3: Primary and TWO additional slots (uicc_secondary_card_1 & uicc_secondary_card_2) */
275
276 UINT8 protocol_supported;
277 /*!< Protocols supported by the DRV_UICC Handler.\n
278 * b1: T=0 supported\n
279 * b2: T=1 supported\n
280 * b3: T=x supported\n
281 * E.g. 0x03 means that both T=0 and T=1 are supported */
282
283 T_ZDrvUicc_ElectricalProfile electrical_profile[DRV_UICC_NOF_CLASSES];
284 /*!< Holds the electrical profile of the specified classes - where
285 * the max. allowed current consumption is indicated for each class. */
286
287 T_ZDrvUicc_ClockProfile clock_profile;
288 /*!< Holds the minimum and maximum clock frequencies supported by the
289 * hardware. */
290
291 BOOL extended_length;
292 /*!< Indicates the driver support of the use of extended Lc/Le.\n
293 * TRUE: extended Lc/Le is supported by the driver. The max. Tx and
294 * Rx data sizes are 65,535 and 65,536 bytes respectively.\n
295 * FALSE: extended Lc/Le is NOT supported by the driver. The max. Tx
296 * and Rx data sizes are 255 and 256 bytes respectively.\n
297 * NOTE: this feature is currently NOT supported! */
298} T_ZDrvUicc_HwProfile;
299
300typedef enum {
301 CARD_INSERTED,
302 CARD_REMOVED
303} T_UICC_CARD_ACTION;
304
305typedef enum {
306 UICC_PRIMARY_CARD,
307 UICC_SECONDARY_CARD_1,
308 // UICC_SECONDARY_CARD_2
309} T_UICC_CARD_SELECTOR;
310
311typedef enum {
312 UICC_CARD, //0
313 VSIM_CARD, //3
314 UICC_VSIM_AUTO,
315 UICC_ESIM_CARD,
316 CLOUD_CARD, //1//1
317 SOFTSIM_CARD, //2//2
318 UICC_VSIM_MAX
319} T_UICC_CARD_TYPE;
320/****************************************************************************
321* Constants
322****************************************************************************/
323
324/****************************************************************************
325* Global Variables
326****************************************************************************/
327
328/****************************************************************************
329* Function Prototypes
330****************************************************************************/
331
332/*!
333 * Function used to exchange APDU with a card. The function will not return
334 * before the response APDU has beed received from the card or until the
335 * appropriate Working Timer has expired.
336 *
337 * \param card_selector (I) Indicates which card the requested command is meant for.
338 * \param command_case (I) Indicates which of the four command cases the current
339 * command belongs to.
340 * \param extended_length (I) Indicates the card support of the use of extended Lc/Le.
341 * The caller of this function has the responsibility of
342 * allocating the apdu_data store correcesponding to the
343 * larger of Lc and Le.\n
344 * TRUE: extended Lc/Le is supported. The max. Tx and Rx
345 * data sizes are 65,535 and 65,536 bytes respectively.\n
346 * FALSE: extended Lc/Le is NOT supported. The max. Tx and Rx
347 * data sizes are 255 and 256 bytes respectively.
348 * \param c_apdu (I) The Command APDU containing: CLA, INS, P1, P2, Lc & Le.
349 * \param r_apdu (O) The Response APDU containing: Luicc, SW1 & SW2.
350 * \param apdu_data (I/O) I: Holds Lc Tx-data to be sent to the card.
351 * O: Holds Luicc Rx-data received from the card.
352 * \return The result of the APDU command execution.
353 */
354
355extern T_ZDrvUicc_ApduReselt zDrvUicc_TransportApdu(T_ZDrvUicc_CardSelector card_selector,
356 T_ZDrvUicc_CommandCase command_case,
357 BOOL extended_length,
358 T_ZDrvUicc_ApduHeader c_apdu,
359 T_ZDrvUicc_ApduFooter *r_apdu_ptr,
360 UINT8 *apdu_data_ptr);
361
362
363/*!
364 * Function used to reset the card. The function will not return until the reset
365 * has been successfully carried out i.e. ATR string has been received or if no
366 * response to the reset is received i.e. IWT times out.
367 * \param card_selector (I) Indicates which card needs to be activated/reset.
368 * \return The outcome of the activation handling.
369 */
370 extern T_ZDrvUicc_ResetResult zDrvUicc_ResetCard(T_ZDrvUicc_CardSelector card_selector);
371
372
373/*!
374 * Function used to deactivat a given card.
375 * \param card_selector (I) Indicates which card needs to be deactivated.
376 * \return The deactivation result.
377 */
378 extern T_ZDrvUicc_CloseResult zDrvUicc_Close(T_ZDrvUicc_CardSelector card_selector);
379
380/*!
381 * Function for Informing the DRV_UICC Handler of the card characteristics of the current used card.
382 * \param card_selector (I) Indicates which card the characteristics are valid for.
383 * \param clock_stop_mode (I) Holds the Clock Stop capabilities indicated by the card.
384 * \param min_clock_freq (I) Holds the minimum acceptable clock frequency for the
385 * card/application. The frequency resolution is 0.1 MHz
386 * i.e. 21h is equivalent to 3.3MHz.
387 * \return None.
388 */
389 extern VOID zDrvUicc_CardCharacteristics(T_ZDrvUicc_CardSelector card_selector,
390 T_ZDrvUicc_ClockStopMode clock_stop_mode,
391 UINT8 min_clock_freq);
392/*!
393 * Returns an overview of the static profile of the HW related interface.
394 * \return The static characteristics (e.g. number of card slots, voltage
395 * levels, max. current cunsumption, supported transmission protocols
396 * etc.
397 */
398 extern T_ZDrvUicc_HwProfile zDrvUicc_HwProfile(VOID);
399
400/*!
401 * Used for initializing the callback function used when the in/out state of the
402 * card changes.
403 * \param inout_call_back (I) Pointer to the function to be invoked when the
404 * in/out state changes. The parameter to the call
405 * back function shall indicated the related card
406 * reader and the IN or OUT action.
407 * \return The outcome of the requested action.
408 */
409 extern T_ZDrvUicc_SetInOutCallBack zDrvUicc_SetInOutCallBack( VOID (*inout_call_back)(T_ZDrvUicc_CardAction card_action, T_ZDrvUicc_CardSelector card_selector));
410 /*!
411 * Used for initializing the callback function used when the in/out state of the
412 * card changes.
413 * \param
414 * \return The outcome of the requested action.
415 */
416 extern T_ZDrvUicc_SetInOutCallBack zDrvUicc_UninstallInOutCallBack(VOID);
417
418/*!
419 * Function used to obtain the ATR string of the current operated card. If no card
420 * is active (or if data is not available) the number of characters returned will
421 * be set to zero.
422 * \param atr Pointer to the store in which the ATR string should be located.
423 * \return Number of ATR characters.
424 */
425 extern UINT8 zDrvUicc_GetAtr(T_ZDrvUicc_CardSelector card_selector, UINT8 *atr);
426
427
428extern VOID zDrvUicc_Highisr(VOID);
429
430extern void invoke_callback(T_UICC_CARD_ACTION card_action, T_UICC_CARD_SELECTOR card_selector);
431
432typedef void (*recoverCallback_func)(void);
433void uicc_setRecover_callback(recoverCallback_func func);
434
435typedef UINT8 (*simStatuCallback_func)(void);
436void uicc_getSimStatu_callback(simStatuCallback_func func);
437#define UICC_SIM_PLUGIN 0x11
438#define UICC_SIM_PLUGOUT 0x10
439
440typedef void (*hotplugCallback_func)(UINT32);
441
442void uicc_set_hotplugCallback(hotplugCallback_func func);
443
444typedef void (*simSwitchCallback_fun)(void);
445void uicc_setUsimSwitch_callback(simSwitchCallback_fun func);
446
447SINT32 uiccramlog_Printf(const VOID *pFormat, ...);
448
449extern SINT32 ramlog_Printf(UINT16 nModNo, const VOID *pFormat, ...);
450
451#ifdef UICC_ENABLE_REALTIME_PRINT
452#define zDrvUiccRamlog_PRINTF(nModNo, s...) uiccramlog_Printf(s)
453#else
454#ifdef _USE_RAMLOG
455#define zDrvUiccRamlog_PRINTF(nModNo, s...) ramlog_Printf(nModNo, s)
456#endif
457#endif
458
459#endif /* _DRVSUICC_H */
460/** \} */
461 /* End of file. */
462