Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: usbip: userspace: add support for viewing imported devices

As of Matt Mooney's major refactoring in 2011, usbip port
option was left out. Add support for this option in
a manner similar to the old implementation.

Sample output:

Imported USB devices
====================
Port 00: <Port in Use> at Full Speed(12Mbps)
unknown vendor : unknown product (1687:6211)
2-1 -> usbip://192.168.122.152:3240/1-1
-> remote bus/dev 001/002

Signed-off-by: Valentina Manea <valentina.manea.m@gmail.com>
Reviewed-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Valentina Manea and committed by
Greg Kroah-Hartman
ec2ff627 55323187

+134 -1
+67
drivers/staging/usbip/userspace/libsrc/vhci_driver.c
··· 4 4 5 5 #include "usbip_common.h" 6 6 #include "vhci_driver.h" 7 + #include <limits.h> 8 + #include <netdb.h> 7 9 8 10 #undef PROGNAME 9 11 #define PROGNAME "libusbip" ··· 339 337 return -1; 340 338 } 341 339 340 + static int read_record(int rhport, char *host, char *port, char *busid) 341 + { 342 + FILE *file; 343 + char path[PATH_MAX+1]; 344 + 345 + snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport); 346 + 347 + file = fopen(path, "r"); 348 + if (!file) { 349 + err("fopen"); 350 + return -1; 351 + } 352 + 353 + if (fscanf(file, "%s %s %s\n", host, port, busid) != 3) { 354 + err("fscanf"); 355 + fclose(file); 356 + return -1; 357 + } 358 + 359 + fclose(file); 360 + 361 + return 0; 362 + } 342 363 343 364 /* ---------------------------------------------------------------------- */ 344 365 ··· 557 532 } 558 533 559 534 dbg("detached port: %d", port); 535 + 536 + return 0; 537 + } 538 + 539 + int usbip_vhci_imported_device_dump(struct usbip_imported_device *idev) 540 + { 541 + char product_name[100]; 542 + char host[NI_MAXHOST] = "unknown host"; 543 + char serv[NI_MAXSERV] = "unknown port"; 544 + char remote_busid[SYSFS_BUS_ID_SIZE]; 545 + int ret; 546 + int read_record_error = 0; 547 + 548 + if (idev->status == VDEV_ST_NULL || idev->status == VDEV_ST_NOTASSIGNED) 549 + return 0; 550 + 551 + ret = read_record(idev->port, host, serv, remote_busid); 552 + if (ret) { 553 + err("read_record"); 554 + read_record_error = 1; 555 + } 556 + 557 + printf("Port %02d: <%s> at %s\n", idev->port, 558 + usbip_status_string(idev->status), 559 + usbip_speed_string(idev->udev.speed)); 560 + 561 + usbip_names_get_product(product_name, sizeof(product_name), 562 + idev->udev.idVendor, idev->udev.idProduct); 563 + 564 + printf(" %s\n", product_name); 565 + 566 + if (!read_record_error) { 567 + printf("%10s -> usbip://%s:%s/%s\n", idev->udev.busid, 568 + host, serv, remote_busid); 569 + printf("%10s -> remote bus/dev %03d/%03d\n", " ", 570 + idev->busnum, idev->devnum); 571 + } else { 572 + printf("%10s -> unknown host, remote port and remote busid\n", 573 + idev->udev.busid); 574 + printf("%10s -> remote bus/dev %03d/%03d\n", " ", 575 + idev->busnum, idev->devnum); 576 + } 560 577 561 578 return 0; 562 579 }
+2
drivers/staging/usbip/userspace/libsrc/vhci_driver.h
··· 64 64 65 65 int usbip_vhci_detach_device(uint8_t port); 66 66 67 + int usbip_vhci_imported_device_dump(struct usbip_imported_device *idev); 68 + 67 69 #endif /* __VHCI_DRIVER_H */
+1 -1
drivers/staging/usbip/userspace/src/Makefile.am
··· 6 6 7 7 usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \ 8 8 usbip_attach.c usbip_detach.c usbip_list.c \ 9 - usbip_bind.c usbip_unbind.c 9 + usbip_bind.c usbip_unbind.c usbip_port.c 10 10 11 11 12 12 usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
+6
drivers/staging/usbip/userspace/src/usbip.c
··· 93 93 .help = "Unbind device from " USBIP_HOST_DRV_NAME ".ko", 94 94 .usage = usbip_unbind_usage 95 95 }, 96 + { 97 + .name = "port", 98 + .fn = usbip_port_show, 99 + .help = "Show imported USB devices", 100 + .usage = NULL 101 + }, 96 102 { NULL, NULL, NULL, NULL } 97 103 }; 98 104
+1
drivers/staging/usbip/userspace/src/usbip.h
··· 29 29 int usbip_list(int argc, char *argv[]); 30 30 int usbip_bind(int argc, char *argv[]); 31 31 int usbip_unbind(int argc, char *argv[]); 32 + int usbip_port_show(int argc, char *argv[]); 32 33 33 34 void usbip_attach_usage(void); 34 35 void usbip_detach_usage(void);
+57
drivers/staging/usbip/userspace/src/usbip_port.c
··· 1 + /* 2 + * Copyright (C) 2011 matt mooney <mfm@muteddisk.com> 3 + * 2005-2007 Takahiro Hirofuchi 4 + * 5 + * 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 7 + * the Free Software Foundation, either version 2 of the License, or 8 + * (at your option) any later version. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + */ 15 + 16 + #include "vhci_driver.h" 17 + #include "usbip_common.h" 18 + 19 + static int list_imported_devices() 20 + { 21 + int i; 22 + struct usbip_imported_device *idev; 23 + int ret; 24 + 25 + ret = usbip_vhci_driver_open(); 26 + if (ret < 0) { 27 + err("open vhci_driver"); 28 + return -1; 29 + } 30 + 31 + printf("Imported USB devices\n"); 32 + printf("====================\n"); 33 + 34 + for (i = 0; i < vhci_driver->nports; i++) { 35 + idev = &vhci_driver->idev[i]; 36 + 37 + if (usbip_vhci_imported_device_dump(idev) < 0) 38 + ret = -1; 39 + } 40 + 41 + usbip_vhci_driver_close(); 42 + 43 + return ret; 44 + 45 + } 46 + 47 + int usbip_port_show(__attribute__((unused)) int argc, 48 + __attribute__((unused)) char *argv[]) 49 + { 50 + int ret; 51 + 52 + ret = list_imported_devices(); 53 + if (ret < 0) 54 + err("list imported devices"); 55 + 56 + return ret; 57 + }