ReactOS 0.4.16-dev-1946-g52006dd
fxwmiapi.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxWmiApi.cpp
8
9Abstract:
10
11 This module implements the C interface to the WMI package
12 for the driver frameworks.
13
14Author:
15
16
17
18Environment:
19
20 Kernel mode only
21
22Revision History:
23
24
25
26--*/
27
28#include "fxwmipch.hpp"
29
30//
31// Extern "C" the tmh file and all external APIs
32//
33extern "C" {
34#if defined(EVENT_TRACING)
35#include "fxwmiapi.tmh"
36#endif
37
42WDFEXPORT(WdfWmiProviderCreate)(
43 __in
44 PWDF_DRIVER_GLOBALS DriverGlobals,
45 __in
46 WDFDEVICE Device,
47 __in
51 __out
52 WDFWMIPROVIDER* WmiProvider
53 )
54{
58
60 Device,
62 (PVOID*) &pDevice);
63
66
67 //
68 // If the Device is a power policy owner then do not allow client drivers
69 // to register for GUID_POWER_DEVICE_ENABLE or GUID_POWER_DEVICE_WAKE_ENABLE
70 // if the framework has already register a provider for those guids.
71 //
74
76 &GUID_POWER_DEVICE_ENABLE) &&
78
80 &GUID_POWER_DEVICE_WAKE_ENABLE) &&
82
84 TRACINGDEVICE, "WMI Guid already registered by "
85 "framework");
87 }
88 }
89
90 return FxWmiProvider::_Create(GetFxDriverGlobals(DriverGlobals),
91 Device,
95 &pProvider);
96}
97
101NTAPI
102WDFEXPORT(WdfWmiInstanceCreate)(
103 __in
104 PWDF_DRIVER_GLOBALS DriverGlobals,
105 __in
106 WDFDEVICE Device,
107 __in
112 WDFWMIINSTANCE* Instance
113 )
114{
118 WDFWMIINSTANCE hInstance;
120
122 pInstance = NULL;
123
125
129 "Expected InstanceConfig Size %d, got %d, %!STATUS!",
130 InstanceConfig->Size, sizeof(*InstanceConfig),
131 status);
132 return status;
133 }
134
135 if (InstanceConfig->Provider == NULL &&
136 InstanceConfig->ProviderConfig == NULL) {
138
141 "InstanceConfig %p Provider and ProviderConfig are both NULL, only "
142 "one can be, %!STATUS!", InstanceConfig, status);
143
144 return status;
145 }
146 else if (InstanceConfig->Provider != NULL &&
147 InstanceConfig->ProviderConfig != NULL) {
149
152 "InstanceConfig %p Provider %p and ProviderConfig %p are both not "
153 "NULL, only one can be, %!STATUS!", InstanceConfig,
154 InstanceConfig->Provider, InstanceConfig->ProviderConfig, status);
155
156 return status;
157 }
158
159 if (InstanceConfig->Provider != NULL) {
161 InstanceConfig->Provider,
163 (PVOID*) &pProvider,
165 }
166 else {
169 WDFWMIPROVIDER hProvider;
170
171 hProvider = NULL;
173 Device,
175 (PVOID*) &pDevice);
176
177 //
178 // If the Device is a power policy owner then do not allow client drivers
179 // to register for GUID_POWER_DEVICE_ENABLE or GUID_POWER_DEVICE_WAKE_ENABLE
180 // if the framework has already register a provider for those guids.
181 //
184
185 if ((FxIsEqualGuid(&InstanceConfig->ProviderConfig->Guid,
186 &GUID_POWER_DEVICE_ENABLE) &&
188
189 (FxIsEqualGuid(&InstanceConfig->ProviderConfig->Guid,
190 &GUID_POWER_DEVICE_WAKE_ENABLE) &&
192
195 TRACINGDEVICE, "WMI Guid already registered by "
196 "framework");
197 return status;
198 }
199 }
200
202 Device,
203 NULL,
204 InstanceConfig->ProviderConfig,
205 &hProvider,
206 &pProvider);
207
209 return status;
210 }
211
212 //
213 // Use the object's globals and not the caller's
214 //
216 }
217
219 pProvider,
222 &hInstance,
223 &pInstance);
224
225 if (NT_SUCCESS(status) && InstanceConfig->Register) {
227 }
228
230 if (Instance != NULL) {
232 }
233 }
234 else {
235 //
236 // Something went wrong, cleanup
237 //
238 if (pInstance != NULL) {
239 //
240 // This will remove the instance from the provider's list as well.
241 //
243 }
244
245 //
246 // Only remove the provider if we created it in this function
247 //
248 if (InstanceConfig->ProviderConfig != NULL) {
250 }
251 }
252
253 return status;
254}
255
256WDFAPI
258WDFDEVICE
259NTAPI
260WDFEXPORT(WdfWmiProviderGetDevice)(
261 __in
262 PWDF_DRIVER_GLOBALS DriverGlobals,
263 __in
264 WDFWMIPROVIDER WmiProvider
265 )
266{
268
272 (PVOID*) &pProvider);
273
275}
276
279NTAPI
280WDFEXPORT(WdfWmiProviderIsEnabled)(
281 __in
282 PWDF_DRIVER_GLOBALS DriverGlobals,
283 __in
284 WDFWMIPROVIDER WmiProvider,
285 __in
287 )
288{
290
294 (PVOID*) &pProvider);
295
297}
298
301NTAPI
302WDFEXPORT(WdfWmiProviderGetTracingHandle)(
303 __in
304 PWDF_DRIVER_GLOBALS DriverGlobals,
305 __in
306 WDFWMIPROVIDER WmiProvider
307 )
308{
310
314 (PVOID*) &pProvider);
315
317}
318
322NTAPI
323WDFEXPORT(WdfWmiInstanceRegister)(
324 __in
325 PWDF_DRIVER_GLOBALS DriverGlobals,
326 __in
327 WDFWMIINSTANCE WmiInstance
328 )
329{
332
336 (PVOID*) &pInstance);
337
339
341}
342
344VOID
345NTAPI
346WDFEXPORT(WdfWmiInstanceDeregister)(
347 __in
348 PWDF_DRIVER_GLOBALS DriverGlobals,
349 __in
350 WDFWMIINSTANCE WmiInstance
351 )
352{
355
359 (PVOID*) &pInstance);
360
363}
364
366WDFDEVICE
367NTAPI
368WDFEXPORT(WdfWmiInstanceGetDevice)(
369 __in
370 PWDF_DRIVER_GLOBALS DriverGlobals,
371 __in
372 WDFWMIINSTANCE WmiInstance
373 )
374{
376
380 (PVOID*) &pInstance);
381
382 return pInstance->GetDevice()->GetHandle();
383}
384
386WDFWMIPROVIDER
387NTAPI
388WDFEXPORT(WdfWmiInstanceGetProvider)(
389 __in
390 PWDF_DRIVER_GLOBALS DriverGlobals,
391 __in
392 WDFWMIINSTANCE WmiInstance
393 )
394{
396
400 (PVOID*) &pInstance);
401
403}
404
405
409NTAPI
410WDFEXPORT(WdfWmiInstanceFireEvent)(
411 __in
412 PWDF_DRIVER_GLOBALS DriverGlobals,
413 __in
414 WDFWMIINSTANCE WmiInstance,
418 PVOID EventData
419 )
420/*++
421
422Routine Description:
423 Fires an event based on the instance handle.
424
425Arguments:
426 WmiInstance - instance which the event is associated with
427 EventDataSize - size of EventData in bytes
428 EventData - buffer associated with the event
429
430Return Value:
431 NTSTATUS
432
433 --*/
434{
437
441 (PVOID*) &pInstance);
442
444 if (!NT_SUCCESS(status)) {
445 return status;
446 }
447
448 return pInstance->FireEvent(EventData, EventDataSize);
449}
450
451} // extern "C"
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
FxPkgPnp * m_PkgPnp
Definition: fxdevice.hpp:670
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
BOOLEAN IsPowerPolicyOwner(VOID)
Definition: fxpkgpnp.hpp:3612
FxPowerPolicyMachine m_PowerPolicyMachine
Definition: fxpkgpnp.hpp:4153
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxWmiProvider *Provider, __in PWDF_WMI_INSTANCE_CONFIG WmiInstanceConfig, __in_opt PWDF_OBJECT_ATTRIBUTES InstanceAttributes, __out WDFWMIINSTANCE *WmiInstance, __out FxWmiInstanceExternal **Instance)
CfxDevice * GetDevice(VOID)
_Must_inspect_result_ NTSTATUS FireEvent(__in_bcount_opt(EventBufferSize) PVOID EventBuffer, __inout ULONG EventBufferSize)
FxWmiProvider * GetProvider(VOID)
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS CallersGlobals, __in WDFDEVICE Device, __in_opt PWDF_OBJECT_ATTRIBUTES ProviderAttributes, __in PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig, __out WDFWMIPROVIDER *WmiProvider, __out FxWmiProvider **Provider)
CfxDevice * GetDevice(VOID)
ULONGLONG GetTracingHandle(VOID)
WDFWMIPROVIDER GetHandle(VOID)
VOID RemoveInstance(__in FxWmiInstance *Instance)
BOOLEAN IsEnabled(__in WDF_WMI_PROVIDER_CONTROL Control)
_Must_inspect_result_ NTSTATUS AddInstance(__in FxWmiInstance *Instance, __in BOOLEAN NoErrorIfPresent=FALSE)
#define __out_opt
Definition: dbghelp.h:65
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define __in_bcount_opt(x)
Definition: dbghelp.h:44
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FxDevice * pDevice
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
__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 WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
@ FX_TYPE_WMI_PROVIDER
Definition: fxtypes.h:49
@ FX_TYPE_DEVICE
Definition: fxtypes.h:47
@ FX_TYPE_WMI_INSTANCE
Definition: fxtypes.h:87
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
NTSTATUS status
Definition: fxwmiapi.cpp:119
FxWmiProvider * pProvider
Definition: fxwmiapi.cpp:57
WDFWMIINSTANCE hInstance
Definition: fxwmiapi.cpp:118
FxPowerPolicyOwnerSettings * ownerSettings
Definition: fxwmiapi.cpp:56
__in WDFWMIPROVIDER __in WDF_WMI_PROVIDER_CONTROL ProviderControl
Definition: fxwmiapi.cpp:288
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES __out WDFWMIPROVIDER * WmiProvider
Definition: fxwmiapi.cpp:54
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *) &pDevice)
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG InstanceConfig
Definition: fxwmiapi.cpp:108
FxWmiInstanceExternal * pInstance
Definition: fxwmiapi.cpp:117
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig
Definition: fxwmiapi.cpp:48
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES __out_opt WDFWMIINSTANCE * Instance
Definition: fxwmiapi.cpp:114
_Must_inspect_result_ __in WDFWMIINSTANCE __in_opt ULONG EventDataSize
Definition: fxwmiapi.cpp:416
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES ProviderAttributes
Definition: fxwmiapi.cpp:50
_Must_inspect_result_ __in WDFDEVICE Device
Definition: fxwmiapi.cpp:46
_Must_inspect_result_ __in WDFWMIINSTANCE WmiInstance
Definition: fxwmiapi.cpp:329
WDFWMIPROVIDER hProvider
Definition: fxwmiapi.cpp:169
pFxDriverGlobals
Definition: fxwmiapi.cpp:121
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES InstanceAttributes
Definition: fxwmiapi.cpp:110
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define STATUS_WMI_GUID_DISCONNECTED
Definition: ntstatus.h:1003
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
FxPowerPolicyOwnerSettings * m_Owner
FxWmiInstanceInternal * WmiInstance
Definition: ps.c:97
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
#define WDFAPI
Definition: wdftypes.h:53
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES InstanceAttributes
Definition: wdfwmi.h:478
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_opt_ WDFWMIINSTANCE * Instance
Definition: wdfwmi.h:481
WDF_EXTERN_C_START enum _WDF_WMI_PROVIDER_CONTROL WDF_WMI_PROVIDER_CONTROL
_Must_inspect_result_ _In_ WDFWMIINSTANCE WmiInstance
Definition: wdfwmi.h:514
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG InstanceConfig
Definition: wdfwmi.h:476
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig
Definition: wdfwmi.h:358
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_PROVIDER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWMIPROVIDER * WmiProvider
Definition: wdfwmi.h:363
_Must_inspect_result_ _In_ WDFWMIINSTANCE _In_opt_ ULONG EventDataSize
Definition: wdfwmi.h:617
_In_ WDFWMIPROVIDER _In_ WDF_WMI_PROVIDER_CONTROL ProviderControl
Definition: wdfwmi.h:422
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_PROVIDER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES ProviderAttributes
Definition: wdfwmi.h:360