xref: /reactos/sdk/include/psdk/winsmcrd.h (revision c2c66aff)
1 /*
2  * WinSmCrd.h
3  *
4  * SmartCard IOCTLs
5  *
6  * THIS SOFTWARE IS NOT COPYRIGHTED
7  *
8  * This source code is offered for use in the public domain. You may
9  * use, modify or distribute it freely.
10  *
11  * This code is distributed in the hope that it will be useful but
12  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
13  * DISCLAIMED. This includes but is not limited to warranties of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  */
17 
18 #ifndef __WINSMCRD_H
19 #define __WINSMCRD_H
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #ifdef _MSC_VER
26 #pragma warning(push)
27 #pragma warning(disable:4820)
28 #endif
29 
30 typedef struct _SCARD_IO_REQUEST
31 {
32   DWORD dwProtocol;
33   DWORD cbPciLength;
34 } SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST;
35 typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST;
36 
37 typedef struct _SCARD_T0_COMMAND
38 {
39   BYTE bCla;
40   BYTE bIns;
41   BYTE P1;
42   BYTE P2;
43   BYTE P3;
44 } SCARD_T0_COMMAND, *PSCARD_T0_COMMAND, *LPSCARD_T0_COMMAND;
45 
46 typedef struct _SCARD_T0_REQUEST
47 {
48   SCARD_IO_REQUEST ioRequest;
49   BYTE bSw1;
50   BYTE bSw2;
51   union
52   {
53     SCARD_T0_COMMAND CmdBytes;
54     BYTE rgbHeader[5];
55   } u;
56 } SCARD_T0_REQUEST, *PSCARD_T0_REQUEST, *LPSCARD_T0_REQUEST;
57 
58 typedef struct _SCARD_T1_REQUEST
59 {
60   SCARD_IO_REQUEST ioRequest;
61 } SCARD_T1_REQUEST, *PSCARD_T1_REQUEST, *LPSCARD_T1_REQUEST;
62 
63 #ifndef FILE_DEVICE_SMARTCARD
64 #define FILE_DEVICE_SMARTCARD 49
65 #elif FILE_DEVICE_SMARTCARD != 49
66 #error "Incorrect Smart Card Device Definition"
67 #endif
68 
69 #define SCARD_ATR_LENGTH (0x21)
70 
71 #define SCARD_PROTOCOL_UNDEFINED (0x00000)
72 #define SCARD_PROTOCOL_T0        (0x00001)
73 #define SCARD_PROTOCOL_T1        (0x00002)
74 #define SCARD_PROTOCOL_RAW       (0x10000)
75 
76 #define SCARD_PROTOCOL_Tx (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
77 
78 #define SCARD_PROTOCOL_DEFAULT (0x80000000)
79 #define SCARD_PROTOCOL_OPTIMAL (0x00000000)
80 
81 #define SCARD_T0_HEADER_LENGTH (0x7)
82 #define SCARD_T0_CMD_LENGTH    (0x5)
83 
84 #define SCARD_T1_PROLOGUE_LENGTH (0x03)
85 #define SCARD_T1_EPILOGUE_LENGTH (0x02)
86 #define SCARD_T1_MAX_IFS         (0xFE)
87 
88 #define SCARD_POWER_DOWN (0x0)
89 #define SCARD_COLD_RESET (0x1)
90 #define SCARD_WARM_RESET (0x2)
91 
92 #define SCARD_UNKNOWN    (0x0)
93 #define SCARD_ABSENT     (0x1)
94 #define SCARD_PRESENT    (0x2)
95 #define SCARD_SWALLOWED  (0x3)
96 #define SCARD_POWERED    (0x4)
97 #define SCARD_NEGOTIABLE (0x5)
98 #define SCARD_SPECIFIC   (0x6)
99 
100 #define IOCTL_SMARTCARD_POWER          CTL_CODE(FILE_DEVICE_SMARTCARD, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)
101 #define IOCTL_SMARTCARD_GET_ATTRIBUTE  CTL_CODE(FILE_DEVICE_SMARTCARD, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
102 #define IOCTL_SMARTCARD_SET_ATTRIBUTE  CTL_CODE(FILE_DEVICE_SMARTCARD, 3, METHOD_BUFFERED, FILE_ANY_ACCESS)
103 #define IOCTL_SMARTCARD_CONFISCATE     CTL_CODE(FILE_DEVICE_SMARTCARD, 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
104 #define IOCTL_SMARTCARD_TRANSMIT       CTL_CODE(FILE_DEVICE_SMARTCARD, 5, METHOD_BUFFERED, FILE_ANY_ACCESS)
105 #define IOCTL_SMARTCARD_EJECT          CTL_CODE(FILE_DEVICE_SMARTCARD, 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
106 #define IOCTL_SMARTCARD_SWALLOW        CTL_CODE(FILE_DEVICE_SMARTCARD, 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
107 #define IOCTL_SMARTCARD_READ           CTL_CODE(FILE_DEVICE_SMARTCARD, 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
108 #define IOCTL_SMARTCARD_WRITE          CTL_CODE(FILE_DEVICE_SMARTCARD, 9, METHOD_BUFFERED, FILE_ANY_ACCESS)
109 #define IOCTL_SMARTCARD_IS_PRESENT     CTL_CODE(FILE_DEVICE_SMARTCARD, 10, METHOD_BUFFERED, FILE_ANY_ACCESS)
110 #define IOCTL_SMARTCARD_IS_ABSENT      CTL_CODE(FILE_DEVICE_SMARTCARD, 11, METHOD_BUFFERED, FILE_ANY_ACCESS)
111 #define IOCTL_SMARTCARD_SET_PROTOCOL   CTL_CODE(FILE_DEVICE_SMARTCARD, 12, METHOD_BUFFERED, FILE_ANY_ACCESS)
112 #define IOCTL_SMARTCARD_GET_STATE      CTL_CODE(FILE_DEVICE_SMARTCARD, 14, METHOD_BUFFERED, FILE_ANY_ACCESS)
113 #define IOCTL_SMARTCARD_GET_LAST_ERROR CTL_CODE(FILE_DEVICE_SMARTCARD, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
114 #define IOCTL_SMARTCARD_GET_PERF_CNTR  CTL_CODE(FILE_DEVICE_SMARTCARD, 16, METHOD_BUFFERED, FILE_ANY_ACCESS)
115 
116 #define MAXIMUM_ATTR_STRING_LENGTH (0x10)
117 #define MAXIMUM_SMARTCARD_READERS  (0x0A)
118 
119 #define SCARD_CLASS_VENDOR_INFO    (0x0001)
120 #define SCARD_CLASS_COMMUNICATIONS (0x0002)
121 #define SCARD_CLASS_PROTOCOL       (0x0003)
122 #define SCARD_CLASS_POWER_MGMT     (0x0004)
123 #define SCARD_CLASS_SECURITY       (0x0005)
124 #define SCARD_CLASS_MECHANICAL     (0x0006)
125 #define SCARD_CLASS_VENDOR_DEFINED (0x0007)
126 #define SCARD_CLASS_IFD_PROTOCOL   (0x0008)
127 #define SCARD_CLASS_ICC_STATE      (0x0009)
128 #define SCARD_CLASS_PERF           (0x7FFE)
129 #define SCARD_CLASS_SYSTEM         (0x7FFF)
130 
131 #define SCARD_READER_TYPE_VENDOR   (0xF0)
132 
133 #define SCARD_READER_TYPE_SERIAL   (0x01)
134 #define SCARD_READER_TYPE_PARALELL (0x02)
135 #define SCARD_READER_TYPE_KEYBOARD (0x04)
136 #define SCARD_READER_TYPE_SCSI     (0x08)
137 #define SCARD_READER_TYPE_IDE      (0x10)
138 #define SCARD_READER_TYPE_USB      (0x20)
139 #define SCARD_READER_TYPE_PCMCIA   (0x40)
140 
141 #define SCARD_READER_SWALLOWS    (0x1)
142 #define SCARD_READER_EJECTS      (0x2)
143 #define SCARD_READER_CONFISCATES (0x4)
144 
145 #define SCARD_ATTR_VALUE(Class, Tag)                                           \
146   (((ULONG)(Class) << 16) | (ULONG)(Tag))
147 
148 #define SCARD_ATTR_VENDOR_NAME              SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0100)
149 #define SCARD_ATTR_VENDOR_IFD_TYPE          SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0101)
150 #define SCARD_ATTR_VENDOR_IFD_VERSION       SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0102)
151 #define SCARD_ATTR_VENDOR_IFD_SERIAL_NO     SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0103)
152 
153 #define SCARD_ATTR_CHANNEL_ID               SCARD_ATTR_VALUE(SCARD_CLASS_COMMUNICATIONS, 0x0110)
154 
155 #define SCARD_ATTR_PROTOCOL_TYPES           SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0120)
156 #define SCARD_ATTR_ASYNC_PROTOCOL_TYPES     SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0120)
157 #define SCARD_ATTR_DEFAULT_CLK              SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0121)
158 #define SCARD_ATTR_MAX_CLK                  SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0122)
159 #define SCARD_ATTR_DEFAULT_DATA_RATE        SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0123)
160 #define SCARD_ATTR_MAX_DATA_RATE            SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0124)
161 #define SCARD_ATTR_MAX_IFSD                 SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0125)
162 #define SCARD_ATTR_SYNC_PROTOCOL_TYPES      SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0126)
163 
164 #define SCARD_ATTR_POWER_MGMT_SUPPORT       SCARD_ATTR_VALUE(SCARD_CLASS_POWER_MGMT, 0x0131)
165 
166 #define SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0140)
167 #define SCARD_ATTR_USER_AUTH_INPUT_DEVICE   SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0142)
168 
169 #define SCARD_ATTR_CHARACTERISTICS          SCARD_ATTR_VALUE(SCARD_CLASS_MECHANICAL, 0x0150)
170 
171 #define SCARD_ATTR_CURRENT_PROTOCOL_TYPE    SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0201)
172 #define SCARD_ATTR_CURRENT_CLK              SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0202)
173 #define SCARD_ATTR_CURRENT_F                SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0203)
174 #define SCARD_ATTR_CURRENT_D                SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0204)
175 #define SCARD_ATTR_CURRENT_N                SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0205)
176 #define SCARD_ATTR_CURRENT_W                SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0206)
177 #define SCARD_ATTR_CURRENT_IFSC             SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0207)
178 #define SCARD_ATTR_CURRENT_IFSD             SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0208)
179 #define SCARD_ATTR_CURRENT_BWT              SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0209)
180 #define SCARD_ATTR_CURRENT_CWT              SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020A)
181 #define SCARD_ATTR_CURRENT_EBC_ENCODING     SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020B)
182 #define SCARD_ATTR_EXTENDED_BWT             SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020C)
183 
184 #define SCARD_ATTR_ICC_PRESENCE             SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0300)
185 #define SCARD_ATTR_ICC_INTERFACE_STATUS     SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0301)
186 #define SCARD_ATTR_CURRENT_IO_STATE         SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0302)
187 #define SCARD_ATTR_ATR_STRING               SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0303)
188 #define SCARD_ATTR_ICC_TYPE_PER_ATR         SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0304)
189 
190 #define SCARD_ATTR_ESC_RESET                SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA000)
191 #define SCARD_ATTR_ESC_CANCEL               SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA003)
192 #define SCARD_ATTR_ESC_AUTHREQUEST          SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA005)
193 #define SCARD_ATTR_MAXINPUT                 SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA007)
194 
195 #define SCARD_ATTR_DEVICE_UNIT              SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0001)
196 #define SCARD_ATTR_DEVICE_IN_USE            SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0002)
197 #define SCARD_ATTR_DEVICE_FRIENDLY_NAME_A   SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0003)
198 #define SCARD_ATTR_DEVICE_SYSTEM_NAME_A     SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0004)
199 #define SCARD_ATTR_DEVICE_FRIENDLY_NAME_W   SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0005)
200 #define SCARD_ATTR_DEVICE_SYSTEM_NAME_W     SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0006)
201 #define SCARD_ATTR_SUPRESS_T1_IFS_REQUEST   SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0007)
202 
203 #define SCARD_PERF_NUM_TRANSMISSIONS        SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0001)
204 #define SCARD_PERF_BYTES_TRANSMITTED        SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0002)
205 #define SCARD_PERF_TRANSMISSION_TIME        SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0003)
206 
207 #ifdef UNICODE
208 #define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_W
209 #define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_W
210 #else /* !UNICODE */
211 #define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_A
212 #define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_A
213 #endif /* UNICODE */
214 
215 #ifdef _MSC_VER
216 #pragma warning(pop)
217 #endif
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 #endif /* __WINSMCRD_H */
223 
224 /* EOF */
225