summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Hjelm <hjelmn@google.com>2022-04-06 10:24:14 -0600
committerTormod Volden <debian.tormod@gmail.com>2023-01-06 23:33:29 +0100
commit65e4a70e0db5dc85cdbce01be276329580e0d986 (patch)
treeb984a50854ac0b2a14a9fe21f40af648a120d20a
parent1c6e76a483238ba9f0511c77b02ea7607c30d897 (diff)
downloadlibusb-65e4a70e0db5dc85cdbce01be276329580e0d986.tar.gz
darwin: Do not clear device data toggle on macOS 10.5 or newer
Historically Mac OS X always cleared the data toggle on the host side. For consistency, libusb has been calling ClearPipeStallBothEnds to also clear the device side toggle. Newer versions of the IOUSBLib do not clear the host side toggle so there is no need to make this call. Additionally, some buggy devices may fail to correctly implement clearing the data toggle. Signed-off-by: Nathan Hjelm <hjelmn@google.com> [Tormod: Return result from AbortPipe] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
-rw-r--r--libusb/io.c10
-rw-r--r--libusb/os/darwin_usb.c12
-rw-r--r--libusb/version_nano.h2
3 files changed, 15 insertions, 9 deletions
diff --git a/libusb/io.c b/libusb/io.c
index 203fd47..2f38d67 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -3,8 +3,8 @@
* I/O functions for libusb
* Copyright © 2007-2009 Daniel Drake <dsd@gentoo.org>
* Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
- * Copyright © 2019 Nathan Hjelm <hjelmn@cs.umm.edu>
- * Copyright © 2019 Google LLC. All rights reserved.
+ * Copyright © 2019-2022 Nathan Hjelm <hjelmn@cs.unm.edu>
+ * Copyright © 2019-2022 Google LLC. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -311,7 +311,11 @@ if (r == 0 && actual_length == sizeof(data)) {
* libusb_cancel_transfer() is asynchronous/non-blocking in itself. When the
* cancellation actually completes, the transfer's callback function will
* be invoked, and the callback function should check the transfer status to
- * determine that it was cancelled.
+ * determine that it was cancelled. On macOS and iOS it is not possible to
+ * cancel a single transfer. In this case cancelling one tranfer on an endpoint
+ * will cause all transfers on that endpoint to be cancelled. In some cases
+ * the call may cause the endpoint to stall. A call to \ref libusb_clear_halt
+ * may be needed.
*
* Freeing the transfer after it has been cancelled but before cancellation
* has completed will result in undefined behaviour.
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index ecf5d58..574b7bb 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -2278,15 +2278,17 @@ static int darwin_abort_transfers (struct usbi_transfer *itransfer) {
/* abort transactions */
#if InterfaceVersion >= 550
if (LIBUSB_TRANSFER_TYPE_BULK_STREAM == transfer->type)
- (*(cInterface->interface))->AbortStreamsPipe (cInterface->interface, pipeRef, itransfer->stream_id);
+ kresult = (*(cInterface->interface))->AbortStreamsPipe (cInterface->interface, pipeRef, itransfer->stream_id);
else
#endif
- (*(cInterface->interface))->AbortPipe (cInterface->interface, pipeRef);
+ kresult = (*(cInterface->interface))->AbortPipe (cInterface->interface, pipeRef);
- usbi_dbg (ctx, "calling clear pipe stall to clear the data toggle bit");
-
- /* newer versions of darwin support clearing additional bits on the device's endpoint */
+#if InterfaceVersion <= 245
+ /* with older releases of IOUSBFamily the OS always clears the host side data toggle. for
+ consistency also clear the data toggle on the device. */
+ usbi_dbg (ctx, "calling ClearPipeStallBothEnds to clear the data toggle bit");
kresult = (*(cInterface->interface))->ClearPipeStallBothEnds(cInterface->interface, pipeRef);
+#endif
return darwin_to_libusb (kresult);
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index b997ad2..99985a0 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11755
+#define LIBUSB_NANO 11756