From 55aadf97d5d2bd86f2a0c3a53d4608c0cf96471e Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Sun, 10 Jul 2011 07:15:57 +0000 Subject: [PATCH] Replace blind interface descriptor search in the incomplete AndroidAccessoryHost demo with an intelligent search for the correct interface in the device matching the correct class/subclass/protocol values. --- .../AndroidAccessoryHost/ConfigDescriptor.c | 48 +++++++++++++++---- .../AndroidAccessoryHost/ConfigDescriptor.h | 5 ++ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c b/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c index 664e065ad0..0dc19e9abe 100644 --- a/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c +++ b/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c @@ -66,18 +66,17 @@ uint8_t ProcessConfigurationDescriptor(void) default: return DevControlError; } - - /* The Android Accessory Mode specification mandates that the accessory communications endpoints - be in the first interface descriptor (interface 0) */ - USB_GetNextDescriptorOfType(&CurrConfigBytesRem, &CurrConfigLocation, DTYPE_Interface); - - /* Ensure that an interface was found, and the end of the descriptor was not reached */ - if (!(CurrConfigBytesRem)) - return NoCompatibleInterfaceFound; + + /* There should be only one compatible Android Accessory Mode interface in the device, attempt to find it */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DCOMP_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + return NoCompatibleInterfaceFound; + } while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Get the next Still Image interface's data endpoint descriptor */ + /* Get the next Android Accessory Mode interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DCOMP_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { @@ -111,7 +110,35 @@ uint8_t ProcessConfigurationDescriptor(void) * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration * descriptor processing if an incompatible descriptor configuration is found. * - * This comparator searches for the next Endpoint descriptor inside the current interface descriptor, aborting the + * This comparator searches for the next Interface descriptor containing the correct Android Accessory Mode Class, Subclass + * and Protocol values. + * + * \return A value from the DSEARCH_Return_ErrorCodes_t enum + */ +uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor) +{ + USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t); + + if (Header->Type == DTYPE_Interface) + { + USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t); + + if ((Interface->Class == ANDROID_INTERFACE_CLASS) && + (Interface->SubClass == ANDROID_INTERFACE_SUBCLASS) && + (Interface->Protocol == ANDROID_INTERFACE_PROTOCOL)) + { + return DESCRIPTOR_SEARCH_Found; + } + } + + return DESCRIPTOR_SEARCH_NotFound; +} + +/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's + * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration + * descriptor processing if an incompatible descriptor configuration is found. + * + * This comparator searches for the next bulk Endpoint descriptor inside the current interface descriptor, aborting the * search if another interface descriptor is found before the required endpoint. * * \return A value from the DSEARCH_Return_ErrorCodes_t enum @@ -125,6 +152,7 @@ uint8_t DCOMP_NextInterfaceBulkEndpoint(void* const CurrentDescriptor) USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t); uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK); + if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress)))) return DESCRIPTOR_SEARCH_Found; } diff --git a/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h b/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h index 92c0d99a92..4989d9d888 100644 --- a/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h +++ b/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h @@ -42,6 +42,10 @@ /* Macros: */ #define ANDROID_DATA_IN_PIPE 1 #define ANDROID_DATA_OUT_PIPE 2 + + #define ANDROID_INTERFACE_CLASS 0xFF + #define ANDROID_INTERFACE_SUBCLASS 0x42 + #define ANDROID_INTERFACE_PROTOCOL 0x01 /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ @@ -57,6 +61,7 @@ /* Function Prototypes: */ uint8_t ProcessConfigurationDescriptor(void); + uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor); uint8_t DCOMP_NextInterfaceBulkEndpoint(void* CurrentDescriptor); #endif