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

Posts under IOKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

Interaction between iPhone and Mac/PC via USB - How?
I'm interested in exploring the idea of connecting an iPhone to a Mac/PC. The initial idea is to allow a computer to access/use the iPhones camera and microphone, but I guess I would also be interested in knowing more about how the communication between an iPhone and Mac/PC could work in a general sense too. There are many posts talking about an iPhone integrating with external hardware devices and MFI is mentioned as well as Redpark cables - but I'm not sure if these same things apply when working with a Mac/PC. So, some questions: What protocols, technologies or frameworks would I use send audio and video from an iPhone and a Mac using a USB cable (if the type of cable matters or makes a difference (ie USB-C vs USB-A), please call it out - but I think it's very likely the type of cable wouldn't make any difference) What protocols, technologies or frameworks would I use to send commands from a Mac to the iPhone using USB so that it can be handled by the iOS app It appears that developers are not able to send raw USB protocol/messages/packets unless the developer is a part of MFI, is that correct? Is there another way to achieve this communication? E.g. with some type of "middle-man" (ie a Redpark cable? some other device?) I've seen iOS applications that turn your phone into a webcam (they usually offer connectivity over USB and over the network (NDI)) - these applications require additional downloads on the Mac/PC. My assumption is that the iOS application is sending messages/packets to the Mac/PC application, and the Mac/PC application is then handling all the work to expose that video/auidio stream as a "camera" device to the system. Would this be the only way to achieve this functionality? Could you expose an iOS application as a camera to a Mac (ignoring PC for now) in a native way, so that it would work the same way it does when you plug in a webcam? Is this possible with MFI alone, or is this possible with a third party device (cable/hardware) in between the iPhone and Mac?
14
0
7.4k
May ’23
Release ExclusiveAccess to an usb device taken by another application?
Seems like both Dropbox and Google Drive has a pretty sad implementation/bug that acquire exclusive access to USB devices that expose MTP (media transfer protocol). The way google and dropbox did it is just wrong as they 1) should ask for permission for reading data on new devices, 2) not open the usb device in exclusive mode... 3) make use of MTP's Multi-Session mode. Well, as it will take them about 4.5 years to correct this, I wonder if there is a way for a app-store/user-space application in macOS 11/12/13 (big sur, monterey, ventura) to do the following: Detect if there is another app that has exclusive lock to a specific usb device Get the name of the app so that an alert could say, "please quit google-drive for this to work..." Release the exclusive lock, i.e. hand over the usb peripheral to my application
0
0
1.4k
Apr ’23
In macOS 13.1, how to communicate with USB billboard device
In macOS 13.1 environment, all IOUSBDevice devices in the current system can be found via the IOServiceAddMatchingNotification function. In the registered callback function, properties such as idVendor, idProduct, and locationID of the device can be read. However, when calling the IOCreatePlugInInterfaceForService function, for USB HID and USB HID devices, a successful status of 0x00000000(kIOReturnSuccess) is returned, but for usb billboard device(type-c ,only have control pipe), an error of 0xe00002be(kIOReturnNoResources) is always returned. Thanks a lot !
1
0
1.7k
Apr ’23
Cannot retrieve the information from iPad device
I am working on an iOS application for internal corporate iPad usage, and I am facing some challenges in getting certain device information programmatically. I was hoping someone could provide me with some guidance or advice on the following coding topics: How can I obtain the "Cellular Data and WiFi Signal Strength" in iPad programmatically, since there is no Apple API provided for this purpose? What is the method to retrieve the "Cellular Network Provider Name" in iPad programmatically after iOS 16 as CTCarrier is deprecated ? Is there a way to obtain the "Monthly Cellular Network Usage" in iPad programmatically, considering that the Network usage count keeps resetting on restart? How can I obtain the "Battery Health Status" in iPad programmatically, since no Apple API is provided for this purpose? Any help or suggestions on these topics would be greatly appreciated. Thank you in advance for your assistance.
1
0
787
Apr ’23
macos 13.3 get usb hid device, interface is 0, is not right
when I upgrade my mac os to version 13.3. I found the usb device interface number is always 0(error ,the right is non-0) when I use kUSBInterfaceNumber from hidapi library(https://github.com/libusb/hidapi). is anyone cause this problem .who can help me. thank you . static int32_t get_int_property(IOHIDDeviceRef device, CFStringRef key) { CFTypeRef ref; int32_t value; ref = IOHIDDeviceGetProperty(device, key); if (ref) { if (CFGetTypeID(ref) == CFNumberGetTypeID()) { CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, &value); return value; } else { printf("\nCFGetTypeID not equal!\n"); } } else { printf("\nref=%p\n",ref); } return 0; } cur_dev->interface_number = get_int_property(dev, CFSTR(kUSBInterfaceNumber));
1
3
1.6k
Apr ’23
Command line IOUserClient: C++, MacOS
Hi colleagues, I am trying to learn macOS kext programming. After some researches I've made a very simple IOKit kext which works. Now I want to try to make a command line client that could communicate with this kext. I created a new project in XCode as a C++ "Command Line Tool" and "HelloWorld" example compiles and builds fine. But, when I add #include <IOKit/IOLib.h>, I immediately got an error "File not found". I have added IOKit.framework to the "Frameworks and Libraries" but have no idea what to do next. Please help. I'd also appreciate any links with examples and/or documentation about how to make a simple kext and client for it. Thank you
1
0
1.2k
Mar ’23
Capturing USB traffic
Hi, I want to capture the USB traffic for my app running on High Sierra. I brought the if XHC20 up and can capture the traffic using Wireshark nightly builds. But I only see incoming traffic (from device to host) but not the other direction. Any ideas what is going wrong here?Starting the IF:&gt; sudo ifconfig XHC20 upAfter that I can select the IF in Wireshark and start capturing packets. I can see incoming traffic from attached devices but not the outbound messages.
8
0
15k
Mar ’23
Correct way to read out information about current energy usage battery&charger/adapter
I'm looking for a way to read out the current energy drain of various macOS devices that should be backwards compatible at least to macOS 12. So far I already had a couple of good idea – well initially I thought so – to get that data from ioreg or IOKit, reading out AppleSmartBattery object. I'm trying to write a small program in Rust that collects the energy usage of our companies macOS devices and record this how much happened while in the office and how much on the road. Therefore I need to consider cases where the battery is charging as well as the battery is full and energy is drawn from the power adapter or usb-c connected display directly via PD. So far I was able to read the desired data out via ioreg with plist output and parse the information into a struct. The issue I have testing this out that my 1st approach of going for PowerTelemetryData which would be perfect is only available on macOS 13+ systems. The second approach reading out the subobjects of BatterData and PowerOutDetails seem to only be available on macOS 12 devices now and then. Any suggestions or hints?
1
0
1.2k
Feb ’23
stop charging while plugged in
Is it possible to change the internal operating system of apple's charging methods? So if I want to make an app or some code to make a MacBook stop charging at a certain percentage while it's still plugged in and then let the battery drain until 20%, it automatically starts charging again to 80%. All while it's plugged in. Does apple allow this? to make something like this?
2
0
1.2k
Feb ’23
Reading EDID data on Apple M1 devices
Is there any way to read EDID data in new Apple M1 devices since the below code snippet does not work in M1 machines however it works in Intel based Mac. io_object_t object = -1;       io_iterator_t iterator;     CFMutableDictionaryRef matching = IOServiceMatching("IODisplayConnect");     kern_return_t kernResult = IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &amp;amp;iterator);       if (KERN_SUCCESS == kernResult &amp;amp;&amp;amp; iterator != 0) {           object = IOIteratorNext(iterator);           while (object != 0) {               CFDictionaryRef dict = IODisplayCreateInfoDictionary(object, kIODisplayOnlyPreferredName);       /*        process data here        */               object = IOIteratorNext(iterator);     }     IOObjectRelease(iterator);   } Also tried replacing "IODisplayConnect" by "IODPDevice" but still get an empty iterator.
5
0
5.7k
Feb ’23
Improving battery reading when the machine wakes.
I am using the CFProperty "AppleRawCurrentCapacity" value from IOServiceGetMathcingService( kIOMainPortDefault, IOServiceMatching( "AppleSmartBattery" ) ) to obtain the mAh value of the MacBook's battery. Once when the app receives the NSWorkspace notification of display sleep, and once again when receiving the NSWorkspace notification of display wake. I then calculate how much battery was expended during sleep by deducting the pre value from post value. The results can wildly vary, from it using 16 mAh per hour, to gaining 10 mAh an hour (without being plugged in). Sometimes a 10 hour sleep doesn't use any mAh... Which is clearly wrong. When my app detects the key kIOPMPSInvalidWakeSecondsKey is present, I set a timer for that period + 3 seconds and attempt to read the battery values again. Yet the results can still wildly vary. I see on Intel Macs there is a kIOPMPSMaxErrKey (set to 9 on a 2019 16"), however I don't see this on M1, and don't know how it can help, if it does exist. Can anyone give me any pointers as to what I am doing wrong, or in the direction of obtaining reliable mAh values? I like mAh as it's more precise that the standard integer values of 0 - 100, but I don't have to stick with mAh, I'd just don't like reporting that a 16 hour sleep didn't use any battery, when I know it's not true. Thanks
1
0
1.4k
Jan ’23
iPad 10th Gen and IOKitLib/IOHIDManager
I'm creating an iPad room information app which needs to communicate over USB with an LED light strip. The USB controller is HID class, vendor ID is 0x20a0 and product ID is 0x41e5. It requires sending a simple feature report to control the LEDs. I've got it working on the Mac using IOKit, and compiling on the 10th gen USB C iPad using copied headers and bridging IOKitLib and IOHIDManager, but sandboxing prevents the code executing on the iPad (IOServiceOpen failed: 0xe00002e2). Is joining the MFi program really the only way to get this to get the necessary entitlements? At our current scale, we don't need to distribute in the App Store.
0
0
1.7k
Jan ’23
Querying for electronics relevant information of my MacBook via native code
Howdy! I have been experimenting with my system's electronics (MacBook Pro 13-inch, M1, 2020) by using software probe written in C/C++ type program. The idea is to extract the relevant information just like it is presented in Apple > About This Mac > System Report, for my cross-platform Engine. I have been tinkering with a tool dmidecode. It works just fine on Linux and Windows. For MacOS, I need to find a graceful way of obtaining the AppleSMBIOS service, in this context. To my best of knowledge, the service is nonexistent as I have checked by C code and some application named IORegistryExplorer (courtesy Google). Just wondering if someone has been on such endurance and how much satisfaction has been achieved upon the topic. Thanks a lot!
9
0
2.1k
Jan ’23
USB device ID
I am new to Mac and got a question. Got a third party USB device and its old library source which has the device old Vendor ID. The device with new Vendor ID is not compatible with old library. So change the Vendor ID in the old source, rebuild it, and use the lib?. Can I use the device in a new Mac?.
3
1
5.6k
Jan ’23
Issues with MSI(x) handling
I've a basic IOPCIDevice driver for a custom device that supports MSI(x). The interrupt filter doesn't get called if I passthe msi index to the IOFilterInterruptEventSource. That's a first problem.The filter is continously called if I don't pass the msi index. That's a 2nd problem.Interrupt was triggered when I initialized the device. In the filter I cleared the cause register. For some reasonintr mask register was already cleared when the filter is called which is another problem.Any clues/pointers?
3
0
2.0k
Dec ’22
How can I use USBmakebmRequestType with DriverKit
I'm building a driver in C++ for my iPad using DriverKit. I'm trying to make a request to a control endpoint, so I'm trying to use DeviceRequest: https://developer.apple.com/documentation/usbdriverkit/iousbhostinterface/3182582-devicerequest But the first parameter ask for USBmakebmRequestType which it's a macro defined in IOKit > USB.h I tried to #include <IOKit/USB.h> and #include <IOKit/usb/USB.h> and  but it doesn't find the header. Any idea? thanks.
1
0
1.9k
Dec ’22
Different Drivers for Individual Interfaces
Hello We have a USB camera. My Mac can recognize it and we can get frames with any software. There is a physical button on it and the vendor says the camera is UVC-compliant. But button doesn't work anyway. I captured some USB traffic data and saw that it has two interfaces. One for streaming and other one for interrupting (like button click). I read UVC 1.5 standards to understand it and it is working like written in UVC 1.5. So, I can get a data with an interrupt transfer when clicking the button. I checked these two interfaces, they use UVCAssistant for driver(System Extension). I tried to use libusb, I can get data from button click. But for frames I had to use libuvc, but it wasn't work for my camera (I think it is related with USB descriptor parsing in libuvc). I thought that I should write a driver for single interface and so second interface will use same UVC assistant driver and first interface will use my driver. I wrote a driver and it matches with first interface. But second interface is empty (unhandled by any driver). I want to load UVCAssistant for second interface of USB port. How can I do this? Output before loading my driver After loading: IOKitPersonalities that I used:
2
0
2.1k
Dec ’22
IOKit or IOUSBHost for USB device acces from user space
USB-Devices without macOS support Every so often I find usefull USB consumer hardware without any macOS support. At best accompanied with some sample code aimed at Linux using libUSB and/or a datasheet [1]. Using code snippets from long since archived IOKit documentation I can deal with that. IOUSBHost Using working IOKit based ObjC Foundation command-line code[2] as reference I am attempting to use theIOUSBHost framework (ObjC Foundation tool). IOUSBHost documentation[3] has all the ingredients but lacks a recipy. Starting with a plugged-in USBDevice and using its idVendor and idProduct[4] I can initialize and destroy base class IOUSBObject and get notified when I unplug the USBDevice. initialize and destroy IOUSBHostDevice[5] and retrieve various descriptors [6] and configure with value: 0, and even do a vendor bmRequestType request without error. But since I already beforehand know the content of my descriptors I can start with IOUSBHostInterface?[7] , needed for my 3 pipes, interrupt, bulk in and out. But Error:Unable to open io_service_t object and create user client. with reason: Exclusive open of usb object failed, whether I asked for exclusive access or not. So I could do with some guidance on how to use IOUSBHost[8]. Let Any Pointer bring joy. Using: Apple M1 Max, MacOS 13.0.1 (22A400), Xcode 14.1 (14B47b) Alternatives considered: Raspberry Pi using UDP (JSON;) over wifi. [1] e.g. https://www.digchip.com/datasheets/parts/datasheet/280/DS2490-pdf.php [2] depending on usage this might need a runloop [3] including dec 2022 https://www.usb.org/sites/default/files/usb_32_202206.zip I failed to find the phrase 'Host-mode'. HINT start by inspecting chapter 9 to get a taste of the terms like function, class, address and value and number. Those wordings will also appear in Apple's documentation. NOTE Tables in chapter 9: Assuming D[n]: stands for bitNr[n] in a bitmap where D[0] is the least significant bit. USEFULL No. [4] use the IORegistryExplorer.app and/or ioreg in Terminal [5] IOUSBHostInterface.h tells me: CFMutableDictionaryRef to be used with IOService matching methods. To be released by caller. But as far a I know CFFoundation is now under ARC. [6] IOUSBInterfaceDescriptor * next = IOUSBGetNextInterfaceDescriptor(configurationDescriptor, nil); while (next != nil) // needs cast (IOUSBDescriptorHeader *)next [7] signed to run locally [8] My next step would be using Swift. Off topic but related and disturbing in a type safe world https://forums.swift.org/t/nsdata-data-vs-data-withunsafebytes/50231/5 Please please please never use NSData.bytes in Swift code. Is this why IOUSBHostObject ioDataWithCapacity uses NSMutableData? Quote: Because the kernel backs the NSMutableData object, the length and capacity aren’t mutable. Any changes to the length or capacity throws an exception. Effectively treating NSMutableData as NSData, only the compiler complains beforehand when an attempt is made to modify the length of NSData (data.bytes ARE mutable)
0
1
2.3k
Dec ’22
How do I invert the luminosity of the display using a color matrix or something else?
I recently came across a program that used data tables to invert the display, however it was a windows only application and I am wondering how I can write a similar thing for Mac, or if there is one already available. The app and config file is attached below so you can sort of dissect how it works Config File: [negativescreen.conf](https://developer.apple.com/forums/content/attachment/f4b67ed7-fa71-4ee6-9c0d-18febe2c3381) Readme file: [README.md](https://developer.apple.com/forums/content/attachment/86bd72f6-46c9-42d5-a925-561f75f24ae8) Window$ Executable: [NegativeScreen.exe](https://developer.apple.com/forums/content/attachment/a4478bd5-d5c7-41dd-9302-0e1a929372c2)
0
0
1.9k
Dec ’22
Interaction between iPhone and Mac/PC via USB - How?
I'm interested in exploring the idea of connecting an iPhone to a Mac/PC. The initial idea is to allow a computer to access/use the iPhones camera and microphone, but I guess I would also be interested in knowing more about how the communication between an iPhone and Mac/PC could work in a general sense too. There are many posts talking about an iPhone integrating with external hardware devices and MFI is mentioned as well as Redpark cables - but I'm not sure if these same things apply when working with a Mac/PC. So, some questions: What protocols, technologies or frameworks would I use send audio and video from an iPhone and a Mac using a USB cable (if the type of cable matters or makes a difference (ie USB-C vs USB-A), please call it out - but I think it's very likely the type of cable wouldn't make any difference) What protocols, technologies or frameworks would I use to send commands from a Mac to the iPhone using USB so that it can be handled by the iOS app It appears that developers are not able to send raw USB protocol/messages/packets unless the developer is a part of MFI, is that correct? Is there another way to achieve this communication? E.g. with some type of "middle-man" (ie a Redpark cable? some other device?) I've seen iOS applications that turn your phone into a webcam (they usually offer connectivity over USB and over the network (NDI)) - these applications require additional downloads on the Mac/PC. My assumption is that the iOS application is sending messages/packets to the Mac/PC application, and the Mac/PC application is then handling all the work to expose that video/auidio stream as a "camera" device to the system. Would this be the only way to achieve this functionality? Could you expose an iOS application as a camera to a Mac (ignoring PC for now) in a native way, so that it would work the same way it does when you plug in a webcam? Is this possible with MFI alone, or is this possible with a third party device (cable/hardware) in between the iPhone and Mac?
Replies
14
Boosts
0
Views
7.4k
Activity
May ’23
Release ExclusiveAccess to an usb device taken by another application?
Seems like both Dropbox and Google Drive has a pretty sad implementation/bug that acquire exclusive access to USB devices that expose MTP (media transfer protocol). The way google and dropbox did it is just wrong as they 1) should ask for permission for reading data on new devices, 2) not open the usb device in exclusive mode... 3) make use of MTP's Multi-Session mode. Well, as it will take them about 4.5 years to correct this, I wonder if there is a way for a app-store/user-space application in macOS 11/12/13 (big sur, monterey, ventura) to do the following: Detect if there is another app that has exclusive lock to a specific usb device Get the name of the app so that an alert could say, "please quit google-drive for this to work..." Release the exclusive lock, i.e. hand over the usb peripheral to my application
Replies
0
Boosts
0
Views
1.4k
Activity
Apr ’23
In macOS 13.1, how to communicate with USB billboard device
In macOS 13.1 environment, all IOUSBDevice devices in the current system can be found via the IOServiceAddMatchingNotification function. In the registered callback function, properties such as idVendor, idProduct, and locationID of the device can be read. However, when calling the IOCreatePlugInInterfaceForService function, for USB HID and USB HID devices, a successful status of 0x00000000(kIOReturnSuccess) is returned, but for usb billboard device(type-c ,only have control pipe), an error of 0xe00002be(kIOReturnNoResources) is always returned. Thanks a lot !
Replies
1
Boosts
0
Views
1.7k
Activity
Apr ’23
Cannot retrieve the information from iPad device
I am working on an iOS application for internal corporate iPad usage, and I am facing some challenges in getting certain device information programmatically. I was hoping someone could provide me with some guidance or advice on the following coding topics: How can I obtain the "Cellular Data and WiFi Signal Strength" in iPad programmatically, since there is no Apple API provided for this purpose? What is the method to retrieve the "Cellular Network Provider Name" in iPad programmatically after iOS 16 as CTCarrier is deprecated ? Is there a way to obtain the "Monthly Cellular Network Usage" in iPad programmatically, considering that the Network usage count keeps resetting on restart? How can I obtain the "Battery Health Status" in iPad programmatically, since no Apple API is provided for this purpose? Any help or suggestions on these topics would be greatly appreciated. Thank you in advance for your assistance.
Replies
1
Boosts
0
Views
787
Activity
Apr ’23
macos 13.3 get usb hid device, interface is 0, is not right
when I upgrade my mac os to version 13.3. I found the usb device interface number is always 0(error ,the right is non-0) when I use kUSBInterfaceNumber from hidapi library(https://github.com/libusb/hidapi). is anyone cause this problem .who can help me. thank you . static int32_t get_int_property(IOHIDDeviceRef device, CFStringRef key) { CFTypeRef ref; int32_t value; ref = IOHIDDeviceGetProperty(device, key); if (ref) { if (CFGetTypeID(ref) == CFNumberGetTypeID()) { CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, &amp;value); return value; } else { printf("\nCFGetTypeID not equal!\n"); } } else { printf("\nref=%p\n",ref); } return 0; } cur_dev-&gt;interface_number = get_int_property(dev, CFSTR(kUSBInterfaceNumber));
Replies
1
Boosts
3
Views
1.6k
Activity
Apr ’23
Command line IOUserClient: C++, MacOS
Hi colleagues, I am trying to learn macOS kext programming. After some researches I've made a very simple IOKit kext which works. Now I want to try to make a command line client that could communicate with this kext. I created a new project in XCode as a C++ "Command Line Tool" and "HelloWorld" example compiles and builds fine. But, when I add #include <IOKit/IOLib.h>, I immediately got an error "File not found". I have added IOKit.framework to the "Frameworks and Libraries" but have no idea what to do next. Please help. I'd also appreciate any links with examples and/or documentation about how to make a simple kext and client for it. Thank you
Replies
1
Boosts
0
Views
1.2k
Activity
Mar ’23
Capturing USB traffic
Hi, I want to capture the USB traffic for my app running on High Sierra. I brought the if XHC20 up and can capture the traffic using Wireshark nightly builds. But I only see incoming traffic (from device to host) but not the other direction. Any ideas what is going wrong here?Starting the IF:&gt; sudo ifconfig XHC20 upAfter that I can select the IF in Wireshark and start capturing packets. I can see incoming traffic from attached devices but not the outbound messages.
Replies
8
Boosts
0
Views
15k
Activity
Mar ’23
Correct way to read out information about current energy usage battery&charger/adapter
I'm looking for a way to read out the current energy drain of various macOS devices that should be backwards compatible at least to macOS 12. So far I already had a couple of good idea – well initially I thought so – to get that data from ioreg or IOKit, reading out AppleSmartBattery object. I'm trying to write a small program in Rust that collects the energy usage of our companies macOS devices and record this how much happened while in the office and how much on the road. Therefore I need to consider cases where the battery is charging as well as the battery is full and energy is drawn from the power adapter or usb-c connected display directly via PD. So far I was able to read the desired data out via ioreg with plist output and parse the information into a struct. The issue I have testing this out that my 1st approach of going for PowerTelemetryData which would be perfect is only available on macOS 13+ systems. The second approach reading out the subobjects of BatterData and PowerOutDetails seem to only be available on macOS 12 devices now and then. Any suggestions or hints?
Replies
1
Boosts
0
Views
1.2k
Activity
Feb ’23
stop charging while plugged in
Is it possible to change the internal operating system of apple's charging methods? So if I want to make an app or some code to make a MacBook stop charging at a certain percentage while it's still plugged in and then let the battery drain until 20%, it automatically starts charging again to 80%. All while it's plugged in. Does apple allow this? to make something like this?
Replies
2
Boosts
0
Views
1.2k
Activity
Feb ’23
Reading EDID data on Apple M1 devices
Is there any way to read EDID data in new Apple M1 devices since the below code snippet does not work in M1 machines however it works in Intel based Mac. io_object_t object = -1;       io_iterator_t iterator;     CFMutableDictionaryRef matching = IOServiceMatching("IODisplayConnect");     kern_return_t kernResult = IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &amp;amp;iterator);       if (KERN_SUCCESS == kernResult &amp;amp;&amp;amp; iterator != 0) {           object = IOIteratorNext(iterator);           while (object != 0) {               CFDictionaryRef dict = IODisplayCreateInfoDictionary(object, kIODisplayOnlyPreferredName);       /*        process data here        */               object = IOIteratorNext(iterator);     }     IOObjectRelease(iterator);   } Also tried replacing "IODisplayConnect" by "IODPDevice" but still get an empty iterator.
Replies
5
Boosts
0
Views
5.7k
Activity
Feb ’23
Improving battery reading when the machine wakes.
I am using the CFProperty "AppleRawCurrentCapacity" value from IOServiceGetMathcingService( kIOMainPortDefault, IOServiceMatching( "AppleSmartBattery" ) ) to obtain the mAh value of the MacBook's battery. Once when the app receives the NSWorkspace notification of display sleep, and once again when receiving the NSWorkspace notification of display wake. I then calculate how much battery was expended during sleep by deducting the pre value from post value. The results can wildly vary, from it using 16 mAh per hour, to gaining 10 mAh an hour (without being plugged in). Sometimes a 10 hour sleep doesn't use any mAh... Which is clearly wrong. When my app detects the key kIOPMPSInvalidWakeSecondsKey is present, I set a timer for that period + 3 seconds and attempt to read the battery values again. Yet the results can still wildly vary. I see on Intel Macs there is a kIOPMPSMaxErrKey (set to 9 on a 2019 16"), however I don't see this on M1, and don't know how it can help, if it does exist. Can anyone give me any pointers as to what I am doing wrong, or in the direction of obtaining reliable mAh values? I like mAh as it's more precise that the standard integer values of 0 - 100, but I don't have to stick with mAh, I'd just don't like reporting that a 16 hour sleep didn't use any battery, when I know it's not true. Thanks
Replies
1
Boosts
0
Views
1.4k
Activity
Jan ’23
iPad 10th Gen and IOKitLib/IOHIDManager
I'm creating an iPad room information app which needs to communicate over USB with an LED light strip. The USB controller is HID class, vendor ID is 0x20a0 and product ID is 0x41e5. It requires sending a simple feature report to control the LEDs. I've got it working on the Mac using IOKit, and compiling on the 10th gen USB C iPad using copied headers and bridging IOKitLib and IOHIDManager, but sandboxing prevents the code executing on the iPad (IOServiceOpen failed: 0xe00002e2). Is joining the MFi program really the only way to get this to get the necessary entitlements? At our current scale, we don't need to distribute in the App Store.
Replies
0
Boosts
0
Views
1.7k
Activity
Jan ’23
M1 Mac does not support DDC/CI
The DDC/CI application can work well on MacbookPro/Mac Pro (Big Sur), but it doesn't work on M1 Mac (both macOS 11.0.1 and 11.1). M1’s graphics card is Apple, not Intel or AMD. Does this incompatible issue relate with new graphics card or kernel change? Any alternative solution for M1?
Replies
6
Boosts
1
Views
12k
Activity
Jan ’23
Querying for electronics relevant information of my MacBook via native code
Howdy! I have been experimenting with my system's electronics (MacBook Pro 13-inch, M1, 2020) by using software probe written in C/C++ type program. The idea is to extract the relevant information just like it is presented in Apple > About This Mac > System Report, for my cross-platform Engine. I have been tinkering with a tool dmidecode. It works just fine on Linux and Windows. For MacOS, I need to find a graceful way of obtaining the AppleSMBIOS service, in this context. To my best of knowledge, the service is nonexistent as I have checked by C code and some application named IORegistryExplorer (courtesy Google). Just wondering if someone has been on such endurance and how much satisfaction has been achieved upon the topic. Thanks a lot!
Replies
9
Boosts
0
Views
2.1k
Activity
Jan ’23
USB device ID
I am new to Mac and got a question. Got a third party USB device and its old library source which has the device old Vendor ID. The device with new Vendor ID is not compatible with old library. So change the Vendor ID in the old source, rebuild it, and use the lib?. Can I use the device in a new Mac?.
Replies
3
Boosts
1
Views
5.6k
Activity
Jan ’23
Issues with MSI(x) handling
I've a basic IOPCIDevice driver for a custom device that supports MSI(x). The interrupt filter doesn't get called if I passthe msi index to the IOFilterInterruptEventSource. That's a first problem.The filter is continously called if I don't pass the msi index. That's a 2nd problem.Interrupt was triggered when I initialized the device. In the filter I cleared the cause register. For some reasonintr mask register was already cleared when the filter is called which is another problem.Any clues/pointers?
Replies
3
Boosts
0
Views
2.0k
Activity
Dec ’22
How can I use USBmakebmRequestType with DriverKit
I'm building a driver in C++ for my iPad using DriverKit. I'm trying to make a request to a control endpoint, so I'm trying to use DeviceRequest: https://developer.apple.com/documentation/usbdriverkit/iousbhostinterface/3182582-devicerequest But the first parameter ask for USBmakebmRequestType which it's a macro defined in IOKit > USB.h I tried to #include <IOKit/USB.h> and #include <IOKit/usb/USB.h> and  but it doesn't find the header. Any idea? thanks.
Replies
1
Boosts
0
Views
1.9k
Activity
Dec ’22
Different Drivers for Individual Interfaces
Hello We have a USB camera. My Mac can recognize it and we can get frames with any software. There is a physical button on it and the vendor says the camera is UVC-compliant. But button doesn't work anyway. I captured some USB traffic data and saw that it has two interfaces. One for streaming and other one for interrupting (like button click). I read UVC 1.5 standards to understand it and it is working like written in UVC 1.5. So, I can get a data with an interrupt transfer when clicking the button. I checked these two interfaces, they use UVCAssistant for driver(System Extension). I tried to use libusb, I can get data from button click. But for frames I had to use libuvc, but it wasn't work for my camera (I think it is related with USB descriptor parsing in libuvc). I thought that I should write a driver for single interface and so second interface will use same UVC assistant driver and first interface will use my driver. I wrote a driver and it matches with first interface. But second interface is empty (unhandled by any driver). I want to load UVCAssistant for second interface of USB port. How can I do this? Output before loading my driver After loading: IOKitPersonalities that I used:
Replies
2
Boosts
0
Views
2.1k
Activity
Dec ’22
IOKit or IOUSBHost for USB device acces from user space
USB-Devices without macOS support Every so often I find usefull USB consumer hardware without any macOS support. At best accompanied with some sample code aimed at Linux using libUSB and/or a datasheet [1]. Using code snippets from long since archived IOKit documentation I can deal with that. IOUSBHost Using working IOKit based ObjC Foundation command-line code[2] as reference I am attempting to use theIOUSBHost framework (ObjC Foundation tool). IOUSBHost documentation[3] has all the ingredients but lacks a recipy. Starting with a plugged-in USBDevice and using its idVendor and idProduct[4] I can initialize and destroy base class IOUSBObject and get notified when I unplug the USBDevice. initialize and destroy IOUSBHostDevice[5] and retrieve various descriptors [6] and configure with value: 0, and even do a vendor bmRequestType request without error. But since I already beforehand know the content of my descriptors I can start with IOUSBHostInterface?[7] , needed for my 3 pipes, interrupt, bulk in and out. But Error:Unable to open io_service_t object and create user client. with reason: Exclusive open of usb object failed, whether I asked for exclusive access or not. So I could do with some guidance on how to use IOUSBHost[8]. Let Any Pointer bring joy. Using: Apple M1 Max, MacOS 13.0.1 (22A400), Xcode 14.1 (14B47b) Alternatives considered: Raspberry Pi using UDP (JSON;) over wifi. [1] e.g. https://www.digchip.com/datasheets/parts/datasheet/280/DS2490-pdf.php [2] depending on usage this might need a runloop [3] including dec 2022 https://www.usb.org/sites/default/files/usb_32_202206.zip I failed to find the phrase 'Host-mode'. HINT start by inspecting chapter 9 to get a taste of the terms like function, class, address and value and number. Those wordings will also appear in Apple's documentation. NOTE Tables in chapter 9: Assuming D[n]: stands for bitNr[n] in a bitmap where D[0] is the least significant bit. USEFULL No. [4] use the IORegistryExplorer.app and/or ioreg in Terminal [5] IOUSBHostInterface.h tells me: CFMutableDictionaryRef to be used with IOService matching methods. To be released by caller. But as far a I know CFFoundation is now under ARC. [6] IOUSBInterfaceDescriptor * next = IOUSBGetNextInterfaceDescriptor(configurationDescriptor, nil); while (next != nil) // needs cast (IOUSBDescriptorHeader *)next [7] signed to run locally [8] My next step would be using Swift. Off topic but related and disturbing in a type safe world https://forums.swift.org/t/nsdata-data-vs-data-withunsafebytes/50231/5 Please please please never use NSData.bytes in Swift code. Is this why IOUSBHostObject ioDataWithCapacity uses NSMutableData? Quote: Because the kernel backs the NSMutableData object, the length and capacity aren’t mutable. Any changes to the length or capacity throws an exception. Effectively treating NSMutableData as NSData, only the compiler complains beforehand when an attempt is made to modify the length of NSData (data.bytes ARE mutable)
Replies
0
Boosts
1
Views
2.3k
Activity
Dec ’22
How do I invert the luminosity of the display using a color matrix or something else?
I recently came across a program that used data tables to invert the display, however it was a windows only application and I am wondering how I can write a similar thing for Mac, or if there is one already available. The app and config file is attached below so you can sort of dissect how it works Config File: [negativescreen.conf](https://developer.apple.com/forums/content/attachment/f4b67ed7-fa71-4ee6-9c0d-18febe2c3381) Readme file: [README.md](https://developer.apple.com/forums/content/attachment/86bd72f6-46c9-42d5-a925-561f75f24ae8) Window$ Executable: [NegativeScreen.exe](https://developer.apple.com/forums/content/attachment/a4478bd5-d5c7-41dd-9302-0e1a929372c2)
Replies
0
Boosts
0
Views
1.9k
Activity
Dec ’22