nefarius / DsHidMini

Virtual HID Mini-user-mode-driver for Sony DualShock 3 Controllers
https://docs.nefarius.at/projects/DsHidMini/
BSD 3-Clause "New" or "Revised" License
1.18k stars 51 forks source link

Mode switching inconsistencies #374

Open nefarius opened 1 month ago

nefarius commented 1 month ago

We now pull the user-specified HID mode from the configuration file, which happens at a state where the device object is already created. The HID mode device property is read by the PnP manager via filter driver when queried for HWID, which happens before the property is refreshed from the configuration file. This can lead to the XI filter being active while the driver mode is still in e.g. SYS mode, causing issues with the different HID report descriptor the filter didn't expect.

A simple workaround is to restart the device twice where the device boots with the correct property value.

For a real fix, it has to be brainstormed how to achieve; we can not delay probing for the mode in the filter PnP routines and we can not read the configuration file content before the device is operational. We could detect the mismatch of the mode from JSON and in the property and react to it somehow, but "auto-restarting" a device in a user-mode driver is tricky and not really supported officially.

nefarius commented 1 month ago

First experimental trick was to issue a USB hub port cycle on mode mismatch, however it is not happy when failing powerup:

image

Might retry by setting a flag and then retrying in a timer after like a second.

nefarius commented 1 month ago

Experimenting with port cycle didn't yield any success sadly because the driver hosting process lacks the necessary permissions to do so. I've archived the relevant code here for future use.