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

IOKit Documentation

Posts under IOKit tag

48 Posts
Sort by:
Post not yet marked as solved
4 Replies
436 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 Last updated
.
Post not yet marked as solved
1 Replies
426 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 nglv.
Last updated
.
Post marked as solved
1 Replies
474 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 Last updated
.
Post not yet marked as solved
3 Replies
467 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 Jafar96.
Last updated
.
Post not yet marked as solved
2 Replies
449 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 Last updated
.
Post marked as solved
6 Replies
650 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 buddax2.
Last updated
.
Post not yet marked as solved
6 Replies
1.9k Views
hi, so i have a little bit of work left on the Asus Xonar family of audio devices. thanks to APPUL's samplepciaudiodriver code and their excellent documentation, Evegeny Gavrilov's kxAudio driver for MAC and Takashi Iwai's exceptional documentation of the ALSA API i have something that is ready for testing. the stats look good, but unfortunately i this is my second HDAV1.3 deluxe. the other one is also in the same room consuming all of my devices with powered audio outputs. no matter, i am in the process of acquiring another xonar sound card in this family. which brings me to my question: what is the benefit of getting an apple developer account for 99 dollars a year? will i be able to distribute a beta kext with my signature that will allow people to test the binary? i don't think others could run a self-signed kext built on one machine, on another, correct? so would a developer license allow others to test a binary built on my machine, assuming they're x86? my hope is that the developer program would allow me to test the binaries and solicit input from enthusiast mac pro owners WORLD WIDE. i them hope to create a new program that will give us the wealth mixers/controls this fantastic line is capable of providing.
Posted
by broly.
Last updated
.
Post marked as solved
3 Replies
4.5k Views
Good day! I'm interested in if there is any way to query CPU/GPU/Battery temperature values on recent iOS systems? I've tried to search forums for "cpu temp", "ios temperature", "battery temperature" etc., but didn't find anything. There was only mentioned some old private API which was supposed to work somehow for iOS<10. All the examples I've found didn't even compile. All the requests and suggestions are pretty old and seems irrelevant. So I decided to bump this topic. Are there any updates? Any hints and suggestions are highly appreciated! Best regards!
Posted Last updated
.
Post not yet marked as solved
3 Replies
698 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 Last updated
.
Post not yet marked as solved
0 Replies
415 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 domj.
Last updated
.
Post not yet marked as solved
1 Replies
421 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 Last updated
.
Post not yet marked as solved
3 Replies
789 Views
Will the External accessory get deprecated, or is it deprecated now?Please reply as the same features are not provided by CoreBluetooth, when connecting with Bluetooth Classic devices.
Posted Last updated
.
Post not yet marked as solved
0 Replies
387 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 Last updated
.
Post not yet marked as solved
1 Replies
1.1k Views
We are developing driver for our USB device. Our approach is to run and test driver on macOS first and then verify on iPadOS 16. In the driver we add custom property -"kUSBSerialNumberString" into default properties: OSDictionary * Driver::devicePropertiesWithSerialNumber() {     kern_return_t ret;     OSDictionary *properties = NULL;     OSDictionary *dictionary = NULL;     OSObjectPtr value;     const IOUSBDeviceDescriptor *deviceDescriptor;     deviceDescriptor = ivars->device->CopyDeviceDescriptor();          ret = CopyProperties(&properties);     value = copyStringAtIndex(deviceDescriptor->iSerialNumber, kIOUSBLanguageIDEnglishUS);     Log("Serial number: %{public}s", ((OSString *)value)->getCStringNoCopy());          dictionary = OSDictionary::withDictionary(properties, 0);     OSSafeReleaseNULL(properties);     if (value) {         OSDictionarySetValue(dictionary, "kUSBSerialNumberString", value);         OSSafeReleaseNULL(value);     }     return  dictionary; } next in kern_return_t IMPL(Driver, Start) we call SetProperties:     ret = SetProperties(devicePropertiesWithSerialNumber());     if(ret != kIOReturnSuccess) {         Log("Start() - Failed to set properties: 0x%08x.", ret);         goto Exit;     } We can read our property on macOS using:     func getDeviceProperty(device: io_object_t, key: String) -> AnyObject? {         IORegistryEntryCreateCFProperty(             device, key as CFString, kCFAllocatorDefault, .zero         )?.takeRetainedValue()     }         if let serialNumber = getDeviceProperty(device: driver, key: "kUSBSerialNumberString") {             print("serialNumber: \(serialNumber)")         } However getDevicePropertyon iPadOS returns nil. We are wondering is any limitation for IORegistry entries(properties) on iPadOS16? Is any way to add custom property to IORegistry? BTW, we added debug method to print all the available properties for IORegistry:     private func debugRegistry(device: io_object_t) {         var dictionary: Unmanaged<CFMutableDictionary>?         IORegistryEntryCreateCFProperties(device, &dictionary, kCFAllocatorDefault, .zero)         if let dictionary = dictionary {             let values = dictionary.takeUnretainedValue()             print(values)         }     } It returns just 1 property for iPadOS: { IOClass = IOUserService; } and much more for macOS including our custom one: { CFBundleIdentifier = "****"; CFBundleIdentifierKernel = "com.apple.kpi.iokit"; IOClass = IOUserService; IOMatchCategory = "***"; IOMatchedPersonality = { CFBundleIdentifier = "****"; CFBundleIdentifierKernel = "com.apple.kpi.iokit"; IOClass = IOUserService; IOMatchCategory = "****"; IOPersonalityPublisher = "****"; IOProviderClass = IOUSBHostInterface; IOResourceMatch = IOKit; IOUserClass = Driver; IOUserServerCDHash = 9cfd03b5c1b90da709ffb1455a053c5d7cdf47ac; IOUserServerName = "*****"; UserClientProperties = { IOClass = IOUserUserClient; IOUserClass = DriverUserClient; }; bConfigurationValue = 1; bInterfaceNumber = 1; bcdDevice = 512; idProduct = XXXXX; idVendor = XXXXX; }; IOPersonalityPublisher = "*****"; IOPowerManagement = { CapabilityFlags = 2; CurrentPowerState = 2; MaxPowerState = 2; }; IOProbeScore = 100000; IOProviderClass = IOUSBHostInterface; IOResourceMatch = IOKit; IOUserClass = Driver; IOUserServerCDHash = 9cfd03b5c1b90da709ffb1455a053c5d7cdf47ac; IOUserServerName = "*****"; UserClientProperties = { IOClass = IOUserUserClient; IOUserClass = DriverUserClient; }; bConfigurationValue = 1; bInterfaceNumber = 1; bcdDevice = 512; idProduct = XXXXX; idVendor = XXXXXX; kUSBSerialNumberString = XXXXXXXXXXX; }
Posted
by myurik2.
Last updated
.
Post not yet marked as solved
3 Replies
730 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 Last updated
.
Post not yet marked as solved
3 Replies
481 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 csv610.
Last updated
.
Post marked as solved
3 Replies
626 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 Last updated
.
Post not yet marked as solved
1 Replies
659 Views
Hello, I am trying to run a sample project from Apple's Developer Documentation that creates and interfaces with a DriverKit Dext. The project can be found here: Creating an Audio Device Driver. I have followed all the steps in the README.md file: downloading the code, enabling automatic signing, building the app, moving it to the Applications folder, and launching it. I then open the app, press "Install Dext", enable it through System Preferences, and receive the message "SoundboardDriver has been activated and is ready to use." However, the audio device does not appear in the MIDI app, there is no mention of it in the IORegistry, and I get the message “Driver extension is not running” when I try to press "Open User Client". Is there another step I need to follow to get the app running? Perhaps it's an entitlement issue? I don't see any error/fault message in the console app relating to the app or driver. I am running MacOS 13.4.1 (22F82) and Xcode 14.3.1 (14E300c). I have tried with and without SIP enabled, but the issue persists. Any help or guidance would be greatly appreciated. Best, Henry
Posted Last updated
.
Post not yet marked as solved
0 Replies
481 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 IvanPN.
Last updated
.
Post not yet marked as solved
0 Replies
476 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 rowlands.
Last updated
.