ReactOS  0.4.15-dev-1171-gab82533
pnpreport.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for pnpreport.c:

Go to the source code of this file.

Classes

struct  _INTERNAL_WORK_QUEUE_ITEM
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _INTERNAL_WORK_QUEUE_ITEM INTERNAL_WORK_QUEUE_ITEM
 
typedef struct _INTERNAL_WORK_QUEUE_ITEMPINTERNAL_WORK_QUEUE_ITEM
 

Functions

NTSTATUS IopSetDeviceInstanceData (HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
 
NTSTATUS IopActionInterrogateDeviceStack (PDEVICE_NODE DeviceNode, PVOID Context)
 
NTSTATUS PpSetCustomTargetEvent (IN PDEVICE_OBJECT DeviceObject, IN OUT PKEVENT SyncEvent OPTIONAL, IN OUT PNTSTATUS SyncStatus OPTIONAL, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL, IN PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure)
 
PWCHAR IopGetInterfaceTypeString (INTERFACE_TYPE IfType)
 
VOID NTAPI IopReportTargetDeviceChangeAsyncWorker (PVOID Context)
 
NTSTATUS NTAPI IoReportDetectedDevice (IN PDRIVER_OBJECT DriverObject, IN INTERFACE_TYPE LegacyBusType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PCM_RESOURCE_LIST ResourceList, IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL, IN BOOLEAN ResourceAssigned, IN OUT PDEVICE_OBJECT *DeviceObject OPTIONAL)
 
NTSTATUS NTAPI IoReportResourceForDetection (IN PDRIVER_OBJECT DriverObject, IN PCM_RESOURCE_LIST DriverList OPTIONAL, IN ULONG DriverListSize OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PCM_RESOURCE_LIST DeviceList OPTIONAL, IN ULONG DeviceListSize OPTIONAL, OUT PBOOLEAN ConflictDetected)
 
VOID NTAPI IopSetEvent (IN PVOID Context)
 
NTSTATUS NTAPI IoReportTargetDeviceChange (IN PDEVICE_OBJECT PhysicalDeviceObject, IN PVOID NotificationStructure)
 
NTSTATUS NTAPI IoReportTargetDeviceChangeAsynchronous (IN PDEVICE_OBJECT PhysicalDeviceObject, IN PVOID NotificationStructure, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file pnpreport.c.

Typedef Documentation

◆ INTERNAL_WORK_QUEUE_ITEM

◆ PINTERNAL_WORK_QUEUE_ITEM

Function Documentation

◆ IopActionInterrogateDeviceStack()

NTSTATUS IopActionInterrogateDeviceStack ( PDEVICE_NODE  DeviceNode,
PVOID  Context 
)

Definition at line 577 of file devaction.c.

579 {
582  PWSTR LocationInformation;
583  PDEVICE_NODE ParentDeviceNode;
584  IO_STACK_LOCATION Stack;
587  LCID LocaleId;
588  HANDLE InstanceKey = NULL;
590  UNICODE_STRING InstancePathU;
591  PDEVICE_OBJECT OldDeviceObject;
592 
593  DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
594  DPRINT("PDO 0x%p\n", DeviceNode->PhysicalDeviceObject);
595 
596  ParentDeviceNode = (PDEVICE_NODE)Context;
597 
598  /*
599  * We are called for the parent too, but we don't need to do special
600  * handling for this node
601  */
602  if (DeviceNode == ParentDeviceNode)
603  {
604  DPRINT("Success\n");
605  return STATUS_SUCCESS;
606  }
607 
608  /*
609  * Make sure this device node is a direct child of the parent device node
610  * that is given as an argument
611  */
612  if (DeviceNode->Parent != ParentDeviceNode)
613  {
614  DPRINT("Skipping 2+ level child\n");
615  return STATUS_SUCCESS;
616  }
617 
618  /* Skip processing if it was already completed before */
619  if (DeviceNode->Flags & DNF_PROCESSED)
620  {
621  /* Nothing to do */
622  return STATUS_SUCCESS;
623  }
624 
625  /* Get Locale ID */
626  Status = ZwQueryDefaultLocale(FALSE, &LocaleId);
627  if (!NT_SUCCESS(Status))
628  {
629  DPRINT1("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status);
630  return Status;
631  }
632 
633  /*
634  * FIXME: For critical errors, cleanup and disable device, but always
635  * return STATUS_SUCCESS.
636  */
637 
638  Status = IopCreateDeviceInstancePath(DeviceNode, &InstancePathU);
639  if (!NT_SUCCESS(Status))
640  {
642  {
643  DPRINT1("IopCreateDeviceInstancePath() failed with status 0x%lx\n", Status);
644  }
645 
646  /* We have to return success otherwise we abort the traverse operation */
647  return STATUS_SUCCESS;
648  }
649 
650  /* Verify that this is not a duplicate */
651  OldDeviceObject = IopGetDeviceObjectFromDeviceInstance(&InstancePathU);
652  if (OldDeviceObject != NULL)
653  {
654  PDEVICE_NODE OldDeviceNode = IopGetDeviceNode(OldDeviceObject);
655 
656  DPRINT1("Duplicate device instance '%wZ'\n", &InstancePathU);
657  DPRINT1("Current instance parent: '%wZ'\n", &DeviceNode->Parent->InstancePath);
658  DPRINT1("Old instance parent: '%wZ'\n", &OldDeviceNode->Parent->InstancePath);
659 
660  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR,
661  0x01,
662  (ULONG_PTR)DeviceNode->PhysicalDeviceObject,
663  (ULONG_PTR)OldDeviceObject,
664  0);
665  }
666 
667  DeviceNode->InstancePath = InstancePathU;
668 
669  DPRINT("InstancePath is %S\n", DeviceNode->InstancePath.Buffer);
670 
671  /*
672  * Create registry key for the instance id, if it doesn't exist yet
673  */
674  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
675  if (!NT_SUCCESS(Status))
676  {
677  DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
678 
679  /* We have to return success otherwise we abort the traverse operation */
680  return STATUS_SUCCESS;
681  }
682 
683  IopQueryHardwareIds(DeviceNode, InstanceKey);
684 
685  IopQueryCompatibleIds(DeviceNode, InstanceKey);
686 
687  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextDescription to device stack\n");
688 
689  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextDescription;
690  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
691  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
692  &IoStatusBlock,
694  &Stack);
696  : NULL;
697  /* This key is mandatory, so even if the Irp fails, we still write it */
698  RtlInitUnicodeString(&ValueName, L"DeviceDesc");
699  if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
700  {
701  if (DeviceDescription &&
703  {
704  /* This key is overriden when a driver is installed. Don't write the
705  * new description if another one already exists */
706  Status = ZwSetValueKey(InstanceKey,
707  &ValueName,
708  0,
709  REG_SZ,
711  ((ULONG)wcslen(DeviceDescription) + 1) * sizeof(WCHAR));
712  }
713  else
714  {
715  UNICODE_STRING DeviceDesc = RTL_CONSTANT_STRING(L"Unknown device");
716  DPRINT("Driver didn't return DeviceDesc (Status 0x%08lx), so place unknown device there\n", Status);
717 
718  Status = ZwSetValueKey(InstanceKey,
719  &ValueName,
720  0,
721  REG_SZ,
722  DeviceDesc.Buffer,
723  DeviceDesc.MaximumLength);
724  if (!NT_SUCCESS(Status))
725  {
726  DPRINT1("ZwSetValueKey() failed (Status 0x%lx)\n", Status);
727  }
728 
729  }
730  }
731 
732  if (DeviceDescription)
733  {
735  }
736 
737  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocation to device stack\n");
738 
739  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextLocationInformation;
740  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
741  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
742  &IoStatusBlock,
744  &Stack);
746  {
747  LocationInformation = (PWSTR)IoStatusBlock.Information;
748  DPRINT("LocationInformation: %S\n", LocationInformation);
749  RtlInitUnicodeString(&ValueName, L"LocationInformation");
750  Status = ZwSetValueKey(InstanceKey,
751  &ValueName,
752  0,
753  REG_SZ,
754  LocationInformation,
755  ((ULONG)wcslen(LocationInformation) + 1) * sizeof(WCHAR));
756  if (!NT_SUCCESS(Status))
757  {
758  DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
759  }
760 
761  ExFreePoolWithTag(LocationInformation, 0);
762  }
763  else
764  {
765  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
766  }
767 
768  DPRINT("Sending IRP_MN_QUERY_BUS_INFORMATION to device stack\n");
769 
770  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
771  &IoStatusBlock,
773  NULL);
775  {
777 
778  DeviceNode->ChildBusNumber = BusInformation->BusNumber;
779  DeviceNode->ChildInterfaceType = BusInformation->LegacyBusType;
780  DeviceNode->ChildBusTypeIndex = IopGetBusTypeGuidIndex(&BusInformation->BusTypeGuid);
781  ExFreePoolWithTag(BusInformation, 0);
782  }
783  else
784  {
785  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
786 
787  DeviceNode->ChildBusNumber = 0xFFFFFFF0;
788  DeviceNode->ChildInterfaceType = InterfaceTypeUndefined;
789  DeviceNode->ChildBusTypeIndex = -1;
790  }
791 
792  DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
793 
794  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
795  &IoStatusBlock,
797  NULL);
799  {
802  }
803  else
804  {
805  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
806  DeviceNode->BootResources = NULL;
807  }
808 
809  DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
810 
811  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
812  &IoStatusBlock,
814  NULL);
815  if (NT_SUCCESS(Status))
816  {
818  }
819  else
820  {
821  DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status);
822  DeviceNode->ResourceRequirements = NULL;
823  }
824 
825  if (InstanceKey != NULL)
826  {
827  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
828  }
829 
830  ZwClose(InstanceKey);
831 
833 
835  {
836  /* Report the device to the user-mode pnp manager */
837  IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
838  &DeviceNode->InstancePath);
839  }
840 
841  return STATUS_SUCCESS;
842 }
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
#define STATUS_PLUGPLAY_NO_DEVICE
Definition: ntstatus.h:731
#define IRP_MN_QUERY_RESOURCES
#define DNF_PROCESSED
Definition: iotypes.h:167
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:56
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:666
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI ZwQueryDefaultLocale(_In_ BOOLEAN UserProfile, _Out_ PLCID DefaultLocaleId)
#define DNF_HAS_BOOT_CONFIG
Definition: iotypes.h:196
struct _IO_RESOURCE_REQUIREMENTS_LIST * PIO_RESOURCE_REQUIREMENTS_LIST
DWORD LCID
Definition: nls.h:13
struct _DEVICE_NODE * Parent
Definition: iotypes.h:825
static NTSTATUS IopQueryHardwareIds(PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
Definition: devaction.c:432
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
static NTSTATUS IopQueryCompatibleIds(PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
Definition: devaction.c:497
struct _DEVICE_NODE * PDEVICE_NODE
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
static NTSTATUS IopCreateDeviceInstancePath(_In_ PDEVICE_NODE DeviceNode, _Out_ PUNICODE_STRING InstancePath)
Definition: devaction.c:182
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
smooth NULL
Definition: ftsmooth.c:416
struct _PNP_BUS_INFORMATION * PPNP_BUS_INFORMATION
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
_Must_inspect_result_ _In_ PDEVICE_DESCRIPTION DeviceDescription
Definition: iofuncs.h:1015
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:46
USHORT NTAPI IopGetBusTypeGuidIndex(LPGUID BusTypeGuid)
Definition: pnpmgr.c:481
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:125
#define IRP_MN_QUERY_DEVICE_TEXT
Definition: Node.h:9
#define IRP_MN_QUERY_BUS_INFORMATION
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
#define IopDeviceNodeHasFlag(DeviceNode, Flag)
Definition: io.h:160
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
INTERFACE_TYPE LegacyBusType
Definition: cmtypes.h:365
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:750
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define REG_SZ
Definition: layer.c:22

Referenced by IoReportDetectedDevice(), and PipEnumerateDevice().

◆ IopGetInterfaceTypeString()

PWCHAR IopGetInterfaceTypeString ( INTERFACE_TYPE  IfType)

Definition at line 46 of file pnpreport.c.

47 {
48  switch (IfType)
49  {
50  case Internal:
51  return L"Internal";
52 
53  case Isa:
54  return L"Isa";
55 
56  case Eisa:
57  return L"Eisa";
58 
59  case MicroChannel:
60  return L"MicroChannel";
61 
62  case TurboChannel:
63  return L"TurboChannel";
64 
65  case PCIBus:
66  return L"PCIBus";
67 
68  case VMEBus:
69  return L"VMEBus";
70 
71  case NuBus:
72  return L"NuBus";
73 
74  case PCMCIABus:
75  return L"PCMCIABus";
76 
77  case CBus:
78  return L"CBus";
79 
80  case MPIBus:
81  return L"MPIBus";
82 
83  case MPSABus:
84  return L"MPSABus";
85 
86  case ProcessorInternal:
87  return L"ProcessorInternal";
88 
89  case PNPISABus:
90  return L"PNPISABus";
91 
92  case PNPBus:
93  return L"PNPBus";
94 
95  case Vmcs:
96  return L"Vmcs";
97 
98  default:
99  DPRINT1("Invalid bus type: %d\n", IfType);
100  return NULL;
101  }
102 }
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250
#define DPRINT1
Definition: precomp.h:8

Referenced by IoReportDetectedDevice().

◆ IopReportTargetDeviceChangeAsyncWorker()

VOID NTAPI IopReportTargetDeviceChangeAsyncWorker ( PVOID  Context)

Definition at line 106 of file pnpreport.c.

107 {
109 
113  ExFreePoolWithTag(Context, ' pP');
114 }
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
smooth NULL
Definition: ftsmooth.c:416
struct _INTERNAL_WORK_QUEUE_ITEM * PINTERNAL_WORK_QUEUE_ITEM
NTSTATUS PpSetCustomTargetEvent(IN PDEVICE_OBJECT DeviceObject, IN OUT PKEVENT SyncEvent OPTIONAL, IN OUT PNTSTATUS SyncStatus OPTIONAL, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL, IN PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure)
Definition: pnpreport.c:117
PDEVICE_CHANGE_COMPLETE_CALLBACK Callback
Definition: pnpreport.c:22
PDEVICE_OBJECT PhysicalDeviceObject
Definition: pnpreport.c:21
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure
Definition: pnpreport.c:24

Referenced by IoReportTargetDeviceChangeAsynchronous().

◆ IopSetDeviceInstanceData()

NTSTATUS IopSetDeviceInstanceData ( HANDLE  InstanceKey,
PDEVICE_NODE  DeviceNode 
)

Definition at line 750 of file pnpmgr.c.

752 {
755  HANDLE LogConfKey, ControlKey, DeviceParamsKey;
756  ULONG ResCount;
759 
760  DPRINT("IopSetDeviceInstanceData() called\n");
761 
762  /* Create the 'LogConf' key */
763  RtlInitUnicodeString(&KeyName, L"LogConf");
765  &KeyName,
767  InstanceKey,
768  NULL);
769  Status = ZwCreateKey(&LogConfKey,
772  0,
773  NULL,
774  // FIXME? In r53694 it was silently turned from non-volatile into this,
775  // without any extra warning. Is this still needed??
777  NULL);
778  if (NT_SUCCESS(Status))
779  {
780  /* Set 'BootConfig' value */
781  if (DeviceNode->BootResources != NULL)
782  {
783  ResCount = DeviceNode->BootResources->Count;
784  if (ResCount != 0)
785  {
786  RtlInitUnicodeString(&KeyName, L"BootConfig");
787  Status = ZwSetValueKey(LogConfKey,
788  &KeyName,
789  0,
791  DeviceNode->BootResources,
792  PnpDetermineResourceListSize(DeviceNode->BootResources));
793  }
794  }
795 
796  /* Set 'BasicConfigVector' value */
797  if (DeviceNode->ResourceRequirements != NULL &&
798  DeviceNode->ResourceRequirements->ListSize != 0)
799  {
800  RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
801  Status = ZwSetValueKey(LogConfKey,
802  &KeyName,
803  0,
805  DeviceNode->ResourceRequirements,
806  DeviceNode->ResourceRequirements->ListSize);
807  }
808 
809  ZwClose(LogConfKey);
810  }
811 
812  /* Set the 'ConfigFlags' value */
813  RtlInitUnicodeString(&KeyName, L"ConfigFlags");
814  Status = ZwQueryValueKey(InstanceKey,
815  &KeyName,
817  NULL,
818  0,
819  &ResultLength);
821  {
822  /* Write the default value */
823  ULONG DefaultConfigFlags = 0;
824  Status = ZwSetValueKey(InstanceKey,
825  &KeyName,
826  0,
827  REG_DWORD,
828  &DefaultConfigFlags,
829  sizeof(DefaultConfigFlags));
830  }
831 
832  /* Create the 'Control' key */
833  RtlInitUnicodeString(&KeyName, L"Control");
835  &KeyName,
837  InstanceKey,
838  NULL);
839  Status = ZwCreateKey(&ControlKey,
840  0,
842  0,
843  NULL,
845  NULL);
846  if (NT_SUCCESS(Status))
847  ZwClose(ControlKey);
848 
849  /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
850  if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
851  {
852  RtlInitUnicodeString(&KeyName, L"Device Parameters");
854  &KeyName,
856  InstanceKey,
857  NULL);
858  Status = ZwCreateKey(&DeviceParamsKey,
859  0,
861  0,
862  NULL,
864  NULL);
865  if (NT_SUCCESS(Status))
866  {
867  ULONG FirmwareIdentified = 1;
868  RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
869  Status = ZwSetValueKey(DeviceParamsKey,
870  &KeyName,
871  0,
872  REG_DWORD,
873  &FirmwareIdentified,
874  sizeof(FirmwareIdentified));
875 
876  ZwClose(DeviceParamsKey);
877  }
878  }
879 
880  DPRINT("IopSetDeviceInstanceData() done\n");
881 
882  return Status;
883 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define REG_RESOURCE_REQUIREMENTS_LIST
Definition: nt_native.h:1504
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: Node.h:9
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1951
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by IoReportDetectedDevice().

◆ IopSetEvent()

VOID NTAPI IopSetEvent ( IN PVOID  Context)

Definition at line 452 of file pnpreport.c.

453 {
455 
456  /* Set the event */
458 }
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
struct tagContext Context
Definition: acpixf.h:1034
#define IO_NO_INCREMENT
Definition: iotypes.h:581

◆ IoReportDetectedDevice()

NTSTATUS NTAPI IoReportDetectedDevice ( IN PDRIVER_OBJECT  DriverObject,
IN INTERFACE_TYPE  LegacyBusType,
IN ULONG  BusNumber,
IN ULONG  SlotNumber,
IN PCM_RESOURCE_LIST  ResourceList,
IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements  OPTIONAL,
IN BOOLEAN  ResourceAssigned,
IN OUT PDEVICE_OBJECT *DeviceObject  OPTIONAL 
)

Definition at line 156 of file pnpreport.c.

164 {
168  HANDLE InstanceKey;
170  UNICODE_STRING ValueName, ServiceLongName, ServiceName;
171  WCHAR HardwareId[256];
172  PWCHAR IfString;
173  ULONG IdLength;
174  ULONG LegacyValue;
175 
176  DPRINT("IoReportDetectedDevice (DeviceObject %p, *DeviceObject %p)\n",
178 
179  ServiceLongName = DriverObject->DriverExtension->ServiceKeyName;
180  ServiceName = ServiceLongName;
181 
182  /* If the interface type is unknown, treat it as internal */
185 
186  /* Get the string equivalent of the interface type */
188 
189  /* If NULL is returned then it's a bad type */
190  if (!IfString)
192 
193  /*
194  * Drivers that have been created via a direct IoCreateDriver() call
195  * have their ServiceKeyName set to \Driver\DriverName. We need to
196  * strip everything up to the last path separator and keep what remains.
197  */
199  {
200  /*
201  * Find the last path separator.
202  * NOTE: Since ServiceName is not necessarily NULL-terminated,
203  * we cannot use wcsrchr().
204  */
205  if (ServiceName.Buffer && ServiceName.Length >= sizeof(WCHAR))
206  {
207  ValueName.Length = 1;
208  ValueName.Buffer = ServiceName.Buffer + (ServiceName.Length / sizeof(WCHAR)) - 1;
209 
210  while ((ValueName.Buffer > ServiceName.Buffer) && (*ValueName.Buffer != L'\\'))
211  {
212  --ValueName.Buffer;
213  ++ValueName.Length;
214  }
215  if (*ValueName.Buffer == L'\\')
216  {
217  ++ValueName.Buffer;
218  --ValueName.Length;
219  }
220  ValueName.Length *= sizeof(WCHAR);
221 
222  /* Shorten the string */
223  ServiceName.MaximumLength -= (ServiceName.Length - ValueName.Length);
224  ServiceName.Length = ValueName.Length;
225  ServiceName.Buffer = ValueName.Buffer;
226  }
227  }
228 
229  /* We use the caller's PDO if they supplied one */
230  if (DeviceObject && *DeviceObject)
231  {
232  Pdo = *DeviceObject;
233  }
234  else
235  {
236  /* Create the PDO */
238  NULL,
239  &Pdo,
240  NULL);
241  if (!NT_SUCCESS(Status))
242  {
243  DPRINT("PnpRootCreateDevice() failed (Status 0x%08lx)\n", Status);
244  return Status;
245  }
246  }
247 
248  /* Create the device node for the new PDO */
250  Pdo,
251  NULL,
252  &DeviceNode);
253  if (!NT_SUCCESS(Status))
254  {
255  DPRINT("IopCreateDeviceNode() failed (Status 0x%08lx)\n", Status);
256  return Status;
257  }
258 
259  /* We're enumerated already */
261 
262  /* We don't call AddDevice for devices reported this way */
264 
265  /* We don't send IRP_MN_START_DEVICE */
267 
268  /* We need to get device IDs */
269 #if 0
270  IopDeviceNodeSetFlag(DeviceNode, DNF_NEED_QUERY_IDS);
271 #endif
272 
273  /* This is a legacy driver for this device */
275 
276  /* Perform a manual configuration of our device */
279 
280  /* Open a handle to the instance path key */
281  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
282  if (!NT_SUCCESS(Status))
283  return Status;
284 
285  /* Save the driver name */
286  RtlInitUnicodeString(&ValueName, L"Service");
287  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_SZ, ServiceLongName.Buffer, ServiceLongName.Length + sizeof(UNICODE_NULL));
288  if (!NT_SUCCESS(Status))
289  {
290  DPRINT("Failed to write the Service name value: 0x%x\n", Status);
291  }
292 
293  /* Report as non-legacy driver */
294  RtlInitUnicodeString(&ValueName, L"Legacy");
295  LegacyValue = 0;
296  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_DWORD, &LegacyValue, sizeof(LegacyValue));
297  if (!NT_SUCCESS(Status))
298  {
299  DPRINT("Failed to write the Legacy value: 0x%x\n", Status);
300  }
301 
302  /* Add DETECTEDInterfaceType\DriverName */
303  IdLength = 0;
304  IdLength += swprintf(&HardwareId[IdLength],
305  L"DETECTED%ls\\%wZ",
306  IfString,
307  &ServiceName);
308  IdLength++;
309 
310  /* Add DETECTED\DriverName */
311  IdLength += swprintf(&HardwareId[IdLength],
312  L"DETECTED\\%wZ",
313  &ServiceName);
314  IdLength++;
315 
316  /* Terminate the string with another null */
317  HardwareId[IdLength++] = UNICODE_NULL;
318 
319  /* Store the value for CompatibleIDs */
320  RtlInitUnicodeString(&ValueName, L"CompatibleIDs");
321  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
322  if (!NT_SUCCESS(Status))
323  {
324  DPRINT("Failed to write the compatible IDs: 0x%x\n", Status);
325  ZwClose(InstanceKey);
326  return Status;
327  }
328 
329  /* Add a hardware ID if the driver didn't report one */
330  RtlInitUnicodeString(&ValueName, L"HardwareID");
331  if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
332  {
333  /* Just use our most specific compatible ID */
334  IdLength = 0;
335  IdLength += swprintf(&HardwareId[IdLength],
336  L"DETECTED%ls\\%wZ",
337  IfString,
338  &ServiceName);
339  IdLength++;
340 
341  HardwareId[IdLength++] = UNICODE_NULL;
342 
343  /* Write the value to the registry */
344  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
345  if (!NT_SUCCESS(Status))
346  {
347  DPRINT("Failed to write the hardware ID: 0x%x\n", Status);
348  ZwClose(InstanceKey);
349  return Status;
350  }
351  }
352 
353  /* Assign the resources to the device node */
354  DeviceNode->BootResources = ResourceList;
355  DeviceNode->ResourceRequirements = ResourceRequirements;
356 
357  /* Set appropriate flags */
358  if (DeviceNode->BootResources)
360 
361  if (!DeviceNode->ResourceRequirements && !DeviceNode->BootResources)
363 
364  /* Write the resource information to the registry */
365  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
366 
367  /* If the caller didn't get the resources assigned for us, do it now */
368  if (!ResourceAssigned)
369  {
371 
372  /* See if we failed */
373  if (!NT_SUCCESS(Status))
374  {
375  DPRINT("Assigning resources failed: 0x%x\n", Status);
376  ZwClose(InstanceKey);
377  return Status;
378  }
379  }
380 
381  /* Close the instance key handle */
382  ZwClose(InstanceKey);
383 
384  /* Register the given DO with PnP root if required */
385  if (DeviceObject && *DeviceObject)
387 
388  /* Report the device's enumeration to umpnpmgr */
389  IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
390  &DeviceNode->InstancePath);
391 
392  /* Report the device's arrival to umpnpmgr */
393  IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
394  &DeviceNode->InstancePath);
395 
396  DPRINT("Reported device: %S (%wZ)\n", HardwareId, &DeviceNode->InstancePath);
397 
399 
400  /* Return the PDO */
401  if (DeviceObject) *DeviceObject = Pdo;
402 
403  return STATUS_SUCCESS;
404 }
NTSTATUS IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: devaction.c:577
NTSTATUS PnpRootRegisterDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnproot.c:129
#define DRVO_BUILTIN_DRIVER
Definition: iotypes.h:2207
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:318
VOID PiQueueDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action, _In_opt_ PKEVENT CompletionEvent, _Out_opt_ NTSTATUS *CompletionStatus)
Queue a device operation to a worker thread.
Definition: devaction.c:2472
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:666
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS IopCreateDeviceNode(IN PDEVICE_NODE ParentNode, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PUNICODE_STRING ServiceName, OUT PDEVICE_NODE *DeviceNode)
#define DNF_NO_RESOURCE_REQUIRED
Definition: iotypes.h:174
#define DNF_HAS_BOOT_CONFIG
Definition: iotypes.h:196
uint16_t * PWCHAR
Definition: typedefs.h:56
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:750
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
#define UNICODE_NULL
#define REG_MULTI_SZ
Definition: nt_native.h:1501
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2262
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
#define DNF_STARTED
Definition: iotypes.h:168
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:46
LPTSTR ServiceName
Definition: ServiceMain.c:15
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
Definition: Node.h:9
_In_ INTERFACE_TYPE LegacyBusType
Definition: iofuncs.h:1543
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
UNICODE_STRING ServiceKeyName
Definition: iotypes.h:2202
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IopAssignDeviceResources(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:1105
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DNF_ENUMERATED
Definition: iotypes.h:170
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements
Definition: iofuncs.h:1543
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST _In_ BOOLEAN ResourceAssigned
Definition: iofuncs.h:1543
PWCHAR IopGetInterfaceTypeString(INTERFACE_TYPE IfType)
Definition: pnpreport.c:46
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define DNF_ADDED
Definition: iotypes.h:179
#define REG_DWORD
Definition: sdbapi.c:596
NTSTATUS IopActionConfigureChildServices(IN PDEVICE_NODE DeviceNode, IN PVOID Context)
NTSTATUS PnpRootCreateDevice(IN PUNICODE_STRING ServiceName, IN OPTIONAL PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *PhysicalDeviceObject, OUT OPTIONAL PUNICODE_STRING FullInstancePath)
Definition: pnproot.c:185
#define REG_SZ
Definition: layer.c:22

Referenced by _Function_class_(), add_volume_device(), DriverEntry(), HalpDriverEntry(), and ReportGreenPdo().

◆ IoReportResourceForDetection()

NTSTATUS NTAPI IoReportResourceForDetection ( IN PDRIVER_OBJECT  DriverObject,
IN PCM_RESOURCE_LIST DriverList  OPTIONAL,
IN ULONG DriverListSize  OPTIONAL,
IN PDEVICE_OBJECT DeviceObject  OPTIONAL,
IN PCM_RESOURCE_LIST DeviceList  OPTIONAL,
IN ULONG DeviceListSize  OPTIONAL,
OUT PBOOLEAN  ConflictDetected 
)

Definition at line 411 of file pnpreport.c.

418 {
421 
422  *ConflictDetected = FALSE;
423 
424  if (!DriverList && !DeviceList)
426 
427  /* Find the real list */
428  if (!DriverList)
430  else
431  ResourceList = DriverList;
432 
433  /* Look for a resource conflict */
436  {
437  /* Oh noes */
438  *ConflictDetected = TRUE;
439  }
440  else if (NT_SUCCESS(Status))
441  {
442  /* Looks like we're good to go */
443 
444  /* TODO: Claim the resources in the ResourceMap */
445  }
446 
447  return Status;
448 }
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
PDEVICE_LIST DeviceList
Definition: utils.c:27
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
NTSTATUS NTAPI IopDetectResourceConflict(IN PCM_RESOURCE_LIST ResourceList, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
Definition: pnpres.c:1251

Referenced by VideoPortVerifyAccessRanges().

◆ IoReportTargetDeviceChange()

NTSTATUS NTAPI IoReportTargetDeviceChange ( IN PDEVICE_OBJECT  PhysicalDeviceObject,
IN PVOID  NotificationStructure 
)

Definition at line 465 of file pnpreport.c.

467 {
468  KEVENT NotifyEvent;
469  NTSTATUS Status, NotifyStatus;
471 
472  ASSERT(notifyStruct);
473 
474  /* Check for valid PDO */
476  {
477  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
478  }
479 
480  /* FileObject must be null. PnP will fill in it */
481  ASSERT(notifyStruct->FileObject == NULL);
482 
483  /* Do not handle system PnP events */
484  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
485  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
486  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
487  {
489  }
490 
491  if (notifyStruct->Version != 1)
492  {
494  }
495 
496  /* Initialize even that will let us know when PnP will have finished notify */
497  KeInitializeEvent(&NotifyEvent, NotificationEvent, FALSE);
498 
499  Status = PpSetCustomTargetEvent(PhysicalDeviceObject, &NotifyEvent, &NotifyStatus, NULL, NULL, notifyStruct);
500  /* If no error, wait for the notify to end and return the status of the notify and not of the event */
501  if (NT_SUCCESS(Status))
502  {
504  Status = NotifyStatus;
505  }
506 
507  return Status;
508 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS PpSetCustomTargetEvent(IN PDEVICE_OBJECT DeviceObject, IN OUT PKEVENT SyncEvent OPTIONAL, IN OUT PNTSTATUS SyncStatus OPTIONAL, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL, IN PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure)
Definition: pnpreport.c:117
struct _TARGET_DEVICE_CUSTOM_NOTIFICATION * PTARGET_DEVICE_CUSTOM_NOTIFICATION
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:995
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by FsRtlNotifyVolumeEvent(), and NtSetVolumeInformationFile().

◆ IoReportTargetDeviceChangeAsynchronous()

NTSTATUS NTAPI IoReportTargetDeviceChangeAsynchronous ( IN PDEVICE_OBJECT  PhysicalDeviceObject,
IN PVOID  NotificationStructure,
IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback  OPTIONAL,
IN PVOID Context  OPTIONAL 
)

Definition at line 515 of file pnpreport.c.

519 {
522 
523  ASSERT(notifyStruct);
524 
525  /* Check for valid PDO */
527  {
528  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
529  }
530 
531  /* FileObject must be null. PnP will fill in it */
532  ASSERT(notifyStruct->FileObject == NULL);
533 
534  /* Do not handle system PnP events */
535  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
536  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
537  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
538  {
540  }
541 
542  if (notifyStruct->Version != 1)
543  {
545  }
546 
547  /* We need to store all the data given by the caller with the WorkItem, so use our own struct */
549  if (!Item) return STATUS_INSUFFICIENT_RESOURCES;
550 
551  /* Initialize all stuff */
553  Item->NotificationStructure = notifyStruct;
555  Item->Callback = Callback;
556  Item->Context = Context;
558 
559  /* Finally, queue the item, our work here is done */
561 
562  return STATUS_PENDING;
563 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
uint32_t ULONG_PTR
Definition: typedefs.h:65
smooth NULL
Definition: ftsmooth.c:416
struct _TARGET_DEVICE_CUSTOM_NOTIFICATION * PTARGET_DEVICE_CUSTOM_NOTIFICATION
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDEVICE_CHANGE_COMPLETE_CALLBACK Callback
Definition: pnpreport.c:22
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
VOID NTAPI IopReportTargetDeviceChangeAsyncWorker(PVOID Context)
Definition: pnpreport.c:106
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
#define ObReferenceObject
Definition: obfuncs.h:204
WORK_QUEUE_ITEM WorkItem
Definition: pnpreport.c:20
struct tagContext Context
Definition: acpixf.h:1034
PDEVICE_OBJECT PhysicalDeviceObject
Definition: pnpreport.c:21
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:995
LPFNPSPCALLBACK Callback
Definition: desk.c:112
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure
Definition: pnpreport.c:24
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by _IRQL_requires_max_(), DeviceSendNotification(), DiskIoctlUpdateDriveSize(), FsRtlNotifyVolumeEvent(), and MountMgrNotifyNameChange().

◆ PpSetCustomTargetEvent()

NTSTATUS PpSetCustomTargetEvent ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PKEVENT SyncEvent  OPTIONAL,
IN OUT PNTSTATUS SyncStatus  OPTIONAL,
IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback  OPTIONAL,
IN PVOID Context  OPTIONAL,
IN PTARGET_DEVICE_CUSTOM_NOTIFICATION  NotificationStructure 
)

Definition at line 117 of file pnpreport.c.

123 {
126 
127  if (SyncEvent)
128  {
131  }
132 
133  /* That call is totally wrong but notifications handler must be fixed first */
136  &GUID_PNP_CUSTOM_NOTIFICATION,
138  NULL);
139 
140  if (SyncEvent)
141  {
142  KeSetEvent(SyncEvent, IO_NO_INCREMENT, FALSE);
144  }
145 
146  return STATUS_SUCCESS;
147 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
SYNC_STATUS SyncStatus
Definition: internettime.c:14
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID IopNotifyPlugPlayNotification(IN PDEVICE_OBJECT DeviceObject, IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN LPCGUID Event, IN PVOID EventCategoryData1, IN PVOID EventCategoryData2)
Definition: pnpnotify.c:36
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IO_NO_INCREMENT
Definition: iotypes.h:581
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by IopReportTargetDeviceChangeAsyncWorker(), and IoReportTargetDeviceChange().