mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-16 21:01:31 +00:00
Changed the parameters and behaviour of the USB_GetDeviceConfigDescriptor() function so that it now performs size checks and data validations internally, to simplify user code.
This commit is contained in:
parent
813e6f0318
commit
7fbb759287
@ -72,9 +72,8 @@ int main(void)
|
|||||||
uint16_t ConfigDescriptorSize;
|
uint16_t ConfigDescriptorSize;
|
||||||
uint8_t ConfigDescriptorData[512];
|
uint8_t ConfigDescriptorData[512];
|
||||||
|
|
||||||
if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||
|
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
|
||||||
(ConfigDescriptorSize > sizeof(ConfigDescriptorData)) ||
|
sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
|
||||||
(USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData)))
|
|
||||||
{
|
{
|
||||||
printf("Error Retrieving Configuration Descriptor.\r\n");
|
printf("Error Retrieving Configuration Descriptor.\r\n");
|
||||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||||
|
@ -71,9 +71,8 @@ int main(void)
|
|||||||
uint16_t ConfigDescriptorSize;
|
uint16_t ConfigDescriptorSize;
|
||||||
uint8_t ConfigDescriptorData[512];
|
uint8_t ConfigDescriptorData[512];
|
||||||
|
|
||||||
if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||
|
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
|
||||||
(ConfigDescriptorSize > sizeof(ConfigDescriptorData)) ||
|
sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
|
||||||
(USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData)))
|
|
||||||
{
|
{
|
||||||
printf("Error Retrieving Configuration Descriptor.\r\n");
|
printf("Error Retrieving Configuration Descriptor.\r\n");
|
||||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||||
|
@ -73,9 +73,8 @@ int main(void)
|
|||||||
uint16_t ConfigDescriptorSize;
|
uint16_t ConfigDescriptorSize;
|
||||||
uint8_t ConfigDescriptorData[512];
|
uint8_t ConfigDescriptorData[512];
|
||||||
|
|
||||||
if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||
|
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
|
||||||
(ConfigDescriptorSize > sizeof(ConfigDescriptorData)) ||
|
sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
|
||||||
(USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData)))
|
|
||||||
{
|
{
|
||||||
printf("Error Retrieving Configuration Descriptor.\r\n");
|
printf("Error Retrieving Configuration Descriptor.\r\n");
|
||||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||||
|
@ -72,9 +72,8 @@ int main(void)
|
|||||||
uint16_t ConfigDescriptorSize;
|
uint16_t ConfigDescriptorSize;
|
||||||
uint8_t ConfigDescriptorData[512];
|
uint8_t ConfigDescriptorData[512];
|
||||||
|
|
||||||
if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||
|
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
|
||||||
(ConfigDescriptorSize > sizeof(ConfigDescriptorData)) ||
|
sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
|
||||||
(USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData)))
|
|
||||||
{
|
{
|
||||||
printf("Error Retrieving Configuration Descriptor.\r\n");
|
printf("Error Retrieving Configuration Descriptor.\r\n");
|
||||||
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||||||
|
@ -32,34 +32,30 @@
|
|||||||
|
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
uint8_t FoundEndpoints = 0;
|
uint8_t FoundEndpoints = 0;
|
||||||
|
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlErrorDuringConfigRead;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlErrorDuringConfigRead;
|
||||||
|
}
|
||||||
|
|
||||||
/* The bluetooth USB transport addendium mandates that the data (not streaming voice) endpoints
|
/* The bluetooth USB transport addendium mandates that the data (not streaming voice) endpoints
|
||||||
be in the first interface descriptor (interface 0) */
|
be in the first interface descriptor (interface 0) */
|
||||||
USB_GetNextDescriptorOfType(&ConfigDescriptorSize, &ConfigDescriptorData, DTYPE_Interface);
|
USB_GetNextDescriptorOfType(&CurrConfigBytesRem, &CurrConfigLocation, DTYPE_Interface);
|
||||||
|
|
||||||
/* Ensure that an interface was found, and the end of the descriptor was not reached */
|
/* Ensure that an interface was found, and the end of the descriptor was not reached */
|
||||||
if (!(ConfigDescriptorSize))
|
if (!(CurrConfigBytesRem))
|
||||||
return NoInterfaceFound;
|
return NoInterfaceFound;
|
||||||
|
|
||||||
/* Get the data IN, data OUT and event notification endpoints for the bluetooth interface */
|
/* Get the data IN, data OUT and event notification endpoints for the bluetooth interface */
|
||||||
@ -67,7 +63,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
(1 << BLUETOOTH_EVENTS_PIPE)))
|
(1 << BLUETOOTH_EVENTS_PIPE)))
|
||||||
{
|
{
|
||||||
/* Fetch the next endpoint from the current bluetooth interface */
|
/* Fetch the next endpoint from the current bluetooth interface */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
NextInterfaceBluetoothDataEndpoint))
|
NextInterfaceBluetoothDataEndpoint))
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
|
@ -42,6 +42,7 @@ uint8_t ProcessDeviceDescriptor(void)
|
|||||||
if (DeviceDescriptor.Header.Type != DTYPE_Device)
|
if (DeviceDescriptor.Header.Type != DTYPE_Device)
|
||||||
return InvalidDeviceDataReturned;
|
return InvalidDeviceDataReturned;
|
||||||
|
|
||||||
|
/* Validate returned device Class, SubClass and Protocol values against the Bluetooth spec values */
|
||||||
if ((DeviceDescriptor.Class != BLUETOOTH_DEVICE_CLASS) ||
|
if ((DeviceDescriptor.Class != BLUETOOTH_DEVICE_CLASS) ||
|
||||||
(DeviceDescriptor.SubClass != BLUETOOTH_DEVICE_SUBCLASS) ||
|
(DeviceDescriptor.SubClass != BLUETOOTH_DEVICE_SUBCLASS) ||
|
||||||
(DeviceDescriptor.Protocol != BLUETOOTH_DEVICE_PROTOCOL))
|
(DeviceDescriptor.Protocol != BLUETOOTH_DEVICE_PROTOCOL))
|
||||||
|
@ -47,30 +47,26 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
uint8_t FoundEndpoints = 0;
|
uint8_t FoundEndpoints = 0;
|
||||||
|
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the CDC control interface from the configuration descriptor */
|
/* Get the CDC control interface from the configuration descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -81,14 +77,14 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
while (FoundEndpoints != ((1 << CDC_NOTIFICATIONPIPE) | (1 << CDC_DATAPIPE_IN) | (1 << CDC_DATAPIPE_OUT)))
|
while (FoundEndpoints != ((1 << CDC_NOTIFICATIONPIPE) | (1 << CDC_DATAPIPE_IN) | (1 << CDC_DATAPIPE_OUT)))
|
||||||
{
|
{
|
||||||
/* Fetch the next bulk or interrupt endpoint from the current CDC interface */
|
/* Fetch the next bulk or interrupt endpoint from the current CDC interface */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Check to see if the control interface's notification pipe has been found, if so search for the data interface */
|
/* Check to see if the control interface's notification pipe has been found, if so search for the data interface */
|
||||||
if (FoundEndpoints & (1 << CDC_NOTIFICATIONPIPE))
|
if (FoundEndpoints & (1 << CDC_NOTIFICATIONPIPE))
|
||||||
{
|
{
|
||||||
/* Get the next CDC data interface from the configuration descriptor (CDC class has two CDC interfaces) */
|
/* Get the next CDC data interface from the configuration descriptor (CDC class has two CDC interfaces) */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -109,7 +105,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
Pipe_DisablePipe();
|
Pipe_DisablePipe();
|
||||||
|
|
||||||
/* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */
|
/* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -118,7 +114,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fetch the next bulk or interrupt endpoint from the current CDC interface */
|
/* Fetch the next bulk or interrupt endpoint from the current CDC interface */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
|
@ -47,31 +47,26 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
uint8_t FoundEndpoints = 0;
|
uint8_t FoundEndpoints = 0;
|
||||||
|
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the HID interface from the configuration descriptor */
|
/* Get the HID interface from the configuration descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -81,7 +76,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
while (FoundEndpoints != ((1 << HID_DATA_IN_PIPE) | (1 << HID_DATA_OUT_PIPE)))
|
while (FoundEndpoints != ((1 << HID_DATA_IN_PIPE) | (1 << HID_DATA_OUT_PIPE)))
|
||||||
{
|
{
|
||||||
/* Get the next HID interface's data endpoint descriptor */
|
/* Get the next HID interface's data endpoint descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextInterfaceHIDDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextInterfaceHIDDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor
|
/* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor
|
||||||
|
@ -47,29 +47,25 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the keyboard interface from the configuration descriptor */
|
/* Get the keyboard interface from the configuration descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -77,7 +73,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the keyboard interface's data endpoint descriptor */
|
/* Get the keyboard interface's data endpoint descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextInterfaceKeyboardDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextInterfaceKeyboardDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
|
@ -47,29 +47,25 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the keyboard interface from the configuration descriptor */
|
/* Get the keyboard interface from the configuration descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -77,7 +73,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the keyboard interface's HID descriptor */
|
/* Get the keyboard interface's HID descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -88,7 +84,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
HIDReportSize = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_HID_t).HIDReportLength;
|
HIDReportSize = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_HID_t).HIDReportLength;
|
||||||
|
|
||||||
/* Get the keyboard interface's data endpoint descriptor */
|
/* Get the keyboard interface's data endpoint descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextInterfaceKeyboardDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextInterfaceKeyboardDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
|
@ -47,30 +47,26 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
uint8_t FoundEndpoints = 0;
|
uint8_t FoundEndpoints = 0;
|
||||||
|
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the mass storage interface from the configuration descriptor */
|
/* Get the mass storage interface from the configuration descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextMassStorageInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextMassStorageInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -81,7 +77,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
while (FoundEndpoints != ((1 << MASS_STORE_DATA_IN_PIPE) | (1 << MASS_STORE_DATA_OUT_PIPE)))
|
while (FoundEndpoints != ((1 << MASS_STORE_DATA_IN_PIPE) | (1 << MASS_STORE_DATA_OUT_PIPE)))
|
||||||
{
|
{
|
||||||
/* Fetch the next bulk endpoint from the current mass storage interface */
|
/* Fetch the next bulk endpoint from the current mass storage interface */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
|
@ -47,29 +47,25 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the mouse interface from the configuration descriptor */
|
/* Get the mouse interface from the configuration descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -77,7 +73,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the mouse interface's data endpoint descriptor */
|
/* Get the mouse interface's data endpoint descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextInterfaceMouseDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextInterfaceMouseDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
|
@ -47,29 +47,25 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the mouse interface from the configuration descriptor */
|
/* Get the mouse interface from the configuration descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -77,7 +73,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the mouse interface's HID descriptor */
|
/* Get the mouse interface's HID descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -88,7 +84,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
HIDReportSize = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_HID_t).HIDReportLength;
|
HIDReportSize = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_HID_t).HIDReportLength;
|
||||||
|
|
||||||
/* Get the mouse interface's data endpoint descriptor */
|
/* Get the mouse interface's data endpoint descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextInterfaceMouseDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextInterfaceMouseDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
|
@ -36,32 +36,26 @@ uint8_t PrinterAltSetting;
|
|||||||
|
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
uint8_t ErrorCode;
|
uint16_t CurrConfigBytesRem;
|
||||||
uint8_t FoundEndpoints = 0;
|
uint8_t FoundEndpoints = 0;
|
||||||
|
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the printer interface from the configuration descriptor */
|
/* Get the printer interface from the configuration descriptor */
|
||||||
if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextBidirectionalPrinterInterface))
|
||||||
DComp_NextBidirectionalPrinterInterface)))
|
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
return NoInterfaceFound;
|
return NoInterfaceFound;
|
||||||
@ -74,8 +68,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
while (FoundEndpoints != ((1 << PRINTER_DATA_OUT_PIPE) | (1 << PRINTER_DATA_IN_PIPE)))
|
while (FoundEndpoints != ((1 << PRINTER_DATA_OUT_PIPE) | (1 << PRINTER_DATA_IN_PIPE)))
|
||||||
{
|
{
|
||||||
/* Fetch the next bulk endpoint from the current printer interface */
|
/* Fetch the next bulk endpoint from the current printer interface */
|
||||||
if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextInterfaceBulkDataEndpoint))
|
||||||
DComp_NextInterfaceBulkDataEndpoint)))
|
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
return NoEndpointFound;
|
return NoEndpointFound;
|
||||||
|
@ -47,30 +47,26 @@
|
|||||||
*/
|
*/
|
||||||
uint8_t ProcessConfigurationDescriptor(void)
|
uint8_t ProcessConfigurationDescriptor(void)
|
||||||
{
|
{
|
||||||
uint8_t* ConfigDescriptorData;
|
uint8_t ConfigDescriptorData[512];
|
||||||
uint16_t ConfigDescriptorSize;
|
uint8_t* CurrConfigLocation = ConfigDescriptorData;
|
||||||
|
uint16_t CurrConfigBytesRem;
|
||||||
uint8_t FoundEndpoints = 0;
|
uint8_t FoundEndpoints = 0;
|
||||||
|
|
||||||
/* Get Configuration Descriptor size from the device */
|
|
||||||
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
|
|
||||||
return ControlError;
|
|
||||||
|
|
||||||
/* Ensure that the Configuration Descriptor isn't too large */
|
|
||||||
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
|
|
||||||
return DescriptorTooLarge;
|
|
||||||
|
|
||||||
/* Allocate enough memory for the entire config descriptor */
|
|
||||||
ConfigDescriptorData = alloca(ConfigDescriptorSize);
|
|
||||||
|
|
||||||
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
/* Retrieve the entire configuration descriptor into the allocated buffer */
|
||||||
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
|
switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
|
||||||
|
{
|
||||||
/* Validate returned data - ensure first entry is a configuration header descriptor */
|
case HOST_GETCONFIG_Successful:
|
||||||
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
|
break;
|
||||||
|
case HOST_GETCONFIG_InvalidData:
|
||||||
return InvalidConfigDataReturned;
|
return InvalidConfigDataReturned;
|
||||||
|
case HOST_GETCONFIG_BuffOverflow:
|
||||||
|
return DescriptorTooLarge;
|
||||||
|
default:
|
||||||
|
return ControlError;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the Still Image interface from the configuration descriptor */
|
/* Get the Still Image interface from the configuration descriptor */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
@ -81,7 +77,7 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||||||
while (FoundEndpoints != ((1 << SIMAGE_EVENTS_PIPE) | (1 << SIMAGE_DATA_IN_PIPE) | (1 << SIMAGE_DATA_OUT_PIPE)))
|
while (FoundEndpoints != ((1 << SIMAGE_EVENTS_PIPE) | (1 << SIMAGE_DATA_IN_PIPE) | (1 << SIMAGE_DATA_OUT_PIPE)))
|
||||||
{
|
{
|
||||||
/* Fetch the next endpoint from the current Still Image interface */
|
/* Fetch the next endpoint from the current Still Image interface */
|
||||||
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DComp_NextStillImageInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
DComp_NextStillImageInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
{
|
{
|
||||||
/* Descriptor not found, error out */
|
/* Descriptor not found, error out */
|
||||||
|
@ -31,9 +31,11 @@
|
|||||||
#include "ConfigDescriptor.h"
|
#include "ConfigDescriptor.h"
|
||||||
|
|
||||||
#if defined(USB_CAN_BE_HOST)
|
#if defined(USB_CAN_BE_HOST)
|
||||||
uint8_t USB_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, void* BufferPtr)
|
uint8_t USB_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr,
|
||||||
|
void* BufferPtr, uint16_t BufferSize)
|
||||||
{
|
{
|
||||||
uint8_t ErrorCode;
|
uint8_t ErrorCode;
|
||||||
|
uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];
|
||||||
|
|
||||||
USB_ControlRequest = (USB_Request_Header_t)
|
USB_ControlRequest = (USB_Request_Header_t)
|
||||||
{
|
{
|
||||||
@ -46,26 +48,27 @@ uint8_t USB_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const Conf
|
|||||||
|
|
||||||
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
Pipe_SelectPipe(PIPE_CONTROLPIPE);
|
||||||
|
|
||||||
if (BufferPtr == NULL)
|
if ((ErrorCode = USB_Host_SendControlRequest(ConfigHeader)) != HOST_SENDCONTROL_Successful)
|
||||||
{
|
return ErrorCode;
|
||||||
uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];
|
|
||||||
|
|
||||||
ErrorCode = USB_Host_SendControlRequest(ConfigHeader);
|
|
||||||
|
|
||||||
#if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)
|
#if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)
|
||||||
*ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).TotalConfigurationSize;
|
*ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).TotalConfigurationSize;
|
||||||
#else
|
#else
|
||||||
*ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).wTotalLength;
|
*ConfigSizePtr = DESCRIPTOR_CAST(ConfigHeader, USB_Descriptor_Configuration_Header_t).wTotalLength;
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
else
|
if (*ConfigSizePtr > BufferSize)
|
||||||
{
|
return HOST_GETCONFIG_BuffOverflow;
|
||||||
|
|
||||||
USB_ControlRequest.wLength = *ConfigSizePtr;
|
USB_ControlRequest.wLength = *ConfigSizePtr;
|
||||||
|
|
||||||
ErrorCode = USB_Host_SendControlRequest(BufferPtr);
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -163,6 +163,23 @@
|
|||||||
uint8_t USB_GetNextDescriptorComp(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ConfigComparatorPtr_t ComparatorRoutine);
|
uint8_t USB_GetNextDescriptorComp(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ConfigComparatorPtr_t ComparatorRoutine);
|
||||||
|
|
||||||
/* Enums: */
|
/* Enums: */
|
||||||
|
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 for return values of a descriptor comparator function. */
|
||||||
enum DSearch_Return_ErrorCodes_t
|
enum DSearch_Return_ErrorCodes_t
|
||||||
{
|
{
|
||||||
@ -181,22 +198,19 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Function Prototypes: */
|
/* 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
|
* \param[in] ConfigNumber Device configuration descriptor number to fetch from the device (usually set to 1 for
|
||||||
* single configuration devices)
|
* 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
|
* \return A value from the \ref USB_Host_GetConfigDescriptor_ErrorCodes_t enum
|
||||||
* 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
|
|
||||||
*/
|
*/
|
||||||
uint8_t USB_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, void* BufferPtr)
|
uint8_t USB_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, void* BufferPtr,
|
||||||
ATTR_NON_NULL_PTR_ARG(2);
|
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.
|
/** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value.
|
||||||
* The bytes remaining value is automatically decremented.
|
* The bytes remaining value is automatically decremented.
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
* - Added new "Common" section to the class drivers, to hold all mode-independant definitions for clarity
|
* - Added new "Common" section to the class drivers, to hold all mode-independant definitions for clarity
|
||||||
* - Moved SCSI command/sense constants into the Mass Storage Class driver, instead of the user-code
|
* - Moved SCSI command/sense constants into the Mass Storage Class driver, instead of the user-code
|
||||||
* - Altered the SCSI commands in the LowLevel Mass Storage Host to save on FLASH space by reducing function calls
|
* - Altered the SCSI commands in the LowLevel Mass Storage Host to save on FLASH space by reducing function calls
|
||||||
|
* - Changed the parameters and behaviour of the USB_GetDeviceConfigDescriptor() function so that it now performs size checks
|
||||||
|
* and data validations internally, to simplify user code
|
||||||
*
|
*
|
||||||
* <b>Fixed:</b>
|
* <b>Fixed:</b>
|
||||||
* - Fixed possible lockup in the CDC device class driver, when the host sends data that is a multiple of the
|
* - Fixed possible lockup in the CDC device class driver, when the host sends data that is a multiple of the
|
||||||
|
@ -19,6 +19,12 @@
|
|||||||
* - The SPI_Init() routine's parameters have changed, so that the clock polarity and data sampling modes can be set. See
|
* - The SPI_Init() routine's parameters have changed, so that the clock polarity and data sampling modes can be set. See
|
||||||
* the SPI_Init() function documentation for more details
|
* the SPI_Init() function documentation for more details
|
||||||
*
|
*
|
||||||
|
* <b>Host Mode</b>
|
||||||
|
* - The \ref USB_GetDeviceConfigDescriptor() function's parameters and behaviour has changed; the user is required to
|
||||||
|
* preallocate the largest allowable buffer, and pass the size of the buffer to the function. This allows for a single
|
||||||
|
* call to the function to retrieve, size check and validate the Configuration Descriptor rather than having the user
|
||||||
|
* application perform these intermediatary steps.
|
||||||
|
*
|
||||||
* \section Sec_Migration090810 Migrating from 090605 to 090810
|
* \section Sec_Migration090810 Migrating from 090605 to 090810
|
||||||
*
|
*
|
||||||
* <b>All</b>
|
* <b>All</b>
|
||||||
|
Loading…
Reference in New Issue
Block a user