How to connect to a IOUSBHostInterface

I have poked around the web looking for a good example to do this and I haven't found a working example.

I need to connect to a USB Device, its multiple ports and supports what looks to be a root port and 4 other ports

I am no expert in USB but I do know how to write a kext and client drivers, but thats really not the way to solve this.

I need to display the serialized output from these USB ports for a development board.

I would rather do this on my Mac than have to cobble up a Linux machine and mess around with Linux.

Here is the output from ioreg

MCHP-Debug@03100000 <class IOUSBHostDevice, id 0x105f6fdc2, registered, matched, active, busy 0 (20 ms), retain 27>

MCHP-Debug@0 <class IOUSBHostInterface, id 0x105f6fdc8, registered, matched, active, busy 0 (13 ms), retain 5>

+-o MCHP-Debug@0 <class IOUSBHostInterface, id 0x105f6fdc8, registered, matched, active, busy 0 (13 ms), retain 5> +-o MCHP-Debug@1 <class IOUSBHostInterface, id 0x105f6fdc9, registered, matched, active, busy 0 (11 ms), retain 5> +-o MCHP-Debug@2 <class IOUSBHostInterface, id 0x105f6fdcb, registered, matched, active, busy 0 (9 ms), retain 5> | | | | | +-o MCHP-Debug@3 <class IOUSBHostInterface, id 0x105f6fdcc, registered, matched, active, busy 0 (7 ms), retain 5>

I have been able to open a inservice to the device at the top level, but I get an error when I use.

usbHostInterface = [[IOUSBHostInterface alloc] initWithIOService:usbDevice options: IOUSBHostObjectInitOptionsNone queue: queue error: &error interestHandler: handler];

Error:Failed to create IOUSBHostInterface. with reason: Unable to obtain configuration descriptor. Assertion failed: (usbHostInterface), function main, file main.m, line 87.

I started using DeviceKit but I received signing errors and I shouldn't have to go down that path just to dump data from a USB port?

Any suggestions would be great, most of the Apple documentation on USB ports is like 20 years old and the new stuff pushes you towards DeviceKit.

Answered by DTS Engineer in 868106022

Any suggestions would be great. Most of the Apple documentation on USB ports is like 20 years old, and the new stuff pushes you towards DriverKit.

Making this explicit, trying to do this with DriverKit is a great way to make a lot of extra work for yourself without any real benefit. You MIGHT need a codeless DEXT, but that's very different than actually using DriverKit. The USB Host framework is exactly what you want to use.

I have been able to open an inservice to the device at the top level, but I get an error when I use it.

What's the device? The typical issue here is that one of the class drivers has claimed the device, which blocks your access.

Assuming that's the case...

I started using DeviceKit, but I received signing errors. I shouldn't have to go down that path just to dump data from a USB port?

...then a codeless DEXT will let you push our driver out of the way. The article "Overriding the default USB video class extension" has an overview of what's involved.

On the codesigning side:

I started using DeviceKit, but I received signing errors.

If all you care about is development, then what you need to do to sign a USB DEXT is:

  • Set your codesigning configuration to "Automatic".

  • Add the "DriverKit USB Transport (development)" capability in Xcode.

  • Switch to your Entitlement.plist and configure the "DriverKit USB Transport"/com.apple.developer.driverkit.transport.usb key as:

<key>com.apple.developer.driverkit.transport.usb</key>
<array>
	<dict>
		<key>idVendor</key>
		<string>*</string>
	</dict>
</array>
  • Hit build and you're (hopefully) done.

I do know how to write a kext and client drivers, but that’s really not the way to solve this.

If you know how IOKit works, then the thing to understand is that DEXT loading actually happens on "top" of the existing IOKit matching/loading process. So a codeless DEXT is a DEXT that's been configured such that its loading process reroutes to an IOKit driver instead of a DEXT support driver. That's basically how codeless KEXTs always worked.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Any suggestions would be great. Most of the Apple documentation on USB ports is like 20 years old, and the new stuff pushes you towards DriverKit.

Making this explicit, trying to do this with DriverKit is a great way to make a lot of extra work for yourself without any real benefit. You MIGHT need a codeless DEXT, but that's very different than actually using DriverKit. The USB Host framework is exactly what you want to use.

I have been able to open an inservice to the device at the top level, but I get an error when I use it.

What's the device? The typical issue here is that one of the class drivers has claimed the device, which blocks your access.

Assuming that's the case...

I started using DeviceKit, but I received signing errors. I shouldn't have to go down that path just to dump data from a USB port?

...then a codeless DEXT will let you push our driver out of the way. The article "Overriding the default USB video class extension" has an overview of what's involved.

On the codesigning side:

I started using DeviceKit, but I received signing errors.

If all you care about is development, then what you need to do to sign a USB DEXT is:

  • Set your codesigning configuration to "Automatic".

  • Add the "DriverKit USB Transport (development)" capability in Xcode.

  • Switch to your Entitlement.plist and configure the "DriverKit USB Transport"/com.apple.developer.driverkit.transport.usb key as:

<key>com.apple.developer.driverkit.transport.usb</key>
<array>
	<dict>
		<key>idVendor</key>
		<string>*</string>
	</dict>
</array>
  • Hit build and you're (hopefully) done.

I do know how to write a kext and client drivers, but that’s really not the way to solve this.

If you know how IOKit works, then the thing to understand is that DEXT loading actually happens on "top" of the existing IOKit matching/loading process. So a codeless DEXT is a DEXT that's been configured such that its loading process reroutes to an IOKit driver instead of a DEXT support driver. That's basically how codeless KEXTs always worked.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

How to connect to a IOUSBHostInterface
 
 
Q