Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UsbDk_StartRedirect hangs if no normal USB driver using UsbDk V1.00-22 #124

Open
gwgill opened this issue Sep 26, 2023 · 2 comments
Open
Assignees

Comments

@gwgill
Copy link

gwgill commented Sep 26, 2023

UsbDk_StartRedirect hangs reliably on my Windows 10 22H2 build 19045.3448 system with a USB device that has no normal USB driver associated with it. It hangs for exactly 2 minutes and then UsbDk_StartRedirect returns failure.
A control-C doesn't terminate the program that has hung.
Re-plugging the device triggers the UsbDk_StartRedirect to return with success.
With a USB driver associated with the device, UsbDk_StartRedirect doesn't hang.
While hung, hiding the device with UsbDkController.exe doesn't resolve the hang.
If the device is hidden before it is plugged in, UsbDk_StartRedirect doesn't hang.

A WdfLogDump is attached.
A TraceView trace is attached.
hang.txt
UsbDkTrace.etl.zip

gwgill added a commit to gwgill/UsbDk that referenced this issue Oct 25, 2023
…mal USB driver". Add filter driver to device with no normal USB driver that sets Raw mode.
gwgill added a commit to gwgill/UsbDk that referenced this issue Oct 25, 2023
…mal USB driver". Add filter driver to device with no normal USB driver that sets Raw mode.
@gwgill
Copy link
Author

gwgill commented Oct 25, 2023

It appears that if a device doesn't have a normal driver associated with it, it gets marked as having a driver install error (28) and then on IOCTL_INTERNAL_USB_CYCLE_PORT the device disappears and is not returned.
The only way of preventing this I found is to mark the device as RawDeviceOK.
To do this, a filter has to be attached to such devices that sets the RawDeviceOK flag in IRP_MN_QUERY_CAPABILITIES.
Ideally such a filter isn't attached to devices that have a normal driver.
It doesn't seem possible to determine if a device has a normal driver or not using conventional means (i.e. IoGetDeviceProperty() or IoOpenDeviceRegistryKey() to see if there is a Driver or Service value), because the PDO is not valid within IRP_MN_QUERY_DEVICE_RELATIONS.
The only workaround to this appears to be to locate the Registry Enum/USB entries for VID/PID devices, and read the Driver or Service value that way.
Devices that are marked Raw and have a corresponding Enum won't switch to using a normal driver if it is installed after the device is first plugged in. A workaround for this is to set the CONFIGFLAG_REINSTALL flag in the devices ConfigFlags value within its Registry Enum on the device being unplugged.
I've added code to do all this in the UsbDk branch here https://github.com/gwgill/UsbDk

@gwgill
Copy link
Author

gwgill commented Oct 30, 2023

After further testing, it seemed that there was no reliable solution to the problem of using UsbDk to drive devices without a conventional driver. While the workaround of adding a filter driver and marking the device RawDeviceOK works for many devices, the hub port CYCLE used by UsbDk was not reliable for some combinations of devices and hubs. Such combinations results in a failure to read the correct VID/PID from the device, returning VID_0000&PID_0002 instead.

After considerable trial and error efforts, it seems that these difficult devices can indeed be made to work if they are configured and their hub port reset before doing a hub port CYCLE. The code to do this and finesse several other aspects of using UsbDk to drive a device without a conventional function driver is present in my fork of UsbDk .

gwgill added a commit to gwgill/UsbDk that referenced this issue Nov 10, 2023
…ving D0 power setting code, daynix#103 by adding more USB3 hub idetifiers, daynix#105 with counting fixes from kvojacheck.

Hopefully fixed remaining daynix#124 issues by adding device configuration and hub port reset before attempting port CYCLE for devices with no function driver. Cleaned up no-function driver devices handling so that the RawFilter doesn't affect devices mis-classified on first plugin, as well as ensuring function driver install proceeds correctly after device has been used without a function driver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants