Commit graph

74 commits

Author SHA1 Message Date
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
Dmitry Fleytman
eefbd06435 UsbDk: Supply USB device descriptors on enumeration
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
dc8c3a09a4 UsbDk: Make StartRedirect operation synchronous
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>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
968a4bbd2c UsbDk: Introduce DoUSBDeviceOp() species with output buffers support
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
a8eb08b2ce UsbDk: Notify control device about redirection activities
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>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
44aeb7b40e UsbDk: Extend CUsbDkRedirection with notifications
Add logic for redirector device created/deleted notifications
Add storage for assotiated redirector ID

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
ec768841b5 UsbDk: Introduce UsbDkFillIDStruct helper
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>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
b93b71ce45 UsbDk: Add port number to per-device data supplied on enumeration
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
0a6379435b UsbDk: Add filter ID to per-device data supplied on enumeration
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
8a0311f624 UsbDk: Make device enumeration return more generic structure
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>
2014-05-11 19:26:13 +03:00