Revert "Add derived UsbTransport class with USB reset method"
This reverts commit ceb7cbf5fde0ff26a35d442135d01e52b0ef0771.
Reason for revert: Broke mac builds:
system/core/fastboot/usb_osx.cpp:513:35: error: use of undeclared identifier 'USB_TRANSACTION_TIMEOUT'
USB_TRANSACTION_TIMEOUT, USB_TRANSACTION_TIMEOUT);
^
Change-Id: Ibe2f9ff2d5c63f9d33f4bd6d9ba962604cf8caeb
diff --git a/fastboot/usb.h b/fastboot/usb.h
index 96eb934..5b44468 100644
--- a/fastboot/usb.h
+++ b/fastboot/usb.h
@@ -52,13 +52,6 @@
char device_path[256];
};
-class UsbTransport : public Transport {
- // Resets the underlying transport. Returns 0 on success.
- // This effectively simulates unplugging and replugging
- virtual int Reset() = 0;
-};
-
typedef int (*ifc_match_func)(usb_ifc_info *ifc);
-// 0 is non blocking
-UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms = 0);
+Transport* usb_open(ifc_match_func callback);
diff --git a/fastboot/usb_linux.cpp b/fastboot/usb_linux.cpp
index 9b779dd..386dd30 100644
--- a/fastboot/usb_linux.cpp
+++ b/fastboot/usb_linux.cpp
@@ -52,7 +52,7 @@
using namespace std::chrono_literals;
-#define MAX_RETRIES 2
+#define MAX_RETRIES 5
/* Timeout in seconds for usb_wait_for_disconnect.
* It doesn't usually take long for a device to disconnect (almost always
@@ -91,21 +91,18 @@
unsigned char ep_out;
};
-class LinuxUsbTransport : public UsbTransport {
+class LinuxUsbTransport : public Transport {
public:
- explicit LinuxUsbTransport(std::unique_ptr<usb_handle> handle, uint32_t ms_timeout = 0)
- : handle_(std::move(handle)), ms_timeout_(ms_timeout) {}
+ explicit LinuxUsbTransport(std::unique_ptr<usb_handle> handle) : handle_(std::move(handle)) {}
~LinuxUsbTransport() override = default;
ssize_t Read(void* data, size_t len) override;
ssize_t Write(const void* data, size_t len) override;
int Close() override;
- int Reset() override;
int WaitForDisconnect() override;
private:
std::unique_ptr<usb_handle> handle_;
- const uint32_t ms_timeout_;
DISALLOW_COPY_AND_ASSIGN(LinuxUsbTransport);
};
@@ -405,7 +402,7 @@
bulk.ep = handle_->ep_out;
bulk.len = xfer;
bulk.data = data;
- bulk.timeout = ms_timeout_;
+ bulk.timeout = 0;
n = ioctl(handle_->desc, USBDEVFS_BULK, &bulk);
if(n != xfer) {
@@ -439,7 +436,7 @@
bulk.ep = handle_->ep_in;
bulk.len = xfer;
bulk.data = data;
- bulk.timeout = ms_timeout_;
+ bulk.timeout = 0;
retry = 0;
do {
@@ -450,7 +447,7 @@
if (n < 0) {
DBG1("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno));
if (++retry > MAX_RETRIES) return -1;
- std::this_thread::sleep_for(100ms);
+ std::this_thread::sleep_for(1s);
}
} while (n < 0);
@@ -480,19 +477,10 @@
return 0;
}
-int LinuxUsbTransport::Reset() {
- int ret = 0;
- // We reset the USB connection
- if ((ret = ioctl(handle_->desc, USBDEVFS_RESET, 0))) {
- return ret;
- }
-
- return 0;
-}
-
-UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms) {
+Transport* usb_open(ifc_match_func callback)
+{
std::unique_ptr<usb_handle> handle = find_usb_device("/sys/bus/usb/devices", callback);
- return handle ? new LinuxUsbTransport(std::move(handle), timeout_ms) : nullptr;
+ return handle ? new LinuxUsbTransport(std::move(handle)) : nullptr;
}
/* Wait for the system to notice the device is gone, so that a subsequent
diff --git a/fastboot/usb_osx.cpp b/fastboot/usb_osx.cpp
index 442dea5..e95b049 100644
--- a/fastboot/usb_osx.cpp
+++ b/fastboot/usb_osx.cpp
@@ -65,20 +65,17 @@
unsigned int zero_mask;
};
-class OsxUsbTransport : public UsbTransport {
+class OsxUsbTransport : public Transport {
public:
- OsxUsbTransport(std::unique_ptr<usb_handle> handle, uint32_t ms_timeout)
- : handle_(std::move(handle)), ms_timeout_(ms_timeout) {}
+ OsxUsbTransport(std::unique_ptr<usb_handle> handle) : handle_(std::move(handle)) {}
~OsxUsbTransport() override = default;
ssize_t Read(void* data, size_t len) override;
ssize_t Write(const void* data, size_t len) override;
int Close() override;
- int Reset() override;
private:
std::unique_ptr<usb_handle> handle_;
- const uint32_t ms_timeout_;
DISALLOW_COPY_AND_ASSIGN(OsxUsbTransport);
};
@@ -459,7 +456,7 @@
* Definitions of this file's public functions.
*/
-UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms) {
+Transport* usb_open(ifc_match_func callback) {
std::unique_ptr<usb_handle> handle;
if (init_usb(callback, &handle) < 0) {
@@ -467,7 +464,7 @@
return nullptr;
}
- return new OsxUsbTransport(std::move(handle), timeout_ms);
+ return new OsxUsbTransport(std::move(handle));
}
int OsxUsbTransport::Close() {
@@ -475,17 +472,6 @@
return 0;
}
-int OsxUsbTransport::Reset() {
- IOReturn result = (*handle_->interface)->ResetDevice(handle_->interface);
-
- if (result == 0) {
- return 0;
- } else {
- ERR("usb_reset failed with status %x\n", result);
- return -1;
- }
-}
-
ssize_t OsxUsbTransport::Read(void* data, size_t len) {
IOReturn result;
UInt32 numBytes = len;
@@ -508,9 +494,7 @@
return -1;
}
- result = (*handle_->interface)
- ->ReadPipeTO(handle_->interface, handle_->bulkIn, data, &numBytes,
- USB_TRANSACTION_TIMEOUT, USB_TRANSACTION_TIMEOUT);
+ result = (*handle_->interface)->ReadPipe(handle_->interface, handle_->bulkIn, data, &numBytes);
if (result == 0) {
return (int) numBytes;
diff --git a/fastboot/usb_windows.cpp b/fastboot/usb_windows.cpp
index 8c60a71..0e5fba1 100644
--- a/fastboot/usb_windows.cpp
+++ b/fastboot/usb_windows.cpp
@@ -66,7 +66,7 @@
std::string interface_name;
};
-class WindowsUsbTransport : public UsbTransport {
+class WindowsUsbTransport : public Transport {
public:
WindowsUsbTransport(std::unique_ptr<usb_handle> handle) : handle_(std::move(handle)) {}
~WindowsUsbTransport() override = default;
@@ -74,7 +74,6 @@
ssize_t Read(void* data, size_t len) override;
ssize_t Write(const void* data, size_t len) override;
int Close() override;
- int Reset() override;
private:
std::unique_ptr<usb_handle> handle_;
@@ -262,12 +261,6 @@
return 0;
}
-int WindowsUsbTransport::Reset() {
- DBG("usb_reset currently unsupported\n\n");
- // TODO, this is a bit complicated since it is using ADB
- return -1;
-}
-
int recognized_device(usb_handle* handle, ifc_match_func callback) {
struct usb_ifc_info info;
USB_DEVICE_DESCRIPTOR device_desc;
@@ -373,7 +366,8 @@
return handle;
}
-UsbTransport* usb_open(ifc_match_func callback, uint32_t) {
+Transport* usb_open(ifc_match_func callback)
+{
std::unique_ptr<usb_handle> handle = find_usb_device(callback);
return handle ? new WindowsUsbTransport(std::move(handle)) : nullptr;
}