blob: 4a789dba5f7d98062827b0dec8467b7b439f325c [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -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,
313 VSIM_CARD,
314 UICC_VSIM_AUTO,
315 UICC_ESIM_CARD,
316 UICC_VSIM_MAX
317} T_UICC_CARD_TYPE;
318/****************************************************************************
319* Constants
320****************************************************************************/
321
322/****************************************************************************
323* Global Variables
324****************************************************************************/
325
326/****************************************************************************
327* Function Prototypes
328****************************************************************************/
329
330/*!
331 * Function used to exchange APDU with a card. The function will not return
332 * before the response APDU has beed received from the card or until the
333 * appropriate Working Timer has expired.
334 *
335 * \param card_selector (I) Indicates which card the requested command is meant for.
336 * \param command_case (I) Indicates which of the four command cases the current
337 * command belongs to.
338 * \param extended_length (I) Indicates the card support of the use of extended Lc/Le.
339 * The caller of this function has the responsibility of
340 * allocating the apdu_data store correcesponding to the
341 * larger of Lc and Le.\n
342 * TRUE: extended Lc/Le is supported. The max. Tx and Rx
343 * data sizes are 65,535 and 65,536 bytes respectively.\n
344 * FALSE: extended Lc/Le is NOT supported. The max. Tx and Rx
345 * data sizes are 255 and 256 bytes respectively.
346 * \param c_apdu (I) The Command APDU containing: CLA, INS, P1, P2, Lc & Le.
347 * \param r_apdu (O) The Response APDU containing: Luicc, SW1 & SW2.
348 * \param apdu_data (I/O) I: Holds Lc Tx-data to be sent to the card.
349 * O: Holds Luicc Rx-data received from the card.
350 * \return The result of the APDU command execution.
351 */
352
353extern T_ZDrvUicc_ApduReselt zDrvUicc_TransportApdu(T_ZDrvUicc_CardSelector card_selector,
354 T_ZDrvUicc_CommandCase command_case,
355 BOOL extended_length,
356 T_ZDrvUicc_ApduHeader c_apdu,
357 T_ZDrvUicc_ApduFooter *r_apdu_ptr,
358 UINT8 *apdu_data_ptr);
359
360
361/*!
362 * Function used to reset the card. The function will not return until the reset
363 * has been successfully carried out i.e. ATR string has been received or if no
364 * response to the reset is received i.e. IWT times out.
365 * \param card_selector (I) Indicates which card needs to be activated/reset.
366 * \return The outcome of the activation handling.
367 */
368 extern T_ZDrvUicc_ResetResult zDrvUicc_ResetCard(T_ZDrvUicc_CardSelector card_selector);
369
370
371/*!
372 * Function used to deactivat a given card.
373 * \param card_selector (I) Indicates which card needs to be deactivated.
374 * \return The deactivation result.
375 */
376 extern T_ZDrvUicc_CloseResult zDrvUicc_Close(T_ZDrvUicc_CardSelector card_selector);
377
378/*!
379 * Function for Informing the DRV_UICC Handler of the card characteristics of the current used card.
380 * \param card_selector (I) Indicates which card the characteristics are valid for.
381 * \param clock_stop_mode (I) Holds the Clock Stop capabilities indicated by the card.
382 * \param min_clock_freq (I) Holds the minimum acceptable clock frequency for the
383 * card/application. The frequency resolution is 0.1 MHz
384 * i.e. 21h is equivalent to 3.3MHz.
385 * \return None.
386 */
387 extern VOID zDrvUicc_CardCharacteristics(T_ZDrvUicc_CardSelector card_selector,
388 T_ZDrvUicc_ClockStopMode clock_stop_mode,
389 UINT8 min_clock_freq);
390/*!
391 * Returns an overview of the static profile of the HW related interface.
392 * \return The static characteristics (e.g. number of card slots, voltage
393 * levels, max. current cunsumption, supported transmission protocols
394 * etc.
395 */
396 extern T_ZDrvUicc_HwProfile zDrvUicc_HwProfile(VOID);
397
398/*!
399 * Used for initializing the callback function used when the in/out state of the
400 * card changes.
401 * \param inout_call_back (I) Pointer to the function to be invoked when the
402 * in/out state changes. The parameter to the call
403 * back function shall indicated the related card
404 * reader and the IN or OUT action.
405 * \return The outcome of the requested action.
406 */
407 extern T_ZDrvUicc_SetInOutCallBack zDrvUicc_SetInOutCallBack( VOID (*inout_call_back)(T_ZDrvUicc_CardAction card_action, T_ZDrvUicc_CardSelector card_selector));
408 /*!
409 * Used for initializing the callback function used when the in/out state of the
410 * card changes.
411 * \param
412 * \return The outcome of the requested action.
413 */
414 extern T_ZDrvUicc_SetInOutCallBack zDrvUicc_UninstallInOutCallBack(VOID);
415
416/*!
417 * Function used to obtain the ATR string of the current operated card. If no card
418 * is active (or if data is not available) the number of characters returned will
419 * be set to zero.
420 * \param atr Pointer to the store in which the ATR string should be located.
421 * \return Number of ATR characters.
422 */
423 extern UINT8 zDrvUicc_GetAtr(T_ZDrvUicc_CardSelector card_selector, UINT8 *atr);
424
425
426extern VOID zDrvUicc_Highisr(VOID);
427
428extern void invoke_callback(T_UICC_CARD_ACTION card_action, T_UICC_CARD_SELECTOR card_selector);
429
430typedef void (*recoverCallback_func)(void);
431void uicc_setRecover_callback(recoverCallback_func func);
432
433typedef UINT8 (*simStatuCallback_func)(void);
434void uicc_getSimStatu_callback(simStatuCallback_func func);
435#define UICC_SIM_PLUGIN 0x11
436#define UICC_SIM_PLUGOUT 0x10
437
438typedef void (*hotplugCallback_func)(UINT32);
439
440void uicc_set_hotplugCallback(hotplugCallback_func func);
441
442typedef void (*simSwitchCallback_fun)(void);
443void uicc_setUsimSwitch_callback(simSwitchCallback_fun func);
444#endif /* _DRVSUICC_H */
445/** \} */
446 /* End of file. */
447