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

IOKit Documentation

Posts under IOKit tag

52 Posts
Sort by:
Post not yet marked as solved
3 Replies
2.1k Views
I am working with USB serial devices on macOS.How can I detect BSD(unix) name have for my USB Serial device on macOS using IOKit?I want to get device name like : "IODialinDevice" = "/dev/tty.usbmodemMyDeviceName"My USB device is USB serial COM port.Also I want to detect when device was attached to machine.I can detect when new USB device with my VID and PID was connected.This code allows me to do it CFMutableDictionaryRef keywordDict = IOServiceMatching(kIOSerialBSDServiceValue); kern_return_t result = IOServiceGetMatchingServices(kIOMasterPortDefault, keywordDict, &iterator); while ((port = IOIteratorNext(iterator))) { io_object_t parent = 0; io_object_t current_device = port; while (KERN_SUCCESS == IORegistryEntryGetParentEntry(current_device, kIOServicePlane, &parent)) { CFTypeRef vendor_Id = IORegistryEntryCreateCFProperty(parent, CFSTR(kUSBVendorID), kCFAllocatorDefault, 0); CFTypeRef pr_Id = IORegistryEntryCreateCFProperty(parent, CFSTR(kUSBProductID), kCFAllocatorDefault, 0); if((vendor_id==MY_VENDOR_ID) && (pr_ID==MY_PRODUCT_ID)) { // MY SERIAL DEVICE DETECTED !! CFTypeRef deviceName = IORegistryEntryCreateCFProperty(device, key, CFSTR(kIOTTYDeviceKey), 0); CFTypeRef callOutDevice = IORegistryEntryCreateCFProperty(device, key, CFSTR(kIOCalloutDeviceKey), 0); CFTypeRef dialInDevice = IORegistryEntryCreateCFProperty(device, key, CFSTR(kIODialinDeviceKey), 0); } } }But the problem that this code not allows me to detect the new device.I just enumerate existing kIOSerialBSDServiceValue devices here and then I check parents VID and PIDIf parent have MY_VID and MY_PID I assume that I have found correct serial device.Another code allows me to detect new USB deviceThis is Apple example LUSBPrivateDataSample.cI can detect my device using VID and PID with the following code int main() { ... ... ... // Create a CFNumber for the idVendor and set the value in the dictionary numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbVendor); CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID), numberRef); CFRelease(numberRef); // Create a CFNumber for the idProduct and set the value in the dictionary numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbProduct); CFDictionarySetValue(matchingDict, CFSTR(kUSBProductID), numberRef); CFRelease(numberRef); ... ... ... // Now set up a notification to be called when a device is first matched by I/O Kit. kr = IOServiceAddMatchingNotification(gNotifyPort, // notifyPort kIOFirstMatchNotification, // notificationType matchingDict, // matching DeviceAdded, // callback NULL, // refCon &gAddedIter // notification ); } void DeviceAdded(void *refCon, io_iterator_t iterator) { io_service_t usbDevice; while ((usbDevice = IOIteratorNext(iterator))) { // I have device here but I can't get IODialinDevice device name } }The problem with this code that I can't get IODialinDevice device nameI have also checked all child nodes for this usbDevice.None of them contain IODialinDevice property or none of them is kIOSerialBSDServiceValue device.Looks like I am doing it wrong.Looks like serial devices and USB live in different IOKit registry branches.The question is how can go from USB device identified by VID and PID to serial device (kIOSerialBSDServiceValue) with IODialinDevice ("/dev/tty.usbmodemMyDeviceName") property .This is part of my ioreg tree: I can detect CDC ACM Data device in my application. (top device in this tree)In ioreg I see this picture.So there are children, AppleUSBACMData and IOSerialBSDClient who has IODialinDevice property.But I can't detect AppleUSBACMData and IOSerialBSDClient in my application .Probably because AppleUSBACMData and IOSerialBSDClient are not devices, but USB Interfaces or USB Endpoints.So this is my problem. +-o CDC ACM Data@3 | { | "USBPortType" = 0 | "IOCFPlugInTypes" = {"2d9786c6-9ef3-11d4-ad51-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"} | "Product Name" = "DevName" | "bcdDevice" = 1044 | "USBSpeed" = 3 | "idProduct" = 260 | "bConfigurationValue" = 1 | "bInterfaceSubClass" = 0 | "locationID" = 338886656 | "IOGeneralInterest" = "IOCommand is not serializable" | "IOServiceLegacyMatchingRegistryID" = 4295561221 | "IOClassNameOverride" = "IOUSBInterface" | "AppleUSBAlternateServiceRegistryID" = 4295561221 | "idVendor" = 7777 | "bInterfaceProtocol" = 0 | "bAlternateSetting" = 0 | "bInterfaceNumber" = 3 | "bInterfaceClass" = 10 | } | +-o AppleUSBACMData | { | "IOClass" = "AppleUSBACMData" | "CFBundleIdentifier" = "com.apple.driver.usb.cdc.acm" | "IOProviderClass" = "IOUSBHostInterface" | "IOTTYBaseName" = "usbmodem" | "idProduct" = 260 | "IOProbeScore" = 49999 | "bInterfaceSubClass" = 0 | "HiddenPort" = Yes | "IOMatchCategory" = "IODefaultMatchCategory" | "idVendor" = 7777 | "IOTTYSuffix" = "DevName_B3" | "bInterfaceClass" = 10 | } | +-o IOSerialBSDClient { "IOClass" = "IOSerialBSDClient" "CFBundleIdentifier" = "com.apple.iokit.IOSerialFamily" "IOProviderClass" = "IOSerialStreamSync" "IOTTYBaseName" = "usbmodem" "IOSerialBSDClientType" = "IORS232SerialStream" "IOProbeScore" = 1000 "IOCalloutDevice" = "/dev/cu.usbmodemDevName_B3" "IODialinDevice" = "/dev/tty.usbmodemDevName_B3" "IOMatchCategory" = "IODefaultMatchCategory" "IOTTYDevice" = "usbmodemDevName_B3" "IOResourceMatch" = "IOBSD" "IOTTYSuffix" = "DevName_B3" }Any help appreciated!
Posted
by vlad2010.
Last updated
.
Post marked as solved
1 Replies
245 Views
I have a digital multimeter that logs data to computer through USB serial. After upgrade to Big Sur it suddenly stopped working. IOKit properly detects device connect/disconnect and HID reports are coming in, but with no data. HID report contains nothing but zeroes... I'm stuck and in need of help. Have anything changed in IOKit.hid interface between 10.15 and 11?
Posted
by ejeklint.
Last updated
.
Post not yet marked as solved
2 Replies
522 Views
I have a driver that was written with IOKit. It works fine on BigSur with an Intel Processor. It is compiled as a universal binary. Each time I try to use kextload to load the kext, the machine crashes with the following.... panic(cpu 5 caller 0xfffffe001e0b9320): Break 0xC470 instruction exception from kernel. Ptrauth failure with IA key resulted in 0xbffffe001cbc0630 at pc 0xfffffe001df2a5d4, lr 0x0addfe001df2a548 (saved state: 0xfffffe306b8c34e0)  x0: 0xfffffe306b8c3860 x1: 0x0000000000000000 x2: 0x0000000000000000 x3: 0xfffffe306b8c3890  x4: 0x0000000000000000 x5: 0x0000000000000000 x6: 0x00626778632e7265 x7: 0x0000000000000d80  x8: 0x000000000000000c x9: 0xfffffe0020892df8 x10: 0x00000000016a016a x11: 0x0000000000000001  x12: 0x00000000016a016a x13: 0x000000000000016a x14: 0xfffffe16669f5448 x15: 0x00000000016a016b  x16: 0xbffffe001cbc0630 x17: 0xfffffe001cbc0630 x18: 0x0000000000000000 x19: 0xfffffe233197ee60  x20: 0x0000000000000001 x21: 0x0000000000000001 x22: 0x8a8afe001cbc0630 x23: 0xfffffe001cb90000  x24: 0xfffffe001d88d971 x25: 0xfffffe001cb88000 x26: 0x0000000000000006 x27: 0x0000000000000006  x28: 0xcda1fe233197ee60 fp: 0xfffffe306b8c38f0 lr: 0x0addfe001df2a548 sp: 0xfffffe306b8c3830  pc: 0xfffffe001df2a5d4 cpsr: 0x80401208    esr: 0xf200c470     far: 0xfffffe30193c4000 Debugger message: panic Memory ID: 0x6 OS release type: User OS version: 20G80 Kernel version: Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:27 PDT 2021; root:xnu-7195.141.2~5/RELEASE_ARM64_T8101 Fileset Kernelcache UUID: E46841F89DC3FD7ACEC6F404AC995579 Kernel UUID: AC4A14A7-8A8E-3AE6-85A6-55E6B2502BF9 iBoot version: iBoot-6723.140.2 secure boot?: YES Paniclog version: 13 KernelCache slide: 0x0000000015c9c000 KernelCache base: 0xfffffe001cca0000 Kernel slide:   0x00000000167e4000 Kernel text base: 0xfffffe001d7e8000 Kernel text exec base: 0xfffffe001d8b4000 mach_absolute_time: 0xc434196c Epoch Time:    sec   usec  Boot  : 0x610c5768 0x00000e2f  Sleep : 0x00000000 0x00000000  Wake  : 0x00000000 0x00000000  Calendar: 0x610c57eb 0x000ebce6 CORE 0 recently retired instr at 0xfffffe001da26d6c CORE 1 recently retired instr at 0xfffffe001da26d6c CORE 2 recently retired instr at 0xfffffe001da26d6c CORE 3 recently retired instr at 0xfffffe001da26d6c CORE 4 recently retired instr at 0xfffffe001da26d70 CORE 5 recently retired instr at 0xfffffe001da256a4 CORE 6 recently retired instr at 0xfffffe001da26d70 CORE 7 recently retired instr at 0xfffffe001da26d70 CORE 0 PVH locks held: None CORE 1 PVH locks held: None CORE 2 PVH locks held: None CORE 3 PVH locks held: None CORE 4 PVH locks held: None CORE 5 PVH locks held: None CORE 6 PVH locks held: None CORE 7 PVH locks held: None CORE 0: PC=0xfffffe00205f0ff0, LR=0xfffffe00205c3c10, FP=0xfffffe3097d5b440 CORE 1: PC=0xfffffe001da1cadc, LR=0xfffffe001db463c4, FP=0xfffffe3097e3b690 CORE 2: PC=0xfffffe001d92da64, LR=0xfffffe001d92da5c, FP=0xfffffe309978bee0 CORE 3: PC=0xfffffe001d92da64, LR=0xfffffe001d92da5c, FP=0xfffffe3097d3bee0 CORE 4: PC=0xfffffe001d92da64, LR=0xfffffe001d92da5c, FP=0xfffffe3097e2bee0 CORE 5 is the one that panicked. Check the full backtrace for details. CORE 6: PC=0xfffffe001d92da64, LR=0xfffffe001d92da5c, FP=0xfffffe3097e1bee0 CORE 7: PC=0xfffffe001d92da64, LR=0xfffffe001d92da5c, FP=0xfffffe3097a2bee0 Panicked task 0xfffffe1667fe1b70: 1825 pages, 3 threads: pid 101: kernelmanagerd Panicked thread: 0xfffffe166a254000, backtrace: 0xfffffe306b8c2bf0, tid: 11112  lr: 0xfffffe001d902b68 fp: 0xfffffe306b8c2c60  lr: 0xfffffe001d90294c fp: 0xfffffe306b8c2cd0  lr: 0xfffffe001da2c1c8 fp: 0xfffffe306b8c2cf0  lr: 0xfffffe001da1d674 fp: 0xfffffe306b8c2da0  lr: 0xfffffe001d8bb7e8 fp: 0xfffffe306b8c2db0  lr: 0xfffffe001d9025dc fp: 0xfffffe306b8c3140  lr: 0xfffffe001d9025dc fp: 0xfffffe306b8c31b0  lr: 0xfffffe001e0b4e80 fp: 0xfffffe306b8c31d0  lr: 0xfffffe001e0b9320 fp: 0xfffffe306b8c3340  lr: 0xfffffe001da1fa50 fp: 0xfffffe306b8c3410  lr: 0xfffffe001da1d9b8 fp: 0xfffffe306b8c34c0  lr: 0xfffffe001d8bb7e8 fp: 0xfffffe306b8c34d0  lr: 0xfffffe001df2a548 fp: 0xfffffe306b8c38f0  lr: 0xfffffe001df2b898 fp: 0xfffffe306b8c3970  lr: 0xfffffe001df30d14 fp: 0xfffffe306b8c39f0  lr: 0xfffffe001df3eaf4 fp: 0xfffffe306b8c3a50  lr: 0xfffffe001df41650 fp: 0xfffffe306b8c3af0  lr: 0xfffffe001df5ce24 fp: 0xfffffe306b8c3b80  lr: 0xfffffe001d967e0c fp: 0xfffffe306b8c3bd0  lr: 0xfffffe001d9082b0 fp: 0xfffffe306b8c3c40  lr: 0xfffffe001d8df960 fp: 0xfffffe306b8c3cc0  lr: 0xfffffe001d8f86f8 fp: 0xfffffe306b8c3d70  lr: 0xfffffe001da11ffc fp: 0xfffffe306b8c3e40  lr: 0xfffffe001da1d6f0 fp: 0xfffffe306b8c3ef0  lr: 0xfffffe001d8bb7e8 fp: 0xfffffe306b8c3f00 last started kext is my kext, which makes sense. Anyone seen this before and been successful in debugging it? Thanks
Posted
by TomReu.
Last updated
.
Post not yet marked as solved
1 Replies
363 Views
iOS version is14.2.1(18B121) dyld: Library not loaded: /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit  Referenced from: /private/var/containers/Bundle/Application/27933966-3944-4FF9-907F-2C69CE0EDA4E/.app/  Reason: image not found dyld: launch, loading dependent libraries DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/Developer/Library/PrivateFrameworks/GPUTools.framework/libglInterpose.dylib:/usr/lib/libMTLCapture.dylib
Posted
by yujieiii.
Last updated
.
Post not yet marked as solved
1 Replies
575 Views
Hi, i am working on a swift package library that gets information about all the disks connected to the mac and displays it organised into a tree structure, including the non-mounted storage devices attached to the machine. My question is how can i get informations about unmounted devices like: The amount of free space (when possible) of a partition or an APFS container The space occupied by a single APFS volume I am already using a combination of IOKit and Disk Arbitration for my library and i don't see this information anywhere in those frameworks, including the description dictionaries provided by Disk Arbitration. Instead the terminal command diskutil info -plist [volume/partition BSD name here] gives me this info, but i can't just use it's output in my swift program (and obtaining it via a process object for example) since it doesn't work with the app sandbox, so i am looking for a sandbox-friendly way using just the API. I hope you can help me figure this out, really any help is appreciated, thank you for your attention.
Posted Last updated
.
Post not yet marked as solved
1 Replies
503 Views
Hi, i have made some code in Swift that allows me to get a list of the storage disks and the relative partitions present in a mac (everything made using the IOKit api), this of course includes the APFS containers that are managed by the OS as separate storage devices. To have a proper representation of the partitions tree in my code i need to know which are the actual partitions housing a given APFS container. I have tried to look for this information on documentation and on the internet, then into the IORegistry (using the registry explorer app) and searching for this info into the description dictionaries provided by Disk arbitration but so far no luck, even by comparing the UUIDs. In IORegistry explorer in the IOService plane I can also see that the APFS Container in my mac's ssd is listed as a sub-node of it's physical storage a partition, but since i am using an IOIterator object to scan the IORegistry i have no idea of how i should look into sub-nodes for a given node. Also i think that some particular storage configurations might have an APFS container split across multiple physical storage devices, in fact the diskutil list -plist command shows the physical store for each APFS containers as an array in the plist output, so the child approach might not be effective there. So how can i do this? I am doing all of this stuff because i am working to a sandbox-friendly open source swift package for macOS apps to easily get a complete tree structure of disks and partitions, in a similar fashion to the above mentioned diskutil list -plist command, my goal is actually to have the exact same structure provided by that command, with the same info.
Posted Last updated
.
Post not yet marked as solved
0 Replies
501 Views
I've done extensive reading on this, but I'm still stumped. I'm trying to call USBInterfaceOpen for a USB Device that I need direct read/write access to, but I get an exclusive access error. There seem to be 2 possibilities here: 1) use the HID interface or 2) do a codeless kext to get to the device before OS X's HID Manager does. So possibility 1 is not going to work, it's not recognized as a storage or network device and nothing is created in the /dev tree that would allow standard POSIX calls. And possibility 2 is not going well. Apple seems to have really locked things down, and I get "Bad code signature" errors when loading trying to load my codeless kext (with just a .plist): Authenticating extension failed: Bad code signature" UserInfo={NSLocalizedDescription=Authenticating extension failed: Kext com.blackrock.cerestim v1.0.0 in codeless kext bundle com.blackrock.cerestim at /private/var/db/KernelExtensionManagement/Staging/com.blackrock.cerestim.ohqHdy/Cerestim.kext: I am really stuck. Is there any simple way of preventing an HID takeover of this device?
Posted
by gghose.
Last updated
.
Post not yet marked as solved
2 Replies
921 Views
I want graphics card details using objective c. used IOServiceGetMatchingServices api for it, its working fine in Intel processor machine, but not returning model info for M1 machine. here is the code I was using    CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice");        io_iterator_t iterator;        if (IOServiceGetMatchingServices(kIOMasterPortDefault,matchDict,                    &iterator) == kIOReturnSuccess)   {      io_registry_entry_t regEntry;            while ((regEntry = IOIteratorNext(iterator))) {        CFMutableDictionaryRef serviceDictionary;        if (IORegistryEntryCreateCFProperties(regEntry,                          &serviceDictionary,                           kCFAllocatorDefault,                           kNilOptions) != kIOReturnSuccess)       {          IOObjectRelease(regEntry);          continue;       }        const void *GPUModel = CFDictionaryGetValue(serviceDictionary, @"model");                if (GPUModel != nil) {          if (CFGetTypeID(GPUModel) == CFDataGetTypeID()) {            NSString *modelName = [[NSString alloc] initWithData:                       (NSData *)GPUModel encoding:NSASCIIStringEncoding];                        NSLog(@"GPU Model: %@", modelName);           [modelName release];         }       }        CFRelease(serviceDictionary);        IOObjectRelease(regEntry);     }      IOObjectRelease(iterator);   }
Posted Last updated
.
Post not yet marked as solved
2 Replies
411 Views
is there any cocoa API available using which we can get below details of physical memory? Able to get this data using system_profiler SPMemoryDataType but looking for API instead of command since this command do not return all above data for Apple M1 machine.
Posted Last updated
.
Post not yet marked as solved
1 Replies
525 Views
Is there any native cocoa API available which gives below graphic card details in Intel and Apple M1 machines? Chipset Model,  Type,  Bus,  VRAM (Dynamic, Max),  Vendor,  Device ID,  Revision ID,  Automatic Graphics Switching,  gMux Version,  Metal Family
Posted Last updated
.
Post not yet marked as solved
0 Replies
445 Views
Hi, I would like to update that we have a kext that has IOStorageFamily in OSBundleLibraries. I would like to know whether we can create DriverKit that support this family and embed in SystemExtension for deployment? and we have another kext that has combination of IOStorageFamily and IOUSBFamily in OSBundleLibraries. Please let me know whether such type of Kext can be converted into DriverKit. I am new to DriverKit development. Please let us know if there is any sample that has these bundles in DriverKit so that I can check. Please let us know if such are supported with DriverKit then what are the capabilities that we need to add in entitlement request so that it can get approved. Thanks & Regards, Mohmad Vasim
Posted Last updated
.