3      Copyright (C) Dean Camera, 2018. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2018  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  11   Copyright 2018  Filipe Rodrigues (filipepazrodrigues [at] gmail [dot] com) 
  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. 
  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 
  33  *  \brief Device mode driver for the library USB CCID Class driver. 
  35  *  Device mode driver for the library USB CCID Class driver. 
  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. 
  41 /** \ingroup Group_USBClassCCID 
  42  *  \defgroup Group_USBClassCCIDDevice CCID Class Device Mode Driver 
  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> 
  48  *  \section Sec_USBClassCCIDDevice_ModDescription Module Description 
  49  *  Device Mode USB Class driver framework interface, for the CCID USB Class driver. 
  54 #ifndef _CCID_CLASS_DEVICE_H_ 
  55 #define _CCID_CLASS_DEVICE_H_ 
  58                 #include "../../USB.h" 
  59                 #include "../Common/CCIDClassCommon.h" 
  61         /* Public Interface - May be used in end-application: */ 
  63                         /** \brief CCID Class Device Mode Configuration and State Structure. 
  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. 
  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. 
  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. 
  87                                 USB_CCID_ProtocolData_T0_t ProtocolData
; 
  88                         } USB_ClassInfo_CCID_Device_t
; 
  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. 
  95                          *      \param[in,out] CCIDInterfaceInfo        Pointer to a structure containing a CCID Class configuration. 
  97                          *      \return Boolean \c true if the endpoints were successfully configured, \c false otherwise. 
  99                         bool CCID_Device_ConfigureEndpoints(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
) ATTR_NON_NULL_PTR_ARG(1); 
 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. 
 104                          *      \param[in,out] CCIDInterfaceInfo        Pointer to a structure containing a CCID Class configuration and state. 
 106                         void CCID_Device_ProcessControlRequest(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
) ATTR_NON_NULL_PTR_ARG(1); 
 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(). 
 111                          *      \param[in,out] CCIDInterfaceInfo        Pointer to a structure containing a CCID Class configuration and state. 
 113                         void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
) ATTR_NON_NULL_PTR_ARG(1); 
 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 
 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. 
 125                          *  \return     The command result code. 
 127                         uint8_t CALLBACK_CCID_IccPowerOn(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
, 
 130                                                          uint8_t* const AtrSize
, 
 131                                                          uint8_t* const Error
) ATTR_NON_NULL_PTR_ARG(1); 
 133                         /** CCID class driver callback for PC_TO_RDR_IccPowerOff CCID message 
 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. 
 140                          *  \return     The command result code. 
 142                         uint8_t CALLBACK_CCID_IccPowerOff(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
, 
 144                                                           uint8_t* const Error
) ATTR_NON_NULL_PTR_ARG(1); 
 146                         /** CCID class driver callback for PC_TO_RDR_GetSlotStatus CCID message 
 147                          *  Retrieves the current status of a given slot 
 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. 
 153                          *  \return     The command result code. 
 155                         uint8_t CALLBACK_CCID_GetSlotStatus(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
, 
 157                                                             uint8_t* const Error
) ATTR_NON_NULL_PTR_ARG(1); 
 160                         /** CCID class driver callback for PC_TO_RDR_SetParameters CCID message for T=0 
 161                          *  Sets the current parameters of a given slot 
 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 
 168                          *  \return     The command result code. 
 170                         uint8_t CALLBACK_CCID_SetParameters_T0(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
, 
 172                                                                                                    uint8_t* const Error
, 
 173                                                                                                    USB_CCID_ProtocolData_T0_t
* const T0
); 
 175                         /** CCID class driver callback for PC_TO_RDR_SetParameters CCID message for T=0 
 176                          *  Retrieves the current parameters of a given slot 
 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 
 183                          *  \return     The command result code. 
 185                         uint8_t CALLBACK_CCID_GetParameters_T0(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
, 
 187                                                                                                    uint8_t* const Error
, 
 188                                                                                                    uint8_t* const ProtocolNum
, 
 189                                                                                                    USB_CCID_ProtocolData_T0_t
* const T0
); 
 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 
 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. 
 203                          *  \return     The command result code. 
 205                         uint8_t CALLBACK_CCID_XfrBlock(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
, 
 207                                                                                    uint8_t* const ReceivedBuffer
, 
 208                                                                                    uint8_t ReceivedBufferSize
, 
 209                                                                                    uint8_t* const SendBuffer
, 
 210                                                                                    uint8_t* const SentBufferSize
, 
 211                                                                                    uint8_t* const Error
); 
 213                         /** CCID class driver callback for CCID_PC_to_RDR_Abort CCID message 
 214                          *  Aborts a BULK out message previously sent to a slot 
 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. 
 222                          *  \return     The command result code. 
 224                         uint8_t CALLBACK_CCID_Abort(USB_ClassInfo_CCID_Device_t
* const CCIDInterfaceInfo
, 
 227                                                     uint8_t* const Error
) ATTR_NON_NULL_PTR_ARG(1);