ReactOS 0.4.17-dev-1190-g4c812f4
plugplay.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for plugplay.c:

Go to the source code of this file.

Classes

struct  _PNP_EVENT_ENTRY
 
struct  _IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _PNP_EVENT_ENTRY PNP_EVENT_ENTRY
 
typedef struct _PNP_EVENT_ENTRY * PPNP_EVENT_ENTRY
 
typedef struct _IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT
 
typedef struct _IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT * PIOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT
 

Functions

NTSTATUS IopSetDeviceInstanceData (HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
 
NTSTATUS IopInitPlugPlayEvents (VOID)
 
NTSTATUS IopQueueDeviceChangeEvent (_In_ const GUID *EventGuid, _In_ const GUID *InterfaceClassGuid, _In_ PUNICODE_STRING SymbolicLinkName)
 
NTSTATUS IopQueueDeviceInstallEvent (_In_ const GUID *EventGuid, _In_ PUNICODE_STRING DeviceId)
 
NTSTATUS IopQueueDevicePropertyChangeEvent (_In_ PCUNICODE_STRING DeviceId)
 
NTSTATUS IopQueueTargetDeviceEvent (const GUID *Guid, PUNICODE_STRING DeviceIds)
 
NTSTATUS IopFindDeviceInstanceTraverse (_In_ PDEVICE_NODE DeviceNode, _Inout_ PVOID Context)
 
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance (PUNICODE_STRING DeviceInstance)
 
static NTSTATUS IopCaptureUnicodeString (PUNICODE_STRING DstName, PUNICODE_STRING SrcName)
 
static NTSTATUS PiControlInitializeDevice (_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA ControlData)
 
static NTSTATUS IopRemovePlugPlayEvent (_In_ PPLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData)
 
static NTSTATUS IopGetInterfaceDeviceList (PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA DeviceList)
 
static NTSTATUS IopGetDeviceProperty (PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData)
 
static NTSTATUS IopGetRelatedDevice (PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA RelatedDeviceData)
 
static BOOLEAN PiIsDevNodeStarted (_In_ PDEVICE_NODE DeviceNode)
 
ULONG IopGetDeviceNodeStatus (_In_ PDEVICE_NODE DeviceNode)
 
static NTSTATUS IopDeviceStatus (PPLUGPLAY_CONTROL_STATUS_DATA StatusData)
 
static NTSTATUS IopGetDeviceRelations (PPLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA RelationsData)
 
static NTSTATUS IopGetDeviceDepth (PPLUGPLAY_CONTROL_DEPTH_DATA DepthData)
 
static NTSTATUS PiControlSyncDeviceAction (_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA DeviceData, _In_ PLUGPLAY_CONTROL_CLASS ControlClass)
 
static NTSTATUS PiControlQueryRemoveDevice (_In_ PPLUGPLAY_CONTROL_QUERY_REMOVE_DATA ControlData)
 
static NTSTATUS PiControlGetInterfaceDeviceAlias (_In_ PPLUGPLAY_CONTROL_INTERFACE_ALIAS_DATA ControlData)
 
static NTSTATUS PiControlDeviceClassAssociation (_In_ PPLUGPLAY_CONTROL_CLASS_ASSOCIATION_DATA ControlData)
 
NTSTATUS NTAPI NtGetPlugPlayEvent (IN ULONG Reserved1, IN ULONG Reserved2, OUT PPLUGPLAY_EVENT_BLOCK Buffer, IN ULONG BufferSize)
 
NTSTATUS NTAPI NtPlugPlayControl (IN PLUGPLAY_CONTROL_CLASS PlugPlayControlClass, IN OUT PVOID Buffer, IN ULONG BufferLength)
 

Variables

static LIST_ENTRY IopPnpEventQueueHead
 
static KEVENT IopPnpNotifyEvent
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file plugplay.c.

Typedef Documentation

◆ IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT

◆ PIOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT

◆ PNP_EVENT_ENTRY

◆ PPNP_EVENT_ENTRY

Function Documentation

◆ IopCaptureUnicodeString()

static NTSTATUS IopCaptureUnicodeString ( PUNICODE_STRING  DstName,
PUNICODE_STRING  SrcName 
)
static

Definition at line 268 of file plugplay.c.

269{
271 volatile UNICODE_STRING Name;
272
273 Name.Buffer = NULL;
275 {
276 Name.Length = SrcName->Length;
277 Name.MaximumLength = SrcName->MaximumLength;
278 if (Name.Length > Name.MaximumLength)
279 {
282 }
283
284 if (Name.MaximumLength)
285 {
286 ProbeForRead(SrcName->Buffer,
287 Name.MaximumLength,
288 sizeof(WCHAR));
289 Name.Buffer = ExAllocatePool(NonPagedPool, Name.MaximumLength);
290 if (Name.Buffer == NULL)
291 {
294 }
295
296 memcpy(Name.Buffer, SrcName->Buffer, Name.MaximumLength);
297 }
298
299 *DstName = Name;
300 }
302 {
303 if (Name.Buffer)
304 {
305 ExFreePool(Name.Buffer);
306 }
308 }
309 _SEH2_END;
310
311 return Status;
312}
LONG NTSTATUS
Definition: precomp.h:26
LPWSTR Name
Definition: desk.c:124
#define NULL
Definition: types.h:112
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
short WCHAR
Definition: pedump.c:58
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define _SEH2_LEAVE
Definition: pseh2_64.h:206
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by IopDeviceStatus(), IopGetDeviceDepth(), IopGetDeviceProperty(), IopGetDeviceRelations(), IopGetInterfaceDeviceList(), IopGetRelatedDevice(), PiControlInitializeDevice(), PiControlQueryRemoveDevice(), and PiControlSyncDeviceAction().

◆ IopDeviceStatus()

static NTSTATUS IopDeviceStatus ( PPLUGPLAY_CONTROL_STATUS_DATA  StatusData)
static

Definition at line 951 of file plugplay.c.

952{
955 ULONG Operation = 0;
956 ULONG DeviceStatus = 0;
957 ULONG DeviceProblem = 0;
960
961 DPRINT("IopDeviceStatus() called\n");
962
964 if (!NT_SUCCESS(Status))
965 {
966 return Status;
967 }
968
969 DPRINT("Device name: '%wZ'\n", &DeviceInstance);
970
972 {
973 Operation = StatusData->Operation;
975 {
976 DeviceStatus = StatusData->DeviceStatus;
977 DeviceProblem = StatusData->DeviceProblem;
978 }
979 }
981 {
982 if (DeviceInstance.Buffer != NULL)
983 {
985 }
987 }
988 _SEH2_END;
989
990 /* Get the device object */
992 if (DeviceInstance.Buffer != NULL)
993 {
995 }
996 if (DeviceObject == NULL)
997 {
999 }
1000
1002
1003 switch (Operation)
1004 {
1006 DPRINT("Get status data\n");
1007 DeviceStatus = IopGetDeviceNodeStatus(DeviceNode);
1008 DeviceProblem = DeviceNode->Problem;
1009 break;
1010
1012 DPRINT1("Set status data is NOT SUPPORTED\n");
1013 break;
1014
1016 DPRINT1("FIXME: Clear status data!\n");
1017 break;
1018 }
1019
1021
1023 {
1024 _SEH2_TRY
1025 {
1026 StatusData->DeviceStatus = DeviceStatus;
1027 StatusData->DeviceProblem = DeviceProblem;
1028 }
1030 {
1032 }
1033 _SEH2_END;
1034 }
1035
1036 return Status;
1037}
@ DeviceNode
Definition: Node.h:9
#define DPRINT1
Definition: precomp.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
static const WCHAR DeviceInstance[]
Definition: interface.c:28
FP_OP Operation
Definition: fpcontrol.c:150
#define PNP_SET_DEVICE_STATUS
Definition: cmtypes.h:60
#define PNP_CLEAR_DEVICE_STATUS
Definition: cmtypes.h:61
#define PNP_GET_DEVICE_STATUS
Definition: cmtypes.h:59
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
ULONG IopGetDeviceNodeStatus(_In_ PDEVICE_NODE DeviceNode)
Definition: plugplay.c:905
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:234
static NTSTATUS IopCaptureUnicodeString(PUNICODE_STRING DstName, PUNICODE_STRING SrcName)
Definition: plugplay.c:268
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207
#define DPRINT
Definition: sndvol32.h:73
UNICODE_STRING DeviceInstance
Definition: cmtypes.h:570
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by NtPlugPlayControl().

◆ IopFindDeviceInstanceTraverse()

NTSTATUS IopFindDeviceInstanceTraverse ( _In_ PDEVICE_NODE  DeviceNode,
_Inout_ PVOID  Context 
)

Definition at line 214 of file plugplay.c.

217{
219
220 if (RtlEqualUnicodeString(&DeviceNode->InstancePath,
221 DeviceInstanceContext->InstancePath, TRUE))
222 {
223 ObReferenceObject(DeviceNode->PhysicalDeviceObject);
224 DeviceInstanceContext->DeviceObject = DeviceNode->PhysicalDeviceObject;
225
226 /* Stop enumeration */
227 return STATUS_UNSUCCESSFUL;
228 }
229
230 return STATUS_SUCCESS;
231}
#define TRUE
Definition: types.h:120
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by IopGetDeviceObjectFromDeviceInstance().

◆ IopGetDeviceDepth()

static NTSTATUS IopGetDeviceDepth ( PPLUGPLAY_CONTROL_DEPTH_DATA  DepthData)
static

Definition at line 1198 of file plugplay.c.

1199{
1204
1205 DPRINT("IopGetDeviceDepth() called\n");
1206 DPRINT("Device name: %wZ\n", &DepthData->DeviceInstance);
1207
1209 if (!NT_SUCCESS(Status))
1210 {
1211 return Status;
1212 }
1213
1214 /* Get the device object */
1216 if (DeviceInstance.Buffer != NULL)
1217 {
1218 ExFreePool(DeviceInstance.Buffer);
1219 }
1220 if (DeviceObject == NULL)
1221 {
1222 return STATUS_NO_SUCH_DEVICE;
1223 }
1224
1226
1227 _SEH2_TRY
1228 {
1229 DepthData->Depth = DeviceNode->Level;
1230 }
1232 {
1234 }
1235 _SEH2_END;
1236
1238
1239 return Status;
1240}
UNICODE_STRING DeviceInstance
Definition: cmtypes.h:579

Referenced by NtPlugPlayControl().

◆ IopGetDeviceNodeStatus()

ULONG IopGetDeviceNodeStatus ( _In_ PDEVICE_NODE  DeviceNode)

Definition at line 905 of file plugplay.c.

907{
909
910 if (DeviceNode->Parent == IopRootDeviceNode)
912
913 // FIXME: review for deleted and removed states
916
919
920 if (DeviceNode->UserFlags & DNUF_WILL_BE_REMOVED)
922
923 if (DeviceNode->Flags & DNF_HAS_PROBLEM)
925
928
929 if (DeviceNode->Flags & DNF_DRIVER_BLOCKED)
931
934
937
938 if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
940
941 if (DeviceNode->UserFlags & DNUF_DONT_SHOW_IN_UI)
943
944 if (!(DeviceNode->UserFlags & DNUF_NOT_DISABLEABLE))
946
947 return Output;
948}
#define DN_NT_DRIVER
Definition: cfg.h:142
#define DN_NO_SHOW_IN_DM
Definition: cfg.h:148
#define DN_NT_ENUMERATOR
Definition: cfg.h:141
#define DN_DRIVER_LOADED
Definition: cfg.h:119
#define DN_DISABLEABLE
Definition: cfg.h:131
#define DN_DRIVER_BLOCKED
Definition: cfg.h:154
#define DN_CHILD_WITH_INVALID_ID
Definition: cfg.h:156
#define DN_HAS_PROBLEM
Definition: cfg.h:128
#define DN_STARTED
Definition: cfg.h:121
#define DN_WILL_BE_REMOVED
Definition: cfg.h:136
#define DN_ROOT_ENUMERATED
Definition: cfg.h:118
#define DN_LEGACY_DRIVER
Definition: cfg.h:155
#define DN_PRIVATE_PROBLEM
Definition: cfg.h:133
#define DNUF_WILL_BE_REMOVED
Definition: iotypes.h:213
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:187
@ DeviceNodeDriversAdded
Definition: iotypes.h:542
#define DNUF_NOT_DISABLEABLE
Definition: iotypes.h:216
#define DNF_HAS_PRIVATE_PROBLEM
Definition: iotypes.h:189
#define DNUF_DONT_SHOW_IN_UI
Definition: iotypes.h:214
#define DNF_CHILD_WITH_INVALID_ID
Definition: iotypes.h:196
#define DNF_DRIVER_BLOCKED
Definition: iotypes.h:195
#define DNF_HAS_PROBLEM
Definition: iotypes.h:188
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
static BOOLEAN PiIsDevNodeStarted(_In_ PDEVICE_NODE DeviceNode)
Definition: plugplay.c:890
@ Output
Definition: arc.h:94

Referenced by IopDeviceStatus(), and PiPropReadDeviceNodeField().

◆ IopGetDeviceObjectFromDeviceInstance()

PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance ( PUNICODE_STRING  DeviceInstance)

Definition at line 234 of file plugplay.c.

235{
237 IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT DeviceInstanceContext;
238
239 if (IopRootDeviceNode == NULL)
240 return NULL;
241
242 if (DeviceInstance == NULL ||
243 DeviceInstance->Length == 0)
244 {
246 {
249 }
250 else
251 return NULL;
252 }
253
254 /* Traverse the device tree to find the matching device node */
255 DeviceInstanceContext.InstancePath = DeviceInstance;
256 DeviceInstanceContext.DeviceObject = NULL;
260 &DeviceInstanceContext);
262
263 /* In case of error or instance not found, this will still be NULL from above. */
264 return DeviceInstanceContext.DeviceObject;
265}
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:228
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
NTSTATUS IopFindDeviceInstanceTraverse(_In_ PDEVICE_NODE DeviceNode, _Inout_ PVOID Context)
Definition: plugplay.c:214
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:1015

Referenced by IopDeviceStatus(), IopGetDeviceDepth(), IopGetDeviceProperty(), IopGetDeviceRelations(), IopGetInterfaceDeviceList(), IopGetRelatedDevice(), IopInitializeBuiltinDriver(), IoSetDeviceInterfaceState(), PiControlDeviceClassAssociation(), PiControlInitializeDevice(), PiControlQueryRemoveDevice(), PiControlSyncDeviceAction(), and PiInitializeDevNode().

◆ IopGetDeviceProperty()

static NTSTATUS IopGetDeviceProperty ( PPLUGPLAY_CONTROL_PROPERTY_DATA  PropertyData)
static

Definition at line 519 of file plugplay.c.

520{
529
530 DPRINT("IopGetDeviceProperty() called\n");
531 DPRINT("Device name: %wZ\n", &PropertyData->DeviceInstance);
532
534 if (!NT_SUCCESS(Status))
535 {
536 return Status;
537 }
538
540 {
541 Property = PropertyData->Property;
542 BufferSize = PropertyData->BufferSize;
545 sizeof(UCHAR));
546 }
548 {
549 if (DeviceInstance.Buffer != NULL)
550 {
552 }
554 }
555 _SEH2_END;
556
557 /* Get the device object */
559 if (DeviceInstance.Buffer != NULL)
560 {
562 }
563 if (DeviceObject == NULL)
564 {
566 }
567
569 if (Buffer == NULL)
570 {
573 }
574
575
577
579 {
580 if (BufferSize < sizeof(CM_POWER_DATA))
581 {
582 BufferSize = 0;
584 }
585 else
586 {
588 PCM_POWER_DATA PowerData;
591
592 PowerData = (PCM_POWER_DATA)Buffer;
593 RtlZeroMemory(PowerData, sizeof(CM_POWER_DATA));
594 PowerData->PD_Size = sizeof(CM_POWER_DATA);
595
598 DeviceCapabilities.Version = 1;
599 DeviceCapabilities.Address = -1;
600 DeviceCapabilities.UINumber = -1;
601
602 Stack.Parameters.DeviceCapabilities.Capabilities = &DeviceCapabilities;
603
607 &Stack);
608 if (NT_SUCCESS(Status))
609 {
610 DPRINT("Got device capabiliities\n");
611
612 PowerData->PD_MostRecentPowerState = PowerDeviceD0; // FIXME
613 if (DeviceCapabilities.DeviceD1)
615 if (DeviceCapabilities.DeviceD2)
617 if (DeviceCapabilities.WakeFromD0)
619 if (DeviceCapabilities.WakeFromD1)
621 if (DeviceCapabilities.WakeFromD2)
623 if (DeviceCapabilities.WakeFromD3)
625 if (DeviceCapabilities.WarmEjectSupported)
627 PowerData->PD_D1Latency = DeviceCapabilities.D1Latency;
628 PowerData->PD_D2Latency = DeviceCapabilities.D2Latency;
629 PowerData->PD_D3Latency = DeviceCapabilities.D3Latency;
631 &DeviceCapabilities.DeviceState,
632 sizeof(DeviceCapabilities.DeviceState));
633 PowerData->PD_DeepestSystemWake = DeviceCapabilities.SystemWake;
634 }
635 else
636 {
637 DPRINT("IRP_MN_QUERY_CAPABILITIES failed (Status 0x%08lx)\n", Status);
638
641 }
642 }
643 }
645 {
647 BufferSize = 0;
649 }
651 {
652 if (BufferSize < sizeof(DeviceNode->HardwareRemovalPolicy))
653 {
654 BufferSize = 0;
656 }
657 else
658 {
659 BufferSize = sizeof(DeviceNode->HardwareRemovalPolicy);
661 &DeviceNode->HardwareRemovalPolicy,
662 BufferSize);
663 }
664 }
665#if (WINVER >= _WIN32_WINNT_WS03)
667 {
669 BufferSize = 0;
671 }
672#endif
673 else
674 {
675 switch (Property)
676 {
679 break;
680
683 break;
684
687 break;
688
691 break;
692
695 break;
696
699 break;
700
703 break;
704
707 break;
708
711 break;
712
713#if (WINVER >= _WIN32_WINNT_WIN7)
716 break;
717#endif
718
719 default:
720 BufferSize = 0;
722 break;
723 }
724
725 if (Status == STATUS_SUCCESS)
726 {
730 Buffer,
731 &BufferSize);
732 }
733 }
734
736
737 if (NT_SUCCESS(Status))
738 {
740 {
742 PropertyData->BufferSize = BufferSize;
743 }
745 {
747 }
748 _SEH2_END;
749 }
750
752 return Status;
753}
struct CM_Power_Data_s * PCM_POWER_DATA
#define PDCAP_WARM_EJECT_SUPPORTED
Definition: advprop.cpp:44
#define PDCAP_D2_SUPPORTED
Definition: advprop.cpp:38
struct CM_Power_Data_s CM_POWER_DATA
#define PDCAP_D0_SUPPORTED
Definition: advprop.cpp:36
#define PDCAP_D1_SUPPORTED
Definition: advprop.cpp:37
#define PDCAP_WAKE_FROM_D3_SUPPORTED
Definition: advprop.cpp:43
#define PDCAP_WAKE_FROM_D1_SUPPORTED
Definition: advprop.cpp:41
#define PDCAP_WAKE_FROM_D0_SUPPORTED
Definition: advprop.cpp:40
#define PDCAP_D3_SUPPORTED
Definition: advprop.cpp:39
#define PDCAP_WAKE_FROM_D2_SUPPORTED
Definition: advprop.cpp:42
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
Definition: bufpool.h:45
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define BufferSize
Definition: mmc.h:75
_In_ ULONG BufferSize
Definition: dispmprt.h:490
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_In_ WDFDEVICE _In_ PWDF_DEVICE_INTERFACE_PROPERTY_DATA PropertyData
#define PNP_PROPERTY_UI_NUMBER
Definition: cmtypes.h:34
#define PNP_PROPERTY_REMOVAL_POLICY
Definition: cmtypes.h:40
#define PNP_PROPERTY_POWER_DATA
Definition: cmtypes.h:39
#define PNP_PROPERTY_ENUMERATOR_NAME
Definition: cmtypes.h:43
#define PNP_PROPERTY_PHYSICAL_DEVICE_OBJECT_NAME
Definition: cmtypes.h:35
#define PNP_PROPERTY_INSTALL_STATE
Definition: cmtypes.h:45
#define PNP_PROPERTY_LOCATION_PATHS
Definition: cmtypes.h:46
#define PNP_PROPERTY_REMOVAL_POLICY_HARDWARE_DEFAULT
Definition: cmtypes.h:44
#define PNP_PROPERTY_REMOVAL_POLICY_OVERRIDE
Definition: cmtypes.h:41
#define PNP_PROPERTY_LEGACYBUSTYPE
Definition: cmtypes.h:37
#define PNP_PROPERTY_BUSTYPEGUID
Definition: cmtypes.h:36
#define PNP_PROPERTY_ADDRESS
Definition: cmtypes.h:42
#define PNP_PROPERTY_BUSNUMBER
Definition: cmtypes.h:38
#define PNP_PROPERTY_CONTAINERID
Definition: cmtypes.h:47
_In_ PIOMMU_DEVICE_PATH _In_ PIOMMU_SVM_CAPABILITIES DeviceCapabilities
Definition: haltypes.h:1892
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack)
#define IoGetDevObjExtension(DeviceObject)
Definition: io.h:128
@ PowerDeviceD0
Definition: ntpoapi.h:49
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1382
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
SYSTEM_POWER_STATE PD_DeepestSystemWake
Definition: advprop.cpp:55
DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum]
Definition: advprop.cpp:54
ULONG PD_D2Latency
Definition: advprop.cpp:52
ULONG PD_Capabilities
Definition: advprop.cpp:50
ULONG PD_D1Latency
Definition: advprop.cpp:51
DEVICE_POWER_STATE PD_MostRecentPowerState
Definition: advprop.cpp:49
ULONG PD_D3Latency
Definition: advprop.cpp:53
unsigned char UCHAR
Definition: typedefs.h:53
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3775
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
#define DeviceCapabilities
Definition: wingdi.h:4895
DEVICE_CAPABILITIES
Definition: iotypes.h:965
DEVICE_REGISTRY_PROPERTY
Definition: iotypes.h:1194
@ DevicePropertyAddress
Definition: iotypes.h:1211
@ DevicePropertyEnumeratorName
Definition: iotypes.h:1210
@ DevicePropertyInstallState
Definition: iotypes.h:1213
@ DevicePropertyUINumber
Definition: iotypes.h:1212
@ DevicePropertyBusNumber
Definition: iotypes.h:1209
@ DevicePropertyRemovalPolicy
Definition: iotypes.h:1214
@ DevicePropertyPhysicalDeviceObjectName
Definition: iotypes.h:1206
@ DevicePropertyLegacyBusType
Definition: iotypes.h:1208
@ DevicePropertyContainerID
Definition: iotypes.h:1217
@ DevicePropertyBusTypeGuid
Definition: iotypes.h:1207
#define IRP_MN_QUERY_CAPABILITIES

Referenced by NtPlugPlayControl().

◆ IopGetDeviceRelations()

static NTSTATUS IopGetDeviceRelations ( PPLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA  RelationsData)
static

Definition at line 1041 of file plugplay.c.

1042{
1047 PDEVICE_RELATIONS DeviceRelations = NULL;
1048 PDEVICE_OBJECT ChildDeviceObject;
1049 PDEVICE_NODE ChildDeviceNode;
1050 ULONG i;
1051 ULONG Relations;
1053 ULONG BufferLeft;
1054 PWCHAR Buffer, Ptr;
1056
1057 DPRINT1("IopGetDeviceRelations() called\n");
1058 DPRINT1("Device name: %wZ\n", &RelationsData->DeviceInstance);
1059 DPRINT("Relations: %lu\n", RelationsData->Relations);
1060 DPRINT("BufferSize: %lu\n", RelationsData->BufferSize);
1061 DPRINT("Buffer: %p\n", RelationsData->Buffer);
1062
1063 _SEH2_TRY
1064 {
1065 Relations = RelationsData->Relations;
1066 BufferSize = RelationsData->BufferSize;
1067 Buffer = RelationsData->Buffer;
1068
1070 }
1072 {
1074 }
1075 _SEH2_END;
1076
1078 if (!NT_SUCCESS(Status))
1079 {
1080 DPRINT1("IopCaptureUnicodeString() failed (Status 0x%08lx)\n", Status);
1081 return Status;
1082 }
1083
1084 /* Get the device object */
1086 if (DeviceObject == NULL)
1087 {
1088 DPRINT1("IopGetDeviceObjectFromDeviceInstance() returned NULL\n");
1090 goto done;
1091 }
1092
1093 switch (Relations)
1094 {
1096 Stack.Parameters.QueryDeviceRelations.Type = EjectionRelations;
1097 break;
1098
1100 Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
1101 break;
1102
1104 Stack.Parameters.QueryDeviceRelations.Type = PowerRelations;
1105 break;
1106
1107 case PNP_BUS_RELATIONS:
1108 Stack.Parameters.QueryDeviceRelations.Type = BusRelations;
1109 break;
1110
1111 default:
1113 goto done;
1114 }
1115
1119 &Stack);
1120 if (!NT_SUCCESS(Status))
1121 {
1122 DPRINT1("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status);
1123 goto done;
1124 }
1125
1126 DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
1127
1128 DPRINT1("Found %d device relations\n", DeviceRelations->Count);
1129
1130 _SEH2_TRY
1131 {
1132 RequiredSize = 0;
1133 BufferLeft = BufferSize;
1134 Ptr = Buffer;
1135
1136 for (i = 0; i < DeviceRelations->Count; i++)
1137 {
1138 ChildDeviceObject = DeviceRelations->Objects[i];
1139
1140 ChildDeviceNode = IopGetDeviceNode(ChildDeviceObject);
1141 if (ChildDeviceNode)
1142 {
1143 DPRINT("Device instance: %wZ\n", &ChildDeviceNode->InstancePath);
1144 DPRINT("RequiredSize: %hu\n", ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1145
1146 if (Ptr != NULL)
1147 {
1148 if (BufferLeft < ChildDeviceNode->InstancePath.Length + 2 * sizeof(WCHAR))
1149 {
1151 break;
1152 }
1153
1155 ChildDeviceNode->InstancePath.Buffer,
1156 ChildDeviceNode->InstancePath.Length);
1157 Ptr = (PWCHAR)((ULONG_PTR)Ptr + ChildDeviceNode->InstancePath.Length);
1158 *Ptr = UNICODE_NULL;
1159 Ptr = (PWCHAR)((ULONG_PTR)Ptr + sizeof(WCHAR));
1160
1161 BufferLeft -= (ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1162 }
1163
1164 RequiredSize += (ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1165 }
1166 }
1167
1168 if (Ptr != NULL && BufferLeft >= sizeof(WCHAR))
1169 *Ptr = UNICODE_NULL;
1170
1171 if (RequiredSize > 0)
1172 RequiredSize += sizeof(WCHAR);
1173
1174 DPRINT("BufferSize: %lu RequiredSize: %lu\n", RelationsData->BufferSize, RequiredSize);
1175
1176 RelationsData->BufferSize = RequiredSize;
1177 }
1179 {
1181 }
1182 _SEH2_END;
1183
1184done:
1185 if (DeviceRelations != NULL)
1186 ExFreePool(DeviceRelations);
1187
1188 if (DeviceObject != NULL)
1190
1191 if (DeviceInstance.Buffer != NULL)
1192 ExFreePool(DeviceInstance.Buffer);
1193
1194 return Status;
1195}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
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 PNP_POWER_RELATIONS
Definition: cmtypes.h:68
#define PNP_BUS_RELATIONS
Definition: cmtypes.h:69
#define PNP_REMOVAL_RELATIONS
Definition: cmtypes.h:67
#define PNP_EJECT_RELATIONS
Definition: cmtypes.h:66
#define UNICODE_NULL
char CHAR
Definition: pedump.c:57
UNICODE_STRING InstancePath
Definition: iotypes.h:1018
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2165
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID _Out_ PULONG RequiredSize
Definition: wdfdevice.h:4445
@ EjectionRelations
Definition: iotypes.h:2155
@ RemovalRelations
Definition: iotypes.h:2157
@ BusRelations
Definition: iotypes.h:2154
@ PowerRelations
Definition: iotypes.h:2156
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define IRP_MN_QUERY_DEVICE_RELATIONS

Referenced by NtPlugPlayControl().

◆ IopGetInterfaceDeviceList()

static NTSTATUS IopGetInterfaceDeviceList ( PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA  DeviceList)
static

Definition at line 441 of file plugplay.c.

442{
447 GUID FilterGuid;
448 PZZWSTR SymbolicLinkList = NULL, LinkList;
450
452 {
454
455 ProbeForRead(StackList.FilterGuid, sizeof(GUID), sizeof(UCHAR));
456 RtlCopyMemory(&FilterGuid, StackList.FilterGuid, sizeof(GUID));
457
458 if (StackList.Buffer != NULL && StackList.BufferSize != 0)
459 {
460 ProbeForWrite(StackList.Buffer, StackList.BufferSize, sizeof(UCHAR));
461 }
462 }
464 {
466 }
467 _SEH2_END;
468
470 if (NT_SUCCESS(Status))
471 {
472 /* Get the device object */
474 if (DeviceInstance.Buffer != NULL)
475 {
477 }
478 }
479
482
483 if (!NT_SUCCESS(Status))
484 {
485 /* failed */
486 return Status;
487 }
488
489 LinkList = SymbolicLinkList;
491 {
493 }
494 TotalLength = ((SymbolicLinkList - LinkList + 1) * sizeof(WCHAR));
495
497 {
498 if (StackList.Buffer != NULL &&
499 StackList.BufferSize >= TotalLength)
500 {
501 // We've already probed the buffer for writing above.
502 RtlCopyMemory(StackList.Buffer, LinkList, TotalLength);
503 }
504
505 DeviceList->BufferSize = TotalLength;
506 }
508 {
509 ExFreePool(LinkList);
511 }
512 _SEH2_END;
513
514 ExFreePool(LinkList);
515 return STATUS_SUCCESS;
516}
PDEVICE_LIST DeviceList
Definition: utils.c:27
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
_NullNull_terminated_ WCHAR * PZZWSTR
Definition: ntbasedef.h:432
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:950
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_In_ ULONG TotalLength
Definition: usbdlib.h:185
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList

Referenced by NtPlugPlayControl().

◆ IopGetRelatedDevice()

static NTSTATUS IopGetRelatedDevice ( PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA  RelatedDeviceData)
static

Definition at line 757 of file plugplay.c.

758{
759 UNICODE_STRING RootDeviceName;
762 PDEVICE_NODE RelatedDeviceNode;
763 UNICODE_STRING TargetDeviceInstance;
765 ULONG Relation = 0;
767
768 DPRINT("IopGetRelatedDevice() called\n");
769 DPRINT("Device name: %wZ\n", &RelatedDeviceData->TargetDeviceInstance);
770
771 Status = IopCaptureUnicodeString(&TargetDeviceInstance, &RelatedDeviceData->TargetDeviceInstance);
772 if (!NT_SUCCESS(Status))
773 {
774 return Status;
775 }
776
778 {
779 Relation = RelatedDeviceData->Relation;
780 MaximumLength = RelatedDeviceData->RelatedDeviceInstanceLength;
781 ProbeForWrite(RelatedDeviceData->RelatedDeviceInstance,
783 sizeof(WCHAR));
784 }
786 {
787 if (TargetDeviceInstance.Buffer != NULL)
788 {
789 ExFreePool(TargetDeviceInstance.Buffer);
790 }
792 }
793 _SEH2_END;
794
795 RtlInitUnicodeString(&RootDeviceName,
796 L"HTREE\\ROOT\\0");
797 if (RtlEqualUnicodeString(&TargetDeviceInstance,
798 &RootDeviceName,
799 TRUE))
800 {
802 if (TargetDeviceInstance.Buffer != NULL)
803 {
804 ExFreePool(TargetDeviceInstance.Buffer);
805 }
806 }
807 else
808 {
809 /* Get the device object */
810 DeviceObject = IopGetDeviceObjectFromDeviceInstance(&TargetDeviceInstance);
811 if (TargetDeviceInstance.Buffer != NULL)
812 {
813 ExFreePool(TargetDeviceInstance.Buffer);
814 }
815 if (DeviceObject == NULL)
817
819 }
820
821 switch (Relation)
822 {
824 RelatedDeviceNode = DeviceNode->Parent;
825 break;
826
828 RelatedDeviceNode = DeviceNode->Child;
829 break;
830
832 RelatedDeviceNode = DeviceNode->Sibling;
833 break;
834
835 default:
836 if (DeviceObject != NULL)
837 {
839 }
840
842 }
843
844 if (RelatedDeviceNode == NULL)
845 {
846 if (DeviceObject)
847 {
849 }
850
852 }
853
854 if (RelatedDeviceNode->InstancePath.Length > MaximumLength)
855 {
856 if (DeviceObject)
857 {
859 }
860
862 }
863
864 /* Copy related device instance name */
866 {
867 RtlCopyMemory(RelatedDeviceData->RelatedDeviceInstance,
868 RelatedDeviceNode->InstancePath.Buffer,
869 RelatedDeviceNode->InstancePath.Length);
870 RelatedDeviceData->RelatedDeviceInstanceLength = RelatedDeviceNode->InstancePath.Length;
871 }
873 {
875 }
876 _SEH2_END;
877
878 if (DeviceObject != NULL)
879 {
881 }
882
883 DPRINT("IopGetRelatedDevice() done\n");
884
885 return Status;
886}
#define L(x)
Definition: resources.c:13
#define PNP_GET_SIBLING_DEVICE
Definition: cmtypes.h:54
#define PNP_GET_PARENT_DEVICE
Definition: cmtypes.h:52
#define PNP_GET_CHILD_DEVICE
Definition: cmtypes.h:53
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength

Referenced by NtPlugPlayControl().

◆ IopInitPlugPlayEvents()

NTSTATUS IopInitPlugPlayEvents ( VOID  )

Definition at line 40 of file plugplay.c.

41{
43
46 FALSE);
47
48 return STATUS_SUCCESS;
49}
#define FALSE
Definition: types.h:117
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ SynchronizationEvent
static LIST_ENTRY IopPnpEventQueueHead
Definition: plugplay.c:30
static KEVENT IopPnpNotifyEvent
Definition: plugplay.c:31

Referenced by IopInitializePlugPlayServices().

◆ IopQueueDeviceChangeEvent()

NTSTATUS IopQueueDeviceChangeEvent ( _In_ const GUID *  EventGuid,
_In_ const GUID *  InterfaceClassGuid,
_In_ PUNICODE_STRING  SymbolicLinkName 
)

Definition at line 52 of file plugplay.c.

56{
57 PPNP_EVENT_ENTRY EventEntry;
59 ULONG TotalSize;
60
61 /* Allocate a big enough buffer */
62 Copy.Length = 0;
63 Copy.MaximumLength = SymbolicLinkName->Length + sizeof(UNICODE_NULL);
64 TotalSize =
66 Copy.MaximumLength;
67
68 EventEntry = ExAllocatePool(NonPagedPool,
69 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
70 if (!EventEntry)
72 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
73
74 /* Fill the buffer with the event GUID */
75 RtlCopyMemory(&EventEntry->Event.EventGuid, EventGuid, sizeof(GUID));
77 EventEntry->Event.TotalSize = TotalSize;
78
79 /* Fill the interface class GUID */
80 RtlCopyMemory(&EventEntry->Event.DeviceClass.ClassGuid, InterfaceClassGuid, sizeof(GUID));
81
82 /* Fill the symbolic link name */
83 RtlCopyMemory(&EventEntry->Event.DeviceClass.SymbolicLinkName,
84 SymbolicLinkName->Buffer, SymbolicLinkName->Length);
85 EventEntry->Event.DeviceClass.SymbolicLinkName[SymbolicLinkName->Length / sizeof(WCHAR)] = UNICODE_NULL;
86
88 &EventEntry->ListEntry);
90 0,
91 FALSE);
92
93 return STATUS_SUCCESS;
94}
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG Event
Definition: dispmprt.h:1287
VOID Copy(PVOID Src, PVOID Dst, ULONG NumBytes)
Definition: mmixer.c:126
#define InsertHeadList(ListHead, Entry)
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
_Must_inspect_result_ _In_ WDFDEVICE _In_ REFGUID EventGuid
_In_ PUNICODE_STRING SymbolicLinkName
Definition: hubucx.h:491
@ DeviceClassChangeEvent
Definition: cmtypes.h:272
WCHAR SymbolicLinkName[ANYSIZE_ARRAY]
Definition: cmtypes.h:441
struct _PLUGPLAY_EVENT_BLOCK::@2851::@2853 DeviceClass
PLUGPLAY_EVENT_CATEGORY EventCategory
Definition: cmtypes.h:431
Definition: plugplay.c:16
LIST_ENTRY ListEntry
Definition: plugplay.c:17
PLUGPLAY_EVENT_BLOCK Event
Definition: plugplay.c:18
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_In_ CONST GUID * InterfaceClassGuid
Definition: iofuncs.h:1136

Referenced by IoSetDeviceInterfaceState().

◆ IopQueueDeviceInstallEvent()

NTSTATUS IopQueueDeviceInstallEvent ( _In_ const GUID *  EventGuid,
_In_ PUNICODE_STRING  DeviceId 
)

Definition at line 97 of file plugplay.c.

100{
101 PPNP_EVENT_ENTRY EventEntry;
103 ULONG TotalSize;
104
105 /* Allocate a big enough buffer */
106 Copy.Length = 0;
107 Copy.MaximumLength = DeviceId->Length + sizeof(UNICODE_NULL);
108 TotalSize =
110 Copy.MaximumLength;
111
112 EventEntry = ExAllocatePool(NonPagedPool,
113 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
114 if (!EventEntry)
116 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
117
118 /* Fill the buffer with the event GUID */
119 RtlCopyMemory(&EventEntry->Event.EventGuid, EventGuid, sizeof(GUID));
121 EventEntry->Event.TotalSize = TotalSize;
122
123 /* Fill the symbolic link name */
124 RtlCopyMemory(&EventEntry->Event.InstallDevice.DeviceId,
125 DeviceId->Buffer, DeviceId->Length);
126 EventEntry->Event.InstallDevice.DeviceId[DeviceId->Length / sizeof(WCHAR)] = UNICODE_NULL;
127
129
131
132 return STATUS_SUCCESS;
133}
static BOOL InstallDevice(PCWSTR DeviceInstance, BOOL ShowWizard)
Definition: install.c:55
@ DeviceInstallEvent
Definition: cmtypes.h:274
struct _PLUGPLAY_EVENT_BLOCK::@2851::@2855 InstallDevice

Referenced by PiControlInitializeDevice(), and PiInitializeDevNode().

◆ IopQueueDevicePropertyChangeEvent()

NTSTATUS IopQueueDevicePropertyChangeEvent ( _In_ PCUNICODE_STRING  DeviceId)

Definition at line 136 of file plugplay.c.

138{
139 PPNP_EVENT_ENTRY EventEntry;
140 ULONG TotalSize, EntrySize;
141
142 TotalSize = FIELD_OFFSET(PLUGPLAY_EVENT_BLOCK, TargetDevice.DeviceIds) +
143 DeviceId->Length + sizeof(UNICODE_NULL);
145
147 if (!EventEntry)
149
150 EventEntry->Event.EventGuid = GUID_PNP_PROPERTY_UPDATE;
152 EventEntry->Event.TotalSize = TotalSize;
153
154 RtlCopyMemory(EventEntry->Event.TargetDevice.DeviceIds,
155 DeviceId->Buffer, DeviceId->Length);
156
159
160 return STATUS_SUCCESS;
161}
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
@ DevicePropertyChangeEvent
Definition: cmtypes.h:285
struct _PLUGPLAY_EVENT_BLOCK::@2851::@2854 TargetDevice
#define TAG_IO
Definition: tag.h:79
_Must_inspect_result_ __drv_aliasesMem PDEVICE_OBJECT _In_ PDEVICE_OBJECT TargetDevice
Definition: iofuncs.h:691
_In_ UCHAR EntrySize
Definition: iofuncs.h:642

Referenced by PiPropSet().

◆ IopQueueTargetDeviceEvent()

NTSTATUS IopQueueTargetDeviceEvent ( const GUID *  Guid,
PUNICODE_STRING  DeviceIds 
)

Definition at line 165 of file plugplay.c.

167{
168 PPNP_EVENT_ENTRY EventEntry;
170 ULONG TotalSize;
172
173 ASSERT(DeviceIds);
174
175 /* Allocate a big enough buffer */
176 Copy.Length = 0;
177 Copy.MaximumLength = DeviceIds->Length + sizeof(UNICODE_NULL);
178 TotalSize =
180 Copy.MaximumLength;
181
182 EventEntry = ExAllocatePool(NonPagedPool,
183 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
184 if (!EventEntry)
186 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
187
188 /* Fill the buffer with the event GUID */
189 RtlCopyMemory(&EventEntry->Event.EventGuid,
190 Guid,
191 sizeof(GUID));
193 EventEntry->Event.TotalSize = TotalSize;
194
195 /* Fill the device id */
196 Copy.Buffer = EventEntry->Event.TargetDevice.DeviceIds;
198 if (!NT_SUCCESS(Status))
199 {
200 ExFreePool(EventEntry);
201 return Status;
202 }
203
205 &EventEntry->ListEntry);
207 0,
208 FALSE);
209
210 return STATUS_SUCCESS;
211}
#define ASSERT(a)
Definition: mode.c:44
@ TargetDeviceChangeEvent
Definition: cmtypes.h:271
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762

◆ IopRemovePlugPlayEvent()

static NTSTATUS IopRemovePlugPlayEvent ( _In_ PPLUGPLAY_CONTROL_USER_RESPONSE_DATA  ResponseData)
static

Definition at line 419 of file plugplay.c.

421{
422 /* Remove a pnp event entry from the tail of the queue */
424 {
426 }
427
428 /* Signal the next pnp event in the queue */
430 {
432 0,
433 FALSE);
434 }
435
436 return STATUS_SUCCESS;
437}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveTailList(ListHead)
Definition: env_spec_w32.h:975
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by NtPlugPlayControl().

◆ IopSetDeviceInstanceData()

NTSTATUS IopSetDeviceInstanceData ( HANDLE  InstanceKey,
PDEVICE_NODE  DeviceNode 
)

Definition at line 606 of file pnpmgr.c.

608{
611 HANDLE LogConfKey, ControlKey, DeviceParamsKey;
612 ULONG ResCount;
615
616 DPRINT("IopSetDeviceInstanceData() called\n");
617
618 /* Create the 'LogConf' key */
619 RtlInitUnicodeString(&KeyName, L"LogConf");
621 &KeyName,
623 InstanceKey,
624 NULL);
625 Status = ZwCreateKey(&LogConfKey,
628 0,
629 NULL,
630 // FIXME? In r53694 it was silently turned from non-volatile into this,
631 // without any extra warning. Is this still needed??
633 NULL);
634 if (NT_SUCCESS(Status))
635 {
636 /* Set 'BootConfig' value */
637 if (DeviceNode->BootResources != NULL)
638 {
639 ResCount = DeviceNode->BootResources->Count;
640 if (ResCount != 0)
641 {
642 RtlInitUnicodeString(&KeyName, L"BootConfig");
643 Status = ZwSetValueKey(LogConfKey,
644 &KeyName,
645 0,
647 DeviceNode->BootResources,
649 }
650 }
651
652 /* Set 'BasicConfigVector' value */
653 if (DeviceNode->ResourceRequirements != NULL &&
654 DeviceNode->ResourceRequirements->ListSize != 0)
655 {
656 RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
657 Status = ZwSetValueKey(LogConfKey,
658 &KeyName,
659 0,
661 DeviceNode->ResourceRequirements,
662 DeviceNode->ResourceRequirements->ListSize);
663 }
664
665 ZwClose(LogConfKey);
666 }
667
668 /* Set the 'ConfigFlags' value */
669 RtlInitUnicodeString(&KeyName, L"ConfigFlags");
670 Status = ZwQueryValueKey(InstanceKey,
671 &KeyName,
673 NULL,
674 0,
675 &ResultLength);
677 {
678 /* Write the default value */
679 ULONG DefaultConfigFlags = 0;
680 Status = ZwSetValueKey(InstanceKey,
681 &KeyName,
682 0,
683 REG_DWORD,
684 &DefaultConfigFlags,
685 sizeof(DefaultConfigFlags));
686 }
687
688 /* Create the 'Control' key */
689 RtlInitUnicodeString(&KeyName, L"Control");
691 &KeyName,
693 InstanceKey,
694 NULL);
695 Status = ZwCreateKey(&ControlKey,
696 0,
698 0,
699 NULL,
701 NULL);
702 if (NT_SUCCESS(Status))
703 ZwClose(ControlKey);
704
705 /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
706 if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
707 {
708 RtlInitUnicodeString(&KeyName, L"Device Parameters");
710 &KeyName,
712 InstanceKey,
713 NULL);
714 Status = ZwCreateKey(&DeviceParamsKey,
715 0,
717 0,
718 NULL,
720 NULL);
721 if (NT_SUCCESS(Status))
722 {
723 ULONG FirmwareIdentified = 1;
724 RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
725 Status = ZwSetValueKey(DeviceParamsKey,
726 &KeyName,
727 0,
728 REG_DWORD,
729 &FirmwareIdentified,
730 sizeof(FirmwareIdentified));
731
732 ZwClose(DeviceParamsKey);
733 }
734 }
735
736 DPRINT("IopSetDeviceInstanceData() done\n");
737
738 return Status;
739}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:200
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValueBasicInformation
Definition: nt_native.h:1183
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
#define REG_RESOURCE_LIST
Definition: nt_native.h:1505
#define REG_RESOURCE_REQUIREMENTS_LIST
Definition: nt_native.h:1507
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1237
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define REG_DWORD
Definition: sdbapi.c:615
_In_ PGUID _In_ ULONG _Out_ PULONG ResultLength
Definition: ucxcontroller.h:83
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705

Referenced by PiControlInitializeDevice().

◆ NtGetPlugPlayEvent()

NTSTATUS NTAPI NtGetPlugPlayEvent ( IN ULONG  Reserved1,
IN ULONG  Reserved2,
OUT PPLUGPLAY_EVENT_BLOCK  Buffer,
IN ULONG  BufferSize 
)

Definition at line 1472 of file plugplay.c.

1476{
1479
1480 DPRINT("NtGetPlugPlayEvent() called\n");
1481
1482 /* Function can only be called from user-mode */
1484 {
1485 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
1486 return STATUS_ACCESS_DENIED;
1487 }
1488
1489 /* Check for Tcb privilege */
1491 UserMode))
1492 {
1493 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
1495 }
1496
1497 /* Wait for a PnP event */
1498 DPRINT("Waiting for pnp notification event\n");
1501 UserMode,
1502 FALSE,
1503 NULL);
1505 {
1506 DPRINT("KeWaitForSingleObject() failed (Status %lx)\n", Status);
1508 return Status;
1509 }
1510
1511 /* Get entry from the tail of the queue */
1514 ListEntry);
1515
1516 /* Check the buffer size */
1517 if (BufferSize < Entry->Event.TotalSize)
1518 {
1519 DPRINT1("Buffer is too small for the pnp-event\n");
1521 }
1522
1523 /* Copy event data to the user buffer */
1524 _SEH2_TRY
1525 {
1527 Entry->Event.TotalSize,
1528 sizeof(UCHAR));
1530 &Entry->Event,
1531 Entry->Event.TotalSize);
1532 }
1534 {
1536 }
1537 _SEH2_END;
1538
1539 DPRINT("NtGetPlugPlayEvent() done\n");
1540
1541 return STATUS_SUCCESS;
1542}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeGetPreviousMode()
Definition: ketypes.h:1115
#define KernelMode
Definition: asm.h:38
#define UserMode
Definition: asm.h:39
const LUID SeTcbPrivilege
Definition: priv.c:26
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:744
#define STATUS_USER_APC
Definition: ntstatus.h:130
Entry
Definition: section.c:5216
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
@ UserRequest
Definition: ketypes.h:473

Referenced by PnpEventThread().

◆ NtPlugPlayControl()

NTSTATUS NTAPI NtPlugPlayControl ( IN PLUGPLAY_CONTROL_CLASS  PlugPlayControlClass,
IN OUT PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 1602 of file plugplay.c.

1605{
1606 DPRINT("NtPlugPlayControl(%d %p %lu) called\n",
1607 PlugPlayControlClass, Buffer, BufferLength);
1608
1609 /* Function can only be called from user-mode */
1611 {
1612 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
1613 return STATUS_ACCESS_DENIED;
1614 }
1615
1616 /* Check for Tcb privilege */
1618 UserMode))
1619 {
1620 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
1622 }
1623
1624 /* Probe the buffer */
1625 _SEH2_TRY
1626 {
1629 sizeof(ULONG));
1630 }
1632 {
1634 }
1635 _SEH2_END;
1636
1637 switch (PlugPlayControlClass)
1638 {
1642 // the Flags field is not used anyway
1644 PlugPlayControlClass);
1645
1646// case PlugPlayControlRegisterNewDevice:
1647// case PlugPlayControlDeregisterDevice:
1648
1653
1659 PlugPlayControlClass);
1660
1663
1668
1673
1674// case PlugPlayControlGenerateLegacyDevice:
1675
1680
1685
1690
1695
1700
1705
1710
1715
1716// case PlugPlayControlTargetDeviceRelation:
1717// case PlugPlayControlQueryConflictList:
1718// case PlugPlayControlRetrieveDock:
1719// case PlugPlayControlHaltDevice:
1720// case PlugPlayControlGetBlockedDriverList:
1721
1722 default:
1724 }
1725
1727}
@ PlugPlayControlEnumerateDevice
Definition: cmtypes.h:223
@ PlugPlayControlUnlockDevice
Definition: cmtypes.h:228
@ PlugPlayControlUserResponse
Definition: cmtypes.h:230
@ PlugPlayControlProperty
Definition: cmtypes.h:233
@ PlugPlayControlQueryDeviceRelations
Definition: cmtypes.h:239
@ PlugPlayControlGetRelatedDevice
Definition: cmtypes.h:235
@ PlugPlayControlDeviceStatus
Definition: cmtypes.h:237
@ PlugPlayControlQueryAndRemoveDevice
Definition: cmtypes.h:229
@ PlugPlayControlGetDeviceDepth
Definition: cmtypes.h:238
@ PlugPlayControlDeviceClassAssociation
Definition: cmtypes.h:234
@ PlugPlayControlInitializeDevice
Definition: cmtypes.h:226
@ PlugPlayControlGetInterfaceDeviceList
Definition: cmtypes.h:232
@ PlugPlayControlStartDevice
Definition: cmtypes.h:227
@ PlugPlayControlGetInterfaceDeviceAlias
Definition: cmtypes.h:236
@ PlugPlayControlResetDevice
Definition: cmtypes.h:243
static NTSTATUS PiControlDeviceClassAssociation(_In_ PPLUGPLAY_CONTROL_CLASS_ASSOCIATION_DATA ControlData)
Definition: plugplay.c:1353
static NTSTATUS IopGetRelatedDevice(PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA RelatedDeviceData)
Definition: plugplay.c:757
static NTSTATUS PiControlQueryRemoveDevice(_In_ PPLUGPLAY_CONTROL_QUERY_REMOVE_DATA ControlData)
Definition: plugplay.c:1299
static NTSTATUS IopRemovePlugPlayEvent(_In_ PPLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData)
Definition: plugplay.c:419
static NTSTATUS IopDeviceStatus(PPLUGPLAY_CONTROL_STATUS_DATA StatusData)
Definition: plugplay.c:951
static NTSTATUS IopGetInterfaceDeviceList(PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA DeviceList)
Definition: plugplay.c:441
static NTSTATUS IopGetDeviceDepth(PPLUGPLAY_CONTROL_DEPTH_DATA DepthData)
Definition: plugplay.c:1198
static NTSTATUS PiControlSyncDeviceAction(_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA DeviceData, _In_ PLUGPLAY_CONTROL_CLASS ControlClass)
Definition: plugplay.c:1244
static NTSTATUS IopGetDeviceRelations(PPLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA RelationsData)
Definition: plugplay.c:1041
static NTSTATUS IopGetDeviceProperty(PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData)
Definition: plugplay.c:519
static NTSTATUS PiControlGetInterfaceDeviceAlias(_In_ PPLUGPLAY_CONTROL_INTERFACE_ALIAS_DATA ControlData)
Definition: plugplay.c:1332
static NTSTATUS PiControlInitializeDevice(_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA ControlData)
Definition: plugplay.c:317
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777

Referenced by AreDriversLoaded(), ClearDeviceStatus(), DisableDeviceInstance(), EnableDeviceInstance(), GetDeviceStatus(), GetRelationsInstanceList(), GetRelationsInstanceListSize(), InstallDriver(), PNP_CreateDevInst(), PNP_GetDepth(), PNP_GetDeviceRegProp(), PNP_GetInterfaceDeviceAlias(), PNP_GetInterfaceDeviceList(), PNP_GetInterfaceDeviceListSize(), PNP_GetRelatedDeviceInstance(), PNP_QueryRemove(), PNP_RegisterDeviceClassAssociation(), PNP_RequestDeviceEject(), PNP_RequestEjectPC(), PNP_UnregisterDeviceClassAssociation(), PnpEventThread(), ReenumerateDeviceInstance(), SetDeviceStatus(), and SetupDeviceInstance().

◆ PiControlDeviceClassAssociation()

static NTSTATUS PiControlDeviceClassAssociation ( _In_ PPLUGPLAY_CONTROL_CLASS_ASSOCIATION_DATA  ControlData)
static

Definition at line 1353 of file plugplay.c.

1355{
1359
1360 DPRINT("PiControlDeviceClassAssociation()\n");
1361 DPRINT("DeviceInstance: %wZ\n", &ControlData->DeviceInstance);
1362
1363 if (ControlData->Register)
1364 {
1365 if ((ControlData->DeviceInstance.Buffer == NULL) ||
1366 (ControlData->DeviceInstance.Length == 0))
1368
1369 if (ControlData->InterfaceGuid == NULL)
1371
1372 DeviceObject = IopGetDeviceObjectFromDeviceInstance(&ControlData->DeviceInstance);
1373 if (DeviceObject == NULL)
1374 return STATUS_NO_SUCH_DEVICE;
1375
1377 ControlData->InterfaceGuid,
1378 &ControlData->Reference,
1379 &SymbolicLink);
1380 if (NT_SUCCESS(Status))
1381 {
1382 if (SymbolicLink.Length + sizeof(WCHAR) <= ControlData->SymbolicLinkNameLength)
1383 {
1384 RtlCopyMemory(ControlData->SymbolicLinkName, SymbolicLink.Buffer, SymbolicLink.Length);
1385 ControlData->SymbolicLinkName[SymbolicLink.Length / sizeof(WCHAR)] = UNICODE_NULL;
1386 ControlData->SymbolicLinkNameLength = SymbolicLink.Length + sizeof(WCHAR);
1387 }
1388 else
1389 {
1390 ControlData->SymbolicLinkNameLength = SymbolicLink.Length + sizeof(WCHAR);
1392 }
1393
1394 ExFreePool(SymbolicLink.Buffer);
1395 }
1396
1398 }
1399 else
1400 {
1403 }
1404
1405 return Status;
1406}
static const WCHAR SymbolicLink[]
Definition: interface.c:31
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:1451

Referenced by NtPlugPlayControl().

◆ PiControlGetInterfaceDeviceAlias()

static NTSTATUS PiControlGetInterfaceDeviceAlias ( _In_ PPLUGPLAY_CONTROL_INTERFACE_ALIAS_DATA  ControlData)
static

Definition at line 1332 of file plugplay.c.

1334{
1335 UNICODE_STRING AliasSymbolicLinkName;
1336
1337 DPRINT("PiControlGetInterfaceDeviceAlias()\n");
1338 DPRINT("SymbolicLinkName: %wZ\n", &ControlData->SymbolicLinkName);
1339 DPRINT("AliasInterfaceClassGuid: %p\n", ControlData->AliasInterfaceClassGuid);
1340 DPRINT("AliasSymbolicLinkName: %p\n", ControlData->AliasSymbolicLinkName);
1341 DPRINT("AliasSymbolicLinkNameLength: %lu\n", ControlData->AliasSymbolicLinkNameLength);
1342
1343 AliasSymbolicLinkName.Length = 0;
1344 AliasSymbolicLinkName.MaximumLength = ControlData->AliasSymbolicLinkNameLength;
1345 AliasSymbolicLinkName.Buffer = ControlData->AliasSymbolicLinkName;
1346 return IoGetDeviceInterfaceAlias(&ControlData->SymbolicLinkName,
1347 ControlData->AliasInterfaceClassGuid,
1348 &AliasSymbolicLinkName);
1349}
NTSTATUS NTAPI IoGetDeviceInterfaceAlias(_In_ PUNICODE_STRING SymbolicLinkName, _In_ CONST GUID *AliasInterfaceClassGuid, _Out_ PUNICODE_STRING AliasSymbolicLinkName)
Returns the alias device interface of the specified device interface instance, if the alias exists.
Definition: deviface.c:772

Referenced by NtPlugPlayControl().

◆ PiControlInitializeDevice()

static NTSTATUS PiControlInitializeDevice ( _In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA  ControlData)
static

Definition at line 317 of file plugplay.c.

319{
324 HANDLE InstanceKey;
325
326 DPRINT("PiControlInitializeDevice(%p)\n", ControlData);
327
328 Status = IopCaptureUnicodeString(&DeviceInstance, &ControlData->DeviceInstance);
329 if (!NT_SUCCESS(Status))
330 {
331 return Status;
332 }
333
334 DPRINT("Device: %wZ\n", &DeviceInstance);
335
336 /* Leave, if the device already exists */
338 if (DeviceObject != NULL)
339 {
340 DPRINT1("Device %wZ already exists!\n", &DeviceInstance);
343 goto done;
344 }
345
346 DPRINT("Device %wZ does not exist!\n", &DeviceInstance);
347
348 /* Create a device node for the device instance */
350 if (!NT_SUCCESS(Status))
351 {
352 DPRINT1("IoCreateDevice() failed (Status 0x%08lx)\n", Status);
353 goto done;
354 }
355
356 /* Allocate a new device node */
358 if (DeviceNode == NULL)
359 {
360 DPRINT1("Failed to allocate a device node!\n");
363 goto done;
364 }
365
366 // Set the device instance of the device node
367 // NOTE: a NULL-terminated string is required for PnpRootRegisterDevice
371 &DeviceNode->InstancePath);
372 if (!NT_SUCCESS(Status))
373 {
374 DPRINT1("RtlDuplicateUnicodeString() failed (Status 0x%08lx)\n", Status);
377 goto done;
378 }
379
383
385 if (!NT_SUCCESS(Status))
386 {
387 DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
390 goto done;
391 }
392
393 /* Write the resource information to the registry */
395
396 // Finish the root device registration
398
399 /* Insert as a root enumerated device node */
401
402 /* Report the device to the user-mode pnp manager */
403 IopQueueDeviceInstallEvent(&GUID_DEVICE_ENUMERATED, &DeviceNode->InstancePath);
404
405 ZwClose(InstanceKey);
406done:
408
409 return Status;
410}
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
#define DNF_ENUMERATED
Definition: iotypes.h:179
@ DeviceNodeInitialized
Definition: iotypes.h:541
#define DNF_IDS_QUERIED
Definition: iotypes.h:180
#define DNF_MADEUP
Definition: iotypes.h:175
VOID PiInsertDevNode(_In_ PDEVICE_NODE DeviceNode, _In_ PDEVICE_NODE ParentNode)
Definition: devnode.c:80
PDEVICE_NODE PipAllocateDeviceNode(IN PDEVICE_OBJECT PhysicalDeviceObject)
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:522
NTSTATUS PnpRootRegisterDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnproot.c:107
NTSTATUS IopFreeDeviceNode(IN PDEVICE_NODE DeviceNode)
PNP_DEVNODE_STATE PiSetDevNodeState(_In_ PDEVICE_NODE DeviceNode, _In_ PNP_DEVNODE_STATE NewState)
Definition: devnode.c:108
NTSTATUS PnpRootCreateDeviceObject(OUT PDEVICE_OBJECT *DeviceObject)
Definition: pnproot.c:167
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1261
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:606
NTSTATUS IopQueueDeviceInstallEvent(_In_ const GUID *EventGuid, _In_ PUNICODE_STRING DeviceId)
Definition: plugplay.c:97
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
#define DO_BUS_ENUMERATED_DEVICE

Referenced by NtPlugPlayControl().

◆ PiControlQueryRemoveDevice()

static NTSTATUS PiControlQueryRemoveDevice ( _In_ PPLUGPLAY_CONTROL_QUERY_REMOVE_DATA  ControlData)
static

Definition at line 1299 of file plugplay.c.

1301{
1305
1306 Status = IopCaptureUnicodeString(&DeviceInstance, &ControlData->DeviceInstance);
1307 if (!NT_SUCCESS(Status))
1308 {
1309 return Status;
1310 }
1311
1313 if (DeviceInstance.Buffer != NULL)
1314 {
1315 ExFreePool(DeviceInstance.Buffer);
1316 }
1317 if (DeviceObject == NULL)
1318 {
1319 return STATUS_NO_SUCH_DEVICE;
1320 }
1321
1324
1326
1327 return Status;
1328}

Referenced by NtPlugPlayControl().

◆ PiControlSyncDeviceAction()

static NTSTATUS PiControlSyncDeviceAction ( _In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA  DeviceData,
_In_ PLUGPLAY_CONTROL_CLASS  ControlClass 
)
static

Definition at line 1244 of file plugplay.c.

1247{
1251
1255
1257 if (!NT_SUCCESS(Status))
1258 {
1259 return Status;
1260 }
1261
1263 if (DeviceInstance.Buffer != NULL)
1264 {
1265 ExFreePool(DeviceInstance.Buffer);
1266 }
1267 if (DeviceObject == NULL)
1268 {
1269 return STATUS_NO_SUCH_DEVICE;
1270 }
1271
1273
1274 switch (ControlClass)
1275 {
1278 break;
1281 break;
1284 break;
1285 default:
1287 break;
1288 }
1289
1291
1293
1294 return Status;
1295}
static const WCHAR ControlClass[]
Definition: cfgmgr.c:38
#define UNREACHABLE
@ PiActionResetDevice
Definition: io.h:527
@ PiActionStartDevice
Definition: io.h:529
@ PiActionEnumDeviceTree
Definition: io.h:525
enum _DEVICE_ACTION DEVICE_ACTION
NTSTATUS PiPerformSyncDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action)
Perfom a device operation synchronously via PiQueueDeviceAction.
Definition: devaction.c:2727
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510

Referenced by NtPlugPlayControl().

◆ PiIsDevNodeStarted()

static BOOLEAN PiIsDevNodeStarted ( _In_ PDEVICE_NODE  DeviceNode)
static

Definition at line 890 of file plugplay.c.

892{
893 return (DeviceNode->State == DeviceNodeStartPending ||
896 DeviceNode->State == DeviceNodeStarted ||
900 DeviceNode->State == DeviceNodeStopped ||
902}
@ DeviceNodeStopped
Definition: iotypes.h:549
@ DeviceNodeRestartCompletion
Definition: iotypes.h:550
@ DeviceNodeStartPostWork
Definition: iotypes.h:546
@ DeviceNodeStarted
Definition: iotypes.h:547
@ DeviceNodeStartCompletion
Definition: iotypes.h:545
@ DeviceNodeEnumerateCompletion
Definition: iotypes.h:552
@ DeviceNodeEnumeratePending
Definition: iotypes.h:551
@ DeviceNodeQueryStopped
Definition: iotypes.h:548
@ DeviceNodeStartPending
Definition: iotypes.h:544

Referenced by IopGetDeviceNodeStatus().

Variable Documentation

◆ IopPnpEventQueueHead

◆ IopPnpNotifyEvent