From 2a057a7209a1a4457306a2bb42894f42a05fffcd Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 6 Aug 2018 19:43:44 +1000 Subject: Clean up CCID class driver and associated demos. --- Demos/Device/ClassDriver/CCID/CCID.c | 97 +++++++------- Demos/Device/LowLevel/CCID/CCID.c | 169 +++++++++++++----------- LUFA/Drivers/USB/Class/Common/CCIDClassCommon.h | 50 +++---- LUFA/Drivers/USB/Class/Device/CCIDClassDevice.c | 31 +++-- LUFA/Drivers/USB/Class/Device/CCIDClassDevice.h | 92 ++++++------- 5 files changed, 227 insertions(+), 212 deletions(-) diff --git a/Demos/Device/ClassDriver/CCID/CCID.c b/Demos/Device/ClassDriver/CCID/CCID.c index 15d2852e4..f0dae9129 100644 --- a/Demos/Device/ClassDriver/CCID/CCID.c +++ b/Demos/Device/ClassDriver/CCID/CCID.c @@ -169,9 +169,11 @@ uint8_t CALLBACK_CCID_IccPowerOn(USB_ClassInfo_CCID_Device_t* const CCIDInterfac *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 @@ -208,59 +210,56 @@ uint8_t CALLBACK_CCID_GetSlotStatus(USB_ClassInfo_CCID_Device_t* const CCIDInter } 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. + * 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, - uint8_t slot, - uint8_t* const error, - USB_CCID_ProtocolData_T0_t* const t0) + uint8_t Slot, + uint8_t* const Error, + USB_CCID_ProtocolData_T0_t* const T0) { - if (slot == 0) + if (Slot == 0) { - //set parameters - memcpy(&CCIDInterfaceInfo->ProtocolData, t0, sizeof(USB_CCID_ProtocolData_T0_t)); - - *error = CCID_ERROR_NO_ERROR; + // 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; + *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. + * 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, - uint8_t slot, - uint8_t* const error, + uint8_t Slot, + uint8_t* const Error, uint8_t* const ProtocolNum, - USB_CCID_ProtocolData_T0_t* const t0) + USB_CCID_ProtocolData_T0_t* const T0) { - if (slot == 0) + if (Slot == 0) { - - *ProtocolNum = CCID_PROTOCOLNUM_T0; - memcpy(t0, &CCIDInterfaceInfo->ProtocolData, sizeof(USB_CCID_ProtocolData_T0_t)); - *ProtocolNum = CCID_PROTOCOLNUM_T0; + memcpy(T0, &CCIDInterfaceInfo->ProtocolData, sizeof(USB_CCID_ProtocolData_T0_t)); - *error = CCID_ERROR_NO_ERROR; + *Error = CCID_ERROR_NO_ERROR; return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } else { - *error = CCID_ERROR_SLOT_NOT_FOUND; + *Error = CCID_ERROR_SLOT_NOT_FOUND; return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT; } } @@ -270,54 +269,56 @@ uint8_t CALLBACK_CCID_GetParameters_T0(USB_ClassInfo_CCID_Device_t* const CCIDIn * THe device reply back with an array of bytes */ uint8_t CALLBACK_CCID_XfrBlock(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, - uint8_t* const receivedBuffer, - uint8_t receivedBufferSize, - uint8_t* const sendBuffer, - uint8_t* const sentBufferSize, - uint8_t* const error) + uint8_t Slot, + uint8_t* const ReceivedBuffer, + uint8_t ReceivedBufferSize, + uint8_t* const SendBuffer, + uint8_t* const SentBufferSize, + uint8_t* const Error) { - if (slot < CCID_Interface.Config.TotalSlots) + if (Slot < CCID_Interface.Config.TotalSlots) { - uint8_t okResponse[2] = {0x90, 0x00}; - memcpy(sendBuffer, okResponse, sizeof(okResponse)); - *sentBufferSize = sizeof(okResponse); + uint8_t OkResponse[2] = {0x90, 0x00}; - *error = CCID_ERROR_NO_ERROR; + 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; + *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, - uint8_t slot, - uint8_t seq, - uint8_t* const error) + uint8_t Slot, + uint8_t Seq, + uint8_t* const Error) { - if (CCID_Interface.State.Aborted && slot == 0 && CCID_Interface.State.AbortedSeq == seq) + if (CCID_Interface.State.Aborted && Slot == 0 && CCID_Interface.State.AbortedSeq == Seq) { 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) { - *error = CCID_ERROR_CMD_NOT_ABORTED; + *Error = CCID_ERROR_CMD_NOT_ABORTED; 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 { - *error = CCID_ERROR_NOT_SUPPORTED; + *Error = CCID_ERROR_NOT_SUPPORTED; return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT; } } diff --git a/Demos/Device/LowLevel/CCID/CCID.c b/Demos/Device/LowLevel/CCID/CCID.c index e55651373..6e3721669 100644 --- a/Demos/Device/LowLevel/CCID/CCID.c +++ b/Demos/Device/LowLevel/CCID/CCID.c @@ -52,21 +52,21 @@ static bool Aborted; static uint8_t AbortedSeq; -static USB_CCID_ProtocolData_T0_t ProtocolData; - +static USB_CCID_ProtocolData_T0_t ProtocolData = + { + .FindexDindex = 0x11, + .TCCKST0 = 0x00, + .GuardTimeT0 = 0x00, + .WaitingIntegerT0 = 0x0A, + .ClockStop = 0x00, + }; /** Main program entry point. This routine configures the hardware required by the application, then * enters a loop to run the application tasks in sequence. */ int main(void) { - ProtocolData.FindexDindex = 0x11; - ProtocolData.TCCKST0 = 0x00; - ProtocolData.GuardTimeT0 = 0x00; - ProtocolData.WaitingIntegerT0 = 0x0A; - ProtocolData.ClockStop = 0x00; - SetupHardware(); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); @@ -175,6 +175,7 @@ void EVENT_USB_Device_ControlRequest(void) break; } + case CCID_GET_CLOCK_FREQUENCIES: { if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) @@ -186,6 +187,7 @@ void EVENT_USB_Device_ControlRequest(void) break; } + case CCID_GET_DATA_RATES: { if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) @@ -204,21 +206,21 @@ 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) */ -uint8_t CCID_IccPowerOn(uint8_t slot, - uint8_t* const atr, - uint8_t* const atrLength, - uint8_t* const error) +uint8_t CCID_IccPowerOn(uint8_t Slot, + uint8_t* const Atr, + uint8_t* const AtrLength, + uint8_t* const Error) { - if (slot == 0) + if (Slot == 0) { - Iso7816_CreateSimpleAtr(atr, atrLength); + Iso7816_CreateSimpleAtr(Atr, AtrLength); - *error = CCID_ERROR_NO_ERROR; + *Error = CCID_ERROR_NO_ERROR; return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } else { - *error = CCID_ERROR_SLOT_NOT_FOUND; + *Error = CCID_ERROR_SLOT_NOT_FOUND; return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT; } } @@ -226,17 +228,17 @@ uint8_t CCID_IccPowerOn(uint8_t 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 CCID_IccPowerOff(uint8_t slot, - uint8_t* const error) +uint8_t CCID_IccPowerOff(uint8_t Slot, + uint8_t* const Error) { - if (slot == 0) + if (Slot == 0) { - *error = CCID_ERROR_NO_ERROR; + *Error = CCID_ERROR_NO_ERROR; return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_NOICCPRESENT; } else { - *error = CCID_ERROR_SLOT_NOT_FOUND; + *Error = CCID_ERROR_SLOT_NOT_FOUND; return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT; } } @@ -245,65 +247,65 @@ uint8_t CCID_IccPowerOff(uint8_t slot, * the device whenever an application at the host wants to get the current * slot status. */ -uint8_t CCID_GetSlotStatus(uint8_t slot, - uint8_t* const error) +uint8_t CCID_GetSlotStatus(uint8_t Slot, + uint8_t* const Error) { - if (slot == 0) + if (Slot == 0) { - *error = CCID_ERROR_NO_ERROR; + *Error = CCID_ERROR_NO_ERROR; return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } 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 CCID_SetParameters_T0(uint8_t slot, - uint8_t* const error, - USB_CCID_ProtocolData_T0_t* const t0) +uint8_t CCID_SetParameters_T0(uint8_t Slot, + uint8_t* const Error, + USB_CCID_ProtocolData_T0_t* const T0) { - if (slot == 0) + if (Slot == 0) { - //set parameters - memcpy(&ProtocolData, t0, sizeof(USB_CCID_ProtocolData_T0_t)); - - *error = CCID_ERROR_NO_ERROR; + // Set parameters + memcpy(&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; + *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 CCID_GetParameters_T0(uint8_t slot, - uint8_t* const error, - uint8_t* ProtocolNum, - USB_CCID_ProtocolData_T0_t* const t0) +uint8_t CCID_GetParameters_T0(uint8_t Slot, + uint8_t* const Error, + uint8_t* ProtocolNum, + USB_CCID_ProtocolData_T0_t* const T0) { - if (slot == 0) + if (Slot == 0) { *ProtocolNum = CCID_PROTOCOLNUM_T0; - memcpy(t0, &ProtocolData, sizeof(USB_CCID_ProtocolData_T0_t)); - - *ProtocolNum = CCID_PROTOCOLNUM_T0; + memcpy(T0, &ProtocolData, sizeof(USB_CCID_ProtocolData_T0_t)); - *error = CCID_ERROR_NO_ERROR; + *Error = CCID_ERROR_NO_ERROR; return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } else { - *error = CCID_ERROR_SLOT_NOT_FOUND; + *Error = CCID_ERROR_SLOT_NOT_FOUND; return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT; } } @@ -312,25 +314,26 @@ uint8_t CCID_GetParameters_T0(uint8_t slot, * 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 CCID_XfrBlock(uint8_t slot, - uint8_t* const receivedBuffer, - uint8_t receivedBufferSize, - uint8_t* const sendBuffer, - uint8_t* const sentBufferSize, - uint8_t* const error) +uint8_t CCID_XfrBlock(uint8_t Slot, + uint8_t* const ReceivedBuffer, + uint8_t ReceivedBufferSize, + uint8_t* const SendBuffer, + uint8_t* const SentBufferSize, + uint8_t* const Error) { - if (slot == 0) + if (Slot == 0) { - uint8_t okResponse[2] = {0x90, 0x00}; - memcpy(sendBuffer, okResponse, sizeof(okResponse)); - *sentBufferSize = sizeof(okResponse); + uint8_t OkResponse[2] = {0x90, 0x00}; - *error = CCID_ERROR_NO_ERROR; + 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; + *Error = CCID_ERROR_SLOT_NOT_FOUND; return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT; } } @@ -339,36 +342,37 @@ uint8_t CCID_XfrBlock(uint8_t slot, * whenever an application wants to abort the current operation. A previous CCID_ABORT * control message has to be sent before this one in order to start the abort operation. */ -uint8_t CCID_Abort(uint8_t slot, - uint8_t seq, - uint8_t* const error) +uint8_t CCID_Abort(uint8_t Slot, + uint8_t Seq, + uint8_t* const Error) { - if (Aborted && slot == 0 && AbortedSeq == seq) + if (Aborted && Slot == 0 && AbortedSeq == Seq) { - Aborted = false; + Aborted = false; AbortedSeq = -1; - *error = CCID_ERROR_NO_ERROR; + + *Error = CCID_ERROR_NO_ERROR; return CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } else if (!Aborted) { - *error = CCID_ERROR_CMD_NOT_ABORTED; + *Error = CCID_ERROR_CMD_NOT_ABORTED; 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; } - *error = CCID_ERROR_NOT_SUPPORTED; + *Error = CCID_ERROR_NOT_SUPPORTED; return CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_NOICCPRESENT; } /** Gets and status and verifies whether an error occurred. */ -bool CCID_CheckStatusNoError(uint8_t status) +bool CCID_CheckStatusNoError(uint8_t Status) { - return (status & 0xC0) == 0x0; + return (Status & 0xC0) == 0x0; } /** Function to manage CCID request parsing and responses back to the host. */ @@ -477,6 +481,7 @@ void CCID_Task(void) Endpoint_ClearIN(); break; } + case CCID_PC_to_RDR_SetParameters: { uint8_t ProtocolNum = Endpoint_Read_8(); @@ -490,14 +495,14 @@ void CCID_Task(void) ResponseParametersStatus->CCIDHeader.Slot = CCIDHeader.Slot; ResponseParametersStatus->CCIDHeader.Seq = CCIDHeader.Seq; - if(ProtocolNum == CCID_PROTOCOLNUM_T0) + if (ProtocolNum == CCID_PROTOCOLNUM_T0) { - if(CCIDHeader.Length * sizeof(uint8_t) == sizeof(USB_CCID_ProtocolData_T0_t)) + if ((CCIDHeader.Length * sizeof(uint8_t)) == sizeof(USB_CCID_ProtocolData_T0_t)) { - Endpoint_Read_Stream_LE(RequestBuffer, CCIDHeader.Length * sizeof(uint8_t), NULL); - Status = CCID_SetParameters_T0(CCIDHeader.Slot, &Error, (USB_CCID_ProtocolData_T0_t*) RequestBuffer); - if(CCID_CheckStatusNoError(Status)) + + Status = CCID_SetParameters_T0(CCIDHeader.Slot, &Error, (USB_CCID_ProtocolData_T0_t*)RequestBuffer); + if (CCID_CheckStatusNoError(Status)) { ResponseParametersStatus->CCIDHeader.Length = CCIDHeader.Length; Status = CCID_GetParameters_T0(CCIDHeader.Slot, &Error, &ResponseParametersStatus->ProtocolNum, (USB_CCID_ProtocolData_T0_t*) &ResponseParametersStatus->ProtocolData); @@ -505,15 +510,16 @@ void CCID_Task(void) } else { - //unexpected length + // Unexpected length Status = CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_PRESENTANDACTIVE; } } else { ResponseParametersStatus->ProtocolNum = CCID_PROTOCOLNUM_T0; - //for now, we don't support T=1 protocol - Error = CCID_ERROR_PARAMETERS_PROTOCOL_NOT_SUPPORTED; + + // For now, we don't support T=1 protocol + Error = CCID_ERROR_PARAMETERS_PROTOCOL_NOT_SUPPORTED; Status = CCID_COMMANDSTATUS_ERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } @@ -523,10 +529,11 @@ void CCID_Task(void) Endpoint_ClearOUT(); Endpoint_SelectEndpoint(CCID_IN_EPADDR); - Endpoint_Write_Stream_LE(ResponseParametersStatus, sizeof(USB_CCID_BulkMessage_Header_t) + 3 + ResponseParametersStatus->CCIDHeader.Length , NULL); + Endpoint_Write_Stream_LE(ResponseParametersStatus, sizeof(USB_CCID_BulkMessage_Header_t) + 3 + ResponseParametersStatus->CCIDHeader.Length, NULL); Endpoint_ClearIN(); break; } + case CCID_PC_to_RDR_GetParameters: { USB_CCID_RDR_to_PC_Parameters_t* ResponseParametersStatus = (USB_CCID_RDR_to_PC_Parameters_t*)&ResponseBuffer; @@ -543,10 +550,11 @@ void CCID_Task(void) Endpoint_ClearOUT(); Endpoint_SelectEndpoint(CCID_IN_EPADDR); - Endpoint_Write_Stream_LE(ResponseParametersStatus, sizeof(USB_CCID_BulkMessage_Header_t) + 3 + ResponseParametersStatus->CCIDHeader.Length , NULL); + Endpoint_Write_Stream_LE(ResponseParametersStatus, sizeof(USB_CCID_BulkMessage_Header_t) + 3 + ResponseParametersStatus->CCIDHeader.Length, NULL); Endpoint_ClearIN(); break; } + case CCID_PC_to_RDR_XfrBlock: { uint8_t Bwi = Endpoint_Read_8(); @@ -575,7 +583,7 @@ void CCID_Task(void) else if (Aborted) { Status = CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_PRESENTANDACTIVE; - Error = CCID_ERROR_CMD_ABORTED; + Error = CCID_ERROR_CMD_ABORTED; ResponseDataLength = 0; } else @@ -616,6 +624,7 @@ void CCID_Task(void) Endpoint_ClearIN(); break; } + default: { memset(ResponseBuffer, 0x00, sizeof(ResponseBuffer)); diff --git a/LUFA/Drivers/USB/Class/Common/CCIDClassCommon.h b/LUFA/Drivers/USB/Class/Common/CCIDClassCommon.h index da92381f6..ce7d0b370 100644 --- a/LUFA/Drivers/USB/Class/Common/CCIDClassCommon.h +++ b/LUFA/Drivers/USB/Class/Common/CCIDClassCommon.h @@ -65,39 +65,39 @@ #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_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_PROTOCOLS_T0 (1 << 0) + #define CCID_PROTOCOLS_T1 (1 << 1) - #define CCID_PROTOCOLNUM_T0 0 - #define CCID_PROTOCOLNUM_T1 (1 << 0) + #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_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_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_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_PARAMETERS_PROTOCOL_NOT_SUPPORTED 0x7 - #define CCID_ERROR_SLOT_NOT_FOUND 5 + #define CCID_ERROR_SLOT_NOT_FOUND 5 - #define CCID_DESCRIPTOR_CLOCK_KHZ(khz) (khz) - #define CCID_DESCRIPTOR_CLOCK_MHZ(mhz) ((mhz) * 1000) + #define CCID_DESCRIPTOR_CLOCK_KHZ(khz) (khz) + #define CCID_DESCRIPTOR_CLOCK_MHZ(mhz) ((mhz) * 1000) /* Enums: */ diff --git a/LUFA/Drivers/USB/Class/Device/CCIDClassDevice.c b/LUFA/Drivers/USB/Class/Device/CCIDClassDevice.c index 34f03c2c1..5bc4c934b 100644 --- a/LUFA/Drivers/USB/Class/Device/CCIDClassDevice.c +++ b/LUFA/Drivers/USB/Class/Device/CCIDClassDevice.c @@ -39,9 +39,9 @@ #include "CCIDClassDevice.h" -bool CCID_CheckStatusNoError(uint8_t status) +bool CCID_CheckStatusNoError(uint8_t Status) { - return (status & 0xC0) == 0x0; + return (Status & 0xC0) == 0x0; } void CCID_Device_ProcessControlRequest(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) @@ -113,7 +113,7 @@ void CCID_Device_ProcessControlRequest(USB_ClassInfo_CCID_Device_t* const CCIDIn bool CCID_Device_ConfigureEndpoints(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) { - CCIDInterfaceInfo->Config.DataINEndpoint.Type = EP_TYPE_BULK; + CCIDInterfaceInfo->Config.DataINEndpoint.Type = EP_TYPE_BULK; CCIDInterfaceInfo->Config.DataOUTEndpoint.Type = EP_TYPE_BULK; if (!(Endpoint_ConfigureEndpointTable(&CCIDInterfaceInfo->Config.DataINEndpoint, 1))) @@ -231,10 +231,11 @@ void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) Endpoint_ClearIN(); break; } + case CCID_PC_to_RDR_SetParameters: { uint8_t ProtocolNum = Endpoint_Read_8(); - uint8_t RFU = Endpoint_Read_16_LE(); + uint8_t RFU = Endpoint_Read_16_LE(); (void)RFU; @@ -244,14 +245,14 @@ void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) ResponseParametersStatus->CCIDHeader.Slot = CCIDHeader.Slot; ResponseParametersStatus->CCIDHeader.Seq = CCIDHeader.Seq; - if(ProtocolNum == CCID_PROTOCOLNUM_T0) + if (ProtocolNum == CCID_PROTOCOLNUM_T0) { - if(CCIDHeader.Length * sizeof(uint8_t) == sizeof(USB_CCID_ProtocolData_T0_t)) + if (CCIDHeader.Length * sizeof(uint8_t) == sizeof(USB_CCID_ProtocolData_T0_t)) { - + Endpoint_Read_Stream_LE(RequestBuffer, CCIDHeader.Length * sizeof(uint8_t), NULL); Status = CALLBACK_CCID_SetParameters_T0(CCIDInterfaceInfo, CCIDHeader.Slot, &Error, (USB_CCID_ProtocolData_T0_t*) RequestBuffer); - if(CCID_CheckStatusNoError(Status)) + if (CCID_CheckStatusNoError(Status)) { ResponseParametersStatus->CCIDHeader.Length = CCIDHeader.Length; Status = CALLBACK_CCID_GetParameters_T0(CCIDInterfaceInfo, CCIDHeader.Slot, &Error, &ResponseParametersStatus->ProtocolNum, (USB_CCID_ProtocolData_T0_t*) &ResponseParametersStatus->ProtocolData); @@ -259,15 +260,16 @@ void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) } else { - //unexpected length + // Unexpected length Status = CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_PRESENTANDACTIVE; } } else { ResponseParametersStatus->ProtocolNum = CCID_PROTOCOLNUM_T0; - //for now, we don't support T=1 protocol - Error = CCID_ERROR_PARAMETERS_PROTOCOL_NOT_SUPPORTED; + + // For now, we don't support T=1 protocol + Error = CCID_ERROR_PARAMETERS_PROTOCOL_NOT_SUPPORTED; Status = CCID_COMMANDSTATUS_ERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } @@ -281,6 +283,7 @@ void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) Endpoint_ClearIN(); break; } + case CCID_PC_to_RDR_GetParameters: { USB_CCID_RDR_to_PC_Parameters_t* ResponseParametersStatus = (USB_CCID_RDR_to_PC_Parameters_t*)&ResponseBuffer; @@ -301,6 +304,7 @@ void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) Endpoint_ClearIN(); break; } + case CCID_PC_to_RDR_XfrBlock: { uint8_t Bwi = Endpoint_Read_8(); @@ -312,7 +316,7 @@ void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) Endpoint_Read_Stream_LE(ReceivedBuffer, sizeof(ReceivedBuffer), NULL); - uint8_t ResponseDataLength = 0; + uint8_t ResponseDataLength = 0; USB_CCID_RDR_to_PC_DataBlock_t* ResponseBlock = (USB_CCID_RDR_to_PC_DataBlock_t*)&ResponseBuffer; ResponseBlock->CCIDHeader.MessageType = CCID_RDR_to_PC_DataBlock; @@ -327,7 +331,7 @@ void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) { ResponseBlock->CCIDHeader.Length = ResponseDataLength; } - else if(CCIDInterfaceInfo->State.Aborted) + else if (CCIDInterfaceInfo->State.Aborted) { Status = CCID_COMMANDSTATUS_FAILED | CCID_ICCSTATUS_PRESENTANDACTIVE; Error = CCID_ERROR_CMD_ABORTED; @@ -379,6 +383,7 @@ void CCID_Device_USBTask(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo) Endpoint_SelectEndpoint(CCIDInterfaceInfo->Config.DataINEndpoint.Address); Endpoint_Write_Stream_LE(ResponseBuffer, sizeof(ResponseBuffer), NULL); Endpoint_ClearIN(); + break; } } } diff --git a/LUFA/Drivers/USB/Class/Device/CCIDClassDevice.h b/LUFA/Drivers/USB/Class/Device/CCIDClassDevice.h index e6b774fda..05f487fa2 100644 --- a/LUFA/Drivers/USB/Class/Device/CCIDClassDevice.h +++ b/LUFA/Drivers/USB/Class/Device/CCIDClassDevice.h @@ -117,31 +117,31 @@ * (answer to reset) * * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state. - * \param[in] slot The slot ID currently being powered on. - * \param[in,out] atr Pointer to an array containing the Power On ATR being sent to the device. - * \param[out] atrSize The size of the ATR being sent (up to 15 bytes maximum). - * \param[out] error The result of the operation, or error. + * \param[in] Slot The slot ID currently being powered on. + * \param[in,out] Atr Pointer to an array containing the Power On ATR being sent to the device. + * \param[out] AtrSize The size of the ATR being sent (up to 15 bytes maximum). + * \param[out] Error The result of the operation, or error. * * \return The command result code. */ uint8_t CALLBACK_CCID_IccPowerOn(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, - uint8_t* const atr, - uint8_t* const atrSize, - uint8_t* const error) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Slot, + uint8_t* const Atr, + uint8_t* const AtrSize, + uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1); /** CCID class driver callback for PC_TO_RDR_IccPowerOff CCID message * Turns off the ICC * * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state. - * \param[in] slot The slot ID currently being powered off. - * \param[out] error The result of the operation, or error. + * \param[in] Slot The slot ID currently being powered off. + * \param[out] Error The result of the operation, or error. * * \return The command result code. */ uint8_t CALLBACK_CCID_IccPowerOff(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, - uint8_t* const error) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Slot, + uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1); /** CCID class driver callback for PC_TO_RDR_GetSlotStatus CCID message * Retrieves the current status of a given slot @@ -153,78 +153,78 @@ * \return The command result code. */ uint8_t CALLBACK_CCID_GetSlotStatus(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, - uint8_t* const error) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Slot, + uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1); /** CCID class driver callback for PC_TO_RDR_SetParameters CCID message for T=0 * Sets the current parameters of a given slot * * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration, state and protocol data. - * \param[in] slot The slot ID from which we want to retrieve the status. - * \param[out] error The result of the operation, or error. - * \param[out] t0 Pointer to a buffer containing the new parameters + * \param[in] Slot The slot ID from which we want to retrieve the status. + * \param[out] Error The result of the operation, or error. + * \param[out] T0 Pointer to a buffer containing the new parameters * * \return The command result code. */ uint8_t CALLBACK_CCID_SetParameters_T0(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, - uint8_t* const error, - USB_CCID_ProtocolData_T0_t* const t0); + uint8_t Slot, + uint8_t* const Error, + USB_CCID_ProtocolData_T0_t* const T0); /** CCID class driver callback for PC_TO_RDR_SetParameters CCID message for T=0 * Retrieves the current parameters of a given slot * * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration, state and protocol data. - * \param[in] slot The slot ID from which we want to retrieve the status. - * \param[out] error The result of the operation, or error. - * \param[out] t0 Pointer to a buffer where the parameters will be returned + * \param[in] Slot The slot ID from which we want to retrieve the status. + * \param[out] Error The result of the operation, or error. + * \param[out] T0 Pointer to a buffer where the parameters will be returned * * \return The command result code. */ uint8_t CALLBACK_CCID_GetParameters_T0(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, - uint8_t* const error, + uint8_t Slot, + uint8_t* const Error, uint8_t* const ProtocolNum, - USB_CCID_ProtocolData_T0_t* const t0); + USB_CCID_ProtocolData_T0_t* const T0); /** CCID class driver callback for PC_TO_RDR_XfrBlock CCID message - * Send a block of bytes from the host to a slot in the device + * Send a block of bytes from the host to a slot in the device * and also received a block of bytes as a response - * + * * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state. - * \param[in] slot The slot ID from which we want to retrieve the status. - * \param[in] receivedBuffer Pointer to an array holding the received block of bytes - * \param[in] receivedBufferSize The size of the received block of bytes - * \param[out] sendBuffer Pointer to a buffer which will hold the bytes being sent back to the host - * \param[out] sentBufferSize The size of the block of bytes being sent back to the host - * \param[out] error The result of the operation, or error. + * \param[in] Slot The slot ID from which we want to retrieve the status. + * \param[in] ReceivedBuffer Pointer to an array holding the received block of bytes + * \param[in] ReceivedBufferSize The size of the received block of bytes + * \param[out] SendBuffer Pointer to a buffer which will hold the bytes being sent back to the host + * \param[out] SentBufferSize The size of the block of bytes being sent back to the host + * \param[out] Error The result of the operation, or error. * * \return The command result code. */ uint8_t CALLBACK_CCID_XfrBlock(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, - uint8_t* const receivedBuffer, - uint8_t receivedBufferSize, - uint8_t* const sendBuffer, - uint8_t* const sentBufferSize, - uint8_t* const error); + uint8_t Slot, + uint8_t* const ReceivedBuffer, + uint8_t ReceivedBufferSize, + uint8_t* const SendBuffer, + uint8_t* const SentBufferSize, + uint8_t* const Error); /** CCID class driver callback for CCID_PC_to_RDR_Abort CCID message * Aborts a BULK out message previously sent to a slot * * \param[in,out] CCIDInterfaceInfo Pointer to a structure containing a CCID Class configuration and state. - * \param[in] slot The slot ID to where the message being aborted was sent to. - * \param[in] seq The current sequence number for this message. Must be checked against + * \param[in] Slot The slot ID to where the message being aborted was sent to. + * \param[in] Seq The current sequence number for this message. Must be checked against * the current abort message being sent at the control pipe. - * \param[out] error The result of the operation, or error. + * \param[out] Error The result of the operation, or error. * * \return The command result code. */ uint8_t CALLBACK_CCID_Abort(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, - uint8_t seq, - uint8_t* const error) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Slot, + uint8_t Seq, + uint8_t* const Error) ATTR_NON_NULL_PTR_ARG(1); #endif -- cgit v1.2.3