Gain user-space access to hardware devices and drivers using IOKit.

IOKit Documentation

Posts under IOKit tag

49 Posts
Sort by:
Post not yet marked as solved
1 Replies
439 Views
Hello, The latest version of Metal (on macOS 14) seems to have the instance property for the Metal device architecture. I was curious how this could be achieved on versions of macOS prior to 14 programatically? xcrun metal-arch The above command provides exactly what I need. I was thinking that I could use Metal and IOKit to grab the architecture, but I am lead to believe that there is some kind of mapping in the metal-arch tool and it may not be that easy. Any help would be greatly appreciated. Thanks.
Posted
by
Post not yet marked as solved
4 Replies
457 Views
I want to get the information of USB like, USB name, size, VID, PID, etc using DriverKit Extension but I'm facing difficulty finding such references or Sample code for the same. Please help me with the Sample code to get USB info with the help of Dext. Thanks
Posted
by
Post marked as solved
1 Replies
492 Views
I'm using IOKit to connect to a custom USB HID device. I'm using XCode 14 and running Swift/SwiftUI. So far I have had great success reading from the device with IOHIDDeviceGetReport and this can be done repeatedly with no issues. However, when I use IOHIDDeviceSetReport, I can only successfully set the report to the device one time correctly but any subsequent call to this function would just end up with an I/O Timeout. Any calls using IOHIDDeviceGetReport still works fine so the USB Device is still functioning correctly, but I couldn't receive any additional IOHIDDeviceSetReport call. If I unplug the USB and plug it in again, I can once again successfully send a command. This is, of course, not very practical for the end user to have to unplug and plug the device in after a single set command, and I don't quite understand what's going on with this. Here's my SetOutputReport function to call the IOHIDDeviceSetReport. The IOHIDDevice must already be connected and opened before calling this function so it's not nil. I don't have this "one shot send command" problem on the PC (Windows 7, 10, 11) or Android (v.11,12,13,14) implementation of this Custom USB HID device. It seems like there's something at the lower level of IOHIDDeviceSetReport on macOS which might be done differently than what's available on the PC or Android. Many searches on the web yielded no useful results. There's an IOHIDDeviceSetReportWithCallback function and it also seems only to work one time as well. private func SetOutputReport(dev: IOHIDDevice? ,reportID: Int, data:[UInt8], reportLength: Int) -> String{ let inputReportID = reportID var buffer = data buffer[0] = UInt8(inputReportID) let bufferPointer = UnsafeMutablePointer<UInt8>.allocate(capacity: buffer.count) bufferPointer.initialize(from: &buffer, count: buffer.count) //print(bufferPointer[0]) let bufferLength: CFIndex = buffer.count var success: IOReturn = kIOReturnError if(dev != nil){ success = IOHIDDeviceSetReport(dev!, kIOHIDReportTypeOutput, CFIndex(buffer[0]), bufferPointer, bufferLength) } print("Set report result \(krToString(success))") return krToString(success) }
Posted
by
Post not yet marked as solved
2 Replies
468 Views
I am currently in the process of developing a DEXT for a USB based external mass storage device using the USBDriverKit framework. IOUSBHostInterface is used as the provider to communicate with the interface's endpoints and I am successful in it. As per the IOUSBHostInterface documentation, To use a host interface object, call Open to create a new session between the interface and your driver. After successfully opening your session, you can request information from the interface and set up pipes to communicate with the interface's endpoints. Remember to close the session you opened in the Stop method of your driver. However, calling Open gains exclusive access to the USB interface and does not allow other services to access the interface. Also, to let go of the exclusive access, Close method can be called but in the Stop method which is called only once during the lifecycle of the extension (when the DEXT is unloaded). As a result of this, Apple's mass storage related KEXTs (media and partition related specifically) do not match the interface and so the filesystem of the drive in question does not get mounted whenever the DEXT has matched the interface. Is this exclusive access a limitation of USBDriverkit or is there any way to get around this issue in this case?
Posted
by
Post not yet marked as solved
3 Replies
484 Views
In a project, I'm using the DriverKit(and HIDDriverKit) framework. I have encountered a problem in the connection between the client app and the driver, which is implemented by the "IOKit" framework. By calling the function "IOServiceGetMatchingServices" the value of "iterator" returns correctly and then communication with the driver is done. However, after releasing the version on the TestFlight, on some systems, the value of the "iterator" returned 0 and it is not possible to communicate with the driver. I checked the status of the activated driver with the command "systemextensionsctl list" and there are no problems on the driver side and the values of "Enabled" and "Active" are starred. AppSandbox = True, SIP: enable ret = IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceNameMatching(dextIdentifier), &iterator); if (ret != kIOReturnSuccess) { goto fail; } while ((service = IOIteratorNext(iterator)) != IO_OBJECT_NULL) { ret = IOServiceOpen(service, mach_task_self(), 0, &connection); if(ret == kIOReturnSuccess) { break; } else { syslog(LOG_WARNING, "IDmelonLog LIB: Can't open service"); } IOObjectRelease(service); }
Posted
by
Post marked as solved
6 Replies
669 Views
I'm working on a system management tool that should be able to Allow/Deny mass storage and portable devices. In case if it is a USB flash drive I can detect Mount events using Endpoint Security framework. Then using IOServiceGetMatchingServices I can find the actual device that is trying to mount new volume, check if it is an allowed device and Allow or Deny mount. But in case if it is an iPhone/iPad or Android device I can't rely on that solution as they don't mount new volumes but user can copy files to the phone. To cover this case I could respond with Deny for the ES_EVENT_TYPE_AUTH_IOKIT_OPEN event. But at that moment I know nothing about the device, only its class which is the same for a mouse and for iPhone. I can add a notification for adding new USB devices, but then I would need somehow to understand that it is a phone/tablet and disconnect or suspend needed USB Device. How could I disconnect or suspend a USB Device having only io_object_t?
Posted
by
Post not yet marked as solved
0 Replies
432 Views
Hi, My goal is to enable this project https://github.com/evidlo/remarkable_mouse to provide native tablet inputs with full information to applications on MacOS, allowing me to reuse my reMarkable tablet for the computer instead of having to buy yet another device, such as a Wacom tablet or an iPad Pro for sidecar when the necessary hardware is already in my posession. I would like to understand whether it is possible to use DriverKit in order to simulate a graphics tablet input device with extra inputs such as pressure and tilt in user-space. Or is this something where IOKit or other comes into play, requiring the creation of a kernel space driver? In either case, what would be the right steps to take? How would I create a virtual device and what are the limitations? If you have the knowledge, how complex would you consider this project to be? The path should basically be some inter-process communication from remarkable_mouse, possibly file-based, triggering tablet events through the driver. At least in the first stage. I assume better performance would be achieved if the whole system was self-contained but porting the reMarkable communication is another challenge on its own. I am experienced developing in other environments but MacOS and driver development are fairly new to me. I've read through the documentation on how to handle the tablet events but creating them seems much murkier. I have searched around for this specific topic without getting much. An open-source tablet driver would be a great place to start but sadly I found none. I've also inquired with ChatGPT but only got high level tips and pseudocode. Any help is greatly appreciated, thank you!
Posted
by
Post not yet marked as solved
1 Replies
437 Views
Hi, I am an absolute beginner at IOKit registry and have a usecase to obtain the device manufacturer name, device serial number and device USB vendor name progrmatically. I m able to obtain the same using ioreg command but I wanted to get these values within my program. Thanks in advance. Device serial number: ioreg -rd1 -c IOPlatformExpertDevice | grep 'IOPlatformSerialNumber' Device manufacturer name: ioreg -rd1 -c IOPlatformExpertDevice | grep 'manufacturer' USB device vendor names: ioreg -rd1 -c IOUSBHostDevice | grep "USB Vendor Name"
Posted
by
Post not yet marked as solved
3 Replies
722 Views
I'd like to check whether there has been (or there will be) any iOS SDK framework or program that support developing a custom driver for our own hardware device via USB type C port, especially after the release of the new iPhone 15 with type C port supported. In addition, I'd like to understand how the app review process will work if we're releasing a Crypto Wallet application that utilizes the cold wallet hardware device, will it be necessary for us to send a set of hardware over to the Apple review team, or the app review can be arranged without the actual device?
Posted
by
Post not yet marked as solved
0 Replies
400 Views
Dear Sirs, I've written a driver extension that can be configured through a user mode application. Now when the system reboots I'd like to start the dext again with the latest configuration right from the beginning and before the user mode applications is started (if it is started at all). What is the recommended way to do this and is there an example available? Should I do this using configuration files and through a special file API inside the dext or is there a kind of registry, or should I use sysctl variables and sysctlbyname? Thanks and best regards, Johannes
Posted
by
Post not yet marked as solved
3 Replies
748 Views
Dear Sirs, I’d like to write a virtual audio driver that also exchanges data with a application and thus probably also offers a driver extension using IOUserClient. My first implementation was based on the sample https://developer.apple.com/documentation/audiodriverkit/creating_an_audio_device_driver and everything works fine and as expected on my development machine and I can install/uninstall the dext from within my application. But I had to learn that I will not be given the required entitlement com.apple.developer.driverkit.family.audio as AudioDriverKit seems to be not intended to be used for virtual drivers. So I found out that this sample should be used as starting point for virtual audio drivers: https://developer.apple.com/documentation/coreaudio/creating_an_audio_server_driver_plug-in. But this sample does not include a dext offering the IOUserClient interface which I think I need. The next sample I found was https://developer.apple.com/documentation/coreaudio/building_an_audio_server_plug-in_and_driver_extension . This doesn’t use AudioDriverKit and it includes IOUserClient so it seems to be a good start. Nevertheless it also requires some entitlements which are com.apple.developer.driverkit and com.apple.developer.driverkit.transport.usb. The client also probably needs the entitlement com.apple.developer.driverkit.userclient-access. Would I be given these entitlements for a pure virtual audio driver and why would I need com.apple.developer.driverkit.transport.usb? And is there a chance that AudioDriverKit will also be opened for virtual drivers as it seems to be a much more modern approach and doesn’t require a reboot for installing? Thanks and best regards, Johannes
Posted
by
Post not yet marked as solved
3 Replies
501 Views
Hello, I get the following error while compiling software, which is related to Apple libs. /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__memory/unique_ptr.h:173:32: error: member 'nullptr_t' declared as a template _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : _ptr(__value_init_tag(), __value_init_tag()) {} What should I do?
Posted
by
Post not yet marked as solved
0 Replies
495 Views
Hi, currently I have a project to develop a customized iOS/iPadOS app that is expected to can connect and communicate an External Cameras to iPhone/iPad device through USB Connection. The app should be able to access the taken photo from the External Cameras and/or take a shot executed by the app. The external camera manufacturers are like Canon, Nikon, and Sony. As references, there are some apps that have that capability above released in Appstore: https://apps.apple.com/us/app/camera-connect-control/id1457548017 https://apps.apple.com/id/app/image-capture-go/id1606632530?platform=iphone As far as I know, I can connect to the Camera by using External Accessory framework provided by Apple as long the external device is MFi program supported and I have the detail of command protocol of the the device used. In my case, Canon Camera is listed as MFi device in https://mfi.apple.com/account/accessory-search. But I don't have the detailed command protocol of the device to communicate with. Questions: Is my understanding related External Accessory framework correct? How to connect and communicate external camera to iPhone/iPad via USB by using External Accessory framework? Is there any other work around to do the things like the reference apps in Appstore above? Thank you very much.
Posted
by
Post not yet marked as solved
0 Replies
491 Views
Using IOHIDManagerCopyDevices to get a list of keyboards and mice attached to Mac, triggers the user facing "Input Monitoring" request. Because I'm NOT monitoring the users input, the result of the user selection makes no difference to the result, but the privacy warning dialog makes my app look suspicious. All it is doing is checking to make sure that the customer has a non-Bluetooth keyboard or mouse, before they click the button to disable Bluetooth. Is there a way a safe way (no private API please) to enumerate HID devices without this warning, or should I file a feedback asking Apple to reconsider what triggers this dialog?
Posted
by
Post marked as solved
3 Replies
635 Views
I have developed a kernel extension (KEXT) for driving SCSI devices and I am able to successfully use it to send commands to the underlying device. The driver class overrides the newUserClient method which gets called whenever IOServiceOpen is called from the user space so that apps can make use of the driver. Is there any way to restrict access to this kernel extension such that only my app would be able to open a user client to access the driver and communicate with it using IOConnectCallMethod?
Posted
by
Post not yet marked as solved
0 Replies
402 Views
macOS, really, so there are a bunch of things that may be running during various types of sleep. I know I can get notifications from IOKit about the system going to sleep or waking up, but if I've got a daemon that crashed, and is then relaunched automatically, can I tell whether the machine is awake, or in some sort of sleep state other than hibernation?
Posted
by
Post not yet marked as solved
2 Replies
456 Views
Hello, I try to get notifications when the display is turned off (not the screensaver). I've tried the following code (part of it), but it don't work at all (the callback is never called).. I don't get where I did something wrong. Any help or relevant documentation link would be very appreciated .. Thank, volfo io_object_t disp_notifierObject; void* disp_refCon = NULL; kern_return_t disp_registerCode; notifyPortRef = IONotificationPortCreate(kIOMainPortDefault); display_wrangler = IOServiceGetMatchingService( kIOMainPortDefault, IOServiceNameMatching("IODisplayWrangler")); // register to receive display sleep notifications disp_registerCode = IOServiceAddInterestNotification( notifyPortRef, display_wrangler, kIOGeneralInterest, CBDisplaySleep, NULL, &disp_notifierObject); if ( disp_registerCode != kIOReturnSuccess ) { printf("IOServiceAddInterestNotification failed\n"); return 2; } CFRunLoopAddSource( CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notifyPortRef), kCFRunLoopCommonModes ); IOObjectRelease (display_wrangler);
Posted
by
Post marked as solved
3 Replies
1.4k Views
Hi, I am developping an app for IOS using React Native. I want to write a native modules in Swift and use Objective C to bridge the React Native JS functions with native component. In particular, i want to use IOKit framework to access such information as Battery Temperature and Battery Level. I read in many stackoverflow articles and in ChatGPT that the usage of IOS Private APIs are forbidden andd Apple will reject the app from AppStore and block the account. Is it true? Is there any legal way to use low level APIs and avoid to be rejected or blocked by Apple? The official Apple Technical Support is not responding me. I would really appreciate your help and support. Best Regards, Kamran
Posted
by
Post marked as solved
5 Replies
704 Views
Hi. I have a class-compliant usb device which announces its serial number as m4121095, as per its kUSBSerialNumberString property. However, the file name it is provided is tty.usbmodemm41210951 – it's the serial number with an additional 1 at the end. What is the meaning of this appendage? (I'm tempted to believe that the 1 at the end is there in the unlikely case another device with the same SN is connected, but there's no way to test this possibility). In the end, I would like to obtain a filename that is guaranteed to be representing a connection to exactly this device. Can I assume that the filename of a device that follows the same protocol of serial numbering will be consistently appended with a number that can in some way be inferred? Thank you.
Posted
by
Post not yet marked as solved
3 Replies
612 Views
Hi everyone, I am fairly new to Apple development. I have been working on a project where I need Mac to interface with an HID device (custom device). I have successfully communicated with the device using IOKit, Core Foundation and Driver Kit frameworks by simply importing these frameworks in the project and making use of their APIs. However, my client is now asking that I develop the communication explicitly using HID Driver Kit. Bear in mind that I have not purchased the apple developer certificate nor do I have any provisional signing certificates and without any of these, Xcode was allowing me to use frameworks like IOKit, DriverKit etc. Now, when I tried importing HIDDriverKit into the project, I am not able to find this framework in the "Frameworks and Libraries" tab. How do I import this framework into my project? Do I have to purchase apple developer ID or get the provisional signing certificates or any other formalities are required? Please let me know what can be done. Any pointers or suggestions are welcome. Best, Vishnu
Posted
by