X-Git-Url: http://git.linex4red.de/pub/lufa.git/blobdiff_plain/1e9e7bc8b88af32f466f7438a06fb8dc96b3035d..refs/heads/master:/Demos/Device/ClassDriver/CCID/CCID.c diff --git a/Demos/Device/ClassDriver/CCID/CCID.c b/Demos/Device/ClassDriver/CCID/CCID.c index bb4c11c45..18e8e6c0a 100644 --- a/Demos/Device/ClassDriver/CCID/CCID.c +++ b/Demos/Device/ClassDriver/CCID/CCID.c @@ -1,14 +1,14 @@ /* LUFA Library - Copyright (C) Dean Camera, 2018. + Copyright (C) Dean Camera, 2021. 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 @@ -158,7 +158,7 @@ void EVENT_USB_Device_ControlRequest(void) * THe slot must reply back with a recognizable ATR (answer to reset) */ uint8_t CALLBACK_CCID_IccPowerOn(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, + const uint8_t slot, uint8_t* const atr, uint8_t* const attrSize, uint8_t* const error) @@ -169,16 +169,18 @@ 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 * whenever an application at the host wants to send a power off signal to a slot. */ uint8_t CALLBACK_CCID_IccPowerOff(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, + const uint8_t slot, uint8_t* const error) { if (slot < CCID_Interface.Config.TotalSlots) @@ -193,12 +195,12 @@ uint8_t CALLBACK_CCID_IccPowerOff(USB_ClassInfo_CCID_Device_t* const CCIDInterfa } } -/** 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 * */ uint8_t CALLBACK_CCID_GetSlotStatus(USB_ClassInfo_CCID_Device_t* const CCIDInterfaceInfo, - uint8_t slot, + const uint8_t slot, uint8_t* const error) { if (slot < CCID_Interface.Config.TotalSlots) @@ -208,7 +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. + */ +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; } } @@ -218,54 +269,56 @@ uint8_t CALLBACK_CCID_GetSlotStatus(USB_ClassInfo_CCID_Device_t* const CCIDInter * 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) + 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 (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) + const uint8_t Slot, + const 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; } }