darwin: add support for handling new error code (kUSBHostReturnPipeStalled)
authorNathan Hjelm <hjelmn@me.com>
Thu, 28 Oct 2021 16:25:03 +0000 (10:25 -0600)
committerNathan Hjelm <hjelmn@me.com>
Thu, 28 Oct 2021 16:25:03 +0000 (10:25 -0600)
With macOS Monterey Apple started using a new error code to indicate a pipe
stall. This new error code needs to be handled both in translation to libusb
error codes and when handling errors setting the alt setting.

References #1011

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
libusb/os/darwin_usb.c
libusb/version_nano.h

index 1243e87f1c28a714474094f5c0bed52d68c9d3bb..007ffd1855a62de570ee4adb34bd6efda65fde28 100644 (file)
@@ -107,6 +107,9 @@ static const char *darwin_error_str (IOReturn result) {
   case kIOReturnExclusiveAccess:
     return "another process has device opened for exclusive access";
   case kIOUSBPipeStalled:
+#if defined(kUSBHostReturnPipeStalled)
+  case kUSBHostReturnPipeStalled:
+#endif
     return "pipe is stalled";
   case kIOReturnError:
     return "could not establish a connection to the Darwin kernel";
@@ -146,6 +149,9 @@ static enum libusb_error darwin_to_libusb (IOReturn result) {
   case kIOReturnExclusiveAccess:
     return LIBUSB_ERROR_ACCESS;
   case kIOUSBPipeStalled:
+#if defined(kUSBHostReturnPipeStalled)
+  case kUSBHostReturnPipeStalled:
+#endif
     return LIBUSB_ERROR_PIPE;
   case kIOReturnBadArgument:
     return LIBUSB_ERROR_INVALID_PARAM;
@@ -1603,8 +1609,10 @@ static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_hand
   else
     usbi_warn (HANDLE_CTX (dev_handle), "SetAlternateInterface: %s", darwin_error_str(kresult));
 
-  if (kresult != kIOUSBPipeStalled)
+  ret = darwin_to_libusb(kresult);
+  if (ret != LIBUSB_ERROR_PIPE) {
     return darwin_to_libusb (kresult);
+  }
 
   /* If a device only supports a default setting for the specified interface, then a STALL
      (kIOUSBPipeStalled) may be returned. Ref: USB 2.0 specs 9.4.10.
index 0243e239e91a801a7db1444dcb8163cd74f76bc3..08f69c6aba34ee4d050782af6cfc205bf019a52a 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11656
+#define LIBUSB_NANO 11657