tools/usbip: import USB devices on a given bus persistently
Subsystems (2)
PATCH v4 5/5 tools/usbip: import USB devices on a given bus persistently
This patch extends the command "usbip attach" with flag "-p|--persistent". When this flag is used, devices on the given remote busid is imported when available, instead of returning an error if the device is not exported. When the usb device is unplugged, it will start monitor the given remote bus again. Increment protocol version to 1.1.2 (0x112) since this patch affects both ends: usbipd (server) and command "usbip attach" (client).
---
v2: Change title, fix style warnings, improve feature description, refactor
cmdline flag usage.
v3: Change title and description.
v4: Fix review comments.
tools/usb/usbip/configure.ac | 2 +- tools/usb/usbip/libsrc/usbip_common.c | 1 + tools/usb/usbip/libsrc/usbip_common.h | 1 + tools/usb/usbip/libsrc/vhci_driver.c | 16 +++ tools/usb/usbip/libsrc/vhci_driver.h | 1 + tools/usb/usbip/src/usbip_attach.c | 134 +++++++++++++++++++------- tools/usb/usbip/src/usbip_network.h | 2 + tools/usb/usbip/src/usbipd.c | 93 ++++++++++++++++-- 8 files changed, 205 insertions(+), 45 deletions(-)
tools/usb/usbip/configure.ac +1 -1
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) AC_INIT([usbip-utils], [2.0], [[email protected]]) -AC_DEFINE([USBIP_VERSION], [0x00000111], [binary-coded decimal version number]) +AC_DEFINE([USBIP_VERSION], [0x00000112], [binary-coded decimal version number]) CURRENT=0 REVISION=1
tools/usb/usbip/libsrc/usbip_common.c +1 -0
@@ -78,6 +78,7 @@ static struct op_common_status_string op_common_status_strings[] = { { ST_DEV_ERR, "Device in error state" }, { ST_NODEV, "Device not found" }, { ST_ERROR, "Unexpected response" }, + { ST_POLL_TIMEOUT, "Poll timeout" }, { 0, NULL} };
tools/usb/usbip/libsrc/usbip_common.h +1 -0
@@ -53,6 +53,7 @@#define ST_DEV_ERR 0x03#define ST_NODEV 0x04#define ST_ERROR 0x05 +#define ST_POLL_TIMEOUT 0x06extern int usbip_use_syslog;extern int usbip_use_stderr;
tools/usb/usbip/libsrc/vhci_driver.c +16 -0
@@ -465,3 +465,19 @@ int usbip_vhci_imported_device_dump(struct usbip_imported_device *idev)return 0 ; } + +int usbip_vhci_get_local_busid_from (int port,char *local_busid) +{ +int rc =-1 ; + +for (int i =0 ; i < vhci_driver->nports; ++i) { +struct usbip_imported_device *idev = &vhci_driver->idev[i]; + +if (idev->port == port &&strnlen (idev->udev.busid,SYSFS_BUS_ID_SIZE )) { +memcpy (local_busid, idev->udev.busid,SYSFS_BUS_ID_SIZE ); + rc =0 ; +break ; + } + } +return rc; +}
tools/usb/usbip/libsrc/vhci_driver.h +1 -0
@@ -63,5 +63,6 @@ int usbip_vhci_attach_device(uint8_t port, int sockfd, uint8_t busnum,int usbip_vhci_detach_device (uint8_t port);int usbip_vhci_imported_device_dump (struct usbip_imported_device *idev); +int usbip_vhci_get_local_busid_from (int port,char *local_busid);#endif /* __VHCI_DRIVER_H */
tools/usb/usbip/src/usbip_attach.c +100 -34
216 lines not on this page · raw message
tools/usb/usbip/src/usbip_network.h +2 -0
@@ -61,6 +61,7 @@ struct op_devinfo_reply {struct op_import_request {char busid[SYSFS_BUS_ID_SIZE ]; +uint32_t poll_timeout_ms; } __attribute__((packed));struct op_import_reply {
@@ -69,6 +70,7 @@ struct op_import_reply { } __attribute__((packed));#define PACK_OP_IMPORT_REQUEST (pack, request) do {\ + (request)->poll_timeout_ms = usbip_net_pack_uint32_t(pack, (request)->poll_timeout_ms);\ } while (0)#define PACK_OP_IMPORT_REPLY (pack, reply) do {\
tools/usb/usbip/src/usbipd.c +83 -10
124 lines not on this page · raw message
--
2.25.1