| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/usb/usb_device_impl.h" | 5 #include "device/usb/usb_device_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 case LIBUSB_ISO_USAGE_TYPE_IMPLICIT: | 87 case LIBUSB_ISO_USAGE_TYPE_IMPLICIT: |
| 88 return USB_USAGE_EXPLICIT_FEEDBACK; | 88 return USB_USAGE_EXPLICIT_FEEDBACK; |
| 89 default: | 89 default: |
| 90 NOTREACHED(); | 90 NOTREACHED(); |
| 91 return USB_USAGE_DATA; | 91 return USB_USAGE_DATA; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ConvertConfigDescriptor(const libusb_config_descriptor* platform_config, | 95 void ConvertConfigDescriptor(const libusb_config_descriptor* platform_config, |
| 96 UsbConfigDescriptor* configuration) { | 96 UsbConfigDescriptor* configuration) { |
| 97 configuration->configuration_value = platform_config->bConfigurationValue; | |
| 98 configuration->self_powered = (platform_config->bmAttributes & 0x40) != 0; | |
| 99 configuration->remote_wakeup = (platform_config->bmAttributes & 0x20) != 0; | |
| 100 configuration->maximum_power = platform_config->MaxPower * 2; | |
| 101 | |
| 102 for (size_t i = 0; i < platform_config->bNumInterfaces; ++i) { | 97 for (size_t i = 0; i < platform_config->bNumInterfaces; ++i) { |
| 103 const struct libusb_interface* platform_interface = | 98 const struct libusb_interface* platform_interface = |
| 104 &platform_config->interface[i]; | 99 &platform_config->interface[i]; |
| 105 for (int j = 0; j < platform_interface->num_altsetting; ++j) { | 100 for (int j = 0; j < platform_interface->num_altsetting; ++j) { |
| 106 const struct libusb_interface_descriptor* platform_alt_setting = | 101 const struct libusb_interface_descriptor* platform_alt_setting = |
| 107 &platform_interface->altsetting[j]; | 102 &platform_interface->altsetting[j]; |
| 108 UsbInterfaceDescriptor interface; | 103 UsbInterfaceDescriptor interface( |
| 109 | 104 platform_alt_setting->bInterfaceNumber, |
| 110 interface.interface_number = platform_alt_setting->bInterfaceNumber; | 105 platform_alt_setting->bAlternateSetting, |
| 111 interface.alternate_setting = platform_alt_setting->bAlternateSetting; | 106 platform_alt_setting->bInterfaceClass, |
| 112 interface.interface_class = platform_alt_setting->bInterfaceClass; | 107 platform_alt_setting->bInterfaceSubClass, |
| 113 interface.interface_subclass = platform_alt_setting->bInterfaceSubClass; | 108 platform_alt_setting->bInterfaceProtocol); |
| 114 interface.interface_protocol = platform_alt_setting->bInterfaceProtocol; | |
| 115 | 109 |
| 116 interface.endpoints.reserve(platform_alt_setting->bNumEndpoints); | 110 interface.endpoints.reserve(platform_alt_setting->bNumEndpoints); |
| 117 for (size_t k = 0; k < platform_alt_setting->bNumEndpoints; ++k) { | 111 for (size_t k = 0; k < platform_alt_setting->bNumEndpoints; ++k) { |
| 118 const struct libusb_endpoint_descriptor* platform_endpoint = | 112 const struct libusb_endpoint_descriptor* platform_endpoint = |
| 119 &platform_alt_setting->endpoint[k]; | 113 &platform_alt_setting->endpoint[k]; |
| 120 UsbEndpointDescriptor endpoint; | 114 UsbEndpointDescriptor endpoint( |
| 121 | 115 platform_endpoint->bEndpointAddress, |
| 122 endpoint.address = platform_endpoint->bEndpointAddress; | 116 GetDirection(platform_endpoint), platform_endpoint->wMaxPacketSize, |
| 123 endpoint.direction = GetDirection(platform_endpoint); | 117 GetSynchronizationType(platform_endpoint), |
| 124 endpoint.maximum_packet_size = platform_endpoint->wMaxPacketSize; | 118 GetTransferType(platform_endpoint), GetUsageType(platform_endpoint), |
| 125 endpoint.synchronization_type = | 119 platform_endpoint->bInterval); |
| 126 GetSynchronizationType(platform_endpoint); | 120 endpoint.extra_data.assign( |
| 127 endpoint.transfer_type = GetTransferType(platform_endpoint); | |
| 128 endpoint.usage_type = GetUsageType(platform_endpoint); | |
| 129 endpoint.polling_interval = platform_endpoint->bInterval; | |
| 130 endpoint.extra_data = std::vector<uint8_t>( | |
| 131 platform_endpoint->extra, | 121 platform_endpoint->extra, |
| 132 platform_endpoint->extra + platform_endpoint->extra_length); | 122 platform_endpoint->extra + platform_endpoint->extra_length); |
| 133 | 123 |
| 134 interface.endpoints.push_back(endpoint); | 124 interface.endpoints.push_back(endpoint); |
| 135 } | 125 } |
| 136 | 126 |
| 137 interface.extra_data = std::vector<uint8_t>( | 127 interface.extra_data.assign( |
| 138 platform_alt_setting->extra, | 128 platform_alt_setting->extra, |
| 139 platform_alt_setting->extra + platform_alt_setting->extra_length); | 129 platform_alt_setting->extra + platform_alt_setting->extra_length); |
| 140 | 130 |
| 141 configuration->interfaces.push_back(interface); | 131 configuration->interfaces.push_back(interface); |
| 142 } | 132 } |
| 143 } | 133 } |
| 144 | 134 |
| 145 configuration->extra_data = std::vector<uint8_t>( | 135 configuration->extra_data.assign( |
| 146 platform_config->extra, | 136 platform_config->extra, |
| 147 platform_config->extra + platform_config->extra_length); | 137 platform_config->extra + platform_config->extra_length); |
| 148 } | 138 } |
| 149 | 139 |
| 150 } // namespace | 140 } // namespace |
| 151 | 141 |
| 152 UsbDeviceImpl::UsbDeviceImpl( | 142 UsbDeviceImpl::UsbDeviceImpl( |
| 153 scoped_refptr<UsbContext> context, | 143 scoped_refptr<UsbContext> context, |
| 154 PlatformUsbDevice platform_device, | 144 PlatformUsbDevice platform_device, |
| 155 uint16_t vendor_id, | 145 uint16_t vendor_id, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 configurations_.reserve(num_configurations); | 234 configurations_.reserve(num_configurations); |
| 245 for (uint8_t i = 0; i < num_configurations; ++i) { | 235 for (uint8_t i = 0; i < num_configurations; ++i) { |
| 246 libusb_config_descriptor* platform_config; | 236 libusb_config_descriptor* platform_config; |
| 247 rv = libusb_get_config_descriptor(platform_device_, i, &platform_config); | 237 rv = libusb_get_config_descriptor(platform_device_, i, &platform_config); |
| 248 if (rv != LIBUSB_SUCCESS) { | 238 if (rv != LIBUSB_SUCCESS) { |
| 249 USB_LOG(EVENT) << "Failed to get config descriptor: " | 239 USB_LOG(EVENT) << "Failed to get config descriptor: " |
| 250 << ConvertPlatformUsbErrorToString(rv); | 240 << ConvertPlatformUsbErrorToString(rv); |
| 251 continue; | 241 continue; |
| 252 } | 242 } |
| 253 | 243 |
| 254 UsbConfigDescriptor config_descriptor; | 244 UsbConfigDescriptor config_descriptor( |
| 245 platform_config->bConfigurationValue, |
| 246 (platform_config->bmAttributes & 0x40) != 0, |
| 247 (platform_config->bmAttributes & 0x20) != 0, |
| 248 platform_config->MaxPower * 2); |
| 255 ConvertConfigDescriptor(platform_config, &config_descriptor); | 249 ConvertConfigDescriptor(platform_config, &config_descriptor); |
| 256 configurations_.push_back(config_descriptor); | 250 configurations_.push_back(config_descriptor); |
| 257 libusb_free_config_descriptor(platform_config); | 251 libusb_free_config_descriptor(platform_config); |
| 258 } | 252 } |
| 259 } else { | 253 } else { |
| 260 USB_LOG(EVENT) << "Failed to get device descriptor: " | 254 USB_LOG(EVENT) << "Failed to get device descriptor: " |
| 261 << ConvertPlatformUsbErrorToString(rv); | 255 << ConvertPlatformUsbErrorToString(rv); |
| 262 } | 256 } |
| 263 } | 257 } |
| 264 | 258 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void UsbDeviceImpl::Opened(PlatformUsbDeviceHandle platform_handle, | 329 void UsbDeviceImpl::Opened(PlatformUsbDeviceHandle platform_handle, |
| 336 const OpenCallback& callback) { | 330 const OpenCallback& callback) { |
| 337 DCHECK(thread_checker_.CalledOnValidThread()); | 331 DCHECK(thread_checker_.CalledOnValidThread()); |
| 338 scoped_refptr<UsbDeviceHandleImpl> device_handle = new UsbDeviceHandleImpl( | 332 scoped_refptr<UsbDeviceHandleImpl> device_handle = new UsbDeviceHandleImpl( |
| 339 context_, this, platform_handle, blocking_task_runner_); | 333 context_, this, platform_handle, blocking_task_runner_); |
| 340 handles_.push_back(device_handle); | 334 handles_.push_back(device_handle); |
| 341 callback.Run(device_handle); | 335 callback.Run(device_handle); |
| 342 } | 336 } |
| 343 | 337 |
| 344 } // namespace device | 338 } // namespace device |
| OLD | NEW |