Something went wrong. Try again.
Reactos
Something went wrong. Try again.
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290/*++
Copyright (c) Microsoft Corporation
Module Name:
FxDeviceInterfaceUM.cpp
Abstract:
This module implements the device interface object.
Author:
Environment:
User mode only
Revision History:
--*/
#include "FxSupportPch.hpp"
extern "C" {#include "FxDeviceInterfaceUM.tmh"}
FxDeviceInterface::FxDeviceInterface( )/*++
Routine Description: Constructor for the object. Initializes all fields
Arguments: None
Return Value: None
--*/{ RtlZeroMemory(&m_InterfaceClassGUID, sizeof(m_InterfaceClassGUID));
RtlZeroMemory(&m_SymbolicLinkName, sizeof(m_SymbolicLinkName)); RtlZeroMemory(&m_ReferenceString, sizeof(m_ReferenceString));
m_Entry.Next = NULL;
m_State = FALSE;}
FxDeviceInterface::~FxDeviceInterface()/*++
Routine Description: Destructor for FxDeviceInterface. Cleans up any allocations previously allocated.
Arguments: None
Return Value: None
--*/{ // the device interface should be off now ASSERT(m_State == FALSE);
// should no longer be in any list ASSERT(m_Entry.Next == NULL);
if (m_ReferenceString.Buffer != NULL) { FxPoolFree(m_ReferenceString.Buffer); RtlZeroMemory(&m_ReferenceString, sizeof(m_ReferenceString)); }
if (m_SymbolicLinkName.Buffer != NULL) { MxMemory::MxFreePool(m_SymbolicLinkName.Buffer); }}
_Must_inspect_result_NTSTATUSFxDeviceInterface::Initialize( __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in CONST GUID* InterfaceGUID, __in_opt PCUNICODE_STRING ReferenceString )/*++
Routine Description: Initializes the object with the interface GUID and optional reference string
Arguments: InterfaceGUID - GUID describing the interface
ReferenceString - string used to differentiate between 2 interfaces on the same PDO
Return Value: STATUS_SUCCESS or STATUS_INSUFFICIENT_RESOURCES
--*/{ RtlCopyMemory(&m_InterfaceClassGUID, InterfaceGUID, sizeof(GUID));
if (ReferenceString != NULL) { return FxDuplicateUnicodeString(FxDriverGlobals, ReferenceString, &m_ReferenceString); } else { return STATUS_SUCCESS; }}
VOIDFxDeviceInterface::SetState( __in BOOLEAN State )/*++
Routine Description: Sets the state of the device interface
Arguments: State - the state to set
Return Value: None.
--*/{ HRESULT hr; NTSTATUS status; IWudfDeviceStack *pDeviceStack;
// // Get the IWudfDeviceStack interface // pDeviceStack = m_Device->GetDeviceStackInterface();
// // Enable the interface // hr = pDeviceStack->SetDeviceInterfaceState(&this->m_InterfaceClassGUID, this->m_ReferenceString.Buffer, State);
if (SUCCEEDED(hr)) { m_State = State; } else { status = FxDevice::NtStatusFromHr(pDeviceStack, hr); DoTraceLevelMessage( FxDevice::GetFxDevice(m_Device)->GetDriverGlobals(), TRACE_LEVEL_WARNING, TRACINGPNP, "Failed to %s device interface %!STATUS!", (State ? "enable" : "disable"), status);
}}
_Must_inspect_result_NTSTATUSFxDeviceInterface::Register( __in MdDeviceObject DeviceObject )/*++
Routine Description: Registers the device interface for a given PDO
Arguments: DeviceObject - FDO for the device stack in case of UM, and PDO for in case of KM.
Return Value: returned by IWudfDeviceStack::CreateDeviceInterface
--*/{ HRESULT hr; NTSTATUS status; IWudfDeviceStack *pDeviceStack;
m_Device = DeviceObject;
// // Get the IWudfDeviceStack interface // pDeviceStack = m_Device->GetDeviceStackInterface();
hr = pDeviceStack->CreateDeviceInterface(&m_InterfaceClassGUID, m_ReferenceString.Buffer);
if (SUCCEEDED(hr)) { status = STATUS_SUCCESS; } else { status = FxDevice::NtStatusFromHr(pDeviceStack, hr); }
return status;}
_Must_inspect_result_NTSTATUSFxDeviceInterface::Register( _In_ FxDevice* Device ){ NTSTATUS status;
// // For UMDF, PDO is already known so no reason to defer registration. // Also, note that Register takes fdo as parameter for UMDF. // status = Register(Device->GetDeviceObject());
return status;}
NTSTATUSFxDeviceInterface::GetSymbolicLinkName( _In_ FxString* LinkString ){ NTSTATUS status; PCWSTR symLink = NULL;
if (m_SymbolicLinkName.Buffer == NULL) { IWudfDeviceStack *pDeviceStack; IWudfDeviceStack2 *pDeviceStack2;
// // Get the IWudfDeviceStack interface // pDeviceStack = m_Device->GetDeviceStackInterface(); HRESULT hrQI; HRESULT hr;
hrQI = pDeviceStack->QueryInterface(IID_IWudfDeviceStack2, (PVOID*)&pDeviceStack2); FX_VERIFY(INTERNAL, CHECK_QI(hrQI, pDeviceStack2)); pDeviceStack->Release();
// // Get the symbolic link // hr = pDeviceStack2->GetInterfaceSymbolicLink(&m_InterfaceClassGUID, m_ReferenceString.Buffer, &symLink); if (FAILED(hr)) { status = FxDevice::GetFxDevice(m_Device)->NtStatusFromHr(hr); } else { RtlInitUnicodeString(&m_SymbolicLinkName, symLink); status = STATUS_SUCCESS; } } else { status = STATUS_SUCCESS; }
if (NT_SUCCESS(status)) { // // Attempt a copy // status = LinkString->Assign(&m_SymbolicLinkName); }
return status;}