From 7ffe369bf45458ad71c58c9dc7e6a85bcbb1b84e Mon Sep 17 00:00:00 2001 From: KyungWoon Cho Date: Mon, 18 Jan 2021 13:57:06 +0900 Subject: [PATCH] raise maximum number of ports of vhci(ude) to 16 Maximum # of ports of vhci(ude) was 4. It was relatively small? Now, ports number is raised to 16. Attach command will show a proper error message when port full occur. --- driver/vhci/vhci_vhub.c | 4 +--- driver/vhci_ude/vhci_hc.c | 2 +- driver/vhci_ude/vhci_ioctl.c | 4 +--- include/usbip_vhci_api.h | 5 +++-- userspace/src/usbip/usbip_attach.c | 3 +++ userspace/src/usbip/usbip_vhci.c | 18 +++++++++--------- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/driver/vhci/vhci_vhub.c b/driver/vhci/vhci_vhub.c index fe819eed..e8c594d4 100644 --- a/driver/vhci/vhci_vhub.c +++ b/driver/vhci/vhci_vhub.c @@ -176,7 +176,6 @@ vhub_get_ports_status(pvhub_dev_t vhub, ioctl_usbip_vhci_get_ports_status *st) { pvpdo_dev_t vpdo; PLIST_ENTRY entry; - unsigned char n_used_ports = 0; PAGED_CODE(); @@ -191,12 +190,11 @@ vhub_get_ports_status(pvhub_dev_t vhub, ioctl_usbip_vhci_get_ports_status *st) DBGE(DBG_VHUB, "strange port"); continue; } - n_used_ports++; st->port_status[vpdo->port] = 1; } ExReleaseFastMutex(&vhub->Mutex); - st->n_used_ports = n_used_ports; + st->n_max_ports = 127; return STATUS_SUCCESS; } diff --git a/driver/vhci_ude/vhci_hc.c b/driver/vhci_ude/vhci_hc.c index 5b7b1ff6..869a01ad 100644 --- a/driver/vhci_ude/vhci_hc.c +++ b/driver/vhci_ude/vhci_hc.c @@ -1,7 +1,7 @@ #include "vhci_driver.h" #include "vhci_hc.tmh" -#define MAX_HUB_PORTS 4 +#define MAX_HUB_PORTS 16 #include "usbip_vhci_api.h" diff --git a/driver/vhci_ude/vhci_ioctl.c b/driver/vhci_ude/vhci_ioctl.c index 53992270..03b41ea2 100644 --- a/driver/vhci_ude/vhci_ioctl.c +++ b/driver/vhci_ude/vhci_ioctl.c @@ -12,7 +12,6 @@ static VOID get_ports_status(pctx_vhci_t vhci, ioctl_usbip_vhci_get_ports_status *ports_status) { ULONG i; - unsigned char n_used_ports = 0; TRD(IOCTL, "Enter\n"); @@ -24,13 +23,12 @@ get_ports_status(pctx_vhci_t vhci, ioctl_usbip_vhci_get_ports_status *ports_stat pctx_vusb_t vusb = vhci->vusbs[i]; if (vusb != NULL) { ports_status->port_status[i] = 1; - n_used_ports++; } } WdfSpinLockRelease(vhci->spin_lock); - ports_status->n_used_ports = n_used_ports; + ports_status->n_max_ports = (UCHAR)vhci->n_max_ports; TRD(IOCTL, "Leave\n"); } diff --git a/include/usbip_vhci_api.h b/include/usbip_vhci_api.h index 45277c04..de08592e 100644 --- a/include/usbip_vhci_api.h +++ b/include/usbip_vhci_api.h @@ -70,10 +70,11 @@ typedef struct _vhci_pluginfo unsigned char dscr_conf[9]; } vhci_pluginfo_t, *pvhci_pluginfo_t; +/* usbip-win assumes max port is 127 */ typedef struct _ioctl_usbip_vhci_get_ports_status { - /* usbip-win assumes max port is 127 */ - unsigned char n_used_ports; + /* maximum number of ports */ + unsigned char n_max_ports; unsigned char port_status[127]; } ioctl_usbip_vhci_get_ports_status; diff --git a/userspace/src/usbip/usbip_attach.c b/userspace/src/usbip/usbip_attach.c index b6f469e3..c5e9c74d 100644 --- a/userspace/src/usbip/usbip_attach.c +++ b/userspace/src/usbip/usbip_attach.c @@ -214,6 +214,9 @@ attach_device(const char *host, const char *busid, const char *serial) case ERR_NOTEXIST: err("non-existent bus id: %s", busid); break; + case ERR_PORTFULL: + err("no available port"); + break; default: err("failed to attach"); break; diff --git a/userspace/src/usbip/usbip_vhci.c b/userspace/src/usbip/usbip_vhci.c index 6b4e5693..cc9ac8c6 100644 --- a/userspace/src/usbip/usbip_vhci.c +++ b/userspace/src/usbip/usbip_vhci.c @@ -91,7 +91,7 @@ usbip_vhci_get_free_port(HANDLE hdev) if (usbip_vhci_get_ports_status(hdev, &status)) return -1; - for (i = 0; i < 127; i++) { + for (i = 0; i < status.n_max_ports; i++) { if (!status.port_status[i]) return i; } @@ -99,7 +99,7 @@ usbip_vhci_get_free_port(HANDLE hdev) } static int -get_n_used_ports(HANDLE hdev) +get_n_max_ports(HANDLE hdev) { ioctl_usbip_vhci_get_ports_status status; int res; @@ -107,23 +107,23 @@ get_n_used_ports(HANDLE hdev) res = usbip_vhci_get_ports_status(hdev, &status); if (res < 0) return res; - return status.n_used_ports; + return status.n_max_ports; } int usbip_vhci_get_imported_devs(HANDLE hdev, pioctl_usbip_vhci_imported_dev_t *pidevs) { ioctl_usbip_vhci_imported_dev *idevs; - int n_used_ports; + int n_max_ports; unsigned long len_out, len_returned; - n_used_ports = get_n_used_ports(hdev); - if (n_used_ports < 0) { - dbg("failed to get the number of used ports: %s", dbg_errcode(n_used_ports)); + n_max_ports = get_n_max_ports(hdev); + if (n_max_ports < 0) { + dbg("failed to get the number of used ports: %s", dbg_errcode(n_max_ports)); return ERR_GENERAL; } - len_out = sizeof(ioctl_usbip_vhci_imported_dev) * (n_used_ports + 1); + len_out = sizeof(ioctl_usbip_vhci_imported_dev) * (n_max_ports + 1); idevs = (ioctl_usbip_vhci_imported_dev *)malloc(len_out); if (idevs == NULL) { dbg("out of memory"); @@ -150,7 +150,7 @@ usbip_vhci_attach_device(HANDLE hdev, pvhci_pluginfo_t pluginfo) if (!DeviceIoControl(hdev, IOCTL_USBIP_VHCI_PLUGIN_HARDWARE, pluginfo, pluginfo->size, NULL, 0, &unused, NULL)) { - err("usbip_vhci_attach_device: DeviceIoControl failed: err: 0x%lx", GetLastError()); + dbg("usbip_vhci_attach_device: DeviceIoControl failed: err: 0x%lx", GetLastError()); return -1; }