ReactOS 0.4.16-dev-197-g92996da
fxdeviceinterfaceapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxDeviceInterfaceAPI.cpp
8
9Abstract:
10
11 This module implements the device interface object external APIs
12
13Author:
14
15
16
17
18Environment:
19
20 kernel and user mode
21
22Revision History:
23
24--*/
25
26#include "fxsupportpch.hpp"
27
28extern "C" {
29// #include "FxDeviceInterfaceAPI.tmh"
30}
31
32//
33// extern "C" the entire file
34//
35extern "C" {
36
41WDFEXPORT(WdfDeviceCreateDeviceInterface)(
42 __in
44 __in
45 WDFDEVICE Device,
46 __in
50 )
51/*++
52
53Routine Description:
54 Creates a device interface associated with the passed in device object
55
56Arguments:
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
64Return Value:
65 STATUS_SUCCESS or appropriate NTSTATUS code
66
67 --*/
68{
69 DDI_ENTRY();
70
77
79 Device,
81 (PVOID*) &pDevice,
83
85
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
157Done:
158 if (!NT_SUCCESS(status)) {
159 delete pDeviceInterface;
161 }
162
163 return status;
164}
165
167VOID
169WDFEXPORT(WdfDeviceSetDeviceInterfaceState)(
170 __in
172 __in
173 WDFDEVICE Device,
174 __in
178 __in
180 )
181{
182 DDI_ENTRY();
183
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 //
230
232
234 if (RefString != NULL) {
235 if ((RefString->Length == pDI->m_ReferenceString.Length)
236 &&
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
277WDFEXPORT(WdfDeviceRetrieveDeviceInterfaceString)(
278 __in
280 __in
281 WDFDEVICE Device,
282 __in
286 __in
287 WDFSTRING String
288 )
289/*++
290
291Routine Description:
292 Returns the symbolic link value of the registered device interface.
293
294Arguments:
295
296
297Return Value:
298
299
300 --*/
301
302{
303 DDI_ENTRY();
304
311
313 Device,
315 (PVOID*) &pDevice,
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) {
361
363
365 if (RefString != NULL) {
366 if ((RefString->Length == pDI->m_ReferenceString.Length)
367 &&
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"
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)
static FxDeviceInterface * _FromEntry(__in PSINGLE_LIST_ENTRY Entry)
UNICODE_STRING m_ReferenceString
NTSTATUS GetSymbolicLinkName(_In_ FxString *LinkString)
_Must_inspect_result_ NTSTATUS Register(__in MdDeviceObject Pdo)
SINGLE_LIST_ENTRY m_Entry
FxPkgPnp * m_PkgPnp
Definition: fxdevice.hpp:670
__inline BOOLEAN IsLegacy(VOID)
Definition: fxdevice.hpp:1209
SINGLE_LIST_ENTRY m_DeviceInterfaceHead
Definition: fxpkgpnp.hpp:4126
FxWaitLockInternal m_DeviceInterfaceLock
Definition: fxpkgpnp.hpp:4124
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define TRACINGERROR
Definition: dbgtrace.h:63
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define PagedPool
Definition: env_spec_w32.h:308
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
FxDevice * pDevice
__in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING __in BOOLEAN State
SINGLE_LIST_ENTRY * pCur
FxDeviceInterface * pDeviceInterface
FxPkgPnp * pPkgPnp
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *) &pDevice, &pFxDriverGlobals)
_Must_inspect_result_ __in WDFDEVICE Device
NTSTATUS status
__in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING RefString
FxString * pString
PSINGLE_LIST_ENTRY ple
_Must_inspect_result_ __in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING ReferenceString
SINGLE_LIST_ENTRY ** ppPrev
_Must_inspect_result_ __in WDFDEVICE __in CONST GUID * InterfaceClassGUID
_Must_inspect_result_ __in WDFDEVICE __in CONST GUID __in_opt PCUNICODE_STRING __in WDFSTRING String
FxObjectHandleGetPtr(pFxDriverGlobals, String, FX_TYPE_STRING,(PVOID *) &pString)
PFX_DRIVER_GLOBALS pFxDriverGlobals
FxVerifierDbgBreakPoint(pFxDriverGlobals)
DriverGlobals
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ BOOLEAN __inline FxIsEqualGuid(__in CONST GUID *Lhs, __in CONST GUID *Rhs)
Definition: fxglobals.h:977
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
@ FX_TYPE_DEVICE
Definition: fxtypes.h:47
@ FX_TYPE_STRING
Definition: fxtypes.h:52
_Must_inspect_result_ NTSTATUS __inline FxValidateUnicodeString(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PCUNICODE_STRING String)
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define DO_NOTHING()
Definition: mxgeneral.h:32
#define CONST
Definition: pedump.c:81
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ntbasedef.h:628
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
Definition: ps.c:97
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STDCALL
Definition: wdf.h:45
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_Must_inspect_result_ _In_ WDFDEVICE _In_ CONST GUID _In_opt_ PCUNICODE_STRING ReferenceString
Definition: wdfdevice.h:3630
_Must_inspect_result_ _In_ WDFDEVICE _In_ CONST GUID * InterfaceClassGUID
Definition: wdfdevice.h:3627
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433