2010-03-13 21:06:22 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS ACPI-Compliant Control Method Battery
|
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
|
|
|
* FILE: boot/drivers/bus/acpi/cmbatt/cmbwmi.c
|
|
|
|
* PURPOSE: WMI Interface
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include "cmbatt.h"
|
|
|
|
|
2014-01-27 22:55:47 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
2010-03-22 01:47:40 +00:00
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
|
|
|
WMIGUIDREGINFO CmBattWmiGuidList[1] =
|
|
|
|
{
|
|
|
|
{&GUID_POWER_DEVICE_WAKE_ENABLE, 1, 0}
|
|
|
|
};
|
|
|
|
|
2010-03-13 21:06:22 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
2010-03-22 02:11:16 +00:00
|
|
|
PCHAR
|
|
|
|
NTAPI
|
|
|
|
WMIMinorFunctionString(IN UCHAR MinorFunction)
|
|
|
|
{
|
|
|
|
switch (MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_CHANGE_SINGLE_INSTANCE:
|
|
|
|
return "IRP_MN_CHANGE_SINGLE_INSTANCE";
|
|
|
|
case IRP_MN_CHANGE_SINGLE_ITEM:
|
|
|
|
return "IRP_MN_CHANGE_SINGLE_ITEM";
|
|
|
|
case IRP_MN_DISABLE_COLLECTION:
|
|
|
|
return "IRP_MN_DISABLE_COLLECTION";
|
|
|
|
case IRP_MN_DISABLE_EVENTS:
|
|
|
|
return "IRP_MN_DISABLE_EVENTS";
|
|
|
|
case IRP_MN_ENABLE_COLLECTION:
|
|
|
|
return "IRP_MN_ENABLE_COLLECTION";
|
|
|
|
case IRP_MN_ENABLE_EVENTS:
|
|
|
|
return "IRP_MN_ENABLE_EVENTS";
|
|
|
|
case IRP_MN_EXECUTE_METHOD:
|
|
|
|
return "IRP_MN_EXECUTE_METHOD";
|
|
|
|
case IRP_MN_QUERY_ALL_DATA:
|
|
|
|
return "IRP_MN_QUERY_ALL_DATA";
|
|
|
|
case IRP_MN_QUERY_SINGLE_INSTANCE:
|
|
|
|
return "IRP_MN_QUERY_SINGLE_INSTANCE";
|
|
|
|
case IRP_MN_REGINFO:
|
|
|
|
return "IRP_MN_REGINFO";
|
|
|
|
default:
|
|
|
|
return "IRP_MN_?????";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-13 21:06:22 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CmBattQueryWmiRegInfo(PDEVICE_OBJECT DeviceObject,
|
|
|
|
PULONG RegFlags,
|
|
|
|
PUNICODE_STRING InstanceName,
|
|
|
|
PUNICODE_STRING *RegistryPath,
|
|
|
|
PUNICODE_STRING MofResourceName,
|
|
|
|
PDEVICE_OBJECT *Pdo)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CmBattQueryWmiDataBlock(PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp,
|
|
|
|
ULONG GuidIndex,
|
|
|
|
ULONG InstanceIndex,
|
|
|
|
ULONG InstanceCount,
|
|
|
|
PULONG InstanceLengthArray,
|
|
|
|
ULONG BufferAvail,
|
|
|
|
PUCHAR Buffer)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CmBattSetWmiDataBlock(PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp,
|
|
|
|
ULONG GuidIndex,
|
|
|
|
ULONG InstanceIndex,
|
|
|
|
ULONG BufferSize,
|
|
|
|
PUCHAR Buffer)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CmBattSetWmiDataItem(PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp,
|
|
|
|
ULONG GuidIndex,
|
|
|
|
ULONG InstanceIndex,
|
|
|
|
ULONG DataItemId,
|
|
|
|
ULONG BufferSize,
|
|
|
|
PUCHAR Buffer)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2010-03-22 01:47:40 +00:00
|
|
|
CmBattWmiDeRegistration(IN PCMBATT_DEVICE_EXTENSION DeviceExtension)
|
2010-03-13 21:06:22 +00:00
|
|
|
{
|
2010-03-22 01:47:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* De-register */
|
|
|
|
return IoWMIRegistrationControl(DeviceExtension->FdoDeviceObject,
|
|
|
|
WMIREG_ACTION_DEREGISTER);
|
2010-03-13 21:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2010-03-22 01:47:40 +00:00
|
|
|
CmBattWmiRegistration(IN PCMBATT_DEVICE_EXTENSION DeviceExtension)
|
2010-03-13 21:06:22 +00:00
|
|
|
{
|
2010-03-22 01:47:40 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* GUID information */
|
|
|
|
DeviceExtension->WmiLibInfo.GuidCount = sizeof(CmBattWmiGuidList) /
|
|
|
|
sizeof(WMIGUIDREGINFO);
|
|
|
|
DeviceExtension->WmiLibInfo.GuidList = CmBattWmiGuidList;
|
|
|
|
|
|
|
|
/* Callbacks */
|
|
|
|
DeviceExtension->WmiLibInfo.QueryWmiRegInfo = CmBattQueryWmiRegInfo;
|
|
|
|
DeviceExtension->WmiLibInfo.QueryWmiDataBlock = CmBattQueryWmiDataBlock;
|
|
|
|
DeviceExtension->WmiLibInfo.SetWmiDataBlock = CmBattSetWmiDataBlock;
|
|
|
|
DeviceExtension->WmiLibInfo.SetWmiDataItem = CmBattSetWmiDataItem;
|
|
|
|
DeviceExtension->WmiLibInfo.ExecuteWmiMethod = NULL;
|
|
|
|
DeviceExtension->WmiLibInfo.WmiFunctionControl = NULL;
|
|
|
|
|
|
|
|
/* Register */
|
|
|
|
return IoWMIRegistrationControl(DeviceExtension->FdoDeviceObject,
|
|
|
|
WMIREG_ACTION_REGISTER);
|
2010-03-13 21:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2010-03-22 02:11:16 +00:00
|
|
|
CmBattSystemControl(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
2010-03-13 21:06:22 +00:00
|
|
|
{
|
2010-03-22 02:11:16 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PCMBATT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PWMILIB_CONTEXT WmiLibContext;
|
|
|
|
SYSCTL_IRP_DISPOSITION Disposition = IrpForward;
|
|
|
|
PAGED_CODE();
|
|
|
|
if (CmBattDebug & 2)
|
|
|
|
DbgPrint("CmBatt: SystemControl: %s\n",
|
|
|
|
WMIMinorFunctionString(IoGetCurrentIrpStackLocation(Irp)->MinorFunction));
|
|
|
|
|
|
|
|
/* Acquire the remove lock */
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, 0);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* It's too late, fail */
|
|
|
|
Irp->IoStatus.Status = STATUS_DEVICE_REMOVED;
|
2012-03-05 20:43:47 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2010-03-22 02:11:16 +00:00
|
|
|
return STATUS_DEVICE_REMOVED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* What kind of device is this? */
|
|
|
|
WmiLibContext = &DeviceExtension->WmiLibInfo;
|
|
|
|
if (DeviceExtension->FdoType == CmBattBattery)
|
|
|
|
{
|
|
|
|
/* For batteries, let the class driver handle it */
|
|
|
|
Status = BatteryClassSystemControl(DeviceExtension->ClassData,
|
|
|
|
WmiLibContext,
|
|
|
|
DeviceObject,
|
|
|
|
Irp,
|
|
|
|
&Disposition);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, call the wmi library directly */
|
|
|
|
Status = WmiSystemControl(WmiLibContext,
|
|
|
|
DeviceObject,
|
|
|
|
Irp,
|
|
|
|
&Disposition);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check what happened */
|
|
|
|
switch (Disposition)
|
|
|
|
{
|
|
|
|
case IrpNotCompleted:
|
|
|
|
|
|
|
|
/* Complete it here */
|
|
|
|
if (CmBattDebug & 2) DbgPrint("CmBatt: SystemControl: Irp Not Completed.\n");
|
2012-03-05 20:43:47 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2010-03-22 02:11:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IrpForward:
|
|
|
|
|
|
|
|
/* Forward it to ACPI */
|
|
|
|
if (CmBattDebug & 2) DbgPrint("CmBatt: SystemControl: Irp Forward.\n");
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IrpProcessed:
|
|
|
|
|
|
|
|
/* Nothing to do */
|
|
|
|
if (CmBattDebug & 2) DbgPrint("CmBatt: SystemControl: Irp Processed.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the lock and return */
|
|
|
|
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, 0);
|
|
|
|
return Status;
|
2010-03-13 21:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|