mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 01:25:41 +00:00
[BATTC] Check if MiniportInfo->Pdo is NULL before passing it to IoRegisterDeviceInterface
[CMBATT] Fix broken CmBattGetAcpiInterfaces [COMPBATT] Fix "typo" in CompBattAddDevice that caused memory corruption svn path=/trunk/; revision=61628
This commit is contained in:
parent
fa95b5794c
commit
1ea1ab9f88
4 changed files with 186 additions and 116 deletions
|
@ -151,18 +151,26 @@ BatteryClassInitializeDevice(PBATTERY_MINIPORT_INFO MiniportInfo,
|
||||||
|
|
||||||
ExInitializeFastMutex(&BattClass->Mutex);
|
ExInitializeFastMutex(&BattClass->Mutex);
|
||||||
|
|
||||||
Status = IoRegisterDeviceInterface(MiniportInfo->Pdo,
|
if (MiniportInfo->Pdo != NULL)
|
||||||
&GUID_DEVICE_BATTERY,
|
|
||||||
NULL,
|
|
||||||
&BattClass->InterfaceName);
|
|
||||||
if (NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
DPRINT("Initialized battery interface: %wZ\n", &BattClass->InterfaceName);
|
Status = IoRegisterDeviceInterface(MiniportInfo->Pdo,
|
||||||
IoSetDeviceInterfaceState(&BattClass->InterfaceName, TRUE);
|
&GUID_DEVICE_BATTERY,
|
||||||
}
|
NULL,
|
||||||
else
|
&BattClass->InterfaceName);
|
||||||
{
|
if (NT_SUCCESS(Status))
|
||||||
DPRINT1("IoRegisterDeviceInterface failed (0x%x)\n", Status);
|
{
|
||||||
|
DPRINT("Initialized battery interface: %wZ\n", &BattClass->InterfaceName);
|
||||||
|
Status = IoSetDeviceInterfaceState(&BattClass->InterfaceName, TRUE);
|
||||||
|
if (Status == STATUS_OBJECT_NAME_EXISTS)
|
||||||
|
{
|
||||||
|
DPRINT1("Got STATUS_OBJECT_NAME_EXISTS for SetDeviceInterfaceState\n");
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DPRINT1("IoRegisterDeviceInterface failed (0x%x)\n", Status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*ClassData = BattClass;
|
*ClassData = BattClass;
|
||||||
|
|
|
@ -23,7 +23,7 @@ CmBattWaitWakeLoop(IN PDEVICE_OBJECT DeviceObject,
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PCMBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
PCMBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
if (CmBattDebug & 0x20) DbgPrint("CmBattWaitWakeLoop: Entered.\n");
|
if (CmBattDebug & 0x20) DbgPrint("CmBattWaitWakeLoop: Entered.\n");
|
||||||
|
|
||||||
/* Check for success */
|
/* Check for success */
|
||||||
if ((NT_SUCCESS(IoStatusBlock->Status)) && (DeviceExtension->WaitWakeEnable))
|
if ((NT_SUCCESS(IoStatusBlock->Status)) && (DeviceExtension->WaitWakeEnable))
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ CmBattWaitWakeLoop(IN PDEVICE_OBJECT DeviceObject,
|
||||||
DeviceExtension->PowerIrp = NULL;
|
DeviceExtension->PowerIrp = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CmBattIoCompletion(IN PDEVICE_OBJECT DeviceObject,
|
CmBattIoCompletion(IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
@ -87,6 +87,7 @@ CmBattGetAcpiInterfaces(IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
/* Build the query */
|
/* Build the query */
|
||||||
IoStackLocation = IoGetNextIrpStackLocation(Irp);
|
IoStackLocation = IoGetNextIrpStackLocation(Irp);
|
||||||
|
IoStackLocation->MajorFunction = IRP_MJ_PNP;
|
||||||
IoStackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE;
|
IoStackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE;
|
||||||
IoStackLocation->Parameters.QueryInterface.InterfaceType = &GUID_ACPI_INTERFACE_STANDARD;
|
IoStackLocation->Parameters.QueryInterface.InterfaceType = &GUID_ACPI_INTERFACE_STANDARD;
|
||||||
IoStackLocation->Parameters.QueryInterface.Size = sizeof(ACPI_INTERFACE_STANDARD);
|
IoStackLocation->Parameters.QueryInterface.Size = sizeof(ACPI_INTERFACE_STANDARD);
|
||||||
|
@ -100,16 +101,15 @@ CmBattGetAcpiInterfaces(IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
/* Initialize our wait event */
|
/* Initialize our wait event */
|
||||||
KeInitializeEvent(&Event, SynchronizationEvent, 0);
|
KeInitializeEvent(&Event, SynchronizationEvent, 0);
|
||||||
|
|
||||||
/* Set the completion routine */
|
/* Set the completion routine */
|
||||||
IoCopyCurrentIrpStackLocationToNext(Irp);
|
|
||||||
IoSetCompletionRoutine(Irp,
|
IoSetCompletionRoutine(Irp,
|
||||||
(PVOID)CmBattIoCompletion,
|
(PVOID)CmBattIoCompletion,
|
||||||
&Event,
|
&Event,
|
||||||
TRUE,
|
TRUE,
|
||||||
TRUE,
|
TRUE,
|
||||||
TRUE);
|
TRUE);
|
||||||
|
|
||||||
/* Now call ACPI */
|
/* Now call ACPI */
|
||||||
Status = IoCallDriver(DeviceObject, Irp);
|
Status = IoCallDriver(DeviceObject, Irp);
|
||||||
if (Status == STATUS_PENDING)
|
if (Status == STATUS_PENDING)
|
||||||
|
@ -122,10 +122,10 @@ CmBattGetAcpiInterfaces(IN PDEVICE_OBJECT DeviceObject,
|
||||||
NULL);
|
NULL);
|
||||||
Status = Irp->IoStatus.Status;
|
Status = Irp->IoStatus.Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the IRP */
|
/* Free the IRP */
|
||||||
IoFreeIrp(Irp);
|
IoFreeIrp(Irp);
|
||||||
|
|
||||||
/* Return status */
|
/* Return status */
|
||||||
if (!(NT_SUCCESS(Status)) && (CmBattDebug & 0xC))
|
if (!(NT_SUCCESS(Status)) && (CmBattDebug & 0xC))
|
||||||
DbgPrint("CmBattGetAcpiInterfaces: Could not get ACPI driver interfaces, status = %x\n", Status);
|
DbgPrint("CmBattGetAcpiInterfaces: Could not get ACPI driver interfaces, status = %x\n", Status);
|
||||||
|
@ -157,7 +157,7 @@ CmBattRemoveDevice(IN PDEVICE_OBJECT DeviceObject,
|
||||||
DeviceExtension,
|
DeviceExtension,
|
||||||
DeviceExtension->FdoType,
|
DeviceExtension->FdoType,
|
||||||
DeviceExtension->DeviceId);
|
DeviceExtension->DeviceId);
|
||||||
|
|
||||||
/* Make sure it's safe to go ahead */
|
/* Make sure it's safe to go ahead */
|
||||||
IoReleaseRemoveLockAndWait(&DeviceExtension->RemoveLock, 0);
|
IoReleaseRemoveLockAndWait(&DeviceExtension->RemoveLock, 0);
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ CmBattRemoveDevice(IN PDEVICE_OBJECT DeviceObject,
|
||||||
IoCancelIrp(DeviceExtension->PowerIrp);
|
IoCancelIrp(DeviceExtension->PowerIrp);
|
||||||
DeviceExtension->PowerIrp = NULL;
|
DeviceExtension->PowerIrp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check what type of FDO is being removed */
|
/* Check what type of FDO is being removed */
|
||||||
Context = DeviceExtension->AcpiInterface.Context;
|
Context = DeviceExtension->AcpiInterface.Context;
|
||||||
if (DeviceExtension->FdoType == CmBattBattery)
|
if (DeviceExtension->FdoType == CmBattBattery)
|
||||||
|
@ -187,7 +187,7 @@ CmBattRemoveDevice(IN PDEVICE_OBJECT DeviceObject,
|
||||||
CmBattWmiDeRegistration(DeviceExtension);
|
CmBattWmiDeRegistration(DeviceExtension);
|
||||||
AcAdapterPdo = NULL;
|
AcAdapterPdo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detach and delete */
|
/* Detach and delete */
|
||||||
IoDetachDevice(DeviceExtension->AttachedDevice);
|
IoDetachDevice(DeviceExtension->AttachedDevice);
|
||||||
IoDeleteDevice(DeviceExtension->DeviceObject);
|
IoDeleteDevice(DeviceExtension->DeviceObject);
|
||||||
|
@ -209,30 +209,30 @@ CmBattPowerDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
DeviceExtension = DeviceObject->DeviceExtension;
|
DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
switch (IoStackLocation->MinorFunction)
|
switch (IoStackLocation->MinorFunction)
|
||||||
{
|
{
|
||||||
case IRP_MN_WAIT_WAKE:
|
case IRP_MN_WAIT_WAKE:
|
||||||
if (CmBattDebug & 0x10)
|
if (CmBattDebug & 0x10)
|
||||||
DbgPrint("CmBattPowerDispatch: IRP_MN_WAIT_WAKE\n");
|
DbgPrint("CmBattPowerDispatch: IRP_MN_WAIT_WAKE\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_POWER_SEQUENCE:
|
case IRP_MN_POWER_SEQUENCE:
|
||||||
if (CmBattDebug & 0x10)
|
if (CmBattDebug & 0x10)
|
||||||
DbgPrint("CmBattPowerDispatch: IRP_MN_POWER_SEQUENCE\n");
|
DbgPrint("CmBattPowerDispatch: IRP_MN_POWER_SEQUENCE\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_QUERY_POWER:
|
case IRP_MN_QUERY_POWER:
|
||||||
if (CmBattDebug & 0x10)
|
if (CmBattDebug & 0x10)
|
||||||
DbgPrint("CmBattPowerDispatch: IRP_MN_WAIT_WAKE\n");
|
DbgPrint("CmBattPowerDispatch: IRP_MN_WAIT_WAKE\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_SET_POWER:
|
case IRP_MN_SET_POWER:
|
||||||
if (CmBattDebug & 0x10)
|
if (CmBattDebug & 0x10)
|
||||||
DbgPrint("CmBattPowerDispatch: IRP_MN_SET_POWER type: %d, State: %d \n",
|
DbgPrint("CmBattPowerDispatch: IRP_MN_SET_POWER type: %d, State: %d \n",
|
||||||
IoStackLocation->Parameters.Power.Type,
|
IoStackLocation->Parameters.Power.Type,
|
||||||
IoStackLocation->Parameters.Power.State);
|
IoStackLocation->Parameters.Power.State);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if (CmBattDebug & 1)
|
if (CmBattDebug & 1)
|
||||||
DbgPrint("CmBattPowerDispatch: minor %d\n", IoStackLocation->MinorFunction);
|
DbgPrint("CmBattPowerDispatch: minor %d\n", IoStackLocation->MinorFunction);
|
||||||
break;
|
break;
|
||||||
|
@ -252,7 +252,7 @@ CmBattPowerDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
Status = Irp->IoStatus.Status;
|
Status = Irp->IoStatus.Status;
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return status */
|
/* Return status */
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -271,12 +271,12 @@ CmBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
/* Get stack location and device extension */
|
/* Get stack location and device extension */
|
||||||
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
||||||
DeviceExtension = DeviceObject->DeviceExtension;
|
DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
|
|
||||||
/* Set default error */
|
/* Set default error */
|
||||||
Status = STATUS_NOT_SUPPORTED;
|
Status = STATUS_NOT_SUPPORTED;
|
||||||
|
|
||||||
/* Try to acquire the lock before doing anything */
|
/* Try to acquire the lock before doing anything */
|
||||||
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, 0);
|
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* Complete the request */
|
/* Complete the request */
|
||||||
|
@ -287,9 +287,9 @@ CmBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
/* What's the operation? */
|
/* What's the operation? */
|
||||||
switch (IoStackLocation->MinorFunction)
|
switch (IoStackLocation->MinorFunction)
|
||||||
{
|
{
|
||||||
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
||||||
|
|
||||||
/* Initialize our wait event */
|
/* Initialize our wait event */
|
||||||
KeInitializeEvent(&Event, SynchronizationEvent, 0);
|
KeInitializeEvent(&Event, SynchronizationEvent, 0);
|
||||||
|
|
||||||
|
@ -322,28 +322,28 @@ CmBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
||||||
return Status;
|
return Status;
|
||||||
|
|
||||||
case IRP_MN_SURPRISE_REMOVAL:
|
case IRP_MN_SURPRISE_REMOVAL:
|
||||||
if (CmBattDebug & 0x20)
|
if (CmBattDebug & 0x20)
|
||||||
DbgPrint("CmBattPnpDispatch: IRP_MN_SURPRISE_REMOVAL\n");
|
DbgPrint("CmBattPnpDispatch: IRP_MN_SURPRISE_REMOVAL\n");
|
||||||
|
|
||||||
/* Lock the device extension and set the handle count to invalid */
|
/* Lock the device extension and set the handle count to invalid */
|
||||||
ExAcquireFastMutex(&DeviceExtension->FastMutex);
|
ExAcquireFastMutex(&DeviceExtension->FastMutex);
|
||||||
DeviceExtension->HandleCount = -1;
|
DeviceExtension->HandleCount = -1;
|
||||||
ExReleaseFastMutex(&DeviceExtension->FastMutex);
|
ExReleaseFastMutex(&DeviceExtension->FastMutex);
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_START_DEVICE:
|
case IRP_MN_START_DEVICE:
|
||||||
if (CmBattDebug & 0x20)
|
if (CmBattDebug & 0x20)
|
||||||
DbgPrint("CmBattPnpDispatch: IRP_MN_START_DEVICE\n");
|
DbgPrint("CmBattPnpDispatch: IRP_MN_START_DEVICE\n");
|
||||||
|
|
||||||
/* Mark the extension as started */
|
/* Mark the extension as started */
|
||||||
if (DeviceExtension->FdoType == CmBattBattery) DeviceExtension->Started = TRUE;
|
if (DeviceExtension->FdoType == CmBattBattery) DeviceExtension->Started = TRUE;
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_STOP_DEVICE:
|
case IRP_MN_STOP_DEVICE:
|
||||||
if (CmBattDebug & 0x20)
|
if (CmBattDebug & 0x20)
|
||||||
DbgPrint("CmBattPnpDispatch: IRP_MN_STOP_DEVICE\n");
|
DbgPrint("CmBattPnpDispatch: IRP_MN_STOP_DEVICE\n");
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ CmBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
if (DeviceExtension->FdoType == CmBattBattery) DeviceExtension->Started = FALSE;
|
if (DeviceExtension->FdoType == CmBattBattery) DeviceExtension->Started = FALSE;
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_QUERY_REMOVE_DEVICE:
|
case IRP_MN_QUERY_REMOVE_DEVICE:
|
||||||
if (CmBattDebug & 0x20)
|
if (CmBattDebug & 0x20)
|
||||||
DbgPrint("CmBattPnpDispatch: IRP_MN_QUERY_REMOVE_DEVICE\n");
|
DbgPrint("CmBattPnpDispatch: IRP_MN_QUERY_REMOVE_DEVICE\n");
|
||||||
|
@ -376,23 +376,23 @@ CmBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
/* Fail because there's still open handles */
|
/* Fail because there's still open handles */
|
||||||
Status = STATUS_UNSUCCESSFUL;
|
Status = STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release the lock and return */
|
/* Release the lock and return */
|
||||||
ExReleaseFastMutex(&DeviceExtension->FastMutex);
|
ExReleaseFastMutex(&DeviceExtension->FastMutex);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_REMOVE_DEVICE:
|
case IRP_MN_REMOVE_DEVICE:
|
||||||
if (CmBattDebug & 0x20)
|
if (CmBattDebug & 0x20)
|
||||||
DbgPrint("CmBattPnpDispatch: IRP_MN_REMOVE_DEVICE\n");
|
DbgPrint("CmBattPnpDispatch: IRP_MN_REMOVE_DEVICE\n");
|
||||||
|
|
||||||
/* Call the remove code */
|
/* Call the remove code */
|
||||||
Status = CmBattRemoveDevice(DeviceObject, Irp);
|
Status = CmBattRemoveDevice(DeviceObject, Irp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
||||||
if (CmBattDebug & 0x20)
|
if (CmBattDebug & 0x20)
|
||||||
DbgPrint("CmBattPnpDispatch: IRP_MN_CANCEL_REMOVE_DEVICE\n");
|
DbgPrint("CmBattPnpDispatch: IRP_MN_CANCEL_REMOVE_DEVICE\n");
|
||||||
|
|
||||||
/* Lock the extension and get the handle count */
|
/* Lock the extension and get the handle count */
|
||||||
ExAcquireFastMutex(&DeviceExtension->FastMutex);
|
ExAcquireFastMutex(&DeviceExtension->FastMutex);
|
||||||
if (DeviceExtension->HandleCount == -1)
|
if (DeviceExtension->HandleCount == -1)
|
||||||
|
@ -403,33 +403,33 @@ CmBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
else if (CmBattDebug & 2)
|
else if (CmBattDebug & 2)
|
||||||
{
|
{
|
||||||
/* Nop, but warn about it */
|
/* Nop, but warn about it */
|
||||||
DbgPrint("CmBattPnpDispatch: Received CANCEL_REMOVE when OpenCount == %x\n",
|
DbgPrint("CmBattPnpDispatch: Received CANCEL_REMOVE when OpenCount == %x\n",
|
||||||
DeviceExtension->HandleCount);
|
DeviceExtension->HandleCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return success in all cases, and release the lock */
|
/* Return success in all cases, and release the lock */
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
ExReleaseFastMutex(&DeviceExtension->FastMutex);
|
ExReleaseFastMutex(&DeviceExtension->FastMutex);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_QUERY_STOP_DEVICE:
|
case IRP_MN_QUERY_STOP_DEVICE:
|
||||||
if (CmBattDebug & 0x20)
|
if (CmBattDebug & 0x20)
|
||||||
DbgPrint("CmBattPnpDispatch: IRP_MN_QUERY_STOP_DEVICE\n");
|
DbgPrint("CmBattPnpDispatch: IRP_MN_QUERY_STOP_DEVICE\n");
|
||||||
|
|
||||||
/* There's no real support for this */
|
/* There's no real support for this */
|
||||||
Status = STATUS_NOT_IMPLEMENTED;
|
Status = STATUS_NOT_IMPLEMENTED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_CANCEL_STOP_DEVICE:
|
case IRP_MN_CANCEL_STOP_DEVICE:
|
||||||
if (CmBattDebug & 0x20)
|
if (CmBattDebug & 0x20)
|
||||||
DbgPrint("CmBattPnpDispatch: IRP_MN_CANCEL_STOP_DEVICE\n");
|
DbgPrint("CmBattPnpDispatch: IRP_MN_CANCEL_STOP_DEVICE\n");
|
||||||
|
|
||||||
/* There's no real support for this */
|
/* There's no real support for this */
|
||||||
Status = STATUS_NOT_IMPLEMENTED;
|
Status = STATUS_NOT_IMPLEMENTED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_QUERY_CAPABILITIES:
|
case IRP_MN_QUERY_CAPABILITIES:
|
||||||
|
|
||||||
/* Initialize our wait event */
|
/* Initialize our wait event */
|
||||||
KeInitializeEvent(&Event, SynchronizationEvent, 0);
|
KeInitializeEvent(&Event, SynchronizationEvent, 0);
|
||||||
|
|
||||||
|
@ -496,14 +496,14 @@ CmBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
IoStackLocation->MinorFunction);
|
IoStackLocation->MinorFunction);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release the remove lock */
|
/* Release the remove lock */
|
||||||
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
||||||
|
|
||||||
/* Set IRP status if we have one */
|
/* Set IRP status if we have one */
|
||||||
if (Status != STATUS_NOT_SUPPORTED) Irp->IoStatus.Status = Status;
|
if (Status != STATUS_NOT_SUPPORTED) Irp->IoStatus.Status = Status;
|
||||||
|
|
||||||
/* Did someone pick it up? */
|
/* Did someone pick it up? */
|
||||||
if ((NT_SUCCESS(Status)) || (Status == STATUS_NOT_SUPPORTED))
|
if ((NT_SUCCESS(Status)) || (Status == STATUS_NOT_SUPPORTED))
|
||||||
{
|
{
|
||||||
/* Still unsupported, try ACPI */
|
/* Still unsupported, try ACPI */
|
||||||
|
@ -539,7 +539,7 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
|
||||||
ULONG ResultLength;
|
ULONG ResultLength;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
if (CmBattDebug & 0x220) DbgPrint("CmBattCreateFdo: Entered\n");
|
if (CmBattDebug & 0x220) DbgPrint("CmBattCreateFdo: Entered\n");
|
||||||
|
|
||||||
/* Get unique ID */
|
/* Get unique ID */
|
||||||
Status = CmBattGetUniqueId(DeviceObject, &UniqueId);
|
Status = CmBattGetUniqueId(DeviceObject, &UniqueId);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
|
@ -549,7 +549,7 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
|
||||||
if (CmBattDebug & 2)
|
if (CmBattDebug & 2)
|
||||||
DbgPrint("CmBattCreateFdo: Error %x from _UID, assuming unit #0\n", Status);
|
DbgPrint("CmBattCreateFdo: Error %x from _UID, assuming unit #0\n", Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the FDO */
|
/* Create the FDO */
|
||||||
Status = IoCreateDevice(DriverObject,
|
Status = IoCreateDevice(DriverObject,
|
||||||
DeviceExtensionSize,
|
DeviceExtensionSize,
|
||||||
|
@ -565,7 +565,7 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
|
||||||
DbgPrint("CmBattCreateFdo: error (0x%x) creating device object\n", Status);
|
DbgPrint("CmBattCreateFdo: error (0x%x) creating device object\n", Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set FDO flags */
|
/* Set FDO flags */
|
||||||
FdoDeviceObject->Flags |= (DO_POWER_PAGABLE | DO_BUFFERED_IO);
|
FdoDeviceObject->Flags |= (DO_POWER_PAGABLE | DO_BUFFERED_IO);
|
||||||
FdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
FdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
||||||
|
@ -576,7 +576,7 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
|
||||||
FdoExtension->DeviceObject = FdoDeviceObject;
|
FdoExtension->DeviceObject = FdoDeviceObject;
|
||||||
FdoExtension->FdoDeviceObject = FdoDeviceObject;
|
FdoExtension->FdoDeviceObject = FdoDeviceObject;
|
||||||
FdoExtension->PdoDeviceObject = DeviceObject;
|
FdoExtension->PdoDeviceObject = DeviceObject;
|
||||||
|
|
||||||
/* Attach to ACPI */
|
/* Attach to ACPI */
|
||||||
FdoExtension->AttachedDevice = IoAttachDeviceToDeviceStack(FdoDeviceObject,
|
FdoExtension->AttachedDevice = IoAttachDeviceToDeviceStack(FdoDeviceObject,
|
||||||
DeviceObject);
|
DeviceObject);
|
||||||
|
@ -588,7 +588,7 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
|
||||||
DbgPrint("CmBattCreateFdo: IoAttachDeviceToDeviceStack failed.\n");
|
DbgPrint("CmBattCreateFdo: IoAttachDeviceToDeviceStack failed.\n");
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get ACPI interface for EVAL */
|
/* Get ACPI interface for EVAL */
|
||||||
Status = CmBattGetAcpiInterfaces(FdoExtension->AttachedDevice,
|
Status = CmBattGetAcpiInterfaces(FdoExtension->AttachedDevice,
|
||||||
&FdoExtension->AcpiInterface);
|
&FdoExtension->AcpiInterface);
|
||||||
|
@ -604,14 +604,14 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
|
||||||
|
|
||||||
/* Setup the rest of the extension */
|
/* Setup the rest of the extension */
|
||||||
ExInitializeFastMutex(&FdoExtension->FastMutex);
|
ExInitializeFastMutex(&FdoExtension->FastMutex);
|
||||||
IoInitializeRemoveLock(&FdoExtension->RemoveLock, 0, 0, 0);
|
IoInitializeRemoveLock(&FdoExtension->RemoveLock, 'RbmC', 0, 0);
|
||||||
FdoExtension->HandleCount = 0;
|
FdoExtension->HandleCount = 0;
|
||||||
FdoExtension->WaitWakeEnable = FALSE;
|
FdoExtension->WaitWakeEnable = FALSE;
|
||||||
FdoExtension->DeviceId = UniqueId;
|
FdoExtension->DeviceId = UniqueId;
|
||||||
FdoExtension->DeviceName = NULL;
|
FdoExtension->DeviceName = NULL;
|
||||||
FdoExtension->DelayNotification = FALSE;
|
FdoExtension->DelayNotification = FALSE;
|
||||||
FdoExtension->ArFlag = 0;
|
FdoExtension->ArFlag = 0;
|
||||||
|
|
||||||
/* Open the device key */
|
/* Open the device key */
|
||||||
Status = IoOpenDeviceRegistryKey(DeviceObject,
|
Status = IoOpenDeviceRegistryKey(DeviceObject,
|
||||||
PLUGPLAY_REGKEY_DEVICE,
|
PLUGPLAY_REGKEY_DEVICE,
|
||||||
|
@ -630,9 +630,9 @@ CmBattCreateFdo(IN PDRIVER_OBJECT DriverObject,
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* Set value */
|
/* Set value */
|
||||||
FdoExtension->WaitWakeEnable = *(PULONG)PartialInfo->Data;
|
FdoExtension->WaitWakeEnable = ((*(PULONG)PartialInfo->Data) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close the handle */
|
/* Close the handle */
|
||||||
ZwClose(KeyHandle);
|
ZwClose(KeyHandle);
|
||||||
}
|
}
|
||||||
|
@ -652,7 +652,7 @@ CmBattAddBattery(IN PDRIVER_OBJECT DriverObject,
|
||||||
BATTERY_MINIPORT_INFO MiniportInfo;
|
BATTERY_MINIPORT_INFO MiniportInfo;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PDEVICE_OBJECT FdoDeviceObject;
|
PDEVICE_OBJECT FdoDeviceObject;
|
||||||
PCMBATT_DEVICE_EXTENSION FdoExtension;
|
PCMBATT_DEVICE_EXTENSION FdoExtension;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
if (CmBattDebug & 0x220)
|
if (CmBattDebug & 0x220)
|
||||||
DbgPrint("CmBattAddBattery: pdo %x\n", DeviceObject);
|
DbgPrint("CmBattAddBattery: pdo %x\n", DeviceObject);
|
||||||
|
@ -680,7 +680,7 @@ CmBattAddBattery(IN PDRIVER_OBJECT DriverObject,
|
||||||
FdoExtension->InterruptTime = KeQueryInterruptTime();
|
FdoExtension->InterruptTime = KeQueryInterruptTime();
|
||||||
FdoExtension->TripPointSet = CmBattSetTripPpoint(FdoExtension, 0) !=
|
FdoExtension->TripPointSet = CmBattSetTripPpoint(FdoExtension, 0) !=
|
||||||
STATUS_OBJECT_NAME_NOT_FOUND;
|
STATUS_OBJECT_NAME_NOT_FOUND;
|
||||||
|
|
||||||
/* Setup the battery miniport information structure */
|
/* Setup the battery miniport information structure */
|
||||||
RtlZeroMemory(&MiniportInfo, sizeof(MiniportInfo));
|
RtlZeroMemory(&MiniportInfo, sizeof(MiniportInfo));
|
||||||
MiniportInfo.Pdo = DeviceObject;
|
MiniportInfo.Pdo = DeviceObject;
|
||||||
|
@ -694,7 +694,7 @@ CmBattAddBattery(IN PDRIVER_OBJECT DriverObject,
|
||||||
MiniportInfo.SetStatusNotify = (PVOID)CmBattSetStatusNotify;
|
MiniportInfo.SetStatusNotify = (PVOID)CmBattSetStatusNotify;
|
||||||
MiniportInfo.DisableStatusNotify = (PVOID)CmBattDisableStatusNotify;
|
MiniportInfo.DisableStatusNotify = (PVOID)CmBattDisableStatusNotify;
|
||||||
MiniportInfo.DeviceName = FdoExtension->DeviceName;
|
MiniportInfo.DeviceName = FdoExtension->DeviceName;
|
||||||
|
|
||||||
/* Register with the class driver */
|
/* Register with the class driver */
|
||||||
Status = BatteryClassInitializeDevice(&MiniportInfo, &FdoExtension->ClassData);
|
Status = BatteryClassInitializeDevice(&MiniportInfo, &FdoExtension->ClassData);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
|
@ -714,7 +714,7 @@ CmBattAddBattery(IN PDRIVER_OBJECT DriverObject,
|
||||||
DbgPrint("CmBattAddBattery: Could not register as a WMI provider, status = %Lx\n", Status);
|
DbgPrint("CmBattAddBattery: Could not register as a WMI provider, status = %Lx\n", Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register ACPI */
|
/* Register ACPI */
|
||||||
Status = FdoExtension->AcpiInterface.RegisterForDeviceNotifications(FdoExtension->AcpiInterface.Context,
|
Status = FdoExtension->AcpiInterface.RegisterForDeviceNotifications(FdoExtension->AcpiInterface.Context,
|
||||||
(PVOID)CmBattNotifyHandler,
|
(PVOID)CmBattNotifyHandler,
|
||||||
|
@ -728,7 +728,7 @@ CmBattAddBattery(IN PDRIVER_OBJECT DriverObject,
|
||||||
if (CmBattDebug & 0xC)
|
if (CmBattDebug & 0xC)
|
||||||
DbgPrint("CmBattAddBattery: Could not register for battery notify, status = %Lx\n", Status);
|
DbgPrint("CmBattAddBattery: Could not register for battery notify, status = %Lx\n", Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return status */
|
/* Return status */
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -757,7 +757,7 @@ CmBattAddAcAdapter(IN PDRIVER_OBJECT DriverObject,
|
||||||
/* Set this as the AC adapter's PDO */
|
/* Set this as the AC adapter's PDO */
|
||||||
AcAdapterPdo = PdoDeviceObject;
|
AcAdapterPdo = PdoDeviceObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the FDO for the adapter */
|
/* Create the FDO for the adapter */
|
||||||
Status = CmBattCreateFdo(DriverObject,
|
Status = CmBattCreateFdo(DriverObject,
|
||||||
PdoDeviceObject,
|
PdoDeviceObject,
|
||||||
|
@ -770,7 +770,7 @@ CmBattAddAcAdapter(IN PDRIVER_OBJECT DriverObject,
|
||||||
DbgPrint("CmBattAddAcAdapter: error (0x%x) creating Fdo\n", Status);
|
DbgPrint("CmBattAddAcAdapter: error (0x%x) creating Fdo\n", Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the type and do WMI registration */
|
/* Set the type and do WMI registration */
|
||||||
DeviceExtension = FdoDeviceObject->DeviceExtension;
|
DeviceExtension = FdoDeviceObject->DeviceExtension;
|
||||||
DeviceExtension->FdoType = CmBattAcAdapter;
|
DeviceExtension->FdoType = CmBattAcAdapter;
|
||||||
|
@ -781,7 +781,7 @@ CmBattAddAcAdapter(IN PDRIVER_OBJECT DriverObject,
|
||||||
if (CmBattDebug & 0xC)
|
if (CmBattDebug & 0xC)
|
||||||
DbgPrint("CmBattAddBattery: Could not register as a WMI provider, status = %Lx\n", Status);
|
DbgPrint("CmBattAddBattery: Could not register as a WMI provider, status = %Lx\n", Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register with ACPI */
|
/* Register with ACPI */
|
||||||
Status = DeviceExtension->AcpiInterface.RegisterForDeviceNotifications(DeviceExtension->AcpiInterface.Context,
|
Status = DeviceExtension->AcpiInterface.RegisterForDeviceNotifications(DeviceExtension->AcpiInterface.Context,
|
||||||
(PVOID)CmBattNotifyHandler,
|
(PVOID)CmBattNotifyHandler,
|
||||||
|
@ -809,7 +809,7 @@ CmBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
if (CmBattDebug & 0x220)
|
if (CmBattDebug & 0x220)
|
||||||
DbgPrint("CmBattAddDevice: Entered with pdo %x\n", PdoDeviceObject);
|
DbgPrint("CmBattAddDevice: Entered with pdo %x\n", PdoDeviceObject);
|
||||||
|
|
||||||
/* Make sure we have a PDO */
|
/* Make sure we have a PDO */
|
||||||
if (!PdoDeviceObject)
|
if (!PdoDeviceObject)
|
||||||
{
|
{
|
||||||
|
@ -817,7 +817,7 @@ CmBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
if (CmBattDebug & 0x24) DbgPrint("CmBattAddDevice: Asked to do detection\n");
|
if (CmBattDebug & 0x24) DbgPrint("CmBattAddDevice: Asked to do detection\n");
|
||||||
return STATUS_NO_MORE_ENTRIES;
|
return STATUS_NO_MORE_ENTRIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open the driver key */
|
/* Open the driver key */
|
||||||
Status = IoOpenDeviceRegistryKey(PdoDeviceObject,
|
Status = IoOpenDeviceRegistryKey(PdoDeviceObject,
|
||||||
PLUGPLAY_REGKEY_DRIVER,
|
PLUGPLAY_REGKEY_DRIVER,
|
||||||
|
@ -846,7 +846,7 @@ CmBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
DbgPrint("CmBattAddDevice: Could not read the power type identifier: %x\n", Status);
|
DbgPrint("CmBattAddDevice: Could not read the power type identifier: %x\n", Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check what kind of power source this is */
|
/* Check what kind of power source this is */
|
||||||
PowerSourceType = *(PULONG)PartialInfo->Data;
|
PowerSourceType = *(PULONG)PartialInfo->Data;
|
||||||
if (PowerSourceType == 1)
|
if (PowerSourceType == 1)
|
||||||
|
@ -866,7 +866,7 @@ CmBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
DbgPrint("CmBattAddDevice: Invalid POWER_SOURCE_TYPE == %d \n", PowerSourceType);
|
DbgPrint("CmBattAddDevice: Invalid POWER_SOURCE_TYPE == %d \n", PowerSourceType);
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return whatever the FDO creation routine did */
|
/* Return whatever the FDO creation routine did */
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "compbatt.h"
|
#include "compbatt.h"
|
||||||
|
|
||||||
/* FUNCTIONS ******************************************************************/
|
/* FUNCTIONS ******************************************************************/
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CompBattPowerDispatch(IN PDEVICE_OBJECT DeviceObject,
|
CompBattPowerDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
@ -19,10 +19,10 @@ CompBattPowerDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
{
|
{
|
||||||
PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
if (CompBattDebug & 1) DbgPrint("CompBatt: PowerDispatch received power IRP.\n");
|
if (CompBattDebug & 1) DbgPrint("CompBatt: PowerDispatch received power IRP.\n");
|
||||||
|
|
||||||
/* Start the next IRP */
|
/* Start the next IRP */
|
||||||
PoStartNextPowerIrp(Irp);
|
PoStartNextPowerIrp(Irp);
|
||||||
|
|
||||||
/* Call the next driver in the stack */
|
/* Call the next driver in the stack */
|
||||||
IoSkipCurrentIrpStackLocation(Irp);
|
IoSkipCurrentIrpStackLocation(Irp);
|
||||||
return PoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
return PoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
||||||
|
@ -52,18 +52,18 @@ RemoveBatteryFromList(IN PCUNICODE_STRING BatteryName,
|
||||||
IoAcquireRemoveLock(&BatteryData->RemoveLock, 0);
|
IoAcquireRemoveLock(&BatteryData->RemoveLock, 0);
|
||||||
ExReleaseFastMutex(&DeviceExtension->Lock);
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
||||||
IoReleaseRemoveLockAndWait(&BatteryData->RemoveLock, 0);
|
IoReleaseRemoveLockAndWait(&BatteryData->RemoveLock, 0);
|
||||||
|
|
||||||
/* Remove the entry from the list */
|
/* Remove the entry from the list */
|
||||||
ExAcquireFastMutex(&DeviceExtension->Lock);
|
ExAcquireFastMutex(&DeviceExtension->Lock);
|
||||||
RemoveEntryList(&BatteryData->BatteryLink);
|
RemoveEntryList(&BatteryData->BatteryLink);
|
||||||
ExReleaseFastMutex(&DeviceExtension->Lock);
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
||||||
return BatteryData;
|
return BatteryData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next */
|
/* Next */
|
||||||
NextEntry = NextEntry->Flink;
|
NextEntry = NextEntry->Flink;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Done */
|
/* Done */
|
||||||
ExReleaseFastMutex(&DeviceExtension->Lock);
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
||||||
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING RemoveBatteryFromList\n");
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING RemoveBatteryFromList\n");
|
||||||
|
@ -80,7 +80,7 @@ IsBatteryAlreadyOnList(IN PCUNICODE_STRING BatteryName,
|
||||||
BOOLEAN Found = FALSE;
|
BOOLEAN Found = FALSE;
|
||||||
if (CompBattDebug & 1)
|
if (CompBattDebug & 1)
|
||||||
DbgPrint("CompBatt: ENTERING IsBatteryAlreadyOnList\n");
|
DbgPrint("CompBatt: ENTERING IsBatteryAlreadyOnList\n");
|
||||||
|
|
||||||
/* Loop the battery list */
|
/* Loop the battery list */
|
||||||
ExAcquireFastMutex(&DeviceExtension->Lock);
|
ExAcquireFastMutex(&DeviceExtension->Lock);
|
||||||
ListHead = &DeviceExtension->BatteryList;
|
ListHead = &DeviceExtension->BatteryList;
|
||||||
|
@ -99,7 +99,7 @@ IsBatteryAlreadyOnList(IN PCUNICODE_STRING BatteryName,
|
||||||
/* Next */
|
/* Next */
|
||||||
NextEntry = NextEntry->Flink;
|
NextEntry = NextEntry->Flink;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release the lock and return search status */
|
/* Release the lock and return search status */
|
||||||
ExReleaseFastMutex(&DeviceExtension->Lock);
|
ExReleaseFastMutex(&DeviceExtension->Lock);
|
||||||
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING IsBatteryAlreadyOnList\n");
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING IsBatteryAlreadyOnList\n");
|
||||||
|
@ -119,7 +119,7 @@ CompBattAddNewBattery(IN PUNICODE_STRING BatteryName,
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
if (CompBattDebug & 1)
|
if (CompBattDebug & 1)
|
||||||
DbgPrint("CompBatt: ENTERING AddNewBattery \"%w\" \n", BatteryName->Buffer);
|
DbgPrint("CompBatt: ENTERING AddNewBattery \"%w\" \n", BatteryName->Buffer);
|
||||||
|
|
||||||
/* Is this a new battery? */
|
/* Is this a new battery? */
|
||||||
if (!IsBatteryAlreadyOnList(BatteryName, DeviceExtension))
|
if (!IsBatteryAlreadyOnList(BatteryName, DeviceExtension))
|
||||||
{
|
{
|
||||||
|
@ -136,7 +136,7 @@ CompBattAddNewBattery(IN PUNICODE_STRING BatteryName,
|
||||||
BatteryData->BatteryName.MaximumLength = BatteryName->Length;
|
BatteryData->BatteryName.MaximumLength = BatteryName->Length;
|
||||||
BatteryData->BatteryName.Buffer = (PWCHAR)(BatteryData + 1);
|
BatteryData->BatteryName.Buffer = (PWCHAR)(BatteryData + 1);
|
||||||
RtlCopyUnicodeString(&BatteryData->BatteryName, BatteryName);
|
RtlCopyUnicodeString(&BatteryData->BatteryName, BatteryName);
|
||||||
|
|
||||||
/* Get the device object */
|
/* Get the device object */
|
||||||
Status = CompBattGetDeviceObjectPointer(BatteryName,
|
Status = CompBattGetDeviceObjectPointer(BatteryName,
|
||||||
FILE_ALL_ACCESS,
|
FILE_ALL_ACCESS,
|
||||||
|
@ -147,14 +147,14 @@ CompBattAddNewBattery(IN PUNICODE_STRING BatteryName,
|
||||||
/* Reference the DO and drop the FO */
|
/* Reference the DO and drop the FO */
|
||||||
ObReferenceObject(BatteryData->DeviceObject);
|
ObReferenceObject(BatteryData->DeviceObject);
|
||||||
ObDereferenceObject(FileObject);
|
ObDereferenceObject(FileObject);
|
||||||
|
|
||||||
/* Allocate the battery IRP */
|
/* Allocate the battery IRP */
|
||||||
Irp = IoAllocateIrp(BatteryData->DeviceObject->StackSize + 1, 0);
|
Irp = IoAllocateIrp(BatteryData->DeviceObject->StackSize + 1, 0);
|
||||||
if (Irp)
|
if (Irp)
|
||||||
{
|
{
|
||||||
/* Save it */
|
/* Save it */
|
||||||
BatteryData->Irp = Irp;
|
BatteryData->Irp = Irp;
|
||||||
|
|
||||||
/* Setup the stack location */
|
/* Setup the stack location */
|
||||||
IoStackLocation = IoGetNextIrpStackLocation(Irp);
|
IoStackLocation = IoGetNextIrpStackLocation(Irp);
|
||||||
IoStackLocation->Parameters.Others.Argument1 = DeviceExtension;
|
IoStackLocation->Parameters.Others.Argument1 = DeviceExtension;
|
||||||
|
@ -176,7 +176,7 @@ CompBattAddNewBattery(IN PUNICODE_STRING BatteryName,
|
||||||
ExInitializeWorkItem(&BatteryData->WorkItem,
|
ExInitializeWorkItem(&BatteryData->WorkItem,
|
||||||
(PVOID)CompBattMonitorIrpCompleteWorker,
|
(PVOID)CompBattMonitorIrpCompleteWorker,
|
||||||
BatteryData);
|
BatteryData);
|
||||||
|
|
||||||
/* Setup the IRP work entry */
|
/* Setup the IRP work entry */
|
||||||
CompBattMonitorIrpComplete(BatteryData->DeviceObject, Irp, 0);
|
CompBattMonitorIrpComplete(BatteryData->DeviceObject, Irp, 0);
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
|
@ -193,10 +193,10 @@ CompBattAddNewBattery(IN PUNICODE_STRING BatteryName,
|
||||||
else if (CompBattDebug & 8)
|
else if (CompBattDebug & 8)
|
||||||
{
|
{
|
||||||
/* Fail */
|
/* Fail */
|
||||||
DbgPrint("CompBattAddNewBattery: Failed to get device Object. status = %lx\n",
|
DbgPrint("CompBattAddNewBattery: Failed to get device Object. status = %lx\n",
|
||||||
Status);
|
Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the battery data */
|
/* Free the battery data */
|
||||||
ExFreePool(BatteryData);
|
ExFreePool(BatteryData);
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ CompBattRemoveBattery(IN PCUNICODE_STRING BatteryName,
|
||||||
/* Dereference and free it */
|
/* Dereference and free it */
|
||||||
ObDereferenceObject(BatteryData->DeviceObject);
|
ObDereferenceObject(BatteryData->DeviceObject);
|
||||||
ExFreePool(BatteryData);
|
ExFreePool(BatteryData);
|
||||||
|
|
||||||
/* Notify class driver */
|
/* Notify class driver */
|
||||||
DeviceExtension->Flags = 0;
|
DeviceExtension->Flags = 0;
|
||||||
BatteryClassStatusNotify(DeviceExtension->ClassData);
|
BatteryClassStatusNotify(DeviceExtension->ClassData);
|
||||||
|
@ -248,7 +248,7 @@ CompBattGetBatteries(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
||||||
PWCHAR LinkList;
|
PWCHAR LinkList;
|
||||||
UNICODE_STRING LinkString;
|
UNICODE_STRING LinkString;
|
||||||
if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING GetBatteries\n");
|
if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING GetBatteries\n");
|
||||||
|
|
||||||
/* Get all battery links */
|
/* Get all battery links */
|
||||||
Status = IoGetDeviceInterfaces(&GUID_DEVICE_BATTERY, NULL, 0, &LinkList);
|
Status = IoGetDeviceInterfaces(&GUID_DEVICE_BATTERY, NULL, 0, &LinkList);
|
||||||
p = LinkList;
|
p = LinkList;
|
||||||
|
@ -260,12 +260,12 @@ CompBattGetBatteries(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
||||||
/* Create the string */
|
/* Create the string */
|
||||||
RtlInitUnicodeString(&LinkString, p);
|
RtlInitUnicodeString(&LinkString, p);
|
||||||
if (!LinkString.Length) break;
|
if (!LinkString.Length) break;
|
||||||
|
|
||||||
/* Add this battery and move on */
|
/* Add this battery and move on */
|
||||||
Status = CompBattAddNewBattery(&LinkString, DeviceExtension);
|
Status = CompBattAddNewBattery(&LinkString, DeviceExtension);
|
||||||
p += (LinkString.Length / sizeof(WCHAR)) + sizeof(UNICODE_NULL);
|
p += (LinkString.Length / sizeof(WCHAR)) + sizeof(UNICODE_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parsing complete, clean up buffer */
|
/* Parsing complete, clean up buffer */
|
||||||
ExFreePool(LinkList);
|
ExFreePool(LinkList);
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ CompBattGetBatteries(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
||||||
/* Fail */
|
/* Fail */
|
||||||
DbgPrint("CompBatt: Couldn't get list of batteries\n");
|
DbgPrint("CompBatt: Couldn't get list of batteries\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Done */
|
/* Done */
|
||||||
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING GetBatteries\n");
|
if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING GetBatteries\n");
|
||||||
return Status;
|
return Status;
|
||||||
|
@ -325,12 +325,12 @@ CompBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
UNICODE_STRING SymbolicLinkName;
|
UNICODE_STRING SymbolicLinkName;
|
||||||
BATTERY_MINIPORT_INFO MiniportInfo;
|
BATTERY_MINIPORT_INFO MiniportInfo;
|
||||||
if (CompBattDebug & 2) DbgPrint("CompBatt: Got an AddDevice - %x\n", PdoDeviceObject);
|
if (CompBattDebug & 2) DbgPrint("CompBatt: Got an AddDevice - %x\n", PdoDeviceObject);
|
||||||
|
|
||||||
/* Create the device */
|
/* Create the device */
|
||||||
RtlInitUnicodeString(&DeviceName, L"\\Device\\CompositeBattery");
|
RtlInitUnicodeString(&DeviceName, L"\\Device\\CompositeBattery");
|
||||||
Status = IoCreateDevice(DriverObject,
|
Status = IoCreateDevice(DriverObject,
|
||||||
sizeof(COMPBATT_DEVICE_EXTENSION),
|
sizeof(COMPBATT_DEVICE_EXTENSION),
|
||||||
&DeviceName,
|
&DeviceName,
|
||||||
FILE_DEVICE_BATTERY,
|
FILE_DEVICE_BATTERY,
|
||||||
FILE_DEVICE_SECURE_OPEN,
|
FILE_DEVICE_SECURE_OPEN,
|
||||||
FALSE,
|
FALSE,
|
||||||
|
@ -340,11 +340,11 @@ CompBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
/* Setup symbolic link for Win32 access */
|
/* Setup symbolic link for Win32 access */
|
||||||
RtlInitUnicodeString(&SymbolicLinkName, L"\\DosDevices\\CompositeBattery");
|
RtlInitUnicodeString(&SymbolicLinkName, L"\\DosDevices\\CompositeBattery");
|
||||||
IoCreateSymbolicLink(&SymbolicLinkName, &DeviceName);
|
IoCreateSymbolicLink(&SymbolicLinkName, &DeviceName);
|
||||||
|
|
||||||
/* Initialize the device extension */
|
/* Initialize the device extension */
|
||||||
DeviceExtension = DeviceObject->DeviceExtension;
|
DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
RtlZeroMemory(DeviceExtension, 0x1B0u);
|
RtlZeroMemory(DeviceExtension, sizeof(COMPBATT_DEVICE_EXTENSION));
|
||||||
|
|
||||||
/* Attach to device stack and set DO pointers */
|
/* Attach to device stack and set DO pointers */
|
||||||
DeviceExtension->AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
DeviceExtension->AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
||||||
PdoDeviceObject);
|
PdoDeviceObject);
|
||||||
|
@ -355,7 +355,7 @@ CompBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
if (CompBattDebug & 8)
|
if (CompBattDebug & 8)
|
||||||
DbgPrint("CompBattAddDevice: Could not attach to LowerDevice.\n");
|
DbgPrint("CompBattAddDevice: Could not attach to LowerDevice.\n");
|
||||||
IoDeleteDevice(DeviceObject);
|
IoDeleteDevice(DeviceObject);
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set device object flags */
|
/* Set device object flags */
|
||||||
|
@ -367,7 +367,7 @@ CompBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
InitializeListHead(&DeviceExtension->BatteryList);
|
InitializeListHead(&DeviceExtension->BatteryList);
|
||||||
DeviceExtension->Flags = 0;
|
DeviceExtension->Flags = 0;
|
||||||
DeviceExtension->NextTag = 1;
|
DeviceExtension->NextTag = 1;
|
||||||
|
|
||||||
/* Setup the miniport data */
|
/* Setup the miniport data */
|
||||||
RtlZeroMemory(&MiniportInfo, sizeof(MiniportInfo));
|
RtlZeroMemory(&MiniportInfo, sizeof(MiniportInfo));
|
||||||
MiniportInfo.MajorVersion = BATTERY_CLASS_MAJOR_VERSION;
|
MiniportInfo.MajorVersion = BATTERY_CLASS_MAJOR_VERSION;
|
||||||
|
@ -381,7 +381,7 @@ CompBattAddDevice(IN PDRIVER_OBJECT DriverObject,
|
||||||
MiniportInfo.SetStatusNotify = (BCLASS_SET_STATUS_NOTIFY)CompBattSetStatusNotify;
|
MiniportInfo.SetStatusNotify = (BCLASS_SET_STATUS_NOTIFY)CompBattSetStatusNotify;
|
||||||
MiniportInfo.DisableStatusNotify = (BCLASS_DISABLE_STATUS_NOTIFY)CompBattDisableStatusNotify;
|
MiniportInfo.DisableStatusNotify = (BCLASS_DISABLE_STATUS_NOTIFY)CompBattDisableStatusNotify;
|
||||||
MiniportInfo.Pdo = NULL;
|
MiniportInfo.Pdo = NULL;
|
||||||
|
|
||||||
/* Register with the class driver */
|
/* Register with the class driver */
|
||||||
Status = BatteryClassInitializeDevice(&MiniportInfo,
|
Status = BatteryClassInitializeDevice(&MiniportInfo,
|
||||||
&DeviceExtension->ClassData);
|
&DeviceExtension->ClassData);
|
||||||
|
@ -413,7 +413,7 @@ CompBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
switch (IoStackLocation->MinorFunction)
|
switch (IoStackLocation->MinorFunction)
|
||||||
{
|
{
|
||||||
case IRP_MN_START_DEVICE:
|
case IRP_MN_START_DEVICE:
|
||||||
|
|
||||||
/* Device is starting, register for new batteries and pick up current ones */
|
/* Device is starting, register for new batteries and pick up current ones */
|
||||||
Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
|
Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
|
||||||
0,
|
0,
|
||||||
|
@ -438,32 +438,32 @@ CompBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IRP_MN_CANCEL_STOP_DEVICE:
|
case IRP_MN_CANCEL_STOP_DEVICE:
|
||||||
|
|
||||||
/* Explicitly say ok */
|
/* Explicitly say ok */
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
||||||
|
|
||||||
/* Explicitly say ok */
|
/* Explicitly say ok */
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_SURPRISE_REMOVAL:
|
case IRP_MN_SURPRISE_REMOVAL:
|
||||||
|
|
||||||
/* Explicitly say ok */
|
/* Explicitly say ok */
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
||||||
|
|
||||||
/* Add this in */
|
/* Add this in */
|
||||||
Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
|
Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
/* Not supported */
|
/* Not supported */
|
||||||
Status = STATUS_INVALID_DEVICE_REQUEST;
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
break;
|
break;
|
||||||
|
@ -472,7 +472,7 @@ CompBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject,
|
||||||
/* Set IRP status if we have one */
|
/* Set IRP status if we have one */
|
||||||
if (Status != STATUS_NOT_SUPPORTED) Irp->IoStatus.Status = Status;
|
if (Status != STATUS_NOT_SUPPORTED) Irp->IoStatus.Status = Status;
|
||||||
|
|
||||||
/* Did someone pick it up? */
|
/* Did someone pick it up? */
|
||||||
if ((NT_SUCCESS(Status)) || (Status == STATUS_NOT_SUPPORTED))
|
if ((NT_SUCCESS(Status)) || (Status == STATUS_NOT_SUPPORTED))
|
||||||
{
|
{
|
||||||
/* Still unsupported, try ACPI */
|
/* Still unsupported, try ACPI */
|
||||||
|
|
|
@ -353,6 +353,63 @@ PciIdeXPdoQueryDeviceRelations(
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GUID_PCIIDE_INTERRUPT_INTERFACE
|
||||||
|
//GUID_PCIIDE_REQUEST_PROPER_RESOURCES
|
||||||
|
|
||||||
|
DEFINE_GUID(GUID_PCIIDE_SYNC_ACCESS_INTERFACE, 0x681190EB, 0xE4EA, 0x11D0, 0xAB, 0x82, 0x00, 0xA0, 0xC9, 0x06, 0x96, 0x2F);
|
||||||
|
DEFINE_GUID(GUID_PCIIDE_XFER_MODE_INTERFACE, 0x681190EC, 0xE4EA, 0x11D0, 0xAB, 0x82, 0x00, 0xA0, 0xC9, 0x06, 0x96, 0x2F);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
PciIdeXPdoPnpQueryInterface(
|
||||||
|
PIRP Irp)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
|
||||||
|
PACPI_INTERFACE_STANDARD AcpiInterface;
|
||||||
|
|
||||||
|
if (IrpStack->Parameters.QueryInterface.Version != 1)
|
||||||
|
{
|
||||||
|
DPRINT1("Invalid version number: %d\n",
|
||||||
|
IrpStack->Parameters.QueryInterface.Version);
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsEqualGUID(IrpStack->Parameters.QueryInterface.InterfaceType,
|
||||||
|
&GUID_PCIIDE_XFER_MODE_INTERFACE))
|
||||||
|
{
|
||||||
|
DPRINT1("GUID_PCIIDE_XFER_MODE_INTERFACE\n");
|
||||||
|
|
||||||
|
if (IrpStack->Parameters.QueryInterface.Size < sizeof(ACPI_INTERFACE_STANDARD))
|
||||||
|
{
|
||||||
|
DPRINT1("Buffer too small! (%d)\n", IrpStack->Parameters.QueryInterface.Size);
|
||||||
|
return STATUS_BUFFER_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
AcpiInterface = (PACPI_INTERFACE_STANDARD)IrpStack->Parameters.QueryInterface.Interface;
|
||||||
|
|
||||||
|
AcpiInterface->InterfaceReference = AcpiInterfaceReference;
|
||||||
|
AcpiInterface->InterfaceDereference = AcpiInterfaceDereference;
|
||||||
|
AcpiInterface->GpeConnectVector = AcpiInterfaceConnectVector;
|
||||||
|
AcpiInterface->GpeDisconnectVector = AcpiInterfaceDisconnectVector;
|
||||||
|
AcpiInterface->GpeEnableEvent = AcpiInterfaceEnableEvent;
|
||||||
|
AcpiInterface->GpeDisableEvent = AcpiInterfaceDisableEvent;
|
||||||
|
AcpiInterface->GpeClearStatus = AcpiInterfaceClearStatus;
|
||||||
|
AcpiInterface->RegisterForDeviceNotifications = AcpiInterfaceNotificationsRegister;
|
||||||
|
AcpiInterface->UnregisterForDeviceNotifications = AcpiInterfaceNotificationsUnregister;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DPRINT1("Invalid GUID\n");
|
||||||
|
return STATUS_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS NTAPI
|
NTSTATUS NTAPI
|
||||||
PciIdeXPdoPnpDispatch(
|
PciIdeXPdoPnpDispatch(
|
||||||
IN PDEVICE_OBJECT DeviceObject,
|
IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
@ -519,6 +576,11 @@ PciIdeXPdoPnpDispatch(
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case IRP_MN_QUERY_INTERFACE:
|
||||||
|
{
|
||||||
|
Status = PciIdeXPdoPnpQueryInterface(Irp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
/* We can't forward request to the lower driver, because
|
/* We can't forward request to the lower driver, because
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue