Problem with libusb20_dev_get_port_path()
Uffe Jakobsen
uffe at uffe.org
Tue Jan 20 11:06:26 UTC 2015
On 2015-01-20 05:35, Hans Petter Selasky wrote:
> On 01/20/15 00:33, Uffe Jakobsen wrote:
>>
>> I seem to be having a problem with libusb20_dev_get_port_path()
>>
>> I iterate through all usb devices in the system.
>> libusb20_dev_get_port_path() returns 0 for all my usb devices.
>>
>> Any hints ?
>>
>> Seen on FreeBSD 10.1 (amd64) with latest patches
>
> Did you do a:
>
> libusb20_dev_open()
>
> first?
>
yes - without that I get an error (negative return code)
Running as root does not change anything (I didn't expect that - but I
had to try)
Stripped sample code below produces the following output:
# ./a.out
BEGIN
device descriptor: 'ugen0.1: <UHCI root HUB Intel> at usbus0'
get_port_path: 0
device descriptor: 'ugen2.1: <UHCI root HUB Intel> at usbus2'
get_port_path: 0
device descriptor: 'ugen1.1: <UHCI root HUB Intel> at usbus1'
get_port_path: 0
device descriptor: 'ugen4.1: <EHCI root HUB Intel> at usbus4'
get_port_path: 0
device descriptor: 'ugen3.1: <UHCI root HUB Intel> at usbus3'
get_port_path: 0
device descriptor: 'ugen3.2: <USB CAT5 vendor 0x0d3d> at usbus3'
get_port_path: 0
END
//
// Compile: cc tst.c -lusb
//
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <libusb20.h>
int main(int argc, char** argv)
{
int rc;
struct libusb20_backend* pbe;
struct libusb20_device* pdev_curr;
struct libusb20_device* pdev_last;
uint8_t usb_ports[UINT8_MAX];
char sbuf[FILENAME_MAX];
char *p_str;
printf("BEGIN\n");
pbe = libusb20_be_alloc_default();
pdev_curr = pdev_last = NULL;
do {
pdev_curr = libusb20_be_device_foreach(pbe, pdev_last);
if (pdev_curr == NULL) {
break;
}
libusb20_dev_open(pdev_curr, 0);
p_str = (char*)libusb20_dev_get_desc(pdev_curr);
printf("device descriptor: '%s'\n", p_str);
rc = libusb20_dev_get_port_path(pdev_curr, (uint8_t*)&usb_ports,
UINT8_MAX);
printf("get_port_path: %d\n", rc);
printf("\n");
libusb20_dev_close(pdev_curr);
pdev_last = pdev_curr;
} while (pdev_curr != NULL);
libusb20_be_free(pbe);
printf("END\n");
return 0;
}
//
// EOF
//
/Uffe
More information about the freebsd-usb
mailing list