darwin: fix behavior of libusb_set_interface_alt_setting when it stalls the pipe
authorNathan Hjelm <hjelmn@google.com>
Tue, 30 Nov 2021 22:10:01 +0000 (15:10 -0700)
committerNathan Hjelm <hjelmn@google.com>
Wed, 1 Dec 2021 16:42:15 +0000 (09:42 -0700)
commitb4b4138a31b2548681ad8af29758e6767c75ae7b
treea9837b1549e7cb293f15bafe19f4685b84d54c74
parent1170db79bdc4155c3d5a64787fcc4f8d56b26174
darwin: fix behavior of libusb_set_interface_alt_setting when it stalls the pipe

In some versions of macOS a pipe stall returned when setting the alternate interface
causes the interface to become unusable. To handle this case the backend was always
re-claiming the interface before clearing the pipe stall. In macOS Monterey
unconditionally re-claiming the interface leads to an error due to the process already
having exclusive access. To resolve this issue we attempt to clear the halt and only
re-claim the interface if clearing the pipe stall returns kIOUSBUnknownPipeErr. Tested
with 12.0.1 and 10.13 and get the expected results in both cases with a custom USB
device that has this behavior.

Fixes #1011
Closes #1031

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