2010-03-25 14:26:04 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Composite Battery Driver
|
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
|
|
|
* FILE: boot/drivers/bus/acpi/compbatt/comppnp.c
|
|
|
|
* PURPOSE: Plug-and-Play IOCTL/IRP Handling
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include "compbatt.h"
|
|
|
|
|
2014-01-27 23:11:48 +00:00
|
|
|
#include <wdmguid.h>
|
|
|
|
|
2010-03-25 14:26:04 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-25 14:26:04 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CompBattPowerDispatch(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2010-03-27 21:34:06 +00:00
|
|
|
PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
2013-04-13 21:28:10 +00:00
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: PowerDispatch received power IRP.\n");
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Start the next IRP */
|
|
|
|
PoStartNextPowerIrp(Irp);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Call the next driver in the stack */
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
return PoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
PCOMPBATT_BATTERY_DATA
|
2010-03-25 14:26:04 +00:00
|
|
|
NTAPI
|
|
|
|
RemoveBatteryFromList(IN PCUNICODE_STRING BatteryName,
|
|
|
|
IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
|
|
|
{
|
2010-03-29 00:02:05 +00:00
|
|
|
PLIST_ENTRY ListHead, NextEntry;
|
|
|
|
PCOMPBATT_BATTERY_DATA BatteryData;
|
|
|
|
if (CompBattDebug & 1)
|
|
|
|
DbgPrint("CompBatt: ENTERING RemoveBatteryFromList\n");
|
|
|
|
|
|
|
|
/* Loop the battery list */
|
|
|
|
ExAcquireFastMutex(&DeviceExtension->Lock);
|
|
|
|
ListHead = &DeviceExtension->BatteryList;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
|
|
|
/* Get the battery information and compare the name */
|
|
|
|
BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
|
|
|
|
if (!RtlCompareUnicodeString(BatteryName, &BatteryData->BatteryName, TRUE))
|
|
|
|
{
|
|
|
|
/* Flush pending deletes and any lock waiters */
|
|
|
|
IoAcquireRemoveLock(&BatteryData->RemoveLock, 0);
|
|
|
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
|
|
|
IoReleaseRemoveLockAndWait(&BatteryData->RemoveLock, 0);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Remove the entry from the list */
|
|
|
|
ExAcquireFastMutex(&DeviceExtension->Lock);
|
|
|
|
RemoveEntryList(&BatteryData->BatteryLink);
|
|
|
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
|
|
|
return BatteryData;
|
|
|
|
}
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 02:02:07 +00:00
|
|
|
/* Next */
|
|
|
|
NextEntry = NextEntry->Flink;
|
2010-03-29 00:02:05 +00:00
|
|
|
}
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Done */
|
|
|
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING RemoveBatteryFromList\n");
|
2014-10-23 18:33:21 +00:00
|
|
|
return NULL;
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
IsBatteryAlreadyOnList(IN PCUNICODE_STRING BatteryName,
|
|
|
|
IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
|
|
|
{
|
2010-03-29 00:02:05 +00:00
|
|
|
PLIST_ENTRY ListHead, NextEntry;
|
|
|
|
PCOMPBATT_BATTERY_DATA BatteryData;
|
|
|
|
BOOLEAN Found = FALSE;
|
|
|
|
if (CompBattDebug & 1)
|
|
|
|
DbgPrint("CompBatt: ENTERING IsBatteryAlreadyOnList\n");
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Loop the battery list */
|
|
|
|
ExAcquireFastMutex(&DeviceExtension->Lock);
|
|
|
|
ListHead = &DeviceExtension->BatteryList;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
|
|
|
/* Get the battery information and compare the name */
|
|
|
|
BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
|
|
|
|
if (!RtlCompareUnicodeString(BatteryName, &BatteryData->BatteryName, TRUE))
|
|
|
|
{
|
|
|
|
/* Got it */
|
|
|
|
Found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-29 02:02:07 +00:00
|
|
|
|
|
|
|
/* Next */
|
|
|
|
NextEntry = NextEntry->Flink;
|
2010-03-29 00:02:05 +00:00
|
|
|
}
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Release the lock and return search status */
|
|
|
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING IsBatteryAlreadyOnList\n");
|
|
|
|
return Found;
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2010-03-29 00:10:56 +00:00
|
|
|
CompBattAddNewBattery(IN PUNICODE_STRING BatteryName,
|
2010-03-25 14:26:04 +00:00
|
|
|
IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
|
|
|
{
|
2010-03-29 00:02:05 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PCOMPBATT_BATTERY_DATA BatteryData;
|
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PAGED_CODE();
|
|
|
|
if (CompBattDebug & 1)
|
|
|
|
DbgPrint("CompBatt: ENTERING AddNewBattery \"%w\" \n", BatteryName->Buffer);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Is this a new battery? */
|
|
|
|
if (!IsBatteryAlreadyOnList(BatteryName, DeviceExtension))
|
|
|
|
{
|
|
|
|
/* Allocate battery data */
|
|
|
|
BatteryData = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(COMPBATT_BATTERY_DATA) +
|
|
|
|
BatteryName->Length,
|
|
|
|
'CtaB');
|
|
|
|
if (BatteryData)
|
|
|
|
{
|
|
|
|
/* Initialize the data and write the battery name */
|
|
|
|
RtlZeroMemory(BatteryData, sizeof(COMPBATT_BATTERY_DATA));
|
|
|
|
BatteryData->Tag = 0;
|
|
|
|
BatteryData->BatteryName.MaximumLength = BatteryName->Length;
|
|
|
|
BatteryData->BatteryName.Buffer = (PWCHAR)(BatteryData + 1);
|
|
|
|
RtlCopyUnicodeString(&BatteryData->BatteryName, BatteryName);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Get the device object */
|
|
|
|
Status = CompBattGetDeviceObjectPointer(BatteryName,
|
|
|
|
FILE_ALL_ACCESS,
|
|
|
|
&FileObject,
|
|
|
|
&BatteryData->DeviceObject);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Reference the DO and drop the FO */
|
2012-03-05 20:43:47 +00:00
|
|
|
ObReferenceObject(BatteryData->DeviceObject);
|
|
|
|
ObDereferenceObject(FileObject);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
|
|
|
/* Allocate the battery IRP */
|
2010-03-29 00:02:05 +00:00
|
|
|
Irp = IoAllocateIrp(BatteryData->DeviceObject->StackSize + 1, 0);
|
|
|
|
if (Irp)
|
|
|
|
{
|
|
|
|
/* Save it */
|
|
|
|
BatteryData->Irp = Irp;
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Setup the stack location */
|
|
|
|
IoStackLocation = IoGetNextIrpStackLocation(Irp);
|
|
|
|
IoStackLocation->Parameters.Others.Argument1 = DeviceExtension;
|
|
|
|
IoStackLocation->Parameters.Others.Argument2 = BatteryData;
|
|
|
|
|
|
|
|
/* Set IRP data */
|
|
|
|
IoSetNextIrpStackLocation(Irp);
|
|
|
|
Irp->IoStatus.Status = STATUS_DEVICE_NOT_CONNECTED;
|
|
|
|
BatteryData->WaitFlag = 0;
|
|
|
|
|
|
|
|
/* Insert this battery in the list */
|
|
|
|
ExAcquireFastMutex(&DeviceExtension->Lock);
|
|
|
|
InsertTailList(&DeviceExtension->BatteryList,
|
|
|
|
&BatteryData->BatteryLink);
|
|
|
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
|
|
|
|
|
|
|
/* Initialize the work item and delete lock */
|
|
|
|
IoInitializeRemoveLock(&BatteryData->RemoveLock, 0, 0, 0);
|
|
|
|
ExInitializeWorkItem(&BatteryData->WorkItem,
|
|
|
|
(PVOID)CompBattMonitorIrpCompleteWorker,
|
|
|
|
BatteryData);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Setup the IRP work entry */
|
|
|
|
CompBattMonitorIrpComplete(BatteryData->DeviceObject, Irp, 0);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Fail, no memory */
|
|
|
|
if (CompBattDebug & 8)
|
|
|
|
DbgPrint("CompBatt: Couldn't allocate new battery Irp\n");
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
2012-03-05 20:43:47 +00:00
|
|
|
ObDereferenceObject(BatteryData->DeviceObject);
|
2010-03-29 00:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (CompBattDebug & 8)
|
|
|
|
{
|
|
|
|
/* Fail */
|
2014-01-14 21:21:29 +00:00
|
|
|
DbgPrint("CompBattAddNewBattery: Failed to get device Object. status = %lx\n",
|
2010-03-29 00:02:05 +00:00
|
|
|
Status);
|
|
|
|
}
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Free the battery data */
|
|
|
|
ExFreePool(BatteryData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Fail, no memory */
|
|
|
|
if (CompBattDebug & 8)
|
|
|
|
DbgPrint("CompBatt: Couldn't allocate new battery node\n");
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We're done */
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING AddNewBattery\n");
|
|
|
|
return Status;
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CompBattRemoveBattery(IN PCUNICODE_STRING BatteryName,
|
|
|
|
IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
|
|
|
{
|
2010-03-29 00:02:05 +00:00
|
|
|
PCOMPBATT_BATTERY_DATA BatteryData;
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: RemoveBattery\n");
|
|
|
|
|
|
|
|
/* Remove the entry */
|
|
|
|
BatteryData = RemoveBatteryFromList(BatteryName, DeviceExtension);
|
|
|
|
if (BatteryData)
|
|
|
|
{
|
|
|
|
/* Dereference and free it */
|
2012-03-05 20:43:47 +00:00
|
|
|
ObDereferenceObject(BatteryData->DeviceObject);
|
2010-03-29 00:02:05 +00:00
|
|
|
ExFreePool(BatteryData);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Notify class driver */
|
|
|
|
DeviceExtension->Flags = 0;
|
|
|
|
BatteryClassStatusNotify(DeviceExtension->ClassData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It's done */
|
|
|
|
return STATUS_SUCCESS;
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CompBattGetBatteries(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
|
|
|
{
|
2010-03-29 00:02:05 +00:00
|
|
|
PWCHAR p;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PWCHAR LinkList;
|
|
|
|
UNICODE_STRING LinkString;
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING GetBatteries\n");
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Get all battery links */
|
|
|
|
Status = IoGetDeviceInterfaces(&GUID_DEVICE_BATTERY, NULL, 0, &LinkList);
|
|
|
|
p = LinkList;
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Loop all strings inside */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Create the string */
|
|
|
|
RtlInitUnicodeString(&LinkString, p);
|
|
|
|
if (!LinkString.Length) break;
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Add this battery and move on */
|
|
|
|
Status = CompBattAddNewBattery(&LinkString, DeviceExtension);
|
|
|
|
p += (LinkString.Length / sizeof(WCHAR)) + sizeof(UNICODE_NULL);
|
|
|
|
}
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Parsing complete, clean up buffer */
|
|
|
|
ExFreePool(LinkList);
|
|
|
|
}
|
|
|
|
else if (CompBattDebug & 8)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
DbgPrint("CompBatt: Couldn't get list of batteries\n");
|
|
|
|
}
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-29 00:02:05 +00:00
|
|
|
/* Done */
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING GetBatteries\n");
|
|
|
|
return Status;
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CompBattPnpEventHandler(IN PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification,
|
|
|
|
IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
|
|
|
{
|
2010-03-29 00:02:05 +00:00
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING PnpEventHandler\n");
|
|
|
|
if (CompBattDebug & 2) DbgPrint("CompBatt: Received device interface change notification\n");
|
|
|
|
|
|
|
|
/* Check what happened */
|
|
|
|
if (IsEqualGUIDAligned(&Notification->Event, &GUID_DEVICE_INTERFACE_ARRIVAL))
|
|
|
|
{
|
|
|
|
/* Add the new battery */
|
|
|
|
if (CompBattDebug & 2)
|
|
|
|
DbgPrint("CompBatt: Received notification of battery arrival\n");
|
|
|
|
CompBattAddNewBattery(Notification->SymbolicLinkName, DeviceExtension);
|
|
|
|
}
|
|
|
|
else if (IsEqualGUIDAligned(&Notification->Event, &GUID_DEVICE_INTERFACE_REMOVAL))
|
|
|
|
{
|
|
|
|
/* Don't do anything */
|
|
|
|
if (CompBattDebug & 2)
|
|
|
|
DbgPrint("CompBatt: Received notification of battery removal\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Shouldn't happen */
|
|
|
|
if (CompBattDebug & 2) DbgPrint("CompBatt: Received unhandled PnP event\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done, return success */
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING PnpEventHandler\n");
|
|
|
|
return STATUS_SUCCESS;
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CompBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PDEVICE_OBJECT PdoDeviceObject)
|
|
|
|
{
|
2010-03-27 21:34:06 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING DeviceName;
|
|
|
|
PCOMPBATT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
UNICODE_STRING SymbolicLinkName;
|
|
|
|
BATTERY_MINIPORT_INFO MiniportInfo;
|
|
|
|
if (CompBattDebug & 2) DbgPrint("CompBatt: Got an AddDevice - %x\n", PdoDeviceObject);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Create the device */
|
|
|
|
RtlInitUnicodeString(&DeviceName, L"\\Device\\CompositeBattery");
|
|
|
|
Status = IoCreateDevice(DriverObject,
|
|
|
|
sizeof(COMPBATT_DEVICE_EXTENSION),
|
2014-01-14 21:21:29 +00:00
|
|
|
&DeviceName,
|
2010-03-27 21:34:06 +00:00
|
|
|
FILE_DEVICE_BATTERY,
|
|
|
|
FILE_DEVICE_SECURE_OPEN,
|
|
|
|
FALSE,
|
|
|
|
&DeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Setup symbolic link for Win32 access */
|
|
|
|
RtlInitUnicodeString(&SymbolicLinkName, L"\\DosDevices\\CompositeBattery");
|
|
|
|
IoCreateSymbolicLink(&SymbolicLinkName, &DeviceName);
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Initialize the device extension */
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
2014-01-14 21:21:29 +00:00
|
|
|
RtlZeroMemory(DeviceExtension, sizeof(COMPBATT_DEVICE_EXTENSION));
|
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Attach to device stack and set DO pointers */
|
|
|
|
DeviceExtension->AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
|
|
|
PdoDeviceObject);
|
|
|
|
DeviceExtension->DeviceObject = DeviceObject;
|
|
|
|
if (!DeviceExtension->AttachedDevice)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
if (CompBattDebug & 8)
|
|
|
|
DbgPrint("CompBattAddDevice: Could not attach to LowerDevice.\n");
|
|
|
|
IoDeleteDevice(DeviceObject);
|
2014-01-14 21:21:29 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2010-03-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set device object flags */
|
|
|
|
DeviceObject->Flags |= (DO_POWER_PAGABLE | DO_BUFFERED_IO);
|
|
|
|
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
|
|
|
|
/* Setup the device extension */
|
|
|
|
ExInitializeFastMutex(&DeviceExtension->Lock);
|
|
|
|
InitializeListHead(&DeviceExtension->BatteryList);
|
|
|
|
DeviceExtension->Flags = 0;
|
|
|
|
DeviceExtension->NextTag = 1;
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Setup the miniport data */
|
|
|
|
RtlZeroMemory(&MiniportInfo, sizeof(MiniportInfo));
|
|
|
|
MiniportInfo.MajorVersion = BATTERY_CLASS_MAJOR_VERSION;
|
|
|
|
MiniportInfo.MinorVersion = BATTERY_CLASS_MINOR_VERSION;
|
|
|
|
MiniportInfo.Context = DeviceExtension;
|
|
|
|
MiniportInfo.DeviceName = &DeviceName;
|
|
|
|
MiniportInfo.QueryTag = (BCLASS_QUERY_TAG)CompBattQueryTag;
|
|
|
|
MiniportInfo.QueryInformation = (BCLASS_QUERY_INFORMATION)CompBattQueryInformation;
|
|
|
|
MiniportInfo.SetInformation = NULL;
|
|
|
|
MiniportInfo.QueryStatus = (BCLASS_QUERY_STATUS)CompBattQueryStatus;
|
|
|
|
MiniportInfo.SetStatusNotify = (BCLASS_SET_STATUS_NOTIFY)CompBattSetStatusNotify;
|
|
|
|
MiniportInfo.DisableStatusNotify = (BCLASS_DISABLE_STATUS_NOTIFY)CompBattDisableStatusNotify;
|
|
|
|
MiniportInfo.Pdo = NULL;
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Register with the class driver */
|
|
|
|
Status = BatteryClassInitializeDevice(&MiniportInfo,
|
|
|
|
&DeviceExtension->ClassData);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Undo everything */
|
|
|
|
IoDetachDevice(DeviceExtension->AttachedDevice);
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CompBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2010-03-27 21:34:06 +00:00
|
|
|
PIO_STACK_LOCATION IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
NTSTATUS Status;
|
|
|
|
PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING PnpDispatch\n");
|
|
|
|
|
|
|
|
/* Set default error */
|
|
|
|
Status = STATUS_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
/* Check what kind of PnP function this is */
|
|
|
|
switch (IoStackLocation->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_START_DEVICE:
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Device is starting, register for new batteries and pick up current ones */
|
|
|
|
Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
|
|
|
|
0,
|
|
|
|
(PVOID)&GUID_DEVICE_BATTERY,
|
|
|
|
DeviceObject->DriverObject,
|
|
|
|
(PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)CompBattPnpEventHandler,
|
|
|
|
DeviceExtension,
|
|
|
|
&DeviceExtension->NotificationEntry);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Now go get the batteries */
|
|
|
|
if (CompBattDebug & 2)
|
|
|
|
DbgPrint("CompBatt: Successfully registered for PnP notification\n");
|
|
|
|
Status = CompBattGetBatteries(DeviceExtension);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We failed */
|
|
|
|
if (CompBattDebug & 8)
|
|
|
|
DbgPrint("CompBatt: Couldn't register for PnP notification - %x\n",
|
|
|
|
Status);
|
|
|
|
}
|
2010-12-28 18:20:28 +00:00
|
|
|
break;
|
2010-03-27 21:34:06 +00:00
|
|
|
case IRP_MN_CANCEL_STOP_DEVICE:
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Explicitly say ok */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
|
|
|
|
|
|
|
/* Explicitly say ok */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Explicitly say ok */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Add this in */
|
|
|
|
Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
default:
|
2014-01-14 21:21:29 +00:00
|
|
|
|
2010-03-27 21:34:06 +00:00
|
|
|
/* Not supported */
|
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set IRP status if we have one */
|
|
|
|
if (Status != STATUS_NOT_SUPPORTED) Irp->IoStatus.Status = Status;
|
|
|
|
|
2014-01-14 21:21:29 +00:00
|
|
|
/* Did someone pick it up? */
|
2010-03-27 21:34:06 +00:00
|
|
|
if ((NT_SUCCESS(Status)) || (Status == STATUS_NOT_SUPPORTED))
|
|
|
|
{
|
|
|
|
/* Still unsupported, try ACPI */
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Complete the request */
|
|
|
|
Status = Irp->IoStatus.Status;
|
2010-03-29 00:02:05 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2010-03-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the remove lock and return status */
|
|
|
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING PnpDispatch\n");
|
|
|
|
return Status;
|
2010-03-25 14:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|