Skip to content

darwin: use the IO registry to detect if a kernel driver is attached to an interface#959

Merged
hjelmn merged 1 commit intolibusb:masterfrom
hjelmn:alternate_check_driver
Jul 22, 2021
Merged

darwin: use the IO registry to detect if a kernel driver is attached to an interface#959
hjelmn merged 1 commit intolibusb:masterfrom
hjelmn:alternate_check_driver

Conversation

@hjelmn
Copy link
Copy Markdown
Member

@hjelmn hjelmn commented Jul 21, 2021

The implementation of libusb_kernel_driver_active was attempting to open the interface to
check if a driver is attached. This may have side effects (like configuring the device)
that may be unexpected to the user. This commit updates the code to find the interface's
IO registry entry (either IOUSBHostInterface or the legacy IOUSBInterface) and check if
the entry has a child entry. A child entry indicates that a driver is currently attached.

Signed-off-by: Nathan Hjelm hjelmn@google.com

@hjelmn
Copy link
Copy Markdown
Member Author

hjelmn commented Jul 21, 2021

This is a return to the prior approach which broke when IOUSBFamily was rewritten. This commit fixes the issues with the previous approach and has been verified on macOS 10.12 and 11.

@hjelmn
Copy link
Copy Markdown
Member Author

hjelmn commented Jul 21, 2021

@mcuee This should work better than claiming/releasing the interface. It should also work with older macOS versions given this approach used to work.

@hjelmn hjelmn added the macOS label Jul 21, 2021
…to an interface

The implementation of libusb_kernel_driver_active was attempting to open the interface to
check if a driver is attached. This may have side effects (like configuring the device)
that may be unexpected to the user. This commit updates the code to find the interface's
IO registry entry (either IOUSBHostInterface or the legacy IOUSBInterface) and check if
the entry has a child entry. A child entry indicates that a driver is currently attached.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
@hjelmn hjelmn force-pushed the alternate_check_driver branch from 5a02a12 to b8e3626 Compare July 21, 2021 22:52
@hjelmn
Copy link
Copy Markdown
Member Author

hjelmn commented Jul 21, 2021

Tested with 10.7 and this works there as well.

@mcuee
Copy link
Copy Markdown
Member

mcuee commented Jul 22, 2021

Great. I will try this out soon.

@mcuee
Copy link
Copy Markdown
Member

mcuee commented Jul 22, 2021

Yes this is good.

libusb_959 on  alternate_check_driver [?] ❯ ./examples/xusb 04b4:00f3
Using libusb v1.0.24.11643

Opening device 04B4:00F3...

Reading device descriptor:
            length: 18
      device class: 0
               S/N: 3
           VID:PID: 04B4:00F3
         bcdDevice: 0100
   iMan:iProd:iSer: 1:2:3
          nb confs: 1

Reading BOS descriptor: no descriptor

Reading first configuration descriptor:
             nb interfaces: 1
              interface[0]: id = 0
interface[0].altsetting[0]: num endpoints = 0
   Class.SubClass.Protocol: FF.00.00

Kernel driver attached for interface 0: 0

Claiming interface 0...
libusb: info [darwin_detach_kernel_driver] no capture entitlements. can not detach the kernel driver for this device
libusb: info [darwin_capture_claim_interface] failed to auto-detach the kernel driver for this device, ret=-12

Reading string descriptors:
   String (0x01): "Cypress"
   String (0x02): "WestBridge "
   String (0x03): "0000000004BE"

Releasing interface 0...
Closing device...
libusb_959 on  alternate_check_driver [?] ❯ ./examples/xusb 046d:c52b
Using libusb v1.0.24.11643

Opening device 046D:C52B...

Reading device descriptor:
            length: 18
      device class: 0
               S/N: 0
           VID:PID: 046D:C52B
         bcdDevice: 2410
   iMan:iProd:iSer: 1:2:0
          nb confs: 1

Reading BOS descriptor: no descriptor

Reading first configuration descriptor:
             nb interfaces: 3
              interface[0]: id = 0
interface[0].altsetting[0]: num endpoints = 1
   Class.SubClass.Protocol: 03.01.01
       endpoint[0].address: 81
           max packet size: 0008
          polling interval: 08
              interface[1]: id = 1
interface[1].altsetting[0]: num endpoints = 1
   Class.SubClass.Protocol: 03.01.02
       endpoint[0].address: 82
           max packet size: 0008
          polling interval: 02
              interface[2]: id = 2
interface[2].altsetting[0]: num endpoints = 1
   Class.SubClass.Protocol: 03.00.00
       endpoint[0].address: 83
           max packet size: 0020
          polling interval: 02

Kernel driver attached for interface 0: 1

Claiming interface 0...
libusb: info [darwin_detach_kernel_driver] no capture entitlements. can not detach the kernel driver for this device
libusb: info [darwin_capture_claim_interface] failed to auto-detach the kernel driver for this device, ret=-12
libusb: info [darwin_claim_interface] USBInterfaceOpen: another process has device opened for exclusive access
   Failed.

Kernel driver attached for interface 1: 1

Claiming interface 1...
libusb: info [darwin_detach_kernel_driver] no capture entitlements. can not detach the kernel driver for this device
libusb: info [darwin_capture_claim_interface] failed to auto-detach the kernel driver for this device, ret=-12
libusb: info [darwin_claim_interface] USBInterfaceOpen: another process has device opened for exclusive access
   Failed.

Kernel driver attached for interface 2: 1

Claiming interface 2...
libusb: info [darwin_detach_kernel_driver] no capture entitlements. can not detach the kernel driver for this device
libusb: info [darwin_capture_claim_interface] failed to auto-detach the kernel driver for this device, ret=-12
libusb: info [darwin_claim_interface] USBInterfaceOpen: another process has device opened for exclusive access
   Failed.

Reading string descriptors:
   String (0x01): "Logitech"
   String (0x02): "USB Receiver"

Releasing interface 0...
Releasing interface 1...
Releasing interface 2...
Closing device...

@mcuee
Copy link
Copy Markdown
Member

mcuee commented Jul 22, 2021

@hjelmn Still I see an issue with the output from the Cypress EZUSB FX2LP bootloader device, I think the two info should not be there since there is no kernel driver to detach in the first place. I think the kernel driver detaching code should check whether there is a need to detach kernel driver first. I will create another issue for that.

Kernel driver attached for interface 0: 0

Claiming interface 0...
libusb: info [darwin_detach_kernel_driver] no capture entitlements. can not detach the kernel driver for this device
libusb: info [darwin_capture_claim_interface] failed to auto-detach the kernel driver for this device, ret=-12

Reading string descriptors:
   String (0x01): "Cypress"
   String (0x02): "WestBridge "
   String (0x03): "0000000004BE"

@hjelmn hjelmn merged commit f8dc6af into libusb:master Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants