darwin: use detach kernel APIs for capture
authorosy <50960678+osy@users.noreply.github.com>
Wed, 12 May 2021 03:56:27 +0000 (20:56 -0700)
committerNathan Hjelm <hjelmn@google.com>
Sun, 16 May 2021 21:14:49 +0000 (15:14 -0600)
commitabd788c203624930241f45f32b501c16936bd806
tree2b37ea0501f4290ff66c3def72ce1c5d54767327
parentbd097fe80255d4df55b673f45d96d39db0d47886
darwin: use detach kernel APIs for capture

When libusb_detach_kernel_driver() is called on the first interface, we use
the capture re-enumerate APIs to force kernel drivers to detach. On
subsequent calls, a counter is incremented to keep track of the number of
detach calls. When libusb_attach_kernel_driver() is called for the same
number of times, then we re-enumerate (reset) and let kernel drivers
re-attach.

darwin_kernel_driver_active() is changed to attempt to claim an interface
and return 1 only if a kIOReturnExclusiveAccess status is returned. The old
implementation which looks for a CFBundleID in the IORegistryEntry does not
seem to work in all cases.

darwin_reset_device() is aware of the capture status and will re-set twice
if capture mode is enabled: once to do a USB reset and again to re-capture.

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