Collapse configuration descriptor size retrieval and size testing into a single if...
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 27 Jul 2009 10:55:21 +0000 (10:55 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 27 Jul 2009 10:55:21 +0000 (10:55 +0000)
Demos/Host/ClassDriver/CDCHost/CDCHost.c
Demos/Host/ClassDriver/MouseHost/MouseHost.c
LUFA/Drivers/USB/Class/Host/HID.h

index b74c394..291e835 100644 (file)
@@ -77,17 +77,10 @@ int main(void)
                                uint16_t ConfigDescriptorSize;\r
                                uint8_t  ConfigDescriptorData[512];\r
 \r
-                               if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)\r
+                               if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||\r
+                                   (ConfigDescriptorSize > sizeof(ConfigDescriptorData)))\r
                                {\r
-                                       printf("Error Retrieving Device Descriptor.\r\n");\r
-                                       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
-                                       USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
-                                       break;\r
-                               }\r
-                               \r
-                               if (ConfigDescriptorSize > 512)\r
-                               {\r
-                                       printf("Device Descriptor Too Large To Process.\r\n");\r
+                                       printf("Error Retrieving Configuration Descriptor.\r\n");\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
index c2850cf..6913ec3 100644 (file)
@@ -79,22 +79,15 @@ int main(void)
                                uint16_t ConfigDescriptorSize;\r
                                uint8_t  ConfigDescriptorData[512];\r
 \r
-                               if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)\r
+                               if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||\r
+                                   (ConfigDescriptorSize > sizeof(ConfigDescriptorData)))\r
                                {\r
-                                       printf("Error Retrieving Device Descriptor.\r\n");\r
+                                       printf("Error Retrieving Configuration Descriptor.\r\n");\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
                                \r
-                               if (ConfigDescriptorSize > 512)\r
-                               {\r
-                                       printf("Device Descriptor Too Large To Process.\r\n");\r
-                                       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
-                                       USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
-                                       break;\r
-                               }\r
-                                 \r
                                USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);\r
 \r
                                if (HID_Host_ConfigurePipes(&Mouse_HID_Interface,\r
index 1959fd2..344c06f 100644 (file)
                                        uint8_t  DataINPipeNumber; /**< Pipe number of the HID interface's IN data pipe */\r
                                        uint8_t  DataOUTPipeNumber; /**< Pipe number of the HID interface's OUT data pipe */\r
                                        \r
-                                       bool     MatchInterfaceProtocol;\r
-                                       uint8_t  HIDInterfaceProtocol;\r
+                                       bool     MatchInterfaceProtocol; /**< Indicates whether the driver should match the device's\r
+                                                                         *   HID interface protocol's value to the \ref HIDInterfaceProtocol\r
+                                                                         *   suppled (otherwise just accept all HID class devices)\r
+                                                                         */\r
+                                       uint8_t  HIDInterfaceProtocol; /**< HID interface protocol value to match against if the\r
+                                                                       *   \ref MatchInterfaceProtocol is set to true (ignored otherwise)\r
+                                                                       */\r
                                } Config; /**< Config data for the USB class interface within the device. All elements in this section\r
                                           *   <b>must</b> be set or the interface will fail to enumerate and operate correctly.\r
                                           */\r