ReactOS 0.4.15-dev-7931-gfd331f1
fxdeviceinterfaceum.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxDeviceInterfaceUM.cpp
8
9Abstract:
10
11 This module implements the device interface object.
12
13Author:
14
15
16
17Environment:
18
19 User mode only
20
21Revision History:
22
23--*/
24
25#include "FxSupportPch.hpp"
26
27extern "C" {
28#include "FxDeviceInterfaceUM.tmh"
29}
30
32 )
33/*++
34
35Routine Description:
36 Constructor for the object. Initializes all fields
37
38Arguments:
39 None
40
41Return Value:
42 None
43
44 --*/
45{
47
50
52
53 m_State = FALSE;
54}
55
57/*++
58
59Routine Description:
60 Destructor for FxDeviceInterface. Cleans up any allocations previously
61 allocated.
62
63Arguments:
64 None
65
66Return Value:
67 None
68
69 --*/
70{
71 // the device interface should be off now
73
74 // should no longer be in any list
76
80 }
81
84 }
85}
86
90 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
91 __in CONST GUID* InterfaceGUID,
93 )
94/*++
95
96Routine Description:
97 Initializes the object with the interface GUID and optional reference string
98
99Arguments:
100 InterfaceGUID - GUID describing the interface
101
102 ReferenceString - string used to differentiate between 2 interfaces on the
103 same PDO
104
105Return Value:
106 STATUS_SUCCESS or STATUS_INSUFFICIENT_RESOURCES
107
108 --*/
109{
110 RtlCopyMemory(&m_InterfaceClassGUID, InterfaceGUID, sizeof(GUID));
111
112 if (ReferenceString != NULL) {
113 return FxDuplicateUnicodeString(FxDriverGlobals,
116 }
117 else {
118 return STATUS_SUCCESS;
119 }
120}
121
122
123VOID
126 )
127/*++
128
129Routine Description:
130 Sets the state of the device interface
131
132Arguments:
133 State - the state to set
134
135
136Return Value:
137 None.
138
139 --*/
140{
141 HRESULT hr;
143 IWudfDeviceStack *pDeviceStack;
144
145
146
147
148 //
149 // Get the IWudfDeviceStack interface
150 //
151 pDeviceStack = m_Device->GetDeviceStackInterface();
152
153 //
154 // Enable the interface
155 //
156 hr = pDeviceStack->SetDeviceInterfaceState(&this->m_InterfaceClassGUID,
158 State);
159
160 if (SUCCEEDED(hr)) {
161 m_State = State;
162 }
163 else {
164 status = FxDevice::NtStatusFromHr(pDeviceStack, hr);
166 FxDevice::GetFxDevice(m_Device)->GetDriverGlobals(),
168 "Failed to %s device interface %!STATUS!",
169 (State ? "enable" : "disable"), status);
170
171
172
173
174
175 }
176}
177
182 )
183/*++
184
185Routine Description:
186 Registers the device interface for a given PDO
187
188Arguments:
189 DeviceObject - FDO for the device stack in case of UM, and PDO for
190 in case of KM.
191
192Return Value:
193 returned by IWudfDeviceStack::CreateDeviceInterface
194
195 --*/
196{
197 HRESULT hr;
199 IWudfDeviceStack *pDeviceStack;
200
202
203 //
204 // Get the IWudfDeviceStack interface
205 //
206 pDeviceStack = m_Device->GetDeviceStackInterface();
207
208 hr = pDeviceStack->CreateDeviceInterface(&m_InterfaceClassGUID,
210
211 if (SUCCEEDED(hr)) {
213 }
214 else {
215 status = FxDevice::NtStatusFromHr(pDeviceStack, hr);
216 }
217
218 return status;
219}
220
225 )
226{
228
229 //
230 // For UMDF, PDO is already known so no reason to defer registration.
231 // Also, note that Register takes fdo as parameter for UMDF.
232 //
233 status = Register(Device->GetDeviceObject());
234
235 return status;
236}
237
240 _In_ FxString* LinkString
241 )
242{
244 PCWSTR symLink = NULL;
245
247 IWudfDeviceStack *pDeviceStack;
248 IWudfDeviceStack2 *pDeviceStack2;
249
250 //
251 // Get the IWudfDeviceStack interface
252 //
253 pDeviceStack = m_Device->GetDeviceStackInterface();
255 HRESULT hr;
256
257 hrQI = pDeviceStack->QueryInterface(IID_IWudfDeviceStack2,
258 (PVOID*)&pDeviceStack2);
259 FX_VERIFY(INTERNAL, CHECK_QI(hrQI, pDeviceStack2));
260 pDeviceStack->Release();
261
262 //
263 // Get the symbolic link
264 //
265 hr = pDeviceStack2->GetInterfaceSymbolicLink(&m_InterfaceClassGUID,
267 &symLink);
268 if (FAILED(hr)) {
270 }
271 else {
274 }
275 }
276 else {
278 }
279
280 if (NT_SUCCESS(status)) {
281 //
282 // Attempt a copy
283 //
284 status = LinkString->Assign(&m_SymbolicLinkName);
285 }
286
287 return status;
288}
289
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ NTSTATUS Initialize(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in CONST GUID *InterfaceGUID, __in_opt PCUNICODE_STRING ReferenceString)
VOID SetState(__in BOOLEAN State)
UNICODE_STRING m_SymbolicLinkName
MdDeviceObject m_Device
UNICODE_STRING m_ReferenceString
NTSTATUS GetSymbolicLinkName(_In_ FxString *LinkString)
_Must_inspect_result_ NTSTATUS Register(__in MdDeviceObject Pdo)
SINGLE_LIST_ENTRY m_Entry
static NTSTATUS NtStatusFromHr(_In_ IWudfDeviceStack *DevStack, _In_ HRESULT Hr)
Definition: fxdeviceum.cpp:826
static FxDevice * GetFxDevice(__in MdDeviceObject DeviceObject)
Definition: fxdeviceum.cpp:60
static __inline VOID MxFreePool(__in PVOID Ptr)
Definition: mxmemorykm.h:41
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define TRACINGPNP
Definition: dbgtrace.h:67
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FX_VERIFY(INTERNAL, CHECK_NOT_NULL(LoaderInterface->pIWudfHost))
HRESULT hrQI
Definition: framework.cpp:106
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define CONST
Definition: pedump.c:81
#define STATUS_SUCCESS
Definition: shellext.h:65
HRESULT hr
Definition: shlfolder.c:183
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
_Must_inspect_result_ NTSTATUS FxDuplicateUnicodeString(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in const UNICODE_STRING *Source, __out PUNICODE_STRING Destination)
Definition: stringutil.cpp:180
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
Definition: ps.c:97
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ CONST GUID _In_opt_ PCUNICODE_STRING ReferenceString
Definition: wdfdevice.h:3630