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@t-online.de>
9 /* INCLUDES *****************************************************************/
15 #if defined (ALLOC_PRAGMA)
16 #pragma alloc_text(INIT, IopInitPlugPlayEvents)
19 typedef struct _PNP_EVENT_ENTRY
22 PLUGPLAY_EVENT_BLOCK Event
;
23 } PNP_EVENT_ENTRY
, *PPNP_EVENT_ENTRY
;
26 /* GLOBALS *******************************************************************/
28 static LIST_ENTRY IopPnpEventQueueHead
;
29 static KEVENT IopPnpNotifyEvent
;
31 /* FUNCTIONS *****************************************************************/
33 NTSTATUS INIT_FUNCTION
34 IopInitPlugPlayEvents(VOID
)
36 InitializeListHead(&IopPnpEventQueueHead
);
38 KeInitializeEvent(&IopPnpNotifyEvent
,
42 return STATUS_SUCCESS
;
46 IopQueueTargetDeviceEvent(const GUID
*Guid
,
47 PUNICODE_STRING DeviceIds
)
49 PPNP_EVENT_ENTRY EventEntry
;
56 /* Allocate a big enough buffer */
58 Copy
.MaximumLength
= DeviceIds
->Length
+ sizeof(UNICODE_NULL
);
60 FIELD_OFFSET(PLUGPLAY_EVENT_BLOCK
, TargetDevice
.DeviceIds
) +
63 EventEntry
= ExAllocatePool(NonPagedPool
,
64 TotalSize
+ FIELD_OFFSET(PNP_EVENT_ENTRY
, Event
));
66 return STATUS_INSUFFICIENT_RESOURCES
;
68 /* Fill the buffer with the event GUID */
69 RtlCopyMemory(&EventEntry
->Event
.EventGuid
,
72 EventEntry
->Event
.EventCategory
= TargetDeviceChangeEvent
;
73 EventEntry
->Event
.TotalSize
= TotalSize
;
75 /* Fill the device id */
76 Copy
.Buffer
= EventEntry
->Event
.TargetDevice
.DeviceIds
;
77 Status
= RtlAppendUnicodeStringToString(&Copy
, DeviceIds
);
78 if (!NT_SUCCESS(Status
))
81 InsertHeadList(&IopPnpEventQueueHead
,
82 &EventEntry
->ListEntry
);
83 KeSetEvent(&IopPnpNotifyEvent
,
87 return STATUS_SUCCESS
;
92 * Remove the current PnP event from the tail of the event queue
93 * and signal IopPnpNotifyEvent if there is yet another event in the queue.
96 IopRemovePlugPlayEvent(VOID
)
98 /* Remove a pnp event entry from the tail of the queue */
99 if (!IsListEmpty(&IopPnpEventQueueHead
))
101 ExFreePool(CONTAINING_RECORD(RemoveTailList(&IopPnpEventQueueHead
), PNP_EVENT_ENTRY
, ListEntry
));
104 /* Signal the next pnp event in the queue */
105 if (!IsListEmpty(&IopPnpEventQueueHead
))
107 KeSetEvent(&IopPnpNotifyEvent
,
112 return STATUS_SUCCESS
;
115 static PDEVICE_OBJECT
116 IopTraverseDeviceNode(PDEVICE_NODE Node
, PUNICODE_STRING DeviceInstance
)
118 PDEVICE_OBJECT DeviceObject
;
119 PDEVICE_NODE ChildNode
;
121 if (RtlEqualUnicodeString(&Node
->InstancePath
,
122 DeviceInstance
, TRUE
))
124 ObReferenceObject(Node
->PhysicalDeviceObject
);
125 return Node
->PhysicalDeviceObject
;
128 /* Traversal of all children nodes */
129 for (ChildNode
= Node
->Child
;
131 ChildNode
= ChildNode
->Sibling
)
133 DeviceObject
= IopTraverseDeviceNode(ChildNode
, DeviceInstance
);
134 if (DeviceObject
!= NULL
)
145 IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance
)
147 if (IopRootDeviceNode
== NULL
)
150 if (DeviceInstance
== NULL
||
151 DeviceInstance
->Length
== 0)
153 if (IopRootDeviceNode
->PhysicalDeviceObject
)
155 ObReferenceObject(IopRootDeviceNode
->PhysicalDeviceObject
);
156 return IopRootDeviceNode
->PhysicalDeviceObject
;
162 return IopTraverseDeviceNode(IopRootDeviceNode
, DeviceInstance
);
167 IopCaptureUnicodeString(PUNICODE_STRING DstName
, PUNICODE_STRING SrcName
)
169 NTSTATUS Status
= STATUS_SUCCESS
;
170 volatile UNICODE_STRING Name
;
175 Name
.Length
= SrcName
->Length
;
176 Name
.MaximumLength
= SrcName
->MaximumLength
;
177 if (Name
.Length
> Name
.MaximumLength
)
179 Status
= STATUS_INVALID_PARAMETER
;
183 if (Name
.MaximumLength
)
185 ProbeForRead(SrcName
->Buffer
,
188 Name
.Buffer
= ExAllocatePool(NonPagedPool
, Name
.MaximumLength
);
189 if (Name
.Buffer
== NULL
)
191 Status
= STATUS_INSUFFICIENT_RESOURCES
;
195 memcpy(Name
.Buffer
, SrcName
->Buffer
, Name
.MaximumLength
);
200 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
204 ExFreePool(Name
.Buffer
);
206 Status
= _SEH2_GetExceptionCode();
214 IopGetInterfaceDeviceList(PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA DeviceList
)
217 UNICODE_STRING DeviceInstance
;
218 PDEVICE_OBJECT DeviceObject
= NULL
;
219 ULONG BufferSize
= 0;
221 PZZWSTR SymbolicLinkList
= NULL
, LinkList
;
222 ULONG TotalLength
= 0;
226 ProbeForRead(DeviceList
->FilterGuid
, sizeof(GUID
), sizeof(UCHAR
));
227 RtlCopyMemory(&FilterGuid
, DeviceList
->FilterGuid
, sizeof(GUID
));
229 if (DeviceList
->Buffer
!= NULL
&& DeviceList
->BufferSize
!= 0)
231 BufferSize
= DeviceList
->BufferSize
;
232 ProbeForWrite(DeviceList
->Buffer
, BufferSize
, sizeof(UCHAR
));
235 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
237 _SEH2_YIELD(return _SEH2_GetExceptionCode());
242 Status
= IopCaptureUnicodeString(&DeviceInstance
, &DeviceList
->DeviceInstance
);
243 if (NT_SUCCESS(Status
))
245 /* Get the device object */
246 DeviceObject
= IopGetDeviceObjectFromDeviceInstance(&DeviceInstance
);
247 ExFreePool(DeviceInstance
.Buffer
);
250 Status
= IoGetDeviceInterfaces(&FilterGuid
, DeviceObject
, DeviceList
->Flags
, &SymbolicLinkList
);
251 ObDereferenceObject(DeviceObject
);
253 if (!NT_SUCCESS(Status
))
259 LinkList
= SymbolicLinkList
;
260 while (*SymbolicLinkList
!= UNICODE_NULL
)
262 TotalLength
+= (wcslen(SymbolicLinkList
) + 1) * sizeof(WCHAR
);
263 SymbolicLinkList
+= wcslen(SymbolicLinkList
) + (sizeof(UNICODE_NULL
) / sizeof(WCHAR
));
265 TotalLength
+= sizeof(UNICODE_NULL
);
267 if (BufferSize
>= TotalLength
)
269 RtlCopyMemory(DeviceList
->Buffer
, SymbolicLinkList
, TotalLength
* sizeof(WCHAR
));
271 DeviceList
->BufferSize
= TotalLength
;
272 ExFreePool(LinkList
);
273 return STATUS_SUCCESS
;
277 IopGetDeviceProperty(PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData
)
279 PDEVICE_OBJECT DeviceObject
= NULL
;
281 UNICODE_STRING DeviceInstance
;
286 DPRINT("IopGetDeviceProperty() called\n");
287 DPRINT("Device name: %wZ\n", &PropertyData
->DeviceInstance
);
289 Status
= IopCaptureUnicodeString(&DeviceInstance
, &PropertyData
->DeviceInstance
);
290 if (!NT_SUCCESS(Status
))
297 Property
= PropertyData
->Property
;
298 BufferSize
= PropertyData
->BufferSize
;
299 ProbeForWrite(PropertyData
->Buffer
,
303 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
305 ExFreePool(DeviceInstance
.Buffer
);
306 _SEH2_YIELD(return _SEH2_GetExceptionCode());
310 /* Get the device object */
311 DeviceObject
= IopGetDeviceObjectFromDeviceInstance(&DeviceInstance
);
312 ExFreePool(DeviceInstance
.Buffer
);
313 if (DeviceObject
== NULL
)
315 return STATUS_NO_SUCH_DEVICE
;
318 Buffer
= ExAllocatePool(NonPagedPool
, BufferSize
);
321 return STATUS_INSUFFICIENT_RESOURCES
;
324 Status
= IoGetDeviceProperty(DeviceObject
,
330 ObDereferenceObject(DeviceObject
);
332 if (NT_SUCCESS(Status
))
336 memcpy(PropertyData
->Buffer
, Buffer
, BufferSize
);
337 PropertyData
->BufferSize
= BufferSize
;
339 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
341 Status
= _SEH2_GetExceptionCode();
352 IopGetRelatedDevice(PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA RelatedDeviceData
)
354 UNICODE_STRING RootDeviceName
;
355 PDEVICE_OBJECT DeviceObject
= NULL
;
356 PDEVICE_NODE DeviceNode
= NULL
;
357 PDEVICE_NODE RelatedDeviceNode
;
358 UNICODE_STRING TargetDeviceInstance
;
359 NTSTATUS Status
= STATUS_SUCCESS
;
361 ULONG MaximumLength
= 0;
363 DPRINT("IopGetRelatedDevice() called\n");
364 DPRINT("Device name: %wZ\n", &RelatedDeviceData
->TargetDeviceInstance
);
366 Status
= IopCaptureUnicodeString(&TargetDeviceInstance
, &RelatedDeviceData
->TargetDeviceInstance
);
367 if (!NT_SUCCESS(Status
))
374 Relation
= RelatedDeviceData
->Relation
;
375 MaximumLength
= RelatedDeviceData
->RelatedDeviceInstanceLength
;
376 ProbeForWrite(RelatedDeviceData
->RelatedDeviceInstance
,
380 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
382 ExFreePool(TargetDeviceInstance
.Buffer
);
383 _SEH2_YIELD(return _SEH2_GetExceptionCode());
387 RtlInitUnicodeString(&RootDeviceName
,
389 if (RtlEqualUnicodeString(&TargetDeviceInstance
,
393 DeviceNode
= IopRootDeviceNode
;
394 ExFreePool(TargetDeviceInstance
.Buffer
);
398 /* Get the device object */
399 DeviceObject
= IopGetDeviceObjectFromDeviceInstance(&TargetDeviceInstance
);
400 ExFreePool(TargetDeviceInstance
.Buffer
);
401 if (DeviceObject
== NULL
)
402 return STATUS_NO_SUCH_DEVICE
;
404 DeviceNode
= ((PEXTENDED_DEVOBJ_EXTENSION
)DeviceObject
->DeviceObjectExtension
)->DeviceNode
;
409 case PNP_GET_PARENT_DEVICE
:
410 RelatedDeviceNode
= DeviceNode
->Parent
;
413 case PNP_GET_CHILD_DEVICE
:
414 RelatedDeviceNode
= DeviceNode
->Child
;
417 case PNP_GET_SIBLING_DEVICE
:
418 RelatedDeviceNode
= DeviceNode
->Sibling
;
422 if (DeviceObject
!= NULL
)
424 ObDereferenceObject(DeviceObject
);
427 return STATUS_INVALID_PARAMETER
;
430 if (RelatedDeviceNode
== NULL
)
434 ObDereferenceObject(DeviceObject
);
437 return STATUS_NO_SUCH_DEVICE
;
440 if (RelatedDeviceNode
->InstancePath
.Length
> MaximumLength
)
444 ObDereferenceObject(DeviceObject
);
447 return STATUS_BUFFER_TOO_SMALL
;
450 /* Copy related device instance name */
453 RtlCopyMemory(RelatedDeviceData
->RelatedDeviceInstance
,
454 RelatedDeviceNode
->InstancePath
.Buffer
,
455 RelatedDeviceNode
->InstancePath
.Length
);
456 RelatedDeviceData
->RelatedDeviceInstanceLength
= RelatedDeviceNode
->InstancePath
.Length
;
458 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
460 Status
= _SEH2_GetExceptionCode();
464 if (DeviceObject
!= NULL
)
466 ObDereferenceObject(DeviceObject
);
469 DPRINT("IopGetRelatedDevice() done\n");
475 IopGetDeviceNodeStatus(PDEVICE_NODE DeviceNode
)
479 if (DeviceNode
->Parent
== IopRootDeviceNode
)
480 Output
|= DN_ROOT_ENUMERATED
;
482 if (DeviceNode
->Flags
& DNF_ADDED
)
483 Output
|= DN_DRIVER_LOADED
;
485 /* FIXME: DN_ENUM_LOADED */
487 if (DeviceNode
->Flags
& DNF_STARTED
)
488 Output
|= DN_STARTED
;
492 if (!(DeviceNode
->Flags
& DNF_PROCESSED
))
493 Output
|= DN_NEED_TO_ENUM
;
495 /* DN_NOT_FIRST_TIME is 9x only */
497 /* FIXME: DN_HARDWARE_ENUM */
499 /* DN_LIAR and DN_HAS_MARK are 9x only */
501 if (DeviceNode
->Problem
!= 0)
502 Output
|= DN_HAS_PROBLEM
;
504 /* FIXME: DN_FILTERED */
506 if (DeviceNode
->Flags
& DNF_LEGACY_DRIVER
)
507 Output
|= DN_LEGACY_DRIVER
;
509 if (DeviceNode
->UserFlags
& DNUF_DONT_SHOW_IN_UI
)
510 Output
|= DN_NO_SHOW_IN_DM
;
512 if (!(DeviceNode
->UserFlags
& DNUF_NOT_DISABLEABLE
))
513 Output
|= DN_DISABLEABLE
;
515 /* FIXME: Implement the rest */
517 Output
|= DN_NT_ENUMERATOR
| DN_NT_DRIVER
;
523 IopDeviceStatus(PPLUGPLAY_CONTROL_STATUS_DATA StatusData
)
525 PDEVICE_OBJECT DeviceObject
;
526 PDEVICE_NODE DeviceNode
;
528 ULONG DeviceStatus
= 0;
529 ULONG DeviceProblem
= 0;
530 UNICODE_STRING DeviceInstance
;
533 DPRINT("IopDeviceStatus() called\n");
535 Status
= IopCaptureUnicodeString(&DeviceInstance
, &StatusData
->DeviceInstance
);
536 if (!NT_SUCCESS(Status
))
540 DPRINT("Device name: '%wZ'\n", &DeviceInstance
);
544 Operation
= StatusData
->Operation
;
545 if (Operation
== PNP_SET_DEVICE_STATUS
)
547 DeviceStatus
= StatusData
->DeviceStatus
;
548 DeviceProblem
= StatusData
->DeviceProblem
;
551 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
553 ExFreePool(DeviceInstance
.Buffer
);
554 _SEH2_YIELD(return _SEH2_GetExceptionCode());
558 /* Get the device object */
559 DeviceObject
= IopGetDeviceObjectFromDeviceInstance(&DeviceInstance
);
560 ExFreePool(DeviceInstance
.Buffer
);
561 if (DeviceObject
== NULL
)
563 return STATUS_NO_SUCH_DEVICE
;
566 DeviceNode
= IopGetDeviceNode(DeviceObject
);
570 case PNP_GET_DEVICE_STATUS
:
571 DPRINT("Get status data\n");
572 DeviceStatus
= IopGetDeviceNodeStatus(DeviceNode
);
573 DeviceProblem
= DeviceNode
->Problem
;
576 case PNP_SET_DEVICE_STATUS
:
577 DPRINT1("Set status data is NOT SUPPORTED\n");
580 case PNP_CLEAR_DEVICE_STATUS
:
581 DPRINT1("FIXME: Clear status data!\n");
585 ObDereferenceObject(DeviceObject
);
587 if (Operation
== PNP_GET_DEVICE_STATUS
)
591 StatusData
->DeviceStatus
= DeviceStatus
;
592 StatusData
->DeviceProblem
= DeviceProblem
;
594 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
596 Status
= _SEH2_GetExceptionCode();
606 IopGetDeviceDepth(PPLUGPLAY_CONTROL_DEPTH_DATA DepthData
)
608 PDEVICE_OBJECT DeviceObject
;
609 PDEVICE_NODE DeviceNode
;
610 UNICODE_STRING DeviceInstance
;
611 NTSTATUS Status
= STATUS_SUCCESS
;
613 DPRINT("IopGetDeviceDepth() called\n");
614 DPRINT("Device name: %wZ\n", &DepthData
->DeviceInstance
);
616 Status
= IopCaptureUnicodeString(&DeviceInstance
, &DepthData
->DeviceInstance
);
617 if (!NT_SUCCESS(Status
))
622 /* Get the device object */
623 DeviceObject
= IopGetDeviceObjectFromDeviceInstance(&DeviceInstance
);
624 ExFreePool(DeviceInstance
.Buffer
);
625 if (DeviceObject
== NULL
)
627 return STATUS_NO_SUCH_DEVICE
;
630 DeviceNode
= IopGetDeviceNode(DeviceObject
);
634 DepthData
->Depth
= DeviceNode
->Level
;
636 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
638 Status
= _SEH2_GetExceptionCode();
642 ObDereferenceObject(DeviceObject
);
649 IopResetDevice(PPLUGPLAY_CONTROL_RESET_DEVICE_DATA ResetDeviceData
)
651 PDEVICE_OBJECT DeviceObject
;
652 PDEVICE_NODE DeviceNode
;
653 NTSTATUS Status
= STATUS_SUCCESS
;
654 UNICODE_STRING DeviceInstance
;
656 Status
= IopCaptureUnicodeString(&DeviceInstance
, &ResetDeviceData
->DeviceInstance
);
657 if (!NT_SUCCESS(Status
))
661 DPRINT("IopResetDevice(%wZ)\n", &DeviceInstance
);
663 /* Get the device object */
664 DeviceObject
= IopGetDeviceObjectFromDeviceInstance(&DeviceInstance
);
665 ExFreePool(DeviceInstance
.Buffer
);
666 if (DeviceObject
== NULL
)
668 return STATUS_NO_SUCH_DEVICE
;
671 /* Get the device node */
672 DeviceNode
= IopGetDeviceNode(DeviceObject
);
674 ASSERT(DeviceNode
->Flags
& DNF_ENUMERATED
);
675 ASSERT(DeviceNode
->Flags
& DNF_PROCESSED
);
677 /* Check if there's already a driver loaded for this device */
678 if (DeviceNode
->Flags
& DNF_ADDED
)
681 /* Remove the device node */
682 Status
= IopRemoveDevice(DeviceNode
);
683 if (NT_SUCCESS(Status
))
685 /* Invalidate device relations for the parent to reenumerate the device */
686 DPRINT1("A new driver will be loaded for '%wZ' (FDO above removed)\n", &DeviceNode
->InstancePath
);
687 Status
= IoSynchronousInvalidateDeviceRelations(DeviceNode
->Parent
->PhysicalDeviceObject
, BusRelations
);
692 /* A driver has already been loaded for this device */
693 DPRINT1("A reboot is required for the current driver for '%wZ' to be replaced\n", &DeviceNode
->InstancePath
);
694 DeviceNode
->Problem
= CM_PROB_NEED_RESTART
;
699 /* FIXME: What if the device really is disabled? */
700 DeviceNode
->Flags
&= ~DNF_DISABLED
;
701 DeviceNode
->Problem
= 0;
703 /* Load service data from the registry */
704 Status
= IopActionConfigureChildServices(DeviceNode
, DeviceNode
->Parent
);
706 if (NT_SUCCESS(Status
))
708 /* Start the service and begin PnP initialization of the device again */
709 DPRINT1("A new driver will be loaded for '%wZ' (no FDO above)\n", &DeviceNode
->InstancePath
);
710 Status
= IopActionInitChildServices(DeviceNode
, DeviceNode
->Parent
);
714 ObDereferenceObject(DeviceObject
);
719 /* PUBLIC FUNCTIONS **********************************************************/
722 * Plug and Play event structure used by NtGetPlugPlayEvent.
725 * Can be one of the following values:
726 * GUID_HWPROFILE_QUERY_CHANGE
727 * GUID_HWPROFILE_CHANGE_CANCELLED
728 * GUID_HWPROFILE_CHANGE_COMPLETE
729 * GUID_TARGET_DEVICE_QUERY_REMOVE
730 * GUID_TARGET_DEVICE_REMOVE_CANCELLED
731 * GUID_TARGET_DEVICE_REMOVE_COMPLETE
732 * GUID_PNP_CUSTOM_NOTIFICATION
733 * GUID_PNP_POWER_NOTIFICATION
734 * GUID_DEVICE_* (see above)
737 * Type of the event that happened.
746 * Size of the event block including the device IDs and other
747 * per category specific fields.
753 * Returns one Plug & Play event from a global queue.
758 * Always set to zero.
761 * The buffer that will be filled with the event information on
762 * successful return from the function.
765 * Size of the buffer pointed by the Buffer parameter. If the
766 * buffer size is not large enough to hold the whole event
767 * information, error STATUS_BUFFER_TOO_SMALL is returned and
768 * the buffer remains untouched.
771 * STATUS_PRIVILEGE_NOT_HELD
772 * STATUS_BUFFER_TOO_SMALL
776 * This function isn't multi-thread safe!
782 NtGetPlugPlayEvent(IN ULONG Reserved1
,
784 OUT PPLUGPLAY_EVENT_BLOCK Buffer
,
787 PPNP_EVENT_ENTRY Entry
;
790 DPRINT("NtGetPlugPlayEvent() called\n");
792 /* Function can only be called from user-mode */
793 if (KeGetPreviousMode() == KernelMode
)
795 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
796 return STATUS_ACCESS_DENIED
;
799 /* Check for Tcb privilege */
800 if (!SeSinglePrivilegeCheck(SeTcbPrivilege
,
803 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
804 return STATUS_PRIVILEGE_NOT_HELD
;
807 /* Wait for a PnP event */
808 DPRINT("Waiting for pnp notification event\n");
809 Status
= KeWaitForSingleObject(&IopPnpNotifyEvent
,
814 if (!NT_SUCCESS(Status
))
816 DPRINT1("KeWaitForSingleObject() failed (Status %lx)\n", Status
);
820 /* Get entry from the tail of the queue */
821 Entry
= CONTAINING_RECORD(IopPnpEventQueueHead
.Blink
,
825 /* Check the buffer size */
826 if (BufferSize
< Entry
->Event
.TotalSize
)
828 DPRINT1("Buffer is too small for the pnp-event\n");
829 return STATUS_BUFFER_TOO_SMALL
;
832 /* Copy event data to the user buffer */
835 Entry
->Event
.TotalSize
);
837 DPRINT("NtGetPlugPlayEvent() done\n");
839 return STATUS_SUCCESS
;
845 * A function for doing various Plug & Play operations from user mode.
848 * PlugPlayControlClass
849 * 0x00 Reenumerate device tree
851 * Buffer points to UNICODE_STRING decribing the instance
852 * path (like "HTREE\ROOT\0" or "Root\ACPI_HAL\0000"). For
853 * more information about instance paths see !devnode command
854 * in kernel debugger or look at "Inside Windows 2000" book,
855 * chapter "Driver Loading, Initialization, and Installation".
857 * 0x01 Register new device
858 * 0x02 Deregister device
859 * 0x03 Initialize device
861 * 0x06 Query and remove device
864 * Called after processing the message from NtGetPlugPlayEvent.
866 * 0x08 Generate legacy device
867 * 0x09 Get interface device list
868 * 0x0A Get property data
869 * 0x0B Device class association (Registration)
870 * 0x0C Get related device
871 * 0x0D Get device interface alias
872 * 0x0E Get/set/clear device status
873 * 0x0F Get device depth
874 * 0x10 Query device relations
875 * 0x11 Query target device relation
876 * 0x12 Query conflict list
877 * 0x13 Retrieve dock data
880 * 0x16 Get blocked driver data
883 * The buffer contains information that is specific to each control
884 * code. The buffer is read-only.
887 * Size of the buffer pointed by the Buffer parameter. If the
888 * buffer size specifies incorrect value for specified control
889 * code, error ??? is returned.
892 * STATUS_PRIVILEGE_NOT_HELD
900 NtPlugPlayControl(IN PLUGPLAY_CONTROL_CLASS PlugPlayControlClass
,
902 IN ULONG BufferLength
)
904 DPRINT("NtPlugPlayControl(%d %p %lu) called\n",
905 PlugPlayControlClass
, Buffer
, BufferLength
);
907 /* Function can only be called from user-mode */
908 if (KeGetPreviousMode() == KernelMode
)
910 DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
911 return STATUS_ACCESS_DENIED
;
914 /* Check for Tcb privilege */
915 if (!SeSinglePrivilegeCheck(SeTcbPrivilege
,
918 DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
919 return STATUS_PRIVILEGE_NOT_HELD
;
922 /* Probe the buffer */
925 ProbeForWrite(Buffer
,
929 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
931 _SEH2_YIELD(return _SEH2_GetExceptionCode());
935 switch (PlugPlayControlClass
)
937 case PlugPlayControlUserResponse
:
938 if (Buffer
|| BufferLength
!= 0)
939 return STATUS_INVALID_PARAMETER
;
940 return IopRemovePlugPlayEvent();
942 case PlugPlayControlGetInterfaceDeviceList
:
943 if (!Buffer
|| BufferLength
< sizeof(PLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA
))
944 return STATUS_INVALID_PARAMETER
;
945 return IopGetInterfaceDeviceList((PPLUGPLAY_CONTROL_INTERFACE_DEVICE_LIST_DATA
)Buffer
);
947 case PlugPlayControlProperty
:
948 if (!Buffer
|| BufferLength
< sizeof(PLUGPLAY_CONTROL_PROPERTY_DATA
))
949 return STATUS_INVALID_PARAMETER
;
950 return IopGetDeviceProperty((PPLUGPLAY_CONTROL_PROPERTY_DATA
)Buffer
);
952 case PlugPlayControlGetRelatedDevice
:
953 if (!Buffer
|| BufferLength
< sizeof(PLUGPLAY_CONTROL_RELATED_DEVICE_DATA
))
954 return STATUS_INVALID_PARAMETER
;
955 return IopGetRelatedDevice((PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA
)Buffer
);
957 case PlugPlayControlDeviceStatus
:
958 if (!Buffer
|| BufferLength
< sizeof(PLUGPLAY_CONTROL_STATUS_DATA
))
959 return STATUS_INVALID_PARAMETER
;
960 return IopDeviceStatus((PPLUGPLAY_CONTROL_STATUS_DATA
)Buffer
);
962 case PlugPlayControlGetDeviceDepth
:
963 if (!Buffer
|| BufferLength
< sizeof(PLUGPLAY_CONTROL_DEPTH_DATA
))
964 return STATUS_INVALID_PARAMETER
;
965 return IopGetDeviceDepth((PPLUGPLAY_CONTROL_DEPTH_DATA
)Buffer
);
967 case PlugPlayControlResetDevice
:
968 if (!Buffer
|| BufferLength
< sizeof(PLUGPLAY_CONTROL_RESET_DEVICE_DATA
))
969 return STATUS_INVALID_PARAMETER
;
970 return IopResetDevice((PPLUGPLAY_CONTROL_RESET_DEVICE_DATA
)Buffer
);
973 return STATUS_NOT_IMPLEMENTED
;
976 return STATUS_NOT_IMPLEMENTED
;