Skip to content

Commit

Permalink
Fix vhci wdm driver installation failure
Browse files Browse the repository at this point in the history
Signed-off-by: vadimgrn <[email protected]>
  • Loading branch information
vadimgrn committed Jul 14, 2021
1 parent 426e319 commit 723f9d5
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 139 deletions.
2 changes: 1 addition & 1 deletion driver/vhci/usbip_root.inf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ AddService = usbip_vhci,%SPSVCINST_ASSOCSERVICE%, usbip_vhci_Service_Inst
[usbip_vhci_Service_Inst]
DisplayName = %ServiceDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\usbip_vhci.sys
LoadOrderGroup = Extended Base
Expand Down
8 changes: 4 additions & 4 deletions driver/vhci/usbip_vhci.inf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PnpLockDown=1

[Standard.NT$ARCH$]
%DeviceDesc%=usbip_vhci_Device, USBIPWIN\vhci
%vhub_DeviceDesc%=usbip_vhci_Device, USB\ROOT_HUB&VID1209&PID8250&REV0000
%vhub_DeviceDesc%=usbip_vhci_Device, USB\ROOT_HUB&VID_1209&PID_8250&REV_0000

[DestinationDirs]
DefaultDestDir = 12
Expand All @@ -38,7 +38,7 @@ CopyFiles=Drivers_Dir
[usbip_vhci_Device.NT$ARCH$.HW]
AddReg=usbip_vhci_Device_AddReg

[usbip_vhci_Device_AddReg]
[usbip_vhci_Device_AddReg]
HKR,,DeviceCharacteristics,0x10001,0x0100 ; Use same security checks on relative opens

;-------------- Service installation
Expand All @@ -49,7 +49,7 @@ AddService = usbip_vhci,%SPSVCINST_ASSOCSERVICE%, usbip_vhci_Service_Inst
[usbip_vhci_Service_Inst]
DisplayName = %ServiceDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\usbip_vhci.sys
LoadOrderGroup = Extended Base
Expand All @@ -62,4 +62,4 @@ DiskId1 = "usbip-win VHCI Disk"
DeviceDesc = "usbip-win VHCI"
vhub_DeviceDesc = "usbip-win VHUB"
ServiceDesc = "usbip-win VHCI Service"
DisplayClassName = "usbip-win"
DisplayClassName = "usbip-win"
8 changes: 2 additions & 6 deletions driver/vhci/usbip_vhci.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@
<Inf>
<TimeStamp>0.3.4.0</TimeStamp>
</Inf>
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<DriverSign />
<PostBuildEvent>
<Command>gencat.bat $(OutDir) 10_$(DDKPlatform) $(SolutionDir)/driver/usbip_test.pfx
</Command>
Expand All @@ -240,9 +238,7 @@
<Inf>
<TimeStamp>0.3.4.0</TimeStamp>
</Inf>
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<DriverSign />
<PostBuildEvent>
<Command>gencat.bat $(OutDir) 10_$(DDKPlatform) $(SolutionDir)/driver/usbip_test.pfx
</Command>
Expand Down
8 changes: 2 additions & 6 deletions driver/vhci/vhci_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@

#define IS_FDO(type) ((type) == VDEV_ROOT || (type) == VDEV_VHCI || (type) == VDEV_VHUB)

#define HWID_ROOT L"USBIPWIN\\root"
#define HWID_VHCI L"USBIPWIN\\vhci"
#define HWID_VHUB L"USB\\ROOT_HUB&VID1209&PID8250&REV0000"

extern LPCWSTR devcodes[];

// These are the states a vpdo or vhub transition upon
Expand Down Expand Up @@ -65,7 +61,7 @@ typedef struct _vdev {
PDEVICE_OBJECT Self;

vdev_type_t type;
// reference count for maintaining vdev validity
// reference count for maintaining vdev validity
LONG n_refs;

// We track the state of the device with every PnP Irp
Expand Down Expand Up @@ -174,7 +170,7 @@ typedef struct
BOOLEAN plugged;

UCHAR speed;
UCHAR unused; /* 4 bytes alignment */
UCHAR num_configurations; // Number of Possible Configurations

// a pending irp when no urb is requested
PIRP pending_read_irp;
Expand Down
55 changes: 29 additions & 26 deletions driver/vhci/vhci_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,49 @@ setup_vpdo_with_dsc_dev(pvpdo_dev_t vpdo, PUSB_DEVICE_DESCRIPTOR dsc_dev)
vpdo->subclass = dsc_dev->bDeviceSubClass;
vpdo->protocol = dsc_dev->bDeviceProtocol;
vpdo->speed = (UCHAR)get_usb_speed(dsc_dev->bcdUSB);
}
else {
vpdo->num_configurations = dsc_dev->bNumConfigurations;
} else {
vpdo->vendor = 0;
vpdo->product = 0;
vpdo->revision = 0;
vpdo->usbclass = 0;
vpdo->subclass = 0;
vpdo->protocol = 0;
vpdo->speed = USB_SPEED_LOW;
vpdo->num_configurations = 0;
}
}

static void
setup_vpdo_with_dsc_conf(pvpdo_dev_t vpdo, PUSB_CONFIGURATION_DESCRIPTOR dsc_conf)
{
if (dsc_conf) {
vpdo->inum = dsc_conf->bNumInterfaces;

/* Many devices have 0 usb class number in a device descriptor.
* 0 value means that class number is determined at interface level.
* USB class, subclass and protocol numbers should be setup before importing.
* Because windows vhci driver builds a device compatible id with those numbers.
*/
if (vpdo->usbclass == 0 && vpdo->subclass == 0 && vpdo->protocol == 0) {
/* buf[4] holds the number of interfaces in USB configuration.
* Supplement class/subclass/protocol only if there exists only single interface.
* A device with multiple interfaces will be detected as a composite by vhci.
*/
if (vpdo->inum == 1) {
PUSB_INTERFACE_DESCRIPTOR dsc_intf = dsc_find_first_intf(dsc_conf);
if (dsc_intf) {
vpdo->usbclass = dsc_intf->bInterfaceClass;
vpdo->subclass = dsc_intf->bInterfaceSubClass;
vpdo->protocol = dsc_intf->bInterfaceProtocol;
}
}
}
}
else {
if (!dsc_conf) {
vpdo->inum = 0;
return;
}

vpdo->inum = dsc_conf->bNumInterfaces;

/* Many devices have 0 usb class number in a device descriptor.
* 0 value means that class number is determined at interface level.
* USB class, subclass and protocol numbers should be setup before importing.
* Because windows vhci driver builds a device compatible id with those numbers.
*/
if (vpdo->usbclass || vpdo->subclass || vpdo->protocol) {
return;
}

/* buf[4] holds the number of interfaces in USB configuration.
* Supplement class/subclass/protocol only if there exists only single interface.
* A device with multiple interfaces will be detected as a composite by vhci.
*/
if (vpdo->inum == 1) {
PUSB_INTERFACE_DESCRIPTOR dsc_intf = dsc_find_first_intf(dsc_conf);
if (dsc_intf) {
vpdo->usbclass = dsc_intf->bInterfaceClass;
vpdo->subclass = dsc_intf->bInterfaceSubClass;
vpdo->protocol = dsc_intf->bInterfaceProtocol;
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions driver/vhci/vhci_pnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
#include "basetype.h"
#include "vhci_dev.h"

#define HWID_ROOT L"USBIPWIN\\root"
#define HWID_VHCI L"USBIPWIN\\vhci"

#define VHUB_PREFIX L"USB\\ROOT_HUB"
#define VHUB_VID L"1209"
#define VHUB_PID L"8250"
#define VHUB_REV L"0000"

#define HWID_VHUB \
VHUB_PREFIX \
L"&VID_" VHUB_VID \
L"&PID_" VHUB_PID \
L"&REV_" VHUB_REV

#define INITIALIZE_PNP_STATE(_Data_) \
(_Data_)->common.DevicePnPState = NotStarted;\
(_Data_)->common.PreviousPnPState = NotStarted;
Expand Down
Loading

0 comments on commit 723f9d5

Please sign in to comment.