-
Notifications
You must be signed in to change notification settings - Fork 52
macos: add kernel driver detaching #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Are there use cases for both?
The Apple docs say IOUSBInterfaceInterface700 was added in macOS 10.10+ and IOUSBDeviceInterface650 in macOS 10.9+. If that's correct, we could just use it without extra steps, because Rust libstd has a minimum of 10.12.
Well, the question is whether there could be a cross-platform API for this. In theory we could emulate the macOS behavior on Linux by detaching all interfaces, and that would probably be enough for most use cases. But Linux can only exclusively claim interfaces, not devices, so they have As it is here, it seems confusing to have |
I don't have sufficient expertise in USB to know if this is actually a concern, but I suppose it could be possible that some devices need to be interacted immediately after coming out of reset/re-enumeration, without changing the config, which would only be possible with
Cool, I'll do that.
I think I'll go the I'll try to clean things up, add Linux support for the kernel driver detection, and ping when I'm ready for review. |
|
@kevinmehall How does this look now? A heads up: I haven't yet tested the new |
|
Oh, and to add to what I was saying here:
If you |
|
We may want to hold off on merging this, as I have some more work that could serve as an alternative for having a function like I have some changes I'm working on to add a "driver" field to the I figure that's a lot more general purpose than a I'll finish that work up and send a different PR for that. In the interim, if you get a chance, please do let me know if the other changes I've made so far in this PR look good. |
|
Yeah, I was wondering if Windows does it both ways -- either the device can be bound to One thing to consider is if we should abstract over the "generic driver for userspace" case into a method or enum variant so that users don't have to hard-code platform-specific driver names like "usbfs" or "winusb". |
|
And for Linux, It looks like |
|
Awesome, thanks for all the info/direction! I'll see if I can incorporate all of that in the upcoming PR.
I had that thought of adding a method just like that -- dunno why I didn't suggest that in my comment earlier. Glad we're thinking along the same lines. I'll add that while I'm at it. And, because it can't be said too many times: thanks again for all your work on |
|
Extracted the IOUSBInterfaceInterface700 and IOUSBDeviceInterface650 part into #148 |
Hi Kevin,
For macOS, this adds support for attaching/detaching kernel drivers to/from interfaces, and checking if there is a kernel driver presently attached to a given interface. Testing shows that things seem to be working as desired (I eventually intend to use this in a cross platform, open source pen tablet driver, starting with macOS and Linux).
On macOS, the only way to detach drivers is to either reset the device by enumerating with
kUSBReEnumerateCaptureDeviceMask(whichlibusbsupports), or re-configure the device viaSetConfigurationV2withstartInterfaceMatching=false(whichlibusbdoes not support). Individual interfaces can then have kernel drivers (re)attached.I've added new interface declarations with the minimum version that adds the function pointers I need. For now, I've switched the type aliases over to these newer versions, but breaks support for older versions of macOS. How would you like to resolve that -- perhaps an
enumover the two interface versions, or a newstructthat cherry picks the function pointers we need?I haven't added
is_kernel_driver_attached_to_interfacesupport for the other OSes, so the build is broken for those.I added
os_versionto get the os version viasysctls, thinking that we might want to do something similar tolibusbwhere they choose the latest available device/interface interface version, but I wasn't sure if / how you'd want to go about that, soos_versionis currently unused.I wasn't sure about naming in a number of places ("detached" vs "captured", for instance), so names may be a bit inconsistent / less than ideal.
Let me know how you'd like me to address the remaining issues (or, if it would be less of a bother for you to touch things up yourself, feel free).