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

Posts under IOKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

Failed to open HID Device
Hello!After updating my devices to iOS to 13.1 I've started to receive "IOServiceOpen failed: 0xe00002e2"in my swift project while connecting USB HID Device to my iPhone. This not good, because IOService is a part of kernel framework and I really need it. What should I do? Is it a bug or a feature of new iOS version?
8
0
4.5k
Nov ’22
Having issues compiling the IOPCIFamily kext
I am trying to compile the IOPCIFamily kext, but it isn't working with me. I'm normally pretty good with troubleshooting, but I'm at a complete loss. I don't even know where to begin 😆 I saw someone say on a thread from 4 years ago that you need to compile XNU to compile IOPCIFamily. I successfully compiled XNU (after much trial and error), but now I'm not sure what to do with it. Could anyone point me in the right direction? Thanks!
1
0
1.3k
Oct ’22
Creating IOHIDEvent objects for DriverKit/IOHIDUserService
The documentation for IOHIDUserService lists the following instance method: virtual void dispatchEvent(IOHIDEvent *event); It specifically says, "You can also call it directly to dispatch events for which you create an IOHIDEvent object." I see nowhere in any documentation on the details for the IOHIDEvent class and creating your own. Google searches let me find https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-368.20/IOHIDFamily/IOHIDEvent.h.auto.html Unfortunately i see nowhere on my computer where IOHIDEvent.h exists. Is this something i'm going to have to build/pull in manually, or is there a framework that I'm just not seeing that I can pull in to create an IOHIDEvent?
1
0
1.7k
Oct ’22
DriverKit code signing/driver loading issues.
I have been trying to get a stub DriverKit driver loading on my computers without success. I keep getting errors regarding the code signature being invalid. I've been beating my head against the wall for a couple weeks now, so I'd appreciate the help. Layout: Standard Application that does the install/removal. BundleId (changed to protect the innocent) com.somename.someapp. Second target with DriverKit driver: com.somename.someapp.mydriver. To start out this is an IOUserHIDEventService. Question 1) I assume these need to be different with their own entitlements. Is that correct? Question 2) this is my current Entitlement layout; App has SystemExtension. Driver has DriverKit, DriverKit HID Transport, and DriverKit HID Event Service Family. Is this correct for this layout? Question 3) Does the Code Signing Identity/Profile in the Apple Developer section need to match exactly, or can that have more than what is requested? (I started equal, but gave more just to try to troubleshoot) Question 4) I have requested and have been approved to have the "Additional Capabilities" versions of the DriverKit entitlements in Identities. Do i need both checked? can I only have the distribution one? Question 5) I have SIP disabled on my machine (csrutil status shows disabled). I thought this was supposed to bypass the code signing checks? I still see the driver loading being killed because of invalid code signing. Question 6) Does the "Additional Capabilities" version of the DriverKit entitlements that I needed get get approval for bypass the need to disable SIP, or will i need to keep it off for the entirety of development? Thanks!
13
0
3.6k
Oct ’22
Where is my kext log(kernel log)
I am new to Mac Os kext development. I want to develop a device driver on macOS Mojave (10.14.2) for my device. I created a demo to check the running process of the driver, but after actually running it, I didn't find any log about the driver. The following is the source code. Compile with xcode. IOKitTest.cpp /* add your code here */ #include "IOKitTest.hpp" #include <IOKit/IOService.h> #include <IOKit/IOLib.h> // 类似cocoa中 super关键字 #define super IOService // 和头文件中的宏定义类似, 自动生成一些特定的代码 OSDefineMetaClassAndStructors(com_apple_driver_IOKitTest, IOService); bool com_apple_driver_IOKitTest::init(OSDictionary *dict) {   bool result = super::init(dict);       IOLog("IOKitTest : did init !! \n"); // IOlog() 生成log日志, 存在在system.log里       log = os_log_create("com.apple.driver", "XmX");   os_log(log, "xmx Tests!!");       /** 遍历OSDictionary */   OSCollectionIterator *iter = OSCollectionIterator::withCollection(dict);   if (iter)   {     OSObject *object = NULL;     while ((object = iter->getNextObject()))     {       OSSymbol *key = OSDynamicCast(OSSymbol, object);       IOLog("iRedTest : key:%s ",key->getCStringNoCopy());       OSString *value = OSDynamicCast(OSString, dict->getObject(key));       if (value != NULL)       {         IOLog("iRedTest : value:%s\n",value->getCStringNoCopy());       }     }   }       return result; } void com_apple_driver_IOKitTest::free(void) {   IOLog("IOKitTest : free \n");   os_log(log, "xmx Tests!!");   super::free(); } IOService *com_apple_driver_IOKitTest::probe(IOService *provider, SInt32 *score) {   IOService *probe = super::probe(provider, score);   return probe; } bool com_apple_driver_IOKitTest::start(IOService *provider) {   bool result = super::start(provider);   IOLog("IOKitTest : start \n");   os_log(log, "xmx Tests!!");   return result; } void com_apple_driver_IOKitTest::stop(IOService *provider) {   IOLog("IOKitTest : stop \n");   os_log(log, "xmx Tests!!");   super::stop(provider); } IOKitTest.hpp /* add your code here */ #include <IOKit/IOService.h> #include <os/log.h> #ifndef IOKitTest_hpp #define IOKitTest_hpp class com_apple_driver_IOKitTest : public IOService {       //一个宏定义,会自动生成该类的构造方法、析构方法和运行时   OSDeclareDefaultStructors(com_apple_driver_IOKitTest);     public:   // 该方法与cocoa中init方法和C++中构造函数类似   virtual bool init(OSDictionary *dict = 0) APPLE_KEXT_OVERRIDE;   // 该方法与cocoa中dealloc方法和c++中析构函数类似   virtual void free(void) APPLE_KEXT_OVERRIDE;   // 进行驱动匹配时调用   virtual IOService *probe(IOService *provider, SInt32 *score) APPLE_KEXT_OVERRIDE;   // 进行加载时调用   virtual bool start(IOService *provider) APPLE_KEXT_OVERRIDE;   // 进行卸载时调用   virtual void stop(IOService *provider) APPLE_KEXT_OVERRIDE;       os_log_t log; }; #endif /* IOKitTest_hpp */ info.plist <?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>CFBundleDevelopmentRegion</key> <string>$(DEVELOPMENT_LANGUAGE)</string> <key>CFBundleExecutable</key> <string>$(EXECUTABLE_NAME)</string> <key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>$(PRODUCT_NAME)</string> <key>CFBundlePackageType</key> <string>KEXT</string> <key>CFBundleShortVersionString</key> <string>1.0</string> <key>CFBundleVersion</key> <string>1</string> <key>IOKitPersonalities</key> <dict> <key>IOKitTest</key> <dict> <key>CFBundleIdentifier</key> <string>com.apple.driver.IOKitTest</string> <key>IOClass</key> <string>com_apple_driver_IOKitTest</string> <key>IOMatchCategory</key> <string>com_apple_driver_IOKitTest</string> <key>IOProbeScore</key> <integer>10000</integer> <key>IOProviderClass</key> <string>IOResource</string> <key>IOResourceMatch</key> <string>IOKit</string> </dict> </dict> <key>NSHumanReadableCopyright</key> <string>Copyright © 2022 JingCe. All rights reserved.</string> <key>OSBundleLibraries</key> <dict> <key>com.apple.kpi.iokit</key> <string>18.2.0</string> <key>com.apple.kpi.libkern</key> <string>18.2.0</string> </dict> </dict> </plist> After the driver is loaded kextstat shows Does the above indicate that the driver is loaded successfully? where to view the kernel log? Where can I learn kext demo?
2
0
1.9k
Oct ’22
USB-C custom device on iPads with iOS16
Hi, I wanted to confirm if it is possible to communicate through the USB-C ports of the newer iPads with USB devices that aren't supported natively by iOS. More specifically, we want to be able to interface CCID (smart cards / USB crypto tokens) devices from our app. It seems that, since iOS 16, the IOKit/DriverKit frameworks are now made available. Does it mean we have everything to interface any kind of USB devices from a mobile app? Will there be constraints when submitting the app to the app store later on? On which devices exactly is this possible? All devices that have a USB-C port (newer iPad Pro / iPad Air / iPad mini)? Only a subset of them? Thank you.
0
1
1.8k
Oct ’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)
1
1
1.2k
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.6k
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
1.9k
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
1.8k
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.2k
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.3k
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.6k
Jul ’22
Failed to open HID Device
Hello!After updating my devices to iOS to 13.1 I've started to receive "IOServiceOpen failed: 0xe00002e2"in my swift project while connecting USB HID Device to my iPhone. This not good, because IOService is a part of kernel framework and I really need it. What should I do? Is it a bug or a feature of new iOS version?
Replies
8
Boosts
0
Views
4.5k
Activity
Nov ’22
Having issues compiling the IOPCIFamily kext
I am trying to compile the IOPCIFamily kext, but it isn't working with me. I'm normally pretty good with troubleshooting, but I'm at a complete loss. I don't even know where to begin 😆 I saw someone say on a thread from 4 years ago that you need to compile XNU to compile IOPCIFamily. I successfully compiled XNU (after much trial and error), but now I'm not sure what to do with it. Could anyone point me in the right direction? Thanks!
Replies
1
Boosts
0
Views
1.3k
Activity
Oct ’22
Creating IOHIDEvent objects for DriverKit/IOHIDUserService
The documentation for IOHIDUserService lists the following instance method: virtual void dispatchEvent(IOHIDEvent *event); It specifically says, "You can also call it directly to dispatch events for which you create an IOHIDEvent object." I see nowhere in any documentation on the details for the IOHIDEvent class and creating your own. Google searches let me find https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-368.20/IOHIDFamily/IOHIDEvent.h.auto.html Unfortunately i see nowhere on my computer where IOHIDEvent.h exists. Is this something i'm going to have to build/pull in manually, or is there a framework that I'm just not seeing that I can pull in to create an IOHIDEvent?
Replies
1
Boosts
0
Views
1.7k
Activity
Oct ’22
DriverKit code signing/driver loading issues.
I have been trying to get a stub DriverKit driver loading on my computers without success. I keep getting errors regarding the code signature being invalid. I've been beating my head against the wall for a couple weeks now, so I'd appreciate the help. Layout: Standard Application that does the install/removal. BundleId (changed to protect the innocent) com.somename.someapp. Second target with DriverKit driver: com.somename.someapp.mydriver. To start out this is an IOUserHIDEventService. Question 1) I assume these need to be different with their own entitlements. Is that correct? Question 2) this is my current Entitlement layout; App has SystemExtension. Driver has DriverKit, DriverKit HID Transport, and DriverKit HID Event Service Family. Is this correct for this layout? Question 3) Does the Code Signing Identity/Profile in the Apple Developer section need to match exactly, or can that have more than what is requested? (I started equal, but gave more just to try to troubleshoot) Question 4) I have requested and have been approved to have the "Additional Capabilities" versions of the DriverKit entitlements in Identities. Do i need both checked? can I only have the distribution one? Question 5) I have SIP disabled on my machine (csrutil status shows disabled). I thought this was supposed to bypass the code signing checks? I still see the driver loading being killed because of invalid code signing. Question 6) Does the "Additional Capabilities" version of the DriverKit entitlements that I needed get get approval for bypass the need to disable SIP, or will i need to keep it off for the entirety of development? Thanks!
Replies
13
Boosts
0
Views
3.6k
Activity
Oct ’22
Where is my kext log(kernel log)
I am new to Mac Os kext development. I want to develop a device driver on macOS Mojave (10.14.2) for my device. I created a demo to check the running process of the driver, but after actually running it, I didn't find any log about the driver. The following is the source code. Compile with xcode. IOKitTest.cpp /* add your code here */ #include "IOKitTest.hpp" #include <IOKit/IOService.h> #include <IOKit/IOLib.h> // 类似cocoa中 super关键字 #define super IOService // 和头文件中的宏定义类似, 自动生成一些特定的代码 OSDefineMetaClassAndStructors(com_apple_driver_IOKitTest, IOService); bool com_apple_driver_IOKitTest::init(OSDictionary *dict) {   bool result = super::init(dict);       IOLog("IOKitTest : did init !! \n"); // IOlog() 生成log日志, 存在在system.log里       log = os_log_create("com.apple.driver", "XmX");   os_log(log, "xmx Tests!!");       /** 遍历OSDictionary */   OSCollectionIterator *iter = OSCollectionIterator::withCollection(dict);   if (iter)   {     OSObject *object = NULL;     while ((object = iter->getNextObject()))     {       OSSymbol *key = OSDynamicCast(OSSymbol, object);       IOLog("iRedTest : key:%s ",key->getCStringNoCopy());       OSString *value = OSDynamicCast(OSString, dict->getObject(key));       if (value != NULL)       {         IOLog("iRedTest : value:%s\n",value->getCStringNoCopy());       }     }   }       return result; } void com_apple_driver_IOKitTest::free(void) {   IOLog("IOKitTest : free \n");   os_log(log, "xmx Tests!!");   super::free(); } IOService *com_apple_driver_IOKitTest::probe(IOService *provider, SInt32 *score) {   IOService *probe = super::probe(provider, score);   return probe; } bool com_apple_driver_IOKitTest::start(IOService *provider) {   bool result = super::start(provider);   IOLog("IOKitTest : start \n");   os_log(log, "xmx Tests!!");   return result; } void com_apple_driver_IOKitTest::stop(IOService *provider) {   IOLog("IOKitTest : stop \n");   os_log(log, "xmx Tests!!");   super::stop(provider); } IOKitTest.hpp /* add your code here */ #include <IOKit/IOService.h> #include <os/log.h> #ifndef IOKitTest_hpp #define IOKitTest_hpp class com_apple_driver_IOKitTest : public IOService {       //一个宏定义,会自动生成该类的构造方法、析构方法和运行时   OSDeclareDefaultStructors(com_apple_driver_IOKitTest);     public:   // 该方法与cocoa中init方法和C++中构造函数类似   virtual bool init(OSDictionary *dict = 0) APPLE_KEXT_OVERRIDE;   // 该方法与cocoa中dealloc方法和c++中析构函数类似   virtual void free(void) APPLE_KEXT_OVERRIDE;   // 进行驱动匹配时调用   virtual IOService *probe(IOService *provider, SInt32 *score) APPLE_KEXT_OVERRIDE;   // 进行加载时调用   virtual bool start(IOService *provider) APPLE_KEXT_OVERRIDE;   // 进行卸载时调用   virtual void stop(IOService *provider) APPLE_KEXT_OVERRIDE;       os_log_t log; }; #endif /* IOKitTest_hpp */ info.plist <?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>CFBundleDevelopmentRegion</key> <string>$(DEVELOPMENT_LANGUAGE)</string> <key>CFBundleExecutable</key> <string>$(EXECUTABLE_NAME)</string> <key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>$(PRODUCT_NAME)</string> <key>CFBundlePackageType</key> <string>KEXT</string> <key>CFBundleShortVersionString</key> <string>1.0</string> <key>CFBundleVersion</key> <string>1</string> <key>IOKitPersonalities</key> <dict> <key>IOKitTest</key> <dict> <key>CFBundleIdentifier</key> <string>com.apple.driver.IOKitTest</string> <key>IOClass</key> <string>com_apple_driver_IOKitTest</string> <key>IOMatchCategory</key> <string>com_apple_driver_IOKitTest</string> <key>IOProbeScore</key> <integer>10000</integer> <key>IOProviderClass</key> <string>IOResource</string> <key>IOResourceMatch</key> <string>IOKit</string> </dict> </dict> <key>NSHumanReadableCopyright</key> <string>Copyright © 2022 JingCe. All rights reserved.</string> <key>OSBundleLibraries</key> <dict> <key>com.apple.kpi.iokit</key> <string>18.2.0</string> <key>com.apple.kpi.libkern</key> <string>18.2.0</string> </dict> </dict> </plist> After the driver is loaded kextstat shows Does the above indicate that the driver is loaded successfully? where to view the kernel log? Where can I learn kext demo?
Replies
2
Boosts
0
Views
1.9k
Activity
Oct ’22
USB-C custom device on iPads with iOS16
Hi, I wanted to confirm if it is possible to communicate through the USB-C ports of the newer iPads with USB devices that aren't supported natively by iOS. More specifically, we want to be able to interface CCID (smart cards / USB crypto tokens) devices from our app. It seems that, since iOS 16, the IOKit/DriverKit frameworks are now made available. Does it mean we have everything to interface any kind of USB devices from a mobile app? Will there be constraints when submitting the app to the app store later on? On which devices exactly is this possible? All devices that have a USB-C port (newer iPad Pro / iPad Air / iPad mini)? Only a subset of them? Thank you.
Replies
0
Boosts
1
Views
1.8k
Activity
Oct ’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.2k
Activity
Sep ’22
How to get LUN id of SCSI connected devices
Hi all I needed some help in getting the LUN id of all devices connected to the system especially for SCSI devices. I'm not able to find any such system command or a SCSI command. Thanks in advance.
Replies
2
Boosts
0
Views
1.1k
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
1k
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.6k
Activity
Aug ’22
get CPU, GPU, Internet connection, etc
how can I get CPU cores and type GPU core and type storage and memory current wifi, recieved&sent packages etc in swift on macOS?
Replies
3
Boosts
0
Views
1.3k
Activity
Aug ’22
IOPSCopyPowerSourcesInfo not working
I have a M2, 13" MacBook Pro import Cocoa import IOKit import Foundation var blob = IOPSCopyPowerSourcesInfo() // cannot find 'IOPSCopyPowerSourcesInfo' in scope
Replies
1
Boosts
0
Views
930
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
1.9k
Activity
Aug ’22
Does the ability to use DriverKit on iPad mean that IOKit will be usable too?
With the advertisement of enhanced IO support on iPadOS16 - Will developers be able to take advantage of IOKit aswell?
Replies
4
Boosts
0
Views
2.6k
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
1.8k
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
618
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.2k
Activity
Aug ’22
Getting Hardware Details like CPU , GPU , Audio names in M1 and Intel Macs
Hi everyone, Does IOKit provide API's for fetching Hardware information from Apple devices. I am unable to implement the required methods, It would be helpful if someone could point me in the right direction. P.S. Is there any common API which could work on both M1 and older chips?
Replies
1
Boosts
0
Views
821
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.3k
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.6k
Activity
Jul ’22