Upgrade doxygen configuration files to the latest version.
[pub/lufa.git] / Demos / Device / ClassDriver / CCID / CCID.c
index 9163065..18e8e6c 100644 (file)
@@ -1,14 +1,14 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2018.
+     Copyright (C) Dean Camera, 2021.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2018  Dean Camera (dean [at] fourwalledcubicle [dot] com)
-  Copyright 2018  Filipe Rodrigues (filipepazrodrigues [at] gmail [dot] com)
+  Copyright 2021  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2021  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
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -157,10 +157,11 @@ void EVENT_USB_Device_ControlRequest(void)
  *  whenever an application at the host wants to send a power off signal to a slot.
  *  THe slot must reply back with a recognizable ATR (answer to reset)
  */
  *  whenever an application at the host wants to send a power off signal to a slot.
  *  THe slot must reply back with a recognizable ATR (answer to reset)
  */
-uint8_t CALLBACK_CCID_IccPowerOn(uint8_t slot,
-                                                                uint8_t* atr,
-                                                                uint8_t* attrSize,
-                                                                uint8_t* error)
+uint8_t CALLBACK_CCID_IccPowerOn(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
+                                 const uint8_t slot,
+                                                                uint8_t* const atr,
+                                                                uint8_t* const attrSize,
+                                                                uint8_t* const error)
 {
        if (slot < CCID_Interface.Config.TotalSlots)
        {
 {
        if (slot < CCID_Interface.Config.TotalSlots)
        {
@@ -168,15 +169,19 @@ uint8_t CALLBACK_CCID_IccPowerOn(uint8_t slot,
                *error = CCID_ERROR_NO_ERROR;
                return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE;
        }
                *error = CCID_ERROR_NO_ERROR;
                return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE;
        }
-
-       *error = CCID_ERROR_SLOT_NOT_FOUND;
-       return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
+       else
+       {
+               *error = CCID_ERROR_SLOT_NOT_FOUND;
+               return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
+       }
 }
 
 /** Event handler for the CCID_PC_to_RDR_IccPowerOff message. This message is sent to the device
  *  whenever an application at the host wants to send a power off signal to a slot.
  */
 }
 
 /** Event handler for the CCID_PC_to_RDR_IccPowerOff message. This message is sent to the device
  *  whenever an application at the host wants to send a power off signal to a slot.
  */
-uint8_t CALLBACK_CCID_IccPowerOff(uint8_t slot, uint8_t* error)
+uint8_t CALLBACK_CCID_IccPowerOff(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
+                                  const uint8_t slot,
+                                  uint8_t* const error)
 {
        if (slot < CCID_Interface.Config.TotalSlots)
        {
 {
        if (slot < CCID_Interface.Config.TotalSlots)
        {
@@ -190,11 +195,13 @@ uint8_t CALLBACK_CCID_IccPowerOff(uint8_t slot, uint8_t* error)
        }
 }
 
        }
 }
 
-/** Event handler for the CCID_PC_to_RDR_GetSlotStatus. THis message is sent to the device
+/** Event handler for the CCID_PC_to_RDR_GetSlotStatus. This message is sent to the device
  *  whenever an application at the host wants to the get the current slot status
  *
  */
  *  whenever an application at the host wants to the get the current slot status
  *
  */
-uint8_t CALLBACK_CCID_GetSlotStatus(uint8_t slot, uint8_t* error)
+uint8_t CALLBACK_CCID_GetSlotStatus(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
+                                    const uint8_t slot,
+                                    uint8_t* const error)
 {
        if (slot < CCID_Interface.Config.TotalSlots)
        {
 {
        if (slot < CCID_Interface.Config.TotalSlots)
        {
@@ -203,35 +210,115 @@ uint8_t CALLBACK_CCID_GetSlotStatus(uint8_t slot, uint8_t* error)
        }
        else
        {
        }
        else
        {
-                *error = CCID_ERROR_SLOT_NOT_FOUND;
+               *error = CCID_ERROR_SLOT_NOT_FOUND;
+               return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
+       }
+}
+
+/** Event handler for the CCID_PC_to_RDR_SetParameters when T=0. This message is sent to
+ *  the device whenever an application at the host wants to set the parameters for a
+ *  given slot.
+ */
+uint8_t CALLBACK_CCID_SetParameters_T0(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
+                                                                          const uint8_t Slot,
+                                                                          uint8_t* const Error,
+                                                                          USB_CCID_ProtocolData_T0_t* const T0)
+{
+       if (Slot == 0)
+       {
+               // Set parameters
+               memcpy(&CCIDInterfaceInfo->ProtocolData, T0, sizeof(USB_CCID_ProtocolData_T0_t));
+
+               *Error = CCID_ERROR_NO_ERROR;
+               return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE;
+       }
+       else
+       {
+               *Error = CCID_ERROR_SLOT_NOT_FOUND;
+               return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
+       }
+}
+
+/** Event handler for the CCID_PC_to_RDR_GetParameters when T=0. This message is sent to
+ *  the device whenever an application at the host wants to get the current parameters for
+ *  a given slot.
+ */
+uint8_t CALLBACK_CCID_GetParameters_T0(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
+                                                                          const uint8_t Slot,
+                                                                          uint8_t* const Error,
+                                                                          uint8_t* const ProtocolNum,
+                                                                          USB_CCID_ProtocolData_T0_t* const T0)
+{
+       if (Slot == 0)
+       {
+               *ProtocolNum = CCID_PROTOCOLNUM_T0;
+               memcpy(T0, &CCIDInterfaceInfo->ProtocolData, sizeof(USB_CCID_ProtocolData_T0_t));
+
+               *Error = CCID_ERROR_NO_ERROR;
+               return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE;
+       }
+       else
+       {
+               *Error = CCID_ERROR_SLOT_NOT_FOUND;
                return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
        }
 }
 
                return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
        }
 }
 
-uint8_t CALLBACK_CCID_Abort(uint8_t slot,
-                                                       uint8_t seq,
-                                                       uint8_t* error)
+/** Event handler for the CCID_PC_to_RDR_XfrBlock. This message is sent to the device
+ *  whenever an application at the host wants to send a block of bytes to the device
+ *  THe device reply back with an array of bytes
+ */
+uint8_t CALLBACK_CCID_XfrBlock(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
+                                                          const uint8_t Slot,
+                                                          const uint8_t* ReceivedBuffer,
+                                                          const uint8_t ReceivedBufferSize,
+                                                          uint8_t* const SendBuffer,
+                                                          uint8_t* const SentBufferSize,
+                                                          uint8_t* const Error)
 {
 {
-       if (CCID_Interface.State.Aborted && slot == 0 && CCID_Interface.State.AbortedSeq == seq)
+       if (Slot < CCID_Interface.Config.TotalSlots)
+       {
+               uint8_t OkResponse[2] = {0x90, 0x00};
+
+               memcpy(SendBuffer, OkResponse, sizeof(OkResponse));
+               *SentBufferSize = sizeof(OkResponse);
+
+               *Error = CCID_ERROR_NO_ERROR;
+               return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_NOICCPRESENT;
+       }
+       else
+       {
+                *Error = CCID_ERROR_SLOT_NOT_FOUND;
+         return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
+       }
+}
+
+uint8_t CALLBACK_CCID_Abort(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo,
+                            const uint8_t Slot,
+                                                       const uint8_t Seq,
+                                                       uint8_t* const Error)
+{
+       if (CCID_Interface.State.Aborted && Slot == 0 && CCID_Interface.State.AbortedSeq == Seq)
        {
                CCID_Interface.State.Aborted    = false;
                CCID_Interface.State.AbortedSeq = -1;
        {
                CCID_Interface.State.Aborted    = false;
                CCID_Interface.State.AbortedSeq = -1;
-               *error = CCID_ERROR_NO_ERROR;
+
+               *Error = CCID_ERROR_NO_ERROR;
                return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE;
        }
        else if (!CCID_Interface.State.Aborted)
        {
                return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE;
        }
        else if (!CCID_Interface.State.Aborted)
        {
-               *error = CCID_ERROR_CMD_NOT_ABORTED;
+               *Error = CCID_ERROR_CMD_NOT_ABORTED;
                return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE;
        }
                return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE;
        }
-       else if (slot != 0)
+       else if (Slot != 0)
        {
        {
-               *error = CCID_ERROR_SLOT_NOT_FOUND;
+               *Error = CCID_ERROR_SLOT_NOT_FOUND;
                return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
        }
        else
        {
                return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
        }
        else
        {
-               *error = CCID_ERROR_NOT_SUPPORTED;
+               *Error = CCID_ERROR_NOT_SUPPORTED;
                return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
        }
 }
                return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT;
        }
 }