* Sync up to trunk head (r64921).
[reactos.git] / ntoskrnl / io / pnpmgr / pnpreport.c
index 18d75ab..206fccf 100644 (file)
@@ -38,9 +38,6 @@ NTSTATUS
 IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
                                 PVOID Context);
 
-NTSTATUS
-IopDetectResourceConflict(IN PCM_RESOURCE_LIST ResourceList);
-
 NTSTATUS
 PpSetCustomTargetEvent(IN PDEVICE_OBJECT DeviceObject,
                        IN OUT PKEVENT SyncEvent OPTIONAL,
@@ -132,12 +129,25 @@ PpSetCustomTargetEvent(IN PDEVICE_OBJECT DeviceObject,
     ASSERT(NotificationStructure != NULL);
     ASSERT(DeviceObject != NULL);
 
+    if (SyncEvent)
+    {
+        ASSERT(SyncStatus);
+        *SyncStatus = STATUS_PENDING;
+    }
+
     /* That call is totally wrong but notifications handler must be fixed first */
     IopNotifyPlugPlayNotification(DeviceObject,
                                   EventCategoryTargetDeviceChange,
                                   &GUID_PNP_CUSTOM_NOTIFICATION,
                                   NotificationStructure,
                                   NULL);
+
+    if (SyncEvent)
+    {
+        KeSetEvent(SyncEvent, IO_NO_INCREMENT, FALSE);
+        *SyncStatus = STATUS_SUCCESS;
+    }
+
     return STATUS_SUCCESS;
 }
 
@@ -192,12 +202,12 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
     if (DeviceObject && *DeviceObject)
     {
         Pdo = *DeviceObject;
-        DeviceNode = IopGetDeviceNode(*DeviceObject);
     }
     else
     {
         /* Create the PDO */
         Status = PnpRootCreateDevice(&ServiceName,
+                                     NULL,
                                      &Pdo,
                                      NULL);
         if (!NT_SUCCESS(Status))
@@ -205,20 +215,23 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
             DPRINT("PnpRootCreateDevice() failed (Status 0x%08lx)\n", Status);
             return Status;
         }
+    }
 
-        /* Create the device node for the new PDO */
-        Status = IopCreateDeviceNode(IopRootDeviceNode,
-                                     Pdo,
-                                     NULL,
-                                     &DeviceNode);
+    /* Create the device node for the new PDO */
+    Status = IopCreateDeviceNode(IopRootDeviceNode,
+                                 Pdo,
+                                 NULL,
+                                 &DeviceNode);
 
-        if (!NT_SUCCESS(Status))
-        {
-            DPRINT("IopCreateDeviceNode() failed (Status 0x%08lx)\n", Status);
-            return Status;
-        }
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT("IopCreateDeviceNode() failed (Status 0x%08lx)\n", Status);
+        return Status;
     }
 
+    /* We're enumerated already */
+    IopDeviceNodeSetFlag(DeviceNode, DNF_ENUMERATED);
+
     /* We don't call AddDevice for devices reported this way */
     IopDeviceNodeSetFlag(DeviceNode, DNF_ADDED);
 
@@ -238,7 +251,8 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
     IopActionConfigureChildServices(DeviceNode, DeviceNode->Parent);
 
     /* Open a handle to the instance path key */
-    Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, 0, &InstanceKey);
+    /* REG_OPTION_VOLATILE is a HACK!!! */
+    Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_VOLATILE, &InstanceKey);
     if (!NT_SUCCESS(Status))
         return Status;
 
@@ -248,16 +262,16 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
                          L"DETECTED%ls\\%wZ",
                          IfString,
                          &ServiceName);
-    HardwareId[IdLength++] = UNICODE_NULL;
+    IdLength++;
 
     /* Add DETECTED\DriverName */
     IdLength += swprintf(&HardwareId[IdLength],
                          L"DETECTED\\%wZ",
                          &ServiceName);
-    HardwareId[IdLength++] = UNICODE_NULL;
+    IdLength++;
 
     /* Terminate the string with another null */
-    HardwareId[IdLength] = UNICODE_NULL;
+    HardwareId[IdLength++] = UNICODE_NULL;
 
     /* Store the value for CompatibleIDs */
     RtlInitUnicodeString(&ValueName, L"CompatibleIDs");
@@ -279,10 +293,12 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
                             L"DETECTED%ls\\%wZ",
                             IfString,
                             &ServiceName);
-       HardwareId[++IdLength] = UNICODE_NULL;
+       IdLength++;
+
+       HardwareId[IdLength++] = UNICODE_NULL;
 
        /* Write the value to the registry */
-       Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_SZ, HardwareId, IdLength * sizeof(WCHAR));
+       Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
        if (!NT_SUCCESS(Status))
        {
           DPRINT("Failed to write the hardware ID: 0x%x\n", Status);
@@ -322,6 +338,10 @@ IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject,
     /* Close the instance key handle */
     ZwClose(InstanceKey);
 
+    /* Register the given DO with PnP root if required */
+    if (DeviceObject && *DeviceObject)
+        PnpRootRegisterDevice(*DeviceObject);
+
     /* Report the device's enumeration to umpnpmgr */
     IopQueueTargetDeviceEvent(&GUID_DEVICE_ENUMERATED,
                               &DeviceNode->InstancePath);
@@ -366,7 +386,7 @@ IoReportResourceForDetection(IN PDRIVER_OBJECT DriverObject,
         ResourceList = DriverList;
 
     /* Look for a resource conflict */
-    Status = IopDetectResourceConflict(ResourceList);
+    Status = IopDetectResourceConflict(ResourceList, FALSE, NULL);
     if (Status == STATUS_CONFLICTING_ADDRESSES)
     {
         /* Oh noes */