/** Select a new configuration for the device. Each device may support several configurations. @param Device The device to select configuration. @param ConfigValue The index of the configuration ( != 0). @retval EFI_NOT_FOUND There is no configuration with the index. @retval EFI_OUT_OF_RESOURCES Failed to allocate resource. @retval EFI_SUCCESS The configuration is selected. **/ EFI_STATUS UsbSelectConfig ( IN USB_DEVICE *Device, IN UINT8 ConfigValue ) { USB_DEVICE_DESC *DevDesc; USB_CONFIG_DESC *ConfigDesc; USB_INTERFACE_DESC *IfDesc; USB_INTERFACE *UsbIf; EFI_STATUS Status; UINT8 Index; // // Locate the active config, then set the device's pointer // DevDesc = Device->DevDesc; ConfigDesc = NULL; for (Index = 0; Index < DevDesc->Desc.NumConfigurations; Index++) { ConfigDesc = DevDesc->Configs[Index]; if (ConfigDesc->Desc.ConfigurationValue == ConfigValue) { break; } } if (Index == DevDesc->Desc.NumConfigurations) { return EFI_NOT_FOUND; } Device->ActiveConfig = ConfigDesc; // DEBUG ((EFI_D_INFO, "UsbSelectConfig: config %d selected for device %d\n", // ConfigValue, Device->Address)); DBG("UsbSelectConfig: config %d selected for device %d\n", ConfigValue, Device->Address); // // Create interfaces for each USB interface descriptor. // for (Index = 0; Index < ConfigDesc->Desc.NumInterfaces; Index++) { // // First select the default interface setting, and reset // the endpoint toggles to zero for its endpoints. // IfDesc = ConfigDesc->Interfaces[Index]; UsbSelectSetting (IfDesc, IfDesc->Settings[0]->Desc.AlternateSetting); // // Create a USB_INTERFACE and install USB_IO and other protocols // UsbIf = UsbCreateInterface (Device, ConfigDesc->Interfaces[Index]); if (UsbIf == NULL) { Device->NumOfInterface = Index; return EFI_OUT_OF_RESOURCES; } // ASSERT (Index < USB_MAX_INTERFACE); Device->Interfaces[Index] = UsbIf; // // Connect the device to drivers, if it failed, ignore // the error. Don't let the unsupported interfaces to block // the supported interfaces. // Status = UsbConnectDriver (UsbIf); DBG("UsbSelect[%d]:%r\n", Index, Status); if (EFI_ERROR (Status)) { // DEBUG ((EFI_D_ERROR, "UsbSelectConfig: failed to connect driver %r, ignored\n", Status)); } } Device->NumOfInterface = Index; return EFI_SUCCESS; }
EFI_STATUS UsbSelectConfig ( IN USB_DEVICE *Device, IN UINT8 ConfigValue ) /*++ Routine Description: Select a new configuration for the device. Each device may support several configurations. Arguments: Device - The device to select configuration ConfigValue - The index of the configuration ( != 0) Returns: EFI_NOT_FOUND - There is no configuration with the index EFI_OUT_OF_RESOURCES - Failed to allocate resource EFI_SUCCESS - The configuration is selected. --*/ { USB_DEVICE_DESC *DevDesc; USB_CONFIG_DESC *ConfigDesc; USB_INTERFACE_DESC *IfDesc; USB_INTERFACE *UsbIf; EFI_STATUS Status; UINT8 Index; // // Locate the active config, then set the device's pointer // DevDesc = Device->DevDesc; ConfigDesc = NULL; for (Index = 0; Index < DevDesc->Desc.NumConfigurations; Index++) { ConfigDesc = DevDesc->Configs[Index]; if (ConfigDesc->Desc.ConfigurationValue == ConfigValue) { break; } } if (Index == DevDesc->Desc.NumConfigurations) { return EFI_NOT_FOUND; } Device->ActiveConfig = ConfigDesc; USB_DEBUG (("UsbSelectConfig: config %d selected for device %d\n", ConfigValue, Device->Address)); // // Create interfaces for each USB interface descriptor. // for (Index = 0; Index < ConfigDesc->Desc.NumInterfaces; Index++) { // // First select the default interface setting, and reset // the endpoint toggles to zero for its endpoints. // IfDesc = ConfigDesc->Interfaces[Index]; UsbSelectSetting (IfDesc, IfDesc->Settings[0]->Desc.AlternateSetting); // // Create a USB_INTERFACE and install USB_IO and other protocols // UsbIf = UsbCreateInterface (Device, ConfigDesc->Interfaces[Index]); if (UsbIf == NULL) { return EFI_OUT_OF_RESOURCES; } Device->Interfaces[Index] = UsbIf; // // Connect the device to drivers, if it failed, ignore // the error. Don't let the unsupported interfaces to block // the supported interfaces. // Status = UsbConnectDriver (UsbIf); if (EFI_ERROR (Status)) { USB_ERROR (("UsbSelectConfig: failed to connect driver %r, ignored\n", Status)); } } Device->NumOfInterface = Index; return EFI_SUCCESS; }