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

Posts under IOKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

Can't get Driver properties using IORegistryEntryCreateCFProperties on iPadOS 16.1
We are developing our Driver using DriverKit. In client App we successfully discover our driver but can't get IORegistry properties except IOClass. So in a client App we use following code to read properties:     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)         }     } output is: {     IOClass = IOUserService; } We tested same code on macOS and output contains about 20+ properties. It looks like IOKi doesn't allow to read other properties except IOClass. Environment: Xcode - Version 14.1 beta 2 (14B5024i). iPadOS - iOS 16.1 (20B5050f)
1
1
1.4k
Sep ’22
Battery level with IOPSCopyPowerSourcesList
I want to get battery level, estimated remaining time, battery health...etc via IOPSCopyPowerSourcesList Not sure how I'm not experienced with pointers...     func updateBatteryView() {         let battery = IOPSCopyPowerSourcesInfo().takeRetainedValue()         let info = IOPSCopyPowerSourcesList(battery).takeRetainedValue() // Now what?     }
1
0
1.8k
Aug ’22
DriverKit: limitations of AsyncCallback in IOConnectCallAsyncStructMethod?
We implemented communication between Swift App and DriverKit driver using IOConnectCallAsyncStructMethod. So in Swift App we have following code to setup AsyncDataCallback: func AsyncDataCallback(refcon: UnsafeMutableRawPointer?, result: IOReturn, args: UnsafeMutablePointer<UnsafeMutableRawPointer?>?, numArgs: UInt32) -> Void { // handle args } var asyncRef: [io_user_reference_t] = .init(repeating: 0, count: 8) asyncRef[kIOAsyncCalloutFuncIndex] = unsafeBitCast(AsyncDataCallback as IOAsyncCallback, to: UInt64.self) asyncRef[kIOAsyncCalloutRefconIndex] = unsafeBitCast(self, to: UInt64.self) ...... let notificationPort = IONotificationPortCreate(kIOMasterPortDefault) let machNotificationPort = IONotificationPortGetMachPort(notificationPort) let runLoopSource = IONotificationPortGetRunLoopSource(notificationPort)! CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource.takeUnretainedValue(), CFRunLoopMode.defaultMode) var input = "someinput".map { UInt8($0.asciiValue!) } let inputSize = input.count IOConnectCallAsyncStructMethod(             connection,             123,             machNotificationPort,             &asyncRef,             UInt32(kIOAsyncCalloutCount),             &input,             inputSize,             nil,             nil ) In the driver's ExternalMethod we save callback in ivars: ivars->callbackAction = arguments->completion; ivars->callbackAction->retain(); Next we start communication with our device in a separate thread and execute callback when we get data from device: SendDataAsync(void *data, uint32_t dataLength) { const int asyncDataCount = 16; if (ivars->callbackAction != nullptr) {         Log("SendDataAsync() - got %u bytes", dataLength);         uint64_t asyncData[asyncDataCount] = { };         asyncData[0] = dataLength;         memcpy(asyncData + 1, data, dataLength);         AsyncCompletion(ivars->callbackAction, kIOReturnSuccess, asyncData, asyncDataCount);     } Limitation 1: Our device produces data packet every 10 ms. So driver gets 100 data packets per second. Receive rate is good and we verified it by logs. However we see some delay in AsyncCallback in Swift App. It looks like async calls are queued since we see that Swift App gets callbacks for a few seconds when we stopped to send data from Driver. We measured receive rate in Swift App and it is about 50 data packets per second. So what's a minimum call rate for AsyncCompletion? Is it higher than 10 ms? Maybe there is other more efficient way to asynchronously pass data from Driver to Swift App? Limitation 2: We thought we can buffer data packets and decrease AsyncCompletion call rate. However asyncData could be only 16 of uint64_t by declaration typedef uint64_t IOUserClientAsyncArgumentsArray[16];. Size of our data packer is 112 bytes that perfectly fits to max args size(8*16 = 128 bytes). So we can't cache and send 2 data packets. How we can avoid this limitation and send more data via AsyncCompletion? Is there any other API for asynchronous communication that allows send more data back?
3
1
2.1k
Aug ’22
It's not possible to use IOUSBDeviceInterface in iPadOS 16
I'm trying to adapt this example to use it in iPadOS: https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/USBBook/USBDeviceInterfaces/USBDevInterfaces.html#//apple_ref/doc/uid/TP40002645-BBIDDHCI I'm particularly having problem when I try to use IOUSBDeviceInterface. I'm importing #include <IOKit/IOKitLib.h> But when I'm trying to have a method like this: IOReturn ConfigureDevice(IOUSBDeviceInterface **dev) I've get the error:Unknown type name 'IOUSBDeviceInterface' I'm using  Xcode - Version 14.0 beta 3 (14A5270f) Any ideas? Thanks
2
0
2.0k
Aug ’22
Programatically read Automatic Graphics Switching preference?
Customers of an app I work on are having some issues on MacBook Pros with external monitors, which don't occur if the Automatic Graphics Switching is turned off. This is on more recent OS versions (Big Sur, Monterey). Is there a reliable way to check programmatically if this preference setting is turned on, so the app could at least alert the user? I've looked at the com.apple.PowerManagement files in /Library/Preferences, however I don't see any key-values in those files changing when I change this setting (tried rebooting system after changing etc.). Online I've seen some reference to use of the pmset command-line tool to check this however I also do not see its output reflecting any change, and I see conflicting notes on what field might correspond to this setting. Is there any definitive answer or documentation around this setting? Thanks in advance!
0
0
1.5k
Aug ’22
Couldn't pass IOConnectCallScalarMethod output greater than 16 elements
According to Communicating Between a DriverKit Extension and a Client App we can use IOConnectCallScalarMethod to send/get data to Driver. We use unchecked variation of IOConnectCallScalarMethod to call method in our Driver from Client App. In a Driver's method we set arguments->scalarOutputCount greater than 16. However in a Client app outputCount equal to 16, so we can get only a portion of output. Is 16 limit enforced by IOConnectCallScalarMethod implementation? How we can get more than 16? Should we use IOConnectCallStructMethod instead?
1
0
1.4k
Jul ’22
DriverKit on iOS - can't actually communicate with a driver in seed 1?
I watched the session multiple times, but it just gives a high level overview that doesn't really say much about this very exciting and complex new feature. It only mentions actually talking to the driver in passing with a single sentence "apps use the IOKit framework to open user clients". Then the presenter says for an example of that we can check out "communicating between a driverkit extension and a client app", which is a macOS app that doesn't even use IOKit, and trying to import IOKit into an iPadOS target doesn't work anyway because the framework is not there. Am I missing something, or is this simply not available in Xcode 14 seed 1? Release notes don't mention anything either, and docs are only updated to reflect that some of this stuff is now available on iPadOS 16...
7
0
2.9k
Jul ’22
How to access serial port with connect OTG with iPhone and external device
Hello Guys,I am trying to access serial port of external device, this external device is connected with iPhone with OTG cable.Is it possible to access the information of external device (like Device ID and Device Version) in iPhone ?And is it possible to connect external device with Apple Lightning to USB Camera Adapter (MD821ZM/A) to iPhone.and access serial port.Thanks &amp; Regards,Ammy
7
0
15k
Jul ’22
Virtual Audio Device driver porting from CoreAudio to DriverKit
Hello, my goal is to port a virtual audio device written using CoreAudio and IOKit to DriverKit because it is mandatory for App Store distribution for macOS. The driver can be easily installed in Library/Audio/Plug-Ins/HAL and has a .driver extension; it already works in user-space and it is a loopback interface for audio capturing and processing. I have viewed other posts on this forum and the WWDC21 and WWDC22 videos regarding the uses of DriverKit. My question is if it possible to port such driver to DriverKit and embed it in a macOS app for the app store. If yes, is there an example I can follow that allows me to fully embed the driver in an app and consume it from there or if I should still stick to using a separate installer distributing it elsewhere.I have viewed this: https://developer.apple.com/documentation/coreaudio/building_an_audio_server_plug-in_and_driver_extension and it seems that the .driver cannot be embedded in an app in anyway. Thank you kindly for your help, Best regards, Chris
0
0
744
Jul ’22
How do we send dynamic flag HID events?
I see that apple provides dynamic flags here: https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-34.1.1/IOHIDSystem/IOKit/hidsystem/IOHIDUsageTables.h.auto.html In page (0x07). I can send a HID using appium for now, using this command in python: self.driver.execute_script("mobile: performIoHidEvent", {"page": 0x07, "usage": 0xE0, "durationSeconds": 0.5}) But I cannot send dynamic flags to do a CMD.+ Combinations or shift + combinations. I would like know if there is any other way I can do multi-key operations such as CMD + A, CMD + C etc.
0
0
764
Jun ’22
Remap different keyboard using IOHID
Hi there! I'm currently new to Mac OS dev (coming from a history of Linux dev). I have an external BT keyboard and a couple keys are mapped differently than my Mac keyboard (§ to ` for example). I'm wondering if it's possible to write a kernel extension that detects the key sent from the BT keyboard and remap the key code. I don't really know whether this is possible and if it is, where to look in the ecosystem. It's a bit different from Linux. Thank you!
1
0
1.7k
May ’22
UVC cameras not working on M1 Pro and M1 Max on Monterey
Using a few webcams that worked previously on both M1 and Intel Macbooks, testing out on the new MacBook Pro 2021 and the UVC streams are not showing across apps. Here's my setup Tested the Anker, OBSBot, and an Opal, and not seeing any of them show up on UVC streams E.g. The Anker shows up in System Information > USB but in UVC apps like Zoom, etc it does not show up. Running system_profiler SPCameraDataType -json Returns just { "SPCameraDataType" : [ { "_name" : "FaceTime HD Camera", "spcamera_model-id" : "FaceTime HD Camera", "spcamera_unique-id" : "47B4B64B70674B9CAD2BAE273A71F4B5" } ] }%
4
0
6.0k
May ’22
How to keep the iAP2 connection on the lightning interface when the Apple device sleeps?
We are developing a Lighting keyboard(C78A) product that can charge apple devices, with the function of displaying the current power level of apple devices.  A problem was encountered during development. When our keyboard is connected, the apple device is charged, let the apple device enter the lock screen status, the apple device will then sleep and the screen will go black. At this time, the iAP2 channel will be closed, causing our keyboard fail to communicate with Apple devices, but also cannot obtain real-time device power information. On the other hand, when the apple device wakes up from hibernation, the keyboard cannot initialize the iAP2 channel again because the keyboard has always been powered on, which makes it unable to be recognized by the apple device.  So, we want to know if there is a way to keep the iAP2 channel in hibernation when the apple device is connected to our keyboard and charged, so that the above problem can be solved.Thanks .
1
0
1.2k
May ’22
Can't get Driver properties using IORegistryEntryCreateCFProperties on iPadOS 16.1
We are developing our Driver using DriverKit. In client App we successfully discover our driver but can't get IORegistry properties except IOClass. So in a client App we use following code to read properties:     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)         }     } output is: {     IOClass = IOUserService; } We tested same code on macOS and output contains about 20+ properties. It looks like IOKi doesn't allow to read other properties except IOClass. Environment: Xcode - Version 14.1 beta 2 (14B5024i). iPadOS - iOS 16.1 (20B5050f)
Replies
1
Boosts
1
Views
1.4k
Activity
Sep ’22
Mapping memory between DriverKit processes
Having read in the forums that it is possible for dext instances to find and invoke methods on one another, is there any way for one dext process to share a mapped buffer with another? The requirement would be for the buffer to be persistent, something like mappings created by IOConnectMapMemory, which persist until explicitly unmapped.
Replies
0
Boosts
0
Views
1.3k
Activity
Aug ’22
Battery level with IOPSCopyPowerSourcesList
I want to get battery level, estimated remaining time, battery health...etc via IOPSCopyPowerSourcesList Not sure how I'm not experienced with pointers...     func updateBatteryView() {         let battery = IOPSCopyPowerSourcesInfo().takeRetainedValue()         let info = IOPSCopyPowerSourcesList(battery).takeRetainedValue() // Now what?     }
Replies
1
Boosts
0
Views
1.8k
Activity
Aug ’22
DriverKit: limitations of AsyncCallback in IOConnectCallAsyncStructMethod?
We implemented communication between Swift App and DriverKit driver using IOConnectCallAsyncStructMethod. So in Swift App we have following code to setup AsyncDataCallback: func AsyncDataCallback(refcon: UnsafeMutableRawPointer?, result: IOReturn, args: UnsafeMutablePointer<UnsafeMutableRawPointer?>?, numArgs: UInt32) -> Void { // handle args } var asyncRef: [io_user_reference_t] = .init(repeating: 0, count: 8) asyncRef[kIOAsyncCalloutFuncIndex] = unsafeBitCast(AsyncDataCallback as IOAsyncCallback, to: UInt64.self) asyncRef[kIOAsyncCalloutRefconIndex] = unsafeBitCast(self, to: UInt64.self) ...... let notificationPort = IONotificationPortCreate(kIOMasterPortDefault) let machNotificationPort = IONotificationPortGetMachPort(notificationPort) let runLoopSource = IONotificationPortGetRunLoopSource(notificationPort)! CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource.takeUnretainedValue(), CFRunLoopMode.defaultMode) var input = "someinput".map { UInt8($0.asciiValue!) } let inputSize = input.count IOConnectCallAsyncStructMethod(             connection,             123,             machNotificationPort,             &asyncRef,             UInt32(kIOAsyncCalloutCount),             &input,             inputSize,             nil,             nil ) In the driver's ExternalMethod we save callback in ivars: ivars->callbackAction = arguments->completion; ivars->callbackAction->retain(); Next we start communication with our device in a separate thread and execute callback when we get data from device: SendDataAsync(void *data, uint32_t dataLength) { const int asyncDataCount = 16; if (ivars->callbackAction != nullptr) {         Log("SendDataAsync() - got %u bytes", dataLength);         uint64_t asyncData[asyncDataCount] = { };         asyncData[0] = dataLength;         memcpy(asyncData + 1, data, dataLength);         AsyncCompletion(ivars->callbackAction, kIOReturnSuccess, asyncData, asyncDataCount);     } Limitation 1: Our device produces data packet every 10 ms. So driver gets 100 data packets per second. Receive rate is good and we verified it by logs. However we see some delay in AsyncCallback in Swift App. It looks like async calls are queued since we see that Swift App gets callbacks for a few seconds when we stopped to send data from Driver. We measured receive rate in Swift App and it is about 50 data packets per second. So what's a minimum call rate for AsyncCompletion? Is it higher than 10 ms? Maybe there is other more efficient way to asynchronously pass data from Driver to Swift App? Limitation 2: We thought we can buffer data packets and decrease AsyncCompletion call rate. However asyncData could be only 16 of uint64_t by declaration typedef uint64_t IOUserClientAsyncArgumentsArray[16];. Size of our data packer is 112 bytes that perfectly fits to max args size(8*16 = 128 bytes). So we can't cache and send 2 data packets. How we can avoid this limitation and send more data via AsyncCompletion? Is there any other API for asynchronous communication that allows send more data back?
Replies
3
Boosts
1
Views
2.1k
Activity
Aug ’22
It's not possible to use IOUSBDeviceInterface in iPadOS 16
I'm trying to adapt this example to use it in iPadOS: https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/USBBook/USBDeviceInterfaces/USBDevInterfaces.html#//apple_ref/doc/uid/TP40002645-BBIDDHCI I'm particularly having problem when I try to use IOUSBDeviceInterface. I'm importing #include <IOKit/IOKitLib.h> But when I'm trying to have a method like this: IOReturn ConfigureDevice(IOUSBDeviceInterface **dev) I've get the error:Unknown type name 'IOUSBDeviceInterface' I'm using  Xcode - Version 14.0 beta 3 (14A5270f) Any ideas? Thanks
Replies
2
Boosts
0
Views
2.0k
Activity
Aug ’22
keyboard
We are now developing an exam app, how to turn off the custom phrase function of the input method, because this is a means of cheating!
Replies
0
Boosts
0
Views
697
Activity
Aug ’22
Programatically read Automatic Graphics Switching preference?
Customers of an app I work on are having some issues on MacBook Pros with external monitors, which don't occur if the Automatic Graphics Switching is turned off. This is on more recent OS versions (Big Sur, Monterey). Is there a reliable way to check programmatically if this preference setting is turned on, so the app could at least alert the user? I've looked at the com.apple.PowerManagement files in /Library/Preferences, however I don't see any key-values in those files changing when I change this setting (tried rebooting system after changing etc.). Online I've seen some reference to use of the pmset command-line tool to check this however I also do not see its output reflecting any change, and I see conflicting notes on what field might correspond to this setting. Is there any definitive answer or documentation around this setting? Thanks in advance!
Replies
0
Boosts
0
Views
1.5k
Activity
Aug ’22
Couldn't pass IOConnectCallScalarMethod output greater than 16 elements
According to Communicating Between a DriverKit Extension and a Client App we can use IOConnectCallScalarMethod to send/get data to Driver. We use unchecked variation of IOConnectCallScalarMethod to call method in our Driver from Client App. In a Driver's method we set arguments->scalarOutputCount greater than 16. However in a Client app outputCount equal to 16, so we can get only a portion of output. Is 16 limit enforced by IOConnectCallScalarMethod implementation? How we can get more than 16? Should we use IOConnectCallStructMethod instead?
Replies
1
Boosts
0
Views
1.4k
Activity
Jul ’22
DriverKit on iOS - can't actually communicate with a driver in seed 1?
I watched the session multiple times, but it just gives a high level overview that doesn't really say much about this very exciting and complex new feature. It only mentions actually talking to the driver in passing with a single sentence "apps use the IOKit framework to open user clients". Then the presenter says for an example of that we can check out "communicating between a driverkit extension and a client app", which is a macOS app that doesn't even use IOKit, and trying to import IOKit into an iPadOS target doesn't work anyway because the framework is not there. Am I missing something, or is this simply not available in Xcode 14 seed 1? Release notes don't mention anything either, and docs are only updated to reflect that some of this stuff is now available on iPadOS 16...
Replies
7
Boosts
0
Views
2.9k
Activity
Jul ’22
How to access serial port with connect OTG with iPhone and external device
Hello Guys,I am trying to access serial port of external device, this external device is connected with iPhone with OTG cable.Is it possible to access the information of external device (like Device ID and Device Version) in iPhone ?And is it possible to connect external device with Apple Lightning to USB Camera Adapter (MD821ZM/A) to iPhone.and access serial port.Thanks &amp; Regards,Ammy
Replies
7
Boosts
0
Views
15k
Activity
Jul ’22
Virtual Audio Device driver porting from CoreAudio to DriverKit
Hello, my goal is to port a virtual audio device written using CoreAudio and IOKit to DriverKit because it is mandatory for App Store distribution for macOS. The driver can be easily installed in Library/Audio/Plug-Ins/HAL and has a .driver extension; it already works in user-space and it is a loopback interface for audio capturing and processing. I have viewed other posts on this forum and the WWDC21 and WWDC22 videos regarding the uses of DriverKit. My question is if it possible to port such driver to DriverKit and embed it in a macOS app for the app store. If yes, is there an example I can follow that allows me to fully embed the driver in an app and consume it from there or if I should still stick to using a separate installer distributing it elsewhere.I have viewed this: https://developer.apple.com/documentation/coreaudio/building_an_audio_server_plug-in_and_driver_extension and it seems that the .driver cannot be embedded in an app in anyway. Thank you kindly for your help, Best regards, Chris
Replies
0
Boosts
0
Views
744
Activity
Jul ’22
How do we send dynamic flag HID events?
I see that apple provides dynamic flags here: https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-34.1.1/IOHIDSystem/IOKit/hidsystem/IOHIDUsageTables.h.auto.html In page (0x07). I can send a HID using appium for now, using this command in python: self.driver.execute_script("mobile: performIoHidEvent", {"page": 0x07, "usage": 0xE0, "durationSeconds": 0.5}) But I cannot send dynamic flags to do a CMD.+ Combinations or shift + combinations. I would like know if there is any other way I can do multi-key operations such as CMD + A, CMD + C etc.
Replies
0
Boosts
0
Views
764
Activity
Jun ’22
Remap different keyboard using IOHID
Hi there! I'm currently new to Mac OS dev (coming from a history of Linux dev). I have an external BT keyboard and a couple keys are mapped differently than my Mac keyboard (§ to ` for example). I'm wondering if it's possible to write a kernel extension that detects the key sent from the BT keyboard and remap the key code. I don't really know whether this is possible and if it is, where to look in the ecosystem. It's a bit different from Linux. Thank you!
Replies
1
Boosts
0
Views
1.7k
Activity
May ’22
UVC cameras not working on M1 Pro and M1 Max on Monterey
Using a few webcams that worked previously on both M1 and Intel Macbooks, testing out on the new MacBook Pro 2021 and the UVC streams are not showing across apps. Here's my setup Tested the Anker, OBSBot, and an Opal, and not seeing any of them show up on UVC streams E.g. The Anker shows up in System Information > USB but in UVC apps like Zoom, etc it does not show up. Running system_profiler SPCameraDataType -json Returns just { "SPCameraDataType" : [ { "_name" : "FaceTime HD Camera", "spcamera_model-id" : "FaceTime HD Camera", "spcamera_unique-id" : "47B4B64B70674B9CAD2BAE273A71F4B5" } ] }%
Replies
4
Boosts
0
Views
6.0k
Activity
May ’22
How to keep the iAP2 connection on the lightning interface when the Apple device sleeps?
We are developing a Lighting keyboard(C78A) product that can charge apple devices, with the function of displaying the current power level of apple devices.  A problem was encountered during development. When our keyboard is connected, the apple device is charged, let the apple device enter the lock screen status, the apple device will then sleep and the screen will go black. At this time, the iAP2 channel will be closed, causing our keyboard fail to communicate with Apple devices, but also cannot obtain real-time device power information. On the other hand, when the apple device wakes up from hibernation, the keyboard cannot initialize the iAP2 channel again because the keyboard has always been powered on, which makes it unable to be recognized by the apple device.  So, we want to know if there is a way to keep the iAP2 channel in hibernation when the apple device is connected to our keyboard and charged, so that the above problem can be solved.Thanks .
Replies
1
Boosts
0
Views
1.2k
Activity
May ’22