| Index: device/usb/usb_device_impl.cc
|
| diff --git a/device/usb/usb_device_impl.cc b/device/usb/usb_device_impl.cc
|
| index bab510e77201a753e7796048d2f5074e928f339c..5d153c09453541dc204c88a529ad1c9eb69ba15f 100644
|
| --- a/device/usb/usb_device_impl.cc
|
| +++ b/device/usb/usb_device_impl.cc
|
| @@ -26,55 +26,6 @@
|
|
|
| namespace device {
|
|
|
| -namespace {
|
| -
|
| -void ConvertConfigDescriptor(const libusb_config_descriptor* platform_config,
|
| - UsbConfigDescriptor* configuration) {
|
| - for (size_t i = 0; i < platform_config->bNumInterfaces; ++i) {
|
| - const struct libusb_interface* platform_interface =
|
| - &platform_config->interface[i];
|
| - for (int j = 0; j < platform_interface->num_altsetting; ++j) {
|
| - const struct libusb_interface_descriptor* platform_alt_setting =
|
| - &platform_interface->altsetting[j];
|
| - UsbInterfaceDescriptor interface(
|
| - platform_alt_setting->bInterfaceNumber,
|
| - platform_alt_setting->bAlternateSetting,
|
| - platform_alt_setting->bInterfaceClass,
|
| - platform_alt_setting->bInterfaceSubClass,
|
| - platform_alt_setting->bInterfaceProtocol);
|
| -
|
| - interface.endpoints.reserve(platform_alt_setting->bNumEndpoints);
|
| - for (size_t k = 0; k < platform_alt_setting->bNumEndpoints; ++k) {
|
| - const struct libusb_endpoint_descriptor* platform_endpoint =
|
| - &platform_alt_setting->endpoint[k];
|
| - UsbEndpointDescriptor endpoint(platform_endpoint->bEndpointAddress,
|
| - platform_endpoint->bmAttributes,
|
| - platform_endpoint->wMaxPacketSize,
|
| - platform_endpoint->bInterval);
|
| - endpoint.extra_data.assign(
|
| - platform_endpoint->extra,
|
| - platform_endpoint->extra + platform_endpoint->extra_length);
|
| -
|
| - interface.endpoints.push_back(endpoint);
|
| - }
|
| -
|
| - interface.extra_data.assign(
|
| - platform_alt_setting->extra,
|
| - platform_alt_setting->extra + platform_alt_setting->extra_length);
|
| -
|
| - configuration->interfaces.push_back(interface);
|
| - }
|
| - }
|
| -
|
| - configuration->extra_data.assign(
|
| - platform_config->extra,
|
| - platform_config->extra + platform_config->extra_length);
|
| -
|
| - configuration->AssignFirstInterfaceNumbers();
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| UsbDeviceImpl::UsbDeviceImpl(
|
| scoped_refptr<UsbContext> context,
|
| PlatformUsbDevice platform_device,
|
| @@ -117,26 +68,21 @@ void UsbDeviceImpl::ReadAllConfigurations() {
|
| libusb_device_descriptor device_descriptor;
|
| int rv = libusb_get_device_descriptor(platform_device_, &device_descriptor);
|
| if (rv == LIBUSB_SUCCESS) {
|
| - uint8_t num_configurations = device_descriptor.bNumConfigurations;
|
| - configurations_.reserve(num_configurations);
|
| - for (uint8_t i = 0; i < num_configurations; ++i) {
|
| - libusb_config_descriptor* platform_config;
|
| - rv = libusb_get_config_descriptor(platform_device_, i, &platform_config);
|
| - if (rv != LIBUSB_SUCCESS) {
|
| + UsbDeviceDescriptor desc;
|
| + for (uint8_t i = 0; i < device_descriptor.bNumConfigurations; ++i) {
|
| + unsigned char* buffer;
|
| + rv = libusb_get_raw_config_descriptor(platform_device_, i, &buffer);
|
| + if (rv < 0) {
|
| USB_LOG(EVENT) << "Failed to get config descriptor: "
|
| << ConvertPlatformUsbErrorToString(rv);
|
| continue;
|
| }
|
|
|
| - UsbConfigDescriptor config_descriptor(
|
| - platform_config->bConfigurationValue,
|
| - (platform_config->bmAttributes & 0x40) != 0,
|
| - (platform_config->bmAttributes & 0x20) != 0,
|
| - platform_config->MaxPower * 2);
|
| - ConvertConfigDescriptor(platform_config, &config_descriptor);
|
| - configurations_.push_back(config_descriptor);
|
| - libusb_free_config_descriptor(platform_config);
|
| + if (!desc.Parse(std::vector<uint8_t>(buffer, buffer + rv)))
|
| + USB_LOG(EVENT) << "Config descriptor index " << i << " was corrupt.";
|
| + free(buffer);
|
| }
|
| + configurations_.swap(desc.configurations);
|
| } else {
|
| USB_LOG(EVENT) << "Failed to get device descriptor: "
|
| << ConvertPlatformUsbErrorToString(rv);
|
| @@ -144,17 +90,15 @@ void UsbDeviceImpl::ReadAllConfigurations() {
|
| }
|
|
|
| void UsbDeviceImpl::RefreshActiveConfiguration() {
|
| - libusb_config_descriptor* platform_config;
|
| - int rv =
|
| - libusb_get_active_config_descriptor(platform_device_, &platform_config);
|
| + uint8_t config_value;
|
| + int rv = libusb_get_active_config_value(platform_device_, &config_value);
|
| if (rv != LIBUSB_SUCCESS) {
|
| - USB_LOG(EVENT) << "Failed to get config descriptor: "
|
| + USB_LOG(EVENT) << "Failed to get active configuration: "
|
| << ConvertPlatformUsbErrorToString(rv);
|
| return;
|
| }
|
|
|
| - ActiveConfigurationChanged(platform_config->bConfigurationValue);
|
| - libusb_free_config_descriptor(platform_config);
|
| + ActiveConfigurationChanged(config_value);
|
| }
|
|
|
| void UsbDeviceImpl::OpenOnBlockingThread(const OpenCallback& callback) {
|
|
|