cf8fdbae082eb1975cf516af20c209ed1ca2d40d
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Common / CCIDClassCommon.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2018.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2018 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11 Copyright 2018 Filipe Rodrigues (filipepazrodrigues [at] gmail [dot] com)
12
13 Permission to use, copy, modify, distribute, and sell this
14 software and its documentation for any purpose is hereby granted
15 without fee, provided that the above copyright notice appear in
16 all copies and that both that the copyright notice and this
17 permission notice and warranty disclaimer appear in supporting
18 documentation, and that the name of the author not be used in
19 advertising or publicity pertaining to distribution of the
20 software without specific, written prior permission.
21
22 The author disclaims all warranties with regard to this
23 software, including all implied warranties of merchantability
24 and fitness. In no event shall the author be liable for any
25 special, indirect or consequential damages or any damages
26 whatsoever resulting from loss of use, data or profits, whether
27 in an action of contract, negligence or other tortious action,
28 arising out of or in connection with the use or performance of
29 this software.
30 */
31
32 /** \file
33 * \brief Common definitions and declarations for the library USB CCID Class driver.
34 *
35 * Common definitions and declarations for the library USB CCID Class driver.
36 *
37 * \note This file should not be included directly. It is automatically included as needed by the USB module driver
38 * dispatch header located in LUFA/Drivers/USB.h.
39 */
40
41 /** \ingroup Group_USBClassCCID
42 * \defgroup Group_USBClassCCIDCommon Common Class Definitions
43 *
44 * \section Sec_USBClassCCIDCommon_ModDescription Module Description
45 * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
46 * CCID Class.
47 *
48 * @{
49 */
50
51 #ifndef _CCID_CLASS_COMMON_H_
52 #define _CCID_CLASS_COMMON_H_
53
54 /* Includes: */
55 #include "../../Core/StdDescriptors.h"
56
57 /* Enable C linkage for C++ Compilers: */
58 #if defined(__cplusplus)
59 extern "C" {
60 #endif
61
62 /* Preprocessor Checks: */
63 #if !defined(__INCLUDE_FROM_CCID_DRIVER)
64 #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
65 #endif
66
67 /* Macros: */
68 #define CCID_CURRENT_SPEC_RELEASE_NUMBER 0x0110
69 #define CCID_VOLTAGESUPPORT_5V 0
70 #define CCID_VOLTAGESUPPORT_3V (1 << 0)
71 #define CCID_VOLTAGESUPPORT_1V8 (1 << 1)
72
73 #define CCID_PROTOCOLS_T0 (1 << 0)
74 #define CCID_PROTOCOLS_T1 (1 << 1)
75
76 #define CCID_PROTOCOLNUM_T0 0
77 #define CCID_PROTOCOLNUM_T1 (1 << 0)
78
79 #define CCID_ICCSTATUS_PRESENTANDACTIVE 0
80 #define CCID_ICCSTATUS_PRESENTANDINACTIVE (1 << 0)
81 #define CCID_ICCSTATUS_NOICCPRESENT (1 << 1)
82
83 #define CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR 0
84 #define CCID_COMMANDSTATUS_FAILED (1 << 6)
85 #define CCID_COMMANDSTATUS_TIMEEXTENSIONREQUESTED (2 << 6)
86 #define CCID_COMMANDSTATUS_RFU (3 << 6)
87
88 #define CCID_ERROR_RFU_START 0x80
89 #define CCID_ERROR_NO_ERROR 0x80
90 #define CCID_ERROR_NOT_SUPPORTED 0
91 #define CCID_ERROR_CMD_ABORTED 0xFF
92 #define CCID_ERROR_CMD_NOT_ABORTED 0xFF
93
94 #define CCID_ERROR_SLOT_NOT_FOUND 5
95
96 #define CCID_DESCRIPTOR_CLOCK_KHZ(khz) (khz)
97 #define CCID_DESCRIPTOR_CLOCK_MHZ(mhz) ((mhz) * 1000)
98
99
100 /* Enums: */
101 /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the CCID
102 * device class.
103 */
104 enum CCID_Descriptor_ClassSubclassProtocol_t
105 {
106 CCID_CSCP_CCIDClass = 0x0b, /**< Descriptor Class value indicating that the device or interface
107 * belongs to the CCID class.
108 */
109 CCID_CSCP_NoSpecificSubclass = 0x00, /**< Descriptor Subclass value indicating that the device or interface
110 * belongs to no specific subclass of the CCID class.
111 */
112 CCID_CSCP_NoSpecificProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface
113 * belongs to no specific protocol of the CCID class.
114 */
115 };
116
117 /** Enum for possible bulk messages between PC and Reader */
118 enum CCID_BulkOutMessages_t
119 {
120 CCID_PC_to_RDR_IccPowerOn = 0x62,
121 CCID_PC_to_RDR_IccPowerOff = 0x63,
122 CCID_PC_to_RDR_GetSlotStatus = 0x65,
123 CCID_PC_to_RDR_XfrBlock = 0x6f,
124 CCID_PC_to_RDR_GetParameters = 0x6c,
125 CCID_PC_to_RDR_ResetParameters = 0x6d,
126 CCID_PC_to_RDR_SetParameters = 0x61,
127 CCID_PC_to_RDR_Escape = 0x6b,
128 CCID_PC_to_RDR_IccClock = 0x6e,
129 CCID_PC_to_RDR_T0APDU = 0x6a,
130 CCID_PC_to_RDR_Secure = 0x69,
131 CCID_PC_to_RDR_Mechanical = 0x71,
132 CCID_PC_to_RDR_Abort = 0x72,
133 CCID_PC_to_RDR_SetDataRateAndClockFrequency = 0x73,
134
135 CCID_RDR_to_PC_DataBlock = 0x80,
136 CCID_RDR_to_PC_SlotStatus = 0x81,
137 CCID_RDR_to_PC_Parameters = 0x82,
138 CCID_RDR_to_PC_Escape = 0x83,
139 CCID_RDR_to_PC_DataRateAndClockFrequency = 0x84,
140 };
141
142 /** Enum for the CCID class specific control requests that can be issued by the USB bus host. */
143 enum CCID_ClassRequests_t
144 {
145 CCID_ABORT = 0x1,
146 CCID_GET_CLOCK_FREQUENCIES = 0x2,
147 CCID_GET_DATA_RATES = 0x3,
148 };
149
150 /** Enum for the CCID class specific descriptor types. */
151 enum CCID_DescriptorTypes_t
152 {
153 CCID_DTYPE_Functional = 0x21, /**< CCID class specific Interface functional descriptor. */
154 };
155
156 enum CCID_Features_Auto_t
157 {
158 CCID_Features_Auto_None = 0x0,
159 CCID_Features_Auto_ParameterConfiguration = 0x2,
160 CCID_Features_Auto_ICCActivation = 0x4,
161 CCID_Features_Auto_VoltageSelection = 0x8,
162
163 CCID_Features_Auto_ICCClockFrequencyChange = 0x10,
164 CCID_Features_Auto_ICCBaudRateChange = 0x20,
165 CCID_Features_Auto_ParameterNegotiation = 0x40,
166 CCID_Features_Auto_PPS = 0x80,
167 };
168
169 enum CCID_Features_ExchangeLevel_t
170 {
171 CCID_Features_ExchangeLevel_TPDU = 0x00010000,
172 CCID_Features_ExchangeLevel_ShortAPDU = 0x00020000,
173 CCID_Features_ExchangeLevel_ShortExtendedAPDU = 0x00040000
174 };
175
176 /* Type Defines: */
177 typedef struct
178 {
179 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
180
181 uint16_t CCID;
182 uint8_t MaxSlotIndex;
183 uint8_t VoltageSupport;
184 uint32_t Protocols;
185 uint32_t DefaultClock;
186 uint32_t MaximumClock;
187 uint8_t NumClockSupported;
188 uint32_t DataRate;
189 uint32_t MaxDataRate;
190 uint8_t NumDataRatesSupported;
191 uint32_t MaxIFSD;
192 uint32_t SynchProtocols;
193 uint32_t Mechanical;
194 uint32_t Features;
195 uint32_t MaxCCIDMessageLength;
196 uint8_t ClassGetResponse;
197 uint8_t ClassEnvelope;
198 uint16_t LcdLayout;
199 uint8_t PINSupport;
200 uint8_t MaxCCIDBusySlots;
201 } ATTR_PACKED USB_CCID_Descriptor_t;
202
203 typedef struct
204 {
205 uint8_t FindexDindex;
206 uint8_t TCCKST0;
207 uint8_t GuardTimeT0;
208 uint8_t WaitingIntegerT0;
209 uint8_t ClockStop;
210 } ATTR_PACKED USB_CCID_ProtocolData_T0_t;
211
212 typedef struct
213 {
214 uint8_t FindexDindex;
215 uint8_t TCCKST1;
216 uint8_t GuardTimeT1;
217 uint8_t WaitingIntegerT1;
218 uint8_t ClockStop;
219 uint8_t FSC;
220 uint8_t NadValue;
221 } ATTR_PACKED USB_CCID_ProtocolData_T1_t;
222
223
224 /** Enum for a common bulk message header. */
225 typedef struct
226 {
227 uint8_t MessageType;
228 uint32_t Length;
229 uint8_t Slot;
230 uint8_t Seq;
231 } ATTR_PACKED USB_CCID_BulkMessage_Header_t;
232
233 typedef struct
234 {
235 USB_CCID_BulkMessage_Header_t CCIDHeader;
236 uint8_t Status;
237 uint8_t Error;
238 uint8_t ChainParam;
239 uint8_t Data[0];
240 } ATTR_PACKED USB_CCID_RDR_to_PC_DataBlock_t;
241
242 typedef struct
243 {
244 USB_CCID_BulkMessage_Header_t CCIDHeader;
245 uint8_t Status;
246 uint8_t Error;
247 uint8_t ClockStatus;
248 } ATTR_PACKED USB_CCID_RDR_to_PC_SlotStatus_t;
249
250 typedef struct
251 {
252 USB_CCID_BulkMessage_Header_t CCIDHeader;
253 uint8_t Status;
254 uint8_t Error;
255 uint8_t ProtocolNum;
256 union
257 {
258 USB_CCID_ProtocolData_T0_t T0;
259 USB_CCID_ProtocolData_T1_t T1;
260 } ProtocolData;
261 } ATTR_PACKED USB_CCID_RDR_to_PC_Parameters_t;
262
263 typedef struct
264 {
265 USB_CCID_BulkMessage_Header_t CCIDHeader;
266 uint8_t Status;
267 uint8_t Error;
268 uint8_t RFU;
269 uint8_t Data[0];
270 } ATTR_PACKED USB_CCID_RDR_to_PC_Escape_t;
271
272 typedef struct
273 {
274 USB_CCID_BulkMessage_Header_t CCIDHeader;
275 uint8_t Status;
276 uint8_t Error;
277 uint8_t RFU;
278 uint32_t ClockFrequency;
279 uint32_t DataRate;
280 } ATTR_PACKED USB_CCID_RDR_to_PC_DataRateAndClockFrequency_t;
281
282 /* Disable C linkage for C++ Compilers: */
283 #if defined(__cplusplus)
284 }
285 #endif
286
287 #endif
288
289 /** @} */
290