ReactOS  0.4.13-dev-99-g7e18b6d
cmbwmi.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS ACPI-Compliant Control Method Battery
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * FILE: boot/drivers/bus/acpi/cmbatt/cmbwmi.c
5  * PURPOSE: WMI Interface
6  * PROGRAMMERS: ReactOS Portable Systems Group
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "cmbatt.h"
12 
13 #include <debug.h>
14 
15 /* GLOBALS ********************************************************************/
16 
18 {
19  {&GUID_POWER_DEVICE_WAKE_ENABLE, 1, 0}
20 };
21 
22 /* FUNCTIONS ******************************************************************/
23 
24 PCHAR
25 NTAPI
27 {
28  switch (MinorFunction)
29  {
31  return "IRP_MN_CHANGE_SINGLE_INSTANCE";
33  return "IRP_MN_CHANGE_SINGLE_ITEM";
35  return "IRP_MN_DISABLE_COLLECTION";
37  return "IRP_MN_DISABLE_EVENTS";
39  return "IRP_MN_ENABLE_COLLECTION";
41  return "IRP_MN_ENABLE_EVENTS";
43  return "IRP_MN_EXECUTE_METHOD";
45  return "IRP_MN_QUERY_ALL_DATA";
47  return "IRP_MN_QUERY_SINGLE_INSTANCE";
48  case IRP_MN_REGINFO:
49  return "IRP_MN_REGINFO";
50  default:
51  return "IRP_MN_?????";
52  }
53 }
54 
56 NTAPI
63 {
66 }
67 
69 NTAPI
71  PIRP Irp,
75  PULONG InstanceLengthArray,
77  PUCHAR Buffer)
78 {
81 }
82 
84 NTAPI
86  PIRP Irp,
90  PUCHAR Buffer)
91 {
94 }
95 
97 NTAPI
99  PIRP Irp,
104  PUCHAR Buffer)
105 {
107  return STATUS_NOT_IMPLEMENTED;
108 }
109 
110 NTSTATUS
111 NTAPI
113 {
114  PAGED_CODE();
115 
116  /* De-register */
117  return IoWMIRegistrationControl(DeviceExtension->FdoDeviceObject,
119 }
120 
121 NTSTATUS
122 NTAPI
124 {
125  PAGED_CODE();
126 
127  /* GUID information */
128  DeviceExtension->WmiLibInfo.GuidCount = sizeof(CmBattWmiGuidList) /
129  sizeof(WMIGUIDREGINFO);
130  DeviceExtension->WmiLibInfo.GuidList = CmBattWmiGuidList;
131 
132  /* Callbacks */
133  DeviceExtension->WmiLibInfo.QueryWmiRegInfo = CmBattQueryWmiRegInfo;
134  DeviceExtension->WmiLibInfo.QueryWmiDataBlock = CmBattQueryWmiDataBlock;
135  DeviceExtension->WmiLibInfo.SetWmiDataBlock = CmBattSetWmiDataBlock;
136  DeviceExtension->WmiLibInfo.SetWmiDataItem = CmBattSetWmiDataItem;
137  DeviceExtension->WmiLibInfo.ExecuteWmiMethod = NULL;
138  DeviceExtension->WmiLibInfo.WmiFunctionControl = NULL;
139 
140  /* Register */
141  return IoWMIRegistrationControl(DeviceExtension->FdoDeviceObject,
143 }
144 
145 NTSTATUS
146 NTAPI
148  IN PIRP Irp)
149 {
151  PCMBATT_DEVICE_EXTENSION DeviceExtension;
154  PAGED_CODE();
155  if (CmBattDebug & 2)
156  DbgPrint("CmBatt: SystemControl: %s\n",
158 
159  /* Acquire the remove lock */
160  DeviceExtension = DeviceObject->DeviceExtension;
161  Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, 0);
162  if (!NT_SUCCESS(Status))
163  {
164  /* It's too late, fail */
165  Irp->IoStatus.Status = STATUS_DEVICE_REMOVED;
167  return STATUS_DEVICE_REMOVED;
168  }
169 
170  /* What kind of device is this? */
171  WmiLibContext = &DeviceExtension->WmiLibInfo;
172  if (DeviceExtension->FdoType == CmBattBattery)
173  {
174  /* For batteries, let the class driver handle it */
175  Status = BatteryClassSystemControl(DeviceExtension->ClassData,
177  DeviceObject,
178  Irp,
179  &Disposition);
180  }
181  else
182  {
183  /* Otherwise, call the wmi library directly */
185  DeviceObject,
186  Irp,
187  &Disposition);
188  }
189 
190  /* Check what happened */
191  switch (Disposition)
192  {
193  case IrpNotCompleted:
194 
195  /* Complete it here */
196  if (CmBattDebug & 2) DbgPrint("CmBatt: SystemControl: Irp Not Completed.\n");
198  break;
199 
200  case IrpForward:
201 
202  /* Forward it to ACPI */
203  if (CmBattDebug & 2) DbgPrint("CmBatt: SystemControl: Irp Forward.\n");
205  Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
206  break;
207 
208  case IrpProcessed:
209 
210  /* Nothing to do */
211  if (CmBattDebug & 2) DbgPrint("CmBatt: SystemControl: Irp Processed.\n");
212  break;
213 
214  default:
215  ASSERT(FALSE);
216  }
217 
218  /* Release the lock and return */
219  IoReleaseRemoveLock(&DeviceExtension->RemoveLock, 0);
220  return Status;
221 }
222 
223 /* EOF */
PCHAR NTAPI WMIMinorFunctionString(IN UCHAR MinorFunction)
Definition: cmbwmi.c:26
signed char * PCHAR
Definition: retypes.h:7
IO_REMOVE_LOCK RemoveLock
Definition: cmbatt.h:115
#define IN
Definition: typedefs.h:38
WMIGUIDREGINFO CmBattWmiGuidList[1]
Definition: cmbwmi.c:17
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:795
#define IRP_MN_REGINFO
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
_In_ PVOID WmiLibContext
Definition: batclass.h:377
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
_In_ PIRP _In_ ULONG _In_ ULONG DataItemId
Definition: classpnp.h:419
WMILIB_CONTEXT WmiLibInfo
Definition: cmbatt.h:113
#define WMIREG_ACTION_DEREGISTER
unsigned char * PUCHAR
Definition: retypes.h:3
NTSTATUS NTAPI WmiSystemControl(IN PWMILIB_CONTEXT WmiLibInfo, IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, OUT PSYSCTL_IRP_DISPOSITION IrpDisposition)
Definition: wmilib.c:48
LONG NTSTATUS
Definition: precomp.h:26
_In_ LPGUID _In_ ULONG InstanceIndex
Definition: classpnp.h:1057
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2716
#define IRP_MN_QUERY_SINGLE_INSTANCE
ULONG CmBattDebug
Definition: cmbatt.c:17
NTSTATUS NTAPI CmBattQueryWmiDataBlock(PDEVICE_OBJECT DeviceObject, PIRP Irp, ULONG GuidIndex, ULONG InstanceIndex, ULONG InstanceCount, PULONG InstanceLengthArray, ULONG BufferAvail, PUCHAR Buffer)
Definition: cmbwmi.c:70
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
#define PAGED_CODE()
Definition: video.h:57
#define IRP_MN_ENABLE_COLLECTION
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define IRP_MN_CHANGE_SINGLE_ITEM
NTSTATUS NTAPI CmBattWmiRegistration(IN PCMBATT_DEVICE_EXTENSION DeviceExtension)
Definition: cmbwmi.c:123
#define IRP_MN_DISABLE_COLLECTION
PVOID DeviceExtension
Definition: env_spec_w32.h:418
_Out_ ULONG * RegFlags
Definition: classpnp.h:386
_Out_ ULONG _Out_ PUNICODE_STRING _Out_ PUNICODE_STRING MofResourceName
Definition: classpnp.h:386
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:401
NTSTATUS NTAPI CmBattSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: cmbwmi.c:147
Definition: bufpool.h:45
NTSTATUS NTAPI IoWMIRegistrationControl(IN PDEVICE_OBJECT DeviceObject, IN ULONG Action)
Definition: wmi.c:68
#define WMIREG_ACTION_REGISTER
enum _SYSCTL_IRP_DISPOSITION SYSCTL_IRP_DISPOSITION
NTSTATUS NTAPI CmBattSetWmiDataItem(PDEVICE_OBJECT DeviceObject, PIRP Irp, ULONG GuidIndex, ULONG InstanceIndex, ULONG DataItemId, ULONG BufferSize, PUCHAR Buffer)
Definition: cmbwmi.c:98
#define IRP_MN_ENABLE_EVENTS
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BCLASSAPI NTSTATUS NTAPI BatteryClassSystemControl(PVOID ClassData, PVOID WmiLibContext, PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Disposition)
Definition: battc.c:49
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MN_DISABLE_EVENTS
#define IRP_MN_EXECUTE_METHOD
_In_ PIRP _In_ ULONG _In_ ULONG BufferAvail
Definition: classpnp.h:401
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
NTSTATUS NTAPI CmBattWmiDeRegistration(IN PCMBATT_DEVICE_EXTENSION DeviceExtension)
Definition: cmbwmi.c:112
Status
Definition: gdiplustypes.h:24
#define IRP_MN_CHANGE_SINGLE_INSTANCE
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS NTAPI CmBattQueryWmiRegInfo(PDEVICE_OBJECT DeviceObject, PULONG RegFlags, PUNICODE_STRING InstanceName, PUNICODE_STRING *RegistryPath, PUNICODE_STRING MofResourceName, PDEVICE_OBJECT *Pdo)
Definition: cmbwmi.c:57
CMBATT_EXTENSION_TYPE FdoType
Definition: cmbatt.h:104
#define IRP_MN_QUERY_ALL_DATA
PDEVICE_OBJECT AttachedDevice
Definition: cmbatt.h:108
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
_Must_inspect_result_ _Inout_ PFLT_VOLUME _In_opt_ PCUNICODE_STRING InstanceName
Definition: fltkernel.h:1162
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
_In_ ULONG InstanceCount
Definition: iofuncs.h:1319
#define UNIMPLEMENTED
Definition: debug.h:114
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IoAcquireRemoveLock(RemoveLock, Tag)
NTSTATUS NTAPI CmBattSetWmiDataBlock(PDEVICE_OBJECT DeviceObject, PIRP Irp, ULONG GuidIndex, ULONG InstanceIndex, ULONG BufferSize, PUCHAR Buffer)
Definition: cmbwmi.c:85