ReactOS  0.4.15-dev-5142-g967f5b9
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 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_opt_ PCM_RESOURCE_LIST ResourceList, _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements, _In_ BOOLEAN ResourceAssigned, _Inout_ PDEVICE_OBJECT *DeviceObject)
 
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

◆ IopGetInterfaceTypeString()

PWCHAR IopGetInterfaceTypeString ( INTERFACE_TYPE  IfType)

Definition at line 42 of file pnpreport.c.

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

Referenced by IoReportDetectedDevice().

◆ IopReportTargetDeviceChangeAsyncWorker()

VOID NTAPI IopReportTargetDeviceChangeAsyncWorker ( PVOID  Context)

Definition at line 102 of file pnpreport.c.

103 {
105 
107  PpSetCustomTargetEvent(Item->PhysicalDeviceObject, NULL, NULL, Item->Callback, Item->Context, Item->NotificationStructure);
108  ObDereferenceObject(Item->PhysicalDeviceObject);
109  ExFreePoolWithTag(Context, ' pP');
110 }
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:113
#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 606 of file pnpmgr.c.

608 {
611  HANDLE LogConfKey, ControlKey, DeviceParamsKey;
612  ULONG ResCount;
615 
616  DPRINT("IopSetDeviceInstanceData() called\n");
617 
618  /* Create the 'LogConf' key */
619  RtlInitUnicodeString(&KeyName, L"LogConf");
621  &KeyName,
623  InstanceKey,
624  NULL);
625  Status = ZwCreateKey(&LogConfKey,
628  0,
629  NULL,
630  // FIXME? In r53694 it was silently turned from non-volatile into this,
631  // without any extra warning. Is this still needed??
633  NULL);
634  if (NT_SUCCESS(Status))
635  {
636  /* Set 'BootConfig' value */
637  if (DeviceNode->BootResources != NULL)
638  {
639  ResCount = DeviceNode->BootResources->Count;
640  if (ResCount != 0)
641  {
642  RtlInitUnicodeString(&KeyName, L"BootConfig");
643  Status = ZwSetValueKey(LogConfKey,
644  &KeyName,
645  0,
647  DeviceNode->BootResources,
648  PnpDetermineResourceListSize(DeviceNode->BootResources));
649  }
650  }
651 
652  /* Set 'BasicConfigVector' value */
653  if (DeviceNode->ResourceRequirements != NULL &&
654  DeviceNode->ResourceRequirements->ListSize != 0)
655  {
656  RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
657  Status = ZwSetValueKey(LogConfKey,
658  &KeyName,
659  0,
661  DeviceNode->ResourceRequirements,
662  DeviceNode->ResourceRequirements->ListSize);
663  }
664 
665  ZwClose(LogConfKey);
666  }
667 
668  /* Set the 'ConfigFlags' value */
669  RtlInitUnicodeString(&KeyName, L"ConfigFlags");
670  Status = ZwQueryValueKey(InstanceKey,
671  &KeyName,
673  NULL,
674  0,
675  &ResultLength);
677  {
678  /* Write the default value */
679  ULONG DefaultConfigFlags = 0;
680  Status = ZwSetValueKey(InstanceKey,
681  &KeyName,
682  0,
683  REG_DWORD,
684  &DefaultConfigFlags,
685  sizeof(DefaultConfigFlags));
686  }
687 
688  /* Create the 'Control' key */
689  RtlInitUnicodeString(&KeyName, L"Control");
691  &KeyName,
693  InstanceKey,
694  NULL);
695  Status = ZwCreateKey(&ControlKey,
696  0,
698  0,
699  NULL,
701  NULL);
702  if (NT_SUCCESS(Status))
703  ZwClose(ControlKey);
704 
705  /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
706  if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
707  {
708  RtlInitUnicodeString(&KeyName, L"Device Parameters");
710  &KeyName,
712  InstanceKey,
713  NULL);
714  Status = ZwCreateKey(&DeviceParamsKey,
715  0,
717  0,
718  NULL,
720  NULL);
721  if (NT_SUCCESS(Status))
722  {
723  ULONG FirmwareIdentified = 1;
724  RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
725  Status = ZwSetValueKey(DeviceParamsKey,
726  &KeyName,
727  0,
728  REG_DWORD,
729  &FirmwareIdentified,
730  sizeof(FirmwareIdentified));
731 
732  ZwClose(DeviceParamsKey);
733  }
734  }
735 
736  DPRINT("IopSetDeviceInstanceData() done\n");
737 
738  return Status;
739 }
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
#define L(x)
Definition: ntvdm.h:50
#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
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1807
#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 DPRINT
Definition: sndvol32.h:71
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by IoReportDetectedDevice().

◆ IopSetEvent()

VOID NTAPI IopSetEvent ( IN PVOID  Context)

Definition at line 434 of file pnpreport.c.

435 {
437 
438  /* Set the event */
440 }
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_opt_ PCM_RESOURCE_LIST  ResourceList,
_In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST  ResourceRequirements,
_In_ BOOLEAN  ResourceAssigned,
_Inout_ PDEVICE_OBJECT DeviceObject 
)

Definition at line 148 of file pnpreport.c.

157 {
159  UNICODE_STRING DeviceReportedName = RTL_CONSTANT_STRING(L"DeviceReported");
164  HANDLE InstanceKey, ControlKey;
165  UNICODE_STRING ValueName, ServiceLongName, ServiceName;
166  WCHAR HardwareId[256];
167  PWCHAR IfString;
168  ULONG IdLength;
169  ULONG LegacyValue;
170  ULONG DeviceReported = 1;
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  UNICODE_STRING instancePath;
227  if (DeviceObject && *DeviceObject)
228  {
229  Pdo = *DeviceObject;
230  }
231  else
232  {
233  /* Create the PDO */
234  Status = PnpRootCreateDevice(&ServiceName, NULL, &Pdo, &instancePath);
235  if (!NT_SUCCESS(Status))
236  {
237  DPRINT("PnpRootCreateDevice() failed (Status 0x%08lx)\n", Status);
238  return Status;
239  }
240  }
241 
242  /* Create the device node for the new PDO */
244  if (!DeviceNode)
245  {
246  DPRINT("PipAllocateDeviceNode() failed\n");
248  }
249 
250  Status = RtlDuplicateUnicodeString(0, &instancePath, &DeviceNode->InstancePath);
251 
252  /* Open a handle to the instance path key */
253  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
254  if (!NT_SUCCESS(Status))
255  return Status;
256 
257  /* Save the driver name */
258  RtlInitUnicodeString(&ValueName, L"Service");
259  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_SZ, ServiceLongName.Buffer, ServiceLongName.Length + sizeof(UNICODE_NULL));
260  if (!NT_SUCCESS(Status))
261  {
262  DPRINT("Failed to write the Service name value: 0x%x\n", Status);
263  }
264 
265  /* Report as non-legacy driver */
266  RtlInitUnicodeString(&ValueName, L"Legacy");
267  LegacyValue = 0;
268  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_DWORD, &LegacyValue, sizeof(LegacyValue));
269  if (!NT_SUCCESS(Status))
270  {
271  DPRINT("Failed to write the Legacy value: 0x%x\n", Status);
272  }
273  Status = ZwSetValueKey(InstanceKey, &DeviceReportedName, 0, REG_DWORD, &DeviceReported, sizeof(DeviceReported));
274  if (!NT_SUCCESS(Status))
275  {
276  DPRINT("Failed to write the DeviceReported value: 0x%x\n", Status);
277  }
278 
279  /* Set DeviceReported=1 in Control subkey */
281  &Control,
283  InstanceKey,
284  NULL);
285  Status = ZwCreateKey(&ControlKey,
288  0,
289  NULL,
291  NULL);
292  if (NT_SUCCESS(Status))
293  {
294  Status = ZwSetValueKey(ControlKey,
295  &DeviceReportedName,
296  0,
297  REG_DWORD,
298  &DeviceReported,
299  sizeof(DeviceReported));
300  ZwClose(ControlKey);
301  }
302  if (!NT_SUCCESS(Status))
303  {
304  DPRINT1("Failed to set ReportedDevice=1 for device %wZ (status 0x%08lx)\n", &instancePath, Status);
305  }
306 
307  /* Add DETECTEDInterfaceType\DriverName */
308  IdLength = 0;
309  IdLength += swprintf(&HardwareId[IdLength],
310  L"DETECTED%ls\\%wZ",
311  IfString,
312  &ServiceName);
313  IdLength++;
314 
315  /* Add DETECTED\DriverName */
316  IdLength += swprintf(&HardwareId[IdLength],
317  L"DETECTED\\%wZ",
318  &ServiceName);
319  IdLength++;
320 
321  /* Terminate the string with another null */
322  HardwareId[IdLength++] = UNICODE_NULL;
323 
324  /* Store the value for CompatibleIDs */
325  RtlInitUnicodeString(&ValueName, L"CompatibleIDs");
326  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
327  if (!NT_SUCCESS(Status))
328  {
329  DPRINT("Failed to write the compatible IDs: 0x%x\n", Status);
330  ZwClose(InstanceKey);
331  return Status;
332  }
333 
334  // Set the device's DeviceDesc and LocationInformation fields
335  PiSetDevNodeText(DeviceNode, InstanceKey);
336 
337  /* Assign the resources to the device node */
338  DeviceNode->BootResources = ResourceList;
339  DeviceNode->ResourceRequirements = ResourceRequirements;
340 
341  /* Set appropriate flags */
342  if (DeviceNode->BootResources)
344 
345  if (!DeviceNode->ResourceRequirements && !DeviceNode->BootResources)
347 
348  /* Write the resource information to the registry */
349  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
350 
351  /* If the caller didn't get the resources assigned for us, do it now */
352  if (!ResourceAssigned)
353  {
355 
356  /* See if we failed */
357  if (!NT_SUCCESS(Status))
358  {
359  DPRINT("Assigning resources failed: 0x%x\n", Status);
360  ZwClose(InstanceKey);
361  return Status;
362  }
363  }
364 
365  /* Close the instance key handle */
366  ZwClose(InstanceKey);
367 
368  /* Register the given DO with PnP root if required */
369  if (DeviceObject && *DeviceObject)
371 
374 
375  // we still need to query IDs, send events and reenumerate this node
377 
378  DPRINT("Reported device: %S (%wZ)\n", HardwareId, &DeviceNode->InstancePath);
379 
381 
382  /* Return the PDO */
383  if (DeviceObject) *DeviceObject = Pdo;
384 
385  return STATUS_SUCCESS;
386 }
NTSTATUS PnpRootRegisterDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnproot.c:130
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define DRVO_BUILTIN_DRIVER
Definition: iotypes.h:2227
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PNP_DEVNODE_STATE PiSetDevNodeState(_In_ PDEVICE_NODE DeviceNode, _In_ PNP_DEVNODE_STATE NewState)
Definition: devnode.c:108
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:2655
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#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:522
LONG NTSTATUS
Definition: precomp.h:26
#define DNF_NO_RESOURCE_REQUIRED
Definition: iotypes.h:178
#define DNF_HAS_BOOT_CONFIG
Definition: iotypes.h:176
uint16_t * PWCHAR
Definition: typedefs.h:56
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
_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:606
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define L(x)
Definition: ntvdm.h:50
#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:146
_In_ WDF_WMI_PROVIDER_CONTROL Control
Definition: wdfwmi.h:166
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
LPTSTR ServiceName
Definition: ServiceMain.c:15
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
Definition: Node.h:9
_In_ INTERFACE_TYPE LegacyBusType
Definition: iofuncs.h:1547
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
int _cdecl swprintf(const WCHAR *,...)
VOID PiSetDevNodeText(_In_ PDEVICE_NODE DeviceNode, _In_ HANDLE InstanceKey)
Sets the DeviceNode's DeviceDesc and LocationInformation registry values.
Definition: devaction.c:1089
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
VOID PiInsertDevNode(_In_ PDEVICE_NODE DeviceNode, _In_ PDEVICE_NODE ParentNode)
Definition: devnode.c:80
NTSTATUS NTAPI IopAssignDeviceResources(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:1116
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 DNF_ENUMERATED
Definition: iotypes.h:174
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements
Definition: iofuncs.h:1547
#define DNF_MADEUP
Definition: iotypes.h:170
#define STATUS_SUCCESS
Definition: shellext.h:65
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST _In_ BOOLEAN ResourceAssigned
Definition: iofuncs.h:1547
#define DPRINT
Definition: sndvol32.h:71
PWCHAR IopGetInterfaceTypeString(INTERFACE_TYPE IfType)
Definition: pnpreport.c:42
#define REG_DWORD
Definition: sdbapi.c:596
NTSTATUS PnpRootCreateDevice(IN PUNICODE_STRING ServiceName, IN OPTIONAL PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *PhysicalDeviceObject, OUT OPTIONAL PUNICODE_STRING FullInstancePath)
Definition: pnproot.c:186
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#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 393 of file pnpreport.c.

400 {
403 
404  *ConflictDetected = FALSE;
405 
406  if (!DriverList && !DeviceList)
408 
409  /* Find the real list */
410  if (!DriverList)
412  else
413  ResourceList = DriverList;
414 
415  /* Look for a resource conflict */
418  {
419  /* Oh noes */
420  *ConflictDetected = TRUE;
421  }
422  else if (NT_SUCCESS(Status))
423  {
424  /* Looks like we're good to go */
425 
426  /* TODO: Claim the resources in the ResourceMap */
427  }
428 
429  return Status;
430 }
#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:1255

Referenced by VideoPortVerifyAccessRanges().

◆ IoReportTargetDeviceChange()

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

Definition at line 447 of file pnpreport.c.

449 {
450  KEVENT NotifyEvent;
451  NTSTATUS Status, NotifyStatus;
453 
454  ASSERT(notifyStruct);
455 
456  /* Check for valid PDO */
458  {
459  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
460  }
461 
462  /* FileObject must be null. PnP will fill in it */
463  ASSERT(notifyStruct->FileObject == NULL);
464 
465  /* Do not handle system PnP events */
466  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
467  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
468  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
469  {
471  }
472 
473  if (notifyStruct->Version != 1)
474  {
476  }
477 
478  /* Initialize even that will let us know when PnP will have finished notify */
479  KeInitializeEvent(&NotifyEvent, NotificationEvent, FALSE);
480 
481  Status = PpSetCustomTargetEvent(PhysicalDeviceObject, &NotifyEvent, &NotifyStatus, NULL, NULL, notifyStruct);
482  /* If no error, wait for the notify to end and return the status of the notify and not of the event */
483  if (NT_SUCCESS(Status))
484  {
486  Status = NotifyStatus;
487  }
488 
489  return Status;
490 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
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:113
struct _TARGET_DEVICE_CUSTOM_NOTIFICATION * PTARGET_DEVICE_CUSTOM_NOTIFICATION
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:242
#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 497 of file pnpreport.c.

501 {
504 
505  ASSERT(notifyStruct);
506 
507  /* Check for valid PDO */
509  {
510  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
511  }
512 
513  /* FileObject must be null. PnP will fill in it */
514  ASSERT(notifyStruct->FileObject == NULL);
515 
516  /* Do not handle system PnP events */
517  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
518  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
519  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
520  {
522  }
523 
524  if (notifyStruct->Version != 1)
525  {
527  }
528 
529  /* We need to store all the data given by the caller with the WorkItem, so use our own struct */
531  if (!Item) return STATUS_INSUFFICIENT_RESOURCES;
532 
533  /* Initialize all stuff */
535  Item->NotificationStructure = notifyStruct;
536  Item->PhysicalDeviceObject = PhysicalDeviceObject;
537  Item->Callback = Callback;
538  Item->Context = Context;
540 
541  /* Finally, queue the item, our work here is done */
542  ExQueueWorkItem(&(Item->WorkItem), DelayedWorkQueue);
543 
544  return STATUS_PENDING;
545 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#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:1157
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:44
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:242
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
VOID NTAPI IopReportTargetDeviceChangeAsyncWorker(PVOID Context)
Definition: pnpreport.c:102
#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 113 of file pnpreport.c.

119 {
122 
123  if (SyncEvent)
124  {
127  }
128 
129  /* That call is totally wrong but notifications handler must be fixed first */
130  PiNotifyTargetDeviceChange(&GUID_PNP_CUSTOM_NOTIFICATION, DeviceObject, NotificationStructure);
131 
132  if (SyncEvent)
133  {
134  KeSetEvent(SyncEvent, IO_NO_INCREMENT, FALSE);
136  }
137 
138  return STATUS_SUCCESS;
139 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
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:44
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().