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

IOKit Documentation

Posts under IOKit tag

57 Posts
Sort by:
Post not yet marked as solved
0 Replies
45 Views
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?
Posted
by myurik2.
Last updated
.
Post not yet marked as solved
0 Replies
40 Views
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!
Posted
by Xjq.
Last updated
.
Post not yet marked as solved
0 Replies
202 Views
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!
Posted
by ccorbell.
Last updated
.
Post not yet marked as solved
1 Replies
43 Views
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?
Posted
by garvitm.
Last updated
.
Post marked as solved
1 Replies
98 Views
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?
Posted
by myurik2.
Last updated
.
Post not yet marked as solved
2 Replies
98 Views
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
Posted Last updated
.
Post not yet marked as solved
7 Replies
543 Views
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...
Posted
by fichek.
Last updated
.
Post not yet marked as solved
6 Replies
7.3k Views
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
Posted Last updated
.
Post not yet marked as solved
0 Replies
132 Views
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
Posted Last updated
.
Post not yet marked as solved
0 Replies
92 Views
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.
Posted Last updated
.
Post not yet marked as solved
1 Replies
229 Views
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!
Posted Last updated
.
Post marked as solved
3 Replies
1.9k Views
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" } ] }%
Posted
by stefguy.
Last updated
.
Post not yet marked as solved
1 Replies
218 Views
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 .
Posted
by temp4app.
Last updated
.
Post not yet marked as solved
3 Replies
474 Views
I get the following errors when running the code below in a sandboxed app (it works when not sandboxed) and I have the com.apple.security.device.usb entitlement enabled. Error:Unable to open io_service_t object and create user client. with reason: IOServiceOpen failed. Error Domain=IOUSBHostErrorDomain Code=-536870174 "Failed to create IOUSBHostObject." UserInfo={NSLocalizedRecoverySuggestion=, NSLocalizedDescription=Failed to create IOUSBHostObject., NSLocalizedFailureReason=IOServiceOpen failed.} import Foundation import IOKit import IOKit.usb import IOKit.usb.IOUSBLib import IOKit.serial import IOUSBHost import IOUSBHost.IOUSBHostInterface class USBService {     enum UsbError: Error {         case noDeviceMatched         case deviceCriteriaNotUnique     }          init() {              }          func getDevice(idVendor: Int?, idProduct: Int?) throws {         let deviceSearchPattern: [IOUSBHostMatchingPropertyKey : Int] = [                    .vendorID : idVendor!,                    .productID : idProduct!,                ]                let deviceDomain = [ "IOProviderClass": "IOUSBHostDevice" ]                let searchRequest = (deviceSearchPattern as NSDictionary).mutableCopy() as! NSMutableDictionary                searchRequest.addEntries(from: deviceDomain)         let service = IOServiceGetMatchingService(kIOMasterPortDefault, searchRequest)         guard service != 0 else {                    throw UsbError.noDeviceMatched         }                       let device = try IOUSBHostDevice.init(__ioService: service, options: [], queue: nil, interestHandler: nil)                  print(device.deviceDescriptor?.pointee.idProduct)     } }
Posted Last updated
.
Post not yet marked as solved
1 Replies
405 Views
I read the doc of installing system extensions https://developer.apple.com/documentation/systemextensions/installing_system_extensions_and_drivers?language=objc , but actually our product is a framework and installed by .pkg. I/O Kit kext is installed by script in .pkg. So I meet a problem :how to install DriverKit dext by script?
Posted Last updated
.
Post not yet marked as solved
1 Replies
253 Views
we are developing USB hid library to interact with HID device, however we're facing on memory lacking when we calling IOCreatePlugInInterfaceForService then calling IODestroyPlugInInterface, the memory is not released and each time of calling it take about 0.3 MB Ram, after long time running, the program crash because runout of memory. what should we do in this case to avoid memory leak? // Create a device interface/HANDLE static BOOL CreateHidDeviceInterface(io_object_t deviceObject, HANDLE* pHandle) { BOOL retVal = FALSE; IOCFPlugInInterface** ppPluginInterface = NULL; SInt32 score = 0; IOReturn pluginResult; HRESULT interfaceResult; // Create a plugin so we can create an interface pluginResult = IOCreatePlugInInterfaceForService(deviceObject, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &ppPluginInterface, &score); if (pluginResult == kIOReturnSuccess) { // Create the interface (HANDLE) interfaceResult = (*ppPluginInterface)->QueryInterface(ppPluginInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void**)pHandle); if (interfaceResult == S_OK) { retVal = TRUE; } IODestroyPlugInInterface(ppPluginInterface); } return retVal; }
Posted Last updated
.
Post not yet marked as solved
1 Replies
280 Views
Hey there, I'm freelancer on electronic circuits designer, and on my current project I want to design a hub that connects to iPhone and works as: 1. lightning to 3.5mm headphone jack, 2. a button to send a simple data as HID to iPhone and 3. has a lightning female port that enables to connection to charger to charge iPhone. The company needs just a few of this device (actually 50) just for they're and they're few VIP costumers use. I'm designing this gadget for iOS and Android devices. I don't have problem with USB and USB-c, but I there is some ambiguity. I searched web and Also Apple MFi program FAQ, I have some questions: What kind of hardware-based considerations I should have in comparison to USB-c? What is standards and protocols of data transfer of lightning port? Is it similar to USB interface? Is USB hub controller ICs work on lightning as well as USB-c? What is accessory identification chip? What is it's datasheet? Were and how to buy it? For this amount of production (something about 50), is there necessary to get MFi certificate? Is there a datasheet of accessory identification chip for me to complete the design and then enrolling to MFi program? Thanks, Hamidreza Hassanvand
Posted Last updated
.
Post marked as solved
1 Replies
343 Views
Hi there forum, I picked up an old Opensource project from github which is a driver for the Xbox 360 controller. I was going through and hoping to update the repo/build for Apple Silicon and learn some macOS Kernel driver dev along the way. I have been scouring the Apple IOKit documentation archive making my 1/4 through the IOKit doc archive, but, currently, I have an issue with the header search paths. I need to import IOKit/usb/IOUSBLib.h as it contains the symbols utilised by the driver, and it appears that by default Xcode does not use the IOKit Frameworkheaders, but Kernel.framework headers (if I search for definition of symbols that can be found, Xcode opens the Kernel.Framework IOKit path.). Any idea how I can add the user-space IOKit to my driver? I saw that there's the kernel/kernlib, kernel/IOKit, and just IOKit. But a bit lost why this header file is not in the search path. Thanks in advance, If you're curious the code is here: https://github.com/VariableDeclared/360Controller/tree/pj/update-source-for-macos-12.0 Peter
Posted
by PJDS.
Last updated
.