Documentation: Update copyrights to 2020.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / CCIDClassDevice.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2020.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2020 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11 Copyright 2020 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 Device mode driver for the library USB CCID Class driver.
34 *
35 * Device mode driver 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_USBClassCCIDDevice CCID Class Device Mode Driver
43 *
44 * \section Sec_USBClassCCIDDevice_Dependencies Module Source Dependencies
45 * The following files must be built with any user project that uses this module:
46 * - LUFA/Drivers/USB/Class/Device/CCIDClassDevice.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
47 *
48 * \section Sec_USBClassCCIDDevice_ModDescription Module Description
49 * Device Mode USB Class driver framework interface, for the CCID USB Class driver.
50 *
51 * @{
52 */
53
54 #ifndef _CCID_CLASS_DEVICE_H_
55 #define _CCID_CLASS_DEVICE_H_
56
57 /* Includes: */
58 #include "../../USB.h"
59 #include "../Common/CCIDClassCommon.h"
60
61 /* Public Interface - May be used in end-application: */
62 /* Type Defines: */
63 /** \brief CCID Class Device Mode Configuration and State Structure.
64 *
65 * Class state structure. An instance of this structure should be made for each CCID interface
66 * within the user application, and passed to each of the CCID class driver functions as the
67 * CCIDInterfaceInfo parameter. This stores each CCID interface's configuration and state information.
68 */
69 typedef struct
70 {
71 struct
72 {
73 uint8_t InterfaceNumber; /**< Interface number of the CCID interface within the device. */
74 uint8_t TotalSlots; /**< Total of slots no this device. */
75 USB_Endpoint_Table_t DataINEndpoint; /**< Data IN endpoint configuration table. */
76 USB_Endpoint_Table_t DataOUTEndpoint; /**< Data OUT endpoint configuration table. */
77 } Config; /**< Config data for the USB class interface within the device. All elements in this section
78 * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
79 */
80 struct
81 {
82 bool Aborted; //< Set if host has started an abort process
83 uint8_t AbortedSeq; //< Sequence number for the current abort process
84 } State; /**< State data for the USB class interface within the device. All elements in this section
85 * are reset to their defaults when the interface is enumerated.
86 */
87 USB_CCID_ProtocolData_T0_t ProtocolData;
88 } USB_ClassInfo_CCID_Device_t;
89
90 /* Function Prototypes: */
91 /** Configures the endpoints of a given CCID interface, ready for use. This should be linked to the library
92 * \ref EVENT_USB_Device_ConfigurationChanged() event so that the endpoints are configured when the configuration containing
93 * the given CCID interface is selected.
94 *
95 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration.
96 *
97 * \return Boolean \c true if the endpoints were successfully configured, \c false otherwise.
98 */
99 bool CCID_Device_ConfigureEndpoints(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
100
101 /** Processes incoming control requests from the host, that are directed to the given CCID class interface. This should be
102 * linked to the library \ref EVENT_USB_Device_ControlRequest() event.
103 *
104 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
105 */
106 void CCID_Device_ProcessControlRequest(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
107
108 /** General management task for a given CCID class interface, required for the correct operation of the interface. This should
109 * be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
110 *
111 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
112 */
113 void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
114
115 /** CCID class driver callback for PC_TO_RDR_IccPowerOn CCID message
116 * When the ICC is inserted into a slot of a CCID, the CCID can activate the ICC, and the ICC will respond with an ATR
117 * (answer to reset)
118 *
119 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
120 * \param[in] Slot The slot ID currently being powered on.
121 * \param[in,out] Atr Pointer to an array containing the Power On ATR being sent to the device.
122 * \param[out] AtrSize The size of the ATR being sent (up to 15 bytes maximum).
123 * \param[out] Error The result of the operation, or error.
124 *
125 * \return The command result code.
126 */
127 uint8_t CALLBACK_CCID_IccPowerOn(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
128 const uint8_t Slot,
129 uint8_t* const Atr,
130 uint8_t* const AtrSize,
131 uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1);
132
133 /** CCID class driver callback for PC_TO_RDR_IccPowerOff CCID message
134 * Turns off the ICC
135 *
136 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
137 * \param[in] Slot The slot ID currently being powered off.
138 * \param[out] Error The result of the operation, or error.
139 *
140 * \return The command result code.
141 */
142 uint8_t CALLBACK_CCID_IccPowerOff(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
143 const uint8_t Slot,
144 uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1);
145
146 /** CCID class driver callback for PC_TO_RDR_GetSlotStatus CCID message
147 * Retrieves the current status of a given slot
148 *
149 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
150 * \param[in] Slot The slot ID from which we want to retrieve the status.
151 * \param[out] Error The result of the operation, or error.
152 *
153 * \return The command result code.
154 */
155 uint8_t CALLBACK_CCID_GetSlotStatus(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
156 const uint8_t Slot,
157 uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1);
158
159
160 /** CCID class driver callback for PC_TO_RDR_SetParameters CCID message for T=0
161 * Sets the current parameters of a given slot
162 *
163 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration, state and protocol data.
164 * \param[in] Slot The slot ID from which we want to retrieve the status.
165 * \param[out] Error The result of the operation, or error.
166 * \param[out] T0 Pointer to a buffer containing the new parameters
167 *
168 * \return The command result code.
169 */
170 uint8_t CALLBACK_CCID_SetParameters_T0(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
171 const uint8_t Slot,
172 uint8_t* const Error,
173 USB_CCID_ProtocolData_T0_t* const T0) ATTR_NON_NULL_PTR_ARG(1);
174
175 /** CCID class driver callback for PC_TO_RDR_SetParameters CCID message for T=0
176 * Retrieves the current parameters of a given slot
177 *
178 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration, state and protocol data.
179 * \param[in] Slot The slot ID from which we want to retrieve the status.
180 * \param[out] Error The result of the operation, or error.
181 * \param[out] ProtocolNum The CCID protocol ID of the parameter being retrieved.
182 * \param[out] T0 Pointer to a buffer where the parameters will be returned
183 *
184 * \return The command result code.
185 */
186 uint8_t CALLBACK_CCID_GetParameters_T0(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
187 const uint8_t Slot,
188 uint8_t* const Error,
189 uint8_t* const ProtocolNum,
190 USB_CCID_ProtocolData_T0_t* const T0) ATTR_NON_NULL_PTR_ARG(1);
191
192 /** CCID class driver callback for PC_TO_RDR_XfrBlock CCID message
193 * Send a block of bytes from the host to a slot in the device
194 * and also received a block of bytes as a response
195 *
196 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
197 * \param[in] Slot The slot ID from which we want to retrieve the status.
198 * \param[in] ReceivedBuffer Pointer to an array holding the received block of bytes
199 * \param[in] ReceivedBufferSize The size of the received block of bytes
200 * \param[out] SendBuffer Pointer to a buffer which will hold the bytes being sent back to the host
201 * \param[out] SentBufferSize The size of the block of bytes being sent back to the host
202 * \param[out] Error The result of the operation, or error.
203 *
204 * \return The command result code.
205 */
206 uint8_t CALLBACK_CCID_XfrBlock(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
207 const uint8_t Slot,
208 const uint8_t* ReceivedBuffer,
209 const uint8_t ReceivedBufferSize,
210 uint8_t* const SendBuffer,
211 uint8_t* const SentBufferSize,
212 uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1);
213
214 /** CCID class driver callback for CCID_PC_to_RDR_Abort CCID message
215 * Aborts a BULK out message previously sent to a slot
216 *
217 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
218 * \param[in] Slot The slot ID to where the message being aborted was sent to.
219 * \param[in] Seq The current sequence number for this message. Must be checked against
220 * the current abort message being sent at the control pipe.
221 * \param[out] Error The result of the operation, or error.
222 *
223 * \return The command result code.
224 */
225 uint8_t CALLBACK_CCID_Abort(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
226 const uint8_t Slot,
227 const uint8_t Seq,
228 uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1);
229
230
231 #endif
232
233 /** @} */