ReactOS  0.4.14-dev-114-gc8cbd56
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 2355 of file pnpmgr.c.

2357 {
2360  PWSTR LocationInformation;
2361  PDEVICE_NODE ParentDeviceNode;
2362  IO_STACK_LOCATION Stack;
2363  NTSTATUS Status;
2365  LCID LocaleId;
2366  HANDLE InstanceKey = NULL;
2368  UNICODE_STRING InstancePathU;
2369  PDEVICE_OBJECT OldDeviceObject;
2370 
2371  DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
2372  DPRINT("PDO 0x%p\n", DeviceNode->PhysicalDeviceObject);
2373 
2374  ParentDeviceNode = (PDEVICE_NODE)Context;
2375 
2376  /*
2377  * We are called for the parent too, but we don't need to do special
2378  * handling for this node
2379  */
2380  if (DeviceNode == ParentDeviceNode)
2381  {
2382  DPRINT("Success\n");
2383  return STATUS_SUCCESS;
2384  }
2385 
2386  /*
2387  * Make sure this device node is a direct child of the parent device node
2388  * that is given as an argument
2389  */
2390  if (DeviceNode->Parent != ParentDeviceNode)
2391  {
2392  DPRINT("Skipping 2+ level child\n");
2393  return STATUS_SUCCESS;
2394  }
2395 
2396  /* Skip processing if it was already completed before */
2397  if (DeviceNode->Flags & DNF_PROCESSED)
2398  {
2399  /* Nothing to do */
2400  return STATUS_SUCCESS;
2401  }
2402 
2403  /* Get Locale ID */
2404  Status = ZwQueryDefaultLocale(FALSE, &LocaleId);
2405  if (!NT_SUCCESS(Status))
2406  {
2407  DPRINT1("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status);
2408  return Status;
2409  }
2410 
2411  /*
2412  * FIXME: For critical errors, cleanup and disable device, but always
2413  * return STATUS_SUCCESS.
2414  */
2415 
2416  Status = IopCreateDeviceInstancePath(DeviceNode, &InstancePathU);
2417  if (!NT_SUCCESS(Status))
2418  {
2420  {
2421  DPRINT1("IopCreateDeviceInstancePath() failed with status 0x%lx\n", Status);
2422  }
2423 
2424  /* We have to return success otherwise we abort the traverse operation */
2425  return STATUS_SUCCESS;
2426  }
2427 
2428  /* Verify that this is not a duplicate */
2429  OldDeviceObject = IopGetDeviceObjectFromDeviceInstance(&InstancePathU);
2430  if (OldDeviceObject != NULL)
2431  {
2432  PDEVICE_NODE OldDeviceNode = IopGetDeviceNode(OldDeviceObject);
2433 
2434  DPRINT1("Duplicate device instance '%wZ'\n", &InstancePathU);
2435  DPRINT1("Current instance parent: '%wZ'\n", &DeviceNode->Parent->InstancePath);
2436  DPRINT1("Old instance parent: '%wZ'\n", &OldDeviceNode->Parent->InstancePath);
2437 
2438  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR,
2439  0x01,
2440  (ULONG_PTR)DeviceNode->PhysicalDeviceObject,
2441  (ULONG_PTR)OldDeviceObject,
2442  0);
2443  }
2444 
2445  DeviceNode->InstancePath = InstancePathU;
2446 
2447  DPRINT("InstancePath is %S\n", DeviceNode->InstancePath.Buffer);
2448 
2449  /*
2450  * Create registry key for the instance id, if it doesn't exist yet
2451  */
2452  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
2453  if (!NT_SUCCESS(Status))
2454  {
2455  DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
2456 
2457  /* We have to return success otherwise we abort the traverse operation */
2458  return STATUS_SUCCESS;
2459  }
2460 
2461  IopQueryHardwareIds(DeviceNode, InstanceKey);
2462 
2463  IopQueryCompatibleIds(DeviceNode, InstanceKey);
2464 
2465  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextDescription to device stack\n");
2466 
2467  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextDescription;
2468  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
2469  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2470  &IoStatusBlock,
2472  &Stack);
2474  : NULL;
2475  /* This key is mandatory, so even if the Irp fails, we still write it */
2476  RtlInitUnicodeString(&ValueName, L"DeviceDesc");
2477  if (ZwQueryValueKey(InstanceKey, &ValueName, KeyValueBasicInformation, NULL, 0, &RequiredLength) == STATUS_OBJECT_NAME_NOT_FOUND)
2478  {
2479  if (DeviceDescription &&
2481  {
2482  /* This key is overriden when a driver is installed. Don't write the
2483  * new description if another one already exists */
2484  Status = ZwSetValueKey(InstanceKey,
2485  &ValueName,
2486  0,
2487  REG_SZ,
2489  ((ULONG)wcslen(DeviceDescription) + 1) * sizeof(WCHAR));
2490  }
2491  else
2492  {
2493  UNICODE_STRING DeviceDesc = RTL_CONSTANT_STRING(L"Unknown device");
2494  DPRINT("Driver didn't return DeviceDesc (Status 0x%08lx), so place unknown device there\n", Status);
2495 
2496  Status = ZwSetValueKey(InstanceKey,
2497  &ValueName,
2498  0,
2499  REG_SZ,
2500  DeviceDesc.Buffer,
2501  DeviceDesc.MaximumLength);
2502  if (!NT_SUCCESS(Status))
2503  {
2504  DPRINT1("ZwSetValueKey() failed (Status 0x%lx)\n", Status);
2505  }
2506 
2507  }
2508  }
2509 
2510  if (DeviceDescription)
2511  {
2513  }
2514 
2515  DPRINT("Sending IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocation to device stack\n");
2516 
2517  Stack.Parameters.QueryDeviceText.DeviceTextType = DeviceTextLocationInformation;
2518  Stack.Parameters.QueryDeviceText.LocaleId = LocaleId;
2519  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2520  &IoStatusBlock,
2522  &Stack);
2524  {
2525  LocationInformation = (PWSTR)IoStatusBlock.Information;
2526  DPRINT("LocationInformation: %S\n", LocationInformation);
2527  RtlInitUnicodeString(&ValueName, L"LocationInformation");
2528  Status = ZwSetValueKey(InstanceKey,
2529  &ValueName,
2530  0,
2531  REG_SZ,
2532  LocationInformation,
2533  ((ULONG)wcslen(LocationInformation) + 1) * sizeof(WCHAR));
2534  if (!NT_SUCCESS(Status))
2535  {
2536  DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
2537  }
2538 
2539  ExFreePoolWithTag(LocationInformation, 0);
2540  }
2541  else
2542  {
2543  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2544  }
2545 
2546  DPRINT("Sending IRP_MN_QUERY_BUS_INFORMATION to device stack\n");
2547 
2548  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2549  &IoStatusBlock,
2551  NULL);
2553  {
2555 
2556  DeviceNode->ChildBusNumber = BusInformation->BusNumber;
2557  DeviceNode->ChildInterfaceType = BusInformation->LegacyBusType;
2558  DeviceNode->ChildBusTypeIndex = IopGetBusTypeGuidIndex(&BusInformation->BusTypeGuid);
2559  ExFreePoolWithTag(BusInformation, 0);
2560  }
2561  else
2562  {
2563  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2564 
2565  DeviceNode->ChildBusNumber = 0xFFFFFFF0;
2566  DeviceNode->ChildInterfaceType = InterfaceTypeUndefined;
2567  DeviceNode->ChildBusTypeIndex = -1;
2568  }
2569 
2570  DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
2571 
2572  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2573  &IoStatusBlock,
2575  NULL);
2577  {
2580  }
2581  else
2582  {
2583  DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
2584  DeviceNode->BootResources = NULL;
2585  }
2586 
2587  DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
2588 
2589  Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
2590  &IoStatusBlock,
2592  NULL);
2593  if (NT_SUCCESS(Status))
2594  {
2596  }
2597  else
2598  {
2599  DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status);
2600  DeviceNode->ResourceRequirements = NULL;
2601  }
2602 
2603  if (InstanceKey != NULL)
2604  {
2605  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
2606  }
2607 
2608  ZwClose(InstanceKey);
2609 
2611 
2613  {
2614  /* Report the device to the user-mode pnp manager */
2615  IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
2616  &DeviceNode->InstancePath);
2617  }
2618 
2619  return STATUS_SUCCESS;
2620 }
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:1612
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:2193
#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:1696
__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:1490
#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:2129
#define DPRINT1
Definition: precomp.h:8
NTSTATUS IopQueryHardwareIds(PDEVICE_NODE DeviceNode, HANDLE InstanceKey)
Definition: pnpmgr.c:2065
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:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
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 1612 of file pnpmgr.c.

1615 {
1617  HANDLE hParent = NULL, hKey;
1620  PCWSTR Current, Last;
1621  USHORT Length;
1622  NTSTATUS Status;
1623 
1624  /* Assume failure */
1625  *Handle = NULL;
1626 
1627  /* Open root key for device instances */
1629  if (!NT_SUCCESS(Status))
1630  {
1631  DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU, Status);
1632  return Status;
1633  }
1634 
1635  Current = KeyName.Buffer = RegistryPath->Buffer;
1636  Last = &RegistryPath->Buffer[RegistryPath->Length / sizeof(WCHAR)];
1637 
1638  /* Go up to the end of the string */
1639  while (Current <= Last)
1640  {
1641  if (Current != Last && *Current != L'\\')
1642  {
1643  /* Not the end of the string and not a separator */
1644  Current++;
1645  continue;
1646  }
1647 
1648  /* Prepare relative key name */
1649  Length = (USHORT)((ULONG_PTR)Current - (ULONG_PTR)KeyName.Buffer);
1650  KeyName.MaximumLength = KeyName.Length = Length;
1651  DPRINT("Create '%wZ'\n", &KeyName);
1652 
1653  /* Open key */
1655  &KeyName,
1657  hParent,
1658  NULL);
1659  Status = ZwCreateKey(&hKey,
1660  Current == Last ? KEY_ALL_ACCESS : KEY_CREATE_SUB_KEY,
1662  0,
1663  NULL,
1664  CreateOptions,
1665  NULL);
1666 
1667  /* Close parent key handle, we don't need it anymore */
1668  if (hParent)
1669  ZwClose(hParent);
1670 
1671  /* Key opening/creating failed? */
1672  if (!NT_SUCCESS(Status))
1673  {
1674  DPRINT1("ZwCreateKey('%wZ') failed with status 0x%08lx\n", &KeyName, Status);
1675  return Status;
1676  }
1677 
1678  /* Check if it is the end of the string */
1679  if (Current == Last)
1680  {
1681  /* Yes, return success */
1682  *Handle = hKey;
1683  return STATUS_SUCCESS;
1684  }
1685 
1686  /* Start with this new parent key */
1687  hParent = hKey;
1688  Current++;
1689  KeyName.Buffer = (PWSTR)Current;
1690  }
1691 
1692  return STATUS_UNSUCCESSFUL;
1693 }
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:3688
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:2966
#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 1696 of file pnpmgr.c.

1698 {
1701  HANDLE LogConfKey, ControlKey, DeviceParamsKey;
1702  ULONG ResCount;
1704  NTSTATUS Status;
1705 
1706  DPRINT("IopSetDeviceInstanceData() called\n");
1707 
1708  /* Create the 'LogConf' key */
1709  RtlInitUnicodeString(&KeyName, L"LogConf");
1711  &KeyName,
1713  InstanceKey,
1714  NULL);
1715  Status = ZwCreateKey(&LogConfKey,
1718  0,
1719  NULL,
1720  // FIXME? In r53694 it was silently turned from non-volatile into this,
1721  // without any extra warning. Is this still needed??
1723  NULL);
1724  if (NT_SUCCESS(Status))
1725  {
1726  /* Set 'BootConfig' value */
1727  if (DeviceNode->BootResources != NULL)
1728  {
1729  ResCount = DeviceNode->BootResources->Count;
1730  if (ResCount != 0)
1731  {
1732  RtlInitUnicodeString(&KeyName, L"BootConfig");
1733  Status = ZwSetValueKey(LogConfKey,
1734  &KeyName,
1735  0,
1737  DeviceNode->BootResources,
1738  PnpDetermineResourceListSize(DeviceNode->BootResources));
1739  }
1740  }
1741 
1742  /* Set 'BasicConfigVector' value */
1743  if (DeviceNode->ResourceRequirements != NULL &&
1744  DeviceNode->ResourceRequirements->ListSize != 0)
1745  {
1746  RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
1747  Status = ZwSetValueKey(LogConfKey,
1748  &KeyName,
1749  0,
1751  DeviceNode->ResourceRequirements,
1752  DeviceNode->ResourceRequirements->ListSize);
1753  }
1754 
1755  ZwClose(LogConfKey);
1756  }
1757 
1758  /* Set the 'ConfigFlags' value */
1759  RtlInitUnicodeString(&KeyName, L"ConfigFlags");
1760  Status = ZwQueryValueKey(InstanceKey,
1761  &KeyName,
1763  NULL,
1764  0,
1765  &ResultLength);
1767  {
1768  /* Write the default value */
1769  ULONG DefaultConfigFlags = 0;
1770  Status = ZwSetValueKey(InstanceKey,
1771  &KeyName,
1772  0,
1773  REG_DWORD,
1774  &DefaultConfigFlags,
1775  sizeof(DefaultConfigFlags));
1776  }
1777 
1778  /* Create the 'Control' key */
1779  RtlInitUnicodeString(&KeyName, L"Control");
1781  &KeyName,
1783  InstanceKey,
1784  NULL);
1785  Status = ZwCreateKey(&ControlKey,
1786  0,
1788  0,
1789  NULL,
1791  NULL);
1792  if (NT_SUCCESS(Status))
1793  ZwClose(ControlKey);
1794 
1795  /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
1796  if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
1797  {
1798  RtlInitUnicodeString(&KeyName, L"Device Parameters");
1800  &KeyName,
1802  InstanceKey,
1803  NULL);
1804  Status = ZwCreateKey(&DeviceParamsKey,
1805  0,
1807  0,
1808  NULL,
1810  NULL);
1811  if (NT_SUCCESS(Status))
1812  {
1813  ULONG FirmwareIdentified = 1;
1814  RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
1815  Status = ZwSetValueKey(DeviceParamsKey,
1816  &KeyName,
1817  0,
1818  REG_DWORD,
1819  &FirmwareIdentified,
1820  sizeof(FirmwareIdentified));
1821 
1822  ZwClose(DeviceParamsKey);
1823  }
1824  }
1825 
1826  DPRINT("IopSetDeviceInstanceData() done\n");
1827 
1828  return Status;
1829 }
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:4083
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:1024
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ 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:2355
NTSTATUS PnpRootRegisterDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnproot.c:130
#define DRVO_BUILTIN_DRIVER
Definition: iotypes.h:2119
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:1612
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:1696
_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:2174
#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:2114
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:2966
#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
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1114
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:975
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
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1114
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:1024
PDEVICE_OBJECT PhysicalDeviceObject
Definition: pnpreport.c:21
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:975
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:566
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by IopReportTargetDeviceChangeAsyncWorker(), and IoReportTargetDeviceChange().