Home > Back-end >  How can I use USBmakebmRequestType with DriverKit
How can I use USBmakebmRequestType with DriverKit

Time:12-21

I'm building a driver in C for my iPad using DriverKit.

I'm trying to make a request to a control endpoint, so I'm trying to use DeviceRequest: https://developer.apple.com/documentation/usbdriverkit/iousbhostinterface/3182582-devicerequest

But the first parameter ask for USBmakebmRequestType which it's a macro defined in IOKit > USB.h

I tried to #include <IOKit/USB.h> but it doesn't find the header.

Any idea? thanks.

CodePudding user response:

As far as I'm aware, that macro isn't available in USBDriverKit. I think the documentation is just a copy-paste from elsewhere. (kernel headers, most likely)

In my code I've simply bitwise or'd (|) different combinations of the various relevant constants from the header <USBDriverKit/AppleUSBDefinitions.h>:

enum tIOUSBDeviceRequest
{
    // […]
    // Pick one each of direction…
    kIOUSBDeviceRequestDirectionOut       = (kIOUSBDeviceRequestDirectionValueOut << kIOUSBDeviceRequestDirectionPhase),
    kIOUSBDeviceRequestDirectionIn        = (kIOUSBDeviceRequestDirectionValueIn << kIOUSBDeviceRequestDirectionPhase),
    // […]
    // …request type…
    kIOUSBDeviceRequestTypeStandard       = (kIOUSBDeviceRequestTypeValueStandard << kIOUSBDeviceRequestTypePhase),
    kIOUSBDeviceRequestTypeClass          = (kIOUSBDeviceRequestTypeValueClass << kIOUSBDeviceRequestTypePhase),
    kIOUSBDeviceRequestTypeVendor         = (kIOUSBDeviceRequestTypeValueVendor << kIOUSBDeviceRequestTypePhase),
    // […]
    // …and recipient:
    kIOUSBDeviceRequestRecipientDevice    = (kIOUSBDeviceRequestRecipientValueDevice << kIOUSBDeviceRequestRecipientPhase),
    kIOUSBDeviceRequestRecipientInterface = (kIOUSBDeviceRequestRecipientValueInterface << kIOUSBDeviceRequestRecipientPhase),
    kIOUSBDeviceRequestRecipientEndpoint  = (kIOUSBDeviceRequestRecipientValueEndpoint << kIOUSBDeviceRequestRecipientPhase),
    kIOUSBDeviceRequestRecipientOther     = (kIOUSBDeviceRequestRecipientValueOther << kIOUSBDeviceRequestRecipientPhase),
}

So, something like:

const uint8_t request_type =
  kIOUSBDeviceRequestTypeVendor
  | kIOUSBDeviceRequestRecipientDevice
  | kIOUSBDeviceRequestDirectionIn;
  • Related