From 3694b3a4c4d28e3330f68c2ddc6ebe3eef9c0ec2 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Thu, 14 Jul 2011 13:17:40 +0200 Subject: usbredirserver: add support for opening devices by bus-address --- usbredirserver/usbredirserver.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'usbredirserver/usbredirserver.c') diff --git a/usbredirserver/usbredirserver.c b/usbredirserver/usbredirserver.c index 117151a..1a550f7 100644 --- a/usbredirserver/usbredirserver.c +++ b/usbredirserver/usbredirserver.c @@ -192,7 +192,7 @@ int main(int argc, char *argv[]) struct addrinfo *r, *res, hints; struct sigaction act; char port_str[16]; - libusb_device_handle *handle; + libusb_device_handle *handle = NULL; while ((o = getopt_long(argc, argv, "hp:", longopts, NULL)) != -1) { switch (o) { @@ -319,12 +319,29 @@ int main(int argc, char *argv[]) fprintf(stderr, "Could not open an usb-device with vid:pid %04x:%04x\n", usbvendor, usbproduct); - exit(1); } } else { - /* FIXME */ - fprintf(stderr, "bus-addr usb device indentification is not implemented\n"); - exit(1); + libusb_device **list = NULL; + ssize_t i, n; + + n = libusb_get_device_list(ctx, &list); + for (i = 0; i < n; i++) { + if (libusb_get_bus_number(list[i]) == usbbus && + libusb_get_device_address(list[i]) == usbaddr) + break; + } + if (i < n) { + if (libusb_open(list[i], &handle) != 0) { + fprintf(stderr, + "Could not open usb-device at bus-addr %d-%d\n", + usbbus, usbaddr); + } + } else { + fprintf(stderr, + "Could not find an usb-device at bus-addr %d-%d\n", + usbbus, usbaddr); + } + libusb_free_device_list(list, 1); } if (!handle) { close(client_fd); @@ -338,6 +355,7 @@ int main(int argc, char *argv[]) exit(1); run_main_loop(); usbredirhost_close(host); + handle = NULL; } close(server_fd); -- cgit v1.2.3