macOS Sierra: Fix detection of parent devices.
authortich <chris@tich.info>
Mon, 13 Mar 2017 16:37:33 +0000 (09:37 -0700)
committerNathan Hjelm <hjelmn@cs.unm.edu>
Fri, 17 Mar 2017 01:35:44 +0000 (19:35 -0600)
commit871eb299b989bc0714391804a9d2fdb145a32ff5
tree90da0bad3d29defdd451fbc7d780edaf173b0ae5
parent2756874a933aaace2d8972a04fc69860ccc6cb55
macOS Sierra: Fix detection of parent devices.

This fixes the output of libusb_get_port_numbers(), where it used to merely return the port number of the device itself.
Now that libusb properly detects parent devices, we get the entire port path of the device.
For reference, here's the output of the 'listdevs' example before my changes:

tich-mbp:libusb-1.0.21 tich$ ./examples/listdevs
0409:005a (bus 29, device 6) path: 1
05ac:8509 (bus 26, device 2) path: 1
05ac:821d (bus 29, device 7) path: 3
05ac:0252 (bus 29, device 5) path: 3
05ac:8242 (bus 29, device 4) path: 2
0a5c:4500 (bus 29, device 3) path: 1
0424:2513 (bus 29, device 2) path: 8
8087:0024 (bus 29, device 1) path: 1
8087:0024 (bus 26, device 1) path: 1

And here's the output after my changes:

tich-mbp:libusb-1.0.21 tich$ ./examples/listdevs
0409:005a (bus 29, device 6) path: 1.1
05ac:8509 (bus 26, device 2) path: 1.1
05ac:821d (bus 29, device 7) path: 1.8.1.3
05ac:0252 (bus 29, device 5) path: 1.8.3
05ac:8242 (bus 29, device 4) path: 1.8.2
0a5c:4500 (bus 29, device 3) path: 1.8.1
0424:2513 (bus 29, device 2) path: 1.8
8087:0024 (bus 29, device 1) path: 1
8087:0024 (bus 26, device 1) path: 1

Since we're now using "IOUSBHostDevice" as the matching service (starting with El Capitan), we need to walk up the IOService plane to look for parents.
You can manually walk up the IOService plane by executing "ioreg -p IOService -l -w 0 -x | less" and looking for your device. Notice that the parent device is always a parent in the tree, but it's not always the _immediate_ parent of the device.
libusb/os/darwin_usb.c
libusb/version_nano.h