ReactOS  0.4.15-dev-1206-g731eddf
compbatt.c File Reference
#include "compbatt.h"
#include <debug.h>
Include dependency graph for compbatt.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI CompBattOpenClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI CompBattSystemControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI CompBattMonitorIrpComplete (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PKEVENT Event)
 
NTSTATUS NTAPI CompBattMonitorIrpCompleteWorker (IN PCOMPBATT_BATTERY_DATA BatteryData)
 
VOID NTAPI CompBattRecalculateTag (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattIoctl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI CompBattQueryTag (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, OUT PULONG Tag)
 
NTSTATUS NTAPI CompBattDisableStatusNotify (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattSetStatusNotify (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG BatteryTag, IN PBATTERY_NOTIFY BatteryNotify)
 
NTSTATUS NTAPI CompBattQueryStatus (IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag, IN PBATTERY_STATUS BatteryStatus)
 
NTSTATUS NTAPI CompBattGetBatteryInformation (OUT PBATTERY_INFORMATION BatteryInfo, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattGetBatteryGranularity (OUT PBATTERY_REPORTING_SCALE ReportingScale, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattGetEstimatedTime (OUT PULONG Time, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
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)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

ULONG CompBattDebug
 

Function Documentation

◆ 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:121
BATTERY_WAIT_STATUS WaitStatus
Definition: compbatt.h:26
Definition: typedefs.h:119
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().

◆ CompBattGetBatteryGranularity()

NTSTATUS NTAPI CompBattGetBatteryGranularity ( OUT PBATTERY_REPORTING_SCALE  ReportingScale,
IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 387 of file compbatt.c.

389 {
392  PCOMPBATT_BATTERY_DATA BatteryData;
393  BATTERY_REPORTING_SCALE BatteryScale[4];
394  PLIST_ENTRY ListHead, NextEntry;
395  ULONG i;
396  if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING GetBatteryGranularity\n");
397 
398  /* Set defaults */
399  ReportingScale[0].Granularity = -1;
400  ReportingScale[1].Granularity = -1;
401  ReportingScale[2].Granularity = -1;
402  ReportingScale[3].Granularity = -1;
403 
404  /* Loop the battery list */
405  ExAcquireFastMutex(&DeviceExtension->Lock);
406  ListHead = &DeviceExtension->BatteryList;
407  NextEntry = ListHead->Flink;
408  while (NextEntry != ListHead)
409  {
410  /* Try to acquire the remove lock */
411  BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
412  if (NT_SUCCESS(IoAcquireRemoveLock(&BatteryData->RemoveLock, 0)))
413  {
414  /* Now release the device lock since the battery can't go away */
415  ExReleaseFastMutex(&DeviceExtension->Lock);
416 
417  /* Build the query */
418  InputBuffer.BatteryTag = BatteryData->Tag;
419  InputBuffer.InformationLevel = BatteryGranularityInformation;
420 
421  /* Make sure the battery has a tag */
422  if (BatteryData->Tag)
423  {
424  /* Send the IOCTL to query the information */
425  RtlZeroMemory(&BatteryData->BatteryInformation,
426  sizeof(BatteryData->BatteryInformation));
428  BatteryData->DeviceObject,
429  &InputBuffer,
430  sizeof(InputBuffer),
431  &BatteryScale,
432  sizeof(BatteryScale),
433  0);
434  if (!NT_SUCCESS(Status))
435  {
436  /* Fail if the query had a problem */
437  ExAcquireFastMutex(&DeviceExtension->Lock);
438  IoReleaseRemoveLock(&BatteryData->RemoveLock, 0);
439  break;
440  }
441 
442  /* Loop all 4 scales */
443  for (i = 0; i < 4; i++)
444  {
445  /* Check for valid granularity */
446  if (BatteryScale[i].Granularity)
447  {
448  /* If it's smaller, use it instead */
449  ReportingScale[i].Granularity = min(BatteryScale[i].Granularity,
450  ReportingScale[i].Granularity);
451  }
452 
453  }
454  }
455 
456  /* Re-acquire the device extension lock and release the remove lock */
457  ExAcquireFastMutex(&DeviceExtension->Lock);
458  IoReleaseRemoveLock(&BatteryData->RemoveLock, 0);
459  }
460 
461  /* Next entry */
462  NextEntry = NextEntry->Flink;
463  }
464 
465  /* All done */
466  ExReleaseFastMutex(&DeviceExtension->Lock);
467  if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING GetBatteryGranularity\n");
468  return STATUS_SUCCESS;
469 }
#define DbgPrint
Definition: loader.c:25
#define IOCTL_BATTERY_QUERY_INFORMATION
Definition: batclass.h:86
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: compmisc.c:17
LONG NTSTATUS
Definition: precomp.h:26
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2760
PDEVICE_OBJECT DeviceObject
Definition: compbatt.h:22
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
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:121
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CHAR InputBuffer[80]
Definition: conmgr.c:33
Status
Definition: gdiplustypes.h:24
Definition: typedefs.h:119
BATTERY_INFORMATION BatteryInformation
Definition: compbatt.h:34
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define min(a, b)
Definition: monoChain.cc:55
IO_REMOVE_LOCK RemoveLock
Definition: compbatt.h:21
unsigned int ULONG
Definition: retypes.h:1
ULONG CompBattDebug
Definition: compbatt.c:17
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IoAcquireRemoveLock(RemoveLock, Tag)

Referenced by CompBattQueryInformation().

◆ CompBattGetBatteryInformation()

NTSTATUS NTAPI CompBattGetBatteryInformation ( OUT PBATTERY_INFORMATION  BatteryInfo,
IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 231 of file compbatt.c.

233 {
236  PCOMPBATT_BATTERY_DATA BatteryData;
237  PLIST_ENTRY ListHead, NextEntry;
238  if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING GetBatteryInformation\n");
239 
240  /* Set defaults */
241  BatteryInfo->DefaultAlert1 = 0;
242  BatteryInfo->DefaultAlert2 = 0;
243  BatteryInfo->CriticalBias = 0;
244 
245  /* Loop the battery list */
246  ExAcquireFastMutex(&DeviceExtension->Lock);
247  ListHead = &DeviceExtension->BatteryList;
248  NextEntry = ListHead->Flink;
249  while (NextEntry != ListHead)
250  {
251  /* Try to acquire the remove lock */
252  BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
253  if (NT_SUCCESS(IoAcquireRemoveLock(&BatteryData->RemoveLock, 0)))
254  {
255  /* Now release the device lock since the battery can't go away */
256  ExReleaseFastMutex(&DeviceExtension->Lock);
257 
258  /* Build the query */
259  InputBuffer.BatteryTag = BatteryData->Tag;
260  InputBuffer.InformationLevel = BatteryInformation;
261  InputBuffer.AtRate = 0;
262 
263  /* Make sure the battery has a tag */
264  if (BatteryData->Tag)
265  {
266  /* Do we already have the data? */
267  if (!(BatteryData->Flags & COMPBATT_BATTERY_INFORMATION_PRESENT))
268  {
269  /* Send the IOCTL to query the information */
270  RtlZeroMemory(&BatteryData->BatteryInformation,
271  sizeof(BatteryData->BatteryInformation));
273  BatteryData->DeviceObject,
274  &InputBuffer,
275  sizeof(InputBuffer),
276  &BatteryData->BatteryInformation,
277  sizeof(BatteryData->BatteryInformation),
278  0);
279  if (!NT_SUCCESS(Status))
280  {
281  /* Fail if the query had a problem */
283  ExAcquireFastMutex(&DeviceExtension->Lock);
284  IoReleaseRemoveLock(&BatteryData->RemoveLock, 0);
285  break;
286  }
287 
288  /* Next time we can use the static copy */
290  if (CompBattDebug & 2)
291  DbgPrint("CompBattGetBatteryInformation: Read individual BATTERY_INFORMATION\n"
292  "-------- Capabilities = %x\n-------- Technology = %x\n"
293  "-------- Chemistry[4] = %x\n-------- DesignedCapacity = %x\n"
294  "-------- FullChargedCapacity = %x\n-------- DefaultAlert1 = %x\n"
295  "-------- DefaultAlert2 = %x\n-------- CriticalBias = %x\n"
296  "-------- CycleCount = %x\n",
297  BatteryData->BatteryInformation.Capabilities,
298  BatteryData->BatteryInformation.Technology,
299  BatteryData->BatteryInformation.Chemistry,
302  BatteryData->BatteryInformation.DefaultAlert1,
303  BatteryData->BatteryInformation.DefaultAlert2,
304  BatteryData->BatteryInformation.CriticalBias,
305  BatteryData->BatteryInformation.CycleCount);
306  }
307 
308  /* Combine capabilities */
309  BatteryInfo->Capabilities |= BatteryData->BatteryInformation.Capabilities;
310 
311  /* Add-on capacity */
313  {
314  BatteryInfo->DesignedCapacity += BatteryData->BatteryInformation.DesignedCapacity;
315  }
316 
317  /* Add on fully charged capacity */
319  {
320  BatteryInfo->FullChargedCapacity += BatteryData->BatteryInformation.FullChargedCapacity;
321  }
322 
323  /* Choose the highest alert */
324  BatteryInfo->DefaultAlert1 = max(BatteryInfo->DefaultAlert1,
325  BatteryData->BatteryInformation.DefaultAlert1);
326 
327  /* Choose the highest alert */
328  BatteryInfo->DefaultAlert2 = max(BatteryInfo->DefaultAlert2,
329  BatteryData->BatteryInformation.DefaultAlert2);
330 
331  /* Choose the highest critical bias */
332  BatteryInfo->CriticalBias = max(BatteryInfo->CriticalBias,
333  BatteryData->BatteryInformation.CriticalBias);
334  }
335 
336  /* Re-acquire the device extension lock and release the remove lock */
337  ExAcquireFastMutex(&DeviceExtension->Lock);
338  IoReleaseRemoveLock(&BatteryData->RemoveLock, 0);
339  }
340 
341  /* Next entry */
342  NextEntry = NextEntry->Flink;
343  }
344 
345  /* We are done with the list, check if the information was queried okay */
346  ExReleaseFastMutex(&DeviceExtension->Lock);
347  if (NT_SUCCESS(Status))
348  {
349  /* If there's no fully charged capacity, use the design capacity */
350  if (!BatteryInfo->FullChargedCapacity)
351  {
352  BatteryInfo->FullChargedCapacity = BatteryInfo->DesignedCapacity;
353  }
354 
355  /* Print out final combined data */
356  if (CompBattDebug & 2)
357  DbgPrint("CompBattGetBatteryInformation: Returning BATTERY_INFORMATION\n"
358  "-------- Capabilities = %x\n-------- Technology = %x\n"
359  "-------- Chemistry[4] = %x\n-------- DesignedCapacity = %x\n"
360  "-------- FullChargedCapacity = %x\n-------- DefaultAlert1 = %x\n"
361  "-------- DefaultAlert2 = %x\n-------- CriticalBias = %x\n"
362  "-------- CycleCount = %x\n",
363  BatteryInfo->Capabilities,
364  BatteryInfo->Technology,
365  BatteryInfo->Chemistry,
366  BatteryInfo->DesignedCapacity,
367  BatteryInfo->FullChargedCapacity,
368  BatteryInfo->DefaultAlert1,
369  BatteryInfo->DefaultAlert2,
370  BatteryInfo->CriticalBias,
371  BatteryInfo->CycleCount);
372 
373  /* Copy the data into the device extension */
374  RtlCopyMemory(&DeviceExtension->BatteryInformation,
375  BatteryInfo,
376  sizeof(DeviceExtension->BatteryInformation));
377  DeviceExtension->Flags |= COMPBATT_BATTERY_INFORMATION_PRESENT;
378  }
379 
380  /* We are done */
381  if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING GetBatteryInformation\n");
382  return Status;
383 }
#define max(a, b)
Definition: svc.c:63
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:809
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define DbgPrint
Definition: loader.c:25
#define IOCTL_BATTERY_QUERY_INFORMATION
Definition: batclass.h:86
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: compmisc.c:17
LONG NTSTATUS
Definition: precomp.h:26
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2760
PDEVICE_OBJECT DeviceObject
Definition: compbatt.h:22
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define BATTERY_UNKNOWN_CAPACITY
Definition: batclass.h:65
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:121
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
CHAR InputBuffer[80]
Definition: conmgr.c:33
Status
Definition: gdiplustypes.h:24
Definition: typedefs.h:119
ULONG FullChargedCapacity
Definition: batclass.h:120
BATTERY_INFORMATION BatteryInformation
Definition: compbatt.h:34
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define COMPBATT_BATTERY_INFORMATION_PRESENT
Definition: compbatt.h:15
UCHAR Chemistry[4]
Definition: batclass.h:118
IO_REMOVE_LOCK RemoveLock
Definition: compbatt.h:21
ULONG CompBattDebug
Definition: compbatt.c:17
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IoAcquireRemoveLock(RemoveLock, Tag)

Referenced by CompBattQueryInformation().

◆ CompBattGetEstimatedTime()

NTSTATUS NTAPI CompBattGetEstimatedTime ( OUT PULONG  Time,
IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 473 of file compbatt.c.

475 {
477  return STATUS_NOT_IMPLEMENTED;
478 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CompBattQueryInformation().

◆ CompBattIoctl()

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

Definition at line 125 of file compbatt.c.

127 {
128  PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
130  if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING Ioctl\n");
131 
132  /* Let the class driver handle it */
133  Status = BatteryClassIoctl(DeviceExtension->ClassData, Irp);
135  {
136  /* It failed, try the next driver up the stack */
137  Irp->IoStatus.Status = Status;
139  Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
140  }
141 
142  /* Return status */
143  if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING Ioctl\n");
144  return Status;
145 }
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:54
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
BCLASSAPI NTSTATUS NTAPI BatteryClassIoctl(PVOID ClassData, PIRP Irp)
Definition: battc.c:189
Status
Definition: gdiplustypes.h:24
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
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:423
ULONG CompBattDebug
Definition: compbatt.c:17

Referenced by DriverEntry().

◆ 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:239
#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:239
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CompBattAddNewBattery().

◆ CompBattOpenClose()

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

Definition at line 23 of file compbatt.c.

25 {
26  PAGED_CODE();
27  if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING OpenClose\n");
28 
29  /* Complete the IRP with success */
30  Irp->IoStatus.Status = STATUS_SUCCESS;
31  Irp->IoStatus.Information = 0;
33 
34  /* Return success */
35  if (CompBattDebug & 0x100) DbgPrint("CompBatt: Exiting OpenClose\n");
36  return STATUS_SUCCESS;
37 }
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:581
ULONG CompBattDebug
Definition: compbatt.c:17
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

Referenced by DriverEntry().

◆ CompBattQueryInformation()

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 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)
_In_ PSCSI_REQUEST_BLOCK _In_opt_ PVOID _In_ ULONG BufferLength
Definition: cdrom.h:989
#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:56
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSTATUS NTAPI CompBattGetEstimatedTime(OUT PULONG Time, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:473
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
Status
Definition: gdiplustypes.h:24
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
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:262
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:239
#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().

◆ CompBattRecalculateTag()

VOID NTAPI CompBattRecalculateTag ( IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 88 of file compbatt.c.

89 {
90  PCOMPBATT_BATTERY_DATA BatteryData;
91  ULONG Tag;
92  PLIST_ENTRY ListHead, NextEntry;
93  if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING CompBattRecalculateTag\n");
94 
95  /* Loop the battery list */
96  ExAcquireFastMutex(&DeviceExtension->Lock);
97  ListHead = &DeviceExtension->BatteryList;
98  NextEntry = ListHead->Flink;
99  while (NextEntry != ListHead)
100  {
101  /* Get the battery information and check if it has a tag */
102  BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
103  if (BatteryData->Flags & COMPBATT_TAG_ASSIGNED)
104  {
105  /* Generate the next tag and exit */
106  Tag = DeviceExtension->NextTag;
107  DeviceExtension->Flags |= COMPBATT_TAG_ASSIGNED;
108  DeviceExtension->Tag = Tag;
109  DeviceExtension->NextTag = Tag + 1;
110  break;
111  }
112 
113  /* No tag for this device extension, clear it */
114  DeviceExtension->Tag = 0;
115  NextEntry = NextEntry->Flink;
116  }
117 
118  /* We're done */
119  ExReleaseFastMutex(&DeviceExtension->Lock);
120  if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING CompBattRecalculateTag\n");
121 }
#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:121
#define COMPBATT_TAG_ASSIGNED
Definition: compbatt.h:16
Definition: typedefs.h:119
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
unsigned int ULONG
Definition: retypes.h:1
ULONG CompBattDebug
Definition: compbatt.c:17

Referenced by CompBattQueryTag().

◆ 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:239
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CompBattAddDevice().

◆ CompBattSystemControl()

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

Definition at line 41 of file compbatt.c.

43 {
44  PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
46  PAGED_CODE();
47  if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING System Control\n");
48 
49  /* Are we attached yet? */
50  if (DeviceExtension->AttachedDevice)
51  {
52  /* Send it up the stack */
54  Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
55  }
56  else
57  {
58  /* We don't support WMI */
60  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
62  }
63 
64  /* Return status */
65  return Status;
66 }
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:54
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define IoCompleteRequest
Definition: irp.c:1240
Status
Definition: gdiplustypes.h:24
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
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:423
#define IO_NO_INCREMENT
Definition: iotypes.h:581
ULONG CompBattDebug
Definition: compbatt.c:17
#define PAGED_CODE()

Referenced by DriverEntry().

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 596 of file compbatt.c.

598 {
599  /* Register add device routine */
601 
602  /* Register other handlers */
609  return STATUS_SUCCESS;
610 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
NTSTATUS NTAPI CompBattIoctl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: compbatt.c:125
NTSTATUS NTAPI CompBattAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PdoDeviceObject)
Definition: comppnp.c:320
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2262
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI CompBattSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: compbatt.c:41
NTSTATUS NTAPI CompBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: comppnp.c:403
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_SYSTEM_CONTROL
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2200
NTSTATUS NTAPI CompBattOpenClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: compbatt.c:23
NTSTATUS NTAPI CompBattPowerDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: comppnp.c:19
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2269
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

Variable Documentation

◆ CompBattDebug