ReactOS 0.4.16-dev-550-g2186ce3
comppnp.c File Reference
#include "compbatt.h"
#include <wdmguid.h>
Include dependency graph for comppnp.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI CompBattPowerDispatch (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
PCOMPBATT_BATTERY_DATA NTAPI RemoveBatteryFromList (_In_ PCUNICODE_STRING BatteryName, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
BOOLEAN NTAPI IsBatteryAlreadyOnList (_In_ PCUNICODE_STRING BatteryName, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattAddNewBattery (_In_ PUNICODE_STRING BatteryName, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattRemoveBattery (_In_ PUNICODE_STRING BatteryName, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattGetBatteries (_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattPnpEventHandler (_In_ PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CompBattAddDevice (_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT PdoDeviceObject)
 
NTSTATUS NTAPI CompBattPnpDispatch (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 

Function Documentation

◆ CompBattAddDevice()

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

Definition at line 328 of file comppnp.c.

331{
334 PCOMPBATT_DEVICE_EXTENSION DeviceExtension;
337 BATTERY_MINIPORT_INFO MiniportInfo;
338 if (CompBattDebug & COMPBATT_DEBUG_WARN) DbgPrint("CompBatt: Got an AddDevice - %x\n", PdoDeviceObject);
339
340 /* Create the device */
341 RtlInitUnicodeString(&DeviceName, L"\\Device\\CompositeBattery");
344 &DeviceName,
347 FALSE,
348 &DeviceObject);
349 if (!NT_SUCCESS(Status)) return Status;
350
351 /* Setup symbolic link for Win32 access */
352 RtlInitUnicodeString(&SymbolicLinkName, L"\\DosDevices\\CompositeBattery");
354
355 /* Initialize the device extension */
356 DeviceExtension = DeviceObject->DeviceExtension;
357 RtlZeroMemory(DeviceExtension, sizeof(COMPBATT_DEVICE_EXTENSION));
358
359 /* Attach to device stack and set DO pointers */
362 DeviceExtension->DeviceObject = DeviceObject;
363 if (!DeviceExtension->AttachedDevice)
364 {
365 /* Fail */
367 DbgPrint("CompBattAddDevice: Could not attach to LowerDevice.\n");
369 return STATUS_UNSUCCESSFUL;
370 }
371
372 /* Set device object flags */
374 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
375
376 /* Setup the device extension */
377 ExInitializeFastMutex(&DeviceExtension->Lock);
378 InitializeListHead(&DeviceExtension->BatteryList);
379 DeviceExtension->Flags = 0;
380 DeviceExtension->NextTag = 1;
381
382 /* Setup the miniport data */
383 RtlZeroMemory(&MiniportInfo, sizeof(MiniportInfo));
386 MiniportInfo.Context = DeviceExtension;
387 MiniportInfo.DeviceName = &DeviceName;
390 MiniportInfo.SetInformation = NULL;
394 MiniportInfo.Pdo = NULL;
395
396 /* Register with the class driver */
397 Status = BatteryClassInitializeDevice(&MiniportInfo,
398 &DeviceExtension->ClassData);
399 if (!NT_SUCCESS(Status))
400 {
401 /* Undo everything */
402 IoDetachDevice(DeviceExtension->AttachedDevice);
404 }
405
406 /* Return status */
407 return Status;
408}
LONG NTSTATUS
Definition: precomp.h:26
#define BATTERY_CLASS_MAJOR_VERSION
Definition: batclass.h:163
PBCLASS_QUERY_INFORMATION_CALLBACK BCLASS_QUERY_INFORMATION
Definition: batclass.h:241
PBCLASS_SET_STATUS_NOTIFY_CALLBACK BCLASS_SET_STATUS_NOTIFY
Definition: batclass.h:243
PBCLASS_DISABLE_STATUS_NOTIFY_CALLBACK BCLASS_DISABLE_STATUS_NOTIFY
Definition: batclass.h:245
#define BATTERY_CLASS_MINOR_VERSION
Definition: batclass.h:164
PBCLASS_QUERY_STATUS_CALLBACK BCLASS_QUERY_STATUS
Definition: batclass.h:242
PBCLASS_QUERY_TAG_CALLBACK BCLASS_QUERY_TAG
Definition: batclass.h:240
BCLASSAPI NTSTATUS NTAPI BatteryClassInitializeDevice(PBATTERY_MINIPORT_INFO MiniportInfo, PVOID *ClassData)
Definition: battc.c:146
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
NTSTATUS NTAPI CompBattQueryInformation(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension, _In_ ULONG Tag, _In_ BATTERY_QUERY_INFORMATION_LEVEL InfoLevel, _In_opt_ LONG AtRate, _In_ PVOID Buffer, _In_ ULONG BufferLength, _Out_ PULONG ReturnedLength)
Definition: compbatt.c:1656
NTSTATUS NTAPI CompBattQueryStatus(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension, _In_ ULONG Tag, _Out_ PBATTERY_STATUS BatteryStatus)
Queries the battery status of each individiual connected battery with the composite battery and combi...
Definition: compbatt.c:932
ULONG CompBattDebug
Definition: compbatt.c:17
NTSTATUS NTAPI CompBattQueryTag(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension, _Out_ PULONG Tag)
Definition: compbatt.c:453
NTSTATUS NTAPI CompBattSetStatusNotify(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension, _In_ ULONG BatteryTag, _In_ PBATTERY_NOTIFY BatteryNotify)
Sets a new configuration battery wait status settings of each battery. The purpose of this is so that...
Definition: compbatt.c:676
NTSTATUS NTAPI CompBattDisableStatusNotify(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:489
#define COMPBATT_DEBUG_WARN
Definition: compbatt.h:70
#define COMPBATT_DEBUG_ERR
Definition: compbatt.h:71
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Status
Definition: gdiplustypes.h:25
#define DbgPrint
Definition: hal.h:12
_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:95
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
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
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_BATTERY
Definition: winioctl.h:86
BCLASS_QUERY_INFORMATION QueryInformation
Definition: batclass.h:252
PDEVICE_OBJECT Pdo
Definition: batclass.h:257
BCLASS_SET_STATUS_NOTIFY SetStatusNotify
Definition: batclass.h:255
BCLASS_SET_INFORMATION SetInformation
Definition: batclass.h:253
PUNICODE_STRING DeviceName
Definition: batclass.h:258
BCLASS_DISABLE_STATUS_NOTIFY DisableStatusNotify
Definition: batclass.h:256
BCLASS_QUERY_STATUS QueryStatus
Definition: batclass.h:254
BCLASS_QUERY_TAG QueryTag
Definition: batclass.h:251
PDEVICE_OBJECT DeviceObject
Definition: compbatt.h:208
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:207
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING SymbolicLinkName
Definition: wdfdevice.h:3739
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define DO_POWER_PAGABLE

Referenced by DriverEntry().

◆ CompBattAddNewBattery()

NTSTATUS NTAPI CompBattAddNewBattery ( _In_ PUNICODE_STRING  BatteryName,
_In_ PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 115 of file comppnp.c.

118{
120 PCOMPBATT_BATTERY_DATA BatteryData;
121 PIRP Irp;
122 PIO_STACK_LOCATION IoStackLocation;
124 PAGED_CODE();
126 DbgPrint("CompBatt: ENTERING AddNewBattery \"%w\" \n", BatteryName->Buffer);
127
128 /* Is this a new battery? */
129 if (!IsBatteryAlreadyOnList(BatteryName, DeviceExtension))
130 {
131 /* Allocate battery data */
133 sizeof(COMPBATT_BATTERY_DATA) +
134 BatteryName->Length,
135 'CtaB');
136 if (BatteryData)
137 {
138 /* Initialize the data and write the battery name */
139 RtlZeroMemory(BatteryData, sizeof(COMPBATT_BATTERY_DATA));
140 BatteryData->Tag = BATTERY_TAG_INVALID;
141 BatteryData->BatteryName.MaximumLength = BatteryName->Length;
142 BatteryData->BatteryName.Buffer = (PWCHAR)(BatteryData + 1);
143 RtlCopyUnicodeString(&BatteryData->BatteryName, BatteryName);
144
145 /* Get the device object */
148 &FileObject,
149 &BatteryData->DeviceObject);
150 if (NT_SUCCESS(Status))
151 {
152 /* Reference the DO and drop the FO */
153 ObReferenceObject(BatteryData->DeviceObject);
155
156 /* Allocate the battery IRP */
157 Irp = IoAllocateIrp(BatteryData->DeviceObject->StackSize + 1, 0);
158 if (Irp)
159 {
160 /* Save it */
161 BatteryData->Irp = Irp;
162
163 /* Setup the stack location */
164 IoStackLocation = IoGetNextIrpStackLocation(Irp);
165 IoStackLocation->Parameters.Others.Argument1 = DeviceExtension;
166 IoStackLocation->Parameters.Others.Argument2 = BatteryData;
167
168 /* Set IRP data */
170 Irp->IoStatus.Status = STATUS_DEVICE_NOT_CONNECTED;
171
172 /* Insert this battery in the list */
173 ExAcquireFastMutex(&DeviceExtension->Lock);
174 InsertTailList(&DeviceExtension->BatteryList,
175 &BatteryData->BatteryLink);
176 ExReleaseFastMutex(&DeviceExtension->Lock);
177
178 /* Initialize the work item and delete lock */
179 IoInitializeRemoveLock(&BatteryData->RemoveLock, COMPBATT_TAG, 0, 0);
180 ExInitializeWorkItem(&BatteryData->WorkItem,
182 BatteryData);
183
184 /* Setup the IRP work entry */
187 }
188 else
189 {
190 /* Fail, no memory */
192 DbgPrint("CompBatt: Couldn't allocate new battery Irp\n");
194 ObDereferenceObject(BatteryData->DeviceObject);
195 }
196 }
198 {
199 /* Fail */
200 DbgPrint("CompBattAddNewBattery: Failed to get device Object. status = %lx\n",
201 Status);
202 }
203
204 if (!NT_SUCCESS(Status))
205 {
206 /* Free the battery data */
207 ExFreePool(BatteryData);
208 }
209 }
210 else
211 {
212 /* Fail, no memory */
214 DbgPrint("CompBatt: Couldn't allocate new battery node\n");
216 }
217 }
218
219 /* We're done */
220 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: EXITING AddNewBattery\n");
221 return Status;
222}
#define PAGED_CODE()
#define BATTERY_TAG_INVALID
Definition: batclass.h:94
NTSTATUS NTAPI CompBattMonitorIrpComplete(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID Context)
Queues a work item thread worker which is bound to the individual CM (Control Method) ACPI battery to...
Definition: compbatt.c:92
VOID NTAPI CompBattMonitorIrpCompleteWorker(_In_ PCOMPBATT_BATTERY_DATA BatteryData)
The brains of the battery IRP worker. It monitors the state of the IRP as well as sends the IRP down ...
Definition: compbatt.c:125
#define COMPBATT_TAG
Definition: compbatt.h:22
NTSTATUS NTAPI CompBattGetDeviceObjectPointer(_In_ PUNICODE_STRING DeviceName, _In_ ACCESS_MASK DesiredAccess, _Out_ PFILE_OBJECT *FileObject, _Out_ PDEVICE_OBJECT *DeviceObject)
Definition: compmisc.c:74
#define COMPBATT_DEBUG_TRACE
Definition: compbatt.h:69
BOOLEAN NTAPI IsBatteryAlreadyOnList(_In_ PCUNICODE_STRING BatteryName, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:78
_In_ PIRP Irp
Definition: csq.h:116
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define STATUS_SUCCESS
Definition: shellext.h:65
PDEVICE_OBJECT DeviceObject
Definition: compbatt.h:91
LIST_ENTRY BatteryLink
Definition: compbatt.h:82
UNICODE_STRING BatteryName
Definition: compbatt.h:148
WORK_QUEUE_ITEM WorkItem
Definition: compbatt.h:98
IO_REMOVE_LOCK RemoveLock
Definition: compbatt.h:85
union _IO_STACK_LOCATION::@1583 Parameters
struct _IO_STACK_LOCATION::@4015::@4054 Others
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
FORCEINLINE VOID IoSetNextIrpStackLocation(_Inout_ PIRP Irp)
Definition: iofuncs.h:2680
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2833
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by CompBattGetBatteries(), and CompBattPnpEventHandler().

◆ CompBattGetBatteries()

NTSTATUS NTAPI CompBattGetBatteries ( _In_ PCOMPBATT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 252 of file comppnp.c.

254{
255 PWCHAR p;
257 PWCHAR LinkList;
258 UNICODE_STRING LinkString;
259 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: ENTERING GetBatteries\n");
260
261 /* Get all battery links */
262 Status = IoGetDeviceInterfaces(&GUID_DEVICE_BATTERY, NULL, 0, &LinkList);
263 p = LinkList;
264 if (NT_SUCCESS(Status))
265 {
266 /* Loop all strings inside */
267 while (TRUE)
268 {
269 /* Create the string */
270 RtlInitUnicodeString(&LinkString, p);
271 if (!LinkString.Length) break;
272
273 /* Add this battery and move on */
274 Status = CompBattAddNewBattery(&LinkString, DeviceExtension);
275 p += (LinkString.Length / sizeof(WCHAR)) + sizeof(UNICODE_NULL);
276 }
277
278 /* Parsing complete, clean up buffer */
279 ExFreePool(LinkList);
280 }
282 {
283 /* Fail */
284 DbgPrint("CompBatt: Couldn't get list of batteries\n");
285 }
286
287 /* Done */
288 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: EXITING GetBatteries\n");
289 return Status;
290}
NTSTATUS NTAPI CompBattAddNewBattery(_In_ PUNICODE_STRING BatteryName, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:115
#define TRUE
Definition: types.h:120
GLfloat GLfloat p
Definition: glext.h:8902
#define UNICODE_NULL
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CompBattPnpDispatch().

◆ CompBattPnpDispatch()

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

Definition at line 412 of file comppnp.c.

415{
418 PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
419 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: ENTERING PnpDispatch\n");
420
421 /* Set default error */
423
424 /* Check what kind of PnP function this is */
425 switch (IoStackLocation->MinorFunction)
426 {
428
429 /* Device is starting, register for new batteries and pick up current ones */
431 0,
432 (PVOID)&GUID_DEVICE_BATTERY,
433 DeviceObject->DriverObject,
435 DeviceExtension,
436 &DeviceExtension->NotificationEntry);
437 if (NT_SUCCESS(Status))
438 {
439 /* Now go get the batteries */
441 DbgPrint("CompBatt: Successfully registered for PnP notification\n");
442 Status = CompBattGetBatteries(DeviceExtension);
443 }
444 else
445 {
446 /* We failed */
448 DbgPrint("CompBatt: Couldn't register for PnP notification - %x\n",
449 Status);
450 }
451 break;
453
454 /* Explicitly say ok */
456 break;
457
459
460 /* Explicitly say ok */
462 break;
463
465
466 /* Explicitly say ok */
468 break;
469
471
472 /* Add this in */
473 Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
475 break;
476
477 default:
478
479 /* Not supported */
480 break;
481 }
482
483 /* Set IRP status if we have one */
484 if (Status != STATUS_NOT_SUPPORTED) Irp->IoStatus.Status = Status;
485
486 /* Did someone pick it up? */
488 {
489 /* Still unsupported, try ACPI */
491 Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
492 }
493 else
494 {
495 /* Complete the request */
496 Status = Irp->IoStatus.Status;
498 }
499
500 /* Release the remove lock and return status */
501 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: EXITING PnpDispatch\n");
502 return Status;
503}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
NTSTATUS NTAPI CompBattPnpEventHandler(_In_ PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:294
NTSTATUS NTAPI CompBattGetBatteries(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:252
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
NTSTATUS NTAPI IoRegisterPlugPlayNotification(_In_ IO_NOTIFICATION_EVENT_CATEGORY EventCategory, _In_ ULONG EventCategoryFlags, _In_opt_ PVOID EventCategoryData, _In_ PDRIVER_OBJECT DriverObject, _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, _Inout_opt_ PVOID Context, _Out_ PVOID *NotificationEntry)
Definition: pnpnotify.c:346
#define IRP_MN_CANCEL_STOP_DEVICE
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_START_DEVICE
@ EventCategoryDeviceInterfaceChange
Definition: iotypes.h:1226
#define IRP_MN_CANCEL_REMOVE_DEVICE
DRIVER_NOTIFICATION_CALLBACK_ROUTINE * PDRIVER_NOTIFICATION_CALLBACK_ROUTINE
Definition: iotypes.h:1247

Referenced by DriverEntry().

◆ CompBattPnpEventHandler()

NTSTATUS NTAPI CompBattPnpEventHandler ( _In_ PDEVICE_INTERFACE_CHANGE_NOTIFICATION  Notification,
_In_ PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 294 of file comppnp.c.

297{
298 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: ENTERING PnpEventHandler\n");
299 if (CompBattDebug & COMPBATT_DEBUG_WARN) DbgPrint("CompBatt: Received device interface change notification\n");
300
301 /* Check what happened */
303 {
304 /* Add the new battery */
306 DbgPrint("CompBatt: Received notification of battery arrival\n");
307 CompBattAddNewBattery(Notification->SymbolicLinkName, DeviceExtension);
308 }
310 {
311 /* Don't do anything */
313 DbgPrint("CompBatt: Received notification of battery removal\n");
314 }
315 else
316 {
317 /* Shouldn't happen */
318 if (CompBattDebug & COMPBATT_DEBUG_WARN) DbgPrint("CompBatt: Received unhandled PnP event\n");
319 }
320
321 /* Done, return success */
322 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: EXITING PnpEventHandler\n");
323 return STATUS_SUCCESS;
324}
const GUID GUID_DEVICE_INTERFACE_ARRIVAL
Definition: deviface.c:14
const GUID GUID_DEVICE_INTERFACE_REMOVAL
Definition: deviface.c:15
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_DEVICE_SHUTDOWN_NOTIFICATION Notification
Definition: wdfcontrol.h:115
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235

Referenced by CompBattPnpDispatch().

◆ CompBattPowerDispatch()

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

Definition at line 18 of file comppnp.c.

21{
22 PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
23 if (CompBattDebug & COMPBATT_DEBUG_WARN) 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}
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758

Referenced by DriverEntry().

◆ CompBattRemoveBattery()

NTSTATUS NTAPI CompBattRemoveBattery ( _In_ PUNICODE_STRING  BatteryName,
_In_ PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 226 of file comppnp.c.

229{
230 PCOMPBATT_BATTERY_DATA BatteryData;
231 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: RemoveBattery\n");
232
233 /* Remove the entry */
234 BatteryData = RemoveBatteryFromList(BatteryName, DeviceExtension);
235 if (BatteryData)
236 {
237 /* Dereference and free it */
238 ObDereferenceObject(BatteryData->DeviceObject);
239 ExFreePool(BatteryData);
240
241 /* Notify class driver */
242 DeviceExtension->Flags = 0;
243 BatteryClassStatusNotify(DeviceExtension->ClassData);
244 }
245
246 /* It's done */
247 return STATUS_SUCCESS;
248}
BCLASSAPI NTSTATUS NTAPI BatteryClassStatusNotify(_In_ PVOID ClassData)
Definition: battc.c:79
PCOMPBATT_BATTERY_DATA NTAPI RemoveBatteryFromList(_In_ PCUNICODE_STRING BatteryName, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:35

Referenced by CompBattMonitorIrpCompleteWorker().

◆ IsBatteryAlreadyOnList()

BOOLEAN NTAPI IsBatteryAlreadyOnList ( _In_ PCUNICODE_STRING  BatteryName,
_In_ PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 78 of file comppnp.c.

81{
82 PLIST_ENTRY ListHead, NextEntry;
83 PCOMPBATT_BATTERY_DATA BatteryData;
86 DbgPrint("CompBatt: ENTERING IsBatteryAlreadyOnList\n");
87
88 /* Loop the battery list */
89 ExAcquireFastMutex(&DeviceExtension->Lock);
90 ListHead = &DeviceExtension->BatteryList;
91 NextEntry = ListHead->Flink;
92 while (NextEntry != ListHead)
93 {
94 /* Get the battery information and compare the name */
95 BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
96 if (!RtlCompareUnicodeString(BatteryName, &BatteryData->BatteryName, TRUE))
97 {
98 /* Got it */
99 Found = TRUE;
100 break;
101 }
102
103 /* Next */
104 NextEntry = NextEntry->Flink;
105 }
106
107 /* Release the lock and return search status */
108 ExReleaseFastMutex(&DeviceExtension->Lock);
109 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: EXITING IsBatteryAlreadyOnList\n");
110 return Found;
111}
unsigned char BOOLEAN
return Found
Definition: dirsup.c:1270
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by CompBattAddNewBattery().

◆ RemoveBatteryFromList()

PCOMPBATT_BATTERY_DATA NTAPI RemoveBatteryFromList ( _In_ PCUNICODE_STRING  BatteryName,
_In_ PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 35 of file comppnp.c.

38{
39 PLIST_ENTRY ListHead, NextEntry;
40 PCOMPBATT_BATTERY_DATA BatteryData;
42 DbgPrint("CompBatt: ENTERING RemoveBatteryFromList\n");
43
44 /* Loop the battery list */
45 ExAcquireFastMutex(&DeviceExtension->Lock);
46 ListHead = &DeviceExtension->BatteryList;
47 NextEntry = ListHead->Flink;
48 while (NextEntry != ListHead)
49 {
50 /* Get the battery information and compare the name */
51 BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
52 if (!RtlCompareUnicodeString(BatteryName, &BatteryData->BatteryName, TRUE))
53 {
54 /* Flush pending deletes and any lock waiters */
55 IoAcquireRemoveLock(&BatteryData->RemoveLock, 0);
56 ExReleaseFastMutex(&DeviceExtension->Lock);
57 IoReleaseRemoveLockAndWait(&BatteryData->RemoveLock, 0);
58
59 /* Remove the entry from the list */
60 ExAcquireFastMutex(&DeviceExtension->Lock);
61 RemoveEntryList(&BatteryData->BatteryLink);
62 ExReleaseFastMutex(&DeviceExtension->Lock);
63 return BatteryData;
64 }
65
66 /* Next */
67 NextEntry = NextEntry->Flink;
68 }
69
70 /* Done */
71 ExReleaseFastMutex(&DeviceExtension->Lock);
72 if (CompBattDebug & COMPBATT_DEBUG_TRACE) DbgPrint("CompBatt: EXITING RemoveBatteryFromList\n");
73 return NULL;
74}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IoAcquireRemoveLock(RemoveLock, Tag)
#define IoReleaseRemoveLockAndWait(_RemoveLock, _Tag)
Definition: iofuncs.h:2774

Referenced by CompBattRemoveBattery().