Skip to content

Commit

Permalink
UsbDk: Implement hider logic via patching device IDs
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Dmitry Fleytman committed Jun 29, 2016
1 parent c80effc commit a9bbb92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
34 changes: 22 additions & 12 deletions UsbDk/FilterDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ bool CUsbDkHubFilterStrategy::FetchConfigurationDescriptors(CWdmUsbDeviceAccess

void CUsbDkHubFilterStrategy::ApplyRedirectionPolicy(CUsbDkChildDevice &Device)
{
if (m_ControlDevice->ShouldRedirect(Device))
if (m_ControlDevice->ShouldRedirect(Device) ||
m_ControlDevice->ShouldHide(Device.DeviceDescriptor()))
{
if (Device.MakeRedirected())
{
Expand Down Expand Up @@ -628,21 +629,30 @@ bool CUsbDkFilterDevice::CStrategist::SelectStrategy(PDEVICE_OBJECT DevObj)
return true;
}

// Configuration doesn't tell to redirect or device already redirected -> no strategy
if (!m_Strategy->GetControlDevice()->ShouldRedirect(ID))
// Configuration tells to redirect -> redirector strategy
if (m_Strategy->GetControlDevice()->ShouldRedirect(ID))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Do not redirect or already redirected device, no strategy assigned");
return false;
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Assigning redirected USB device strategy");
m_DevStrategy.SetDeviceID(DevID.detach());
m_DevStrategy.SetInstanceID(InstanceID.detach());
m_Strategy->Delete();
m_Strategy = &m_DevStrategy;
return true;
}

// Redirector strategy
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Assigning redirected USB device strategy");
m_DevStrategy.SetDeviceID(DevID.detach());
m_DevStrategy.SetInstanceID(InstanceID.detach());
m_Strategy->Delete();
m_Strategy = &m_DevStrategy;
// Should be hidden -> hider strategy
if (m_Strategy->GetControlDevice()->ShouldHide(DevDescr))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Assigning hidden USB device strategy");
m_Strategy->Delete();
m_Strategy = &m_HiderStrategy;
return true;
}

return true;
// No strategy
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Do not redirect or already redirected device, no strategy assigned");

return false;
}

size_t CUsbDkFilterDevice::CStrategist::GetRequestContextSize()
Expand Down
1 change: 1 addition & 0 deletions UsbDk/FilterDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class CUsbDkFilterDevice : public CWdfDevice,
CUsbDkFilterStrategy *m_Strategy = nullptr;
CUsbDkNullFilterStrategy m_NullStrategy;
CUsbDkHubFilterStrategy m_HubStrategy;
CUsbDkHiderStrategy m_HiderStrategy;
CUsbDkRedirectorStrategy m_DevStrategy;
} m_Strategy;

Expand Down

0 comments on commit a9bbb92

Please sign in to comment.