1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:17:35 +00:00

Kernel/USB: Fetch configuration descriptors on enumeration

This also introduces a new class, `USBConfiguration` that stores a
configuration. The device, when instructed, sets this configuration and
holds a pointer to it so we have a record of what configuration is
currently active.
This commit is contained in:
Jesse Buhagiar 2022-04-11 20:18:31 +10:00 committed by Andreas Kling
parent 1409a48da6
commit dac26f89cb
3 changed files with 62 additions and 0 deletions

View file

@ -115,6 +115,26 @@ ErrorOr<void> Device::enumerate_device()
dbgln_if(USB_DEBUG, "USB Device: Set address to {}", m_address);
memcpy(&m_device_descriptor, &dev_descriptor, sizeof(USBDeviceDescriptor));
// Fetch the configuration descriptors from the device
m_configurations.ensure_capacity(m_device_descriptor.num_configurations);
for (auto configuration = 0u; configuration < m_device_descriptor.num_configurations; configuration++) {
USBConfigurationDescriptor configuration_descriptor;
transfer_length = TRY(m_default_pipe->control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8u) | configuration, 0, sizeof(USBConfigurationDescriptor), &configuration_descriptor));
if constexpr (USB_DEBUG) {
dbgln("USB Configuration Descriptor {}", configuration);
dbgln("Total Length: {}", configuration_descriptor.total_length);
dbgln("Number of interfaces: {}", configuration_descriptor.number_of_interfaces);
dbgln("Configuration Value: {}", configuration_descriptor.configuration_value);
dbgln("Attributes Bitmap: {:08b}", configuration_descriptor.attributes_bitmap);
dbgln("Maximum Power: {}mA", configuration_descriptor.max_power_in_ma * 2u); // This value is in 2mA steps
}
USBConfiguration device_configuration(*this, configuration_descriptor);
m_configurations.append(device_configuration);
}
return {};
}