ReactOS 0.4.15-dev-6679-g945ee4b
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_ENTRYPPNP_EVENT_ENTRY
 
typedef struct _IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT
 
typedef struct _IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXTPIOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT
 

Functions

NTSTATUS IopSetDeviceInstanceData (HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
 
NTSTATUS IopInitPlugPlayEvents (VOID)
 
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)
 
static ULONG IopGetDeviceNodeStatus (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)
 
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 155 of file plugplay.c.

156{
158 volatile UNICODE_STRING Name;
159
160 Name.Buffer = NULL;
162 {
163 Name.Length = SrcName->Length;
164 Name.MaximumLength = SrcName->MaximumLength;
165 if (Name.Length > Name.MaximumLength)
166 {
169 }
170
171 if (Name.MaximumLength)
172 {
173 ProbeForRead(SrcName->Buffer,
174 Name.MaximumLength,
175 sizeof(WCHAR));
176 Name.Buffer = ExAllocatePool(NonPagedPool, Name.MaximumLength);
177 if (Name.Buffer == NULL)
178 {
181 }
182
183 memcpy(Name.Buffer, SrcName->Buffer, Name.MaximumLength);
184 }
185
186 *DstName = Name;
187 }
189 {
190 if (Name.Buffer)
191 {
192 ExFreePool(Name.Buffer);
193 }
195 }
196 _SEH2_END;
197
198 return Status;
199}
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
#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
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define _SEH2_LEAVE
Definition: filesup.c:20
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#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
__wchar_t WCHAR
Definition: xmlstorage.h:180

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 836 of file plugplay.c.

837{
840 ULONG Operation = 0;
841 ULONG DeviceStatus = 0;
842 ULONG DeviceProblem = 0;
845
846 DPRINT("IopDeviceStatus() called\n");
847
849 if (!NT_SUCCESS(Status))
850 {
851 return Status;
852 }
853
854 DPRINT("Device name: '%wZ'\n", &DeviceInstance);
855
857 {
858 Operation = StatusData->Operation;
860 {
861 DeviceStatus = StatusData->DeviceStatus;
862 DeviceProblem = StatusData->DeviceProblem;
863 }
864 }
866 {
867 if (DeviceInstance.Buffer != NULL)
868 {
870 }
872 }
873 _SEH2_END;
874
875 /* Get the device object */
877 if (DeviceInstance.Buffer != NULL)
878 {
880 }
881 if (DeviceObject == NULL)
882 {
884 }
885
887
888 switch (Operation)
889 {
891 DPRINT("Get status data\n");
892 DeviceStatus = IopGetDeviceNodeStatus(DeviceNode);
893 DeviceProblem = DeviceNode->Problem;
894 break;
895
897 DPRINT1("Set status data is NOT SUPPORTED\n");
898 break;
899
901 DPRINT1("FIXME: Clear status data!\n");
902 break;
903 }
904
906
908 {
910 {
911 StatusData->DeviceStatus = DeviceStatus;
912 StatusData->DeviceProblem = DeviceProblem;
913 }
915 {
917 }
918 _SEH2_END;
919 }
920
921 return Status;
922}
@ DeviceNode
Definition: Node.h:9
#define DPRINT1
Definition: precomp.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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)
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:121
static NTSTATUS IopCaptureUnicodeString(PUNICODE_STRING DstName, PUNICODE_STRING SrcName)
Definition: plugplay.c:155
static ULONG IopGetDeviceNodeStatus(PDEVICE_NODE DeviceNode)
Definition: plugplay.c:791
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
#define DPRINT
Definition: sndvol32.h:71
UNICODE_STRING DeviceInstance
Definition: cmtypes.h:525
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by NtPlugPlayControl().

◆ IopFindDeviceInstanceTraverse()

NTSTATUS IopFindDeviceInstanceTraverse ( _In_ PDEVICE_NODE  DeviceNode,
_Inout_ PVOID  Context 
)

Definition at line 101 of file plugplay.c.

104{
106
107 if (RtlEqualUnicodeString(&DeviceNode->InstancePath,
108 DeviceInstanceContext->InstancePath, TRUE))
109 {
110 ObReferenceObject(DeviceNode->PhysicalDeviceObject);
111 DeviceInstanceContext->DeviceObject = DeviceNode->PhysicalDeviceObject;
112
113 /* Stop enumeration */
114 return STATUS_UNSUCCESSFUL;
115 }
116
117 return STATUS_SUCCESS;
118}
#define TRUE
Definition: types.h:120
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 1083 of file plugplay.c.

1084{
1089
1090 DPRINT("IopGetDeviceDepth() called\n");
1091 DPRINT("Device name: %wZ\n", &DepthData->DeviceInstance);
1092
1094 if (!NT_SUCCESS(Status))
1095 {
1096 return Status;
1097 }
1098
1099 /* Get the device object */
1101 if (DeviceInstance.Buffer != NULL)
1102 {
1103 ExFreePool(DeviceInstance.Buffer);
1104 }
1105 if (DeviceObject == NULL)
1106 {
1107 return STATUS_NO_SUCH_DEVICE;
1108 }
1109
1111
1112 _SEH2_TRY
1113 {
1114 DepthData->Depth = DeviceNode->Level;
1115 }
1117 {
1119 }
1120 _SEH2_END;
1121
1123
1124 return Status;
1125}
UNICODE_STRING DeviceInstance
Definition: cmtypes.h:534

Referenced by NtPlugPlayControl().

◆ IopGetDeviceNodeStatus()

static ULONG IopGetDeviceNodeStatus ( PDEVICE_NODE  DeviceNode)
static

Definition at line 791 of file plugplay.c.

792{
794
795 if (DeviceNode->Parent == IopRootDeviceNode)
797
798 // FIXME: review for deleted and removed states
801
804
805 if (DeviceNode->UserFlags & DNUF_WILL_BE_REMOVED)
807
808 if (DeviceNode->Flags & DNF_HAS_PROBLEM)
810
813
814 if (DeviceNode->Flags & DNF_DRIVER_BLOCKED)
816
819
822
823 if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
825
826 if (DeviceNode->UserFlags & DNUF_DONT_SHOW_IN_UI)
828
829 if (!(DeviceNode->UserFlags & DNUF_NOT_DISABLEABLE))
831
832 return Output;
833}
#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:208
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:182
@ DeviceNodeDriversAdded
Definition: iotypes.h:387
#define DNUF_NOT_DISABLEABLE
Definition: iotypes.h:211
#define DNF_HAS_PRIVATE_PROBLEM
Definition: iotypes.h:184
#define DNUF_DONT_SHOW_IN_UI
Definition: iotypes.h:209
#define DNF_CHILD_WITH_INVALID_ID
Definition: iotypes.h:191
#define DNF_DRIVER_BLOCKED
Definition: iotypes.h:190
#define DNF_HAS_PROBLEM
Definition: iotypes.h:183
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
static BOOLEAN PiIsDevNodeStarted(_In_ PDEVICE_NODE DeviceNode)
Definition: plugplay.c:776
@ Output
Definition: arc.h:85

Referenced by IopDeviceStatus().

◆ IopGetDeviceObjectFromDeviceInstance()

PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance ( PUNICODE_STRING  DeviceInstance)

Definition at line 121 of file plugplay.c.

122{
124 IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT DeviceInstanceContext;
125
126 if (IopRootDeviceNode == NULL)
127 return NULL;
128
129 if (DeviceInstance == NULL ||
130 DeviceInstance->Length == 0)
131 {
133 {
136 }
137 else
138 return NULL;
139 }
140
141 /* Traverse the device tree to find the matching device node */
142 DeviceInstanceContext.InstancePath = DeviceInstance;
143 DeviceInstanceContext.DeviceObject = NULL;
147 &DeviceInstanceContext);
149
150 /* In case of error or instance not found, this will still be NULL from above. */
151 return DeviceInstanceContext.DeviceObject;
152}
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:229
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
NTSTATUS IopFindDeviceInstanceTraverse(_In_ PDEVICE_NODE DeviceNode, _Inout_ PVOID Context)
Definition: plugplay.c:101
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:855

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

◆ IopGetDeviceProperty()

static NTSTATUS IopGetDeviceProperty ( PPLUGPLAY_CONTROL_PROPERTY_DATA  PropertyData)
static

Definition at line 405 of file plugplay.c.

406{
415
416 DPRINT("IopGetDeviceProperty() called\n");
417 DPRINT("Device name: %wZ\n", &PropertyData->DeviceInstance);
418
420 if (!NT_SUCCESS(Status))
421 {
422 return Status;
423 }
424
426 {
427 Property = PropertyData->Property;
428 BufferSize = PropertyData->BufferSize;
431 sizeof(UCHAR));
432 }
434 {
435 if (DeviceInstance.Buffer != NULL)
436 {
438 }
440 }
441 _SEH2_END;
442
443 /* Get the device object */
445 if (DeviceInstance.Buffer != NULL)
446 {
448 }
449 if (DeviceObject == NULL)
450 {
452 }
453
455 if (Buffer == NULL)
456 {
459 }
460
461
462 DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode;
463
465 {
466 if (BufferSize < sizeof(CM_POWER_DATA))
467 {
468 BufferSize = 0;
470 }
471 else
472 {
474 PCM_POWER_DATA PowerData;
477
478 PowerData = (PCM_POWER_DATA)Buffer;
479 RtlZeroMemory(PowerData, sizeof(CM_POWER_DATA));
480 PowerData->PD_Size = sizeof(CM_POWER_DATA);
481
484 DeviceCapabilities.Version = 1;
485 DeviceCapabilities.Address = -1;
486 DeviceCapabilities.UINumber = -1;
487
488 Stack.Parameters.DeviceCapabilities.Capabilities = &DeviceCapabilities;
489
493 &Stack);
494 if (NT_SUCCESS(Status))
495 {
496 DPRINT("Got device capabiliities\n");
497
498 PowerData->PD_MostRecentPowerState = PowerDeviceD0; // FIXME
499 if (DeviceCapabilities.DeviceD1)
501 if (DeviceCapabilities.DeviceD2)
503 if (DeviceCapabilities.WakeFromD0)
505 if (DeviceCapabilities.WakeFromD1)
507 if (DeviceCapabilities.WakeFromD2)
509 if (DeviceCapabilities.WakeFromD3)
511 if (DeviceCapabilities.WarmEjectSupported)
513 PowerData->PD_D1Latency = DeviceCapabilities.D1Latency;
514 PowerData->PD_D2Latency = DeviceCapabilities.D2Latency;
515 PowerData->PD_D3Latency = DeviceCapabilities.D3Latency;
517 &DeviceCapabilities.DeviceState,
518 sizeof(DeviceCapabilities.DeviceState));
519 PowerData->PD_DeepestSystemWake = DeviceCapabilities.SystemWake;
520 }
521 else
522 {
523 DPRINT("IRP_MN_QUERY_CAPABILITIES failed (Status 0x%08lx)\n", Status);
524
527 }
528 }
529 }
531 {
533 BufferSize = 0;
535 }
537 {
538 if (BufferSize < sizeof(DeviceNode->HardwareRemovalPolicy))
539 {
540 BufferSize = 0;
542 }
543 else
544 {
545 BufferSize = sizeof(DeviceNode->HardwareRemovalPolicy);
547 &DeviceNode->HardwareRemovalPolicy,
548 BufferSize);
549 }
550 }
551 else
552 {
553 switch (Property)
554 {
557 break;
558
561 break;
562
565 break;
566
569 break;
570
573 break;
574
577 break;
578
581 break;
582
585 break;
586
589 break;
590
591#if (WINVER >= _WIN32_WINNT_WS03)
594 BufferSize = 0;
596 break;
597#endif
598
599#if (WINVER >= _WIN32_WINNT_WIN7)
602 break;
603#endif
604
605 default:
606 BufferSize = 0;
608 break;
609 }
610
611 if (Status == STATUS_SUCCESS)
612 {
616 Buffer,
617 &BufferSize);
618 }
619 }
620
622
623 if (NT_SUCCESS(Status))
624 {
626 {
628 PropertyData->BufferSize = BufferSize;
629 }
631 {
633 }
634 _SEH2_END;
635 }
636
638 return Status;
639}
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: debug.h:115
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#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
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack)
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
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
#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:3769
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
#define DeviceCapabilities
Definition: wingdi.h:4449
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
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by NtPlugPlayControl().

◆ IopGetDeviceRelations()

static NTSTATUS IopGetDeviceRelations ( PPLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA  RelationsData)
static

Definition at line 926 of file plugplay.c.

927{
932 PDEVICE_RELATIONS DeviceRelations = NULL;
933 PDEVICE_OBJECT ChildDeviceObject;
934 PDEVICE_NODE ChildDeviceNode;
935 ULONG i;
936 ULONG Relations;
938 ULONG BufferLeft;
941
942 DPRINT("IopGetDeviceRelations() called\n");
943 DPRINT("Device name: %wZ\n", &RelationsData->DeviceInstance);
944 DPRINT("Relations: %lu\n", RelationsData->Relations);
945 DPRINT("BufferSize: %lu\n", RelationsData->BufferSize);
946 DPRINT("Buffer: %p\n", RelationsData->Buffer);
947
949 {
950 Relations = RelationsData->Relations;
951 BufferSize = RelationsData->BufferSize;
952 Buffer = RelationsData->Buffer;
953
955 }
957 {
959 }
960 _SEH2_END;
961
963 if (!NT_SUCCESS(Status))
964 {
965 DPRINT1("IopCaptureUnicodeString() failed (Status 0x%08lx)\n", Status);
966 return Status;
967 }
968
969 /* Get the device object */
971 if (DeviceObject == NULL)
972 {
973 DPRINT1("IopGetDeviceObjectFromDeviceInstance() returned NULL\n");
975 goto done;
976 }
977
978 switch (Relations)
979 {
981 Stack.Parameters.QueryDeviceRelations.Type = EjectionRelations;
982 break;
983
985 Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
986 break;
987
989 Stack.Parameters.QueryDeviceRelations.Type = PowerRelations;
990 break;
991
993 Stack.Parameters.QueryDeviceRelations.Type = BusRelations;
994 break;
995
996 default:
998 goto done;
999 }
1000
1004 &Stack);
1005 if (!NT_SUCCESS(Status))
1006 {
1007 DPRINT1("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status);
1008 goto done;
1009 }
1010
1011 DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
1012
1013 DPRINT("Found %d device relations\n", DeviceRelations->Count);
1014
1015 _SEH2_TRY
1016 {
1017 RequiredSize = 0;
1018 BufferLeft = BufferSize;
1019 Ptr = Buffer;
1020
1021 for (i = 0; i < DeviceRelations->Count; i++)
1022 {
1023 ChildDeviceObject = DeviceRelations->Objects[i];
1024
1025 ChildDeviceNode = IopGetDeviceNode(ChildDeviceObject);
1026 if (ChildDeviceNode)
1027 {
1028 DPRINT("Device instance: %wZ\n", &ChildDeviceNode->InstancePath);
1029 DPRINT("RequiredSize: %hu\n", ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1030
1031 if (Ptr != NULL)
1032 {
1033 if (BufferLeft < ChildDeviceNode->InstancePath.Length + 2 * sizeof(WCHAR))
1034 {
1036 break;
1037 }
1038
1040 ChildDeviceNode->InstancePath.Buffer,
1041 ChildDeviceNode->InstancePath.Length);
1042 Ptr = (PWCHAR)((ULONG_PTR)Ptr + ChildDeviceNode->InstancePath.Length);
1043 *Ptr = UNICODE_NULL;
1044 Ptr = (PWCHAR)((ULONG_PTR)Ptr + sizeof(WCHAR));
1045
1046 BufferLeft -= (ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1047 }
1048
1049 RequiredSize += (ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1050 }
1051 }
1052
1053 if (Ptr != NULL && BufferLeft >= sizeof(WCHAR))
1054 *Ptr = UNICODE_NULL;
1055
1056 if (RequiredSize > 0)
1057 RequiredSize += sizeof(WCHAR);
1058
1059 DPRINT("BufferSize: %lu RequiredSize: %lu\n", RelationsData->BufferSize, RequiredSize);
1060
1061 RelationsData->BufferSize = RequiredSize;
1062 }
1064 {
1066 }
1067 _SEH2_END;
1068
1069done:
1070 if (DeviceRelations != NULL)
1071 ExFreePool(DeviceRelations);
1072
1073 if (DeviceObject != NULL)
1075
1076 if (DeviceInstance.Buffer != NULL)
1077 ExFreePool(DeviceInstance.Buffer);
1078
1079 return Status;
1080}
_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
UNICODE_STRING InstancePath
Definition: iotypes.h:858
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
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:4439
@ EjectionRelations
Definition: iotypes.h:2153
@ RemovalRelations
Definition: iotypes.h:2155
@ BusRelations
Definition: iotypes.h:2152
@ PowerRelations
Definition: iotypes.h:2154
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define IRP_MN_QUERY_DEVICE_RELATIONS
char CHAR
Definition: xmlstorage.h:175

Referenced by NtPlugPlayControl().

◆ IopGetInterfaceDeviceList()

static NTSTATUS IopGetInterfaceDeviceList ( PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA  DeviceList)
static

Definition at line 327 of file plugplay.c.

328{
333 GUID FilterGuid;
334 PZZWSTR SymbolicLinkList = NULL, LinkList;
336
338 {
340
341 ProbeForRead(StackList.FilterGuid, sizeof(GUID), sizeof(UCHAR));
342 RtlCopyMemory(&FilterGuid, StackList.FilterGuid, sizeof(GUID));
343
344 if (StackList.Buffer != NULL && StackList.BufferSize != 0)
345 {
346 ProbeForWrite(StackList.Buffer, StackList.BufferSize, sizeof(UCHAR));
347 }
348 }
350 {
352 }
353 _SEH2_END;
354
356 if (NT_SUCCESS(Status))
357 {
358 /* Get the device object */
360 if (DeviceInstance.Buffer != NULL)
361 {
363 }
364 }
365
368
369 if (!NT_SUCCESS(Status))
370 {
371 /* failed */
372 return Status;
373 }
374
375 LinkList = SymbolicLinkList;
377 {
379 }
380 TotalLength = ((SymbolicLinkList - LinkList + 1) * sizeof(WCHAR));
381
383 {
384 if (StackList.Buffer != NULL &&
385 StackList.BufferSize >= TotalLength)
386 {
387 // We've already probed the buffer for writing above.
388 RtlCopyMemory(StackList.Buffer, LinkList, TotalLength);
389 }
390
391 DeviceList->BufferSize = TotalLength;
392 }
394 {
395 ExFreePool(LinkList);
397 }
398 _SEH2_END;
399
400 ExFreePool(LinkList);
401 return STATUS_SUCCESS;
402}
PDEVICE_LIST DeviceList
Definition: utils.c:27
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_NullNull_terminated_ WCHAR * PZZWSTR
Definition: ntbasedef.h:420
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_In_ ULONG TotalLength
Definition: usbdlib.h:158
_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 643 of file plugplay.c.

644{
645 UNICODE_STRING RootDeviceName;
648 PDEVICE_NODE RelatedDeviceNode;
649 UNICODE_STRING TargetDeviceInstance;
651 ULONG Relation = 0;
653
654 DPRINT("IopGetRelatedDevice() called\n");
655 DPRINT("Device name: %wZ\n", &RelatedDeviceData->TargetDeviceInstance);
656
657 Status = IopCaptureUnicodeString(&TargetDeviceInstance, &RelatedDeviceData->TargetDeviceInstance);
658 if (!NT_SUCCESS(Status))
659 {
660 return Status;
661 }
662
664 {
665 Relation = RelatedDeviceData->Relation;
666 MaximumLength = RelatedDeviceData->RelatedDeviceInstanceLength;
667 ProbeForWrite(RelatedDeviceData->RelatedDeviceInstance,
669 sizeof(WCHAR));
670 }
672 {
673 if (TargetDeviceInstance.Buffer != NULL)
674 {
675 ExFreePool(TargetDeviceInstance.Buffer);
676 }
678 }
679 _SEH2_END;
680
681 RtlInitUnicodeString(&RootDeviceName,
682 L"HTREE\\ROOT\\0");
683 if (RtlEqualUnicodeString(&TargetDeviceInstance,
684 &RootDeviceName,
685 TRUE))
686 {
688 if (TargetDeviceInstance.Buffer != NULL)
689 {
690 ExFreePool(TargetDeviceInstance.Buffer);
691 }
692 }
693 else
694 {
695 /* Get the device object */
696 DeviceObject = IopGetDeviceObjectFromDeviceInstance(&TargetDeviceInstance);
697 if (TargetDeviceInstance.Buffer != NULL)
698 {
699 ExFreePool(TargetDeviceInstance.Buffer);
700 }
701 if (DeviceObject == NULL)
703
704 DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode;
705 }
706
707 switch (Relation)
708 {
710 RelatedDeviceNode = DeviceNode->Parent;
711 break;
712
714 RelatedDeviceNode = DeviceNode->Child;
715 break;
716
718 RelatedDeviceNode = DeviceNode->Sibling;
719 break;
720
721 default:
722 if (DeviceObject != NULL)
723 {
725 }
726
728 }
729
730 if (RelatedDeviceNode == NULL)
731 {
732 if (DeviceObject)
733 {
735 }
736
738 }
739
740 if (RelatedDeviceNode->InstancePath.Length > MaximumLength)
741 {
742 if (DeviceObject)
743 {
745 }
746
748 }
749
750 /* Copy related device instance name */
752 {
753 RtlCopyMemory(RelatedDeviceData->RelatedDeviceInstance,
754 RelatedDeviceNode->InstancePath.Buffer,
755 RelatedDeviceNode->InstancePath.Length);
756 RelatedDeviceData->RelatedDeviceInstanceLength = RelatedDeviceNode->InstancePath.Length;
757 }
759 {
761 }
762 _SEH2_END;
763
764 if (DeviceObject != NULL)
765 {
767 }
768
769 DPRINT("IopGetRelatedDevice() done\n");
770
771 return Status;
772}
#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)
#define L(x)
Definition: ntvdm.h:50
_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().

◆ IopQueueTargetDeviceEvent()

NTSTATUS IopQueueTargetDeviceEvent ( const GUID Guid,
PUNICODE_STRING  DeviceIds 
)

Definition at line 52 of file plugplay.c.

54{
55 PPNP_EVENT_ENTRY EventEntry;
57 ULONG TotalSize;
59
60 ASSERT(DeviceIds);
61
62 /* Allocate a big enough buffer */
63 Copy.Length = 0;
64 Copy.MaximumLength = DeviceIds->Length + sizeof(UNICODE_NULL);
65 TotalSize =
67 Copy.MaximumLength;
68
69 EventEntry = ExAllocatePool(NonPagedPool,
70 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
71 if (!EventEntry)
73 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
74
75 /* Fill the buffer with the event GUID */
76 RtlCopyMemory(&EventEntry->Event.EventGuid,
77 Guid,
78 sizeof(GUID));
80 EventEntry->Event.TotalSize = TotalSize;
81
82 /* Fill the device id */
83 Copy.Buffer = EventEntry->Event.TargetDevice.DeviceIds;
85 if (!NT_SUCCESS(Status))
86 {
87 ExFreePool(EventEntry);
88 return Status;
89 }
90
92 &EventEntry->ListEntry);
94 0,
95 FALSE);
96
97 return STATUS_SUCCESS;
98}
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
#define ASSERT(a)
Definition: mode.c:44
@ TargetDeviceChangeEvent
Definition: cmtypes.h:257
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
struct _PLUGPLAY_EVENT_BLOCK::@2372::@2375 TargetDevice
PLUGPLAY_EVENT_CATEGORY EventCategory
Definition: cmtypes.h:406
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
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_Must_inspect_result_ __drv_aliasesMem PDEVICE_OBJECT _In_ PDEVICE_OBJECT TargetDevice
Definition: iofuncs.h:691

Referenced by IopQueryRemoveDevice(), IopRemoveDevice(), IoRequestDeviceEject(), PiControlInitializeDevice(), PiInitializeDevNode(), and PiStartDeviceFinal().

◆ IopRemovePlugPlayEvent()

static NTSTATUS IopRemovePlugPlayEvent ( _In_ PPLUGPLAY_CONTROL_USER_RESPONSE_DATA  ResponseData)
static

Definition at line 305 of file plugplay.c.

307{
308 /* Remove a pnp event entry from the tail of the queue */
310 {
312 }
313
314 /* Signal the next pnp event in the queue */
316 {
318 0,
319 FALSE);
320 }
321
322 return STATUS_SUCCESS;
323}
#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
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValueBasicInformation
Definition: nt_native.h:1180
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define REG_RESOURCE_REQUIREMENTS_LIST
Definition: nt_native.h:1504
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1237
#define REG_DWORD
Definition: sdbapi.c:596
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699

Referenced by PiControlInitializeDevice().

◆ NtGetPlugPlayEvent()

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

Definition at line 1278 of file plugplay.c.

1282{
1285
1286 DPRINT("NtGetPlugPlayEvent() called\n");
1287
1288 /* Function can only be called from user-mode */
1290 {
1291 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
1292 return STATUS_ACCESS_DENIED;
1293 }
1294
1295 /* Check for Tcb privilege */
1297 UserMode))
1298 {
1299 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
1301 }
1302
1303 /* Wait for a PnP event */
1304 DPRINT("Waiting for pnp notification event\n");
1307 UserMode,
1308 FALSE,
1309 NULL);
1311 {
1312 DPRINT("KeWaitForSingleObject() failed (Status %lx)\n", Status);
1314 return Status;
1315 }
1316
1317 /* Get entry from the tail of the queue */
1320 ListEntry);
1321
1322 /* Check the buffer size */
1323 if (BufferSize < Entry->Event.TotalSize)
1324 {
1325 DPRINT1("Buffer is too small for the pnp-event\n");
1327 }
1328
1329 /* Copy event data to the user buffer */
1330 _SEH2_TRY
1331 {
1333 Entry->Event.TotalSize,
1334 sizeof(UCHAR));
1336 &Entry->Event,
1337 Entry->Event.TotalSize);
1338 }
1340 {
1342 }
1343 _SEH2_END;
1344
1345 DPRINT("NtGetPlugPlayEvent() done\n");
1346
1347 return STATUS_SUCCESS;
1348}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KernelMode
Definition: asm.h:34
#define UserMode
Definition: asm.h:35
#define KeGetPreviousMode()
Definition: ketypes.h:1110
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:78
base of all file and directory entries
Definition: entries.h:83
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
@ UserRequest
Definition: ketypes.h:409

Referenced by PnpEventThread().

◆ NtPlugPlayControl()

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

Definition at line 1408 of file plugplay.c.

1411{
1412 DPRINT("NtPlugPlayControl(%d %p %lu) called\n",
1413 PlugPlayControlClass, Buffer, BufferLength);
1414
1415 /* Function can only be called from user-mode */
1417 {
1418 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
1419 return STATUS_ACCESS_DENIED;
1420 }
1421
1422 /* Check for Tcb privilege */
1424 UserMode))
1425 {
1426 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
1428 }
1429
1430 /* Probe the buffer */
1431 _SEH2_TRY
1432 {
1435 sizeof(ULONG));
1436 }
1438 {
1440 }
1441 _SEH2_END;
1442
1443 switch (PlugPlayControlClass)
1444 {
1448 // the Flags field is not used anyway
1450 PlugPlayControlClass);
1451
1452// case PlugPlayControlRegisterNewDevice:
1453// case PlugPlayControlDeregisterDevice:
1454
1459
1465 PlugPlayControlClass);
1466
1467// case PlugPlayControlUnlockDevice:
1472
1477
1478// case PlugPlayControlGenerateLegacyDevice:
1479
1484
1489
1490// case PlugPlayControlDeviceClassAssociation:
1491
1496
1497// case PlugPlayControlGetInterfaceDeviceAlias:
1498
1503
1508
1513
1514// case PlugPlayControlTargetDeviceRelation:
1515// case PlugPlayControlQueryConflictList:
1516// case PlugPlayControlRetrieveDock:
1517// case PlugPlayControlHaltDevice:
1518// case PlugPlayControlGetBlockedDriverList:
1519
1520 default:
1522 }
1523
1525}
@ PlugPlayControlEnumerateDevice
Definition: cmtypes.h:209
@ PlugPlayControlUserResponse
Definition: cmtypes.h:216
@ PlugPlayControlProperty
Definition: cmtypes.h:219
@ PlugPlayControlQueryDeviceRelations
Definition: cmtypes.h:225
@ PlugPlayControlGetRelatedDevice
Definition: cmtypes.h:221
@ PlugPlayControlDeviceStatus
Definition: cmtypes.h:223
@ PlugPlayControlQueryAndRemoveDevice
Definition: cmtypes.h:215
@ PlugPlayControlGetDeviceDepth
Definition: cmtypes.h:224
@ PlugPlayControlInitializeDevice
Definition: cmtypes.h:212
@ PlugPlayControlGetInterfaceDeviceList
Definition: cmtypes.h:218
@ PlugPlayControlStartDevice
Definition: cmtypes.h:213
@ PlugPlayControlResetDevice
Definition: cmtypes.h:229
static NTSTATUS IopGetRelatedDevice(PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA RelatedDeviceData)
Definition: plugplay.c:643
static NTSTATUS PiControlQueryRemoveDevice(_In_ PPLUGPLAY_CONTROL_QUERY_REMOVE_DATA ControlData)
Definition: plugplay.c:1184
static NTSTATUS IopRemovePlugPlayEvent(_In_ PPLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData)
Definition: plugplay.c:305
static NTSTATUS IopDeviceStatus(PPLUGPLAY_CONTROL_STATUS_DATA StatusData)
Definition: plugplay.c:836
static NTSTATUS IopGetInterfaceDeviceList(PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA DeviceList)
Definition: plugplay.c:327
static NTSTATUS IopGetDeviceDepth(PPLUGPLAY_CONTROL_DEPTH_DATA DepthData)
Definition: plugplay.c:1083
static NTSTATUS PiControlSyncDeviceAction(_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA DeviceData, _In_ PLUGPLAY_CONTROL_CLASS ControlClass)
Definition: plugplay.c:1129
static NTSTATUS IopGetDeviceRelations(PPLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA RelationsData)
Definition: plugplay.c:926
static NTSTATUS IopGetDeviceProperty(PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData)
Definition: plugplay.c:405
static NTSTATUS PiControlInitializeDevice(_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA ControlData)
Definition: plugplay.c:204
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

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

◆ PiControlInitializeDevice()

static NTSTATUS PiControlInitializeDevice ( _In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA  ControlData)
static

Definition at line 204 of file plugplay.c.

206{
211 HANDLE InstanceKey;
212
213 DPRINT("PiControlInitializeDevice(%p)\n", ControlData);
214
215 Status = IopCaptureUnicodeString(&DeviceInstance, &ControlData->DeviceInstance);
216 if (!NT_SUCCESS(Status))
217 {
218 return Status;
219 }
220
221 DPRINT("Device: %wZ\n", &DeviceInstance);
222
223 /* Leave, if the device already exists */
225 if (DeviceObject != NULL)
226 {
227 DPRINT1("Device %wZ already exists!\n", &DeviceInstance);
230 goto done;
231 }
232
233 DPRINT("Device %wZ does not exist!\n", &DeviceInstance);
234
235 /* Create a device node for the device instance */
237 if (!NT_SUCCESS(Status))
238 {
239 DPRINT1("IoCreateDevice() failed (Status 0x%08lx)\n", Status);
240 goto done;
241 }
242
243 /* Allocate a new device node */
245 if (DeviceNode == NULL)
246 {
247 DPRINT1("Failed to allocate a device node!\n");
250 goto done;
251 }
252
253 // Set the device instance of the device node
254 // NOTE: a NULL-terminated string is required for PnpRootRegisterDevice
258 &DeviceNode->InstancePath);
259 if (!NT_SUCCESS(Status))
260 {
261 DPRINT1("RtlDuplicateUnicodeString() failed (Status 0x%08lx)\n", Status);
264 goto done;
265 }
266
270
272 if (!NT_SUCCESS(Status))
273 {
274 DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
277 goto done;
278 }
279
280 /* Write the resource information to the registry */
282
283 // Finish the root device registration
285
286 /* Insert as a root enumerated device node */
288
289 IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED, &DeviceInstance);
290
291 ZwClose(InstanceKey);
292done:
294
295 return Status;
296}
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
#define DNF_ENUMERATED
Definition: iotypes.h:174
@ DeviceNodeInitialized
Definition: iotypes.h:386
#define DNF_IDS_QUERIED
Definition: iotypes.h:175
#define DNF_MADEUP
Definition: iotypes.h:170
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:1251
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:52
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:606
#define DO_BUS_ENUMERATED_DEVICE

Referenced by NtPlugPlayControl().

◆ PiControlQueryRemoveDevice()

static NTSTATUS PiControlQueryRemoveDevice ( _In_ PPLUGPLAY_CONTROL_QUERY_REMOVE_DATA  ControlData)
static

Definition at line 1184 of file plugplay.c.

1186{
1190
1191 Status = IopCaptureUnicodeString(&DeviceInstance, &ControlData->DeviceInstance);
1192 if (!NT_SUCCESS(Status))
1193 {
1194 return Status;
1195 }
1196
1198 if (DeviceInstance.Buffer != NULL)
1199 {
1200 ExFreePool(DeviceInstance.Buffer);
1201 }
1202 if (DeviceObject == NULL)
1203 {
1204 return STATUS_NO_SUCH_DEVICE;
1205 }
1206
1209
1211
1212 return Status;
1213}

Referenced by NtPlugPlayControl().

◆ PiControlSyncDeviceAction()

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

Definition at line 1129 of file plugplay.c.

1132{
1136
1140
1142 if (!NT_SUCCESS(Status))
1143 {
1144 return Status;
1145 }
1146
1148 if (DeviceInstance.Buffer != NULL)
1149 {
1150 ExFreePool(DeviceInstance.Buffer);
1151 }
1152 if (DeviceObject == NULL)
1153 {
1154 return STATUS_NO_SUCH_DEVICE;
1155 }
1156
1158
1159 switch (ControlClass)
1160 {
1163 break;
1166 break;
1169 break;
1170 default:
1172 break;
1173 }
1174
1176
1178
1179 return Status;
1180}
static const WCHAR ControlClass[]
Definition: cfgmgr.c:44
#define UNREACHABLE
@ PiActionResetDevice
Definition: io.h:528
@ PiActionStartDevice
Definition: io.h:530
@ PiActionEnumDeviceTree
Definition: io.h:526
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:2714
_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 776 of file plugplay.c.

778{
779 return (DeviceNode->State == DeviceNodeStartPending ||
782 DeviceNode->State == DeviceNodeStarted ||
786 DeviceNode->State == DeviceNodeStopped ||
788}
@ DeviceNodeStopped
Definition: iotypes.h:394
@ DeviceNodeRestartCompletion
Definition: iotypes.h:395
@ DeviceNodeStartPostWork
Definition: iotypes.h:391
@ DeviceNodeStarted
Definition: iotypes.h:392
@ DeviceNodeStartCompletion
Definition: iotypes.h:390
@ DeviceNodeEnumerateCompletion
Definition: iotypes.h:397
@ DeviceNodeEnumeratePending
Definition: iotypes.h:396
@ DeviceNodeQueryStopped
Definition: iotypes.h:393
@ DeviceNodeStartPending
Definition: iotypes.h:389

Referenced by IopGetDeviceNodeStatus().

Variable Documentation

◆ IopPnpEventQueueHead

LIST_ENTRY IopPnpEventQueueHead
static

◆ IopPnpNotifyEvent

KEVENT IopPnpNotifyEvent
static