ReactOS 0.4.16-dev-297-gc569aee
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}
ULONG CompBattDebug
Definition: compbatt.c:17
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define DbgPrint
Definition: hal.h:12
#define STATUS_SUCCESS
Definition: shellext.h:65
BATTERY_WAIT_STATUS WaitStatus
Definition: compbatt.h:26
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

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;
420
421 /* Make sure the battery has a tag */
422 if (BatteryData->Tag != BATTERY_TAG_INVALID)
423 {
424 /* Send the IOCTL to query the information */
425 RtlZeroMemory(&BatteryData->BatteryInformation,
426 sizeof(BatteryData->BatteryInformation));
428 BatteryData->DeviceObject,
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}
LONG NTSTATUS
Definition: precomp.h:26
@ BatteryGranularityInformation
Definition: batclass.h:98
#define IOCTL_BATTERY_QUERY_INFORMATION
Definition: batclass.h:86
#define BATTERY_TAG_INVALID
Definition: batclass.h:94
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
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
#define min(a, b)
Definition: monoChain.cc:55
PDEVICE_OBJECT DeviceObject
Definition: compbatt.h:22
BATTERY_INFORMATION BatteryInformation
Definition: compbatt.h:34
IO_REMOVE_LOCK RemoveLock
Definition: compbatt.h:21
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
#define IoAcquireRemoveLock(RemoveLock, Tag)
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2764

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 != BATTERY_TAG_INVALID)
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,
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,
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 BATTERY_UNKNOWN_CAPACITY
Definition: batclass.h:65
@ BatteryInformation
Definition: batclass.h:97
#define COMPBATT_BATTERY_INFORMATION_PRESENT
Definition: compbatt.h:15
#define STATUS_DEVICE_REMOVED
Definition: d3dkmdt.h:39
UCHAR Chemistry[4]
Definition: batclass.h:118
ULONG FullChargedCapacity
Definition: batclass.h:120
#define max(a, b)
Definition: svc.c:63
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136

Referenced by CompBattQueryInformation().

◆ CompBattGetEstimatedTime()

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

Definition at line 473 of file compbatt.c.

475{
478}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42

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}
BCLASSAPI NTSTATUS NTAPI BatteryClassIoctl(PVOID ClassData, PIRP Irp)
Definition: battc.c:189
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1225
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:54
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

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}

Referenced by CompBattAddNewBattery().

◆ CompBattMonitorIrpCompleteWorker()

NTSTATUS NTAPI CompBattMonitorIrpCompleteWorker ( IN PCOMPBATT_BATTERY_DATA  BatteryData)

Definition at line 80 of file compbatt.c.

81{
84}

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 PAGED_CODE()
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598

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 */
507 }
508
509 /* Check what caller wants */
510 switch (InfoLevel)
511 {
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
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
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}
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
@ BatteryManufactureName
Definition: batclass.h:103
@ BatteryUniqueID
Definition: batclass.h:104
@ BatteryEstimatedTime
Definition: batclass.h:100
@ BatteryDeviceName
Definition: batclass.h:101
@ BatteryTemperature
Definition: batclass.h:99
@ BatteryManufactureDate
Definition: batclass.h:102
Definition: bufpool.h:45
NTSTATUS NTAPI CompBattGetBatteryInformation(OUT PBATTERY_INFORMATION BatteryInfo, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:231
NTSTATUS NTAPI CompBattGetBatteryGranularity(OUT PBATTERY_REPORTING_SCALE ReportingScale, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:387
NTSTATUS NTAPI CompBattGetEstimatedTime(OUT PULONG Time, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:473
#define COMPBATT_TAG_ASSIGNED
Definition: compbatt.h:16
#define NULL
Definition: types.h:112
static PLARGE_INTEGER Time
Definition: time.c:105
#define L(x)
Definition: ntvdm.h:50
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

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{
227}

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 != BATTERY_TAG_INVALID)
165 {
166 /* Return the tag */
167 *Tag = DeviceExtension->Tag;
169 }
170 else
171 {
172 /* No tag */
175 }
176
177 /* Return status */
178 if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING QueryTag\n");
179 return Status;
180}
VOID NTAPI CompBattRecalculateTag(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:88

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 = BATTERY_TAG_INVALID;
115 NextEntry = NextEntry->Flink;
116 }
117
118 /* We're done */
119 ExReleaseFastMutex(&DeviceExtension->Lock);
120 if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING CompBattRecalculateTag\n");
121}

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{
217}

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}

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 */
600 DriverObject->DriverExtension->AddDevice = CompBattAddDevice;
601
602 /* Register other handlers */
609 return STATUS_SUCCESS;
610}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
NTSTATUS NTAPI CompBattSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: compbatt.c:41
NTSTATUS NTAPI CompBattIoctl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: compbatt.c:125
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
NTSTATUS NTAPI CompBattAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PdoDeviceObject)
Definition: comppnp.c:323
NTSTATUS NTAPI CompBattPnpDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: comppnp.c:406
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_POWER

Variable Documentation

◆ CompBattDebug