aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/Class/Common/CCIDClassCommon.h
blob: 3f4031ac8c05ac4d765fd37f6662a9b497f1ab89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
             LUFA Library
     Copyright (C) Dean Camera, 2019.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

/*
  Copyright 2019  Dean Camera (dean [at] fourwalledcubicle [dot] com)
  Copyright 2019  Filipe Rodrigues (filipepazrodrigues [at] gmail [dot] com)

  Permission to use, copy, modify, distribute, and sell this
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in
  all copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.

  The author disclaims all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

/** \file
 *  \brief Common definitions and declarations for the library USB CCID Class driver.
 *
 *  Common definitions and declarations for the library USB CCID Class driver.
 *
 *  \note This file should not be included directly. It is automatically included as needed by the USB module driver
 *        dispatch header located in LUFA/Drivers/USB.h.
 */

/** \ingroup Group_USBClassCCID
 *  \defgroup Group_USBClassCCIDCommon  Common Class Definitions
 *
 *  \section Sec_USBClassCCIDCommon_ModDescription Module Description
 *  Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
 *  CCID Class.
 *
 *  @{
 */

#ifndef _CCID_CLASS_COMMON_H_
#define _CCID_CLASS_COMMON_H_

	/* Includes: */
		#include "../../Core/StdDescriptors.h"

	/* Enable C linkage for C++ Compilers: */
		#if defined(__cplusplus)
			extern "C" {
		#endif

	/* Preprocessor Checks: */
		#if !defined(__INCLUDE_FROM_CCID_DRIVER)
			#error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
		#endif

	/* Macros: */
		#define CCID_CURRENT_SPEC_RELEASE_NUMBER              0x0110
		#define CCID_VOLTAGESUPPORT_5V                        0
		#define CCID_VOLTAGESUPPORT_3V                        (1 << 0)
		#define CCID_VOLTAGESUPPORT_1V8                       (1 << 1)

		#define CCID_PROTOCOLS_T0                             (1 << 0)
		#define CCID_PROTOCOLS_T1                             (1 << 1)

		#define CCID_PROTOCOLNUM_T0                           0
		#define CCID_PROTOCOLNUM_T1                           (1 << 0)

		#define CCID_ICCSTATUS_PRESENTANDACTIVE               0
		#define CCID_ICCSTATUS_PRESENTANDINACTIVE             (1 << 0)
		#define CCID_ICCSTATUS_NOICCPRESENT                   (1 << 1)

		#define CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR      0
		#define CCID_COMMANDSTATUS_ERROR                      1
		#define CCID_COMMANDSTATUS_FAILED                     (1 << 6)
		#define CCID_COMMANDSTATUS_TIMEEXTENSIONREQUESTED     (2 << 6)
		#define CCID_COMMANDSTATUS_RFU                        (3 << 6)

		#define CCID_ERROR_RFU_START                          0x80
		#define CCID_ERROR_NO_ERROR                           0x80
		#define CCID_ERROR_NOT_SUPPORTED                      0
		#define CCID_ERROR_CMD_ABORTED                        0xFF
		#define CCID_ERROR_CMD_NOT_ABORTED                    0xFF

		#define CCID_ERROR_PARAMETERS_PROTOCOL_NOT_SUPPORTED  0x7

		#define CCID_ERROR_SLOT_NOT_FOUND                     5

		#define CCID_DESCRIPTOR_CLOCK_KHZ(khz)                (khz)
		#define CCID_DESCRIPTOR_CLOCK_MHZ(mhz)                ((mhz) * 1000)


	/* Enums: */
		/** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the CCID
		 *  device class.
		 */
		enum CCID_Descriptor_ClassSubclassProtocol_t
		{
			CCID_CSCP_CCIDClass                         = 0x0b, /**< Descriptor Class value indicating that the device or interface
			                                                     *   belongs to the CCID class.
			                                                     */
			CCID_CSCP_NoSpecificSubclass                = 0x00, /**< Descriptor Subclass value indicating that the device or interface
			                                                     *   belongs to no specific subclass of the CCID class.
			                                                     */
			CCID_CSCP_NoSpecificProtocol                = 0x00, /**< Descriptor Protocol value indicating that the device or interface
			                                                     *   belongs to no specific protocol of the CCID class.
			                                                     */
		};

		/** Enum for possible bulk messages between PC and Reader */
		enum CCID_BulkOutMessages_t
		{
			CCID_PC_to_RDR_IccPowerOn                   = 0x62,
			CCID_PC_to_RDR_IccPowerOff                  = 0x63,
			CCID_PC_to_RDR_GetSlotStatus                = 0x65,
			CCID_PC_to_RDR_XfrBlock                     = 0x6f,
			CCID_PC_to_RDR_GetParameters                = 0x6c,
			CCID_PC_to_RDR_ResetParameters              = 0x6d,
			CCID_PC_to_RDR_SetParameters                = 0x61,
			CCID_PC_to_RDR_Escape                       = 0x6b,
			CCID_PC_to_RDR_IccClock                     = 0x6e,
			CCID_PC_to_RDR_T0APDU                       = 0x6a,
			CCID_PC_to_RDR_Secure                       = 0x69,
			CCID_PC_to_RDR_Mechanical                   = 0x71,
			CCID_PC_to_RDR_Abort                        = 0x72,
			CCID_PC_to_RDR_SetDataRateAndClockFrequency = 0x73,

			CCID_RDR_to_PC_DataBlock                    = 0x80,
			CCID_RDR_to_PC_SlotStatus                   = 0x81,
			CCID_RDR_to_PC_Parameters                   = 0x82,
			CCID_RDR_to_PC_Escape                       = 0x83,
			CCID_RDR_to_PC_DataRateAndClockFrequency    = 0x84,
		};

		/** Enum for the CCID class specific control requests that can be issued by the USB bus host. */
		enum CCID_ClassRequests_t
		{
			CCID_ABORT                                  = 0x1,
			CCID_GET_CLOCK_FREQUENCIES                  = 0x2,
			CCID_GET_DATA_RATES                         = 0x3,
		};

		/** Enum for the CCID class specific descriptor types. */
		enum CCID_DescriptorTypes_t
		{
			CCID_DTYPE_Functional                       = 0x21, /**< CCID class specific Interface functional descriptor. */
		};

		enum CCID_Features_Auto_t
		{
			CCID_Features_Auto_None 					= 0x0,
			CCID_Features_Auto_ParameterConfiguration	= 0x2,
			CCID_Features_Auto_ICCActivation			= 0x4,
			CCID_Features_Auto_VoltageSelection			= 0x8,

			CCID_Features_Auto_ICCClockFrequencyChange	= 0x10,
			CCID_Features_Auto_ICCBaudRateChange		= 0x20,
			CCID_Features_Auto_ParameterNegotiation		= 0x40,
			CCID_Features_Auto_PPS						= 0x80,
		};

		enum CCID_Features_ExchangeLevel_t
		{
			CCID_Features_ExchangeLevel_TPDU  				= 0x00010000,
			CCID_Features_ExchangeLevel_ShortAPDU 			= 0x00020000,
			CCID_Features_ExchangeLevel_ShortExtendedAPDU	= 0x00040000
		};

	/* Type Defines: */
		typedef struct
		{
			USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */

			uint16_t    CCID;
			uint8_t     MaxSlotIndex;
			uint8_t     VoltageSupport;
			uint32_t    Protocols;
			uint32_t    DefaultClock;
			uint32_t    MaximumClock;
			uint8_t     NumClockSupported;
			uint32_t    DataRate;
			uint32_t    MaxDataRate;
			uint8_t     NumDataRatesSupported;
			uint32_t    MaxIFSD;
			uint32_t    SynchProtocols;
			uint32_t    Mechanical;
			uint32_t    Features;
			uint32_t    MaxCCIDMessageLength;
			uint8_t     ClassGetResponse;
			uint8_t     ClassEnvelope;
			uint16_t    LcdLayout;
			uint8_t     PINSupport;
			uint8_t     MaxCCIDBusySlots;
		} ATTR_PACKED USB_CCID_Descriptor_t;

		typedef struct
		{
			uint8_t FindexDindex;
			uint8_t TCCKST0;
			uint8_t GuardTimeT0;
			uint8_t WaitingIntegerT0;
			uint8_t ClockStop;
		} ATTR_PACKED USB_CCID_ProtocolData_T0_t;

		typedef struct
		{
			uint8_t FindexDindex;
			uint8_t TCCKST1;
			uint8_t GuardTimeT1;
			uint8_t WaitingIntegerT1;
			uint8_t ClockStop;
			uint8_t FSC;
			uint8_t NadValue;
		} ATTR_PACKED USB_CCID_ProtocolData_T1_t;


		/** Enum for a common bulk message header. */
		typedef struct
		{
			uint8_t     MessageType;
			uint32_t    Length;
			uint8_t     Slot;
			uint8_t     Seq;
		} ATTR_PACKED USB_CCID_BulkMessage_Header_t;

		typedef struct
		{
			USB_CCID_BulkMessage_Header_t CCIDHeader;
			uint8_t Status;
			uint8_t Error;
			uint8_t ChainParam;
			uint8_t Data[0];
		} ATTR_PACKED USB_CCID_RDR_to_PC_DataBlock_t;

		typedef struct
		{
			USB_CCID_BulkMessage_Header_t CCIDHeader;
			uint8_t Status;
			uint8_t Error;
			uint8_t ClockStatus;
		} ATTR_PACKED USB_CCID_RDR_to_PC_SlotStatus_t;

		typedef struct
		{
			USB_CCID_BulkMessage_Header_t CCIDHeader;
			uint8_t Status;
			uint8_t Error;
			uint8_t ProtocolNum;
			union
			{
				USB_CCID_ProtocolData_T0_t T0;
				USB_CCID_ProtocolData_T1_t T1;
			} ProtocolData;
		} ATTR_PACKED USB_CCID_RDR_to_PC_Parameters_t;

		typedef struct
		{
			USB_CCID_BulkMessage_Header_t CCIDHeader;
			uint8_t Status;
			uint8_t Error;
			uint8_t RFU;
			uint8_t Data[0];
		} ATTR_PACKED USB_CCID_RDR_to_PC_Escape_t;

		typedef struct
		{
			USB_CCID_BulkMessage_Header_t CCIDHeader;
			uint8_t Status;
			uint8_t Error;
			uint8_t RFU;
			uint32_t ClockFrequency;
			uint32_t DataRate;
		} ATTR_PACKED USB_CCID_RDR_to_PC_DataRateAndClockFrequency_t;

	/* Disable C linkage for C++ Compilers: */
		#if defined(__cplusplus)
			}
		#endif

#endif

/** @} */