ReactOS 0.4.15-dev-8191-gbc6c731
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#include "fxwmiapi.tmh"
35
39WDFEXPORT(WdfWmiProviderCreate)(
40 __in
42 __in
43 WDFDEVICE Device,
44 __in
48 __out
49 WDFWMIPROVIDER* WmiProvider
50 )
51{
55
57 Device,
59 (PVOID*) &pDevice);
60
63
64 //
65 // If the Device is a power policy owner then do not allow client drivers
66 // to register for GUID_POWER_DEVICE_ENABLE or GUID_POWER_DEVICE_WAKE_ENABLE
67 // if the framework has already register a provider for those guids.
68 //
71
73 &GUID_POWER_DEVICE_ENABLE) &&
75
77 &GUID_POWER_DEVICE_WAKE_ENABLE) &&
79
81 TRACINGDEVICE, "WMI Guid already registered by "
82 "framework");
84 }
85 }
86
88 Device,
92 &pProvider);
93}
94
98WDFEXPORT(WdfWmiInstanceCreate)(
99 __in
101 __in
102 WDFDEVICE Device,
103 __in
108 WDFWMIINSTANCE* Instance
109 )
110{
114 WDFWMIINSTANCE hInstance;
116
118 pInstance = NULL;
119
121
125 "Expected InstanceConfig Size %d, got %d, %!STATUS!",
126 InstanceConfig->Size, sizeof(*InstanceConfig),
127 status);
128 return status;
129 }
130
131 if (InstanceConfig->Provider == NULL &&
132 InstanceConfig->ProviderConfig == NULL) {
134
137 "InstanceConfig %p Provider and ProviderConfig are both NULL, only "
138 "one can be, %!STATUS!", InstanceConfig, status);
139
140 return status;
141 }
142 else if (InstanceConfig->Provider != NULL &&
143 InstanceConfig->ProviderConfig != NULL) {
145
148 "InstanceConfig %p Provider %p and ProviderConfig %p are both not "
149 "NULL, only one can be, %!STATUS!", InstanceConfig,
150 InstanceConfig->Provider, InstanceConfig->ProviderConfig, status);
151
152 return status;
153 }
154
155 if (InstanceConfig->Provider != NULL) {
157 InstanceConfig->Provider,
159 (PVOID*) &pProvider,
161 }
162 else {
165 WDFWMIPROVIDER hProvider;
166
167 hProvider = NULL;
169 Device,
171 (PVOID*) &pDevice);
172
173 //
174 // If the Device is a power policy owner then do not allow client drivers
175 // to register for GUID_POWER_DEVICE_ENABLE or GUID_POWER_DEVICE_WAKE_ENABLE
176 // if the framework has already register a provider for those guids.
177 //
180
181 if ((FxIsEqualGuid(&InstanceConfig->ProviderConfig->Guid,
182 &GUID_POWER_DEVICE_ENABLE) &&
184
185 (FxIsEqualGuid(&InstanceConfig->ProviderConfig->Guid,
186 &GUID_POWER_DEVICE_WAKE_ENABLE) &&
188
191 TRACINGDEVICE, "WMI Guid already registered by "
192 "framework");
193 return status;
194 }
195 }
196
198 Device,
199 NULL,
200 InstanceConfig->ProviderConfig,
201 &hProvider,
202 &pProvider);
203
205 return status;
206 }
207
208 //
209 // Use the object's globals and not the caller's
210 //
212 }
213
215 pProvider,
218 &hInstance,
219 &pInstance);
220
221 if (NT_SUCCESS(status) && InstanceConfig->Register) {
223 }
224
226 if (Instance != NULL) {
228 }
229 }
230 else {
231 //
232 // Something went wrong, cleanup
233 //
234 if (pInstance != NULL) {
235 //
236 // This will remove the instance from the provider's list as well.
237 //
239 }
240
241 //
242 // Only remove the provider if we created it in this function
243 //
244 if (InstanceConfig->ProviderConfig != NULL) {
246 }
247 }
248
249 return status;
250}
251
252WDFAPI
254WDFDEVICE
255WDFEXPORT(WdfWmiProviderGetDevice)(
256 __in
258 __in
259 WDFWMIPROVIDER WmiProvider
260 )
261{
263
267 (PVOID*) &pProvider);
268
270}
271
274WDFEXPORT(WdfWmiProviderIsEnabled)(
275 __in
277 __in
278 WDFWMIPROVIDER WmiProvider,
279 __in
281 )
282{
284
288 (PVOID*) &pProvider);
289
291}
292
295WDFEXPORT(WdfWmiProviderGetTracingHandle)(
296 __in
298 __in
299 WDFWMIPROVIDER WmiProvider
300 )
301{
303
307 (PVOID*) &pProvider);
308
310}
311
315WDFEXPORT(WdfWmiInstanceRegister)(
316 __in
318 __in
319 WDFWMIINSTANCE WmiInstance
320 )
321{
324
328 (PVOID*) &pInstance);
329
331
333}
334
336VOID
337WDFEXPORT(WdfWmiInstanceDeregister)(
338 __in
340 __in
341 WDFWMIINSTANCE WmiInstance
342 )
343{
346
350 (PVOID*) &pInstance);
351
354}
355
357WDFDEVICE
358WDFEXPORT(WdfWmiInstanceGetDevice)(
359 __in
361 __in
362 WDFWMIINSTANCE WmiInstance
363 )
364{
366
370 (PVOID*) &pInstance);
371
372 return pInstance->GetDevice()->GetHandle();
373}
374
376WDFWMIPROVIDER
377WDFEXPORT(WdfWmiInstanceGetProvider)(
378 __in
380 __in
381 WDFWMIINSTANCE WmiInstance
382 )
383{
385
389 (PVOID*) &pInstance);
390
392}
393
394
398WDFEXPORT(WdfWmiInstanceFireEvent)(
399 __in
401 __in
402 WDFWMIINSTANCE WmiInstance,
406 PVOID EventData
407 )
408/*++
409
410Routine Description:
411 Fires an event based on the instance handle.
412
413Arguments:
414 WmiInstance - instance which the event is associated with
415 EventDataSize - size of EventData in bytes
416 EventData - buffer associated with the event
417
418Return Value:
419 NTSTATUS
420
421 --*/
422{
425
429 (PVOID*) &pInstance);
430
432 if (!NT_SUCCESS(status)) {
433 return status;
434 }
435
436 return pInstance->FireEvent(EventData, EventDataSize);
437}
438
439} // 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:32
#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)
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 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:115
FxWmiProvider * pProvider
Definition: fxwmiapi.cpp:54
WDFWMIINSTANCE hInstance
Definition: fxwmiapi.cpp:114
FxPowerPolicyOwnerSettings * ownerSettings
Definition: fxwmiapi.cpp:53
__in WDFWMIPROVIDER __in WDF_WMI_PROVIDER_CONTROL ProviderControl
Definition: fxwmiapi.cpp:282
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES __out WDFWMIPROVIDER * WmiProvider
Definition: fxwmiapi.cpp:51
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *) &pDevice)
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG InstanceConfig
Definition: fxwmiapi.cpp:104
FxWmiInstanceExternal * pInstance
Definition: fxwmiapi.cpp:113
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig
Definition: fxwmiapi.cpp:45
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES __out_opt WDFWMIINSTANCE * Instance
Definition: fxwmiapi.cpp:110
_Must_inspect_result_ __in WDFWMIINSTANCE __in_opt ULONG EventDataSize
Definition: fxwmiapi.cpp:404
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES ProviderAttributes
Definition: fxwmiapi.cpp:47
_Must_inspect_result_ __in WDFDEVICE Device
Definition: fxwmiapi.cpp:43
_Must_inspect_result_ __in WDFWMIINSTANCE WmiInstance
Definition: fxwmiapi.cpp:321
WDFWMIPROVIDER hProvider
Definition: fxwmiapi.cpp:165
pFxDriverGlobals
Definition: fxwmiapi.cpp:117
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES InstanceAttributes
Definition: fxwmiapi.cpp:106
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define STATUS_WMI_GUID_DISCONNECTED
Definition: ntstatus.h:877
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
FxPowerPolicyOwnerSettings * m_Owner
FxWmiInstanceInternal * WmiInstance
Definition: ps.c:97
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