diff options
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; |