ReactOS  0.4.13-dev-259-g5ca9c9c
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 NTAPI IopCreateDeviceKeyPath (IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
 
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 2337 of file pnpmgr.c.

2339 {
2342  PWSTR LocationInformation;
2343  PDEVICE_NODE ParentDeviceNode;
2344  IO_STACK_LOCATION Stack;
2345  NTSTATUS Status;
2347  LCID LocaleId;
2348  HANDLE InstanceKey = NULL;
2350  UNICODE_STRING InstancePathU;
2351  PDEVICE_OBJECT OldDeviceObject;
2352 
2353  DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
2354  DPRINT("PDO 0x%p\n", DeviceNode->PhysicalDeviceObject);
2355 
2356  ParentDeviceNode = (PDEVICE_NODE)Context;
2357 
2358  /*
2359  * We are called for the parent too, but we don't need to do special
2360  * handling for this node
2361  */
2362  if (DeviceNode == ParentDeviceNode)
2363  {
2364  DPRINT("Success\n");
2365  return STATUS_SUCCESS;
2366  }
2367 
2368  /*
2369  * Make sure this device node is a direct child of the parent device node
2370  * that is given as an argument
2371  */
2372  if (DeviceNode->Parent != ParentDeviceNode)
2373  {
2374  DPRINT("Skipping 2+ level child\n");
2375  return STATUS_SUCCESS;
2376  }
2377 
2378  /* Skip processing if it was already completed before */
2379  if (DeviceNode->Flags & DNF_PROCESSED)
2380  {
2381  /* Nothing to do */
2382  return STATUS_SUCCESS;
2383  }
2384 
2385  /* Get Locale ID */
2386  Status = ZwQueryDefaultLocale(FALSE, &LocaleId);
2387  if (!NT_SUCCESS(Status))
2388  {
2389  DPRINT1("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status);
2390  return Status;
2391  }
2392 
2393  /*
2394  * FIXME: For critical errors, cleanup and disable device, but always
2395  * return STATUS_SUCCESS.
2396  */
2397 
2398  Status = IopCreateDeviceInstancePath(DeviceNode, &InstancePathU);
2399  if (!NT_SUCCESS(Status))
2400  {
2402  {
2403  DPRINT1("IopCreateDeviceInstancePath() failed with status 0x%lx\n", Status);
2404  }
2405 
2406  /* We have to return success otherwise we abort the traverse operation */
2407  return STATUS_SUCCESS;
2408  }
2409 
2410  /* Verify that this is not a duplicate */
2411  OldDeviceObject = IopGetDeviceObjectFromDeviceInstance(&InstancePathU);
2412  if (OldDeviceObject != NULL)
2413  {
2414  PDEVICE_NODE OldDeviceNode = IopGetDeviceNode(OldDeviceObject);
2415 
2416  DPRINT1("Duplicate device instance '%wZ'\n", &InstancePathU);
2417  DPRINT1("Current instance parent: '%wZ'\n", &DeviceNode->Parent->InstancePath);
2418  DPRINT1("Old instance parent: '%wZ'\n", &OldDeviceNode->Parent->InstancePath);
2419 
2420  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR,
2421  0x01,
2422  (ULONG_PTR)DeviceNode->PhysicalDeviceObject,
2423  (ULONG_PTR)OldDeviceObject,
2424  0);
2425  }
2426 
2427  DeviceNode->InstancePath = InstancePathU;
2428 
2429  DPRINT("InstancePath is %S\n", DeviceNode->InstancePath.Buffer);
2430 
2431  /*
2432  * Create registry key for the instance id, if it doesn't exist yet
2433  */
2434  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
2435  if (!NT_SUCCESS(Status))
2436  {
2437  DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
2438 
2439  /* We have to return success otherwise we abort the traverse operation */
2440  return STATUS_SUCCESS;
2441  }
2442 
2443  IopQueryHardwareIds(DeviceNode, InstanceKey);
2444 
2445  IopQueryCompatibleIds(DeviceNode, InstanceKey);
2446 
2447  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextDescription to device stack\n");
2448 
2449  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextDescription;
2450  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
2451  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2452  &IoStatusBlock,
2454  &Stack);
2456  : NULL;
2457  /* This key is mandatory, so even if the Irp fails, we still write it */
2458  RtlInitUnicodeString(&ValueName, L"DeviceDesc");
2459  if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
2460  {
2461  if (DeviceDescription &&
2463  {
2464  /* This key is overriden when a driver is installed. Don't write the
2465  * new description if another one already exists */
2466  Status = ZwSetValueKey(InstanceKey,
2467  &ValueName,
2468  0,
2469  REG_SZ,
2471  ((ULONG)wcslen(DeviceDescription) + 1) * sizeof(WCHAR));
2472  }
2473  else
2474  {
2475  UNICODE_STRING DeviceDesc = RTL_CONSTANT_STRING(L"Unknown device");
2476  DPRINT("Driver didn't return DeviceDesc (Status 0x%08lx), so place unknown device there\n", Status);
2477 
2478  Status = ZwSetValueKey(InstanceKey,
2479  &ValueName,
2480  0,
2481  REG_SZ,
2482  DeviceDesc.Buffer,
2483  DeviceDesc.MaximumLength);
2484  if (!NT_SUCCESS(Status))
2485  {
2486  DPRINT1("ZwSetValueKey() failed (Status 0x%lx)\n", Status);
2487  }
2488 
2489  }
2490  }
2491 
2492  if (DeviceDescription)
2493  {
2495  }
2496 
2497  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocation to device stack\n");
2498 
2499  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextLocationInformation;
2500  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
2501  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2502  &IoStatusBlock,
2504  &Stack);
2506  {
2507  LocationInformation = (PWSTR)IoStatusBlock.Information;
2508  DPRINT("LocationInformation: %S\n", LocationInformation);
2509  RtlInitUnicodeString(&ValueName, L"LocationInformation");
2510  Status = ZwSetValueKey(InstanceKey,
2511  &ValueName,
2512  0,
2513  REG_SZ,
2514  LocationInformation,
2515  ((ULONG)wcslen(LocationInformation) + 1) * sizeof(WCHAR));
2516  if (!NT_SUCCESS(Status))
2517  {
2518  DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
2519  }
2520 
2521  ExFreePoolWithTag(LocationInformation, 0);
2522  }
2523  else
2524  {
2525  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2526  }
2527 
2528  DPRINT("Sending IRP_MN_QUERY_BUS_INFORMATION to device stack\n");
2529 
2530  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2531  &IoStatusBlock,
2533  NULL);
2535  {
2537 
2538  DeviceNode->ChildBusNumber = BusInformation->BusNumber;
2539  DeviceNode->ChildInterfaceType = BusInformation->LegacyBusType;
2540  DeviceNode->ChildBusTypeIndex = IopGetBusTypeGuidIndex(&BusInformation->BusTypeGuid);
2541  ExFreePoolWithTag(BusInformation, 0);
2542  }
2543  else
2544  {
2545  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2546 
2547  DeviceNode->ChildBusNumber = 0xFFFFFFF0;
2548  DeviceNode->ChildInterfaceType = InterfaceTypeUndefined;
2549  DeviceNode->ChildBusTypeIndex = -1;
2550  }
2551 
2552  DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
2553 
2554  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2555  &IoStatusBlock,
2557  NULL);
2559  {
2562  }
2563  else
2564  {
2565  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2566  DeviceNode->BootResources = NULL;
2567  }
2568 
2569  DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
2570 
2571  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2572  &IoStatusBlock,
2574  NULL);
2575  if (NT_SUCCESS(Status))
2576  {
2578  }
2579  else
2580  {
2581  DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status);
2582  DeviceNode->ResourceRequirements = NULL;
2583  }
2584 
2585  if (InstanceKey != NULL)
2586  {
2587  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
2588  }
2589 
2590  ZwClose(InstanceKey);
2591 
2593 
2595  {
2596  /* Report the device to the user-mode pnp manager */
2597  IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
2598  &DeviceNode->InstancePath);
2599  }
2600 
2601  return STATUS_SUCCESS;
2602 }
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
#define STATUS_PLUGPLAY_NO_DEVICE
Definition: ntstatus.h:717
#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:54
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:1594
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
PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
Definition: plugplay.c:148
DWORD LCID
Definition: nls.h:13
struct _DEVICE_NODE * Parent
Definition: iotypes.h:825
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
struct _DEVICE_NODE * PDEVICE_NODE
#define UNICODE_NULL
NTSTATUS IopCreateDeviceInstancePath(_In_ PDEVICE_NODE DeviceNode, _Out_ PUNICODE_STRING InstancePath)
Definition: pnpmgr.c:2175
#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
USHORT NTAPI IopGetBusTypeGuidIndex(LPGUID BusTypeGuid)
Definition: pnpmgr.c:1106
#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
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:1678
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_QUERY_DEVICE_TEXT
Definition: Node.h:9
PDEVICE_NODE FASTCALL IopGetDeviceNode(PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:66
#define IRP_MN_QUERY_BUS_INFORMATION
static const WCHAR L[]
Definition: oid.c:1250
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack OPTIONAL)
Definition: pnpmgr.c:1489
#define IopDeviceNodeHasFlag(DeviceNode, Flag)
Definition: io.h:160
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
struct _IO_RESOURCE_REQUIREMENTS_LIST * PIO_RESOURCE_REQUIREMENTS_LIST
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS IopQueryCompatibleIds(PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
Definition: pnpmgr.c:2111
#define DPRINT1
Definition: precomp.h:8
NTSTATUS IopQueryHardwareIds(PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
Definition: pnpmgr.c:2047
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:2771
return STATUS_SUCCESS
Definition: btrfs.c:2745
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
INTERFACE_TYPE LegacyBusType
Definition: cmtypes.h:363
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:107
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define REG_SZ
Definition: layer.c:22

Referenced by IopEnumerateDevice(), and IoReportDetectedDevice().

◆ IopCreateDeviceKeyPath()

NTSTATUS NTAPI IopCreateDeviceKeyPath ( IN PCUNICODE_STRING  RegistryPath,
IN ULONG  CreateOptions,
OUT PHANDLE  Handle 
)

Definition at line 1594 of file pnpmgr.c.

1597 {
1599  HANDLE hParent = NULL, hKey;
1602  PCWSTR Current, Last;
1603  USHORT Length;
1604  NTSTATUS Status;
1605 
1606  /* Assume failure */
1607  *Handle = NULL;
1608 
1609  /* Open root key for device instances */
1611  if (!NT_SUCCESS(Status))
1612  {
1613  DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU, Status);
1614  return Status;
1615  }
1616 
1617  Current = KeyName.Buffer = RegistryPath->Buffer;
1618  Last = &RegistryPath->Buffer[RegistryPath->Length / sizeof(WCHAR)];
1619 
1620  /* Go up to the end of the string */
1621  while (Current <= Last)
1622  {
1623  if (Current != Last && *Current != L'\\')
1624  {
1625  /* Not the end of the string and not a separator */
1626  Current++;
1627  continue;
1628  }
1629 
1630  /* Prepare relative key name */
1631  Length = (USHORT)((ULONG_PTR)Current - (ULONG_PTR)KeyName.Buffer);
1632  KeyName.MaximumLength = KeyName.Length = Length;
1633  DPRINT("Create '%wZ'\n", &KeyName);
1634 
1635  /* Open key */
1637  &KeyName,
1639  hParent,
1640  NULL);
1641  Status = ZwCreateKey(&hKey,
1642  Current == Last ? KEY_ALL_ACCESS : KEY_CREATE_SUB_KEY,
1644  0,
1645  NULL,
1646  CreateOptions,
1647  NULL);
1648 
1649  /* Close parent key handle, we don't need it anymore */
1650  if (hParent)
1651  ZwClose(hParent);
1652 
1653  /* Key opening/creating failed? */
1654  if (!NT_SUCCESS(Status))
1655  {
1656  DPRINT1("ZwCreateKey('%wZ') failed with status 0x%08lx\n", &KeyName, Status);
1657  return Status;
1658  }
1659 
1660  /* Check if it is the end of the string */
1661  if (Current == Last)
1662  {
1663  /* Yes, return success */
1664  *Handle = hKey;
1665  return STATUS_SUCCESS;
1666  }
1667 
1668  /* Start with this new parent key */
1669  hParent = hKey;
1670  Current++;
1671  KeyName.Buffer = (PWSTR)Current;
1672  }
1673 
1674  return STATUS_UNSUCCESSFUL;
1675 }
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
const uint16_t * PCWSTR
Definition: typedefs.h:55
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:3670
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ENUM_ROOT
Definition: io.h:53
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR L[]
Definition: oid.c:1250
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define DPRINT1
Definition: precomp.h:8
#define ULONG_PTR
Definition: config.h:101
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by IopActionInterrogateDeviceStack(), IopCreateDeviceNode(), IopInstallCriticalDevice(), IopQueryDeviceCapabilities(), IopStartDevice(), and IoReportDetectedDevice().

◆ IopGetInterfaceTypeString()

PWCHAR IopGetInterfaceTypeString ( INTERFACE_TYPE  IfType)

Definition at line 52 of file pnpreport.c.

53 {
54  switch (IfType)
55  {
56  case Internal:
57  return L"Internal";
58 
59  case Isa:
60  return L"Isa";
61 
62  case Eisa:
63  return L"Eisa";
64 
65  case MicroChannel:
66  return L"MicroChannel";
67 
68  case TurboChannel:
69  return L"TurboChannel";
70 
71  case PCIBus:
72  return L"PCIBus";
73 
74  case VMEBus:
75  return L"VMEBus";
76 
77  case NuBus:
78  return L"NuBus";
79 
80  case PCMCIABus:
81  return L"PCMCIABus";
82 
83  case CBus:
84  return L"CBus";
85 
86  case MPIBus:
87  return L"MPIBus";
88 
89  case MPSABus:
90  return L"MPSABus";
91 
92  case ProcessorInternal:
93  return L"ProcessorInternal";
94 
95  case PNPISABus:
96  return L"PNPISABus";
97 
98  case PNPBus:
99  return L"PNPBus";
100 
101  case Vmcs:
102  return L"Vmcs";
103 
104  default:
105  DPRINT1("Invalid bus type: %d\n", IfType);
106  return NULL;
107  }
108 }
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 112 of file pnpreport.c.

113 {
115 
119  ExFreePoolWithTag(Context, ' pP');
120 }
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:123
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 1678 of file pnpmgr.c.

1680 {
1683  HANDLE LogConfKey, ControlKey, DeviceParamsKey;
1684  ULONG ResCount;
1686  NTSTATUS Status;
1687 
1688  DPRINT("IopSetDeviceInstanceData() called\n");
1689 
1690  /* Create the 'LogConf' key */
1691  RtlInitUnicodeString(&KeyName, L"LogConf");
1693  &KeyName,
1695  InstanceKey,
1696  NULL);
1697  Status = ZwCreateKey(&LogConfKey,
1700  0,
1701  NULL,
1702  // FIXME? In r53694 it was silently turned from non-volatile into this,
1703  // without any extra warning. Is this still needed??
1705  NULL);
1706  if (NT_SUCCESS(Status))
1707  {
1708  /* Set 'BootConfig' value */
1709  if (DeviceNode->BootResources != NULL)
1710  {
1711  ResCount = DeviceNode->BootResources->Count;
1712  if (ResCount != 0)
1713  {
1714  RtlInitUnicodeString(&KeyName, L"BootConfig");
1715  Status = ZwSetValueKey(LogConfKey,
1716  &KeyName,
1717  0,
1719  DeviceNode->BootResources,
1720  PnpDetermineResourceListSize(DeviceNode->BootResources));
1721  }
1722  }
1723 
1724  /* Set 'BasicConfigVector' value */
1725  if (DeviceNode->ResourceRequirements != NULL &&
1726  DeviceNode->ResourceRequirements->ListSize != 0)
1727  {
1728  RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
1729  Status = ZwSetValueKey(LogConfKey,
1730  &KeyName,
1731  0,
1733  DeviceNode->ResourceRequirements,
1734  DeviceNode->ResourceRequirements->ListSize);
1735  }
1736 
1737  ZwClose(LogConfKey);
1738  }
1739 
1740  /* Set the 'ConfigFlags' value */
1741  RtlInitUnicodeString(&KeyName, L"ConfigFlags");
1742  Status = ZwQueryValueKey(InstanceKey,
1743  &KeyName,
1745  NULL,
1746  0,
1747  &ResultLength);
1749  {
1750  /* Write the default value */
1751  ULONG DefaultConfigFlags = 0;
1752  Status = ZwSetValueKey(InstanceKey,
1753  &KeyName,
1754  0,
1755  REG_DWORD,
1756  &DefaultConfigFlags,
1757  sizeof(DefaultConfigFlags));
1758  }
1759 
1760  /* Create the 'Control' key */
1761  RtlInitUnicodeString(&KeyName, L"Control");
1763  &KeyName,
1765  InstanceKey,
1766  NULL);
1767  Status = ZwCreateKey(&ControlKey,
1768  0,
1770  0,
1771  NULL,
1773  NULL);
1774  if (NT_SUCCESS(Status))
1775  ZwClose(ControlKey);
1776 
1777  /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
1778  if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
1779  {
1780  RtlInitUnicodeString(&KeyName, L"Device Parameters");
1782  &KeyName,
1784  InstanceKey,
1785  NULL);
1786  Status = ZwCreateKey(&DeviceParamsKey,
1787  0,
1789  0,
1790  NULL,
1792  NULL);
1793  if (NT_SUCCESS(Status))
1794  {
1795  ULONG FirmwareIdentified = 1;
1796  RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
1797  Status = ZwSetValueKey(DeviceParamsKey,
1798  &KeyName,
1799  0,
1800  REG_DWORD,
1801  &FirmwareIdentified,
1802  sizeof(FirmwareIdentified));
1803 
1804  ZwClose(DeviceParamsKey);
1805  }
1806  }
1807 
1808  DPRINT("IopSetDeviceInstanceData() done\n");
1809 
1810  return Status;
1811 }
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
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 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
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
Definition: Node.h:9
static const WCHAR L[]
Definition: oid.c:1250
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:4065
Status
Definition: gdiplustypes.h:24
#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
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Referenced by IopActionInterrogateDeviceStack(), and IoReportDetectedDevice().

◆ IopSetEvent()

VOID NTAPI IopSetEvent ( IN PVOID  Context)

Definition at line 456 of file pnpreport.c.

457 {
459 
460  /* Set the event */
462 }
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
struct tagContext Context
Definition: acpixf.h:1012
#define IO_NO_INCREMENT
Definition: iotypes.h:565

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

170 {
174  HANDLE InstanceKey;
176  UNICODE_STRING ValueName, ServiceLongName, ServiceName;
177  WCHAR HardwareId[256];
178  PWCHAR IfString;
179  ULONG IdLength;
180  ULONG LegacyValue;
181 
182  DPRINT("IoReportDetectedDevice (DeviceObject %p, *DeviceObject %p)\n",
184 
185  ServiceLongName = DriverObject->DriverExtension->ServiceKeyName;
186  ServiceName = ServiceLongName;
187 
188  /* If the interface type is unknown, treat it as internal */
191 
192  /* Get the string equivalent of the interface type */
194 
195  /* If NULL is returned then it's a bad type */
196  if (!IfString)
198 
199  /*
200  * Drivers that have been created via a direct IoCreateDriver() call
201  * have their ServiceKeyName set to \Driver\DriverName. We need to
202  * strip everything up to the last path separator and keep what remains.
203  */
205  {
206  /*
207  * Find the last path separator.
208  * NOTE: Since ServiceName is not necessarily NULL-terminated,
209  * we cannot use wcsrchr().
210  */
211  if (ServiceName.Buffer && ServiceName.Length >= sizeof(WCHAR))
212  {
213  ValueName.Length = 1;
214  ValueName.Buffer = ServiceName.Buffer + (ServiceName.Length / sizeof(WCHAR)) - 1;
215 
216  while ((ValueName.Buffer > ServiceName.Buffer) && (*ValueName.Buffer != L'\\'))
217  {
218  --ValueName.Buffer;
219  ++ValueName.Length;
220  }
221  if (*ValueName.Buffer == L'\\')
222  {
223  ++ValueName.Buffer;
224  --ValueName.Length;
225  }
226  ValueName.Length *= sizeof(WCHAR);
227 
228  /* Shorten the string */
229  ServiceName.MaximumLength -= (ServiceName.Length - ValueName.Length);
230  ServiceName.Length = ValueName.Length;
231  ServiceName.Buffer = ValueName.Buffer;
232  }
233  }
234 
235  /* We use the caller's PDO if they supplied one */
236  if (DeviceObject && *DeviceObject)
237  {
238  Pdo = *DeviceObject;
239  }
240  else
241  {
242  /* Create the PDO */
244  NULL,
245  &Pdo,
246  NULL);
247  if (!NT_SUCCESS(Status))
248  {
249  DPRINT("PnpRootCreateDevice() failed (Status 0x%08lx)\n", Status);
250  return Status;
251  }
252  }
253 
254  /* Create the device node for the new PDO */
256  Pdo,
257  NULL,
258  &DeviceNode);
259  if (!NT_SUCCESS(Status))
260  {
261  DPRINT("IopCreateDeviceNode() failed (Status 0x%08lx)\n", Status);
262  return Status;
263  }
264 
265  /* We're enumerated already */
267 
268  /* We don't call AddDevice for devices reported this way */
270 
271  /* We don't send IRP_MN_START_DEVICE */
273 
274  /* We need to get device IDs */
275 #if 0
276  IopDeviceNodeSetFlag(DeviceNode, DNF_NEED_QUERY_IDS);
277 #endif
278 
279  /* This is a legacy driver for this device */
281 
282  /* Perform a manual configuration of our device */
285 
286  /* Open a handle to the instance path key */
287  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
288  if (!NT_SUCCESS(Status))
289  return Status;
290 
291  /* Save the driver name */
292  RtlInitUnicodeString(&ValueName, L"Service");
293  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_SZ, ServiceLongName.Buffer, ServiceLongName.Length + sizeof(UNICODE_NULL));
294  if (!NT_SUCCESS(Status))
295  {
296  DPRINT("Failed to write the Service name value: 0x%x\n", Status);
297  }
298 
299  /* Report as non-legacy driver */
300  RtlInitUnicodeString(&ValueName, L"Legacy");
301  LegacyValue = 0;
302  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_DWORD, &LegacyValue, sizeof(LegacyValue));
303  if (!NT_SUCCESS(Status))
304  {
305  DPRINT("Failed to write the Legacy value: 0x%x\n", Status);
306  }
307 
308  /* Add DETECTEDInterfaceType\DriverName */
309  IdLength = 0;
310  IdLength += swprintf(&HardwareId[IdLength],
311  L"DETECTED%ls\\%wZ",
312  IfString,
313  &ServiceName);
314  IdLength++;
315 
316  /* Add DETECTED\DriverName */
317  IdLength += swprintf(&HardwareId[IdLength],
318  L"DETECTED\\%wZ",
319  &ServiceName);
320  IdLength++;
321 
322  /* Terminate the string with another null */
323  HardwareId[IdLength++] = UNICODE_NULL;
324 
325  /* Store the value for CompatibleIDs */
326  RtlInitUnicodeString(&ValueName, L"CompatibleIDs");
327  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
328  if (!NT_SUCCESS(Status))
329  {
330  DPRINT("Failed to write the compatible IDs: 0x%x\n", Status);
331  ZwClose(InstanceKey);
332  return Status;
333  }
334 
335  /* Add a hardware ID if the driver didn't report one */
336  RtlInitUnicodeString(&ValueName, L"HardwareID");
337  if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
338  {
339  /* Just use our most specific compatible ID */
340  IdLength = 0;
341  IdLength += swprintf(&HardwareId[IdLength],
342  L"DETECTED%ls\\%wZ",
343  IfString,
344  &ServiceName);
345  IdLength++;
346 
347  HardwareId[IdLength++] = UNICODE_NULL;
348 
349  /* Write the value to the registry */
350  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
351  if (!NT_SUCCESS(Status))
352  {
353  DPRINT("Failed to write the hardware ID: 0x%x\n", Status);
354  ZwClose(InstanceKey);
355  return Status;
356  }
357  }
358 
359  /* Assign the resources to the device node */
360  DeviceNode->BootResources = ResourceList;
361  DeviceNode->ResourceRequirements = ResourceRequirements;
362 
363  /* Set appropriate flags */
364  if (DeviceNode->BootResources)
366 
367  if (!DeviceNode->ResourceRequirements && !DeviceNode->BootResources)
369 
370  /* Write the resource information to the registry */
371  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
372 
373  /* If the caller didn't get the resources assigned for us, do it now */
374  if (!ResourceAssigned)
375  {
377 
378  /* See if we failed */
379  if (!NT_SUCCESS(Status))
380  {
381  DPRINT("Assigning resources failed: 0x%x\n", Status);
382  ZwClose(InstanceKey);
383  return Status;
384  }
385  }
386 
387  /* Close the instance key handle */
388  ZwClose(InstanceKey);
389 
390  /* Register the given DO with PnP root if required */
391  if (DeviceObject && *DeviceObject)
393 
394  /* Report the device's enumeration to umpnpmgr */
395  IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
396  &DeviceNode->InstancePath);
397 
398  /* Report the device's arrival to umpnpmgr */
399  IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
400  &DeviceNode->InstancePath);
401 
402  DPRINT("Reported device: %S (%wZ)\n", HardwareId, &DeviceNode->InstancePath);
403 
404  /* Return the PDO */
405  if (DeviceObject) *DeviceObject = Pdo;
406 
407  return STATUS_SUCCESS;
408 }
NTSTATUS IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: pnpmgr.c:2337
NTSTATUS PnpRootRegisterDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnproot.c:130
#define DRVO_BUILTIN_DRIVER
Definition: iotypes.h:2118
PDEVICE_NODE IopRootDeviceNode
Definition: pnpmgr.c:18
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
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:54
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:1594
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:1678
_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:2173
#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
static const WCHAR L[]
Definition: oid.c:1250
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
Status
Definition: gdiplustypes.h:24
UNICODE_STRING ServiceKeyName
Definition: iotypes.h:2113
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
NTSTATUS NTAPI IopAssignDeviceResources(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:1060
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:52
return STATUS_SUCCESS
Definition: btrfs.c:2745
#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:186
#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 415 of file pnpreport.c.

422 {
425 
426  *ConflictDetected = FALSE;
427 
428  if (!DriverList && !DeviceList)
430 
431  /* Find the real list */
432  if (!DriverList)
434  else
435  ResourceList = DriverList;
436 
437  /* Look for a resource conflict */
440  {
441  /* Oh noes */
442  *ConflictDetected = TRUE;
443  }
444  else if (NT_SUCCESS(Status))
445  {
446  /* Looks like we're good to go */
447 
448  /* TODO: Claim the resources in the ResourceMap */
449  }
450 
451  return Status;
452 }
#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
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:247
NTSTATUS NTAPI IopDetectResourceConflict(IN PCM_RESOURCE_LIST ResourceList, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
Definition: pnpres.c:1200

Referenced by VideoPortVerifyAccessRanges().

◆ IoReportTargetDeviceChange()

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

Definition at line 469 of file pnpreport.c.

471 {
472  KEVENT NotifyEvent;
473  NTSTATUS Status, NotifyStatus;
475 
476  ASSERT(notifyStruct);
477 
478  /* Check for valid PDO */
480  {
481  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
482  }
483 
484  /* FileObject must be null. PnP will fill in it */
485  ASSERT(notifyStruct->FileObject == NULL);
486 
487  /* Do not handle system PnP events */
488  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
489  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
490  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
491  {
493  }
494 
495  if (notifyStruct->Version != 1)
496  {
498  }
499 
500  /* Initialize even that will let us know when PnP will have finished notify */
501  KeInitializeEvent(&NotifyEvent, NotificationEvent, FALSE);
502 
503  Status = PpSetCustomTargetEvent(PhysicalDeviceObject, &NotifyEvent, &NotifyStatus, NULL, NULL, notifyStruct);
504  /* If no error, wait for the notify to end and return the status of the notify and not of the event */
505  if (NT_SUCCESS(Status))
506  {
508  Status = NotifyStatus;
509  }
510 
511  return Status;
512 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
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:63
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:123
struct _TARGET_DEVICE_CUSTOM_NOTIFICATION * PTARGET_DEVICE_CUSTOM_NOTIFICATION
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
Status
Definition: gdiplustypes.h:24
#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:974
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:107
#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 519 of file pnpreport.c.

523 {
526 
527  ASSERT(notifyStruct);
528 
529  /* Check for valid PDO */
531  {
532  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
533  }
534 
535  /* FileObject must be null. PnP will fill in it */
536  ASSERT(notifyStruct->FileObject == NULL);
537 
538  /* Do not handle system PnP events */
539  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
540  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
541  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
542  {
544  }
545 
546  if (notifyStruct->Version != 1)
547  {
549  }
550 
551  /* We need to store all the data given by the caller with the WorkItem, so use our own struct */
553  if (!Item) return STATUS_INSUFFICIENT_RESOURCES;
554 
555  /* Initialize all stuff */
557  Item->NotificationStructure = notifyStruct;
559  Item->Callback = Callback;
560  Item->Context = Context;
562 
563  /* Finally, queue the item, our work here is done */
565 
566  return STATUS_PENDING;
567 }
_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
uint32_t ULONG_PTR
Definition: typedefs.h:63
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:112
_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:1012
PDEVICE_OBJECT PhysicalDeviceObject
Definition: pnpreport.c:21
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:974
LPFNPSPCALLBACK Callback
Definition: desk.c:111
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:107
PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure
Definition: pnpreport.c:24
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by ClasspSendNotification(), DiskDeviceControl(), 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 123 of file pnpreport.c.

129 {
132 
133  if (SyncEvent)
134  {
135  ASSERT(SyncStatus);
136  *SyncStatus = STATUS_PENDING;
137  }
138 
139  /* That call is totally wrong but notifications handler must be fixed first */
142  &GUID_PNP_CUSTOM_NOTIFICATION,
144  NULL);
145 
146  if (SyncEvent)
147  {
148  KeSetEvent(SyncEvent, IO_NO_INCREMENT, FALSE);
149  *SyncStatus = STATUS_SUCCESS;
150  }
151 
152  return STATUS_SUCCESS;
153 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
smooth NULL
Definition: ftsmooth.c:416
#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: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:565
return STATUS_SUCCESS
Definition: btrfs.c:2745

Referenced by IopReportTargetDeviceChangeAsyncWorker(), and IoReportTargetDeviceChange().