macOS: rework list_ports to support unicode product descriptors.

This commit makes some changes to try to improve the behavior of
serial.tools.list_ports on macOS and to reduce the amount of magic
numbers in this code. These changes include a better adherence to iokit
function type declarations as taken from the iokit header files, as
well as switching all iokit calls to use UTF-8 encoding rather than
mac_roman.

The main functional change of this commit is that the devicename is
now retrieved through IORegistryEntryName, which avoids some weird
USB descriptor mangling that happens somewhere deep within the BSD
serial device subsystem in XNU. In particular, on serial devices, all
USB product descriptor characters that are not in the basic
alphanumeric set are replaced with underscores, which is silly as USB
descriptors are unicode strings. This mangling ONLY happens to the
product descriptor string, so the vendor and serial number strings do
not need to be handled differently than before.
1 file changed