Oops - Bootloader optimizations to GetDescriptor() don't work, as the Configuration Descriptor's header does not contain the full length of the descriptor, breaking full enumeration.

Dean Camera 14 years ago
parent f6f4ac588c
commit c7f4752d6b
  1. 19
      Bootloaders/CDC/Descriptors.c
  2. 27
      Bootloaders/DFU/Descriptors.c
  3. 26
      Bootloaders/HID/Descriptors.c
  4. 1
      LUFA/ManPages/FutureChanges.txt

@ -206,29 +206,38 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
const void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = &DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = &ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
if (!(DescriptorNumber)) if (!(DescriptorNumber))
Address = &LanguageString; {
Address = &LanguageString;
Size = LanguageString.Header.Size;
}
else else
Address = &ProductString; {
Address = &ProductString;
Size = ProductString.Header.Size;
}
break; break;
} }
*DescriptorAddress = Address; *DescriptorAddress = Address;
return (Address != NULL) ? ((USB_Descriptor_Header_t*)Address)->Size : NO_DESCRIPTOR; return Size;
} }

@ -147,29 +147,38 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
const void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = &DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = &ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
if (!(DescriptorNumber)) if (!(DescriptorNumber))
Address = &LanguageString; {
Address = &LanguageString;
Size = LanguageString.Header.Size;
}
else else
Address = &ProductString; {
Address = &ProductString;
Size = ProductString.Header.Size;
}
break; break;
} }
*DescriptorAddress = Address; *DescriptorAddress = Address;
return (Address != NULL) ? ((USB_Descriptor_Header_t*)Address)->Size : NO_DESCRIPTOR; return Size;
} }

@ -154,23 +154,33 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex, const uint8_t wIndex,
const void** const DescriptorAddress) const void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR; uint16_t Size = NO_DESCRIPTOR;
/* If/Else If chain compiles slightly smaller than a switch case */
if (DescriptorType == DTYPE_Device) if (DescriptorType == DTYPE_Device)
Address = &DeviceDescriptor; {
Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
}
else if (DescriptorType == DTYPE_Configuration) else if (DescriptorType == DTYPE_Configuration)
Address = &ConfigurationDescriptor; {
Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
}
else if (DescriptorType == HID_DTYPE_HID) else if (DescriptorType == HID_DTYPE_HID)
Address = &ConfigurationDescriptor.HID_VendorHID; {
Address = &ConfigurationDescriptor.HID_VendorHID;
Size = sizeof(USB_HID_Descriptor_HID_t);
}
else else
Address = &HIDReport; {
Address = &HIDReport;
Size = sizeof(HIDReport);
}
if (Address != NULL)
Size = (Address == &HIDReport) ? sizeof(HIDReport) : ((USB_Descriptor_Header_t*)Address)->Size;
*DescriptorAddress = Address; *DescriptorAddress = Address;
return Size; return Size;
} }

@ -17,7 +17,6 @@
* -# Investigate virtual hubs when in device mode instead of composite devices * -# Investigate virtual hubs when in device mode instead of composite devices
* -# Change makefiles to allow for absolute LUFA location to be used * -# Change makefiles to allow for absolute LUFA location to be used
* -# Re-add interrupt Pipe/Endpoint support * -# Re-add interrupt Pipe/Endpoint support
* -# Investigate dynamically created device descriptors
* -# Add makefile includes to reduce boilerplate in user makefiles * -# Add makefile includes to reduce boilerplate in user makefiles
* - Documentation/Support * - Documentation/Support
* -# Add detailed overviews of how each demo works * -# Add detailed overviews of how each demo works

Loading…
Cancel
Save