USBDriverKit

RSS for tag

Develop drivers for USB-based devices using USBDriverKit.

Posts under USBDriverKit tag

45 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

DriverKit | Memory limitations of AsyncCallback
We implemented communication between Swift App and DriverKit driver using IOConnectCallAsyncStructMethod. void USBDriverClass::registerAsyncCallback(){   // Async required variables   notificationPort = NULL;   machNotificationPort = NULL;   runLoopSource = NULL;       // Async initialization   globalRunLoop = CFRunLoopGetMain();   CFRetain(globalRunLoop);       notificationPort = IONotificationPortCreate(kIOMainPortDefault);   if (notificationPort == NULL)   {     printf("Failed to create notification port for application.\n");   }       machNotificationPort = IONotificationPortGetMachPort(notificationPort);   if (machNotificationPort == 0)   {     printf("Failed to get mach notification port for application.\n");   }       runLoopSource = IONotificationPortGetRunLoopSource(notificationPort);   if (runLoopSource == NULL)   {     printf("Failed to get run loop for application.\n");   }       // Establish our notifications in the run loop, so we can get callbacks.   CFRunLoopAddSource(globalRunLoop, runLoopSource, kCFRunLoopDefaultMode);       // Establish our "AsyncCallback" function as the function that will be called by our Dext when it calls its "AsyncCompletion" function.   // We'll use kIOAsyncCalloutFuncIndex and kIOAsyncCalloutRefconIndex to define the parameters for our async callback   // This is your callback function. Check the definition for more details.   asyncRef[kIOAsyncCalloutFuncIndex] = (io_user_reference_t)AsyncCallback;   // Use this for context on the return. For example you might pass "this". But since this example is entirely static, we'll skip that step.   asyncRef[kIOAsyncCalloutRefconIndex] = (io_user_reference_t)NULL;       kern_return_t ret = kIOReturnSuccess;   uint8_t words = 4;       size_t inputSize = sizeof(StructA);   StructA structA;       structA.tag = 1;   structA.length = 0;   structA.values[0] = 0x106000;   structA.values[1] = words * sizeof(uint32_t);       size_t outputSize = sizeof(OutputData);   OutputData data;   printf("registerAsyncCallback called");       ret = IOConnectCallAsyncStructMethod(connection, MessageType_RegisterAsyncCallback, machNotificationPort, asyncRef, kIOAsyncCalloutCount, &structA, inputSize, &data, &outputSize);   if (ret != kIOReturnSuccess)   {     printf("IOConnectCallAsyncStructMethod failed with error: 0x%08x.\n", ret);   } } And when we get data from device we send data back from Driver to Swift app ivars->mUSBProbeDriverClient->AsyncCompletion(ivars->streamingDataCallback, kIOReturnSuccess, asyncData, 16); Driver should transfer data to swift app asynchronously when it's provided by USB device so we can not transfer struct synchronously. Async call back has limitation of 16 of uint64_t only and our application require larger data transfer. The logical way to transfer data using a memory buffer and as per Apple documentation they are providing this using IODataQueueDispatchSource. But they have not provided any example or showed how to use this. How to use fill buffer and use it in swift app using IODataQueueDispatchSource?
1
1
1k
Nov ’23
USBDriverKit driver doesn't match, instead uses standard HID drivers
I'm trying to built a USBDriverKit driver on the Mac. The driver loads properly but when my device is inserted the driver is ignored and instead the com.apple.AppleUserHIDDrivers driver is loaded. I do not understand what is causing this. The device both have USB and HID cababilities but I want it to work with USBDriverKit so that the driver can be used on the Ipad as well. How can I get the driver to match properly? Entitlements: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.developer.driverkit</key> <true/> <key>com.apple.developer.driverkit.transport.usb</key> <array> <dict> <key>idVendor</key> <integer>1240</integer> </dict> </array> <key>com.apple.developer.driverkit.userclient-access</key> <true/> <key>com.apple.security.app-sandbox</key> <true/> </dict> </plist> Info.plist: ... <dict> <key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>IOKitPersonalities</key> <dict> <key>ClickerDriver</key> <dict> <key>IOKitDebug</key> <string>65535</string> <key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>IOClass</key> <string>IOUserService</string> <key>IOProviderClass</key> <string>IOUSBHostInterface</string> <key>IOUserClass</key> <string>ClickerDriver</string> <key>IOUserServerName</key> <string>example.Clicker.driver</string> <key>bInterfaceClass</key> <string>3</string> <key>bInterfaceSubClass</key> <string>0</string> <key>bConfigurationValue</key> <string>1</string> <key>bInterfaceNumber</key> <string>0</string> <key>idProduct</key> <integer>63</integer> <key>idVendor</key> <integer>1240</integer> <key>UserClientProperties</key> <dict> <key>IOClass</key> <string>IOUserUserClient</string> <key>IOUserClass</key> <string>ClickerDriverUserClient</string> </dict> </dict> </dict> <key>OSBundleUsageDescription</key> <string>The app interprets monitors key presses. </string> </dict> </plist> Output of ioreg -b -n "Simple HID Device Demo" -r -l is attacheded. ioreg.log
4
0
1.7k
Aug ’23