ReactOS 0.4.15-dev-7788-g1ad9096
plugplay.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * COPYRIGHT: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/io/pnpmgr/plugplay.c
5 * PURPOSE: Plug-and-play interface routines
6 * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
7 */
8
9/* INCLUDES *****************************************************************/
10
11#include <ntoskrnl.h>
12#define NDEBUG
13#include <debug.h>
14
15typedef struct _PNP_EVENT_ENTRY
16{
20
22{
26
27
28/* GLOBALS *******************************************************************/
29
32
33/* FUNCTIONS *****************************************************************/
34
37
38CODE_SEG("INIT")
41{
43
46 FALSE);
47
48 return STATUS_SUCCESS;
49}
50
53 _In_ const GUID *EventGuid,
56{
57 PPNP_EVENT_ENTRY EventEntry;
59 ULONG TotalSize;
60
61 /* Allocate a big enough buffer */
62 Copy.Length = 0;
63 Copy.MaximumLength = SymbolicLinkName->Length + sizeof(UNICODE_NULL);
64 TotalSize =
66 Copy.MaximumLength;
67
68 EventEntry = ExAllocatePool(NonPagedPool,
69 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
70 if (!EventEntry)
72 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
73
74 /* Fill the buffer with the event GUID */
75 RtlCopyMemory(&EventEntry->Event.EventGuid, EventGuid, sizeof(GUID));
77 EventEntry->Event.TotalSize = TotalSize;
78
79 /* Fill the interface class GUID */
80 RtlCopyMemory(&EventEntry->Event.DeviceClass.ClassGuid, InterfaceClassGuid, sizeof(GUID));
81
82 /* Fill the symbolic link name */
83 RtlCopyMemory(&EventEntry->Event.DeviceClass.SymbolicLinkName,
84 SymbolicLinkName->Buffer, SymbolicLinkName->Length);
85 EventEntry->Event.DeviceClass.SymbolicLinkName[SymbolicLinkName->Length / sizeof(WCHAR)] = UNICODE_NULL;
86
88 &EventEntry->ListEntry);
90 0,
91 FALSE);
92
93 return STATUS_SUCCESS;
94}
95
98 _In_ const GUID *EventGuid,
99 _In_ PUNICODE_STRING DeviceId)
100{
101 PPNP_EVENT_ENTRY EventEntry;
103 ULONG TotalSize;
104
105 /* Allocate a big enough buffer */
106 Copy.Length = 0;
107 Copy.MaximumLength = DeviceId->Length + sizeof(UNICODE_NULL);
108 TotalSize =
110 Copy.MaximumLength;
111
112 EventEntry = ExAllocatePool(NonPagedPool,
113 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
114 if (!EventEntry)
116 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
117
118 /* Fill the buffer with the event GUID */
119 RtlCopyMemory(&EventEntry->Event.EventGuid, EventGuid, sizeof(GUID));
121 EventEntry->Event.TotalSize = TotalSize;
122
123 /* Fill the symbolic link name */
124 RtlCopyMemory(&EventEntry->Event.InstallDevice.DeviceId,
125 DeviceId->Buffer, DeviceId->Length);
126 EventEntry->Event.InstallDevice.DeviceId[DeviceId->Length / sizeof(WCHAR)] = UNICODE_NULL;
127
129
131
132 return STATUS_SUCCESS;
133}
134
135
138 PUNICODE_STRING DeviceIds)
139{
140 PPNP_EVENT_ENTRY EventEntry;
142 ULONG TotalSize;
144
145 ASSERT(DeviceIds);
146
147 /* Allocate a big enough buffer */
148 Copy.Length = 0;
149 Copy.MaximumLength = DeviceIds->Length + sizeof(UNICODE_NULL);
150 TotalSize =
152 Copy.MaximumLength;
153
154 EventEntry = ExAllocatePool(NonPagedPool,
155 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
156 if (!EventEntry)
158 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
159
160 /* Fill the buffer with the event GUID */
161 RtlCopyMemory(&EventEntry->Event.EventGuid,
162 Guid,
163 sizeof(GUID));
165 EventEntry->Event.TotalSize = TotalSize;
166
167 /* Fill the device id */
168 Copy.Buffer = EventEntry->Event.TargetDevice.DeviceIds;
170 if (!NT_SUCCESS(Status))
171 {
172 ExFreePool(EventEntry);
173 return Status;
174 }
175
177 &EventEntry->ListEntry);
179 0,
180 FALSE);
181
182 return STATUS_SUCCESS;
183}
184
189{
191
192 if (RtlEqualUnicodeString(&DeviceNode->InstancePath,
193 DeviceInstanceContext->InstancePath, TRUE))
194 {
195 ObReferenceObject(DeviceNode->PhysicalDeviceObject);
196 DeviceInstanceContext->DeviceObject = DeviceNode->PhysicalDeviceObject;
197
198 /* Stop enumeration */
199 return STATUS_UNSUCCESSFUL;
200 }
201
202 return STATUS_SUCCESS;
203}
204
207{
209 IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT DeviceInstanceContext;
210
211 if (IopRootDeviceNode == NULL)
212 return NULL;
213
214 if (DeviceInstance == NULL ||
215 DeviceInstance->Length == 0)
216 {
218 {
221 }
222 else
223 return NULL;
224 }
225
226 /* Traverse the device tree to find the matching device node */
227 DeviceInstanceContext.InstancePath = DeviceInstance;
228 DeviceInstanceContext.DeviceObject = NULL;
232 &DeviceInstanceContext);
234
235 /* In case of error or instance not found, this will still be NULL from above. */
236 return DeviceInstanceContext.DeviceObject;
237}
238
239static NTSTATUS
241{
243 volatile UNICODE_STRING Name;
244
245 Name.Buffer = NULL;
247 {
248 Name.Length = SrcName->Length;
249 Name.MaximumLength = SrcName->MaximumLength;
250 if (Name.Length > Name.MaximumLength)
251 {
254 }
255
256 if (Name.MaximumLength)
257 {
258 ProbeForRead(SrcName->Buffer,
259 Name.MaximumLength,
260 sizeof(WCHAR));
261 Name.Buffer = ExAllocatePool(NonPagedPool, Name.MaximumLength);
262 if (Name.Buffer == NULL)
263 {
266 }
267
268 memcpy(Name.Buffer, SrcName->Buffer, Name.MaximumLength);
269 }
270
271 *DstName = Name;
272 }
274 {
275 if (Name.Buffer)
276 {
277 ExFreePool(Name.Buffer);
278 }
280 }
281 _SEH2_END;
282
283 return Status;
284}
285
286
287static
291{
296 HANDLE InstanceKey;
297
298 DPRINT("PiControlInitializeDevice(%p)\n", ControlData);
299
300 Status = IopCaptureUnicodeString(&DeviceInstance, &ControlData->DeviceInstance);
301 if (!NT_SUCCESS(Status))
302 {
303 return Status;
304 }
305
306 DPRINT("Device: %wZ\n", &DeviceInstance);
307
308 /* Leave, if the device already exists */
310 if (DeviceObject != NULL)
311 {
312 DPRINT1("Device %wZ already exists!\n", &DeviceInstance);
315 goto done;
316 }
317
318 DPRINT("Device %wZ does not exist!\n", &DeviceInstance);
319
320 /* Create a device node for the device instance */
322 if (!NT_SUCCESS(Status))
323 {
324 DPRINT1("IoCreateDevice() failed (Status 0x%08lx)\n", Status);
325 goto done;
326 }
327
328 /* Allocate a new device node */
330 if (DeviceNode == NULL)
331 {
332 DPRINT1("Failed to allocate a device node!\n");
335 goto done;
336 }
337
338 // Set the device instance of the device node
339 // NOTE: a NULL-terminated string is required for PnpRootRegisterDevice
343 &DeviceNode->InstancePath);
344 if (!NT_SUCCESS(Status))
345 {
346 DPRINT1("RtlDuplicateUnicodeString() failed (Status 0x%08lx)\n", Status);
349 goto done;
350 }
351
355
357 if (!NT_SUCCESS(Status))
358 {
359 DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
362 goto done;
363 }
364
365 /* Write the resource information to the registry */
367
368 // Finish the root device registration
370
371 /* Insert as a root enumerated device node */
373
374 /* Report the device to the user-mode pnp manager */
375 IopQueueDeviceInstallEvent(&GUID_DEVICE_ENUMERATED, &DeviceNode->InstancePath);
376
377 ZwClose(InstanceKey);
378done:
380
381 return Status;
382}
383
384
385/*
386 * Remove the current PnP event from the tail of the event queue
387 * and signal IopPnpNotifyEvent if there is yet another event in the queue.
388 */
389static
393{
394 /* Remove a pnp event entry from the tail of the queue */
396 {
398 }
399
400 /* Signal the next pnp event in the queue */
402 {
404 0,
405 FALSE);
406 }
407
408 return STATUS_SUCCESS;
409}
410
411
412static NTSTATUS
414{
419 GUID FilterGuid;
420 PZZWSTR SymbolicLinkList = NULL, LinkList;
422
424 {
426
427 ProbeForRead(StackList.FilterGuid, sizeof(GUID), sizeof(UCHAR));
428 RtlCopyMemory(&FilterGuid, StackList.FilterGuid, sizeof(GUID));
429
430 if (StackList.Buffer != NULL && StackList.BufferSize != 0)
431 {
432 ProbeForWrite(StackList.Buffer, StackList.BufferSize, sizeof(UCHAR));
433 }
434 }
436 {
438 }
439 _SEH2_END;
440
442 if (NT_SUCCESS(Status))
443 {
444 /* Get the device object */
446 if (DeviceInstance.Buffer != NULL)
447 {
449 }
450 }
451
454
455 if (!NT_SUCCESS(Status))
456 {
457 /* failed */
458 return Status;
459 }
460
461 LinkList = SymbolicLinkList;
463 {
465 }
466 TotalLength = ((SymbolicLinkList - LinkList + 1) * sizeof(WCHAR));
467
469 {
470 if (StackList.Buffer != NULL &&
471 StackList.BufferSize >= TotalLength)
472 {
473 // We've already probed the buffer for writing above.
474 RtlCopyMemory(StackList.Buffer, LinkList, TotalLength);
475 }
476
477 DeviceList->BufferSize = TotalLength;
478 }
480 {
481 ExFreePool(LinkList);
483 }
484 _SEH2_END;
485
486 ExFreePool(LinkList);
487 return STATUS_SUCCESS;
488}
489
490static NTSTATUS
492{
501
502 DPRINT("IopGetDeviceProperty() called\n");
503 DPRINT("Device name: %wZ\n", &PropertyData->DeviceInstance);
504
506 if (!NT_SUCCESS(Status))
507 {
508 return Status;
509 }
510
512 {
513 Property = PropertyData->Property;
514 BufferSize = PropertyData->BufferSize;
517 sizeof(UCHAR));
518 }
520 {
521 if (DeviceInstance.Buffer != NULL)
522 {
524 }
526 }
527 _SEH2_END;
528
529 /* Get the device object */
531 if (DeviceInstance.Buffer != NULL)
532 {
534 }
535 if (DeviceObject == NULL)
536 {
538 }
539
541 if (Buffer == NULL)
542 {
545 }
546
547
548 DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode;
549
551 {
552 if (BufferSize < sizeof(CM_POWER_DATA))
553 {
554 BufferSize = 0;
556 }
557 else
558 {
560 PCM_POWER_DATA PowerData;
563
564 PowerData = (PCM_POWER_DATA)Buffer;
565 RtlZeroMemory(PowerData, sizeof(CM_POWER_DATA));
566 PowerData->PD_Size = sizeof(CM_POWER_DATA);
567
570 DeviceCapabilities.Version = 1;
571 DeviceCapabilities.Address = -1;
572 DeviceCapabilities.UINumber = -1;
573
574 Stack.Parameters.DeviceCapabilities.Capabilities = &DeviceCapabilities;
575
579 &Stack);
580 if (NT_SUCCESS(Status))
581 {
582 DPRINT("Got device capabiliities\n");
583
584 PowerData->PD_MostRecentPowerState = PowerDeviceD0; // FIXME
585 if (DeviceCapabilities.DeviceD1)
587 if (DeviceCapabilities.DeviceD2)
589 if (DeviceCapabilities.WakeFromD0)
591 if (DeviceCapabilities.WakeFromD1)
593 if (DeviceCapabilities.WakeFromD2)
595 if (DeviceCapabilities.WakeFromD3)
597 if (DeviceCapabilities.WarmEjectSupported)
599 PowerData->PD_D1Latency = DeviceCapabilities.D1Latency;
600 PowerData->PD_D2Latency = DeviceCapabilities.D2Latency;
601 PowerData->PD_D3Latency = DeviceCapabilities.D3Latency;
603 &DeviceCapabilities.DeviceState,
604 sizeof(DeviceCapabilities.DeviceState));
605 PowerData->PD_DeepestSystemWake = DeviceCapabilities.SystemWake;
606 }
607 else
608 {
609 DPRINT("IRP_MN_QUERY_CAPABILITIES failed (Status 0x%08lx)\n", Status);
610
613 }
614 }
615 }
617 {
619 BufferSize = 0;
621 }
623 {
624 if (BufferSize < sizeof(DeviceNode->HardwareRemovalPolicy))
625 {
626 BufferSize = 0;
628 }
629 else
630 {
631 BufferSize = sizeof(DeviceNode->HardwareRemovalPolicy);
633 &DeviceNode->HardwareRemovalPolicy,
634 BufferSize);
635 }
636 }
637 else
638 {
639 switch (Property)
640 {
643 break;
644
647 break;
648
651 break;
652
655 break;
656
659 break;
660
663 break;
664
667 break;
668
671 break;
672
675 break;
676
677#if (WINVER >= _WIN32_WINNT_WS03)
680 BufferSize = 0;
682 break;
683#endif
684
685#if (WINVER >= _WIN32_WINNT_WIN7)
688 break;
689#endif
690
691 default:
692 BufferSize = 0;
694 break;
695 }
696
697 if (Status == STATUS_SUCCESS)
698 {
702 Buffer,
703 &BufferSize);
704 }
705 }
706
708
709 if (NT_SUCCESS(Status))
710 {
712 {
714 PropertyData->BufferSize = BufferSize;
715 }
717 {
719 }
720 _SEH2_END;
721 }
722
724 return Status;
725}
726
727
728static NTSTATUS
730{
731 UNICODE_STRING RootDeviceName;
734 PDEVICE_NODE RelatedDeviceNode;
735 UNICODE_STRING TargetDeviceInstance;
737 ULONG Relation = 0;
739
740 DPRINT("IopGetRelatedDevice() called\n");
741 DPRINT("Device name: %wZ\n", &RelatedDeviceData->TargetDeviceInstance);
742
743 Status = IopCaptureUnicodeString(&TargetDeviceInstance, &RelatedDeviceData->TargetDeviceInstance);
744 if (!NT_SUCCESS(Status))
745 {
746 return Status;
747 }
748
750 {
751 Relation = RelatedDeviceData->Relation;
752 MaximumLength = RelatedDeviceData->RelatedDeviceInstanceLength;
753 ProbeForWrite(RelatedDeviceData->RelatedDeviceInstance,
755 sizeof(WCHAR));
756 }
758 {
759 if (TargetDeviceInstance.Buffer != NULL)
760 {
761 ExFreePool(TargetDeviceInstance.Buffer);
762 }
764 }
765 _SEH2_END;
766
767 RtlInitUnicodeString(&RootDeviceName,
768 L"HTREE\\ROOT\\0");
769 if (RtlEqualUnicodeString(&TargetDeviceInstance,
770 &RootDeviceName,
771 TRUE))
772 {
774 if (TargetDeviceInstance.Buffer != NULL)
775 {
776 ExFreePool(TargetDeviceInstance.Buffer);
777 }
778 }
779 else
780 {
781 /* Get the device object */
782 DeviceObject = IopGetDeviceObjectFromDeviceInstance(&TargetDeviceInstance);
783 if (TargetDeviceInstance.Buffer != NULL)
784 {
785 ExFreePool(TargetDeviceInstance.Buffer);
786 }
787 if (DeviceObject == NULL)
789
790 DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode;
791 }
792
793 switch (Relation)
794 {
796 RelatedDeviceNode = DeviceNode->Parent;
797 break;
798
800 RelatedDeviceNode = DeviceNode->Child;
801 break;
802
804 RelatedDeviceNode = DeviceNode->Sibling;
805 break;
806
807 default:
808 if (DeviceObject != NULL)
809 {
811 }
812
814 }
815
816 if (RelatedDeviceNode == NULL)
817 {
818 if (DeviceObject)
819 {
821 }
822
824 }
825
826 if (RelatedDeviceNode->InstancePath.Length > MaximumLength)
827 {
828 if (DeviceObject)
829 {
831 }
832
834 }
835
836 /* Copy related device instance name */
838 {
839 RtlCopyMemory(RelatedDeviceData->RelatedDeviceInstance,
840 RelatedDeviceNode->InstancePath.Buffer,
841 RelatedDeviceNode->InstancePath.Length);
842 RelatedDeviceData->RelatedDeviceInstanceLength = RelatedDeviceNode->InstancePath.Length;
843 }
845 {
847 }
848 _SEH2_END;
849
850 if (DeviceObject != NULL)
851 {
853 }
854
855 DPRINT("IopGetRelatedDevice() done\n");
856
857 return Status;
858}
859
860static
864{
865 return (DeviceNode->State == DeviceNodeStartPending ||
868 DeviceNode->State == DeviceNodeStarted ||
872 DeviceNode->State == DeviceNodeStopped ||
874}
875
876static ULONG
878{
880
881 if (DeviceNode->Parent == IopRootDeviceNode)
883
884 // FIXME: review for deleted and removed states
887
890
891 if (DeviceNode->UserFlags & DNUF_WILL_BE_REMOVED)
893
894 if (DeviceNode->Flags & DNF_HAS_PROBLEM)
896
899
900 if (DeviceNode->Flags & DNF_DRIVER_BLOCKED)
902
905
908
909 if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
911
912 if (DeviceNode->UserFlags & DNUF_DONT_SHOW_IN_UI)
914
915 if (!(DeviceNode->UserFlags & DNUF_NOT_DISABLEABLE))
917
918 return Output;
919}
920
921static NTSTATUS
923{
926 ULONG Operation = 0;
927 ULONG DeviceStatus = 0;
928 ULONG DeviceProblem = 0;
931
932 DPRINT("IopDeviceStatus() called\n");
933
935 if (!NT_SUCCESS(Status))
936 {
937 return Status;
938 }
939
940 DPRINT("Device name: '%wZ'\n", &DeviceInstance);
941
943 {
944 Operation = StatusData->Operation;
946 {
947 DeviceStatus = StatusData->DeviceStatus;
948 DeviceProblem = StatusData->DeviceProblem;
949 }
950 }
952 {
953 if (DeviceInstance.Buffer != NULL)
954 {
956 }
958 }
959 _SEH2_END;
960
961 /* Get the device object */
963 if (DeviceInstance.Buffer != NULL)
964 {
966 }
967 if (DeviceObject == NULL)
968 {
970 }
971
973
974 switch (Operation)
975 {
977 DPRINT("Get status data\n");
978 DeviceStatus = IopGetDeviceNodeStatus(DeviceNode);
979 DeviceProblem = DeviceNode->Problem;
980 break;
981
983 DPRINT1("Set status data is NOT SUPPORTED\n");
984 break;
985
987 DPRINT1("FIXME: Clear status data!\n");
988 break;
989 }
990
992
994 {
996 {
997 StatusData->DeviceStatus = DeviceStatus;
998 StatusData->DeviceProblem = DeviceProblem;
999 }
1001 {
1003 }
1004 _SEH2_END;
1005 }
1006
1007 return Status;
1008}
1009
1010static
1013{
1018 PDEVICE_RELATIONS DeviceRelations = NULL;
1019 PDEVICE_OBJECT ChildDeviceObject;
1020 PDEVICE_NODE ChildDeviceNode;
1021 ULONG i;
1022 ULONG Relations;
1024 ULONG BufferLeft;
1025 PWCHAR Buffer, Ptr;
1027
1028 DPRINT("IopGetDeviceRelations() called\n");
1029 DPRINT("Device name: %wZ\n", &RelationsData->DeviceInstance);
1030 DPRINT("Relations: %lu\n", RelationsData->Relations);
1031 DPRINT("BufferSize: %lu\n", RelationsData->BufferSize);
1032 DPRINT("Buffer: %p\n", RelationsData->Buffer);
1033
1034 _SEH2_TRY
1035 {
1036 Relations = RelationsData->Relations;
1037 BufferSize = RelationsData->BufferSize;
1038 Buffer = RelationsData->Buffer;
1039
1041 }
1043 {
1045 }
1046 _SEH2_END;
1047
1049 if (!NT_SUCCESS(Status))
1050 {
1051 DPRINT1("IopCaptureUnicodeString() failed (Status 0x%08lx)\n", Status);
1052 return Status;
1053 }
1054
1055 /* Get the device object */
1057 if (DeviceObject == NULL)
1058 {
1059 DPRINT1("IopGetDeviceObjectFromDeviceInstance() returned NULL\n");
1061 goto done;
1062 }
1063
1064 switch (Relations)
1065 {
1067 Stack.Parameters.QueryDeviceRelations.Type = EjectionRelations;
1068 break;
1069
1071 Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
1072 break;
1073
1075 Stack.Parameters.QueryDeviceRelations.Type = PowerRelations;
1076 break;
1077
1078 case PNP_BUS_RELATIONS:
1079 Stack.Parameters.QueryDeviceRelations.Type = BusRelations;
1080 break;
1081
1082 default:
1084 goto done;
1085 }
1086
1090 &Stack);
1091 if (!NT_SUCCESS(Status))
1092 {
1093 DPRINT1("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status);
1094 goto done;
1095 }
1096
1097 DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
1098
1099 DPRINT("Found %d device relations\n", DeviceRelations->Count);
1100
1101 _SEH2_TRY
1102 {
1103 RequiredSize = 0;
1104 BufferLeft = BufferSize;
1105 Ptr = Buffer;
1106
1107 for (i = 0; i < DeviceRelations->Count; i++)
1108 {
1109 ChildDeviceObject = DeviceRelations->Objects[i];
1110
1111 ChildDeviceNode = IopGetDeviceNode(ChildDeviceObject);
1112 if (ChildDeviceNode)
1113 {
1114 DPRINT("Device instance: %wZ\n", &ChildDeviceNode->InstancePath);
1115 DPRINT("RequiredSize: %hu\n", ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1116
1117 if (Ptr != NULL)
1118 {
1119 if (BufferLeft < ChildDeviceNode->InstancePath.Length + 2 * sizeof(WCHAR))
1120 {
1122 break;
1123 }
1124
1126 ChildDeviceNode->InstancePath.Buffer,
1127 ChildDeviceNode->InstancePath.Length);
1128 Ptr = (PWCHAR)((ULONG_PTR)Ptr + ChildDeviceNode->InstancePath.Length);
1129 *Ptr = UNICODE_NULL;
1130 Ptr = (PWCHAR)((ULONG_PTR)Ptr + sizeof(WCHAR));
1131
1132 BufferLeft -= (ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1133 }
1134
1135 RequiredSize += (ChildDeviceNode->InstancePath.Length + sizeof(WCHAR));
1136 }
1137 }
1138
1139 if (Ptr != NULL && BufferLeft >= sizeof(WCHAR))
1140 *Ptr = UNICODE_NULL;
1141
1142 if (RequiredSize > 0)
1143 RequiredSize += sizeof(WCHAR);
1144
1145 DPRINT("BufferSize: %lu RequiredSize: %lu\n", RelationsData->BufferSize, RequiredSize);
1146
1147 RelationsData->BufferSize = RequiredSize;
1148 }
1150 {
1152 }
1153 _SEH2_END;
1154
1155done:
1156 if (DeviceRelations != NULL)
1157 ExFreePool(DeviceRelations);
1158
1159 if (DeviceObject != NULL)
1161
1162 if (DeviceInstance.Buffer != NULL)
1163 ExFreePool(DeviceInstance.Buffer);
1164
1165 return Status;
1166}
1167
1168static NTSTATUS
1170{
1175
1176 DPRINT("IopGetDeviceDepth() called\n");
1177 DPRINT("Device name: %wZ\n", &DepthData->DeviceInstance);
1178
1180 if (!NT_SUCCESS(Status))
1181 {
1182 return Status;
1183 }
1184
1185 /* Get the device object */
1187 if (DeviceInstance.Buffer != NULL)
1188 {
1189 ExFreePool(DeviceInstance.Buffer);
1190 }
1191 if (DeviceObject == NULL)
1192 {
1193 return STATUS_NO_SUCH_DEVICE;
1194 }
1195
1197
1198 _SEH2_TRY
1199 {
1200 DepthData->Depth = DeviceNode->Level;
1201 }
1203 {
1205 }
1206 _SEH2_END;
1207
1209
1210 return Status;
1211}
1212
1213static
1218{
1222
1226
1228 if (!NT_SUCCESS(Status))
1229 {
1230 return Status;
1231 }
1232
1234 if (DeviceInstance.Buffer != NULL)
1235 {
1236 ExFreePool(DeviceInstance.Buffer);
1237 }
1238 if (DeviceObject == NULL)
1239 {
1240 return STATUS_NO_SUCH_DEVICE;
1241 }
1242
1244
1245 switch (ControlClass)
1246 {
1249 break;
1252 break;
1255 break;
1256 default:
1258 break;
1259 }
1260
1262
1264
1265 return Status;
1266}
1267
1268static
1272{
1276
1277 Status = IopCaptureUnicodeString(&DeviceInstance, &ControlData->DeviceInstance);
1278 if (!NT_SUCCESS(Status))
1279 {
1280 return Status;
1281 }
1282
1284 if (DeviceInstance.Buffer != NULL)
1285 {
1286 ExFreePool(DeviceInstance.Buffer);
1287 }
1288 if (DeviceObject == NULL)
1289 {
1290 return STATUS_NO_SUCH_DEVICE;
1291 }
1292
1295
1297
1298 return Status;
1299}
1300
1301/* PUBLIC FUNCTIONS **********************************************************/
1302
1303/*
1304 * Plug and Play event structure used by NtGetPlugPlayEvent.
1305 *
1306 * EventGuid
1307 * Can be one of the following values:
1308 * GUID_HWPROFILE_QUERY_CHANGE
1309 * GUID_HWPROFILE_CHANGE_CANCELLED
1310 * GUID_HWPROFILE_CHANGE_COMPLETE
1311 * GUID_TARGET_DEVICE_QUERY_REMOVE
1312 * GUID_TARGET_DEVICE_REMOVE_CANCELLED
1313 * GUID_TARGET_DEVICE_REMOVE_COMPLETE
1314 * GUID_PNP_CUSTOM_NOTIFICATION
1315 * GUID_PNP_POWER_NOTIFICATION
1316 * GUID_DEVICE_* (see above)
1317 *
1318 * EventCategory
1319 * Type of the event that happened.
1320 *
1321 * Result
1322 * ?
1323 *
1324 * Flags
1325 * ?
1326 *
1327 * TotalSize
1328 * Size of the event block including the device IDs and other
1329 * per category specific fields.
1330 */
1331
1332/*
1333 * NtGetPlugPlayEvent
1334 *
1335 * Returns one Plug & Play event from a global queue.
1336 *
1337 * Parameters
1338 * Reserved1
1339 * Reserved2
1340 * Always set to zero.
1341 *
1342 * Buffer
1343 * The buffer that will be filled with the event information on
1344 * successful return from the function.
1345 *
1346 * BufferSize
1347 * Size of the buffer pointed by the Buffer parameter. If the
1348 * buffer size is not large enough to hold the whole event
1349 * information, error STATUS_BUFFER_TOO_SMALL is returned and
1350 * the buffer remains untouched.
1351 *
1352 * Return Values
1353 * STATUS_PRIVILEGE_NOT_HELD
1354 * STATUS_BUFFER_TOO_SMALL
1355 * STATUS_SUCCESS
1356 *
1357 * Remarks
1358 * This function isn't multi-thread safe!
1359 *
1360 * @implemented
1361 */
1363NTAPI
1368{
1371
1372 DPRINT("NtGetPlugPlayEvent() called\n");
1373
1374 /* Function can only be called from user-mode */
1376 {
1377 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
1378 return STATUS_ACCESS_DENIED;
1379 }
1380
1381 /* Check for Tcb privilege */
1383 UserMode))
1384 {
1385 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
1387 }
1388
1389 /* Wait for a PnP event */
1390 DPRINT("Waiting for pnp notification event\n");
1393 UserMode,
1394 FALSE,
1395 NULL);
1397 {
1398 DPRINT("KeWaitForSingleObject() failed (Status %lx)\n", Status);
1400 return Status;
1401 }
1402
1403 /* Get entry from the tail of the queue */
1406 ListEntry);
1407
1408 /* Check the buffer size */
1409 if (BufferSize < Entry->Event.TotalSize)
1410 {
1411 DPRINT1("Buffer is too small for the pnp-event\n");
1413 }
1414
1415 /* Copy event data to the user buffer */
1416 _SEH2_TRY
1417 {
1419 Entry->Event.TotalSize,
1420 sizeof(UCHAR));
1422 &Entry->Event,
1423 Entry->Event.TotalSize);
1424 }
1426 {
1428 }
1429 _SEH2_END;
1430
1431 DPRINT("NtGetPlugPlayEvent() done\n");
1432
1433 return STATUS_SUCCESS;
1434}
1435
1436/*
1437 * NtPlugPlayControl
1438 *
1439 * A function for doing various Plug & Play operations from user mode.
1440 *
1441 * Parameters
1442 * PlugPlayControlClass
1443 * 0x00 Reenumerate device tree
1444 *
1445 * Buffer points to UNICODE_STRING decribing the instance
1446 * path (like "HTREE\ROOT\0" or "Root\ACPI_HAL\0000"). For
1447 * more information about instance paths see !devnode command
1448 * in kernel debugger or look at "Inside Windows 2000" book,
1449 * chapter "Driver Loading, Initialization, and Installation".
1450 *
1451 * 0x01 Register new device
1452 * 0x02 Deregister device
1453 * 0x03 Initialize device
1454 * 0x04 Start device
1455 * 0x06 Query and remove device
1456 * 0x07 User response
1457 *
1458 * Called after processing the message from NtGetPlugPlayEvent.
1459 *
1460 * 0x08 Generate legacy device
1461 * 0x09 Get interface device list
1462 * 0x0A Get property data
1463 * 0x0B Device class association (Registration)
1464 * 0x0C Get related device
1465 * 0x0D Get device interface alias
1466 * 0x0E Get/set/clear device status
1467 * 0x0F Get device depth
1468 * 0x10 Query device relations
1469 * 0x11 Query target device relation
1470 * 0x12 Query conflict list
1471 * 0x13 Retrieve dock data
1472 * 0x14 Reset device
1473 * 0x15 Halt device
1474 * 0x16 Get blocked driver data
1475 *
1476 * Buffer
1477 * The buffer contains information that is specific to each control
1478 * code. The buffer is read-only.
1479 *
1480 * BufferSize
1481 * Size of the buffer pointed by the Buffer parameter. If the
1482 * buffer size specifies incorrect value for specified control
1483 * code, error ??? is returned.
1484 *
1485 * Return Values
1486 * STATUS_PRIVILEGE_NOT_HELD
1487 * STATUS_SUCCESS
1488 * ...
1489 *
1490 * @unimplemented
1491 */
1493NTAPI
1497{
1498 DPRINT("NtPlugPlayControl(%d %p %lu) called\n",
1499 PlugPlayControlClass, Buffer, BufferLength);
1500
1501 /* Function can only be called from user-mode */
1503 {
1504 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
1505 return STATUS_ACCESS_DENIED;
1506 }
1507
1508 /* Check for Tcb privilege */
1510 UserMode))
1511 {
1512 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
1514 }
1515
1516 /* Probe the buffer */
1517 _SEH2_TRY
1518 {
1521 sizeof(ULONG));
1522 }
1524 {
1526 }
1527 _SEH2_END;
1528
1529 switch (PlugPlayControlClass)
1530 {
1534 // the Flags field is not used anyway
1536 PlugPlayControlClass);
1537
1538// case PlugPlayControlRegisterNewDevice:
1539// case PlugPlayControlDeregisterDevice:
1540
1545
1551 PlugPlayControlClass);
1552
1553// case PlugPlayControlUnlockDevice:
1558
1563
1564// case PlugPlayControlGenerateLegacyDevice:
1565
1570
1575
1576// case PlugPlayControlDeviceClassAssociation:
1577
1582
1583// case PlugPlayControlGetInterfaceDeviceAlias:
1584
1589
1594
1599
1600// case PlugPlayControlTargetDeviceRelation:
1601// case PlugPlayControlQueryConflictList:
1602// case PlugPlayControlRetrieveDock:
1603// case PlugPlayControlHaltDevice:
1604// case PlugPlayControlGetBlockedDriverList:
1605
1606 default:
1608 }
1609
1611}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
@ DeviceNode
Definition: Node.h:9
unsigned char BOOLEAN
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
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
static BOOL InstallDevice(PCWSTR DeviceInstance, BOOL ShowWizard)
Definition: install.c:55
@ Reserved2
Definition: bcd.h:202
@ Reserved1
Definition: bcd.h:201
#define UNIMPLEMENTED
Definition: debug.h:115
#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
static const WCHAR ControlClass[]
Definition: cfgmgr.c:44
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PDEVICE_LIST DeviceList
Definition: utils.c:27
static const WCHAR DeviceInstance[]
Definition: interface.c:28
VOID Copy(PVOID Src, PVOID Dst, ULONG NumBytes)
Definition: mmixer.c:126
#define InsertHeadList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define RemoveTailList(ListHead)
Definition: env_spec_w32.h:975
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#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
FP_OP Operation
Definition: fpcontrol.c:150
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_In_ WDFDEVICE _In_ PWDF_DEVICE_INTERFACE_PROPERTY_DATA PropertyData
_Must_inspect_result_ _In_ WDFDEVICE _In_ REFGUID EventGuid
Status
Definition: gdiplustypes.h:25
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 RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ASSERT(a)
Definition: mode.c:44
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
#define KernelMode
Definition: asm.h:34
#define UserMode
Definition: asm.h:35
#define KeGetPreviousMode()
Definition: ketypes.h:1115
#define PNP_PROPERTY_UI_NUMBER
Definition: cmtypes.h:34
#define PNP_SET_DEVICE_STATUS
Definition: cmtypes.h:60
#define PNP_PROPERTY_REMOVAL_POLICY
Definition: cmtypes.h:40
enum _PLUGPLAY_CONTROL_CLASS PLUGPLAY_CONTROL_CLASS
#define PNP_GET_SIBLING_DEVICE
Definition: cmtypes.h:54
#define PNP_PROPERTY_POWER_DATA
Definition: cmtypes.h:39
#define PNP_GET_PARENT_DEVICE
Definition: cmtypes.h:52
#define PNP_PROPERTY_ENUMERATOR_NAME
Definition: cmtypes.h:43
#define PNP_GET_CHILD_DEVICE
Definition: cmtypes.h:53
@ TargetDeviceChangeEvent
Definition: cmtypes.h:257
@ DeviceClassChangeEvent
Definition: cmtypes.h:258
@ DeviceInstallEvent
Definition: cmtypes.h:260
#define PNP_PROPERTY_PHYSICAL_DEVICE_OBJECT_NAME
Definition: cmtypes.h:35
@ 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
#define PNP_POWER_RELATIONS
Definition: cmtypes.h:68
#define PNP_PROPERTY_INSTALL_STATE
Definition: cmtypes.h:45
#define PNP_BUS_RELATIONS
Definition: cmtypes.h:69
#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_CLEAR_DEVICE_STATUS
Definition: cmtypes.h:61
#define PNP_PROPERTY_LEGACYBUSTYPE
Definition: cmtypes.h:37
#define PNP_GET_DEVICE_STATUS
Definition: cmtypes.h:59
#define PNP_PROPERTY_BUSTYPEGUID
Definition: cmtypes.h:36
#define PNP_REMOVAL_RELATIONS
Definition: cmtypes.h:67
#define PNP_PROPERTY_ADDRESS
Definition: cmtypes.h:42
#define PNP_PROPERTY_BUSNUMBER
Definition: cmtypes.h:38
#define PNP_EJECT_RELATIONS
Definition: cmtypes.h:66
#define PNP_PROPERTY_CONTAINERID
Definition: cmtypes.h:47
#define DNUF_WILL_BE_REMOVED
Definition: iotypes.h:208
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:182
#define DNF_ENUMERATED
Definition: iotypes.h:174
@ DeviceNodeDriversAdded
Definition: iotypes.h:424
@ DeviceNodeStopped
Definition: iotypes.h:431
@ DeviceNodeRestartCompletion
Definition: iotypes.h:432
@ DeviceNodeInitialized
Definition: iotypes.h:423
@ DeviceNodeStartPostWork
Definition: iotypes.h:428
@ DeviceNodeStarted
Definition: iotypes.h:429
@ DeviceNodeStartCompletion
Definition: iotypes.h:427
@ DeviceNodeEnumerateCompletion
Definition: iotypes.h:434
@ DeviceNodeEnumeratePending
Definition: iotypes.h:433
@ DeviceNodeQueryStopped
Definition: iotypes.h:430
@ DeviceNodeStartPending
Definition: iotypes.h:426
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
#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
#define DNF_IDS_QUERIED
Definition: iotypes.h:175
#define DNF_MADEUP
Definition: iotypes.h:170
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define UNREACHABLE
#define UNICODE_NULL
_NullNull_terminated_ WCHAR * PZZWSTR
Definition: ntbasedef.h:420
@ SynchronizationEvent
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
@ PiActionResetDevice
Definition: io.h:528
@ PiActionStartDevice
Definition: io.h:530
@ PiActionEnumDeviceTree
Definition: io.h:526
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
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:229
NTSTATUS PnpRootRegisterDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnproot.c:107
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
NTSTATUS IopFreeDeviceNode(IN PDEVICE_NODE DeviceNode)
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack)
PNP_DEVNODE_STATE PiSetDevNodeState(_In_ PDEVICE_NODE DeviceNode, _In_ PNP_DEVNODE_STATE NewState)
Definition: devnode.c:108
enum _DEVICE_ACTION DEVICE_ACTION
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
NTSTATUS PiPerformSyncDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action)
Perfom a device operation synchronously via PiQueueDeviceAction.
Definition: devaction.c:2718
NTSTATUS PnpRootCreateDeviceObject(OUT PDEVICE_OBJECT *DeviceObject)
Definition: pnproot.c:167
const LUID SeTcbPrivilege
Definition: priv.c:26
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
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
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define STATUS_USER_APC
Definition: ntstatus.h:78
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define L(x)
Definition: ntvdm.h:50
struct _IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT
static BOOLEAN PiIsDevNodeStarted(_In_ PDEVICE_NODE DeviceNode)
Definition: plugplay.c:862
static NTSTATUS IopGetRelatedDevice(PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA RelatedDeviceData)
Definition: plugplay.c:729
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:137
NTSTATUS IopInitPlugPlayEvents(VOID)
Definition: plugplay.c:40
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:206
static NTSTATUS PiControlQueryRemoveDevice(_In_ PPLUGPLAY_CONTROL_QUERY_REMOVE_DATA ControlData)
Definition: plugplay.c:1270
static NTSTATUS IopRemovePlugPlayEvent(_In_ PPLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData)
Definition: plugplay.c:391
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:606
NTSTATUS IopQueueDeviceInstallEvent(_In_ const GUID *EventGuid, _In_ PUNICODE_STRING DeviceId)
Definition: plugplay.c:97
static NTSTATUS IopCaptureUnicodeString(PUNICODE_STRING DstName, PUNICODE_STRING SrcName)
Definition: plugplay.c:240
static NTSTATUS IopDeviceStatus(PPLUGPLAY_CONTROL_STATUS_DATA StatusData)
Definition: plugplay.c:922
struct _PNP_EVENT_ENTRY * PPNP_EVENT_ENTRY
static ULONG IopGetDeviceNodeStatus(PDEVICE_NODE DeviceNode)
Definition: plugplay.c:877
NTSTATUS IopFindDeviceInstanceTraverse(_In_ PDEVICE_NODE DeviceNode, _Inout_ PVOID Context)
Definition: plugplay.c:186
static NTSTATUS IopGetInterfaceDeviceList(PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA DeviceList)
Definition: plugplay.c:413
static NTSTATUS IopGetDeviceDepth(PPLUGPLAY_CONTROL_DEPTH_DATA DepthData)
Definition: plugplay.c:1169
static LIST_ENTRY IopPnpEventQueueHead
Definition: plugplay.c:30
NTSTATUS NTAPI NtGetPlugPlayEvent(IN ULONG Reserved1, IN ULONG Reserved2, OUT PPLUGPLAY_EVENT_BLOCK Buffer, IN ULONG BufferSize)
Definition: plugplay.c:1364
NTSTATUS IopQueueDeviceChangeEvent(_In_ const GUID *EventGuid, _In_ const GUID *InterfaceClassGuid, _In_ PUNICODE_STRING SymbolicLinkName)
Definition: plugplay.c:52
static NTSTATUS PiControlSyncDeviceAction(_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA DeviceData, _In_ PLUGPLAY_CONTROL_CLASS ControlClass)
Definition: plugplay.c:1215
struct _IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT * PIOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT
NTSTATUS NTAPI NtPlugPlayControl(IN PLUGPLAY_CONTROL_CLASS PlugPlayControlClass, IN OUT PVOID Buffer, IN ULONG BufferLength)
Definition: plugplay.c:1494
static NTSTATUS IopGetDeviceRelations(PPLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA RelationsData)
Definition: plugplay.c:1012
static NTSTATUS IopGetDeviceProperty(PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData)
Definition: plugplay.c:491
static NTSTATUS PiControlInitializeDevice(_In_ PPLUGPLAY_CONTROL_DEVICE_CONTROL_DATA ControlData)
Definition: plugplay.c:289
static KEVENT IopPnpNotifyEvent
Definition: plugplay.c:31
struct _PNP_EVENT_ENTRY PNP_EVENT_ENTRY
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 _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
@ Output
Definition: arc.h:85
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:71
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
base of all file and directory entries
Definition: entries.h:83
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:892
UNICODE_STRING InstancePath
Definition: iotypes.h:895
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
UNICODE_STRING DeviceInstance
Definition: cmtypes.h:525
UNICODE_STRING DeviceInstance
Definition: cmtypes.h:534
WCHAR SymbolicLinkName[ANYSIZE_ARRAY]
Definition: cmtypes.h:416
struct _PLUGPLAY_EVENT_BLOCK::@2388::@2391 TargetDevice
struct _PLUGPLAY_EVENT_BLOCK::@2388::@2390 DeviceClass
struct _PLUGPLAY_EVENT_BLOCK::@2388::@2392 InstallDevice
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
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG TotalLength
Definition: usbdlib.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING SymbolicLinkName
Definition: wdfdevice.h:3739
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3769
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID _Out_ PULONG RequiredSize
Definition: wdfdevice.h:4439
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
#define DeviceCapabilities
Definition: wingdi.h:4449
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList
_Must_inspect_result_ __drv_aliasesMem PDEVICE_OBJECT _In_ PDEVICE_OBJECT TargetDevice
Definition: iofuncs.h:691
_In_ CONST GUID * InterfaceClassGuid
Definition: iofuncs.h:1136
DEVICE_CAPABILITIES
Definition: iotypes.h:965
@ EjectionRelations
Definition: iotypes.h:2153
@ RemovalRelations
Definition: iotypes.h:2155
@ BusRelations
Definition: iotypes.h:2152
@ PowerRelations
Definition: iotypes.h:2154
#define DO_BUS_ENUMERATED_DEVICE
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
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_CAPABILITIES
@ UserRequest
Definition: ketypes.h:421
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175