From eb9942e5dc2ed683b5a23a00de6f487475af2c22 Mon Sep 17 00:00:00 2001 From: Pavel Gurvich Date: Wed, 10 Sep 2014 15:31:54 +0300 Subject: [PATCH] UsbDk: drop unused DeviceAccess logic This patch removes CWdfDeviceAccess class, merges CDeviceAccess with CWdmDeviceAccess and removes unused CWdmDeviceAccess code. Signed-off-by: Pavel Gurvich Signed-off-by: Dmitry Fleytman --- UsbDk/DeviceAccess.cpp | 87 +----------------------------------------- UsbDk/DeviceAccess.h | 70 ++++++--------------------------- 2 files changed, 13 insertions(+), 144 deletions(-) diff --git a/UsbDk/DeviceAccess.cpp b/UsbDk/DeviceAccess.cpp index 599e5e2..c8d5d06 100644 --- a/UsbDk/DeviceAccess.cpp +++ b/UsbDk/DeviceAccess.cpp @@ -77,7 +77,7 @@ CWdmUSBD::~CWdmUSBD() } #endif -ULONG CDeviceAccess::GetAddress() +ULONG CWdmDeviceAccess::GetAddress() { DEVICE_CAPABILITIES Capabilities; @@ -89,39 +89,6 @@ ULONG CDeviceAccess::GetAddress() return Capabilities.Address; } -PWCHAR CWdfDeviceAccess::QueryBusID(BUS_QUERY_ID_TYPE idType) -{ - UNREFERENCED_PARAMETER(idType); - ASSERT(!"NOT IMPLEMENTED"); - return nullptr; -} - -NTSTATUS CWdfDeviceAccess::QueryCapabilities(DEVICE_CAPABILITIES &Capabilities) -{ - UNREFERENCED_PARAMETER(Capabilities); - ASSERT(!"NOT IMPLEMENTED"); - return STATUS_NOT_IMPLEMENTED; -} - -CMemoryBuffer *CWdfDeviceAccess::GetDeviceProperty(DEVICE_REGISTRY_PROPERTY propertyId) -{ - PAGED_CODE(); - WDFMEMORY devProperty; - - NTSTATUS status = WdfDeviceAllocAndQueryProperty(m_DevObj, - propertyId, - NonPagedPool, - WDF_NO_OBJECT_ATTRIBUTES, - &devProperty); - - if (NT_SUCCESS(status)) - { - return CMemoryBuffer::GetMemoryBuffer(devProperty); - } - - return nullptr; -} - PWCHAR CWdmDeviceAccess::QueryBusID(BUS_QUERY_ID_TYPE idType) { CIrp irp; @@ -219,58 +186,6 @@ PWCHAR CWdmDeviceAccess::MakeNonPagedDuplicate(BUS_QUERY_ID_TYPE idType, PWCHAR return static_cast(newIdData); } -CMemoryBuffer *CWdmDeviceAccess::GetDeviceProperty(DEVICE_REGISTRY_PROPERTY propertyId) -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVACCESS, "%!FUNC! Entry for device 0x%p, %!devprop!", m_DevObj, propertyId); - - PAGED_CODE(); - - ULONG bytesNeeded = 0; - auto status = IoGetDeviceProperty(m_DevObj, propertyId, 0, nullptr, &bytesNeeded); - - if (!NT_SUCCESS(status)) - { - if (status == STATUS_BUFFER_TOO_SMALL) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVACCESS, - "%!FUNC! Property %!devprop! size for device 0x%p is %lu bytes", propertyId, m_DevObj, bytesNeeded); - - CObjHolder buffer(new CWdmMemoryBuffer()); - if (buffer) - { - status = buffer->Create(bytesNeeded, NonPagedPool); - if (!NT_SUCCESS(status)) - { - TraceEvents(TRACE_LEVEL_ERROR, TRACE_DEVACCESS, - "%!FUNC! Error %!STATUS! during memory buffer creation", status); - return nullptr; - } - - status = IoGetDeviceProperty(m_DevObj, propertyId, static_cast(buffer->Size()), buffer->Ptr(), &bytesNeeded); - if (NT_SUCCESS(status)) - { - TraceEvents(TRACE_LEVEL_ERROR, TRACE_DEVACCESS, - "%!FUNC! Error %!STATUS! while reading property for device 0x%p, %!devprop!", status, m_DevObj, propertyId); - return buffer.detach(); - } - } - } - else - { - TraceEvents(TRACE_LEVEL_ERROR, TRACE_DEVACCESS, - "%!FUNC! Error %!STATUS! while reading property for device 0x%p, %!devprop!", status, m_DevObj, propertyId); - } - } - else - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVACCESS, - "%!FUNC! Empty property read for device 0x%p, %!devprop!", m_DevObj, propertyId); - return CMemoryBuffer::GetMemoryBuffer(nullptr, 0); - } - - return nullptr; -} - NTSTATUS CWdmDeviceAccess::QueryForInterface(const GUID &guid, __out INTERFACE &intf, USHORT intfSize, USHORT intfVer, __in_opt PVOID intfCtx) { diff --git a/UsbDk/DeviceAccess.h b/UsbDk/DeviceAccess.h index f182472..800c3a3 100644 --- a/UsbDk/DeviceAccess.h +++ b/UsbDk/DeviceAccess.h @@ -28,62 +28,8 @@ #include "MemoryBuffer.h" #include "Public.h" -class CDeviceAccess : public CAllocatable -{ -public: - CRegText *GetHardwareIdProperty() { return new CRegText(GetDeviceProperty(DevicePropertyHardwareID)); }; - CRegText *GetDeviceID() { return QueryBusIDWrapped(BusQueryDeviceID); } - CRegText *GetInstanceID() { return QueryBusIDWrapped(BusQueryInstanceID); } - CRegText *GetHardwareIDs() { return QueryBusIDWrapped(BusQueryHardwareIDs); } - enum : ULONG - { - NO_ADDRESS = (ULONG) -1 - }; - - ULONG GetAddress(); - - virtual ~CDeviceAccess() - {} - -protected: - virtual CMemoryBuffer *GetDeviceProperty(DEVICE_REGISTRY_PROPERTY propertyId) = 0; - virtual PWCHAR QueryBusID(BUS_QUERY_ID_TYPE idType) = 0; - virtual NTSTATUS QueryCapabilities(DEVICE_CAPABILITIES &Capabilities) = 0; - - CDeviceAccess() - {} - -private: - - template - ResT *QueryBusIDWrapped(BUS_QUERY_ID_TYPE idType) - { return new ResT(QueryBusID(idType)); } - -}; - -class CWdfDeviceAccess : public CDeviceAccess -{ -public: - CWdfDeviceAccess(WDFDEVICE WdfDevice) - : m_DevObj(WdfDevice) - { WdfObjectReferenceWithTag(m_DevObj, (PVOID) 'DWHR'); } - - virtual ~CWdfDeviceAccess() - { WdfObjectDereferenceWithTag(m_DevObj, (PVOID) 'DWHR'); } - - CWdfDeviceAccess(const CWdfDeviceAccess&) = delete; - CWdfDeviceAccess& operator= (const CWdfDeviceAccess&) = delete; - -private: - virtual CMemoryBuffer *GetDeviceProperty(DEVICE_REGISTRY_PROPERTY propertyId) override; - virtual PWCHAR QueryBusID(BUS_QUERY_ID_TYPE idType) override; - virtual NTSTATUS QueryCapabilities(DEVICE_CAPABILITIES &Capabilities) override; - - WDFDEVICE m_DevObj; -}; - -class CWdmDeviceAccess : public CDeviceAccess +class CWdmDeviceAccess : public CAllocatable { public: CWdmDeviceAccess(PDEVICE_OBJECT WdmDevice) @@ -98,13 +44,21 @@ public: NTSTATUS QueryForInterface(const GUID &, __out INTERFACE &, USHORT intfSize, USHORT intfVer, __in_opt PVOID intfCtx = nullptr); + enum : ULONG + { + NO_ADDRESS = (ULONG)-1 + }; + + ULONG GetAddress(); + CRegText *GetDeviceID() { return new CRegSz(QueryBusID(BusQueryDeviceID)); } + CRegText *GetInstanceID() { return new CRegSz(QueryBusID(BusQueryInstanceID)); } + protected: PDEVICE_OBJECT m_DevObj; private: - virtual CMemoryBuffer *GetDeviceProperty(DEVICE_REGISTRY_PROPERTY propertyId) override; - virtual PWCHAR QueryBusID(BUS_QUERY_ID_TYPE idType) override; - virtual NTSTATUS QueryCapabilities(DEVICE_CAPABILITIES &Capabilities) override; + PWCHAR QueryBusID(BUS_QUERY_ID_TYPE idType); + NTSTATUS QueryCapabilities(DEVICE_CAPABILITIES &Capabilities); static PWCHAR MakeNonPagedDuplicate(BUS_QUERY_ID_TYPE idType, PWCHAR idData); static SIZE_T GetIdBufferLength(BUS_QUERY_ID_TYPE idType, PWCHAR idData);