I found some nice code that implements a NUT client, and now I want to take the next step -- I would like to get it to show up as a UPS for macOS. But I've never done anything with IOKit... and there don't seem to be a lot of examples of, maybe, IOPowerSources?
Network UPS?
But I've never done anything with IOKit... and there don't seem to be a lot of examples of, maybe, IOPowerSources?
So, trying to do this through IOKit is almost certainly a mistake. Direct KEXT development has largely been closed off for many years and, even when it wasn't, I think most developers avoided trying to directly create "raw" power sources like this.
I haven't looked into the particular case in any detail, but the common issue with directly creating a "higher level" constructs like our power management endpoints is that the larger system is implicitly assuming that they'll be attached to some real hardware of some kind. Typically, that means you're able to get something working fairly quickly, then you end up endlessly chasing down small bugs as you try to "fill out" your implementation to match the system’s undocumented expectations.
That leads to here:
I found some nice code that implements a NUT client, and now I want to take the next step -- I would like to get it to show up as a UPS for macOS.
I believe most products did this sort of thing by publishing a virtual HID device that implemented either Power Page (0x84) and/or Battery System Page (0x85) from the HID Usage Tables spec:
https://usb.org/sites/default/files/hut1_7.pdf
That sidesteps the hardware issue I noted above and, as specs go, HID is relatively easy to understand and implement. Historically (back when this sort of thing was implemented in a KEXT), it also meant that you could use HID commands to manage/control the virtual HID device which was tended to be a bit more "pleasant" than implementing a full user client[1].
In any case, the right way to do this is to use CoreHID to create a virtual device. That lets you write a straightforward app/daemon without any kernel code. FYI, you can also do the same thing (create a virtual HID device) using DriverKit, but that's basically just more work without any advantage.
[1] Even after 26 years, I still have the vague sense that the code doesn't really work every time I look at an IOUserClient implementation.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware
Ha, I didn't mean a kernel-space driver, I was thinking a user-space USB provider of some sort.
Thanks for the pointer, I'll take a read soon! Yay!
Thanks for the pointer, I'll take a read soon! Yay!
You're very welcome and good luck!
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware