Mac OS X USB Kernel Sample Code

This directory contains three example XCode projects for writing USB drivers which operate inside the kernel.  For more details on driver matching for USB devices, see 

http://developer.apple.com/qa/qa2001/qa1076.html

AnchorUSB Driver

This project shows how to implement a kernel level driver. It uses the Cypress/Anchor EZ-USB chip as the target for the driver.

VendorSpecific Driver

This project implements a code-less USB kernel driver that matches to a USB device but does nothing to it.  It actually uses IOKit as the driver for the device, taking advantage of the fact that IOService::start always returns true.  If you are writing a user land driver but your device or interface is already being used by another kernel driver, you can use this driver to supersede that driver. 

For example, if  you have a device that is matched by the IOUSBHIDDriver kernel driver but you want to write your own user land driver, you can modify this project to match your device.  This new driver will then match against your device, but since it doesn't open the device, you will be able to access it through your user space code (without getting the kIOExclusiveAccessError ).  If you are using it to control a USB device, (as opposed to a USB Interface),  the device will be in an unconfigured state (e.g. no IOUSBInterfaces will have been instantiated).  You will need to configure it to a known state before you can start using it.
  
In order to modify this driver, you will need to change the matching criteria.  Edit the VendorSpecificDriver.plist  and modify the bcdDevice, idProduct, and idVendor to suit your device.  Also, change all instances of "MySoftwareCompany" to an appropriate name.  Do so in the Build tab of the Target as well (Double-click on the VendorSpecificDriver symbol in the Targets tab of your project.  In the Build Tab, change the Product name to something more appropriate than MySoftwareCompanyVendorSpecificDriver. 

ClassicNotSeize Driver

This project implements another type of code-less USB kernel driver.  It will use the AppleUSBMergeNub kext to merge a property into the provider's registry entry.  It can be used to create a kernel driver that puts a property in the USB device's dictionary that instructs Classic to not seize control of the device.  For example, Classic will always attempt to control a USB device with a vendor specific bDeviceClass (255) field in its device descriptor.  Another user space application will be unable to use the device while Classic is running.  Using this driver will instruct Classic to not seize control of the device.  This driver can also be used to instruct Classic to always seize the device.

The driver itself does not contain any code.  It uses the code from the com.apple.driver.AppleUSBMergeNub driver (CFBundleIdentifier in the IOKitPersonalities dictionary).  The probe method  for AppleUSBMergeNub driver will look for a dictionary called IOProviderMergeProperties and will merge the items in that dictionary into the device's dictionary.  It will then return false from the probe method, meaning that it won't actually load any more code.

You will need to modify  the IOKitPersonalities dictionary to match your device.  The driver is matching to an IOUSBDevice with idProduct = 0 and idVendor = 0.  As always, you can have multiple personalities in this driver.  You need to modify the ClassicNotSeizeDriver.plist

If you want classic to not seize your device, you need to merge the ClassicMustNotSeize property into your device's dictionary (as shown in this example).  If you want Classic to always seize your device, you need to merge the ClassicMustSeize property.  Be aware that these properties are of type Boolean.

Last modified: 04-Feb-2005