diff --git a/UsbDk/FilterDevice.cpp b/UsbDk/FilterDevice.cpp index c70f5fc..15d8e18 100644 --- a/UsbDk/FilterDevice.cpp +++ b/UsbDk/FilterDevice.cpp @@ -1,7 +1,6 @@ #include "FilterDevice.h" #include "trace.h" #include "FilterDevice.tmh" -#include "Public.h" #include "DeviceAccess.h" #include "ControlDevice.h" @@ -121,59 +120,62 @@ UsbDkClonePdo(WDFDEVICE ParentDevice) return ClonePdo; } - -//TODO: Temporary function, printouts only -VOID UsbDkDumpHWIds(CDeviceAccess* devAcc) -{ - CObjHolder IDs(devAcc->GetHardwareIDs()); - - if (!IDs || IDs->empty()) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! No HW IDs read"); - } - else - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! HW IDs read"); - IDs->Dump(); - } - - CObjHolder DevIDs(devAcc->GetDeviceID()); - - if (!DevIDs || DevIDs->empty()) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! No Device IDs read"); - } - else - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! Device IDs read"); - DevIDs->Dump(); - } -} /////////////////////////////////////////////////////////////////////////////////////////////// +void CUsbDkFilterDevice::ClearChildrenList() +{ + m_ChildDevices.ForEachDetached([] (CUsbDkChildDevice* Child) { delete Child; }); +} + void CUsbDkFilterDevice::QDRPostProcessWi() { ASSERT(m_QDRIrp != NULL); TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Entry"); - PDEVICE_RELATIONS Relations = (PDEVICE_RELATIONS) m_QDRIrp->IoStatus.Information; + ClearChildrenList(); + + auto Relations = (PDEVICE_RELATIONS) m_QDRIrp->IoStatus.Information; if (Relations) { + for (ULONG i = 0; i < Relations->Count; i++) + { + CObjHolder pdoAccess(CDeviceAccess::GetDeviceAccess(Relations->Objects[i])); + CObjHolder DevID(pdoAccess->GetDeviceID()); + + if (!DevID || DevID->empty()) + { + TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! No Device IDs read"); + continue; + } + + CObjHolder InstanceID(pdoAccess->GetInstanceID()); + + if (!InstanceID || InstanceID->empty()) + { + TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! No Instance ID read"); + continue; + } + + CUsbDkChildDevice *Device = new CUsbDkChildDevice(DevID, InstanceID); + + if (Device == nullptr) + { + TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! Cannot allocate child device instance"); + continue; + } + + DevID.detach(); + InstanceID.detach(); + + m_ChildDevices.PushBack(Device); + } + if (Relations->Count > 0) { m_ClonedPdo = Relations->Objects[0]; - { - //TEMPORARY: To verify we see HW ids of PDO to be cloned - CObjHolder pdoAccess(CDeviceAccess::GetDeviceAccess(m_ClonedPdo)); - if (pdoAccess) - { - UsbDkDumpHWIds(pdoAccess); - } - } - WDFDEVICE PdoClone = UsbDkClonePdo(m_Device); if (PdoClone != WDF_NO_HANDLE) @@ -202,6 +204,7 @@ void CUsbDkFilterDevice::QDRPostProcessWi() CUsbDkFilterDevice::~CUsbDkFilterDevice() { + ClearChildrenList(); if (m_ControlDevice != nullptr) { m_ControlDevice->UnregisterFilter(*this); diff --git a/UsbDk/FilterDevice.h b/UsbDk/FilterDevice.h index fccd449..a207b74 100644 --- a/UsbDk/FilterDevice.h +++ b/UsbDk/FilterDevice.h @@ -61,6 +61,10 @@ public: NTSTATUS Create(PWDFDEVICE_INIT DevInit, WDFDRIVER Driver); NTSTATUS CreateFilterDevice(PWDFDEVICE_INIT DevInit); + template + void EnumerateChildren(TFunctor Functor) + { m_ChildDevices.ForEach(Functor); } + PLIST_ENTRY GetListEntry() { return &m_ListEntry; } static CUsbDkFilterDevice *GetByListEntry(PLIST_ENTRY entry) @@ -82,6 +86,7 @@ private: void CUsbDkFilterDevice::QDRPostProcessWi(); bool ShouldAttach(); + void ClearChildrenList(); CWdfWorkitem m_QDRCompletionWorkItem; @@ -89,6 +94,8 @@ private: PDEVICE_OBJECT m_ClonedPdo = nullptr; CUsbDkControlDevice *m_ControlDevice = nullptr; + CWdmList m_ChildDevices; + LIST_ENTRY m_ListEntry; CUsbDkFilterDevice(const CUsbDkFilterDevice&) = delete;