ReactOS  0.4.15-dev-2991-g632fa1c
fxdeviceinterfaceapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxDeviceInterfaceAPI.cpp
8 
9 Abstract:
10 
11  This module implements the device interface object external APIs
12 
13 Author:
14 
15 
16 
17 
18 Environment:
19 
20  kernel and user mode
21 
22 Revision History:
23 
24 --*/
25 
26 #include "fxsupportpch.hpp"
27 
28 extern "C" {
29 // #include "FxDeviceInterfaceAPI.tmh"
30 }
31 
32 //
33 // extern "C" the entire file
34 //
35 extern "C" {
36 
40 STDCALL
41 WDFEXPORT(WdfDeviceCreateDeviceInterface)(
42  __in
44  __in
45  WDFDEVICE Device,
46  __in
48  __in_opt
50  )
51 /*++
52 
53 Routine Description:
54  Creates a device interface associated with the passed in device object
55 
56 Arguments:
57  Device - Handle which represents the device exposing the interface
58 
59  InterfaceGUID - GUID describing the interface being exposed
60 
61  ReferenceString - OPTIONAL string which allows the driver writer to
62  distinguish between different exposed interfaces
63 
64 Return Value:
65  STATUS_SUCCESS or appropriate NTSTATUS code
66 
67  --*/
68 {
69  DDI_ENTRY();
70 
77 
79  Device,
81  (PVOID*) &pDevice,
83 
85 
87  if (!NT_SUCCESS(status)) {
88  return status;
89  }
90 
93  if (!NT_SUCCESS(status)) {
94  return status;
95  }
96  }
97 
98  if (pDevice->IsLegacy()) {
100 
103  "WDFDEVICE %p is not a PNP device, device interface creation not "
104  "allowed %!STATUS!", Device, status);
105 
106  return status;
107  }
108 
110 
113 
116  "WDFDEVICE %p DeviceInterface object creation failed, %!STATUS!",
117  Device, status);
118 
119  return status;
120  }
121 
125 
126  if (!NT_SUCCESS(status)) {
129  "WDFDEVICE %p, DeviceInterface object initialization failed, %!STATUS!",
130  Device, status );
131 
132  goto Done;
133  }
134 
136 
138 
140 
142  //
143  // Insert into the end of the list
144  //
147  while (pCur != NULL) {
148  ppPrev = &pCur->Next;
149  pCur = pCur->Next;
150  }
151 
153  }
154 
156 
157 Done:
158  if (!NT_SUCCESS(status)) {
161  }
162 
163  return status;
164 }
165 
167 VOID
168 STDCALL
169 WDFEXPORT(WdfDeviceSetDeviceInterfaceState)(
170  __in
172  __in
173  WDFDEVICE Device,
174  __in
176  __in_opt
178  __in
179  BOOLEAN State
180  )
181 {
182  DDI_ENTRY();
183 
187  FxDevice* pDevice;
188  FxPkgPnp* pPkgPnp;
189 
191  Device,
193  (PVOID*) &pDevice,
195 
197 
199  if (!NT_SUCCESS(status)) {
201  return;
202  }
203 
204  if (RefString != NULL) {
206  if (!NT_SUCCESS(status)) {
208  return;
209  }
210  }
211 
212  if (pDevice->IsLegacy()) {
215  "WDFDEVICE %p is not a PNP device, device interfaces not allowed",
216  Device);
218  return;
219  }
220 
222 
224 
225  //
226  // Iterate over the interfaces and see if we have a match
227  //
229  FxDeviceInterface *pDI;
230 
232 
234  if (RefString != NULL) {
235  if ((RefString->Length == pDI->m_ReferenceString.Length)
236  &&
237  (RtlCompareMemory(RefString->Buffer,
239  RefString->Length) == RefString->Length)) {
240  //
241  // They match, carry on
242  //
243  DO_NOTHING();
244  }
245  else {
246  //
247  // The ref strings do not match, continue on in the search
248  // of the collection.
249  //
250  continue;
251  }
252  }
253  else if (pDI->m_ReferenceString.Length > 0) {
254  //
255  // Caller didn't specify a ref string but this interface has
256  // one, continue on in the search through the collection.
257  //
258  continue;
259  }
260 
261  //
262  // Set the state and break out of the loop because we found our
263  // interface.
264  //
265  pDI->SetState(State);
266  break;
267  }
268  }
269 
271 }
272 
275 NTSTATUS
276 STDCALL
277 WDFEXPORT(WdfDeviceRetrieveDeviceInterfaceString)(
278  __in
280  __in
281  WDFDEVICE Device,
282  __in
284  __in_opt
286  __in
287  WDFSTRING String
288  )
289 /*++
290 
291 Routine Description:
292  Returns the symbolic link value of the registered device interface.
293 
294 Arguments:
295 
296 
297 Return Value:
298 
299 
300  --*/
301 
302 {
303  DDI_ENTRY();
304 
307  FxDevice* pDevice;
308  FxPkgPnp* pPkgPnp;
311 
313  Device,
315  (PVOID*) &pDevice,
316  &pFxDriverGlobals );
317 
319 
321  if (!NT_SUCCESS(status)) {
322  return status;
323  }
324 
325  if (RefString != NULL) {
327  if (!NT_SUCCESS(status)) {
328  return status;
329  }
330  }
331 
332  if (pDevice->IsLegacy()) {
334 
337  "WDFDEVICE %p is not a PNP device, device interface creation not "
338  "allowed %!STATUS!", Device, status);
339 
340  return status;
341  }
342 
344  String,
346  (PVOID*) &pString);
347 
349 
351 
353 
354  //
355  // Iterate over the interfaces and see if we have a match
356  //
358  ple != NULL;
359  ple = ple->Next) {
360  FxDeviceInterface *pDI;
361 
363 
365  if (RefString != NULL) {
366  if ((RefString->Length == pDI->m_ReferenceString.Length)
367  &&
368  (RtlCompareMemory(RefString->Buffer,
370  RefString->Length) == RefString->Length)) {
371  //
372  // They match, carry on
373  //
374  DO_NOTHING();
375  }
376  else {
377  //
378  // The ref strings do not match, continue on in the search
379  // of the collection.
380  //
381  continue;
382  }
383  }
384  else if (pDI->m_ReferenceString.Length > 0) {
385  //
386  // Caller didn't specify a ref string but this interface has
387  // one, continue on in the search through the collection.
388  //
389  continue;
390  }
391 
393 
394  break;
395  }
396  }
397 
399 
400  return status;
401 }
402 
403 } // extern "C"
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
UNICODE_STRING m_ReferenceString
_Must_inspect_result_ NTSTATUS Register(__in MdDeviceObject Pdo)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
static FxDeviceInterface * _FromEntry(__in PSINGLE_LIST_ENTRY Entry)
Definition: ntbasedef.h:628
_Must_inspect_result_ __in WDFDEVICE __in CONST GUID * InterfaceClassGUID
#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)
__in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING RefString
FxDeviceInterface * pDeviceInterface
LONG NTSTATUS
Definition: precomp.h:26
FxString * pString
_Must_inspect_result_ __in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING ReferenceString
NTSTATUS GetSymbolicLinkName(_In_ FxString *LinkString)
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_Must_inspect_result_ BOOLEAN __inline FxIsEqualGuid(__in CONST GUID *Lhs, __in CONST GUID *Rhs)
Definition: fxglobals.h:977
DriverGlobals
__inline BOOLEAN IsLegacy(VOID)
Definition: fxdevice.hpp:1209
PSINGLE_LIST_ENTRY ple
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
FxDevice * pDevice
_Must_inspect_result_ __in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING __in WDFSTRING String
_Must_inspect_result_ __drv_maxIRQL(PASSIVE_LEVEL) NTSTATUS STDCALL WDFEXPORT(WdfDeviceCreateDeviceInterface)(__in PWDF_DRIVER_GLOBALS DriverGlobals
unsigned char BOOLEAN
FxPkgPnp * pPkgPnp
FxObjectHandleGetPtr(pFxDriverGlobals, String, FX_TYPE_STRING,(PVOID *) &pString)
VOID SetState(__in BOOLEAN State)
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define STDCALL
Definition: wdf.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FxWaitLockInternal m_DeviceInterfaceLock
Definition: fxpkgpnp.hpp:4124
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
SINGLE_LIST_ENTRY m_DeviceInterfaceHead
Definition: fxpkgpnp.hpp:4126
_Must_inspect_result_ NTSTATUS __inline FxValidateUnicodeString(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PCUNICODE_STRING String)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
FxPkgPnp * m_PkgPnp
Definition: fxdevice.hpp:670
__in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING __in BOOLEAN State
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *) &pDevice, &pFxDriverGlobals)
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ CONST GUID _In_opt_ PCUNICODE_STRING ReferenceString
Definition: wdfdevice.h:3625
SINGLE_LIST_ENTRY * pCur
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
PFX_DRIVER_GLOBALS pFxDriverGlobals
SINGLE_LIST_ENTRY m_Entry
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ _In_ WDFDEVICE _In_ CONST GUID * InterfaceClassGUID
Definition: wdfdevice.h:3625
#define TRACINGERROR
Definition: dbgtrace.h:63
FxPointerNotNull(pFxDriverGlobals, InterfaceClassGUID)
#define __in
Definition: dbghelp.h:35
_Must_inspect_result_ __in WDFDEVICE Device
#define CONST
Definition: pedump.c:81
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
FxVerifierDbgBreakPoint(pFxDriverGlobals)
SINGLE_LIST_ENTRY ** ppPrev
NTSTATUS status
#define DO_NOTHING()
Definition: mxgeneral.h:32
Definition: ps.c:97