ReactOS 0.4.15-dev-8231-g29a56f3
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 PCUNICODE_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 320 of file comppnp.c.

322{
325 PCOMPBATT_DEVICE_EXTENSION DeviceExtension;
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");
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 */
365 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
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}
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:137
#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 OPTIONAL LONG AtRate, IN PVOID Buffer, IN ULONG BufferLength, OUT PULONG ReturnedLength)
Definition: compbatt.c:482
ULONG CompBattDebug
Definition: compbatt.c:17
NTSTATUS NTAPI CompBattDisableStatusNotify(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:184
NTSTATUS NTAPI CompBattQueryTag(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, OUT PULONG Tag)
Definition: compbatt.c:149
NTSTATUS NTAPI CompBattSetStatusNotify(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG BatteryTag, IN PBATTERY_NOTIFY BatteryNotify)
Definition: compbatt.c:211
NTSTATUS NTAPI CompBattQueryStatus(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag, IN PBATTERY_STATUS BatteryStatus)
Definition: compbatt.c:221
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#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:55
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:54
#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 113 of file comppnp.c.

115{
117 PCOMPBATT_BATTERY_DATA BatteryData;
118 PIRP Irp;
119 PIO_STACK_LOCATION IoStackLocation;
121 PAGED_CODE();
122 if (CompBattDebug & 1)
123 DbgPrint("CompBatt: ENTERING AddNewBattery \"%w\" \n", BatteryName->Buffer);
124
125 /* Is this a new battery? */
126 if (!IsBatteryAlreadyOnList(BatteryName, DeviceExtension))
127 {
128 /* Allocate battery data */
130 sizeof(COMPBATT_BATTERY_DATA) +
131 BatteryName->Length,
132 'CtaB');
133 if (BatteryData)
134 {
135 /* Initialize the data and write the battery name */
136 RtlZeroMemory(BatteryData, sizeof(COMPBATT_BATTERY_DATA));
137 BatteryData->Tag = 0;
138 BatteryData->BatteryName.MaximumLength = BatteryName->Length;
139 BatteryData->BatteryName.Buffer = (PWCHAR)(BatteryData + 1);
140 RtlCopyUnicodeString(&BatteryData->BatteryName, BatteryName);
141
142 /* Get the device object */
145 &FileObject,
146 &BatteryData->DeviceObject);
147 if (NT_SUCCESS(Status))
148 {
149 /* Reference the DO and drop the FO */
150 ObReferenceObject(BatteryData->DeviceObject);
152
153 /* Allocate the battery IRP */
154 Irp = IoAllocateIrp(BatteryData->DeviceObject->StackSize + 1, 0);
155 if (Irp)
156 {
157 /* Save it */
158 BatteryData->Irp = Irp;
159
160 /* Setup the stack location */
161 IoStackLocation = IoGetNextIrpStackLocation(Irp);
162 IoStackLocation->Parameters.Others.Argument1 = DeviceExtension;
163 IoStackLocation->Parameters.Others.Argument2 = BatteryData;
164
165 /* Set IRP data */
167 Irp->IoStatus.Status = STATUS_DEVICE_NOT_CONNECTED;
168 BatteryData->WaitFlag = 0;
169
170 /* Insert this battery in the list */
171 ExAcquireFastMutex(&DeviceExtension->Lock);
172 InsertTailList(&DeviceExtension->BatteryList,
173 &BatteryData->BatteryLink);
174 ExReleaseFastMutex(&DeviceExtension->Lock);
175
176 /* Initialize the work item and delete lock */
177 IoInitializeRemoveLock(&BatteryData->RemoveLock, 0, 0, 0);
178 ExInitializeWorkItem(&BatteryData->WorkItem,
180 BatteryData);
181
182 /* Setup the IRP work entry */
185 }
186 else
187 {
188 /* Fail, no memory */
189 if (CompBattDebug & 8)
190 DbgPrint("CompBatt: Couldn't allocate new battery Irp\n");
192 ObDereferenceObject(BatteryData->DeviceObject);
193 }
194 }
195 else if (CompBattDebug & 8)
196 {
197 /* Fail */
198 DbgPrint("CompBattAddNewBattery: Failed to get device Object. status = %lx\n",
199 Status);
200 }
201
202 /* Free the battery data */
203 ExFreePool(BatteryData);
204 }
205 else
206 {
207 /* Fail, no memory */
208 if (CompBattDebug & 8)
209 DbgPrint("CompBatt: Couldn't allocate new battery node\n");
211 }
212 }
213
214 /* We're done */
215 if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING AddNewBattery\n");
216 return Status;
217}
#define PAGED_CODE()
NTSTATUS NTAPI CompBattMonitorIrpComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PKEVENT Event)
Definition: compbatt.c:70
NTSTATUS NTAPI CompBattMonitorIrpCompleteWorker(IN PCOMPBATT_BATTERY_DATA BatteryData)
Definition: compbatt.c:80
NTSTATUS NTAPI CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: compmisc.c:74
BOOLEAN NTAPI IsBatteryAlreadyOnList(IN PCUNICODE_STRING BatteryName, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:77
_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:22
LIST_ENTRY BatteryLink
Definition: compbatt.h:20
UNICODE_STRING BatteryName
Definition: compbatt.h:37
WORK_QUEUE_ITEM WorkItem
Definition: compbatt.h:24
IO_REMOVE_LOCK RemoveLock
Definition: compbatt.h:21
struct _IO_STACK_LOCATION::@3991::@4030 Others
union _IO_STACK_LOCATION::@1573 Parameters
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 246 of file comppnp.c.

247{
248 PWCHAR p;
250 PWCHAR LinkList;
251 UNICODE_STRING LinkString;
252 if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING GetBatteries\n");
253
254 /* Get all battery links */
255 Status = IoGetDeviceInterfaces(&GUID_DEVICE_BATTERY, NULL, 0, &LinkList);
256 p = LinkList;
257 if (NT_SUCCESS(Status))
258 {
259 /* Loop all strings inside */
260 while (TRUE)
261 {
262 /* Create the string */
263 RtlInitUnicodeString(&LinkString, p);
264 if (!LinkString.Length) break;
265
266 /* Add this battery and move on */
267 Status = CompBattAddNewBattery(&LinkString, DeviceExtension);
268 p += (LinkString.Length / sizeof(WCHAR)) + sizeof(UNICODE_NULL);
269 }
270
271 /* Parsing complete, clean up buffer */
272 ExFreePool(LinkList);
273 }
274 else if (CompBattDebug & 8)
275 {
276 /* Fail */
277 DbgPrint("CompBatt: Couldn't get list of batteries\n");
278 }
279
280 /* Done */
281 if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING GetBatteries\n");
282 return Status;
283}
NTSTATUS NTAPI CompBattAddNewBattery(IN PUNICODE_STRING BatteryName, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:113
#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 403 of file comppnp.c.

405{
408 PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
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 {
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}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
NTSTATUS NTAPI CompBattPnpEventHandler(IN PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification, IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:287
NTSTATUS NTAPI CompBattGetBatteries(IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:246
#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
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
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:345
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#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 287 of file comppnp.c.

289{
290 if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING PnpEventHandler\n");
291 if (CompBattDebug & 2) DbgPrint("CompBatt: Received device interface change notification\n");
292
293 /* Check what happened */
295 {
296 /* Add the new battery */
297 if (CompBattDebug & 2)
298 DbgPrint("CompBatt: Received notification of battery arrival\n");
299 CompBattAddNewBattery(Notification->SymbolicLinkName, DeviceExtension);
300 }
302 {
303 /* Don't do anything */
304 if (CompBattDebug & 2)
305 DbgPrint("CompBatt: Received notification of battery removal\n");
306 }
307 else
308 {
309 /* Shouldn't happen */
310 if (CompBattDebug & 2) DbgPrint("CompBatt: Received unhandled PnP event\n");
311 }
312
313 /* Done, return success */
314 if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING PnpEventHandler\n");
315 return STATUS_SUCCESS;
316}
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 19 of file comppnp.c.

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

Referenced by DriverEntry().

◆ CompBattRemoveBattery()

NTSTATUS NTAPI CompBattRemoveBattery ( IN PCUNICODE_STRING  BatteryName,
IN PCOMPBATT_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 221 of file comppnp.c.

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

◆ IsBatteryAlreadyOnList()

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

Definition at line 77 of file comppnp.c.

79{
80 PLIST_ENTRY ListHead, NextEntry;
81 PCOMPBATT_BATTERY_DATA BatteryData;
83 if (CompBattDebug & 1)
84 DbgPrint("CompBatt: ENTERING IsBatteryAlreadyOnList\n");
85
86 /* Loop the battery list */
87 ExAcquireFastMutex(&DeviceExtension->Lock);
88 ListHead = &DeviceExtension->BatteryList;
89 NextEntry = ListHead->Flink;
90 while (NextEntry != ListHead)
91 {
92 /* Get the battery information and compare the name */
93 BatteryData = CONTAINING_RECORD(NextEntry, COMPBATT_BATTERY_DATA, BatteryLink);
94 if (!RtlCompareUnicodeString(BatteryName, &BatteryData->BatteryName, TRUE))
95 {
96 /* Got it */
97 Found = TRUE;
98 break;
99 }
100
101 /* Next */
102 NextEntry = NextEntry->Flink;
103 }
104
105 /* Release the lock and return search status */
106 ExReleaseFastMutex(&DeviceExtension->Lock);
107 if (CompBattDebug & 1) DbgPrint("CompBatt: EXITING IsBatteryAlreadyOnList\n");
108 return Found;
109}
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.

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

Referenced by CompBattRemoveBattery().