2 The UEFI Smart Card Reader Protocol provides an abstraction for device to provide
3 smart card reader support. This protocol is very close to Part 5 of PC/SC workgroup
4 specifications and provides an API to applications willing to communicate with a
5 smart card or a smart card reader.
7 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #ifndef __SMART_CARD_READER_H__
13 #define __SMART_CARD_READER_H__
15 #define EFI_SMART_CARD_READER_PROTOCOL_GUID \
17 0x2a4d1adf, 0x21dc, 0x4b81, {0xa4, 0x2f, 0x8b, 0x8e, 0xe2, 0x38, 0x00, 0x60} \
20 typedef struct _EFI_SMART_CARD_READER_PROTOCOL EFI_SMART_CARD_READER_PROTOCOL
;
23 // Codes for access mode
25 #define SCARD_AM_READER 0x0001 // Exclusive access to reader
26 #define SCARD_AM_CARD 0x0002 // Exclusive access to card
28 // Codes for card action
30 #define SCARD_CA_NORESET 0x0000 // Don't reset card
31 #define SCARD_CA_COLDRESET 0x0001 // Perform a cold reset
32 #define SCARD_CA_WARMRESET 0x0002 // Perform a warm reset
33 #define SCARD_CA_UNPOWER 0x0003 // Power off the card
34 #define SCARD_CA_EJECT 0x0004 // Eject the card
38 #define SCARD_PROTOCOL_UNDEFINED 0x0000
39 #define SCARD_PROTOCOL_T0 0x0001
40 #define SCARD_PROTOCOL_T1 0x0002
41 #define SCARD_PROTOCOL_RAW 0x0004
43 // Codes for state type
45 #define SCARD_UNKNOWN 0x0000 /* state is unknown */
46 #define SCARD_ABSENT 0x0001 /* Card is absent */
47 #define SCARD_INACTIVE 0x0002 /* Card is present and not powered*/
48 #define SCARD_ACTIVE 0x0003 /* Card is present and powered */
50 // Macro to generate a ControlCode & PC/SC part 10 control code
52 #define SCARD_CTL_CODE(code) (0x42000000 + (code))
53 #define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
56 This function requests connection to the smart card or the reader, using the
57 appropriate reset type and protocol.
59 The SCardConnectfunction requests access to the smart card or the reader. Upon
60 success, it is then possible to call SCardTransmit.
62 If AccessMode is set to SCARD_AM_READER, PreferredProtocols must be set to
63 SCARD_PROTOCOL_UNDEFINED and CardAction to SCARD_CA_NORESET else function
64 fails with EFI_INVALID_PARAMETER.
66 @param[in] This Indicates a pointer to the calling context.
67 @param[in] AccessMode Codes of access mode.
68 @param[in] CardAction SCARD_CA_NORESET, SCARD_CA_COLDRESET or
70 @param[in] PreferredProtocols Bitmask of acceptable protocols.
71 @param[out] ActiveProtocol A flag that indicates the active protocol.
73 @retval EFI_SUCCESS The requested command completed successfully.
74 @retval EFI_INVALID_PARAMETER This is NULL
75 @retval EFI_INVALID_PARAMETER AccessMode is not valid.
76 @retval EFI_INVALID_PARAMETER CardAction is not valid.
77 @retval EFI_INVALID_PARAMETER Invalid combination of AccessMode/CardAction/
79 @retval EFI_NOT_READY A smart card is inserted but failed to return an ATR.
80 @retval EFI_UNSUPPORTED PreferredProtocols does not contain an available
82 @retval EFI_NO_MEDIA AccessMode is set to SCARD_AM_CARD but there is
83 no smart card inserted.
84 @retval EFI_ACCESS_DENIED Access is already locked by a previous SCardConnectcall.
85 @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.
90 (EFIAPI
*EFI_SMART_CARD_READER_CONNECT
)(
91 IN EFI_SMART_CARD_READER_PROTOCOL
*This
,
94 IN UINT32 PreferredProtocols
,
95 OUT UINT32
*ActiveProtocol
99 This function releases a connection previously taken by SCardConnect.
101 The SCardDisconnect function releases the lock previously taken by SCardConnect.
102 In case the smart card has been removed before this call, thisfunction
103 returns EFI_SUCCESS. If there is no previous call to SCardConnect, this
104 function returns EFI_SUCCESS.
106 @param[in] This Indicates a pointer to the calling context.
107 @param[in] CardAction Codes for card action.
109 @retval EFI_SUCCESS The requested command completed successfully.
110 @retval EFI_INVALID_PARAMETER This is NULL
111 @retval EFI_INVALID_PARAMETER CardAction value is unknown.
112 @retval EFI_UNSUPPORTED Reader does not support Eject card feature
113 (disconnect was not performed).
114 @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.
119 (EFIAPI
*EFI_SMART_CARD_READER_DISCONNECT
)(
120 IN EFI_SMART_CARD_READER_PROTOCOL
*This
,
125 This function retrieves some basic information about the smart card and reader.
127 The SCardStatusfunction retrieves basic reader and card information.
129 If ReaderName, State, CardProtocolor Atris NULL, the function does not fail but
130 does not fill in such variables.
132 If EFI_SUCCESS is not returned, ReaderName and Atr contents shall not be considered
135 @param[in] This Indicates a pointer to the calling context.
136 @param[out] ReaderName A pointer to a NULL terminated string that will
137 contain the reader name.
138 @param[in, out] ReaderNameLength On input, a pointer to the variablethat holds the
139 maximal size, in bytes,of ReaderName.
140 On output, the required size, in bytes, for ReaderName.
141 @param[out] State Current state of the smart card reader.
142 @param[out] CardProtocol Current protocol used to communicate with the smart card.
143 @param[out] Atr A pointer to retrieve the ATR of the smart card.
144 @param[in, out] AtrLength On input, a pointer to hold the maximum size, in bytes,
146 On output, the required size, inbytes, for the smart
149 @retval EFI_SUCCESS The requested command completed successfully.
150 @retval EFI_INVALID_PARAMETER This is NULL
151 @retval EFI_INVALID_PARAMETER ReaderName is not NULL but ReaderNameLength is NULL
152 @retval EFI_INVALID_PARAMETER Atr is not NULL but AtrLength is NULL
153 @retval EFI_BUFFER_TOO_SMALL ReaderNameLength is not big enough to hold the reader name.
154 ReaderNameLength has been updated to the required value.
155 @retval EFI_BUFFER_TOO_SMALL AtrLength is not big enough to hold the ATR.
156 AtrLength has been updated to the required value.
157 @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.
162 (EFIAPI
*EFI_SMART_CARD_READER_STATUS
)(
163 IN EFI_SMART_CARD_READER_PROTOCOL
*This
,
164 OUT CHAR16
*ReaderName OPTIONAL
,
165 IN OUT UINTN
*ReaderNameLength OPTIONAL
,
166 OUT UINT32
*State OPTIONAL
,
167 OUT UINT32
*CardProtocol OPTIONAL
,
168 OUT UINT8
*Atr OPTIONAL
,
169 IN OUT UINTN
*AtrLength OPTIONAL
173 This function sends a command to the card or reader and returns its response.
175 The protocol to use to communicate with the smart card has been selected through
178 In case RAPDULength indicates a buffer too small to holdthe response APDU, the
179 function fails with EFI_BUFFER_TOO_SMALL.
181 @param[in] This A pointer to the EFI_USBFN_IO_PROTOCOLinstance.
182 @param[in] CAPDU A pointer to a byte array thatcontains the Command
183 APDU to send to the smart card or reader.
184 @param[in] CAPDULength Command APDU size, in bytes.
185 @param[out] RAPDU A pointer to a byte array that will contain the
187 @param[in, out] RAPDULength On input, the maximum size, inbytes, of the Response
189 On output, the size, in bytes, of the Response APDU.
191 @retval EFI_SUCCESS The requested command completed successfully.
192 @retval EFI_INVALID_PARAMETER This is NULL.
193 @retval EFI_INVALID_PARAMETER CAPDU is NULL or CAPDULength is 0.
194 @retval EFI_BUFFER_TOO_SMALL RAPDULength is not big enough to hold the response APDU.
195 RAPDULength has been updated to the required value.
196 @retval EFI_NO_MEDIA There is no card in the reader.
197 @retval EFI_NOT_READY Card is not powered.
198 @retval EFI_PROTOCOL_ERROR A protocol error has occurred.
199 @retval EFI_TIMEOUT The reader did not respond.
200 @retval EFI_ACCESS_DENIED A communication with the reader/card is already pending.
201 @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.
206 (EFIAPI
*EFI_SMART_CARD_READER_TRANSMIT
)(
207 IN EFI_SMART_CARD_READER_PROTOCOL
*This
,
209 IN UINTN CAPDULength
,
211 IN OUT UINTN
*RAPDULength
215 This function provides direct access to the reader.
217 This function gives direct control to send commands to the driver or the reader.
218 The ControlCode to use is vendor dependant; the only standard code defined is
219 the one to get PC/SC part 10 features.
221 InBuffer and Outbuffer may be NULL when ControlCode operation does not require
224 @param[in] This Indicates a pointer to the calling context.
225 @param[in] ControlCode The control code for the operation to perform.
226 @param[in] InBuffer A pointer to the input parameters.
227 @param[in] InBufferLength Size, in bytes, of input parameters.
228 @param[out] OutBuffer A pointer to the output parameters.
229 @param[in, out] OutBufferLength On input, maximal size, in bytes, to store output
231 On output, the size, in bytes, of output parameters.
233 @retval EFI_SUCCESS The requested command completed successfully.
234 @retval EFI_INVALID_PARAMETER This is NULL.
235 @retval EFI_INVALID_PARAMETER ControlCode requires input parameters but:
236 InBuffer is NULL or InBufferLenth is NULL or
237 InBuffer is not NULL but InBufferLenth is less than
239 @retval EFI_INVALID_PARAMETER OutBuffer is not NULL but OutBufferLength is NULL.
240 @retval EFI_UNSUPPORTED ControlCode is not supported.
241 @retval EFI_BUFFER_TOO_SMALL OutBufferLength is not big enough to hold the output
243 OutBufferLength has been updated to the required value.
244 @retval EFI_NO_MEDIA There is no card in the reader and the control code
245 specified requires one.
246 @retval EFI_NOT_READY ControlCode requires a powered card to operate.
247 @retval EFI_PROTOCOL_ERROR A protocol error has occurred.
248 @retval EFI_TIMEOUT The reader did not respond.
249 @retval EFI_ACCESS_DENIED A communication with the reader/card is already pending.
250 @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.
255 (EFIAPI
*EFI_SMART_CARD_READER_CONTROL
)(
256 IN EFI_SMART_CARD_READER_PROTOCOL
*This
,
257 IN UINT32 ControlCode
,
258 IN UINT8
*InBuffer OPTIONAL
,
259 IN UINTN InBufferLength OPTIONAL
,
260 OUT UINT8
*OutBuffer OPTIONAL
,
261 IN OUT UINTN
*OutBufferLength OPTIONAL
265 This function retrieves a reader or smart card attribute.
267 Possibly supported attrib values are listed in "PC/SC specification, Part 3:
268 Requirements for PC-Connected Interface Devices".
270 @param[in] This Indicates a pointer to the calling context.
271 @param[in] Attrib Identifier for the attribute to retrieve.
272 @param[out] OutBuffer A pointer to a buffer that will contain
274 @param[in, out] OutBufferLength On input, maximal size, in bytes, to store
276 On output, the size, in bytes, of attribute
279 @retval EFI_SUCCESS The requested command completed successfully.
280 @retval EFI_INVALID_PARAMETER This is NULL.
281 @retval EFI_INVALID_PARAMETER OutBuffer is NULL or OutBufferLength is 0.
282 @retval EFI_BUFFER_TOO_SMALL OutBufferLength is not big enough to hold the output
284 OutBufferLength has been updated to the required value.
285 @retval EFI_UNSUPPORTED Attribis not supported
286 @retval EFI_NO_MEDIA There is no card in the reader and Attrib value
288 @retval EFI_NOT_READY Attrib requires a powered card to operate.
289 @retval EFI_PROTOCOL_ERROR A protocol error has occurred.
290 @retval EFI_TIMEOUT The reader did not respond.
291 @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.
296 (EFIAPI
*EFI_SMART_CARD_READER_GET_ATTRIB
)(
297 IN EFI_SMART_CARD_READER_PROTOCOL
*This
,
299 OUT UINT8
*OutBuffer
,
300 IN OUT UINTN
*OutBufferLength
304 /// Smart card aware application invokes this protocol to get access to an inserted
305 /// smart card in the reader or to the reader itself.
307 struct _EFI_SMART_CARD_READER_PROTOCOL
{
308 EFI_SMART_CARD_READER_CONNECT SCardConnect
;
309 EFI_SMART_CARD_READER_DISCONNECT SCardDisconnect
;
310 EFI_SMART_CARD_READER_STATUS SCardStatus
;
311 EFI_SMART_CARD_READER_TRANSMIT SCardTransmit
;
312 EFI_SMART_CARD_READER_CONTROL SCardControl
;
313 EFI_SMART_CARD_READER_GET_ATTRIB SCardGetAttrib
;
316 extern EFI_GUID gEfiSmartCardReaderProtocolGuid
;