Commit graph

449 commits

Author SHA1 Message Date
Yuri Benditovich
d902e99a2a Use lower device for queries during initialization
It is more correct to use lower device in stack for queries
during filter initialization. Lower device is in initialized
state and can process all kinds of requests, when current one is
not ready yet.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2017-07-12 16:49:32 +03:00
Dmitry Fleytman
446daeca3e Build: Introduce debug configurations without test signing
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
2017-04-06 13:24:06 +03:00
Sameeh Jubran
2cd4aa5262 Build: Migrate to VS 2015 and add Win10 configurations
This commit migrates from VS 2013 to VS 2015. Beside the auto conversion
which was performed by VS this commit includes the following fixes
which enabled the builld to work:

Win (7, 8, 8.1, 10):
* Set the KMDF Version Major to 1.
* Set the KMDF Version Minor to 11.

Win XP:
* Add _When_ define.
* Add empty implementation to guard functions which else would cause an
  unresolved symbols.
* Add path to WinDDK's wdfinstaller.h in UsbDkHelper project.
* Add "GetDriverProjectAttributes" and "GetPackageFiles" targets to
  UsbDkController, UsbDkHelper and UsbDkInstHelper project files.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-03 15:06:47 +03:00
Yuri Benditovich
6da5b27ca6 Alloc: Make non-paged allocation from Nx pool on Win8 and later
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>
2017-04-02 17:24:35 +03:00
Yuri Benditovich
7c72773cd1 FilterDevice: Do not report non-USB devices in list of devices
The driver may report non-USB device in list of devices
available for redirection (for example, this happens with
FTDI dual-port serial adapter PID 6010)

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-02 17:24:19 +03:00
Sameeh Jubran
dddc046940 UsbDk: Use case sensitive comparison
When attempting to redirect a device and the <device id> input string doesn't
match the actual <device id> string (case sensitive) the UsbDkController gets
stuck for two minutes and the error: "Redirect of USB device failed" is shown.
This is caused by case insensitive comparison between the input string and the
<device id> string in "CRegText::Match(PCWSTR String)" followed by case
sensitive comparison in "CStringBase::operator== (const UNICODE_STRING& Str)"
causing the "m_RedirectionCreated" event's timeout - two minutes - to expire.

This commit makes the error message show instantly eliminating the two
minutes delay.

<device id> string comparison should be case sensitive as defined
by user mode UsbDk API contract.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-03-14 12:40:26 +02:00
Dmitry Fleytman
1217ff2739 HiderStrategy: Re-use serial numbers of UsbDk devices
See log message of previous commit for rationale.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 14:10:30 +02: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
2e945fe180 FilterDevice: Add support for externally assigned serial number
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 13:54:06 +02:00
Dmitry Fleytman
6f383cb2b9 HiderStrategy: Do not allow hidden device removal right after creation
See commit diff for explanation.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 13:52:51 +02:00
Dmitry Fleytman
6dd93fb7c5 RedirectorStrategy: Fix MakeAvailable() logic chaining
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 11:15:50 +02:00
Dmitry Fleytman
2c06508b1c FilterStrategy: Introduce helper function for IRP completion
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 11:14:32 +02:00
Dmitry Fleytman
435ea8de58 UsbDkUtil: Introduce CStopWatch class
This class does elapsed time measurement.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 11:13:42 +02:00
Dmitry Fleytman
2f54f6e20f HiderStrategy: Add printout for device ID patcher
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-15 16:03:43 +02:00
Dmitry Fleytman
8624b1e0b6 WdfDevice: Add printout on device destruction
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-15 15:54:58 +02:00
Dmitry Fleytman
f5de68b75d WdfDevice: Fix severity of information printout
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-15 15:53:58 +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
76299389ce ControlIrp: Clear event state prior to sending IRP
This is needed in case client sends the same IRP
for a few times.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-08 13:00:16 +02:00
Dmitry Fleytman
5288bfcbcb Utils: Fix event type for CWdmEvent
Event wrapped by CWdmEvent expected to be
NotificationEvent, i.e. not auto-reset.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-08 12:57:39 +02:00
Dmitry Fleytman
db95b4651e FilterDevice: Fix recognition of HUB devices
Sometimes UsbDk cannot query device descriptors for USB hubs,
in such cases it does not attach to theirs stack during parent bus
relations processing.

However, since UsbDk is registered as USB hub class filter,
WDF will call its AddDevice callback anyway.

In this case UsbDk should assume that it is dealing with a hub
and assign its usual hub strategy.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-02 12:04:36 +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
Sameeh Jubran
6b623e0ba2 Fix a possible BSOD due to null pointer
m_Relations can be null therefore we should access it carefully.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-01-18 15:28:09 +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
e68f982ff7 RedirectorStrategy: Override device description for redirected devices.
There are two reasons for that:

1. There are devices that do not provide device description:
   In this case, for normal devices, Windows gets description from INF file.
   Since there is no INF file for UsbDk devices, Windows may fail
   to initialize the device (depending on implementation of bus driver).

2. With this patch redirected devices show up in device manager as
   "UsbDk device" which is better then "Unknown Device" or
   "Mass Storage Device" etc.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-07-04 11:29:29 +03:00
Dmitry Fleytman
8c7edd9997 FilterDevice: Extend IRP post processing logic
This patch adds support for IRP post processing
on failure and in all cases.

New logic will be used by following commits to
implement device text patching.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-07-04 11:29:27 +03:00
Dmitry Fleytman
e0c43569d3 Trace: Add separate trace group for Hider strategy
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-07-04 11:29:27 +03:00
Dmitry Fleytman
f01408384a UsbDk: Simplify and refactor filter attachment code
This is a refactoring commit, no functional changes introduced.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:09 +03:00
Dmitry Fleytman
0b7487ba56 UsbDk: Retire old hiding logic
This commit retires old device hider logic based
on wiping PDOs from BusRelations array.

Previous commits introduce new logic based on IDs
patching.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:05 +03:00
Dmitry Fleytman
a9bbb929f5 UsbDk: Implement hider logic via patching device IDs
Wiping PDOs from BusRelations list has side effect
of absence of hotplug events from the OS.

This is not good for applications that want devices
appear hidden and start redirection process on plug
at the same time.

Following patches will retire old hiding logic.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:00 +03:00
Dmitry Fleytman
c80effc7dd UsbDk: Introduce hider strategy class
This class will be used by following patches to
implement hiding via patching device IDs.

See commit messages of corresponfing patches
for rationale.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:31:55 +03:00
Dmitry Fleytman
b354d0ea35 UsbDk: Trivial: Remove comments numbering
It is ridiculous to update numbering manually after
each change in that function.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:31:50 +03:00
Dmitry Fleytman
eadd31b315 UsbTarget: Trivial: Remove m_ prefix from stack variables names
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-03-09 11:03:26 +02:00
Dmitry Fleytman
0a4f4811bc RedirectorStrategy: Add request counters to traces
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 12:03:39 +02:00
Dmitry Fleytman
074128a491 Utils: Introduce CAtomicCounter class
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 11:59:49 +02:00
Dmitry Fleytman
3d0a2050b3 UsbTarget: Introduce TargetRequest class
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 11:02:14 +02:00
Dmitry Fleytman
603d98e602 FilterDevice: Use generic WDF request context
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 10:56:23 +02:00
Dmitry Fleytman
32e08302d0 WdfRequest: Introduce generic request context
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 10:56:22 +02:00
Dmitry Fleytman
346554ff0c RedirectorStrategy: Use more specific type for request objects
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 10:56:21 +02:00
Dmitry Fleytman
44e3837eff RedirectorStrategy: Replace explicit type names with auto where possible
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 10:56:09 +02:00
Dmitry Fleytman
fa23267405 DeviceAccess: Drop UsbDkWdmUsbDeviceIsHub
This function is not used anymore.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-01-28 15:55:11 +02:00
Dmitry Fleytman
6b21ddc78c FilterDevice: Use cached device descriptor for strategy selection
Querying device descriptor fails in that context.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-01-28 15:53:35 +02: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
82b9a59bc4 UsbDk: Introduce tracing for BusRelations processing
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-01-25 15:05:59 +02:00
Dmitry Fleytman
c573972ff1 RedirectorStrategy: Do not report STALL conditions on control pipe
STALL condition on control pipe cleared automatically
by underlying infrastructure. Do not report it to client
otherwise it may decide to clear it via ResetPipe and
reset of control pipe is not supported by WDF.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-01-14 11:30:59 +02:00
Dmitry Fleytman
0fbeb04527 UsbDk: Trivial: Minor comments fix
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-01-14 10:45:44 +02:00
Dmitry Fleytman
3b1f461d5c Revert "RedirectorStrategy: Ensure there are no short buffers on read"
This reverts commit 32aadcb4fe.

Reverting commit because a regression was discovered on some devices.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-12-25 08:44:38 +02:00
Dmitry Fleytman
910c71c191 UsbTarget: Add trace for ResetDevice
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-12-24 16:40:13 +02:00
Dmitry Fleytman
00cf4cbb04 FilterStrategy: Simplify requests forwarding code
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-12-24 12:04:07 +02:00
Dmitry Fleytman
32aadcb4fe RedirectorStrategy: Ensure there are no short buffers on read
To avoid "BABBLE" conditions.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-12-24 11:25:31 +02:00