aboutsummaryrefslogtreecommitdiffstats
path: root/tools/usb/usbip
diff options
context:
space:
mode:
authorIgor Kotrasinski <i.kotrasinsk@samsung.com>2016-03-08 15:49:06 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-04-26 18:19:50 -0400
commite0546fd8b748b19d8edd1550530da8ebad6e4b31 (patch)
tree79f1d0273652e45a13b96ed1cb1d3fa6122599e3 /tools/usb/usbip
parent7b3f74f7e0601b2767aee7e188b1e3a912c082a2 (diff)
usbip: tools: Start using VUDC backend in usbip tools
Modify userspace tools to allow exporting and connecting to vudc. This commit is a result of cooperation between Samsung R&D Institute Poland and Open Operating Systems Student Society at University of Warsaw (O2S3@UW) consisting of: Igor Kotrasinski <ikotrasinsk@gmail.com> Karol Kosik <karo9@interia.eu> Ewelina Kosmider <3w3lfin@gmail.com> Dawid Lazarczyk <lazarczyk.dawid@gmail.com> Piotr Szulc <ps347277@students.mimuw.edu.pl> Tutor and project owner: Krzysztof Opasiak <k.opasiak@samsung.com> Signed-off-by: Igor Kotrasinski <i.kotrasinsk@samsung.com> Signed-off-by: Ewelina Kosmider <3w3lfin@gmail.com> [Various bug fixes and improvements] Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/usb/usbip')
-rw-r--r--tools/usb/usbip/src/usbip_attach.c10
-rw-r--r--tools/usb/usbip/src/usbip_list.c96
-rw-r--r--tools/usb/usbip/src/usbipd.c12
3 files changed, 112 insertions, 6 deletions
diff --git a/tools/usb/usbip/src/usbip_attach.c b/tools/usb/usbip/src/usbip_attach.c
index d58a14dfc094..70a6b507fb62 100644
--- a/tools/usb/usbip/src/usbip_attach.c
+++ b/tools/usb/usbip/src/usbip_attach.c
@@ -1,6 +1,9 @@
1/* 1/*
2 * Copyright (C) 2011 matt mooney <mfm@muteddisk.com> 2 * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
3 * 2005-2007 Takahiro Hirofuchi 3 * 2005-2007 Takahiro Hirofuchi
4 * Copyright (C) 2015-2016 Samsung Electronics
5 * Igor Kotrasinski <i.kotrasinsk@samsung.com>
6 * Krzysztof Opasiak <k.opasiak@samsung.com>
4 * 7 *
5 * This program is free software: you can redistribute it and/or modify 8 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -36,7 +39,8 @@
36static const char usbip_attach_usage_string[] = 39static const char usbip_attach_usage_string[] =
37 "usbip attach <args>\n" 40 "usbip attach <args>\n"
38 " -r, --remote=<host> The machine with exported USB devices\n" 41 " -r, --remote=<host> The machine with exported USB devices\n"
39 " -b, --busid=<busid> Busid of the device on <host>\n"; 42 " -b, --busid=<busid> Busid of the device on <host>\n"
43 " -d, --device=<devid> Id of the virtual UDC on <host>\n";
40 44
41void usbip_attach_usage(void) 45void usbip_attach_usage(void)
42{ 46{
@@ -203,6 +207,7 @@ int usbip_attach(int argc, char *argv[])
203 static const struct option opts[] = { 207 static const struct option opts[] = {
204 { "remote", required_argument, NULL, 'r' }, 208 { "remote", required_argument, NULL, 'r' },
205 { "busid", required_argument, NULL, 'b' }, 209 { "busid", required_argument, NULL, 'b' },
210 { "device", required_argument, NULL, 'd' },
206 { NULL, 0, NULL, 0 } 211 { NULL, 0, NULL, 0 }
207 }; 212 };
208 char *host = NULL; 213 char *host = NULL;
@@ -211,7 +216,7 @@ int usbip_attach(int argc, char *argv[])
211 int ret = -1; 216 int ret = -1;
212 217
213 for (;;) { 218 for (;;) {
214 opt = getopt_long(argc, argv, "r:b:", opts, NULL); 219 opt = getopt_long(argc, argv, "d:r:b:", opts, NULL);
215 220
216 if (opt == -1) 221 if (opt == -1)
217 break; 222 break;
@@ -220,6 +225,7 @@ int usbip_attach(int argc, char *argv[])
220 case 'r': 225 case 'r':
221 host = optarg; 226 host = optarg;
222 break; 227 break;
228 case 'd':
223 case 'b': 229 case 'b':
224 busid = optarg; 230 busid = optarg;
225 break; 231 break;
diff --git a/tools/usb/usbip/src/usbip_list.c b/tools/usb/usbip/src/usbip_list.c
index d5ce34a410e7..f1b38e866dd7 100644
--- a/tools/usb/usbip/src/usbip_list.c
+++ b/tools/usb/usbip/src/usbip_list.c
@@ -1,6 +1,9 @@
1/* 1/*
2 * Copyright (C) 2011 matt mooney <mfm@muteddisk.com> 2 * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
3 * 2005-2007 Takahiro Hirofuchi 3 * 2005-2007 Takahiro Hirofuchi
4 * Copyright (C) 2015-2016 Samsung Electronics
5 * Igor Kotrasinski <i.kotrasinsk@samsung.com>
6 * Krzysztof Opasiak <k.opasiak@samsung.com>
4 * 7 *
5 * This program is free software: you can redistribute it and/or modify 8 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -30,6 +33,10 @@
30#include <netdb.h> 33#include <netdb.h>
31#include <unistd.h> 34#include <unistd.h>
32 35
36#include <dirent.h>
37
38#include <linux/usb/ch9.h>
39
33#include "usbip_common.h" 40#include "usbip_common.h"
34#include "usbip_network.h" 41#include "usbip_network.h"
35#include "usbip.h" 42#include "usbip.h"
@@ -205,8 +212,10 @@ static int list_devices(bool parsable)
205 /* Get device information. */ 212 /* Get device information. */
206 idVendor = udev_device_get_sysattr_value(dev, "idVendor"); 213 idVendor = udev_device_get_sysattr_value(dev, "idVendor");
207 idProduct = udev_device_get_sysattr_value(dev, "idProduct"); 214 idProduct = udev_device_get_sysattr_value(dev, "idProduct");
208 bConfValue = udev_device_get_sysattr_value(dev, "bConfigurationValue"); 215 bConfValue = udev_device_get_sysattr_value(dev,
209 bNumIntfs = udev_device_get_sysattr_value(dev, "bNumInterfaces"); 216 "bConfigurationValue");
217 bNumIntfs = udev_device_get_sysattr_value(dev,
218 "bNumInterfaces");
210 busid = udev_device_get_sysname(dev); 219 busid = udev_device_get_sysname(dev);
211 if (!idVendor || !idProduct || !bConfValue || !bNumIntfs) { 220 if (!idVendor || !idProduct || !bConfValue || !bNumIntfs) {
212 err("problem getting device attributes: %s", 221 err("problem getting device attributes: %s",
@@ -237,12 +246,90 @@ err_out:
237 return ret; 246 return ret;
238} 247}
239 248
249static int list_gadget_devices(bool parsable)
250{
251 int ret = -1;
252 struct udev *udev;
253 struct udev_enumerate *enumerate;
254 struct udev_list_entry *devices, *dev_list_entry;
255 struct udev_device *dev;
256 const char *path;
257 const char *driver;
258
259 const struct usb_device_descriptor *d_desc;
260 const char *descriptors;
261 char product_name[128];
262
263 uint16_t idVendor;
264 char idVendor_buf[8];
265 uint16_t idProduct;
266 char idProduct_buf[8];
267 const char *busid;
268
269 udev = udev_new();
270 enumerate = udev_enumerate_new(udev);
271
272 udev_enumerate_add_match_subsystem(enumerate, "platform");
273
274 udev_enumerate_scan_devices(enumerate);
275 devices = udev_enumerate_get_list_entry(enumerate);
276
277 udev_list_entry_foreach(dev_list_entry, devices) {
278 path = udev_list_entry_get_name(dev_list_entry);
279 dev = udev_device_new_from_syspath(udev, path);
280
281 driver = udev_device_get_driver(dev);
282 /* We only have mechanism to enumerate gadgets bound to vudc */
283 if (driver == NULL || strcmp(driver, USBIP_DEVICE_DRV_NAME))
284 continue;
285
286 /* Get device information. */
287 descriptors = udev_device_get_sysattr_value(dev,
288 VUDC_DEVICE_DESCR_FILE);
289
290 if (!descriptors) {
291 err("problem getting device attributes: %s",
292 strerror(errno));
293 goto err_out;
294 }
295
296 d_desc = (const struct usb_device_descriptor *) descriptors;
297
298 idVendor = le16toh(d_desc->idVendor);
299 sprintf(idVendor_buf, "0x%4x", idVendor);
300 idProduct = le16toh(d_desc->idProduct);
301 sprintf(idProduct_buf, "0x%4x", idVendor);
302 busid = udev_device_get_sysname(dev);
303
304 /* Get product name. */
305 usbip_names_get_product(product_name, sizeof(product_name),
306 le16toh(idVendor),
307 le16toh(idProduct));
308
309 /* Print information. */
310 print_device(busid, idVendor_buf, idProduct_buf, parsable);
311 print_product_name(product_name, parsable);
312
313 printf("\n");
314
315 udev_device_unref(dev);
316 }
317 ret = 0;
318
319err_out:
320 udev_enumerate_unref(enumerate);
321 udev_unref(udev);
322
323 return ret;
324}
325
240int usbip_list(int argc, char *argv[]) 326int usbip_list(int argc, char *argv[])
241{ 327{
242 static const struct option opts[] = { 328 static const struct option opts[] = {
243 { "parsable", no_argument, NULL, 'p' }, 329 { "parsable", no_argument, NULL, 'p' },
244 { "remote", required_argument, NULL, 'r' }, 330 { "remote", required_argument, NULL, 'r' },
245 { "local", no_argument, NULL, 'l' }, 331 { "local", no_argument, NULL, 'l' },
332 { "device", no_argument, NULL, 'd' },
246 { NULL, 0, NULL, 0 } 333 { NULL, 0, NULL, 0 }
247 }; 334 };
248 335
@@ -254,7 +341,7 @@ int usbip_list(int argc, char *argv[])
254 err("failed to open %s", USBIDS_FILE); 341 err("failed to open %s", USBIDS_FILE);
255 342
256 for (;;) { 343 for (;;) {
257 opt = getopt_long(argc, argv, "pr:l", opts, NULL); 344 opt = getopt_long(argc, argv, "pr:ld", opts, NULL);
258 345
259 if (opt == -1) 346 if (opt == -1)
260 break; 347 break;
@@ -269,6 +356,9 @@ int usbip_list(int argc, char *argv[])
269 case 'l': 356 case 'l':
270 ret = list_devices(parsable); 357 ret = list_devices(parsable);
271 goto out; 358 goto out;
359 case 'd':
360 ret = list_gadget_devices(parsable);
361 goto out;
272 default: 362 default:
273 goto err_out; 363 goto err_out;
274 } 364 }
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index 8a2ec4dab4bd..a0972dea9e6c 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -45,6 +45,7 @@
45 45
46#include "usbip_host_driver.h" 46#include "usbip_host_driver.h"
47#include "usbip_host_common.h" 47#include "usbip_host_common.h"
48#include "usbip_device_driver.h"
48#include "usbip_common.h" 49#include "usbip_common.h"
49#include "usbip_network.h" 50#include "usbip_network.h"
50#include "list.h" 51#include "list.h"
@@ -68,6 +69,11 @@ static const char usbipd_help_string[] =
68 " -6, --ipv6\n" 69 " -6, --ipv6\n"
69 " Bind to IPv6. Default is both.\n" 70 " Bind to IPv6. Default is both.\n"
70 "\n" 71 "\n"
72 " -e, --device\n"
73 " Run in device mode.\n"
74 " Rather than drive an attached device, create\n"
75 " a virtual UDC to bind gadgets to.\n"
76 "\n"
71 " -D, --daemon\n" 77 " -D, --daemon\n"
72 " Run as a daemon process.\n" 78 " Run as a daemon process.\n"
73 "\n" 79 "\n"
@@ -590,6 +596,7 @@ int main(int argc, char *argv[])
590 { "daemon", no_argument, NULL, 'D' }, 596 { "daemon", no_argument, NULL, 'D' },
591 { "daemon", no_argument, NULL, 'D' }, 597 { "daemon", no_argument, NULL, 'D' },
592 { "debug", no_argument, NULL, 'd' }, 598 { "debug", no_argument, NULL, 'd' },
599 { "device", no_argument, NULL, 'e' },
593 { "pid", optional_argument, NULL, 'P' }, 600 { "pid", optional_argument, NULL, 'P' },
594 { "tcp-port", required_argument, NULL, 't' }, 601 { "tcp-port", required_argument, NULL, 't' },
595 { "help", no_argument, NULL, 'h' }, 602 { "help", no_argument, NULL, 'h' },
@@ -618,7 +625,7 @@ int main(int argc, char *argv[])
618 cmd = cmd_standalone_mode; 625 cmd = cmd_standalone_mode;
619 driver = &host_driver; 626 driver = &host_driver;
620 for (;;) { 627 for (;;) {
621 opt = getopt_long(argc, argv, "46DdP::t:hv", longopts, NULL); 628 opt = getopt_long(argc, argv, "46DdeP::t:hv", longopts, NULL);
622 629
623 if (opt == -1) 630 if (opt == -1)
624 break; 631 break;
@@ -648,6 +655,9 @@ int main(int argc, char *argv[])
648 case 'v': 655 case 'v':
649 cmd = cmd_version; 656 cmd = cmd_version;
650 break; 657 break;
658 case 'e':
659 driver = &device_driver;
660 break;
651 case '?': 661 case '?':
652 usbipd_help(); 662 usbipd_help();
653 default: 663 default: