Commit f8e111a1 authored by reillyg's avatar reillyg Committed by Commit bot

Shorten USB enumeration control transfer timeouts to 2 seconds

One minute was a completely ridiculous timeout length as this means that
Chrome will behave as if the device simply doesn't exist until the bad
transfer times out. If the device isn't responding in a couple seconds
it likely never will.

BUG=None

Review-Url: https://codereview.chromium.org/2849893003
Cr-Commit-Position: refs/heads/master@{#468221}
parent dbe2663c
...@@ -41,7 +41,7 @@ const uint8_t kInterfaceDescriptorLength = 9; ...@@ -41,7 +41,7 @@ const uint8_t kInterfaceDescriptorLength = 9;
const uint8_t kEndpointDescriptorLength = 7; const uint8_t kEndpointDescriptorLength = 7;
const uint8_t kInterfaceAssociationDescriptorLength = 8; const uint8_t kInterfaceAssociationDescriptorLength = 8;
const int kControlTransferTimeout = 60000; // 1 minute const int kControlTransferTimeoutMs = 2000; // 2 seconds
struct UsbInterfaceAssociationDescriptor { struct UsbInterfaceAssociationDescriptor {
UsbInterfaceAssociationDescriptor(uint8_t first_interface, UsbInterfaceAssociationDescriptor(uint8_t first_interface,
...@@ -123,7 +123,7 @@ void OnReadConfigDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle, ...@@ -123,7 +123,7 @@ void OnReadConfigDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle,
UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD, UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest, UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kConfigurationDescriptorType << 8 | index, 0, buffer, total_length, kConfigurationDescriptorType << 8 | index, 0, buffer, total_length,
kControlTransferTimeout, kControlTransferTimeoutMs,
base::Bind(&OnReadConfigDescriptor, desc, closure)); base::Bind(&OnReadConfigDescriptor, desc, closure));
} else { } else {
LOG(ERROR) << "Failed to read length for configuration " LOG(ERROR) << "Failed to read length for configuration "
...@@ -169,7 +169,7 @@ void OnReadDeviceDescriptor( ...@@ -169,7 +169,7 @@ void OnReadDeviceDescriptor(
UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD, UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest, UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kConfigurationDescriptorType << 8 | i, 0, header, header->size(), kConfigurationDescriptorType << 8 | i, 0, header, header->size(),
kControlTransferTimeout, kControlTransferTimeoutMs,
base::Bind(&OnReadConfigDescriptorHeader, device_handle, desc_ptr, i, base::Bind(&OnReadConfigDescriptorHeader, device_handle, desc_ptr, i,
closure)); closure));
} }
...@@ -208,7 +208,7 @@ void ReadStringDescriptor( ...@@ -208,7 +208,7 @@ void ReadStringDescriptor(
UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD, UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest, UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kStringDescriptorType << 8 | index, language_id, buffer, buffer->size(), kStringDescriptorType << 8 | index, language_id, buffer, buffer->size(),
kControlTransferTimeout, base::Bind(&OnReadStringDescriptor, callback)); kControlTransferTimeoutMs, base::Bind(&OnReadStringDescriptor, callback));
} }
void OnReadLanguageIds(scoped_refptr<UsbDeviceHandle> device_handle, void OnReadLanguageIds(scoped_refptr<UsbDeviceHandle> device_handle,
...@@ -503,7 +503,7 @@ void ReadUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle, ...@@ -503,7 +503,7 @@ void ReadUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle,
UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD, UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest, UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kDeviceDescriptorType << 8, 0, buffer, buffer->size(), kDeviceDescriptorType << 8, 0, buffer, buffer->size(),
kControlTransferTimeout, kControlTransferTimeoutMs,
base::Bind(&OnReadDeviceDescriptor, device_handle, callback)); base::Bind(&OnReadDeviceDescriptor, device_handle, callback));
} }
......
...@@ -45,7 +45,7 @@ const uint8_t kWebUsbCapabilityUUID[16] = { ...@@ -45,7 +45,7 @@ const uint8_t kWebUsbCapabilityUUID[16] = {
0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, 0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47,
0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65}; 0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65};
const int kControlTransferTimeout = 60000; // 1 minute const int kControlTransferTimeoutMs = 2000; // 2 seconds
using ReadWebUsbDescriptorsCallback = using ReadWebUsbDescriptorsCallback =
base::Callback<void(std::unique_ptr<WebUsbAllowedOrigins> allowed_origins, base::Callback<void(std::unique_ptr<WebUsbAllowedOrigins> allowed_origins,
...@@ -218,7 +218,7 @@ void ReadUrlDescriptor(scoped_refptr<UsbDeviceHandle> device_handle, ...@@ -218,7 +218,7 @@ void ReadUrlDescriptor(scoped_refptr<UsbDeviceHandle> device_handle,
device_handle->ControlTransfer( device_handle->ControlTransfer(
UsbTransferDirection::INBOUND, UsbControlTransferType::VENDOR, UsbTransferDirection::INBOUND, UsbControlTransferType::VENDOR,
UsbControlTransferRecipient::DEVICE, vendor_code, index, kGetUrlRequest, UsbControlTransferRecipient::DEVICE, vendor_code, index, kGetUrlRequest,
buffer, buffer->size(), kControlTransferTimeout, buffer, buffer->size(), kControlTransferTimeoutMs,
base::Bind(&OnReadUrlDescriptor, url_map, index, callback)); base::Bind(&OnReadUrlDescriptor, url_map, index, callback));
} }
...@@ -301,7 +301,7 @@ void OnReadWebUsbAllowedOriginsHeader( ...@@ -301,7 +301,7 @@ void OnReadWebUsbAllowedOriginsHeader(
UsbTransferDirection::INBOUND, UsbControlTransferType::VENDOR, UsbTransferDirection::INBOUND, UsbControlTransferType::VENDOR,
UsbControlTransferRecipient::DEVICE, vendor_code, 0, UsbControlTransferRecipient::DEVICE, vendor_code, 0,
kGetAllowedOriginsRequest, new_buffer, new_buffer->size(), kGetAllowedOriginsRequest, new_buffer, new_buffer->size(),
kControlTransferTimeout, kControlTransferTimeoutMs,
base::Bind(&OnReadWebUsbAllowedOrigins, callback)); base::Bind(&OnReadWebUsbAllowedOrigins, callback));
} }
...@@ -314,7 +314,7 @@ void ReadWebUsbAllowedOrigins( ...@@ -314,7 +314,7 @@ void ReadWebUsbAllowedOrigins(
UsbTransferDirection::INBOUND, UsbControlTransferType::VENDOR, UsbTransferDirection::INBOUND, UsbControlTransferType::VENDOR,
UsbControlTransferRecipient::DEVICE, vendor_code, 0, UsbControlTransferRecipient::DEVICE, vendor_code, 0,
kGetAllowedOriginsRequest, buffer, buffer->size(), kGetAllowedOriginsRequest, buffer, buffer->size(),
kControlTransferTimeout, kControlTransferTimeoutMs,
base::Bind(&OnReadWebUsbAllowedOriginsHeader, device_handle, callback, base::Bind(&OnReadWebUsbAllowedOriginsHeader, device_handle, callback,
vendor_code)); vendor_code));
} }
...@@ -361,7 +361,7 @@ void OnReadBosDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle, ...@@ -361,7 +361,7 @@ void OnReadBosDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle,
UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD, UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest, UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kBosDescriptorType << 8, 0, new_buffer, new_buffer->size(), kBosDescriptorType << 8, 0, new_buffer, new_buffer->size(),
kControlTransferTimeout, kControlTransferTimeoutMs,
base::Bind(&OnReadBosDescriptor, device_handle, callback)); base::Bind(&OnReadBosDescriptor, device_handle, callback));
} }
...@@ -574,7 +574,7 @@ void ReadWebUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle, ...@@ -574,7 +574,7 @@ void ReadWebUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle,
UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD, UsbTransferDirection::INBOUND, UsbControlTransferType::STANDARD,
UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest, UsbControlTransferRecipient::DEVICE, kGetDescriptorRequest,
kBosDescriptorType << 8, 0, buffer, buffer->size(), kBosDescriptorType << 8, 0, buffer, buffer->size(),
kControlTransferTimeout, kControlTransferTimeoutMs,
base::Bind(&OnReadBosDescriptorHeader, device_handle, callback)); base::Bind(&OnReadBosDescriptorHeader, device_handle, callback));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment