Skip to contentSkip to conversation

tools/usbip: support use case reconnect: command attach

PATCH In review Lars Gunnarsson 1 participant 1 message Oct 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 tools/usbip: support use case reconnect: command attach

Extend command "usbip attach" with:

* flag "-c" to wait for busid to become exported on remote end, and then attach, instead of returning error.
* flag "-d", to wait for busid to disconnect before exit.

Today manual steps is required to re-import usb device when re-connected. With above flags enabled, it's possible to permanently "import" usb devices with help of example systemd or other process supervisors, or with a simple while-loop in bash. With patch [1/3] and [2/3] it is possible to fully support usb devices to be reconnected over both ends.

Note:

* Reclaimed flag "-d" which was superflous and no different to "-b".
* This patch affects both ends: usbipd (server) and command "usbip attach" (client). Usbip must preferably have both ends of the new versions.

---
 tools/usb/usbip/libsrc/vhci_driver.c | 16 ++++++
 tools/usb/usbip/libsrc/vhci_driver.h |  1 +
 tools/usb/usbip/src/usbip_attach.c   | 80 ++++++++++++++++++++++------
 tools/usb/usbip/src/usbip_network.h  |  1 +
 tools/usb/usbip/src/usbipd.c         | 42 +++++++++++----
 5 files changed, 114 insertions(+), 26 deletions(-)
tools/usb/usbip/libsrc/vhci_driver.c +16 -0
index 8159fd98680b..4fc75e8bad66 100644
@@ -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
index 6c9aca216705..4aecd4013cbe 100644
@@ -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 +65 -15

160 lines not on this page · raw message

tools/usb/usbip/src/usbip_network.h +1 -0
index 83b4c5344f72..b9b80d24e68d 100644
@@ -61,6 +61,7 @@ struct op_devinfo_reply {
 
 struct op_import_request {
 	char busid[SYSFS_BUS_ID_SIZE];
+	char monitor_connect;
 } __attribute__((packed));
 
 struct op_import_reply {
tools/usb/usbip/src/usbipd.c +31 -11

66 lines not on this page · raw message

Signature · 1 line
2.25.1