Changed the parameters and behaviour of the USB_GetDeviceConfigDescriptor() function...
[pub/lufa.git] / Demos / Host / Incomplete / BluetoothHost / ConfigDescriptor.c
index 948c4fc..f856262 100644 (file)
 \r
 uint8_t ProcessConfigurationDescriptor(void)\r
 {\r
-       uint8_t* ConfigDescriptorData;\r
-       uint16_t ConfigDescriptorSize;\r
+       uint8_t  ConfigDescriptorData[512];\r
+       uint8_t* CurrConfigLocation = ConfigDescriptorData;\r
+       uint16_t CurrConfigBytesRem;\r
        uint8_t  FoundEndpoints = 0;\r
-       \r
-       /* Get Configuration Descriptor size from the device */\r
-       if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)\r
-         return ControlErrorDuringConfigRead;\r
-       \r
-       /* Ensure that the Configuration Descriptor isn't too large */\r
-       if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)\r
-         return DescriptorTooLarge;\r
-         \r
-       /* Allocate enough memory for the entire config descriptor */\r
-       ConfigDescriptorData = alloca(ConfigDescriptorSize);\r
 \r
        /* Retrieve the entire configuration descriptor into the allocated buffer */\r
-       USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);\r
+       switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))\r
+       {\r
+               case HOST_GETCONFIG_Successful:\r
+                       break;\r
+               case HOST_GETCONFIG_InvalidData:\r
+                       return InvalidConfigDataReturned;\r
+               case HOST_GETCONFIG_BuffOverflow:\r
+                       return DescriptorTooLarge;\r
+               default:\r
+                       return ControlErrorDuringConfigRead;\r
+       }\r
        \r
-       /* Validate returned data - ensure first entry is a configuration header descriptor */\r
-       if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)\r
-         return InvalidConfigDataReturned;\r
-\r
        /* The bluetooth USB transport addendium mandates that the data (not streaming voice) endpoints\r
           be in the first interface descriptor (interface 0) */\r
-       USB_GetNextDescriptorOfType(&ConfigDescriptorSize, &ConfigDescriptorData, DTYPE_Interface);\r
+       USB_GetNextDescriptorOfType(&CurrConfigBytesRem, &CurrConfigLocation, DTYPE_Interface);\r
        \r
        /* Ensure that an interface was found, and the end of the descriptor was not reached */\r
-       if (!(ConfigDescriptorSize))\r
+       if (!(CurrConfigBytesRem))\r
          return NoInterfaceFound;\r
 \r
        /* Get the data IN, data OUT and event notification endpoints for the bluetooth interface */\r
@@ -67,8 +63,8 @@ uint8_t ProcessConfigurationDescriptor(void)
                                  (1 << BLUETOOTH_EVENTS_PIPE)))\r
        {\r
                /* Fetch the next endpoint from the current bluetooth interface */\r
-               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                                  NextInterfaceBluetoothDataEndpoint))\r
+               if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
+                                             NextInterfaceBluetoothDataEndpoint))\r
                {\r
                        /* Descriptor not found, error out */\r
                        return NoEndpointFound;\r