ReactOS  0.4.15-dev-1632-g4e289ce
fxwmiapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxWmiApi.cpp
8 
9 Abstract:
10 
11  This module implements the C interface to the WMI package
12  for the driver frameworks.
13 
14 Author:
15 
16 
17 
18 Environment:
19 
20  Kernel mode only
21 
22 Revision History:
23 
24 
25 
26 --*/
27 
28 #include "fxwmipch.hpp"
29 
30 //
31 // Extern "C" the tmh file and all external APIs
32 //
33 extern "C" {
34 #include "fxwmiapi.tmh"
35 
39 WDFEXPORT(WdfWmiProviderCreate)(
40  __in
42  __in
43  WDFDEVICE Device,
44  __in
46  __in_opt
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 
72  if ((FxIsEqualGuid(&WmiProviderConfig->Guid,
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 
98 WDFEXPORT(WdfWmiInstanceCreate)(
99  __in
101  __in
102  WDFDEVICE Device,
103  __in
105  __in_opt
107  __out_opt
108  WDFWMIINSTANCE* Instance
109  )
110 {
114  WDFWMIINSTANCE hInstance;
116 
118  pInstance = NULL;
119 
121 
122  if (InstanceConfig->Size != sizeof(WDF_WMI_INSTANCE_CONFIG)) {
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 {
163  FxDevice* pDevice;
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) {
227  *Instance = hInstance;
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 
252 WDFAPI
254 WDFDEVICE
255 WDFEXPORT(WdfWmiProviderGetDevice)(
256  __in
258  __in
259  WDFWMIPROVIDER WmiProvider
260  )
261 {
263 
265  WmiProvider,
267  (PVOID*) &pProvider);
268 
269  return pProvider->GetDevice()->GetHandle();
270 }
271 
273 BOOLEAN
274 WDFEXPORT(WdfWmiProviderIsEnabled)(
275  __in
277  __in
278  WDFWMIPROVIDER WmiProvider,
279  __in
281  )
282 {
284 
286  WmiProvider,
288  (PVOID*) &pProvider);
289 
291 }
292 
294 ULONGLONG
295 WDFEXPORT(WdfWmiProviderGetTracingHandle)(
296  __in
298  __in
299  WDFWMIPROVIDER WmiProvider
300  )
301 {
303 
305  WmiProvider,
307  (PVOID*) &pProvider);
308 
309  return pProvider->GetTracingHandle();
310 }
311 
314 NTSTATUS
315 WDFEXPORT(WdfWmiInstanceRegister)(
316  __in
318  __in
319  WDFWMIINSTANCE WmiInstance
320  )
321 {
324 
326  WmiInstance,
328  (PVOID*) &pInstance);
329 
331 
333 }
334 
336 VOID
337 WDFEXPORT(WdfWmiInstanceDeregister)(
338  __in
340  __in
341  WDFWMIINSTANCE WmiInstance
342  )
343 {
346 
348  WmiInstance,
350  (PVOID*) &pInstance);
351 
354 }
355 
357 WDFDEVICE
358 WDFEXPORT(WdfWmiInstanceGetDevice)(
359  __in
361  __in
362  WDFWMIINSTANCE WmiInstance
363  )
364 {
366 
368  WmiInstance,
370  (PVOID*) &pInstance);
371 
372  return pInstance->GetDevice()->GetHandle();
373 }
374 
376 WDFWMIPROVIDER
377 WDFEXPORT(WdfWmiInstanceGetProvider)(
378  __in
380  __in
381  WDFWMIINSTANCE WmiInstance
382  )
383 {
385 
387  WmiInstance,
389  (PVOID*) &pInstance);
390 
391  return pInstance->GetProvider()->GetHandle();
392 }
393 
394 
397 NTSTATUS
398 WDFEXPORT(WdfWmiInstanceFireEvent)(
399  __in
401  __in
402  WDFWMIINSTANCE WmiInstance,
403  __in_opt
406  PVOID EventData
407  )
408 /*++
409 
410 Routine Description:
411  Fires an event based on the instance handle.
412 
413 Arguments:
414  WmiInstance - instance which the event is associated with
415  EventDataSize - size of EventData in bytes
416  EventData - buffer associated with the event
417 
418 Return Value:
419  NTSTATUS
420 
421  --*/
422 {
425 
427  WmiInstance,
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"
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig
Definition: wdfwmi.h:356
_Must_inspect_result_ _In_ WDFWMIINSTANCE _In_opt_ ULONG EventDataSize
Definition: wdfwmi.h:615
#define _Must_inspect_result_
Definition: no_sal2.h:62
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES InstanceAttributes
Definition: fxwmiapi.cpp:102
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
_In_ WDFWMIPROVIDER _In_ WDF_WMI_PROVIDER_CONTROL ProviderControl
Definition: wdfwmi.h:419
#define __in_opt
Definition: dbghelp.h:38
FxWmiProvider * pProvider
Definition: fxwmiapi.cpp:54
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
WDF_EXTERN_C_START enum _WDF_WMI_PROVIDER_CONTROL WDF_WMI_PROVIDER_CONTROL
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES InstanceAttributes
Definition: wdfwmi.h:474
WDFWMIPROVIDER hProvider
Definition: fxwmiapi.cpp:165
_Must_inspect_result_ BOOLEAN __inline FxIsEqualGuid(__in CONST GUID *Lhs, __in CONST GUID *Rhs)
Definition: fxglobals.h:977
WDFWMIINSTANCE hInstance
Definition: fxwmiapi.cpp:114
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES ProviderAttributes
Definition: fxwmiapi.cpp:43
FxPowerPolicyMachine m_PowerPolicyMachine
Definition: fxpkgpnp.hpp:4153
DriverGlobals
_Must_inspect_result_ __drv_maxIRQL(DISPATCH_LEVEL) NTSTATUS WDFEXPORT(WdfWmiProviderCreate)(__in PWDF_DRIVER_GLOBALS DriverGlobals
_Must_inspect_result_ _In_ WDFWMIINSTANCE WmiInstance
Definition: wdfwmi.h:514
_Must_inspect_result_ __in WDFDEVICE Device
Definition: fxwmiapi.cpp:43
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES __out_opt WDFWMIINSTANCE * Instance
Definition: fxwmiapi.cpp:110
#define __out_opt
Definition: dbghelp.h:65
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define WDFAPI
Definition: wdftypes.h:53
CfxDevice * GetDevice(VOID)
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
#define STATUS_WMI_GUID_DISCONNECTED
Definition: ntstatus.h:877
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_PROVIDER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWMIPROVIDER * WmiProvider
Definition: wdfwmi.h:356
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_INSTANCE_CONFIG InstanceConfig
Definition: fxwmiapi.cpp:102
VOID RemoveInstance(__in FxWmiInstance *Instance)
FxDevice * pDevice
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
FxPowerPolicyOwnerSettings * m_Owner
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_PROVIDER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES ProviderAttributes
Definition: wdfwmi.h:356
__in WDFWMIPROVIDER __in WDF_WMI_PROVIDER_CONTROL ProviderControl
Definition: fxwmiapi.cpp:282
FxPointerNotNull(GetFxDriverGlobals(DriverGlobals), WmiProviderConfig)
BOOLEAN IsPowerPolicyOwner(VOID)
Definition: fxpkgpnp.hpp:3612
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig
Definition: fxwmiapi.cpp:43
_Must_inspect_result_ __in WDFWMIINSTANCE __in_opt ULONG EventDataSize
Definition: fxwmiapi.cpp:402
NTSTATUS status
Definition: fxwmiapi.cpp:115
BOOLEAN IsEnabled(__in WDF_WMI_PROVIDER_CONTROL Control)
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
FxWmiInstanceInternal * WmiInstance
pFxDriverGlobals
Definition: fxwmiapi.cpp:117
FxWmiProvider * GetProvider(VOID)
FxPkgPnp * m_PkgPnp
Definition: fxdevice.hpp:670
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONGLONG GetTracingHandle(VOID)
FxWmiInstanceExternal * pInstance
Definition: fxwmiapi.cpp:113
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
_Must_inspect_result_ __in WDFWMIINSTANCE WmiInstance
Definition: fxwmiapi.cpp:321
#define NULL
Definition: types.h:112
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG InstanceConfig
Definition: wdfwmi.h:474
FxPowerPolicyOwnerSettings * ownerSettings
Definition: fxwmiapi.cpp:53
unsigned int ULONG
Definition: retypes.h:1
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *) &pDevice)
_Must_inspect_result_ __in WDFWMIINSTANCE __in_opt ULONG __in_bcount_opt(EventDataSize) PVOID EventData)
Definition: fxwmiapi.cpp:405
CfxDevice * GetDevice(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)
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ __in WDFDEVICE __in PWDF_WMI_PROVIDER_CONFIG __in_opt PWDF_OBJECT_ATTRIBUTES __out WDFWMIPROVIDER * WmiProvider
Definition: fxwmiapi.cpp:51
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)
WDFWMIPROVIDER GetHandle(VOID)
_Must_inspect_result_ NTSTATUS AddInstance(__in FxWmiInstance *Instance, __in BOOLEAN NoErrorIfPresent=FALSE)
#define __in
Definition: dbghelp.h:35
#define APC_LEVEL
Definition: env_spec_w32.h:695
IN PVOID Instance
Definition: pci.h:361
_Must_inspect_result_ NTSTATUS FireEvent(__in_bcount_opt(EventBufferSize) PVOID EventBuffer, __inout ULONG EventBufferSize)
Definition: ps.c:97