IOUSBHostDevice: Exclusive open of usb object failed

I have a command line tool and am trying to connect to a USB device using:
Code Block Objective-C
   _device = [[IOUSBHostDevice alloc] initWithIOService:_service
   options:IOUSBHostObjectInitOptionsDeviceCapture
   queue:_queue
   error:&error
   interestHandler:^(IOUSBHostObject * _Nonnull hostObject, uint32_t messageType, void * _Nullable messageArgument) {
    NSLog(@"Interest handler...");
   }];


However, when I run this tool (even under sudo), I'm hitting the error:

Error:Unable to open io_service_t object and create user client. with reason: Exclusive open of usb object failed.

The documentation for IOUSBHostObjectInitOptionsDeviceCapture implies that using this option and having root privilege should gain exclusive access to the device. The alternative is to use an entitlement, but the executable is terminated immediately in that case probably due to code signing.

I would have expected that running the tool under sudo would have been sufficient to avoid this issue.

I just want to first get things working locally on my Mac for a proof of concept, so I don't really want to deal with code signing up front unless that is absolutely necessary.

What do I need to do to get exclusive access to the USB device?

Thanks in advance.


I am facing this issue too for a while and can't figure it out. Any pointers here?

Hi, is this problem resolved? I am also facing the same issue, after add "com.apple.vm.device-access" entitlement, click run my sandbox app, it crashed

it crashed

See my response on the other thread here you raised this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have the same problem on Ventura, but from an SPM-based macOS command line program (thus no Info.plist nor any entitlement files nor sandbox configurations). What do I need to do in order to access USB from an SPM-based macOS command line program?

Your question seems to be predicated on the assumption that you can apply an entitlement to resolve this issue. That’s not the case. As I mentioned in the post I referenced earlier, the com.apple.vm.device-access is intended to be used by hypervisor apps. If you’re not building a hypervisor app, it’s not the droid you’re looking for.

Now, I’m hardly a USB expect but my understanding is that all the places where macOS gates an action based on com.apple.vm.device-access it also allows programs running as root through the gate.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

IOUSBHostDevice: Exclusive open of usb object failed
 
 
Q