a1ien / rusb

A safe Rust wrapper for libusb.
Other
382 stars 78 forks source link

K8055 Board fails to detach kernel driver on MacOS #193

Closed aidenfoxivey closed 2 months ago

aidenfoxivey commented 5 months ago

I got this K8055 board from velleman and I thought I'd write a program to use it via libusb. I'm on a Mac, but I wanted to write it to be cross platform. Unfortunately detach_kernel_driver panics! I would be very grateful for any help with sorting this predicament out.

I'm on Darwin orchard 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64 running with SIP enabled.

Minimum working example.

use rusb::{supports_detach_kernel_driver, DeviceHandle};

fn main() {
    let (vendor_id, product_id) = (0x10cf, 0x5500);

    let mut handle: Option<DeviceHandle<rusb::GlobalContext>> = None;

    for device in rusb::devices().unwrap().iter() {
        let device_desc = device.device_descriptor().unwrap();
        if device_desc.vendor_id() == vendor_id && device_desc.product_id() == product_id {
            handle = Some(device.open().unwrap());
            break;
        }
    }

    if let Some(mut device_handle) = handle {
        println!("Supports detach kernel driver is {}", supports_detach_kernel_driver());
        device_handle.detach_kernel_driver(0).unwrap();
    }
}

I expected it to work, but instead I get

Supports detach kernel driver is true
thread 'main' panicked at src/bin.rs:18:47:
called `Result::unwrap()` on an `Err` value: Access
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I'm not sure I know what Access means. I also checked Console.app and didn't find anything that indicated what was happening.

Is doing this just quite complicated on a Mac and I didn't realize?

Thank you for your assistance.

a1ien commented 2 months ago

I think you need root access to detach kernel drive.

aidenfoxivey commented 2 months ago

Let me give that a try - maybe I screwed something up.

aidenfoxivey commented 2 months ago

@a1ien sorry to bother you - it was just my cluelessness.