X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/f1076ac4d6e56bff7fb6d2126746af1108211370..be9d0a5aa97c84cc8723f69f2b88576965e386aa:/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h diff --git a/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h b/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h index a9b0b1423..c0ebe0956 100644 --- a/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h +++ b/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h @@ -98,18 +98,10 @@ * This value's meaning depends on the descriptor's placement in the descriptor, but standard type * values can be accessed in the \ref USB_DescriptorTypes_t enum. */ - #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) - #define DESCRIPTOR_TYPE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).Type - #else - #define DESCRIPTOR_TYPE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).bDescriptorType - #endif + #define DESCRIPTOR_TYPE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).Type /** Returns the descriptor's size, expressed as the 8-bit value indicating the number of bytes. */ - #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) || defined(__DOXYGEN__) - #define DESCRIPTOR_SIZE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).Size - #else - #define DESCRIPTOR_SIZE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).bLength - #endif + #define DESCRIPTOR_SIZE(DescriptorPtr) DESCRIPTOR_CAST(DescriptorPtr, USB_Descriptor_Header_t).Size /* Type Defines: */ /** Type define for a Configuration Descriptor comparator function (function taking a pointer to an array @@ -153,7 +145,7 @@ * * //... * // After retrieving configuration descriptor: - * if (USB_Host_GetNextDescriptorComp(&BytesRemaining, &ConfigDescriptorData, EndpointSearcher) == + * if (USB_Host_GetNextDescriptorComp(&BytesRemaining, &CurrentConfigLoc, EndpointSearcher) == * Descriptor_Search_Comp_Found) * { * // Do something with the endpoint descriptor @@ -163,6 +155,24 @@ uint8_t USB_GetNextDescriptorComp(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ConfigComparatorPtr_t ComparatorRoutine); /* Enums: */ + /** Enum for the possible return codes of the \ref USB_GetDeviceConfigDescriptor() function. */ + enum USB_Host_GetConfigDescriptor_ErrorCodes_t + { + HOST_GETCONFIG_Successful = 0, /**< No error occurred while retrieving the configuration descriptor */ + HOST_GETCONFIG_DeviceDisconnect = 1, /**< The attached device was disconnected while retrieving the configuration + * descriptor + */ + HOST_GETCONFIG_PipeError = 2, /**< An error occurred in the pipe while sending the request */ + HOST_GETCONFIG_SetupStalled = 3, /**< The attached device stalled the request to retrieve the configuration + * descriptor + */ + HOST_GETCONFIG_SoftwareTimeOut = 4, /**< The request or data transfer timed out */ + HOST_GETCONFIG_BuffOverflow = 5, /**< The device's configuration descriptor is too large to fit into the allocated + * buffer + */ + HOST_GETCONFIG_InvalidData = 6, /**< The device returned invalid configuration descriptor data */ + }; + /** Enum for return values of a descriptor comparator function. */ enum DSearch_Return_ErrorCodes_t { @@ -181,22 +191,19 @@ }; /* Function Prototypes: */ - /** Retrieves the configuration descriptor data or size from an attached device via a standard request. + /** Retrieves the configuration descriptor data from an attached device via a standard request into a buffer, + * including validity and size checking to prevent a buffer overflow. * * \param[in] ConfigNumber Device configuration descriptor number to fetch from the device (usually set to 1 for * single configuration devices) + * \param[in,out] ConfigSizePtr Pointer to a uint16_t for storing the retrieved configuration descriptor size + * \param[out] BufferPtr Pointer to the buffer for storing the configuration descriptor data. + * \param[out] BufferSize Size of the allocated buffer where the configuration descriptor is to be stored * - * \param[in,out] ConfigSizePtr Pointer to a uint16_t for either storing or retrieving the configuration - * descriptor size - * - * \param[out] BufferPtr Pointer to the buffer for storing the configuration descriptor data. If this is - * NULL, the size of the configuration descriptor will be retrieved instead and - * placed in the variable pointed to by ConfigSizePtr. If this is non-NULL, the number - * of bytes indicated by ConfigSizePtr of the configuration descriptor will be loaded - * into the buffer + * \return A value from the \ref USB_Host_GetConfigDescriptor_ErrorCodes_t enum */ - uint8_t USB_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, void* BufferPtr) - ATTR_NON_NULL_PTR_ARG(2); + uint8_t USB_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, void* BufferPtr, + uint16_t BufferSize) ATTR_NON_NULL_PTR_ARG(2, 3); /** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value. * The bytes remaining value is automatically decremented. @@ -254,11 +261,7 @@ static inline void USB_GetNextDescriptor(uint16_t* const BytesRem, uint8_t** const CurrConfigLoc) { - #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) uint16_t CurrDescriptorSize = DESCRIPTOR_CAST(*CurrConfigLoc, USB_Descriptor_Header_t).Size; - #else - uint16_t CurrDescriptorSize = DESCRIPTOR_CAST(*CurrConfigLoc, USB_Descriptor_Header_t).bLength; - #endif *CurrConfigLoc += CurrDescriptorSize; *BytesRem -= CurrDescriptorSize;