Skip to content

Commit

Permalink
raise maximum number of ports of vhci(ude) to 16
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cezanne committed Jan 18, 2021
1 parent 2bb69f1 commit 7ffe369
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 1 addition & 3 deletions driver/vhci/vhci_vhub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion driver/vhci_ude/vhci_hc.c
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
4 changes: 1 addition & 3 deletions driver/vhci_ude/vhci_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");
}
Expand Down
5 changes: 3 additions & 2 deletions include/usbip_vhci_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions userspace/src/usbip/usbip_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions userspace/src/usbip/usbip_vhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,39 @@ 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;
}
return -1;
}

static int
get_n_used_ports(HANDLE hdev)
get_n_max_ports(HANDLE hdev)
{
ioctl_usbip_vhci_get_ports_status status;
int res;

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");
Expand All @@ -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;
}

Expand Down

0 comments on commit 7ffe369

Please sign in to comment.