diff options
author | Aaron Wisner <awisner@google.com> | 2018-07-23 15:40:58 -0500 |
---|---|---|
committer | Aaron Wisner <awisner@google.com> | 2018-07-24 11:24:15 -0500 |
commit | ceb7cbf5fde0ff26a35d442135d01e52b0ef0771 (patch) | |
tree | 839d5d4c329fe15e5391e02f829b886db4f00d05 /fastboot/usb_osx.cpp | |
parent | 767506fc5a5023e815cdc36e56688adaac2fe0d5 (diff) | |
download | system_core-ceb7cbf5fde0ff26a35d442135d01e52b0ef0771.tar.gz system_core-ceb7cbf5fde0ff26a35d442135d01e52b0ef0771.tar.bz2 system_core-ceb7cbf5fde0ff26a35d442135d01e52b0ef0771.zip |
Add derived UsbTransport class with USB reset method
For testing there needs to be a way to simulate unplugging and
replugging a device. This change adds support for a USB reset
method that does this.
Also add timeouts, so USB reads/writes don't block forever
on an unresponsive device.
Test: glinux, fastboot tool still works
Test: Reset confirmed working via wireshark Linux URB captures
Change-Id: I7213a2395d4ef1c0238810e4929ab966e78c8b55
Diffstat (limited to 'fastboot/usb_osx.cpp')
-rw-r--r-- | fastboot/usb_osx.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/fastboot/usb_osx.cpp b/fastboot/usb_osx.cpp index e95b04936..442dea527 100644 --- a/fastboot/usb_osx.cpp +++ b/fastboot/usb_osx.cpp @@ -65,17 +65,20 @@ struct usb_handle unsigned int zero_mask; }; -class OsxUsbTransport : public Transport { +class OsxUsbTransport : public UsbTransport { public: - OsxUsbTransport(std::unique_ptr<usb_handle> handle) : handle_(std::move(handle)) {} + OsxUsbTransport(std::unique_ptr<usb_handle> handle, uint32_t ms_timeout) + : handle_(std::move(handle)), ms_timeout_(ms_timeout) {} ~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); }; @@ -456,7 +459,7 @@ static int init_usb(ifc_match_func callback, std::unique_ptr<usb_handle>* handle * Definitions of this file's public functions. */ -Transport* usb_open(ifc_match_func callback) { +UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms) { std::unique_ptr<usb_handle> handle; if (init_usb(callback, &handle) < 0) { @@ -464,7 +467,7 @@ Transport* usb_open(ifc_match_func callback) { return nullptr; } - return new OsxUsbTransport(std::move(handle)); + return new OsxUsbTransport(std::move(handle), timeout_ms); } int OsxUsbTransport::Close() { @@ -472,6 +475,17 @@ int OsxUsbTransport::Close() { 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; @@ -494,7 +508,9 @@ ssize_t OsxUsbTransport::Read(void* data, size_t len) { return -1; } - result = (*handle_->interface)->ReadPipe(handle_->interface, handle_->bulkIn, data, &numBytes); + result = (*handle_->interface) + ->ReadPipeTO(handle_->interface, handle_->bulkIn, data, &numBytes, + USB_TRANSACTION_TIMEOUT, USB_TRANSACTION_TIMEOUT); if (result == 0) { return (int) numBytes; |