Reformatting and add const qualifiers.
[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 /* Type Defines: */
157 typedef struct
158 {
159 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
160
161 uint16_t CCID;
162 uint8_t MaxSlotIndex;
163 uint8_t VoltageSupport;
164 uint32_t Protocols;
165 uint32_t DefaultClock;
166 uint32_t MaximumClock;
167 uint8_t NumClockSupported;
168 uint32_t DataRate;
169 uint32_t MaxDataRate;
170 uint8_t NumDataRatesSupported;
171 uint32_t MaxIFSD;
172 uint32_t SynchProtocols;
173 uint32_t Mechanical;
174 uint32_t Features;
175 uint32_t MaxCCIDMessageLength;
176 uint8_t ClassGetResponse;
177 uint8_t ClassEnvelope;
178 uint16_t LcdLayout;
179 uint8_t PINSupport;
180 uint8_t MaxCCIDBusySlots;
181 } ATTR_PACKED USB_CCID_Descriptor_t;
182
183 typedef struct
184 {
185 uint8_t FindexDindex;
186 uint8_t TCCKST0;
187 uint8_t GuardTimeT0;
188 uint8_t WaitingIntegerT0;
189 uint8_t ClockStop;
190 } ATTR_PACKED USB_CCID_ProtocolData_T0_t;
191
192 typedef struct
193 {
194 uint8_t FindexDindex;
195 uint8_t TCCKST1;
196 uint8_t GuardTimeT1;
197 uint8_t WaitingIntegerT1;
198 uint8_t ClockStop;
199 uint8_t FSC;
200 uint8_t NadValue;
201 } ATTR_PACKED USB_CCID_ProtocolData_T1_t;
202
203
204 /** Enum for a common bulk message header. */
205 typedef struct
206 {
207 uint8_t MessageType;
208 uint32_t Length;
209 uint8_t Slot;
210 uint8_t Seq;
211 } ATTR_PACKED USB_CCID_BulkMessage_Header_t;
212
213 typedef struct
214 {
215 USB_CCID_BulkMessage_Header_t CCIDHeader;
216 uint8_t Status;
217 uint8_t Error;
218 uint8_t ChainParam;
219 uint8_t Data[0];
220 } ATTR_PACKED USB_CCID_RDR_to_PC_DataBlock_t;
221
222 typedef struct
223 {
224 USB_CCID_BulkMessage_Header_t CCIDHeader;
225 uint8_t Status;
226 uint8_t Error;
227 uint8_t ClockStatus;
228 } ATTR_PACKED USB_CCID_RDR_to_PC_SlotStatus_t;
229
230 typedef struct
231 {
232 USB_CCID_BulkMessage_Header_t CCIDHeader;
233 uint8_t Status;
234 uint8_t Error;
235 uint8_t ProtocolNum;
236 union
237 {
238 USB_CCID_ProtocolData_T0_t T0;
239 USB_CCID_ProtocolData_T1_t T1;
240 } ProtocolData;
241 } ATTR_PACKED USB_CCID_RDR_to_PC_Parameters_t;
242
243 typedef struct
244 {
245 USB_CCID_BulkMessage_Header_t CCIDHeader;
246 uint8_t Status;
247 uint8_t Error;
248 uint8_t RFU;
249 uint8_t Data[0];
250 } ATTR_PACKED USB_CCID_RDR_to_PC_Escape_t;
251
252 typedef struct
253 {
254 USB_CCID_BulkMessage_Header_t CCIDHeader;
255 uint8_t Status;
256 uint8_t Error;
257 uint8_t RFU;
258 uint32_t ClockFrequency;
259 uint32_t DataRate;
260 } ATTR_PACKED USB_CCID_RDR_to_PC_DataRateAndClockFrequency_t;
261
262 /* Disable C linkage for C++ Compilers: */
263 #if defined(__cplusplus)
264 }
265 #endif
266
267 #endif
268
269 /** @} */
270