Skip to content

Mac: Use IOKit paths - #40

Closed
mrpippy wants to merge 3 commits into
signal11:masterfrom
mrpippy:iokit_path
Closed

mrpippy wants to merge 3 commits into
signal11:masterfrom
mrpippy:iokit_path

Conversation

@mrpippy

@mrpippy mrpippy commented Jan 26, 2012

Copy link
Copy Markdown
Contributor

These commits change hid_enumerate() and hid_open_path() to use IOKit IOService:/ paths for devices.

On 10.6 and above, it's real clean and much simpler than the previous hid_open_path() implementation.

On 10.5, it's a little sticky since IOHIDDeviceGetService() isn't available. First, I'm weakly linking to IOHIDDeviceGetService(), so its availability gets checked at runtime and used if it exists (10.6 and up). For 10.5, the backup plan is to just get the io_service_t directly out of the IOHIDDevice struct. The IOHIDDevice struct never changed throughout 10.5, and I've tested (with hidtest) successfully on 10.5.8 ppc, i386, and x86_64. It's naughty, but it works :)

Also, the device_list removal patches are needed for disconnect detection to work right. I guess since the IOHIDDevice is being created without going through the manager, assigning the removal callback to the manager wouldn't work (the callback wasn't getting called).

@mrpippy
mrpippy force-pushed the iokit_path branch 5 times, most recently from 3d75ba3 to f66c04c Compare November 6, 2014 03:35
mrpippy and others added 3 commits November 24, 2014 12:56
Change hid_enumerate() and hid_open_path() to use IOKit IOService:/
paths to uniquely identify devices, instead of creating a path
(done by the make_path() function).

The path passed to hid_open_path() now must be a valid path to an
IOHIDDevice in the IOService plane, like:
"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC1@1D,7/
AppleUSBEHCI/PLAYSTATION(R)3
Controller@fd120000/IOUSBInterface@0/IOUSBHIDDriver"
Remove get_string_property_utf8(), it's not used since make_path() was removed
Disable get_location_id(), it's not used in active code since make_path() was removed
@mrpippy

mrpippy commented Nov 24, 2014

Copy link
Copy Markdown
Contributor Author

I was making the changes you suggested and realized that using dlopen()/dlsym() to get the address of IOHIDDeviceGetService() is simpler and works in more cases than doing the weak linking.

In particular, with weak-linking if hidapi was compiled on 10.5, the fallback method (pulling it out of IOHIDDevice) would always be used (regardless of what OS the binary was running on).
Now the check is purely runtime, and doesn't require any added compile flags.

I'll push a new version with these changes

@amullins83

Copy link
Copy Markdown
Contributor

After you get that done can you verify my PR #199? I'm not aware of anyone else on here who can test hidapi on a Mac. I'd gladly accept any changes.

@prusnak

prusnak commented Sep 13, 2016

Copy link
Copy Markdown
Contributor

As per discussion in #288, can we please get this fix in?

At the moment HIDAPI is unusable under OS X for devices with more than one interface.

@prusnak

prusnak commented Sep 15, 2016

Copy link
Copy Markdown
Contributor

Let's get this in. There are 2+ ACKs in #288 thread.

@karelbilek

Copy link
Copy Markdown

hey, is this moving along?

@signal11

Copy link
Copy Markdown
Owner

pushed 59a0767 474145e ae15b65

Brenden, thank you so much for all your hard work on this. This kind of code doesn't write itself, and I appreciate how painful some of it must have been to get right. I'm sorry I waited so long before merging it. -- Alan.

@signal11 signal11 closed this Sep 20, 2016
@karelbilek

Copy link
Copy Markdown

Thanks a lot to both of you :)

@prusnak

prusnak commented Sep 20, 2016

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants