c++macosiokitipadosdriverkit

How can I use USBmakebmRequestType with DriverKit


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 IOUSBHostInterface::DeviceRequest(). For the first parameter, bmRequestType, the documentation states:

bmRequestType

The characteristics of the device request. See the USBmakebmRequestType macro for information about how to construct this request.

But this macro USBmakebmRequestType is defined in IOKit > USB.h

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

Any idea?


Solution

  • 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;