ReactOS  0.4.15-dev-499-g1f31905
compbatt.h File Reference
#include <wdm.h>
#include <batclass.h>
Include dependency graph for compbatt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _COMPBATT_BATTERY_DATA
 
struct  _COMPBATT_DEVICE_EXTENSION
 

Macros

#define COMPBATT_BATTERY_INFORMATION_PRESENT   0x04
 
#define COMPBATT_TAG_ASSIGNED   0x80
 

Typedefs

typedef struct _COMPBATT_BATTERY_DATA COMPBATT_BATTERY_DATA
 
typedef struct _COMPBATT_BATTERY_DATAPCOMPBATT_BATTERY_DATA
 
typedef struct _COMPBATT_DEVICE_EXTENSION COMPBATT_DEVICE_EXTENSION
 
typedef struct _COMPBATT_DEVICE_EXTENSIONPCOMPBATT_DEVICE_EXTENSION
 

Functions

NTSTATUS NTAPI CompBattAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PdoDeviceObject)
 
NTSTATUS NTAPI CompBattPowerDispatch (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI CompBattPnpDispatch (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI CompBattQueryInformation (IN PCOMPBATT_DEVICE_EXTENSION FdoExtension, IN ULONG Tag, IN BATTERY_QUERY_INFORMATION_LEVEL InfoLevel, IN OPTIONAL LONG AtRate, IN PVOID Buffer, IN ULONG BufferLength, OUT PULONG ReturnedLength)
 
NTSTATUS NTAPI CompBattQueryStatus (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag, IN PBATTERY_STATUS BatteryStatus)
 
NTSTATUS NTAPI CompBattSetStatusNotify (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG BatteryTag, IN PBATTERY_NOTIFY BatteryNotify)
 
NTSTATUS NTAPI CompBattDisableStatusNotify (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattQueryTag (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, OUT PULONG Tag)
 
NTSTATUS NTAPI CompBattMonitorIrpComplete (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PKEVENT Event)
 
NTSTATUS NTAPI CompBattMonitorIrpCompleteWorker (IN PCOMPBATT_BATTERY_DATA BatteryData)
 
NTSTATUS NTAPI CompBattGetDeviceObjectPointer (IN PUNICODE_STRING DeviceName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
 
NTSTATUS NTAPI BatteryIoctl (IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl)
 

Variables

ULONG CompBattDebug
 

Macro Definition Documentation

◆ COMPBATT_BATTERY_INFORMATION_PRESENT

#define COMPBATT_BATTERY_INFORMATION_PRESENT   0x04

Definition at line 15 of file compbatt.h.

◆ COMPBATT_TAG_ASSIGNED

#define COMPBATT_TAG_ASSIGNED   0x80

Definition at line 16 of file compbatt.h.

Typedef Documentation

◆ COMPBATT_BATTERY_DATA

◆ COMPBATT_DEVICE_EXTENSION

◆ PCOMPBATT_BATTERY_DATA

◆ PCOMPBATT_DEVICE_EXTENSION

Function Documentation

◆ BatteryIoctl()

NTSTATUS NTAPI BatteryIoctl ( IN ULONG  IoControlCode,
IN PDEVICE_OBJECT  DeviceObject,
IN PVOID  InputBuffer,
IN ULONG  InputBufferLength,
IN PVOID  OutputBuffer,
IN ULONG  OutputBufferLength,
IN BOOLEAN  InternalDeviceIoControl 
)

Definition at line 17 of file compmisc.c.

24 {
26  KEVENT Event;
28  PIRP Irp;
29  PAGED_CODE();
30  if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING BatteryIoctl\n");
31 
32  /* Initialize the event and IRP */
41  &Event,
42  &IoStatusBlock);
43  if (Irp)
44  {
45  /* Call the class driver miniport */
47  if (Status == STATUS_PENDING)
48  {
49  /* Wait for result */
52  }
53 
54  /* Print failure */
55  if (!(NT_SUCCESS(Status)) && (CompBattDebug & 8))
56  DbgPrint("BatteryIoctl: Irp failed - %x\n", Status);
57 
58  /* Done */
59  if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING BatteryIoctl\n");
60  }
61  else
62  {
63  /* Out of memory */
64  if (CompBattDebug & 8) DbgPrint("BatteryIoctl: couldn't create Irp\n");
66  }
67 
68  /* Return status */
69  return Status;
70 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID _In_ ULONG _In_ BOOLEAN InternalDeviceIoControl
Definition: iofuncs.h:713
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
CHAR InputBuffer[80]
Definition: conmgr.c:33
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:437
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
ULONG CompBattDebug
Definition: compbatt.c:17
#define PAGED_CODE()

Referenced by CompBattGetBatteryGranularity(), and CompBattGetBatteryInformation().

◆ CompBattAddDevice()

NTSTATUS NTAPI CompBattAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PdoDeviceObject 
)

Definition at line 320 of file comppnp.c.

322 {
325  PCOMPBATT_DEVICE_EXTENSION DeviceExtension;
327  UNICODE_STRING SymbolicLinkName;
328  BATTERY_MINIPORT_INFO MiniportInfo;
329  if (CompBattDebug & 2) DbgPrint("CompBatt: Got an AddDevice - %x\n", PdoDeviceObject);
330 
331  /* Create the device */
332  RtlInitUnicodeString(&DeviceName, L"\\Device\\CompositeBattery");
335  &DeviceName,
338  FALSE,
339  &DeviceObject);
340  if (!NT_SUCCESS(Status)) return Status;
341 
342  /* Setup symbolic link for Win32 access */
343  RtlInitUnicodeString(&SymbolicLinkName, L"\\DosDevices\\CompositeBattery");
344  IoCreateSymbolicLink(&SymbolicLinkName, &DeviceName);
345 
346  /* Initialize the device extension */
347  DeviceExtension = DeviceObject->DeviceExtension;
348  RtlZeroMemory(DeviceExtension, sizeof(COMPBATT_DEVICE_EXTENSION));
349 
350  /* Attach to device stack and set DO pointers */
353  DeviceExtension->DeviceObject = DeviceObject;
354  if (!DeviceExtension->AttachedDevice)
355  {
356  /* Fail */
357  if (CompBattDebug & 8)
358  DbgPrint("CompBattAddDevice: Could not attach to LowerDevice.\n");
360  return STATUS_UNSUCCESSFUL;
361  }
362 
363  /* Set device object flags */
366 
367  /* Setup the device extension */
368  ExInitializeFastMutex(&DeviceExtension->Lock);
369  InitializeListHead(&DeviceExtension->BatteryList);
370  DeviceExtension->Flags = 0;
371  DeviceExtension->NextTag = 1;
372 
373  /* Setup the miniport data */
374  RtlZeroMemory(&MiniportInfo, sizeof(MiniportInfo));
377  MiniportInfo.Context = DeviceExtension;
378  MiniportInfo.DeviceName = &DeviceName;
381  MiniportInfo.SetInformation = NULL;
385  MiniportInfo.Pdo = NULL;
386 
387  /* Register with the class driver */
388  Status = BatteryClassInitializeDevice(&MiniportInfo,
389  &DeviceExtension->ClassData);
390  if (!NT_SUCCESS(Status))
391  {
392  /* Undo everything */
393  IoDetachDevice(DeviceExtension->AttachedDevice);
395  }
396 
397  /* Return status */
398  return Status;
399 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:54
BCLASSAPI NTSTATUS NTAPI BatteryClassInitializeDevice(PBATTERY_MINIPORT_INFO MiniportInfo, PVOID *ClassData)
Definition: battc.c:137
#define DbgPrint
Definition: loader.c:25
#define FILE_DEVICE_BATTERY
Definition: winioctl.h:146
PBCLASS_QUERY_STATUS_CALLBACK BCLASS_QUERY_STATUS
Definition: batclass.h:242
PBCLASS_SET_STATUS_NOTIFY_CALLBACK BCLASS_SET_STATUS_NOTIFY
Definition: batclass.h:243
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT _In_ PUSB_PORT_PATH _Out_ PUSB_CD_ERROR_INFORMATION _In_ USHORT _In_ PDEVICE_OBJECT PdoDeviceObject
Definition: hubbusif.h:89
WCHAR DeviceName[]
Definition: adapter.cpp:21
BCLASS_DISABLE_STATUS_NOTIFY DisableStatusNotify
Definition: batclass.h:256
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDEVICE_OBJECT DeviceObject
Definition: compbatt.h:55
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PBCLASS_DISABLE_STATUS_NOTIFY_CALLBACK BCLASS_DISABLE_STATUS_NOTIFY
Definition: batclass.h:245
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI CompBattSetStatusNotify(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG BatteryTag, IN PBATTERY_NOTIFY BatteryNotify)
Definition: compbatt.c:211
NTSTATUS NTAPI CompBattDisableStatusNotify(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:184
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
PDEVICE_OBJECT Pdo
Definition: batclass.h:257
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
PUNICODE_STRING DeviceName
Definition: batclass.h:258
NTSTATUS NTAPI CompBattQueryInformation(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag, IN BATTERY_QUERY_INFORMATION_LEVEL InfoLevel, IN OPTIONAL LONG AtRate, IN PVOID Buffer, IN ULONG BufferLength, OUT PULONG ReturnedLength)
Definition: compbatt.c:482
static const WCHAR L[]
Definition: oid.c:1250
BCLASS_QUERY_INFORMATION QueryInformation
Definition: batclass.h:252
#define BATTERY_CLASS_MINOR_VERSION
Definition: batclass.h:164
NTSTATUS NTAPI CompBattQueryTag(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, OUT PULONG Tag)
Definition: compbatt.c:149
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
BCLASS_SET_INFORMATION SetInformation
Definition: batclass.h:253
PBCLASS_QUERY_TAG_CALLBACK BCLASS_QUERY_TAG
Definition: batclass.h:240
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
ULONG CompBattDebug
Definition: compbatt.c:17
BCLASS_SET_STATUS_NOTIFY SetStatusNotify
Definition: batclass.h:255
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
BCLASS_QUERY_TAG QueryTag
Definition: batclass.h:251
BCLASS_QUERY_STATUS QueryStatus
Definition: batclass.h:254
PBCLASS_QUERY_INFORMATION_CALLBACK BCLASS_QUERY_INFORMATION
Definition: batclass.h:241
NTSTATUS NTAPI CompBattQueryStatus(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag, IN PBATTERY_STATUS BatteryStatus)
Definition: compbatt.c:221
#define BATTERY_CLASS_MAJOR_VERSION
Definition: batclass.h:163

Referenced by DriverEntry().

◆ CompBattDisableStatusNotify()

NTSTATUS NTAPI CompBattDisableStatusNotify ( IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 184 of file compbatt.c.

185 {
186  PCOMPBATT_BATTERY_DATA BatteryData;
187  PLIST_ENTRY ListHead, NextEntry;
188  if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING DisableStatusNotify\n");
189 
190  /* Loop the battery list */
191  ExAcquireFastMutex(&DeviceExtension->Lock);
192  ListHead = &DeviceExtension->BatteryList;
193  NextEntry = ListHead->Flink;
194  while (NextEntry != ListHead)
195  {
196  /* Get the battery information and clear capacity data */
197  BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
198  BatteryData->WaitStatus.LowCapacity = 0;
199  BatteryData->WaitStatus.HighCapacity = 0x7FFFFFFF;
200  NextEntry = NextEntry->Flink;
201  }
202 
203  /* Done */
204  ExReleaseFastMutex(&DeviceExtension->Lock);
205  if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING DisableStatusNotify\n");
206  return STATUS_SUCCESS;
207 }
#define DbgPrint
Definition: loader.c:25
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
BATTERY_WAIT_STATUS WaitStatus
Definition: compbatt.h:26
Definition: typedefs.h:118
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
ULONG CompBattDebug
Definition: compbatt.c:17
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CompBattAddDevice().

◆ CompBattGetDeviceObjectPointer()

NTSTATUS NTAPI CompBattGetDeviceObjectPointer ( IN PUNICODE_STRING  DeviceName,
IN ACCESS_MASK  DesiredAccess,
OUT PFILE_OBJECT FileObject,
OUT PDEVICE_OBJECT DeviceObject 
)

Definition at line 74 of file compmisc.c.

78 {
82  PFILE_OBJECT LocalFileObject;
84  PAGED_CODE();
85 
86  /* Open a file object handle to the device */
88  Status = ZwCreateFile(&DeviceHandle,
92  NULL,
93  0,
95  FILE_OPEN,
96  0,
97  NULL,
98  0);
99  if (NT_SUCCESS(Status))
100  {
101  /* Reference the file object */
103  0,
105  KernelMode,
106  (PVOID)&LocalFileObject,
107  NULL);
108  if (NT_SUCCESS(Status))
109  {
110  /* Return the FO and the associated DO */
111  *FileObject = LocalFileObject;
112  *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
113  }
114 
115  /* Close the handle */
117  }
118 
119  /* Return status */
120  return Status;
121 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define FILE_SHARE_READ
Definition: compat.h:125
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1957
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4137
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define PAGED_CODE()

Referenced by CompBattAddNewBattery().

◆ CompBattMonitorIrpComplete()

NTSTATUS NTAPI CompBattMonitorIrpComplete ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PKEVENT  Event 
)

Definition at line 70 of file compbatt.c.

73 {
76 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CompBattAddNewBattery().

◆ CompBattMonitorIrpCompleteWorker()

NTSTATUS NTAPI CompBattMonitorIrpCompleteWorker ( IN PCOMPBATT_BATTERY_DATA  BatteryData)

Definition at line 80 of file compbatt.c.

81 {
84 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CompBattAddNewBattery().

◆ CompBattPnpDispatch()

NTSTATUS NTAPI CompBattPnpDispatch ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 403 of file comppnp.c.

405 {
409  if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING PnpDispatch\n");
410 
411  /* Set default error */
413 
414  /* Check what kind of PnP function this is */
415  switch (IoStackLocation->MinorFunction)
416  {
417  case IRP_MN_START_DEVICE:
418 
419  /* Device is starting, register for new batteries and pick up current ones */
421  0,
422  (PVOID)&GUID_DEVICE_BATTERY,
423  DeviceObject->DriverObject,
425  DeviceExtension,
426  &DeviceExtension->NotificationEntry);
427  if (NT_SUCCESS(Status))
428  {
429  /* Now go get the batteries */
430  if (CompBattDebug & 2)
431  DbgPrint("CompBatt: Successfully registered for PnP notification\n");
432  Status = CompBattGetBatteries(DeviceExtension);
433  }
434  else
435  {
436  /* We failed */
437  if (CompBattDebug & 8)
438  DbgPrint("CompBatt: Couldn't register for PnP notification - %x\n",
439  Status);
440  }
441  break;
443 
444  /* Explicitly say ok */
446  break;
447 
449 
450  /* Explicitly say ok */
452  break;
453 
455 
456  /* Explicitly say ok */
458  break;
459 
461 
462  /* Add this in */
463  Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
465  break;
466 
467  default:
468 
469  /* Not supported */
471  break;
472  }
473 
474  /* Set IRP status if we have one */
475  if (Status != STATUS_NOT_SUPPORTED) Irp->IoStatus.Status = Status;
476 
477  /* Did someone pick it up? */
479  {
480  /* Still unsupported, try ACPI */
482  Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
483  }
484  else
485  {
486  /* Complete the request */
487  Status = Irp->IoStatus.Status;
489  }
490 
491  /* Release the remove lock and return status */
492  if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING PnpDispatch\n");
493  return Status;
494 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:54
DRIVER_NOTIFICATION_CALLBACK_ROUTINE * PDRIVER_NOTIFICATION_CALLBACK_ROUTINE
Definition: iotypes.h:1206
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS NTAPI CompBattPnpEventHandler(IN PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:287
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_START_DEVICE
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:971
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define IO_NO_INCREMENT
Definition: iotypes.h:568
ULONG CompBattDebug
Definition: compbatt.c:17
#define IRP_MN_CANCEL_STOP_DEVICE
NTSTATUS NTAPI CompBattGetBatteries(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:246
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MN_QUERY_PNP_DEVICE_STATE

Referenced by DriverEntry().

◆ CompBattPowerDispatch()

NTSTATUS NTAPI CompBattPowerDispatch ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 19 of file comppnp.c.

21 {
23  if (CompBattDebug & 1) DbgPrint("CompBatt: PowerDispatch received power IRP.\n");
24 
25  /* Start the next IRP */
27 
28  /* Call the next driver in the stack */
30  return PoCallDriver(DeviceExtension->AttachedDevice, Irp);
31 }
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:54
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
PVOID DeviceExtension
Definition: env_spec_w32.h:418
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
ULONG CompBattDebug
Definition: compbatt.c:17

Referenced by DriverEntry().

◆ CompBattQueryInformation()

NTSTATUS NTAPI CompBattQueryInformation ( IN PCOMPBATT_DEVICE_EXTENSION  FdoExtension,
IN ULONG  Tag,
IN BATTERY_QUERY_INFORMATION_LEVEL  InfoLevel,
IN OPTIONAL LONG  AtRate,
IN PVOID  Buffer,
IN ULONG  BufferLength,
OUT PULONG  ReturnedLength 
)

Definition at line 482 of file compbatt.c.

489 {
490  BATTERY_INFORMATION BatteryInfo;
491  BATTERY_REPORTING_SCALE BatteryGranularity[4];
492  PWCHAR BatteryName = L"Composite Battery";
493  //BATTERY_MANUFACTURE_DATE Date;
494  ULONG Dummy, Time;
495  PVOID QueryData = NULL;
496  ULONG QueryLength = 0;
498  PAGED_CODE();
499  if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING QueryInformation\n");
500 
501  /* Check for valid/correct tag */
502  if ((Tag != DeviceExtension->Tag) ||
503  (!(DeviceExtension->Flags & COMPBATT_TAG_ASSIGNED)))
504  {
505  /* Not right, so fail */
506  return STATUS_NO_SUCH_DEVICE;
507  }
508 
509  /* Check what caller wants */
510  switch (InfoLevel)
511  {
512  case BatteryInformation:
513 
514  /* Query combined battery information */
515  RtlZeroMemory(&BatteryInfo, sizeof(BatteryInfo));
516  Status = CompBattGetBatteryInformation(&BatteryInfo, DeviceExtension);
517  if (NT_SUCCESS(Status))
518  {
519  /* Return the data if successful */
520  QueryData = &BatteryInfo;
521  QueryLength = sizeof(BatteryInfo);
522  }
523  break;
524 
526 
527  /* Query combined granularity information */
528  RtlZeroMemory(&BatteryGranularity, sizeof(BatteryGranularity));
529  Status = CompBattGetBatteryGranularity(BatteryGranularity, DeviceExtension);
530  if (NT_SUCCESS(Status))
531  {
532  /* Return the data if successful */
533  QueryLength = sizeof(BatteryGranularity);
534  QueryData = &BatteryGranularity;
535  }
536  break;
537 
539 
540  /* Query combined time estimate information */
541  RtlZeroMemory(&Time, sizeof(Time));
542  Status = CompBattGetEstimatedTime(&Time, DeviceExtension);
543  if (NT_SUCCESS(Status))
544  {
545  /* Return the data if successful */
546  QueryLength = sizeof(Time);
547  QueryData = &Time;
548  }
549  break;
550 
552  case BatteryDeviceName:
553 
554  /* Return the static buffer */
555  QueryData = BatteryName;
556  QueryLength = sizeof(L"Composite Battery");
557  break;
558 
560 
561  /* Static data */
562  //Date.Day = 26;
563  //Date.Month = 06;
564  //Date.Year = 1997;
565  break;
566 
567  case BatteryTemperature:
568  case BatteryUniqueID:
569 
570  /* Return zero */
571  Dummy = 0;
572  QueryData = &Dummy;
573  QueryLength = sizeof(Dummy);
574  break;
575 
576  default:
577  /* Everything else is unknown */
579  break;
580  }
581 
582  /* Return the required length and check if the caller supplied enough */
583  *ReturnedLength = QueryLength;
584  if (BufferLength < QueryLength) Status = STATUS_BUFFER_TOO_SMALL;
585 
586  /* Copy the data if there's enough space and it exists */
587  if ((NT_SUCCESS(Status)) && (QueryData)) RtlCopyMemory(Buffer, QueryData, QueryLength);
588 
589  /* Return function result */
590  if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING QueryInformation\n");
591  return Status;
592 }
NTSTATUS NTAPI CompBattGetBatteryGranularity(OUT PBATTERY_REPORTING_SCALE ReportingScale, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:387
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define DbgPrint
Definition: loader.c:25
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI CompBattGetBatteryInformation(OUT PBATTERY_INFORMATION BatteryInfo, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:231
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:55
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSTATUS NTAPI CompBattGetEstimatedTime(OUT PULONG Time, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:473
_In_ ULONG BufferLength
Definition: usbdlib.h:225
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define COMPBATT_TAG_ASSIGNED
Definition: compbatt.h:16
static const WCHAR L[]
Definition: oid.c:1250
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187
Status
Definition: gdiplustypes.h:24
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
unsigned int ULONG
Definition: retypes.h:1
ULONG CompBattDebug
Definition: compbatt.c:17
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:3014
static PLARGE_INTEGER Time
Definition: time.c:105
#define PAGED_CODE()

Referenced by CompBattAddDevice().

◆ CompBattQueryStatus()

NTSTATUS NTAPI CompBattQueryStatus ( IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  Tag,
IN PBATTERY_STATUS  BatteryStatus 
)

Definition at line 221 of file compbatt.c.

224 {
226  return STATUS_NOT_IMPLEMENTED;
227 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CompBattAddDevice().

◆ CompBattQueryTag()

NTSTATUS NTAPI CompBattQueryTag ( IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension,
OUT PULONG  Tag 
)

Definition at line 149 of file compbatt.c.

151 {
153  PAGED_CODE();
154  if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING QueryTag\n");
155 
156  /* Was a tag assigned? */
157  if (!(DeviceExtension->Flags & COMPBATT_TAG_ASSIGNED))
158  {
159  /* Assign one */
160  CompBattRecalculateTag(DeviceExtension);
161  }
162 
163  /* Do we have a tag now? */
164  if ((DeviceExtension->Flags & COMPBATT_TAG_ASSIGNED) && (DeviceExtension->Tag))
165  {
166  /* Return the tag */
167  *Tag = DeviceExtension->Tag;
169  }
170  else
171  {
172  /* No tag */
173  *Tag = 0;
175  }
176 
177  /* Return status */
178  if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING QueryTag\n");
179  return Status;
180 }
#define DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CompBattRecalculateTag(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:88
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define COMPBATT_TAG_ASSIGNED
Definition: compbatt.h:16
Status
Definition: gdiplustypes.h:24
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
ULONG CompBattDebug
Definition: compbatt.c:17
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

Referenced by CompBattAddDevice().

◆ CompBattSetStatusNotify()

NTSTATUS NTAPI CompBattSetStatusNotify ( IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  BatteryTag,
IN PBATTERY_NOTIFY  BatteryNotify 
)

Definition at line 211 of file compbatt.c.

214 {
216  return STATUS_NOT_IMPLEMENTED;
217 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CompBattAddDevice().

Variable Documentation

◆ CompBattDebug