ReactOS  0.4.15-dev-3299-gbe8e5fc
fxdeviceinterfaceum.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxDeviceInterfaceUM.cpp
8 
9 Abstract:
10 
11  This module implements the device interface object.
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  User mode only
20 
21 Revision History:
22 
23 --*/
24 
25 #include "FxSupportPch.hpp"
26 
27 extern "C" {
28 #include "FxDeviceInterfaceUM.tmh"
29 }
30 
32  )
33 /*++
34 
35 Routine Description:
36  Constructor for the object. Initializes all fields
37 
38 Arguments:
39  None
40 
41 Return Value:
42  None
43 
44  --*/
45 {
47 
50 
51  m_Entry.Next = NULL;
52 
53  m_State = FALSE;
54 }
55 
57 /*++
58 
59 Routine Description:
60  Destructor for FxDeviceInterface. Cleans up any allocations previously
61  allocated.
62 
63 Arguments:
64  None
65 
66 Return Value:
67  None
68 
69  --*/
70 {
71  // the device interface should be off now
72  ASSERT(m_State == FALSE);
73 
74  // should no longer be in any list
75  ASSERT(m_Entry.Next == NULL);
76 
77  if (m_ReferenceString.Buffer != NULL) {
80  }
81 
84  }
85 }
86 
90  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
91  __in CONST GUID* InterfaceGUID,
93  )
94 /*++
95 
96 Routine Description:
97  Initializes the object with the interface GUID and optional reference string
98 
99 Arguments:
100  InterfaceGUID - GUID describing the interface
101 
102  ReferenceString - string used to differentiate between 2 interfaces on the
103  same PDO
104 
105 Return 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 
123 VOID
126  )
127 /*++
128 
129 Routine Description:
130  Sets the state of the device interface
131 
132 Arguments:
133  State - the state to set
134 
135 
136 Return 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);
168  "Failed to %s device interface %!STATUS!",
169  (State ? "enable" : "disable"), status);
170 
171 
172 
173 
174 
175  }
176 }
177 
179 NTSTATUS
182  )
183 /*++
184 
185 Routine Description:
186  Registers the device interface for a given PDO
187 
188 Arguments:
189  DeviceObject - FDO for the device stack in case of UM, and PDO for
190  in case of KM.
191 
192 Return 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 
222 NTSTATUS
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 
238 NTSTATUS
240  _In_ FxString* LinkString
241  )
242 {
244  PCWSTR symLink = NULL;
245 
246  if (m_SymbolicLinkName.Buffer == NULL) {
247  IWudfDeviceStack *pDeviceStack;
248  IWudfDeviceStack2 *pDeviceStack2;
249 
250  //
251  // Get the IWudfDeviceStack interface
252  //
253  pDeviceStack = m_Device->GetDeviceStackInterface();
254  HRESULT hrQI;
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 
const uint16_t * PCWSTR
Definition: typedefs.h:57
UNICODE_STRING m_ReferenceString
_Must_inspect_result_ NTSTATUS Register(__in MdDeviceObject Pdo)
HRESULT hr
Definition: shlfolder.c:183
#define __in_opt
Definition: dbghelp.h:38
_Must_inspect_result_ NTSTATUS Initialize(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in CONST GUID *InterfaceGUID, __in_opt PCUNICODE_STRING ReferenceString)
LONG NTSTATUS
Definition: precomp.h:26
static FxDevice * GetFxDevice(__in MdDeviceObject DeviceObject)
Definition: fxdeviceum.cpp:60
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
NTSTATUS GetSymbolicLinkName(_In_ FxString *LinkString)
UNICODE_STRING m_SymbolicLinkName
static __inline VOID MxFreePool(__in PVOID Ptr)
Definition: mxmemorykm.h:41
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
if SUCCEEDED(hr)
unsigned char BOOLEAN
static NTSTATUS NtStatusFromHr(_In_ IWudfDeviceStack *DevStack, _In_ HRESULT Hr)
Definition: fxdeviceum.cpp:826
#define _In_
Definition: ms_sal.h:308
HRESULT hrQI
Definition: framework.cpp:106
VOID SetState(__in BOOLEAN State)
FX_VERIFY(INTERNAL, CHECK_NOT_NULL(LoaderInterface->pIWudfHost))
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LONG HRESULT
Definition: typedefs.h:79
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
_Must_inspect_result_ NTSTATUS FxDuplicateUnicodeString(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in const UNICODE_STRING *Source, __out PUNICODE_STRING Destination)
Definition: stringutil.cpp:180
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
#define TRACINGPNP
Definition: dbgtrace.h:67
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
_Must_inspect_result_ _In_ WDFDEVICE _In_ CONST GUID _In_opt_ PCUNICODE_STRING ReferenceString
Definition: wdfdevice.h:3625
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
SINGLE_LIST_ENTRY m_Entry
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
MdDeviceObject m_Device
#define STATUS_SUCCESS
Definition: shellext.h:65
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
#define __in
Definition: dbghelp.h:35
static SERVICE_STATUS status
Definition: service.c:31
#define CONST
Definition: pedump.c:81
Definition: ps.c:97