Device redirection often fails when the device is in D3/D2 when
we start redirecting it. Current commit brings the device to
D0 before sending 'cycle power' command to the device port if
the device is in low power mode at the moment of starting
redirection.
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
https://github.com/daynix/UsbDk/issues/81
OnClose -> RemoveRedirect -> NotifyRedirectorRemovalStarted
NotifyRedirectorRemovalStarted passes process id to ModifyOne
in order to avoid stopping redirection if another not related
process just opens the filter device and then closes it.
Example (before this commit):
Start VM and use remote-viewer to it.
Separate application 'App' registers notification on USB
device interface arrival. When new device comes, the application
opens a file using symbolic link name and closes it.
Redirect USB device to VM.
The UsbDk forces device to be reenumerated.
Open-close operation from the 'App' unexpectedly discards
device redirection.
After this commit: because the 'App' process is not an owner
of the redirection, OnClose will not cause removal of the
redirection.
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Set owner process id when device redirection successfully
established (i.e. filter device is open and respective user
mode handle created for the process).
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
https://github.com/daynix/UsbDk/issues/81
If during redirection the redirection object is deleted
we may try accessing the deleted object in the loop of
attempts to create the redirection handle.
To avoid this we reference the redirection object until
the redirection request completely satisfied or failed.
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Extended rules processing uses bitmask OR between device type
determination bitmap and class/type bitmap provided in 'Class'
parameter of the extended rule.
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Windows recognizes USB devices by PID/VID/SN combination,
for each new USB device plugged in it generates a new
cached driver information entry in the registry.
When UsbDk hides or redirects a device it creates a virtual
device with UsbDk VID/PID and a generated serial number.
On one hand, this serial number should be unique because
there should be no multiple devices with the same PID/VID/SN
combination at any given moment of time. On the other hand,
UsbDk should re-use serial numbers of unplugged devices,
because we don't want Windows to cache one more driver
information entry each time we redirect of hide a device.
This patch introduces a simple but efficient mechanism
for serial number generation for virtual UsbDk devices.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This is useful for devices that change ID on reset.
Previous scheme of raising event on device
"reconnection" after port cycle does not work
for such devices because after reset
they look like another device for UsbDK.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
On unplug of USB hub that contains a redirected
device, removal of redirection is started when redirected
device PDO is still present in UsbDk device lists.
In this case UsbDk will try to send reset IOCTL to this device
and system will return STATUS_NO_SUCH_DEVICE error code.
This commit changes behavior of redirection removal
logic in a way that it will not interrupt removal
process when such an error is returned by reset.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This patch makes filter object reference counting objects and
ensures reference is help to filter objects while they are in use.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit moves processing of AddRedirect IOCTL from
IoInCallerContext callback of control device to normal
default queue DeviceIoControl callback.
This change eliminates posibility for parallel execution
of AddRedirect and other operations, particularly RemoveRedirect.
Initially AddRedirect was perfomed in IoInCallerContext callback
to open user mode handle to the device being redirected in context
of correct user mode process. This patch achieves the same goal
by storing caller's process handle in request context in
IoInCallerContext callback and duplicating handle to the original
calling process from queue's DeviceIoControl callback.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Remove redirection process should pass
succesfully for unplugged devices.
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
If control device creation fails - memory
allocated for control device object gets leaked.
The issue is found by HCK fault injection test.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
It is basically forbidden to send arbitrary requests to device
directly via PDO while device driver is present in device stack.
This may lead to unexpected behaviour because device may be
in many different states e.g. low power, processing other
requests etc.
In order to avoid sending descriptor requests to devices with
active functional driver we're caching all descriptors we need
on QDR post-processing while we're on top of device stack for
sure.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit makes redirection creation atomic operation
from user mode client point of view.
This ensures redirection will be stopped automatically
in case of unexpected user mode client termination.
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This makes include policy more strict and ensures
all system includes properly wrapped with extern "C"
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This is needed to make structures similar on all architectures
and all compilers.
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>