summaryrefslogtreecommitdiff
path: root/usbredirserver
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2011-07-14 13:17:40 +0200
committerHans de Goede <hdegoede@redhat.com>2011-07-14 14:59:44 +0200
commit3694b3a4c4d28e3330f68c2ddc6ebe3eef9c0ec2 (patch)
tree86750f49091862ac3049dc8e8f178ccbff60389e /usbredirserver
parentf61b0b3af2a9e5cebf78a3530ea1a0688227e14c (diff)
usbredirserver: add support for opening devices by bus-address
Diffstat (limited to 'usbredirserver')
-rw-r--r--usbredirserver/usbredirserver.c28
1 files changed, 23 insertions, 5 deletions
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);