[NTOS:PNP] Queue a device change event on interface enable or disable

This commit is contained in:
Eric Kohl 2023-11-27 22:36:05 +01:00
parent a64a674980
commit 12a5971b7a
3 changed files with 53 additions and 1 deletions

View file

@ -668,6 +668,12 @@ CODE_SEG("INIT")
NTSTATUS NTSTATUS
IopInitPlugPlayEvents(VOID); IopInitPlugPlayEvents(VOID);
NTSTATUS
IopQueueDeviceChangeEvent(
_In_ const GUID *EventGuid,
_In_ const GUID *InterfaceClassGuid,
_In_ PUNICODE_STRING SymbolicLinkName);
NTSTATUS NTSTATUS
IopQueueTargetDeviceEvent( IopQueueTargetDeviceEvent(
const GUID *Guid, const GUID *Guid,

View file

@ -6,7 +6,7 @@
* *
* PROGRAMMERS: Filip Navara (xnavara@volny.cz) * PROGRAMMERS: Filip Navara (xnavara@volny.cz)
* Matthew Brace (ismarc@austin.rr.com) * Matthew Brace (ismarc@austin.rr.com)
* Hervé Poussineau (hpoussin@reactos.org) * Hervé Poussineau (hpoussin@reactos.org)
*/ */
/* INCLUDES ******************************************************************/ /* INCLUDES ******************************************************************/
@ -1465,6 +1465,7 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName,
EventGuid = Enable ? &GUID_DEVICE_INTERFACE_ARRIVAL : &GUID_DEVICE_INTERFACE_REMOVAL; EventGuid = Enable ? &GUID_DEVICE_INTERFACE_ARRIVAL : &GUID_DEVICE_INTERFACE_REMOVAL;
PiNotifyDeviceInterfaceChange(EventGuid, &DeviceGuid, SymbolicLinkName); PiNotifyDeviceInterfaceChange(EventGuid, &DeviceGuid, SymbolicLinkName);
IopQueueDeviceChangeEvent(EventGuid, &DeviceGuid, SymbolicLinkName);
ObDereferenceObject(PhysicalDeviceObject); ObDereferenceObject(PhysicalDeviceObject);
DPRINT("Status %x\n", Status); DPRINT("Status %x\n", Status);

View file

@ -48,6 +48,51 @@ IopInitPlugPlayEvents(VOID)
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
NTSTATUS
IopQueueDeviceChangeEvent(
_In_ const GUID *EventGuid,
_In_ const GUID *InterfaceClassGuid,
_In_ PUNICODE_STRING SymbolicLinkName)
{
PPNP_EVENT_ENTRY EventEntry;
UNICODE_STRING Copy;
ULONG TotalSize;
/* Allocate a big enough buffer */
Copy.Length = 0;
Copy.MaximumLength = SymbolicLinkName->Length + sizeof(UNICODE_NULL);
TotalSize =
FIELD_OFFSET(PLUGPLAY_EVENT_BLOCK, DeviceClass.SymbolicLinkName) +
Copy.MaximumLength;
EventEntry = ExAllocatePool(NonPagedPool,
TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
if (!EventEntry)
return STATUS_INSUFFICIENT_RESOURCES;
RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
/* Fill the buffer with the event GUID */
RtlCopyMemory(&EventEntry->Event.EventGuid, EventGuid, sizeof(GUID));
EventEntry->Event.EventCategory = DeviceClassChangeEvent;
EventEntry->Event.TotalSize = TotalSize;
/* Fill the interface class GUID */
RtlCopyMemory(&EventEntry->Event.DeviceClass.ClassGuid, InterfaceClassGuid, sizeof(GUID));
/* Fill the symbolic link name */
RtlCopyMemory(&EventEntry->Event.DeviceClass.SymbolicLinkName,
SymbolicLinkName->Buffer, SymbolicLinkName->Length);
EventEntry->Event.DeviceClass.SymbolicLinkName[SymbolicLinkName->Length / sizeof(WCHAR)] = UNICODE_NULL;
InsertHeadList(&IopPnpEventQueueHead,
&EventEntry->ListEntry);
KeSetEvent(&IopPnpNotifyEvent,
0,
FALSE);
return STATUS_SUCCESS;
}
NTSTATUS NTSTATUS
IopQueueTargetDeviceEvent(const GUID *Guid, IopQueueTargetDeviceEvent(const GUID *Guid,
PUNICODE_STRING DeviceIds) PUNICODE_STRING DeviceIds)