mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 14:13:01 +00:00
[CMBATT]: CmBattIoctl: Add handling for the direct-access undocumented IOCTLs. Some PnP glue remains, as well as the ACPI routines, and the driver is done.
svn path=/trunk/; revision=46338
This commit is contained in:
parent
9cb5d1c622
commit
db734f6736
2 changed files with 169 additions and 5 deletions
|
@ -353,6 +353,8 @@ CmBattIoctl(IN PDEVICE_OBJECT DeviceObject,
|
||||||
{
|
{
|
||||||
PCMBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
PCMBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
PIO_STACK_LOCATION IoStackLocation;
|
||||||
|
ULONG IoControlCode, OutputBufferLength, InputBufferLength;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
if (CmBattDebug & 2) DbgPrint("CmBattIoctl\n");
|
if (CmBattDebug & 2) DbgPrint("CmBattIoctl\n");
|
||||||
|
|
||||||
|
@ -380,11 +382,148 @@ CmBattIoctl(IN PDEVICE_OBJECT DeviceObject,
|
||||||
Status = BatteryClassIoctl(DeviceExtension->ClassData, Irp);
|
Status = BatteryClassIoctl(DeviceExtension->ClassData, Irp);
|
||||||
if (Status == STATUS_NOT_SUPPORTED)
|
if (Status == STATUS_NOT_SUPPORTED)
|
||||||
{
|
{
|
||||||
/* FIXME: Should handle custom codes here */
|
/* Read IOCTL information from IRP stack */
|
||||||
Irp->IoStatus.Status = Status;
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
||||||
Irp->IoStatus.Information = 0;
|
IoControlCode = IoStackLocation->Parameters.DeviceIoControl.IoControlCode;
|
||||||
|
OutputBufferLength = IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength;
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
InputBufferLength = IoStackLocation->Parameters.DeviceIoControl.InputBufferLength;
|
||||||
|
if (CmBattDebug & 4)
|
||||||
|
DbgPrint("CmBattIoctl: Received Direct Access IOCTL %x\n", IoControlCode);
|
||||||
|
|
||||||
|
/* Handle internal IOCTLs */
|
||||||
|
switch (IoControlCode)
|
||||||
|
{
|
||||||
|
case IOCTL_BATTERY_QUERY_UNIQUE_ID:
|
||||||
|
|
||||||
|
/* Data is 4 bytes long */
|
||||||
|
if (OutputBufferLength == sizeof(ULONG))
|
||||||
|
{
|
||||||
|
/* Query it */
|
||||||
|
Status = CmBattGetUniqueId(DeviceExtension->PdoDeviceObject,
|
||||||
|
Irp->AssociatedIrp.SystemBuffer);
|
||||||
|
if (NT_SUCCESS(Status)) Irp->IoStatus.Information = sizeof(ULONG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Buffer size invalid */
|
||||||
|
Status = STATUS_INVALID_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IOCTL_BATTERY_QUERY_STA:
|
||||||
|
|
||||||
|
/* Data is 4 bytes long */
|
||||||
|
if (OutputBufferLength == sizeof(ULONG))
|
||||||
|
{
|
||||||
|
/* Query it */
|
||||||
|
Status = CmBattGetStaData(DeviceExtension->PdoDeviceObject,
|
||||||
|
Irp->AssociatedIrp.SystemBuffer);
|
||||||
|
if (NT_SUCCESS(Status)) Irp->IoStatus.Information = sizeof(ULONG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Buffer size invalid */
|
||||||
|
Status = STATUS_INVALID_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IOCTL_BATTERY_QUERY_PSR:
|
||||||
|
|
||||||
|
/* Data is 4 bytes long */
|
||||||
|
if (OutputBufferLength == sizeof(ULONG))
|
||||||
|
{
|
||||||
|
/* Do we have an AC adapter? */
|
||||||
|
if (AcAdapterPdo)
|
||||||
|
{
|
||||||
|
/* Query it */
|
||||||
|
Status = CmBattGetPsrData(AcAdapterPdo,
|
||||||
|
Irp->AssociatedIrp.SystemBuffer);
|
||||||
|
if (NT_SUCCESS(Status)) Irp->IoStatus.Information = sizeof(ULONG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* No adapter, just a battery, so fail */
|
||||||
|
Status = STATUS_NO_SUCH_DEVICE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Buffer size invalid */
|
||||||
|
Status = STATUS_INVALID_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IOCTL_BATTERY_SET_TRIP_POINT:
|
||||||
|
|
||||||
|
/* Data is 4 bytes long */
|
||||||
|
if (InputBufferLength == sizeof(ULONG))
|
||||||
|
{
|
||||||
|
/* Query it */
|
||||||
|
Status = CmBattSetTripPpoint(DeviceExtension,
|
||||||
|
*(PULONG)Irp->AssociatedIrp.SystemBuffer);
|
||||||
|
Irp->IoStatus.Information = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Buffer size invalid */
|
||||||
|
Status = STATUS_INVALID_BUFFER_SIZE; }
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IOCTL_BATTERY_QUERY_BIF:
|
||||||
|
|
||||||
|
/* Data is 1060 bytes long */
|
||||||
|
if (OutputBufferLength == sizeof(ACPI_BIF_DATA))
|
||||||
|
{
|
||||||
|
/* Query it */
|
||||||
|
Status = CmBattGetBifData(DeviceExtension,
|
||||||
|
Irp->AssociatedIrp.SystemBuffer);
|
||||||
|
if (NT_SUCCESS(Status)) Irp->IoStatus.Information = sizeof(ACPI_BIF_DATA);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Buffer size invalid */
|
||||||
|
Status = STATUS_INVALID_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IOCTL_BATTERY_QUERY_BST:
|
||||||
|
|
||||||
|
/* Data is 16 bytes long */
|
||||||
|
if (OutputBufferLength == sizeof(ACPI_BST_DATA))
|
||||||
|
{
|
||||||
|
/* Query it */
|
||||||
|
Status = CmBattGetBstData(DeviceExtension,
|
||||||
|
Irp->AssociatedIrp.SystemBuffer);
|
||||||
|
if (NT_SUCCESS(Status)) Irp->IoStatus.Information = sizeof(ACPI_BST_DATA);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Buffer size invalid */
|
||||||
|
Status = STATUS_INVALID_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
/* Unknown, let us pass it on to ACPI */
|
||||||
|
if (CmBattDebug & 0xC)
|
||||||
|
DbgPrint("CmBattIoctl: Unknown IOCTL %x\n", IoControlCode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Did someone pick it up? */
|
||||||
|
if (Status != STATUS_NOT_SUPPORTED)
|
||||||
|
{
|
||||||
|
/* Complete the request */
|
||||||
|
Irp->IoStatus.Status = Status;
|
||||||
|
IofCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Still unsupported, try ACPI */
|
||||||
|
IoSkipCurrentIrpStackLocation(Irp);
|
||||||
|
Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release the remove lock and return status */
|
/* Release the remove lock and return status */
|
||||||
|
|
|
@ -14,6 +14,24 @@
|
||||||
#include <wdmguid.h>
|
#include <wdmguid.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#define IOCTL_BATTERY_QUERY_UNIQUE_ID \
|
||||||
|
CTL_CODE(FILE_DEVICE_BATTERY, 0x101, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294404
|
||||||
|
|
||||||
|
#define IOCTL_BATTERY_QUERY_STA \
|
||||||
|
CTL_CODE(FILE_DEVICE_BATTERY, 0x102, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294408
|
||||||
|
|
||||||
|
#define IOCTL_BATTERY_QUERY_PSR \
|
||||||
|
CTL_CODE(FILE_DEVICE_BATTERY, 0x103, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x29440C
|
||||||
|
|
||||||
|
#define IOCTL_BATTERY_SET_TRIP_POINT \
|
||||||
|
CTL_CODE(FILE_DEVICE_BATTERY, 0x104, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294410
|
||||||
|
|
||||||
|
#define IOCTL_BATTERY_QUERY_BIF \
|
||||||
|
CTL_CODE(FILE_DEVICE_BATTERY, 0x105, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294414
|
||||||
|
|
||||||
|
#define IOCTL_BATTERY_QUERY_BST \
|
||||||
|
CTL_CODE(FILE_DEVICE_BATTERY, 0x106, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294418
|
||||||
|
|
||||||
#define CMBATT_GENERIC_STATUS 0x01
|
#define CMBATT_GENERIC_STATUS 0x01
|
||||||
#define CMBATT_GENERIC_INFO 0x02
|
#define CMBATT_GENERIC_INFO 0x02
|
||||||
#define CMBATT_GENERIC_WARNING 0x04
|
#define CMBATT_GENERIC_WARNING 0x04
|
||||||
|
@ -177,6 +195,13 @@ CmBattGetStaData(
|
||||||
PULONG StaData
|
PULONG StaData
|
||||||
);
|
);
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
NTAPI
|
||||||
|
CmBattGetBifData(
|
||||||
|
PCMBATT_DEVICE_EXTENSION DeviceExtension,
|
||||||
|
PACPI_BIF_DATA BifData
|
||||||
|
);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CmBattSetTripPpoint(
|
CmBattSetTripPpoint(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue