pcsc-lite 2.3.0
reader.h
Go to the documentation of this file.
1/*
2 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
3 *
4 * Copyright (C) 1999-2005
5 * David Corcoran <corcoran@musclecard.com>
6 * Copyright (C) 2005-2023
7 * Ludovic Rousseau <ludovic.rousseau@free.fr>
8 *
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
12
131. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
152. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
183. The name of the author may not be used to endorse or promote products
19 derived from this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
38#ifndef __reader_h__
39#define __reader_h__
40
41/*
42 * Tags for requesting card and reader attributes
43 */
44
45#define SCARD_ATTR_VALUE(Class, Tag) ((((ULONG)(Class)) << 16) | ((ULONG)(Tag)))
46
47#define SCARD_CLASS_VENDOR_INFO 1
48#define SCARD_CLASS_COMMUNICATIONS 2
49#define SCARD_CLASS_PROTOCOL 3
50#define SCARD_CLASS_POWER_MGMT 4
51#define SCARD_CLASS_SECURITY 5
52#define SCARD_CLASS_MECHANICAL 6
53#define SCARD_CLASS_VENDOR_DEFINED 7
54#define SCARD_CLASS_IFD_PROTOCOL 8
55#define SCARD_CLASS_ICC_STATE 9
56#define SCARD_CLASS_SYSTEM 0x7fff
58#define SCARD_ATTR_VENDOR_NAME SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0100)
59#define SCARD_ATTR_VENDOR_IFD_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0101)
60#define SCARD_ATTR_VENDOR_IFD_VERSION SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0102)
61#define SCARD_ATTR_VENDOR_IFD_SERIAL_NO SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0103)
62#define SCARD_ATTR_CHANNEL_ID SCARD_ATTR_VALUE(SCARD_CLASS_COMMUNICATIONS, 0x0110)
63#define SCARD_ATTR_ASYNC_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0120)
64#define SCARD_ATTR_DEFAULT_CLK SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0121)
65#define SCARD_ATTR_MAX_CLK SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0122)
66#define SCARD_ATTR_DEFAULT_DATA_RATE SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0123)
67#define SCARD_ATTR_MAX_DATA_RATE SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0124)
68#define SCARD_ATTR_MAX_IFSD SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0125)
69#define SCARD_ATTR_SYNC_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0126)
70#define SCARD_ATTR_POWER_MGMT_SUPPORT SCARD_ATTR_VALUE(SCARD_CLASS_POWER_MGMT, 0x0131)
71#define SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0140)
72#define SCARD_ATTR_USER_AUTH_INPUT_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0142)
73#define SCARD_ATTR_CHARACTERISTICS SCARD_ATTR_VALUE(SCARD_CLASS_MECHANICAL, 0x0150)
75#define SCARD_ATTR_CURRENT_PROTOCOL_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0201)
76#define SCARD_ATTR_CURRENT_CLK SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0202)
77#define SCARD_ATTR_CURRENT_F SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0203)
78#define SCARD_ATTR_CURRENT_D SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0204)
79#define SCARD_ATTR_CURRENT_N SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0205)
80#define SCARD_ATTR_CURRENT_W SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0206)
81#define SCARD_ATTR_CURRENT_IFSC SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0207)
82#define SCARD_ATTR_CURRENT_IFSD SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0208)
83#define SCARD_ATTR_CURRENT_BWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0209)
84#define SCARD_ATTR_CURRENT_CWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020a)
85#define SCARD_ATTR_CURRENT_EBC_ENCODING SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020b)
86#define SCARD_ATTR_EXTENDED_BWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020c)
88#define SCARD_ATTR_ICC_PRESENCE SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0300)
89#define SCARD_ATTR_ICC_INTERFACE_STATUS SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0301)
90#define SCARD_ATTR_CURRENT_IO_STATE SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0302)
91#define SCARD_ATTR_ATR_STRING SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0303)
92#define SCARD_ATTR_ICC_TYPE_PER_ATR SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0304)
94#define SCARD_ATTR_ESC_RESET SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA000)
95#define SCARD_ATTR_ESC_CANCEL SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA003)
96#define SCARD_ATTR_ESC_AUTHREQUEST SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA005)
97#define SCARD_ATTR_MAXINPUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA007)
99#define SCARD_ATTR_DEVICE_UNIT SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0001)
100#define SCARD_ATTR_DEVICE_IN_USE SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0002)
101#define SCARD_ATTR_DEVICE_FRIENDLY_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0003)
102#define SCARD_ATTR_DEVICE_SYSTEM_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0004)
103#define SCARD_ATTR_DEVICE_FRIENDLY_NAME_W SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0005)
104#define SCARD_ATTR_DEVICE_SYSTEM_NAME_W SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0006)
105#define SCARD_ATTR_SUPRESS_T1_IFS_REQUEST SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0007)
107#ifdef UNICODE
108#define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_W
109#define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_W
110#else
111#define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_A
112#define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_A
113#endif
114
118#define SCARD_CTL_CODE(code) (0x42000000 + (code))
119
123#define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
124
125#define FEATURE_VERIFY_PIN_START 0x01
126#define FEATURE_VERIFY_PIN_FINISH 0x02
127#define FEATURE_MODIFY_PIN_START 0x03
128#define FEATURE_MODIFY_PIN_FINISH 0x04
129#define FEATURE_GET_KEY_PRESSED 0x05
130#define FEATURE_VERIFY_PIN_DIRECT 0x06
131#define FEATURE_MODIFY_PIN_DIRECT 0x07
132#define FEATURE_MCT_READER_DIRECT 0x08
133#define FEATURE_MCT_UNIVERSAL 0x09
134#define FEATURE_IFD_PIN_PROPERTIES 0x0A
135#define FEATURE_ABORT 0x0B
136#define FEATURE_SET_SPE_MESSAGE 0x0C
137#define FEATURE_VERIFY_PIN_DIRECT_APP_ID 0x0D
138#define FEATURE_MODIFY_PIN_DIRECT_APP_ID 0x0E
139#define FEATURE_WRITE_DISPLAY 0x0F
140#define FEATURE_GET_KEY 0x10
141#define FEATURE_IFD_DISPLAY_PROPERTIES 0x11
142#define FEATURE_GET_TLV_PROPERTIES 0x12
143#define FEATURE_CCID_ESC_COMMAND 0x13
144#define FEATURE_EXECUTE_PACE 0x20
145
146/* structures used (but not defined) in PC/SC Part 10:
147 * "IFDs with Secure Pin Entry Capabilities" */
148
149#include <inttypes.h>
150
151/* Set structure elements alignment on bytes
152 * http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
153#if defined(__APPLE__) || defined(sun) || defined(__NetBSD__)
154#pragma pack(1)
155#else
156#pragma pack(push, 1)
157#endif
158
160typedef struct
161{
162 uint8_t tag;
163 uint8_t length;
164 uint32_t value;
166
169#define HOST_TO_CCID_16(x) (x)
170#define HOST_TO_CCID_32(x) (x)
171
173typedef struct
174{
175 uint8_t bTimerOut;
176 uint8_t bTimerOut2;
190 uint16_t wLangId;
191 uint8_t bMsgIndex;
192 uint8_t bTeoPrologue[3];
193 uint32_t ulDataLength;
194 uint8_t abData
195#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
196 [] /* valid C99 code */
197#else
198 [0] /* non-standard, but usually working code */
199#endif
200 ;
202
204typedef struct
205{
206 uint8_t bTimerOut;
207 uint8_t bTimerOut2;
223 uint8_t bConfirmPIN;
227 uint16_t wLangId;
228 uint8_t bMsgIndex1;
229 uint8_t bMsgIndex2;
230 uint8_t bMsgIndex3;
231 uint8_t bTeoPrologue[3];
232 uint32_t ulDataLength;
233 uint8_t abData
234#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
235 [] /* valid C99 code */
236#else
237 [0] /* non-standard, but usually working code */
238#endif
239 ;
241
243typedef struct {
244 uint16_t wLcdLayout;
245 uint8_t bEntryValidationCondition;
246 uint8_t bTimeOut2;
248
249/* restore default structure elements alignment */
250#if defined(__APPLE__) || defined(sun) || defined(__NetBSD__)
251#pragma pack()
252#else
253#pragma pack(pop)
254#endif
255
256/* properties returned by FEATURE_GET_TLV_PROPERTIES */
257#define PCSCv2_PART10_PROPERTY_wLcdLayout 1
258#define PCSCv2_PART10_PROPERTY_bEntryValidationCondition 2
259#define PCSCv2_PART10_PROPERTY_bTimeOut2 3
260#define PCSCv2_PART10_PROPERTY_wLcdMaxCharacters 4
261#define PCSCv2_PART10_PROPERTY_wLcdMaxLines 5
262#define PCSCv2_PART10_PROPERTY_bMinPINSize 6
263#define PCSCv2_PART10_PROPERTY_bMaxPINSize 7
264#define PCSCv2_PART10_PROPERTY_sFirmwareID 8
265#define PCSCv2_PART10_PROPERTY_bPPDUSupport 9
266#define PCSCv2_PART10_PROPERTY_dwMaxAPDUDataSize 10
267#define PCSCv2_PART10_PROPERTY_wIdVendor 11
268#define PCSCv2_PART10_PROPERTY_wIdProduct 12
269
270#endif
271
the structure must be 6-bytes long
Definition reader.h:161
uint32_t value
This value is always in BIG ENDIAN format as documented in PCSC v2 part 10 ch 2.2 page 2.
Definition reader.h:164
structure used with FEATURE_MODIFY_PIN_DIRECT
Definition reader.h:205
uint8_t bmPINLengthFormat
bits 7-5 RFU, bit 4 set if system units are bytes, clear if system units are bits,...
Definition reader.h:212
uint8_t bInsertionOffsetOld
Insertion position offset in bytes for the current PIN.
Definition reader.h:216
uint8_t bConfirmPIN
Flags governing need for confirmation of new PIN.
Definition reader.h:223
uint8_t bmFormatString
formatting options
Definition reader.h:208
uint8_t bTimerOut
timeout is seconds (00 means use default timeout)
Definition reader.h:206
uint16_t wPINMaxExtraDigit
0xXXYY where XX is minimum PIN size in digits, and YY is maximum PIN size in digits
Definition reader.h:220
uint8_t bmPINBlockString
bits 7-4 bit size of PIN length in APDU, bits 3-0 PIN block size in bytes after justification and for...
Definition reader.h:209
uint16_t wLangId
Language for messages.
Definition reader.h:227
uint8_t bNumberMessage
Number of messages to display for PIN verification.
Definition reader.h:226
uint8_t bMsgIndex3
index of 3d prompting message
Definition reader.h:230
uint32_t ulDataLength
length of Data to be sent to the ICC
Definition reader.h:232
uint8_t bTimerOut2
timeout in seconds after first key stroke
Definition reader.h:207
uint8_t bInsertionOffsetNew
Insertion position offset in bytes for the new PIN.
Definition reader.h:218
uint8_t bEntryValidationCondition
Conditions under which PIN entry should be considered complete.
Definition reader.h:224
uint8_t bMsgIndex2
index of 2d prompting message
Definition reader.h:229
uint8_t bMsgIndex1
index of 1st prompting message
Definition reader.h:228
structure used with FEATURE_IFD_PIN_PROPERTIES
Definition reader.h:243
uint16_t wLcdLayout
display characteristics
Definition reader.h:244
structure used with FEATURE_VERIFY_PIN_DIRECT
Definition reader.h:174
uint8_t bmPINLengthFormat
bits 7-5 RFU, bit 4 set if system units are bytes, clear if system units are bits,...
Definition reader.h:181
uint8_t bMsgIndex
Message index (should be 00)
Definition reader.h:191
uint8_t bmFormatString
formatting options
Definition reader.h:177
uint8_t bTimerOut
timeout is seconds (00 means use default timeout)
Definition reader.h:175
uint16_t wPINMaxExtraDigit
0xXXYY where XX is minimum PIN size in digits, and YY is maximum PIN size in digits
Definition reader.h:185
uint8_t bmPINBlockString
bits 7-4 bit size of PIN length in APDU, bits 3-0 PIN block size in bytes after justification and for...
Definition reader.h:178
uint16_t wLangId
Language for messages.
Definition reader.h:190
uint8_t bNumberMessage
Number of messages to display for PIN verification.
Definition reader.h:189
uint32_t ulDataLength
length of Data to be sent to the ICC
Definition reader.h:193
uint8_t bTimerOut2
timeout in seconds after first key stroke
Definition reader.h:176
uint8_t bEntryValidationCondition
Conditions under which PIN entry should be considered complete.
Definition reader.h:187