ReactOS 0.4.15-dev-5667-ged97270
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 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 IopInitializeDevice (_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 152 of file plugplay.c.

153{
155 volatile UNICODE_STRING Name;
156
157 Name.Buffer = NULL;
159 {
160 Name.Length = SrcName->Length;
161 Name.MaximumLength = SrcName->MaximumLength;
162 if (Name.Length > Name.MaximumLength)
163 {
166 }
167
168 if (Name.MaximumLength)
169 {
170 ProbeForRead(SrcName->Buffer,
171 Name.MaximumLength,
172 sizeof(WCHAR));
173 Name.Buffer = ExAllocatePool(NonPagedPool, Name.MaximumLength);
174 if (Name.Buffer == NULL)
175 {
178 }
179
180 memcpy(Name.Buffer, SrcName->Buffer, Name.MaximumLength);
181 }
182
183 *DstName = Name;
184 }
186 {
187 if (Name.Buffer)
188 {
189 ExFreePool(Name.Buffer);
190 }
192 }
193 _SEH2_END;
194
195 return Status;
196}
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(), IopInitializeDevice(), PiControlQueryRemoveDevice(), and PiControlSyncDeviceAction().

◆ IopDeviceStatus()

static NTSTATUS IopDeviceStatus ( PPLUGPLAY_CONTROL_STATUS_DATA  StatusData)
static

Definition at line 813 of file plugplay.c.

814{
817 ULONG Operation = 0;
818 ULONG DeviceStatus = 0;
819 ULONG DeviceProblem = 0;
822
823 DPRINT("IopDeviceStatus() called\n");
824
826 if (!NT_SUCCESS(Status))
827 {
828 return Status;
829 }
830
831 DPRINT("Device name: '%wZ'\n", &DeviceInstance);
832
834 {
835 Operation = StatusData->Operation;
837 {
838 DeviceStatus = StatusData->DeviceStatus;
839 DeviceProblem = StatusData->DeviceProblem;
840 }
841 }
843 {
844 if (DeviceInstance.Buffer != NULL)
845 {
847 }
849 }
850 _SEH2_END;
851
852 /* Get the device object */
854 if (DeviceInstance.Buffer != NULL)
855 {
857 }
858 if (DeviceObject == NULL)
859 {
861 }
862
864
865 switch (Operation)
866 {
868 DPRINT("Get status data\n");
869 DeviceStatus = IopGetDeviceNodeStatus(DeviceNode);
870 DeviceProblem = DeviceNode->Problem;
871 break;
872
874 DPRINT1("Set status data is NOT SUPPORTED\n");
875 break;
876
878 DPRINT1("FIXME: Clear status data!\n");
879 break;
880 }
881
883
885 {
887 {
888 StatusData->DeviceStatus = DeviceStatus;
889 StatusData->DeviceProblem = DeviceProblem;
890 }
892 {
894 }
895 _SEH2_END;
896 }
897
898 return Status;
899}
@ 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:118
static NTSTATUS IopCaptureUnicodeString(PUNICODE_STRING DstName, PUNICODE_STRING SrcName)
Definition: plugplay.c:152
static ULONG IopGetDeviceNodeStatus(PDEVICE_NODE DeviceNode)
Definition: plugplay.c:768
#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 98 of file plugplay.c.

101{
103
104 if (RtlEqualUnicodeString(&DeviceNode->InstancePath,
105 DeviceInstanceContext->InstancePath, TRUE))
106 {
107 ObReferenceObject(DeviceNode->PhysicalDeviceObject);
108 DeviceInstanceContext->DeviceObject = DeviceNode->PhysicalDeviceObject;
109
110 /* Stop enumeration */
111 return STATUS_UNSUCCESSFUL;
112 }
113
114 return STATUS_SUCCESS;
115}
#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 1060 of file plugplay.c.

1061{
1066
1067 DPRINT("IopGetDeviceDepth() called\n");
1068 DPRINT("Device name: %wZ\n", &DepthData->DeviceInstance);
1069
1071 if (!NT_SUCCESS(Status))
1072 {
1073 return Status;
1074 }
1075
1076 /* Get the device object */
1078 if (DeviceInstance.Buffer != NULL)
1079 {
1080 ExFreePool(DeviceInstance.Buffer);
1081 }
1082 if (DeviceObject == NULL)
1083 {
1084 return STATUS_NO_SUCH_DEVICE;
1085 }
1086
1088
1089 _SEH2_TRY
1090 {
1091 DepthData->Depth = DeviceNode->Level;
1092 }
1094 {
1096 }
1097 _SEH2_END;
1098
1100
1101 return Status;
1102}
UNICODE_STRING DeviceInstance
Definition: cmtypes.h:534

Referenced by NtPlugPlayControl().

◆ IopGetDeviceNodeStatus()

static ULONG IopGetDeviceNodeStatus ( PDEVICE_NODE  DeviceNode)
static

Definition at line 768 of file plugplay.c.

769{
771
772 if (DeviceNode->Parent == IopRootDeviceNode)
774
775 // FIXME: review for deleted and removed states
778
781
782 if (DeviceNode->UserFlags & DNUF_WILL_BE_REMOVED)
784
785 if (DeviceNode->Flags & DNF_HAS_PROBLEM)
787
790
791 if (DeviceNode->Flags & DNF_DRIVER_BLOCKED)
793
796
799
800 if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
802
803 if (DeviceNode->UserFlags & DNUF_DONT_SHOW_IN_UI)
805
806 if (!(DeviceNode->UserFlags & DNUF_NOT_DISABLEABLE))
808
809 return Output;
810}
#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:753
@ Output
Definition: arc.h:85

Referenced by IopDeviceStatus().

◆ IopGetDeviceObjectFromDeviceInstance()

PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance ( PUNICODE_STRING  DeviceInstance)

Definition at line 118 of file plugplay.c.

119{
121 IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT DeviceInstanceContext;
122
123 if (IopRootDeviceNode == NULL)
124 return NULL;
125
126 if (DeviceInstance == NULL ||
127 DeviceInstance->Length == 0)
128 {
130 {
133 }
134 else
135 return NULL;
136 }
137
138 /* Traverse the device tree to find the matching device node */
139 DeviceInstanceContext.InstancePath = DeviceInstance;
140 DeviceInstanceContext.DeviceObject = NULL;
144 &DeviceInstanceContext);
146
147 /* In case of error or instance not found, this will still be NULL from above. */
148 return DeviceInstanceContext.DeviceObject;
149}
#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:98
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:855

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

◆ IopGetDeviceProperty()

static NTSTATUS IopGetDeviceProperty ( PPLUGPLAY_CONTROL_PROPERTY_DATA  PropertyData)
static

Definition at line 382 of file plugplay.c.

383{
392
393 DPRINT("IopGetDeviceProperty() called\n");
394 DPRINT("Device name: %wZ\n", &PropertyData->DeviceInstance);
395
397 if (!NT_SUCCESS(Status))
398 {
399 return Status;
400 }
401
403 {
404 Property = PropertyData->Property;
405 BufferSize = PropertyData->BufferSize;
408 sizeof(UCHAR));
409 }
411 {
412 if (DeviceInstance.Buffer != NULL)
413 {
415 }
417 }
418 _SEH2_END;
419
420 /* Get the device object */
422 if (DeviceInstance.Buffer != NULL)
423 {
425 }
426 if (DeviceObject == NULL)
427 {
429 }
430
432 if (Buffer == NULL)
433 {
436 }
437
438
439 DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode;
440
442 {
443 if (BufferSize < sizeof(CM_POWER_DATA))
444 {
445 BufferSize = 0;
447 }
448 else
449 {
451 PCM_POWER_DATA PowerData;
454
455 PowerData = (PCM_POWER_DATA)Buffer;
456 RtlZeroMemory(PowerData, sizeof(CM_POWER_DATA));
457 PowerData->PD_Size = sizeof(CM_POWER_DATA);
458
461 DeviceCapabilities.Version = 1;
462 DeviceCapabilities.Address = -1;
463 DeviceCapabilities.UINumber = -1;
464
465 Stack.Parameters.DeviceCapabilities.Capabilities = &DeviceCapabilities;
466
470 &Stack);
471 if (NT_SUCCESS(Status))
472 {
473 DPRINT("Got device capabiliities\n");
474
475 PowerData->PD_MostRecentPowerState = PowerDeviceD0; // FIXME
476 if (DeviceCapabilities.DeviceD1)
478 if (DeviceCapabilities.DeviceD2)
480 if (DeviceCapabilities.WakeFromD0)
482 if (DeviceCapabilities.WakeFromD1)
484 if (DeviceCapabilities.WakeFromD2)
486 if (DeviceCapabilities.WakeFromD3)
488 if (DeviceCapabilities.WarmEjectSupported)
490 PowerData->PD_D1Latency = DeviceCapabilities.D1Latency;
491 PowerData->PD_D2Latency = DeviceCapabilities.D2Latency;
492 PowerData->PD_D3Latency = DeviceCapabilities.D3Latency;
494 &DeviceCapabilities.DeviceState,
495 sizeof(DeviceCapabilities.DeviceState));
496 PowerData->PD_DeepestSystemWake = DeviceCapabilities.SystemWake;
497 }
498 else
499 {
500 DPRINT("IRP_MN_QUERY_CAPABILITIES failed (Status 0x%08lx)\n", Status);
501
504 }
505 }
506 }
508 {
510 BufferSize = 0;
512 }
514 {
515 if (BufferSize < sizeof(DeviceNode->HardwareRemovalPolicy))
516 {
517 BufferSize = 0;
519 }
520 else
521 {
522 BufferSize = sizeof(DeviceNode->HardwareRemovalPolicy);
524 &DeviceNode->HardwareRemovalPolicy,
525 BufferSize);
526 }
527 }
528 else
529 {
530 switch (Property)
531 {
534 break;
535
538 break;
539
542 break;
543
546 break;
547
550 break;
551
554 break;
555
558 break;
559
562 break;
563
566 break;
567
568#if (WINVER >= _WIN32_WINNT_WS03)
571 BufferSize = 0;
573 break;
574#endif
575
576#if (WINVER >= _WIN32_WINNT_WIN7)
579 break;
580#endif
581
582 default:
583 BufferSize = 0;
585 break;
586 }
587
588 if (Status == STATUS_SUCCESS)
589 {
593 Buffer,
594 &BufferSize);
595 }
596 }
597
599
600 if (NT_SUCCESS(Status))
601 {
603 {
605 PropertyData->BufferSize = BufferSize;
606 }
608 {
610 }
611 _SEH2_END;
612 }
613
615 return Status;
616}
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:1952
#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 903 of file plugplay.c.

904{
909 PDEVICE_RELATIONS DeviceRelations = NULL;
910 PDEVICE_OBJECT ChildDeviceObject;
911 PDEVICE_NODE ChildDeviceNode;
912 ULONG i;
913 ULONG Relations;
915 ULONG BufferLeft;
918
919 DPRINT("IopGetDeviceRelations() called\n");
920 DPRINT("Device name: %wZ\n", &RelationsData->DeviceInstance);
921 DPRINT("Relations: %lu\n", RelationsData->Relations);
922 DPRINT("BufferSize: %lu\n", RelationsData->BufferSize);
923 DPRINT("Buffer: %p\n", RelationsData->Buffer);
924
926 {
927 Relations = RelationsData->Relations;
928 BufferSize = RelationsData->BufferSize;
929 Buffer = RelationsData->Buffer;
930
932 }
934 {
936 }
937 _SEH2_END;
938
940 if (!NT_SUCCESS(Status))
941 {
942 DPRINT1("IopCaptureUnicodeString() failed (Status 0x%08lx)\n", Status);
943 return Status;
944 }
945
946 /* Get the device object */
948 if (DeviceObject == NULL)
949 {
950 DPRINT1("IopGetDeviceObjectFromDeviceInstance() returned NULL\n");
952 goto done;
953 }
954
955 switch (Relations)
956 {
958 Stack.Parameters.QueryDeviceRelations.Type = EjectionRelations;
959 break;
960
962 Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
963 break;
964
966 Stack.Parameters.QueryDeviceRelations.Type = PowerRelations;
967 break;
968
970 Stack.Parameters.QueryDeviceRelations.Type = BusRelations;
971 break;
972
973 default:
975 goto done;
976 }
977
981 &Stack);
982 if (!NT_SUCCESS(Status))
983 {
984 DPRINT1("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status);
985 goto done;
986 }
987
989
990 DPRINT("Found %d device relations\n", DeviceRelations->Count);
991
993 {
994 RequiredSize = 0;
995 BufferLeft = BufferSize;
996 Ptr = Buffer;
997
998 for (i = 0; i < DeviceRelations->Count; i++)
999 {
1000 ChildDeviceObject = DeviceRelations->Objects[i];
1001
1002 ChildDeviceNode = IopGetDeviceNode(ChildDeviceObject);
1003 if (ChildDeviceNode)
1004 {
1005 DPRINT("Device instance: %wZ\n", &ChildDeviceNode->InstancePath);
1006 DPRINT("RequiredSize: %hu\n", ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1007
1008 if (Ptr != NULL)
1009 {
1010 if (BufferLeft < ChildDeviceNode->InstancePath.Length + 2 * sizeof(WCHAR))
1011 {
1013 break;
1014 }
1015
1017 ChildDeviceNode->InstancePath.Buffer,
1018 ChildDeviceNode->InstancePath.Length);
1019 Ptr = (PWCHAR)((ULONG_PTR)Ptr + ChildDeviceNode->InstancePath.Length);
1020 *Ptr = UNICODE_NULL;
1021 Ptr = (PWCHAR)((ULONG_PTR)Ptr + sizeof(WCHAR));
1022
1023 BufferLeft -= (ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1024 }
1025
1026 RequiredSize += (ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1027 }
1028 }
1029
1030 if (Ptr != NULL && BufferLeft >= sizeof(WCHAR))
1031 *Ptr = UNICODE_NULL;
1032
1033 if (RequiredSize > 0)
1034 RequiredSize += sizeof(WCHAR);
1035
1036 DPRINT("BufferSize: %lu RequiredSize: %lu\n", RelationsData->BufferSize, RequiredSize);
1037
1038 RelationsData->BufferSize = RequiredSize;
1039 }
1041 {
1043 }
1044 _SEH2_END;
1045
1046done:
1047 if (DeviceRelations != NULL)
1048 ExFreePool(DeviceRelations);
1049
1050 if (DeviceObject != NULL)
1052
1053 if (DeviceInstance.Buffer != NULL)
1054 ExFreePool(DeviceInstance.Buffer);
1055
1056 return Status;
1057}
_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 304 of file plugplay.c.

305{
310 GUID FilterGuid;
311 PZZWSTR SymbolicLinkList = NULL, LinkList;
313
315 {
317
318 ProbeForRead(StackList.FilterGuid, sizeof(GUID), sizeof(UCHAR));
319 RtlCopyMemory(&FilterGuid, StackList.FilterGuid, sizeof(GUID));
320
321 if (StackList.Buffer != NULL && StackList.BufferSize != 0)
322 {
323 ProbeForWrite(StackList.Buffer, StackList.BufferSize, sizeof(UCHAR));
324 }
325 }
327 {
329 }
330 _SEH2_END;
331
333 if (NT_SUCCESS(Status))
334 {
335 /* Get the device object */
337 if (DeviceInstance.Buffer != NULL)
338 {
340 }
341 }
342
345
346 if (!NT_SUCCESS(Status))
347 {
348 /* failed */
349 return Status;
350 }
351
352 LinkList = SymbolicLinkList;
354 {
356 }
357 TotalLength = ((SymbolicLinkList - LinkList + 1) * sizeof(WCHAR));
358
360 {
361 if (StackList.Buffer != NULL &&
362 StackList.BufferSize >= TotalLength)
363 {
364 // We've already probed the buffer for writing above.
365 RtlCopyMemory(StackList.Buffer, LinkList, TotalLength);
366 }
367
368 DeviceList->BufferSize = TotalLength;
369 }
371 {
372 ExFreePool(LinkList);
374 }
375 _SEH2_END;
376
377 ExFreePool(LinkList);
378 return STATUS_SUCCESS;
379}
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 620 of file plugplay.c.

621{
622 UNICODE_STRING RootDeviceName;
625 PDEVICE_NODE RelatedDeviceNode;
626 UNICODE_STRING TargetDeviceInstance;
628 ULONG Relation = 0;
630
631 DPRINT("IopGetRelatedDevice() called\n");
632 DPRINT("Device name: %wZ\n", &RelatedDeviceData->TargetDeviceInstance);
633
634 Status = IopCaptureUnicodeString(&TargetDeviceInstance, &RelatedDeviceData->TargetDeviceInstance);
635 if (!NT_SUCCESS(Status))
636 {
637 return Status;
638 }
639
641 {
642 Relation = RelatedDeviceData->Relation;
643 MaximumLength = RelatedDeviceData->RelatedDeviceInstanceLength;
644 ProbeForWrite(RelatedDeviceData->RelatedDeviceInstance,
646 sizeof(WCHAR));
647 }
649 {
650 if (TargetDeviceInstance.Buffer != NULL)
651 {
652 ExFreePool(TargetDeviceInstance.Buffer);
653 }
655 }
656 _SEH2_END;
657
658 RtlInitUnicodeString(&RootDeviceName,
659 L"HTREE\\ROOT\\0");
660 if (RtlEqualUnicodeString(&TargetDeviceInstance,
661 &RootDeviceName,
662 TRUE))
663 {
665 if (TargetDeviceInstance.Buffer != NULL)
666 {
667 ExFreePool(TargetDeviceInstance.Buffer);
668 }
669 }
670 else
671 {
672 /* Get the device object */
673 DeviceObject = IopGetDeviceObjectFromDeviceInstance(&TargetDeviceInstance);
674 if (TargetDeviceInstance.Buffer != NULL)
675 {
676 ExFreePool(TargetDeviceInstance.Buffer);
677 }
678 if (DeviceObject == NULL)
680
681 DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode;
682 }
683
684 switch (Relation)
685 {
687 RelatedDeviceNode = DeviceNode->Parent;
688 break;
689
691 RelatedDeviceNode = DeviceNode->Child;
692 break;
693
695 RelatedDeviceNode = DeviceNode->Sibling;
696 break;
697
698 default:
699 if (DeviceObject != NULL)
700 {
702 }
703
705 }
706
707 if (RelatedDeviceNode == NULL)
708 {
709 if (DeviceObject)
710 {
712 }
713
715 }
716
717 if (RelatedDeviceNode->InstancePath.Length > MaximumLength)
718 {
719 if (DeviceObject)
720 {
722 }
723
725 }
726
727 /* Copy related device instance name */
729 {
730 RtlCopyMemory(RelatedDeviceData->RelatedDeviceInstance,
731 RelatedDeviceNode->InstancePath.Buffer,
732 RelatedDeviceNode->InstancePath.Length);
733 RelatedDeviceData->RelatedDeviceInstanceLength = RelatedDeviceNode->InstancePath.Length;
734 }
736 {
738 }
739 _SEH2_END;
740
741 if (DeviceObject != NULL)
742 {
744 }
745
746 DPRINT("IopGetRelatedDevice() done\n");
747
748 return Status;
749}
#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().

◆ IopInitializeDevice()

static NTSTATUS IopInitializeDevice ( _In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA  ControlData)
static

Definition at line 201 of file plugplay.c.

203{
208
209 DPRINT("IopInitializeDevice(%p)\n", ControlData);
210
211 Status = IopCaptureUnicodeString(&DeviceInstance, &ControlData->DeviceInstance);
212 if (!NT_SUCCESS(Status))
213 {
214 return Status;
215 }
216
217 DPRINT("Device: %wZ\n", &DeviceInstance);
218
219 /* Leave, if the device already exists */
221 if (DeviceInstance.Buffer != NULL)
222 {
223 DPRINT1("Device %wZ already exists!\n", &DeviceInstance);
225 goto done;
226 }
227
229
230 DPRINT("Device %wZ does not exist!\n", &DeviceInstance);
231
232 /* Create a device node for the device instance */
234 0,
235 NULL,
238 FALSE,
239 &DeviceObject);
240 if (!NT_SUCCESS(Status))
241 {
242 DPRINT1("IoCreateDevice() failed (Status 0x%08lx)\n", Status);
243 goto done;
244 }
245
246 /* Allocate a new device node */
248 if (DeviceNode == NULL)
249 {
250 DPRINT1("Failed to allocate a device node!\n");
253 goto done;
254 }
255
256 /* Set the device instance of the device node */
258 if (!NT_SUCCESS(Status))
259 {
260 DPRINT1("RtlDuplicateUnicodeString() failed (Status 0x%08lx)\n", Status);
263 goto done;
264 }
265
266 /* Insert as a root enumerated device node */
268
269done:
271
272 return Status;
273}
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
VOID PiInsertDevNode(_In_ PDEVICE_NODE DeviceNode, _In_ PDEVICE_NODE ParentNode)
Definition: devnode.c:80
PDEVICE_NODE PipAllocateDeviceNode(IN PDEVICE_OBJECT PhysicalDeviceObject)
NTSTATUS IopFreeDeviceNode(IN PDEVICE_NODE DeviceNode)
PDRIVER_OBJECT IopRootDriverObject
Definition: pnpmgr.c:26
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:110

Referenced by NtPlugPlayControl().

◆ IopInitPlugPlayEvents()

NTSTATUS IopInitPlugPlayEvents ( VOID  )

Definition at line 37 of file plugplay.c.

38{
40
43 FALSE);
44
45 return STATUS_SUCCESS;
46}
#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 49 of file plugplay.c.

51{
52 PPNP_EVENT_ENTRY EventEntry;
54 ULONG TotalSize;
56
57 ASSERT(DeviceIds);
58
59 /* Allocate a big enough buffer */
60 Copy.Length = 0;
61 Copy.MaximumLength = DeviceIds->Length + sizeof(UNICODE_NULL);
62 TotalSize =
64 Copy.MaximumLength;
65
66 EventEntry = ExAllocatePool(NonPagedPool,
67 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
68 if (!EventEntry)
70 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
71
72 /* Fill the buffer with the event GUID */
73 RtlCopyMemory(&EventEntry->Event.EventGuid,
74 Guid,
75 sizeof(GUID));
77 EventEntry->Event.TotalSize = TotalSize;
78
79 /* Fill the device id */
80 Copy.Buffer = EventEntry->Event.TargetDevice.DeviceIds;
82 if (!NT_SUCCESS(Status))
83 {
84 ExFreePool(EventEntry);
85 return Status;
86 }
87
89 &EventEntry->ListEntry);
91 0,
92 FALSE);
93
94 return STATUS_SUCCESS;
95}
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::@2366::@2369 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(), PiInitializeDevNode(), and PiStartDeviceFinal().

◆ IopRemovePlugPlayEvent()

static NTSTATUS IopRemovePlugPlayEvent ( _In_ PPLUGPLAY_CONTROL_USER_RESPONSE_DATA  ResponseData)
static

Definition at line 282 of file plugplay.c.

284{
285 /* Remove a pnp event entry from the tail of the queue */
287 {
289 }
290
291 /* Signal the next pnp event in the queue */
293 {
295 0,
296 FALSE);
297 }
298
299 return STATUS_SUCCESS;
300}
#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().

◆ NtGetPlugPlayEvent()

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

Definition at line 1255 of file plugplay.c.

1259{
1262
1263 DPRINT("NtGetPlugPlayEvent() called\n");
1264
1265 /* Function can only be called from user-mode */
1267 {
1268 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
1269 return STATUS_ACCESS_DENIED;
1270 }
1271
1272 /* Check for Tcb privilege */
1274 UserMode))
1275 {
1276 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
1278 }
1279
1280 /* Wait for a PnP event */
1281 DPRINT("Waiting for pnp notification event\n");
1284 UserMode,
1285 FALSE,
1286 NULL);
1288 {
1289 DPRINT("KeWaitForSingleObject() failed (Status %lx)\n", Status);
1291 return Status;
1292 }
1293
1294 /* Get entry from the tail of the queue */
1297 ListEntry);
1298
1299 /* Check the buffer size */
1300 if (BufferSize < Entry->Event.TotalSize)
1301 {
1302 DPRINT1("Buffer is too small for the pnp-event\n");
1304 }
1305
1306 /* Copy event data to the user buffer */
1307 _SEH2_TRY
1308 {
1310 Entry->Event.TotalSize,
1311 sizeof(UCHAR));
1313 &Entry->Event,
1314 Entry->Event.TotalSize);
1315 }
1317 {
1319 }
1320 _SEH2_END;
1321
1322 DPRINT("NtGetPlugPlayEvent() done\n");
1323
1324 return STATUS_SUCCESS;
1325}
#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:1108
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 1385 of file plugplay.c.

1388{
1389 DPRINT("NtPlugPlayControl(%d %p %lu) called\n",
1390 PlugPlayControlClass, Buffer, BufferLength);
1391
1392 /* Function can only be called from user-mode */
1394 {
1395 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
1396 return STATUS_ACCESS_DENIED;
1397 }
1398
1399 /* Check for Tcb privilege */
1401 UserMode))
1402 {
1403 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
1405 }
1406
1407 /* Probe the buffer */
1408 _SEH2_TRY
1409 {
1412 sizeof(ULONG));
1413 }
1415 {
1417 }
1418 _SEH2_END;
1419
1420 switch (PlugPlayControlClass)
1421 {
1425 // the Flags field is not used anyway
1427 PlugPlayControlClass);
1428
1429// case PlugPlayControlRegisterNewDevice:
1430// case PlugPlayControlDeregisterDevice:
1431
1436
1442 PlugPlayControlClass);
1443
1444// case PlugPlayControlUnlockDevice:
1449
1454
1455// case PlugPlayControlGenerateLegacyDevice:
1456
1461
1466
1467// case PlugPlayControlDeviceClassAssociation:
1468
1473
1474// case PlugPlayControlGetInterfaceDeviceAlias:
1475
1480
1485
1490
1491// case PlugPlayControlTargetDeviceRelation:
1492// case PlugPlayControlQueryConflictList:
1493// case PlugPlayControlRetrieveDock:
1494// case PlugPlayControlHaltDevice:
1495// case PlugPlayControlGetBlockedDriverList:
1496
1497 default:
1499 }
1500
1502}
@ 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:620
static NTSTATUS PiControlQueryRemoveDevice(_In_ PPLUGPLAY_CONTROL_QUERY_REMOVE_DATA ControlData)
Definition: plugplay.c:1161
static NTSTATUS IopRemovePlugPlayEvent(_In_ PPLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData)
Definition: plugplay.c:282
static NTSTATUS IopDeviceStatus(PPLUGPLAY_CONTROL_STATUS_DATA StatusData)
Definition: plugplay.c:813
static NTSTATUS IopGetInterfaceDeviceList(PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA DeviceList)
Definition: plugplay.c:304
static NTSTATUS IopGetDeviceDepth(PPLUGPLAY_CONTROL_DEPTH_DATA DepthData)
Definition: plugplay.c:1060
static NTSTATUS PiControlSyncDeviceAction(_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA DeviceData, _In_ PLUGPLAY_CONTROL_CLASS ControlClass)
Definition: plugplay.c:1106
static NTSTATUS IopInitializeDevice(_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA ControlData)
Definition: plugplay.c:201
static NTSTATUS IopGetDeviceRelations(PPLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA RelationsData)
Definition: plugplay.c:903
static NTSTATUS IopGetDeviceProperty(PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData)
Definition: plugplay.c:382
_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().

◆ PiControlQueryRemoveDevice()

static NTSTATUS PiControlQueryRemoveDevice ( _In_ PPLUGPLAY_CONTROL_QUERY_REMOVE_DATA  ControlData)
static

Definition at line 1161 of file plugplay.c.

1163{
1167
1168 Status = IopCaptureUnicodeString(&DeviceInstance, &ControlData->DeviceInstance);
1169 if (!NT_SUCCESS(Status))
1170 {
1171 return Status;
1172 }
1173
1175 if (DeviceInstance.Buffer != NULL)
1176 {
1177 ExFreePool(DeviceInstance.Buffer);
1178 }
1179 if (DeviceObject == NULL)
1180 {
1181 return STATUS_NO_SUCH_DEVICE;
1182 }
1183
1186
1188
1189 return Status;
1190}

Referenced by NtPlugPlayControl().

◆ PiControlSyncDeviceAction()

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

Definition at line 1106 of file plugplay.c.

1109{
1113
1117
1119 if (!NT_SUCCESS(Status))
1120 {
1121 return Status;
1122 }
1123
1125 if (DeviceInstance.Buffer != NULL)
1126 {
1127 ExFreePool(DeviceInstance.Buffer);
1128 }
1129 if (DeviceObject == NULL)
1130 {
1131 return STATUS_NO_SUCH_DEVICE;
1132 }
1133
1135
1136 switch (ControlClass)
1137 {
1140 break;
1143 break;
1146 break;
1147 default:
1149 break;
1150 }
1151
1153
1155
1156 return Status;
1157}
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 753 of file plugplay.c.

755{
756 return (DeviceNode->State == DeviceNodeStartPending ||
759 DeviceNode->State == DeviceNodeStarted ||
763 DeviceNode->State == DeviceNodeStopped ||
765}
@ 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