X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d0806c817cbf0c1b5c5362d1577eac6075c94dfc..a7aaa45ec4c3f415bf6073a5cc016635d5ecf77d:/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c diff --git a/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c b/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c index bbe258b3a..270a98aeb 100644 --- a/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c +++ b/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c @@ -1,21 +1,21 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -28,49 +28,49 @@ this software. */ +#define __INCLUDE_FROM_USB_DRIVER #include "ConfigDescriptor.h" #if defined(USB_CAN_BE_HOST) -uint8_t USB_GetDeviceConfigDescriptor(uint16_t* const ConfigSizePtr, void* BufferPtr) +uint8_t USB_Host_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, + void* BufferPtr, uint16_t BufferSize) { uint8_t ErrorCode; + uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)]; USB_ControlRequest = (USB_Request_Header_t) { .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE), .bRequest = REQ_GetDescriptor, - .wValue = (DTYPE_Configuration << 8), + .wValue = ((DTYPE_Configuration << 8) | (ConfigNumber - 1)), .wIndex = 0, .wLength = sizeof(USB_Descriptor_Configuration_Header_t), }; Pipe_SelectPipe(PIPE_CONTROLPIPE); - if (BufferPtr == NULL) - { - uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)]; + if ((ErrorCode = USB_Host_SendControlRequest(ConfigHeader)) != HOST_SENDCONTROL_Successful) + return ErrorCode; - ErrorCode = USB_Host_SendControlRequest(ConfigHeader); + *ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).TotalConfigurationSize; - #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) - *ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).TotalConfigurationSize; - #else - *ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).wTotalLength; - #endif - } - else - { - USB_ControlRequest.wLength = *ConfigSizePtr; - - ErrorCode = USB_Host_SendControlRequest(BufferPtr); - } + if (*ConfigSizePtr > BufferSize) + return HOST_GETCONFIG_BuffOverflow; + + USB_ControlRequest.wLength = *ConfigSizePtr; + + if ((ErrorCode = USB_Host_SendControlRequest(BufferPtr)) != HOST_SENDCONTROL_Successful) + return ErrorCode; - return ErrorCode; + if (DESCRIPTOR_TYPE(BufferPtr) != DTYPE_Configuration) + return HOST_GETCONFIG_InvalidData; + + return HOST_GETCONFIG_Successful; } #endif void USB_GetNextDescriptorOfType(uint16_t* const BytesRem, - uint8_t** const CurrConfigLoc, + void** const CurrConfigLoc, const uint8_t Type) { while (*BytesRem) @@ -83,7 +83,7 @@ void USB_GetNextDescriptorOfType(uint16_t* const BytesRem, } void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem, - uint8_t** const CurrConfigLoc, + void** const CurrConfigLoc, const uint8_t Type, const uint8_t BeforeType) { @@ -104,7 +104,7 @@ void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem, } void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem, - uint8_t** const CurrConfigLoc, + void** const CurrConfigLoc, const uint8_t Type, const uint8_t AfterType) { @@ -114,7 +114,7 @@ void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem, USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type); } -uint8_t USB_GetNextDescriptorComp(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ConfigComparatorPtr_t ComparatorRoutine) +uint8_t USB_GetNextDescriptorComp(uint16_t* BytesRem, void** CurrConfigLoc, ConfigComparatorPtr_t ComparatorRoutine) { uint8_t ErrorCode;