CCID: Initial support for GetParameters and SetParameters
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / CCIDClassDevice.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 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 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 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 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 uint8_t slot,
172 uint8_t* const error,
173 USB_CCID_ProtocolData_T0_t* const t0);
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] t0 Pointer to a buffer where the parameters will be returned
182 *
183 * \return The command result code.
184 */
185 uint8_t CALLBACK_CCID_GetParameters_T0(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
186 uint8_t slot,
187 uint8_t* const error,
188 uint8_t* const ProtocolNum,
189 USB_CCID_ProtocolData_T0_t* const t0);
190
191 /** CCID class driver callback for PC_TO_RDR_XfrBlock CCID message
192 * Send a block of bytes from the host to a slot in the device
193 * and also received a block of bytes as a response
194 *
195 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
196 * \param[in] slot The slot ID from which we want to retrieve the status.
197 * \param[in] receivedBuffer Pointer to an array holding the received block of bytes
198 * \param[in] receivedBufferSize The size of the received block of bytes
199 * \param[out] sendBuffer Pointer to a buffer which will hold the bytes being sent back to the host
200 * \param[out] sentBufferSize The size of the block of bytes being sent back to the host
201 * \param[out] error The result of the operation, or error.
202 *
203 * \return The command result code.
204 */
205 uint8_t CALLBACK_CCID_XfrBlock(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
206 uint8_t slot,
207 uint8_t* const receivedBuffer,
208 uint8_t receivedBufferSize,
209 uint8_t* const sendBuffer,
210 uint8_t* const sentBufferSize,
211 uint8_t* const error);
212
213 /** CCID class driver callback for CCID_PC_to_RDR_Abort CCID message
214 * Aborts a BULK out message previously sent to a slot
215 *
216 * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state.
217 * \param[in] slot The slot ID to where the message being aborted was sent to.
218 * \param[in] seq The current sequence number for this message. Must be checked against
219 * the current abort message being sent at the control pipe.
220 * \param[out] error The result of the operation, or error.
221 *
222 * \return The command result code.
223 */
224 uint8_t CALLBACK_CCID_Abort(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
225 uint8_t slot,
226 uint8_t seq,
227 uint8_t* const error) ATTR_NON_NULL_PTR_ARG(1);
228
229
230 #endif
231
232 /** @} */