Bypassing HID on the Mac
Greg Abbas

Just recently I tried something new (for me)... writing code for the Mac OS that interacts with a USB device (an INSTEON PowerLinc Controller). I'm in over my head so it's been an adventure, to say the least. One of the first hurdles was pretty annoying, and now that I have it licked (I think) I thought I would share my results with the big ole' internet.

Here's the problem: the device I'm trying to write for represents itself as a HID device, but it's not really. The Mac OS seems to make some assumptions about HID devices that aren't really valid for this one, so I needed to talk to it using the lower-level USB API, not the higher-level HID USB functions. But when you plug in a HID device, apparently the Mac's HID driver "grabs" it and won't let you talk to it directly, so I needed a way to tell the HID manager to leave my device alone. After some Googling and experimentation, here's what I found that worked.

I made a new "kext" bundle (that I put in /System/Library/Extensions) that doesn't have any code in it, just an Info.plist and a version.plist. The version.plist didn't require any tweaking; you can just copy and modify one from one of the other kexts in the folder. The Info.plist is where the magic is. Mine looks something like this.

Replace all of the stuff marked CHANGEME with your own names and values, and use USB Prober to find the product ID and vendor ID of your device if you like. Make sure your bundle is owned by root and writable only by its user (i.e., drwxr-xr-x) otherwise the system won't tolerate it (Console.app is good for debugging issues like that). Finally, load the new kernel extension with kextload (or reboot) for it to take effect. If all goes well, now you can use IOKit to call QueryInterface, USBInterfaceOpen, GetNumEndpoints, and so on without receiving any errors about the device already being locked for exclusive access.

p.s.: Caveat programmer. This was tested only on Tiger (Mac OS X version 10.4). When 10.5 comes out maybe it'll change everything, who knows. :-)

1 response to "Bypassing HID on the Mac"

  1. 781 DaveG October 30, 2007 at 4:03 p.m.

    Thanks for the tip and just a heads up, I sent you an email about your work with the Insteon PLC...


Post a comment

Your name:

Email address:   (optional. used for gravatar but not displayed.)

Website:   (optional)

Comment:   (Limited HTML markup is allowed, including a, abbr, acronym, b, blockquote, br, em, i, li, ol, p, strong, sub, super, and ul.)