Commit graph

83 commits

Author SHA1 Message Date
Yuri Benditovich
3d2e5a6272 driver: bring device to D0 before redirection
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>
2020-01-27 19:49:45 +02:00
Yuri Benditovich
4de57a9ff6 driver: pass current process id in file close flow
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>
2020-01-02 21:47:41 +02:00
Yuri Benditovich
427b3f0106 driver: maintain owner process id field of CUsbDkRedirection
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>
2020-01-02 21:47:41 +02:00
Yuri Benditovich
65f7251d2c driver: prevent access to already deleted object
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>
2020-01-02 21:47:41 +02:00
Yuri Benditovich
b08ff21f7b driver: add optional message to Dump() procedure
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2020-01-02 21:47:41 +02:00
Yuri Benditovich
08ad758943 Use also extended rules to decide whether device should be hidden
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>
2019-04-15 11:19:13 +03:00
Yuri Benditovich
916f797c89 Load extended rules in the driver
Load dynamic and persistent rules with type == 1
to extended rules sets.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2019-04-15 11:19:13 +03:00
Yuri Benditovich
68500dc8c3 Add ability to dump rules with configurable trace level
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2019-04-15 11:19:13 +03:00
Yuri Benditovich
ad8a8836ab hider: maintain additional extended hiding rules
Add set of dynamic and persistent rules for advanced
device hiding feature.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2019-04-15 11:19:13 +03:00
Dmitry Fleytman
a4bf95a211 ControlDevice: Generate serial numbers for UsbDk devices
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>
2017-02-19 14:09:52 +02:00
Dmitry Fleytman
848bb79ac2 FilterDevice: Raise redirection removal event on device disconnection
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>
2017-02-09 18:28:21 +02:00
Dmitry Fleytman
bb931eade4 ControlDevice: Add more traces for redirection set modifications
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-01-31 15:43:47 +02:00
Dmitry Fleytman
4ae38672d4 ControlDevice: Always log full device ID including serial number
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-01-30 14:43:44 +02:00
Dmitry Fleytman
bf79d6e942 ControlDevice: Fix removal of redirection on hub unplug
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>
2016-09-01 10:36:48 +03:00
Dmitry Fleytman
4f1bec2125 ControlDevice: Add method for device descriptor retrieval
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-01-28 14:57:47 +02:00
Dmitry Fleytman
2b207ae5e8 UsbDk: Trivial: Drop extra empty line
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-12-20 12:13:16 +02:00
Dmitry Fleytman
2cac450d17 UsbDk: Drop uneeded dynamic memory allocations 2015-11-24 12:32:35 +02:00
Dmitry Fleytman
fccb982f58 FilterDevice: Protect filter objects from deletion while in use
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>
2015-11-24 12:32:33 +02:00
Dmitry Fleytman
8fcd2fe092 ControlDevice: Never delete redirection object explicitely
Redirection object is a refcountong object and cannot
be leter with operator delete().

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-11-24 12:32:33 +02:00
Dmitry Fleytman
92527fd8b8 Redirector: Introduce additional traces
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-11-24 12:32:31 +02:00
Dmitry Fleytman
a3ee8f04c0 ControlDevice: Refactoring: Rename some private members
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-11-24 12:32:30 +02:00
Dmitry Fleytman
cbd15f5d55 ControlDevice: Do not process AddRedirect in IoInCallerContext
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>
2015-11-24 12:20:23 +02:00
Dmitry Fleytman
065604373f ControlDevice: Make WDF allocate context area for control requests
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-11-16 15:37:13 +02:00
Dmitry Fleytman
ec04c9a874 trivial: cleanup comments
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-03-25 17:38:00 +02:00
Dmitry Fleytman
e05ca16aaa ControlDevice: Split dynamic and persistent hide rules lists
Required to properly support removal of persistent hide rule

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-03-25 17:37:59 +02:00
Dmitry Fleytman
2baf64f1e5 UsbDk: Add IOCTL for rescanning registry configuration
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-03-25 17:37:56 +02:00
Dmitry Fleytman
73ba48bfee Hider: Introduce header file with registry layout
Signed-off-by: Kirill Moizik <kirill@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-03-23 13:24:07 +02:00
Dmitry Fleytman
9075137d0c CControlDevice: Introduce support for persistent hide rules
1. Read persistent rules from registry on driver load
2. Re-read persistent rules on hide rules list clear

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-03-22 15:32:07 +02:00
Dmitry Fleytman
1b169f4bb4 UsbDk: Store driver params registry key path for future use
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-03-10 19:10:20 +02:00
Dmitry Fleytman
ca71629dbf ControlDevice: Drop redundant printout on control device creation
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-03-09 11:23:23 +02:00
Dmitry Fleytman
27a04f8d55 HiderDevice: Introduce hider device creation and registration
Signed-off-by: Kirill Moizik <kirill@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-02-16 11:49:02 +02:00
Dmitry Fleytman
2f9f80cd74 ControlDevice: Introduce hide rules collection
Signed-off-by: Kirill Moizik <kirill@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-02-16 11:49:01 +02:00
Dmitry Fleytman
1c87a881e4 ControlDevice: Introduce hide rule class
Signed-off-by: Kirill Moizik <kirill@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-02-11 17:30:53 +02:00
Pavel Gurvich
8956dfcc3a UsbDk: BZ#1136861: USB redirection (auto or on-demand) is gradually prevented by -99 errors
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>
2014-10-02 15:18:25 +03:00
Dmitry Fleytman
c6c5078807 UsbDk: Fix roll-back of control device creation
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>
2014-09-16 13:49:59 +03:00
Pavel Gurvich
c8e6ed4378 UsbDk. Add comment for EnumUsbDevicesByID()
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-09-11 09:33:13 +03:00
Dmitry Fleytman
f31d25fde7 UsbDk: Cache configuration descriptors on QDR
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>
2014-09-09 18:10:47 +03:00
Pavel Gurvich
413c56304c UsbDk: Remove unused IOCTL RemoveRedirect
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-08-20 17:28:52 +03:00
Dmitry Fleytman
5c4d0af852 UsbDk: Open redirector handle in driver
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>
2014-06-12 00:57:33 +03:00
Dmitry Fleytman
d5d51dfd47 UsbDk: place all system includes into stdafx.h
This makes include policy more strict and ensures
all system includes properly wrapped with extern "C"

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-06-09 11:50:26 +03:00
Dmitry Fleytman
1af417f1d7 UsbDk: Supply USB device speed on enumeration
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-29 15:34:07 +03:00
Pavel Gurvich
7ef985384e UsbDk: Make all interface fields ULONG64
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>
2014-05-26 18:41:17 +03:00
Pavel Gurvich
00da1f59fc UsbDk: make stop redirection synchronous
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-20 12:03:27 +03:00
Pavel Gurvich
a77d8161e4 UsbDk: Add license-related files and headers
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-20 11:56:20 +03:00
Dmitry Fleytman
af30ad9b0a UsbDk: Move MAX_DEVICE_ID_LEN definition to Public.h
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:15 +03:00
Dmitry Fleytman
e602d6c4cc UsbDk: Trivial: traces cleanup/fixes
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:15 +03:00
Dmitry Fleytman
af4d7e21e7 UsbDk: Make CUsbDkRedirection compare operators const
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:14 +03:00
Dmitry Fleytman
59f80a0f90 UsbDk: Introduce API for configuration descriptors retrieval
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:14 +03:00
Dmitry Fleytman
c0098eefed UsbDk: Introduce GetPDOByDeviceID() helper
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
57025f34c1 UsbDk: make DoUSBDeviceOp() more generic
Make CUsbDkControlDeviceQueue::DoUSBDeviceOp() input buffer type
a template parameter.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00