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>
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>
Just a helper function that fills USB_DK_DEVICE_ID structure
havind DeviceID and InstanceID strings provided.
Available for both user mode and kernel mode.
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>