]>
Commit | Line | Data |
---|---|---|
21bd4958 FT |
1 | /** @file\r |
2 | The UEFI Smart Card Reader Protocol provides an abstraction for device to provide\r | |
3 | smart card reader support. This protocol is very close to Part 5 of PC/SC workgroup\r | |
4 | specifications and provides an API to applications willing to communicate with a\r | |
5 | smart card or a smart card reader.\r | |
6 | \r | |
7 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r | |
8 | This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #ifndef __SMART_CARD_READER_H__\r | |
19 | #define __SMART_CARD_READER_H__\r | |
20 | \r | |
21 | #define EFI_SMART_CARD_READER_PROTOCOL_GUID \\r | |
22 | { \\r | |
23 | 0x2a4d1adf, 0x21dc, 0x4b81, {0xa4, 0x2f, 0x8b, 0x8e, 0xe2, 0x38, 0x00, 0x60} \\r | |
24 | }\r | |
25 | \r | |
26 | typedef struct _EFI_SMART_CARD_READER_PROTOCOL EFI_SMART_CARD_READER_PROTOCOL;\r | |
27 | \r | |
28 | //\r | |
29 | // Codes for access mode\r | |
30 | //\r | |
31 | #define SCARD_AM_READER 0x0001 // Exclusive access to reader\r | |
32 | #define SCARD_AM_CARD 0x0002 // Exclusive access to card\r | |
33 | //\r | |
34 | // Codes for card action\r | |
35 | //\r | |
36 | #define SCARD_CA_NORESET 0x0000 // Don't reset card\r | |
37 | #define SCARD_CA_COLDRESET 0x0001 // Perform a cold reset\r | |
38 | #define SCARD_CA_WARMRESET 0x0002 // Perform a warm reset\r | |
39 | #define SCARD_CA_UNPOWER 0x0003 // Power off the card\r | |
40 | #define SCARD_CA_EJECT 0x0004 // Eject the card\r | |
41 | //\r | |
42 | // Protocol types\r | |
43 | //\r | |
44 | #define SCARD_PROTOCOL_UNDEFINED 0x0000\r | |
45 | #define SCARD_PROTOCOL_T0 0x0001\r | |
46 | #define SCARD_PROTOCOL_T1 0x0002\r | |
47 | #define SCARD_PROTOCOL_RAW 0x0004\r | |
48 | //\r | |
49 | // Codes for state type\r | |
50 | //\r | |
51 | #define SCARD_UNKNOWN 0x0000 /* state is unknown */\r | |
52 | #define SCARD_ABSENT 0x0001 /* Card is absent */\r | |
53 | #define SCARD_INACTIVE 0x0002 /* Card is present and not powered*/\r | |
54 | #define SCARD_ACTIVE 0x0003 /* Card is present and powered */\r | |
55 | //\r | |
56 | // Macro to generate a ControlCode & PC/SC part 10 control code\r | |
57 | //\r | |
58 | #define SCARD_CTL_CODE(code) (0x42000000 + (code))\r | |
59 | #define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)\r | |
60 | \r | |
61 | /**\r | |
62 | This function requests connection to the smart card or the reader, using the\r | |
63 | appropriate reset type and protocol.\r | |
64 | \r | |
65 | The SCardConnectfunction requests access to the smart card or the reader. Upon\r | |
66 | success, it is then possible to call SCardTransmit.\r | |
67 | \r | |
68 | If AccessMode is set to SCARD_AM_READER, PreferredProtocols must be set to\r | |
69 | SCARD_PROTOCOL_UNDEFINED and CardAction to SCARD_CA_NORESET else function\r | |
70 | fails with EFI_INVALID_PARAMETER.\r | |
71 | \r | |
72 | @param[in] This Indicates a pointer to the calling context.\r | |
73 | @param[in] AccessMode Codes of access mode.\r | |
74 | @param[in] CardAction SCARD_CA_NORESET, SCARD_CA_COLDRESET or\r | |
75 | SCARD_CA_WARMRESET.\r | |
76 | @param[in] PreferredProtocols Bitmask of acceptable protocols.\r | |
77 | @param[out] ActiveProtocol A flag that indicates the active protocol.\r | |
78 | \r | |
79 | @retval EFI_SUCCESS The requested command completed successfully.\r | |
80 | @retval EFI_INVALID_PARAMETER This is NULL\r | |
81 | @retval EFI_INVALID_PARAMETER AccessMode is not valid.\r | |
82 | @retval EFI_INVALID_PARAMETER CardAction is not valid.\r | |
83 | @retval EFI_INVALID_PARAMETER Invalid combination of AccessMode/CardAction/\r | |
84 | PreferredProtocols.\r | |
85 | @retval EFI_NOT_READY A smart card is inserted but failed to return an ATR.\r | |
86 | @retval EFI_UNSUPPORTED PreferredProtocols does not contain an available\r | |
87 | protocol to use.\r | |
88 | @retval EFI_NO_MEDIA AccessMode is set to SCARD_AM_CARD but there is\r | |
89 | no smart card inserted.\r | |
90 | @retval EFI_ACCESS_DENIED Access is already locked by a previous SCardConnectcall.\r | |
91 | @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.\r | |
92 | \r | |
93 | **/\r | |
94 | typedef\r | |
95 | EFI_STATUS\r | |
96 | (EFIAPI *EFI_SMART_CARD_READER_CONNECT) (\r | |
97 | IN EFI_SMART_CARD_READER_PROTOCOL *This,\r | |
98 | IN UINT32 AccessMode,\r | |
99 | IN UINT32 CardAction,\r | |
100 | IN UINT32 PreferredProtocols,\r | |
101 | OUT UINT32 *ActiveProtocol\r | |
102 | );\r | |
103 | \r | |
104 | /**\r | |
105 | This function releases a connection previously taken by SCardConnect.\r | |
106 | \r | |
107 | The SCardDisconnect function releases the lock previously taken by SCardConnect.\r | |
108 | In case the smart card has been removed before this call, thisfunction\r | |
109 | returns EFI_SUCCESS. If there is no previous call to SCardConnect, this\r | |
110 | function returns EFI_SUCCESS.\r | |
111 | \r | |
112 | @param[in] This Indicates a pointer to the calling context.\r | |
113 | @param[in] CardAction Codes for card action.\r | |
114 | \r | |
115 | @retval EFI_SUCCESS The requested command completed successfully.\r | |
116 | @retval EFI_INVALID_PARAMETER This is NULL\r | |
117 | @retval EFI_INVALID_PARAMETER CardAction value is unknown.\r | |
118 | @retval EFI_UNSUPPORTED Reader does not support Eject card feature\r | |
119 | (disconnect was not performed).\r | |
120 | @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.\r | |
121 | \r | |
122 | **/\r | |
123 | typedef\r | |
124 | EFI_STATUS\r | |
125 | (EFIAPI *EFI_SMART_CARD_READER_DISCONNECT) (\r | |
126 | IN EFI_SMART_CARD_READER_PROTOCOL *This,\r | |
127 | IN UINT32 CardAction\r | |
128 | );\r | |
129 | \r | |
130 | /**\r | |
131 | This function retrieves some basic information about the smart card and reader.\r | |
132 | \r | |
133 | The SCardStatusfunction retrieves basic reader and card information.\r | |
134 | \r | |
135 | If ReaderName, State, CardProtocolor Atris NULL, the function does not fail but\r | |
136 | does not fill in such variables.\r | |
137 | \r | |
138 | If EFI_SUCCESS is not returned, ReaderName and Atr contents shall not be considered\r | |
139 | as valid.\r | |
140 | \r | |
141 | @param[in] This Indicates a pointer to the calling context.\r | |
142 | @param[out] ReaderName A pointer to a NULL terminated string that will\r | |
143 | contain the reader name.\r | |
144 | @param[in, out] ReaderNameLength On input, a pointer to the variablethat holds the\r | |
145 | maximal size, in bytes,of ReaderName.\r | |
146 | On output, the required size, in bytes, for ReaderName.\r | |
147 | @param[out] State Current state of the smart card reader.\r | |
148 | @param[out] CardProtocol Current protocol used to communicate with the smart card.\r | |
149 | @param[out] Atr A pointer to retrieve the ATR of the smart card.\r | |
150 | @param[in, out] AtrLength On input, a pointer to hold the maximum size, in bytes,\r | |
151 | of Atr(usually 33).\r | |
152 | On output, the required size, inbytes, for the smart\r | |
153 | card ATR.\r | |
154 | \r | |
155 | @retval EFI_SUCCESS The requested command completed successfully.\r | |
156 | @retval EFI_INVALID_PARAMETER This is NULL\r | |
157 | @retval EFI_INVALID_PARAMETER ReaderName is not NULL but ReaderNameLength is NULL\r | |
158 | @retval EFI_INVALID_PARAMETER Atr is not NULL but AtrLength is NULL\r | |
159 | @retval EFI_BUFFER_TOO_SMALL ReaderNameLength is not big enough to hold the reader name.\r | |
160 | ReaderNameLength has been updated to the required value.\r | |
161 | @retval EFI_BUFFER_TOO_SMALL AtrLength is not big enough to hold the ATR.\r | |
162 | AtrLength has been updated to the required value.\r | |
163 | @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.\r | |
164 | \r | |
165 | **/\r | |
166 | typedef\r | |
167 | EFI_STATUS\r | |
168 | (EFIAPI *EFI_SMART_CARD_READER_STATUS) (\r | |
169 | IN EFI_SMART_CARD_READER_PROTOCOL *This,\r | |
170 | OUT CHAR16 *ReaderName OPTIONAL,\r | |
171 | IN OUT UINTN *ReaderNameLength OPTIONAL,\r | |
172 | OUT UINT32 *State OPTIONAL,\r | |
173 | OUT UINT32 *CardProtocol OPTIONAL,\r | |
174 | OUT UINT8 *Atr OPTIONAL,\r | |
175 | IN OUT UINTN *AtrLength OPTIONAL\r | |
176 | );\r | |
177 | \r | |
178 | /**\r | |
179 | This function sends a command to the card or reader and returns its response.\r | |
180 | \r | |
181 | The protocol to use to communicate with the smart card has been selected through\r | |
182 | SCardConnectcall.\r | |
183 | \r | |
184 | In case RAPDULength indicates a buffer too small to holdthe response APDU, the\r | |
185 | function fails with EFI_BUFFER_TOO_SMALL.\r | |
186 | \r | |
187 | @param[in] This A pointer to the EFI_USBFN_IO_PROTOCOLinstance.\r | |
188 | @param[in] CAPDU A pointer to a byte array thatcontains the Command\r | |
189 | APDU to send to the smart card or reader.\r | |
190 | @param[in] CAPDULength Command APDU size, in bytes.\r | |
191 | @param[out] RAPDU A pointer to a byte array that will contain the\r | |
192 | Response APDU.\r | |
193 | @param[in, out] RAPDULength On input, the maximum size, inbytes, of the Response\r | |
194 | APDU.\r | |
195 | On output, the size, in bytes, of the Response APDU.\r | |
196 | \r | |
197 | @retval EFI_SUCCESS The requested command completed successfully.\r | |
198 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
199 | @retval EFI_INVALID_PARAMETER CAPDU is NULL or CAPDULength is 0.\r | |
200 | @retval EFI_BUFFER_TOO_SMALL RAPDULength is not big enough to hold the response APDU.\r | |
201 | RAPDULength has been updated to the required value.\r | |
202 | @retval EFI_NO_MEDIA There is no card in the reader.\r | |
203 | @retval EFI_NOT_READY Card is not powered.\r | |
204 | @retval EFI_PROTOCOL_ERROR A protocol error has occurred.\r | |
205 | @retval EFI_TIMEOUT The reader did not respond.\r | |
206 | @retval EFI_ACCESS_DENIED A communication with the reader/card is already pending.\r | |
207 | @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.\r | |
208 | \r | |
209 | **/\r | |
210 | typedef\r | |
211 | EFI_STATUS\r | |
212 | (EFIAPI *EFI_SMART_CARD_READER_TRANSMIT) (\r | |
213 | IN EFI_SMART_CARD_READER_PROTOCOL *This,\r | |
214 | IN UINT8 *CAPDU,\r | |
215 | IN UINTN CAPDULength,\r | |
216 | OUT UINT8 *RAPDU,\r | |
217 | IN OUT UINTN *RAPDULength\r | |
21bd4958 FT |
218 | );\r |
219 | \r | |
220 | /**\r | |
221 | This function provides direct access to the reader.\r | |
222 | \r | |
223 | This function gives direct control to send commands to the driver or the reader.\r | |
224 | The ControlCode to use is vendor dependant; the only standard code defined is\r | |
225 | the one to get PC/SC part 10 features.\r | |
226 | \r | |
227 | InBuffer and Outbuffer may be NULL when ControlCode operation does not require\r | |
228 | them.\r | |
229 | \r | |
230 | @param[in] This Indicates a pointer to the calling context.\r | |
231 | @param[in] ControlCode The control code for the operation to perform.\r | |
232 | @param[in] InBuffer A pointer to the input parameters.\r | |
233 | @param[in] InBufferLength Size, in bytes, of input parameters.\r | |
234 | @param[out] OutBuffer A pointer to the output parameters.\r | |
235 | @param[in, out] OutBufferLength On input, maximal size, in bytes, to store output\r | |
236 | parameters.\r | |
237 | On output, the size, in bytes, of output parameters.\r | |
238 | \r | |
239 | @retval EFI_SUCCESS The requested command completed successfully.\r | |
240 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
241 | @retval EFI_INVALID_PARAMETER ControlCode requires input parameters but:\r | |
242 | InBuffer is NULL or InBufferLenth is NULL or\r | |
243 | InBuffer is not NULL but InBufferLenth is less than\r | |
244 | expected.\r | |
245 | @retval EFI_INVALID_PARAMETER OutBuffer is not NULL but OutBufferLength is NULL.\r | |
246 | @retval EFI_UNSUPPORTED ControlCode is not supported.\r | |
247 | @retval EFI_BUFFER_TOO_SMALL OutBufferLength is not big enough to hold the output\r | |
248 | parameters.\r | |
249 | OutBufferLength has been updated to the required value.\r | |
250 | @retval EFI_NO_MEDIA There is no card in the reader and the control code\r | |
251 | specified requires one.\r | |
252 | @retval EFI_NOT_READY ControlCode requires a powered card to operate.\r | |
253 | @retval EFI_PROTOCOL_ERROR A protocol error has occurred.\r | |
254 | @retval EFI_TIMEOUT The reader did not respond.\r | |
255 | @retval EFI_ACCESS_DENIED A communication with the reader/card is already pending.\r | |
256 | @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.\r | |
257 | \r | |
258 | **/\r | |
259 | typedef\r | |
260 | EFI_STATUS\r | |
261 | (EFIAPI *EFI_SMART_CARD_READER_CONTROL) (\r | |
262 | IN EFI_SMART_CARD_READER_PROTOCOL *This,\r | |
263 | IN UINT32 ControlCode,\r | |
264 | IN UINT8 *InBuffer OPTIONAL,\r | |
265 | IN UINTN InBufferLength OPTIONAL,\r | |
266 | OUT UINT8 *OutBuffer OPTIONAL,\r | |
267 | IN OUT UINTN *OutBufferLength OPTIONAL\r | |
268 | );\r | |
269 | \r | |
270 | /**\r | |
271 | This function retrieves a reader or smart card attribute.\r | |
272 | \r | |
273 | Possibly supported attrib values are listed in "PC/SC specification, Part 3:\r | |
274 | Requirements for PC-Connected Interface Devices".\r | |
275 | \r | |
276 | @param[in] This Indicates a pointer to the calling context.\r | |
277 | @param[in] Attrib Identifier for the attribute to retrieve.\r | |
278 | @param[out] OutBuffer A pointer to a buffer that will contain\r | |
279 | attribute data.\r | |
280 | @param[in, out] OutBufferLength On input, maximal size, in bytes, to store\r | |
281 | attribute data.\r | |
282 | On output, the size, in bytes, of attribute\r | |
283 | data.\r | |
284 | \r | |
285 | @retval EFI_SUCCESS The requested command completed successfully.\r | |
286 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
287 | @retval EFI_INVALID_PARAMETER OutBuffer is NULL or OutBufferLength is 0.\r | |
288 | @retval EFI_BUFFER_TOO_SMALL OutBufferLength is not big enough to hold the output\r | |
289 | parameters.\r | |
290 | OutBufferLength has been updated to the required value.\r | |
291 | @retval EFI_UNSUPPORTED Attribis not supported\r | |
292 | @retval EFI_NO_MEDIA There is no card in the reader and Attrib value\r | |
293 | requires one.\r | |
294 | @retval EFI_NOT_READY Attrib requires a powered card to operate.\r | |
295 | @retval EFI_PROTOCOL_ERROR A protocol error has occurred.\r | |
296 | @retval EFI_TIMEOUT The reader did not respond.\r | |
297 | @retval EFI_DEVICE_ERROR Any other error condition, typically a reader removal.\r | |
298 | \r | |
299 | **/\r | |
300 | typedef\r | |
301 | EFI_STATUS\r | |
302 | (EFIAPI *EFI_SMART_CARD_READER_GET_ATTRIB) (\r | |
303 | IN EFI_SMART_CARD_READER_PROTOCOL *This,\r | |
304 | IN UINT32 Attrib,\r | |
305 | OUT UINT8 *OutBuffer,\r | |
306 | IN OUT UINTN *OutBufferLength\r | |
307 | );\r | |
308 | \r | |
309 | ///\r | |
310 | /// Smart card aware application invokes this protocol to get access to an inserted\r | |
311 | /// smart card in the reader or to the reader itself.\r | |
312 | ///\r | |
313 | struct _EFI_SMART_CARD_READER_PROTOCOL {\r | |
314 | EFI_SMART_CARD_READER_CONNECT SCardConnect;\r | |
315 | EFI_SMART_CARD_READER_DISCONNECT SCardDisconnect;\r | |
316 | EFI_SMART_CARD_READER_STATUS SCardStatus;\r | |
317 | EFI_SMART_CARD_READER_TRANSMIT SCardTransmit;\r | |
318 | EFI_SMART_CARD_READER_CONTROL SCardControl;\r | |
319 | EFI_SMART_CARD_READER_GET_ATTRIB SCardGetAttrib;\r | |
320 | };\r | |
321 | \r | |
322 | extern EFI_GUID gEfiSmartCardReaderProtocolGuid;\r | |
323 | \r | |
324 | #endif\r | |
325 | \r |