ReactOS  0.4.15-dev-1618-g9c8ed68
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 1098 of file devaction.c.

1100 {
1103  PWSTR LocationInformation;
1104  PDEVICE_NODE ParentDeviceNode;
1106  NTSTATUS Status;
1108  LCID LocaleId;
1109  HANDLE InstanceKey = NULL;
1111  UNICODE_STRING InstancePathU;
1112  PDEVICE_OBJECT OldDeviceObject;
1113 
1114  DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
1115  DPRINT("PDO 0x%p\n", DeviceNode->PhysicalDeviceObject);
1116 
1117  ParentDeviceNode = (PDEVICE_NODE)Context;
1118 
1119  /*
1120  * We are called for the parent too, but we don't need to do special
1121  * handling for this node
1122  */
1123  if (DeviceNode == ParentDeviceNode)
1124  {
1125  DPRINT("Success\n");
1126  return STATUS_SUCCESS;
1127  }
1128 
1129  /*
1130  * Make sure this device node is a direct child of the parent device node
1131  * that is given as an argument
1132  */
1133  if (DeviceNode->Parent != ParentDeviceNode)
1134  {
1135  DPRINT("Skipping 2+ level child\n");
1136  return STATUS_SUCCESS;
1137  }
1138 
1139  /* Skip processing if it was already completed before */
1140  if (DeviceNode->Flags & DNF_PROCESSED)
1141  {
1142  /* Nothing to do */
1143  return STATUS_SUCCESS;
1144  }
1145 
1146  /* Get Locale ID */
1148  if (!NT_SUCCESS(Status))
1149  {
1150  DPRINT1("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status);
1151  return Status;
1152  }
1153 
1154  /*
1155  * FIXME: For critical errors, cleanup and disable device, but always
1156  * return STATUS_SUCCESS.
1157  */
1158 
1159  Status = IopCreateDeviceInstancePath(DeviceNode, &InstancePathU);
1160  if (!NT_SUCCESS(Status))
1161  {
1163  {
1164  DPRINT1("IopCreateDeviceInstancePath() failed with status 0x%lx\n", Status);
1165  }
1166 
1167  /* We have to return success otherwise we abort the traverse operation */
1168  return STATUS_SUCCESS;
1169  }
1170 
1171  /* Verify that this is not a duplicate */
1172  OldDeviceObject = IopGetDeviceObjectFromDeviceInstance(&InstancePathU);
1173  if (OldDeviceObject != NULL)
1174  {
1175  PDEVICE_NODE OldDeviceNode = IopGetDeviceNode(OldDeviceObject);
1176 
1177  DPRINT1("Duplicate device instance '%wZ'\n", &InstancePathU);
1178  DPRINT1("Current instance parent: '%wZ'\n", &DeviceNode->Parent->InstancePath);
1179  DPRINT1("Old instance parent: '%wZ'\n", &OldDeviceNode->Parent->InstancePath);
1180 
1181  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR,
1182  0x01,
1183  (ULONG_PTR)DeviceNode->PhysicalDeviceObject,
1184  (ULONG_PTR)OldDeviceObject,
1185  0);
1186  }
1187 
1188  DeviceNode->InstancePath = InstancePathU;
1189 
1190  DPRINT("InstancePath is %S\n", DeviceNode->InstancePath.Buffer);
1191 
1192  /*
1193  * Create registry key for the instance id, if it doesn't exist yet
1194  */
1195  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
1196  if (!NT_SUCCESS(Status))
1197  {
1198  DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
1199 
1200  /* We have to return success otherwise we abort the traverse operation */
1201  return STATUS_SUCCESS;
1202  }
1203 
1204  IopQueryHardwareIds(DeviceNode, InstanceKey);
1205 
1206  IopQueryCompatibleIds(DeviceNode, InstanceKey);
1207 
1208  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextDescription to device stack\n");
1209 
1210  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextDescription;
1211  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
1212  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
1213  &IoStatusBlock,
1215  &Stack);
1217  : NULL;
1218  /* This key is mandatory, so even if the Irp fails, we still write it */
1219  RtlInitUnicodeString(&ValueName, L"DeviceDesc");
1220  if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
1221  {
1222  if (DeviceDescription &&
1224  {
1225  /* This key is overriden when a driver is installed. Don't write the
1226  * new description if another one already exists */
1227  Status = ZwSetValueKey(InstanceKey,
1228  &ValueName,
1229  0,
1230  REG_SZ,
1232  ((ULONG)wcslen(DeviceDescription) + 1) * sizeof(WCHAR));
1233  }
1234  else
1235  {
1236  UNICODE_STRING DeviceDesc = RTL_CONSTANT_STRING(L"Unknown device");
1237  DPRINT("Driver didn't return DeviceDesc (Status 0x%08lx), so place unknown device there\n", Status);
1238 
1239  Status = ZwSetValueKey(InstanceKey,
1240  &ValueName,
1241  0,
1242  REG_SZ,
1243  DeviceDesc.Buffer,
1244  DeviceDesc.MaximumLength);
1245  if (!NT_SUCCESS(Status))
1246  {
1247  DPRINT1("ZwSetValueKey() failed (Status 0x%lx)\n", Status);
1248  }
1249 
1250  }
1251  }
1252 
1253  if (DeviceDescription)
1254  {
1256  }
1257 
1258  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocation to device stack\n");
1259 
1260  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextLocationInformation;
1261  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
1262  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
1263  &IoStatusBlock,
1265  &Stack);
1267  {
1268  LocationInformation = (PWSTR)IoStatusBlock.Information;
1269  DPRINT("LocationInformation: %S\n", LocationInformation);
1270  RtlInitUnicodeString(&ValueName, L"LocationInformation");
1271  Status = ZwSetValueKey(InstanceKey,
1272  &ValueName,
1273  0,
1274  REG_SZ,
1275  LocationInformation,
1276  ((ULONG)wcslen(LocationInformation) + 1) * sizeof(WCHAR));
1277  if (!NT_SUCCESS(Status))
1278  {
1279  DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
1280  }
1281 
1282  ExFreePoolWithTag(LocationInformation, 0);
1283  }
1284  else
1285  {
1286  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
1287  }
1288 
1289  DPRINT("Sending IRP_MN_QUERY_BUS_INFORMATION to device stack\n");
1290 
1291  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
1292  &IoStatusBlock,
1294  NULL);
1296  {
1298 
1299  DeviceNode->ChildBusNumber = BusInformation->BusNumber;
1300  DeviceNode->ChildInterfaceType = BusInformation->LegacyBusType;
1301  DeviceNode->ChildBusTypeIndex = IopGetBusTypeGuidIndex(&BusInformation->BusTypeGuid);
1303  }
1304  else
1305  {
1306  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
1307 
1308  DeviceNode->ChildBusNumber = 0xFFFFFFF0;
1309  DeviceNode->ChildInterfaceType = InterfaceTypeUndefined;
1310  DeviceNode->ChildBusTypeIndex = -1;
1311  }
1312 
1313  DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
1314 
1315  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
1316  &IoStatusBlock,
1318  NULL);
1320  {
1323  }
1324  else
1325  {
1326  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
1327  DeviceNode->BootResources = NULL;
1328  }
1329 
1330  DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
1331 
1332  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
1333  &IoStatusBlock,
1335  NULL);
1336  if (NT_SUCCESS(Status))
1337  {
1339  }
1340  else
1341  {
1342  DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status);
1343  DeviceNode->ResourceRequirements = NULL;
1344  }
1345 
1346  if (InstanceKey != NULL)
1347  {
1348  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
1349  }
1350 
1351  ZwClose(InstanceKey);
1352 
1354 
1356  {
1357  /* Report the device to the user-mode pnp manager */
1358  IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
1359  &DeviceNode->InstancePath);
1360  }
1361 
1362  return STATUS_SUCCESS;
1363 }
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:599
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:953
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
static NTSTATUS IopQueryCompatibleIds(PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
Definition: devaction.c:1018
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:430
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:209
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
struct _PNP_BUS_INFORMATION * PPNP_BUS_INFORMATION
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:43
USHORT NTAPI IopGetBusTypeGuidIndex(LPGUID BusTypeGuid)
Definition: pnpmgr.c:412
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:122
#define IRP_MN_QUERY_DEVICE_TEXT
Definition: Node.h:9
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING _In_ PCUNICODE_STRING _In_ LCID LocaleId
Definition: wdfpdo.h:430
#define IRP_MN_QUERY_BUS_INFORMATION
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_In_ WDFDEVICE _In_ PPNP_BUS_INFORMATION BusInformation
Definition: wdfdevice.h:3912
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)
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:683
#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 }
static const WCHAR L[]
Definition: oid.c:1250
#define NULL
Definition: types.h:112
#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 
111  PpSetCustomTargetEvent(Item->PhysicalDeviceObject, NULL, NULL, Item->Callback, Item->Context, Item->NotificationStructure);
112  ObDereferenceObject(Item->PhysicalDeviceObject);
113  ExFreePoolWithTag(Context, ' pP');
114 }
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
#define ObDereferenceObject
Definition: obfuncs.h:203
#define NULL
Definition: types.h:112
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by IoReportTargetDeviceChangeAsynchronous().

◆ IopSetDeviceInstanceData()

NTSTATUS IopSetDeviceInstanceData ( HANDLE  InstanceKey,
PDEVICE_NODE  DeviceNode 
)

Definition at line 683 of file pnpmgr.c.

685 {
688  HANDLE LogConfKey, ControlKey, DeviceParamsKey;
689  ULONG ResCount;
692 
693  DPRINT("IopSetDeviceInstanceData() called\n");
694 
695  /* Create the 'LogConf' key */
696  RtlInitUnicodeString(&KeyName, L"LogConf");
698  &KeyName,
700  InstanceKey,
701  NULL);
702  Status = ZwCreateKey(&LogConfKey,
705  0,
706  NULL,
707  // FIXME? In r53694 it was silently turned from non-volatile into this,
708  // without any extra warning. Is this still needed??
710  NULL);
711  if (NT_SUCCESS(Status))
712  {
713  /* Set 'BootConfig' value */
714  if (DeviceNode->BootResources != NULL)
715  {
716  ResCount = DeviceNode->BootResources->Count;
717  if (ResCount != 0)
718  {
719  RtlInitUnicodeString(&KeyName, L"BootConfig");
720  Status = ZwSetValueKey(LogConfKey,
721  &KeyName,
722  0,
724  DeviceNode->BootResources,
725  PnpDetermineResourceListSize(DeviceNode->BootResources));
726  }
727  }
728 
729  /* Set 'BasicConfigVector' value */
730  if (DeviceNode->ResourceRequirements != NULL &&
731  DeviceNode->ResourceRequirements->ListSize != 0)
732  {
733  RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
734  Status = ZwSetValueKey(LogConfKey,
735  &KeyName,
736  0,
738  DeviceNode->ResourceRequirements,
739  DeviceNode->ResourceRequirements->ListSize);
740  }
741 
742  ZwClose(LogConfKey);
743  }
744 
745  /* Set the 'ConfigFlags' value */
746  RtlInitUnicodeString(&KeyName, L"ConfigFlags");
747  Status = ZwQueryValueKey(InstanceKey,
748  &KeyName,
750  NULL,
751  0,
752  &ResultLength);
754  {
755  /* Write the default value */
756  ULONG DefaultConfigFlags = 0;
757  Status = ZwSetValueKey(InstanceKey,
758  &KeyName,
759  0,
760  REG_DWORD,
761  &DefaultConfigFlags,
762  sizeof(DefaultConfigFlags));
763  }
764 
765  /* Create the 'Control' key */
766  RtlInitUnicodeString(&KeyName, L"Control");
768  &KeyName,
770  InstanceKey,
771  NULL);
772  Status = ZwCreateKey(&ControlKey,
773  0,
775  0,
776  NULL,
778  NULL);
779  if (NT_SUCCESS(Status))
780  ZwClose(ControlKey);
781 
782  /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
783  if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
784  {
785  RtlInitUnicodeString(&KeyName, L"Device Parameters");
787  &KeyName,
789  InstanceKey,
790  NULL);
791  Status = ZwCreateKey(&DeviceParamsKey,
792  0,
794  0,
795  NULL,
797  NULL);
798  if (NT_SUCCESS(Status))
799  {
800  ULONG FirmwareIdentified = 1;
801  RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
802  Status = ZwSetValueKey(DeviceParamsKey,
803  &KeyName,
804  0,
805  REG_DWORD,
806  &FirmwareIdentified,
807  sizeof(FirmwareIdentified));
808 
809  ZwClose(DeviceParamsKey);
810  }
811  }
812 
813  DPRINT("IopSetDeviceInstanceData() done\n");
814 
815  return Status;
816 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#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
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
Status
Definition: gdiplustypes.h:24
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: Node.h:9
static const WCHAR L[]
Definition: oid.c:1250
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1884
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define NULL
Definition: types.h:112
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
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
#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 447 of file pnpreport.c.

448 {
450 
451  /* Set the event */
453 }
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:598

◆ 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 152 of file pnpreport.c.

160 {
164  HANDLE InstanceKey;
166  UNICODE_STRING ValueName, ServiceLongName, ServiceName;
167  WCHAR HardwareId[256];
168  PWCHAR IfString;
169  ULONG IdLength;
170  ULONG LegacyValue;
171 
172  DPRINT("IoReportDetectedDevice (DeviceObject %p, *DeviceObject %p)\n",
174 
175  ServiceLongName = DriverObject->DriverExtension->ServiceKeyName;
176  ServiceName = ServiceLongName;
177 
178  /* If the interface type is unknown, treat it as internal */
181 
182  /* Get the string equivalent of the interface type */
184 
185  /* If NULL is returned then it's a bad type */
186  if (!IfString)
188 
189  /*
190  * Drivers that have been created via a direct IoCreateDriver() call
191  * have their ServiceKeyName set to \Driver\DriverName. We need to
192  * strip everything up to the last path separator and keep what remains.
193  */
194  if (DriverObject->Flags & DRVO_BUILTIN_DRIVER)
195  {
196  /*
197  * Find the last path separator.
198  * NOTE: Since ServiceName is not necessarily NULL-terminated,
199  * we cannot use wcsrchr().
200  */
201  if (ServiceName.Buffer && ServiceName.Length >= sizeof(WCHAR))
202  {
203  ValueName.Length = 1;
204  ValueName.Buffer = ServiceName.Buffer + (ServiceName.Length / sizeof(WCHAR)) - 1;
205 
206  while ((ValueName.Buffer > ServiceName.Buffer) && (*ValueName.Buffer != L'\\'))
207  {
208  --ValueName.Buffer;
209  ++ValueName.Length;
210  }
211  if (*ValueName.Buffer == L'\\')
212  {
213  ++ValueName.Buffer;
214  --ValueName.Length;
215  }
216  ValueName.Length *= sizeof(WCHAR);
217 
218  /* Shorten the string */
219  ServiceName.MaximumLength -= (ServiceName.Length - ValueName.Length);
220  ServiceName.Length = ValueName.Length;
221  ServiceName.Buffer = ValueName.Buffer;
222  }
223  }
224 
225  /* We use the caller's PDO if they supplied one */
226  if (DeviceObject && *DeviceObject)
227  {
228  Pdo = *DeviceObject;
229  }
230  else
231  {
232  /* Create the PDO */
234  NULL,
235  &Pdo,
236  NULL);
237  if (!NT_SUCCESS(Status))
238  {
239  DPRINT("PnpRootCreateDevice() failed (Status 0x%08lx)\n", Status);
240  return Status;
241  }
242  }
243 
244  /* Create the device node for the new PDO */
246  if (!DeviceNode)
247  {
248  DPRINT("PipAllocateDeviceNode() failed\n");
250  }
251 
253 
254  /* We're enumerated already */
256 
257  /* We don't call AddDevice for devices reported this way */
259 
260  /* We don't send IRP_MN_START_DEVICE */
262 
263  /* We need to get device IDs */
264 #if 0
265  IopDeviceNodeSetFlag(DeviceNode, DNF_NEED_QUERY_IDS);
266 #endif
267 
268  /* This is a legacy driver for this device */
270 
271  /* Perform a manual configuration of our device */
274 
275  /* Open a handle to the instance path key */
276  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
277  if (!NT_SUCCESS(Status))
278  return Status;
279 
280  /* Save the driver name */
281  RtlInitUnicodeString(&ValueName, L"Service");
282  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_SZ, ServiceLongName.Buffer, ServiceLongName.Length + sizeof(UNICODE_NULL));
283  if (!NT_SUCCESS(Status))
284  {
285  DPRINT("Failed to write the Service name value: 0x%x\n", Status);
286  }
287 
288  /* Report as non-legacy driver */
289  RtlInitUnicodeString(&ValueName, L"Legacy");
290  LegacyValue = 0;
291  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_DWORD, &LegacyValue, sizeof(LegacyValue));
292  if (!NT_SUCCESS(Status))
293  {
294  DPRINT("Failed to write the Legacy value: 0x%x\n", Status);
295  }
296 
297  /* Add DETECTEDInterfaceType\DriverName */
298  IdLength = 0;
299  IdLength += swprintf(&HardwareId[IdLength],
300  L"DETECTED%ls\\%wZ",
301  IfString,
302  &ServiceName);
303  IdLength++;
304 
305  /* Add DETECTED\DriverName */
306  IdLength += swprintf(&HardwareId[IdLength],
307  L"DETECTED\\%wZ",
308  &ServiceName);
309  IdLength++;
310 
311  /* Terminate the string with another null */
312  HardwareId[IdLength++] = UNICODE_NULL;
313 
314  /* Store the value for CompatibleIDs */
315  RtlInitUnicodeString(&ValueName, L"CompatibleIDs");
316  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
317  if (!NT_SUCCESS(Status))
318  {
319  DPRINT("Failed to write the compatible IDs: 0x%x\n", Status);
320  ZwClose(InstanceKey);
321  return Status;
322  }
323 
324  /* Add a hardware ID if the driver didn't report one */
325  RtlInitUnicodeString(&ValueName, L"HardwareID");
326  if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
327  {
328  /* Just use our most specific compatible ID */
329  IdLength = 0;
330  IdLength += swprintf(&HardwareId[IdLength],
331  L"DETECTED%ls\\%wZ",
332  IfString,
333  &ServiceName);
334  IdLength++;
335 
336  HardwareId[IdLength++] = UNICODE_NULL;
337 
338  /* Write the value to the registry */
339  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
340  if (!NT_SUCCESS(Status))
341  {
342  DPRINT("Failed to write the hardware ID: 0x%x\n", Status);
343  ZwClose(InstanceKey);
344  return Status;
345  }
346  }
347 
348  /* Assign the resources to the device node */
349  DeviceNode->BootResources = ResourceList;
350  DeviceNode->ResourceRequirements = ResourceRequirements;
351 
352  /* Set appropriate flags */
353  if (DeviceNode->BootResources)
355 
356  if (!DeviceNode->ResourceRequirements && !DeviceNode->BootResources)
358 
359  /* Write the resource information to the registry */
360  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
361 
362  /* If the caller didn't get the resources assigned for us, do it now */
363  if (!ResourceAssigned)
364  {
366 
367  /* See if we failed */
368  if (!NT_SUCCESS(Status))
369  {
370  DPRINT("Assigning resources failed: 0x%x\n", Status);
371  ZwClose(InstanceKey);
372  return Status;
373  }
374  }
375 
376  /* Close the instance key handle */
377  ZwClose(InstanceKey);
378 
379  /* Register the given DO with PnP root if required */
380  if (DeviceObject && *DeviceObject)
382 
383  /* Report the device's enumeration to umpnpmgr */
384  IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
385  &DeviceNode->InstancePath);
386 
387  /* Report the device's arrival to umpnpmgr */
388  IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
389  &DeviceNode->InstancePath);
390 
391  DPRINT("Reported device: %S (%wZ)\n", HardwareId, &DeviceNode->InstancePath);
392 
394 
395  /* Return the PDO */
396  if (DeviceObject) *DeviceObject = Pdo;
397 
398  return STATUS_SUCCESS;
399 }
NTSTATUS IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: devaction.c:1098
NTSTATUS PnpRootRegisterDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnproot.c:129
#define DRVO_BUILTIN_DRIVER
Definition: iotypes.h:2224
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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:2950
#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:599
LONG NTSTATUS
Definition: precomp.h:26
#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
#define swprintf
Definition: precomp.h:40
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:304
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:683
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define UNICODE_NULL
PDEVICE_NODE PipAllocateDeviceNode(IN PDEVICE_OBJECT PhysicalDeviceObject)
#define REG_MULTI_SZ
Definition: nt_native.h:1501
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:64
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
void DPRINT(...)
Definition: polytest.cpp:61
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define DNF_STARTED
Definition: iotypes.h:168
Status
Definition: gdiplustypes.h:24
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
NTSTATUS IopQueueTargetDeviceEvent(const GUID *Guid, PUNICODE_STRING DeviceIds)
Definition: plugplay.c:43
LPTSTR ServiceName
Definition: ServiceMain.c:15
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: Node.h:9
_In_ INTERFACE_TYPE LegacyBusType
Definition: iofuncs.h:1543
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
static const WCHAR L[]
Definition: oid.c:1250
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
#define NULL
Definition: types.h:112
VOID PiInsertDevNode(_In_ PDEVICE_NODE DeviceNode, _In_ PDEVICE_NODE ParentNode)
Definition: devnode.c:78
NTSTATUS NTAPI IopAssignDeviceResources(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:1106
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
#define STATUS_SUCCESS
Definition: shellext.h:65
_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
#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(), ReportGreenPdo(), and ScsiPortInitialize().

◆ 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 406 of file pnpreport.c.

413 {
416 
417  *ConflictDetected = FALSE;
418 
419  if (!DriverList && !DeviceList)
421 
422  /* Find the real list */
423  if (!DriverList)
425  else
426  ResourceList = DriverList;
427 
428  /* Look for a resource conflict */
431  {
432  /* Oh noes */
433  *ConflictDetected = TRUE;
434  }
435  else if (NT_SUCCESS(Status))
436  {
437  /* Looks like we're good to go */
438 
439  /* TODO: Claim the resources in the ResourceMap */
440  }
441 
442  return Status;
443 }
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_LIST DeviceList
Definition: utils.c:27
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:304
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NULL
Definition: types.h:112
#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:1252

Referenced by VideoPortVerifyAccessRanges().

◆ IoReportTargetDeviceChange()

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

Definition at line 460 of file pnpreport.c.

462 {
463  KEVENT NotifyEvent;
464  NTSTATUS Status, NotifyStatus;
466 
467  ASSERT(notifyStruct);
468 
469  /* Check for valid PDO */
471  {
472  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
473  }
474 
475  /* FileObject must be null. PnP will fill in it */
476  ASSERT(notifyStruct->FileObject == NULL);
477 
478  /* Do not handle system PnP events */
479  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
480  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
481  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
482  {
484  }
485 
486  if (notifyStruct->Version != 1)
487  {
489  }
490 
491  /* Initialize even that will let us know when PnP will have finished notify */
492  KeInitializeEvent(&NotifyEvent, NotificationEvent, FALSE);
493 
494  Status = PpSetCustomTargetEvent(PhysicalDeviceObject, &NotifyEvent, &NotifyStatus, NULL, NULL, notifyStruct);
495  /* If no error, wait for the notify to end and return the status of the notify and not of the event */
496  if (NT_SUCCESS(Status))
497  {
499  Status = NotifyStatus;
500  }
501 
502  return Status;
503 }
_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
Status
Definition: gdiplustypes.h:24
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 ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:1012
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 510 of file pnpreport.c.

514 {
517 
518  ASSERT(notifyStruct);
519 
520  /* Check for valid PDO */
522  {
523  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
524  }
525 
526  /* FileObject must be null. PnP will fill in it */
527  ASSERT(notifyStruct->FileObject == NULL);
528 
529  /* Do not handle system PnP events */
530  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
531  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
532  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
533  {
535  }
536 
537  if (notifyStruct->Version != 1)
538  {
540  }
541 
542  /* We need to store all the data given by the caller with the WorkItem, so use our own struct */
544  if (!Item) return STATUS_INSUFFICIENT_RESOURCES;
545 
546  /* Initialize all stuff */
548  Item->NotificationStructure = notifyStruct;
549  Item->PhysicalDeviceObject = PhysicalDeviceObject;
550  Item->Callback = Callback;
551  Item->Context = Context;
553 
554  /* Finally, queue the item, our work here is done */
555  ExQueueWorkItem(&(Item->WorkItem), DelayedWorkQueue);
556 
557  return STATUS_PENDING;
558 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:711
#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
struct _TARGET_DEVICE_CUSTOM_NOTIFICATION * PTARGET_DEVICE_CUSTOM_NOTIFICATION
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define ASSERT(a)
Definition: mode.c:45
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
VOID NTAPI IopReportTargetDeviceChangeAsyncWorker(PVOID Context)
Definition: pnpreport.c:106
#define NULL
Definition: types.h:112
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
struct tagContext Context
Definition: acpixf.h:1034
#define ObReferenceObject
Definition: obfuncs.h:204
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:1012
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 _IRQL_requires_max_(), DeviceSendNotification(), DiskIoctlUpdateDriveSize(), FdoIoctlDiskSetDriveLayout(), FdoIoctlDiskSetDriveLayoutEx(), 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 */
134  PiNotifyTargetDeviceChange(&GUID_PNP_CUSTOM_NOTIFICATION, DeviceObject, NotificationStructure);
135 
136  if (SyncEvent)
137  {
138  KeSetEvent(SyncEvent, IO_NO_INCREMENT, FALSE);
140  }
141 
142  return STATUS_SUCCESS;
143 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:45
SYNC_STATUS SyncStatus
Definition: internettime.c:14
#define STATUS_PENDING
Definition: ntstatus.h:82
#define NULL
Definition: types.h:112
VOID PiNotifyTargetDeviceChange(_In_ LPCGUID Event, _In_ PDEVICE_OBJECT DeviceObject, _In_opt_ PTARGET_DEVICE_CUSTOM_NOTIFICATION CustomNotification)
Delivers the event to all drivers subscribed to EventCategoryTargetDeviceChange PnP event.
Definition: pnpnotify.c:258
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by IopReportTargetDeviceChangeAsyncWorker(), and IoReportTargetDeviceChange().