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>
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>
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>
This is requirement of DeviceGuard and HyperVisor Code
Integrity Readiness Test on Win10/Server2016.
We use Nx allocations for all the systems where Nx pool
is implemented, i.e. for Windows 8 and later.
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.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>
Change ExecutionLevel for redirector data queue
to WdfExecutionLevelDispatch.
There is no real reason to force USB transfers exection
on PASSIVE_LEVEL and DISPATCH_LEVEL execution is definitely
faster.
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>
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>
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>
For some USB devices system calls our AddDevice callback for FDO.
In addition we call the same callback for PDO of the devices we
want to redirect. In this case we will try to install our filter
two times into the same stack which is problematic.
This patch eliminates such a possibility.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
1. Wait for reset and redirector creation completion on IOCTL handler
2. Return RedirectorID from driver to user mode caller
3. Open corresponding redirector device using RedirectorID returned
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This patch make redirectors notify control device
on creation and destruction. These notifications
are needed to make Add/Remove redirection operations
synchronous from user mode client's point of view.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This patch makes device enumeration API return array of
device info structures instead of array of device IDs.
This change is needed to return per-device information
in addition to device ID.
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Reset should be part of start/stop redirection. No separate API needed
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>