Closed legege closed 2 years ago
Ah, thanks for pointing that out. It looks like I knew at the time that code was kind of brittle. You can of course pass interface_number-1
to libusbp_serial_port_create
as a workaround, but maybe we should think of some better way to do this.
Could you detail the reason for the +1? Would you have ioreg for that device?
I think I wanted the behavior of that function to be consistent on Windows, Linux, and macOS. The only devices I had around to test were CDC ACM devices. I don't have an ioreg printout but you can see CDC ACM USB descriptors in many different open source projects, including this one (note how it has two interfaces):
https://github.com/pololu/wixel-sdk/blob/master/libraries/src/usb_cdc_acm/usb_cdc_acm.c
For some reason, the way the macOS is designed, the serial port gets associated with the data interface which is usually (or maybe always) the second interface. For the other operating systems I think it is associated with the control interface.
Are you asking for an ioreg prinout so that you can think if there is a way to improve the code? One idea would be to detect the CDC case we are concerned about and only increment the interface number for those devices.
The ioreg output in this thread matches the situation I remember. I found it by searching for "AppleUSBACMData ioreg":
https://bytemeta.vip/repo/RfidResearchGroup/proxmark3/issues/1616
Ok, thanks for the context! By reading your comment from lsport.cpp
, would you agree that the root of this challenge is coming from the "API" that requires the user to know the interface number of the USB device in advance to determine its path(s)? I get to this conclusion because of this:
// Note: This example is slow and ugly because libusbp does not yet have // built-in support for listing serial ports; it only has support for finding // a serial port if you already know what USB device it is connected to and what // interface you expect the port to be on. This might be improved in the future.
For the use case I'm working on (https://gitlab.com/CarbonCollins/nomad-usb-device-plugin/-/issues/9), it would actually be helpful to have a method returning all the interfaces + path of a USB device. For Mac, would it be possible to scan for all IOSerialBSDClient from your experience?
I think the current API is fine and it's pretty close to what you would want if you know what kind of device you have, and you want to connect to a specific serial port on it. (Composite devices can have multiple serial ports and specifying an interface number is how we distinguish them.) The fact that the interface numbering is not correct with FTDI devices is a bug I would like to fix though.
For applications like lsport
where you don't know what type of device you have and you just want to list everything, it would be beneficial to some day add another libusbp API function that finds all the serial ports of the device, along with the interface numbers.
Once you have an io_service_t
representing the USB device, you should be able to scan for all of its IOSerialBSDClient
descendents. The function service_get_child_by_class basically does that, except that function only returns the first matching child, and I only use it to scan a USB interface, not a whole device (but I don't see why it wouldn't work if you pass a USB device to it).
I'm pretty sure commit 9f4ae10 (which I just pushed to the master branch) fixes your issue. Do you want to try it out and tell me your results?
Hi,
On macOS, because of the interface_number += 1, the port is not found for FTDI devices. Here is how it's reported with
ioreg
: