Allow more than one USB controller (was a XBOX hack no more needed)
[reactos.git] / reactos / drivers / usb / miniport / common / main.c
index a6a1ce2..88785c7 100644 (file)
@@ -65,16 +65,69 @@ CreateRootHubPdo(
        return STATUS_SUCCESS;
 }
 
-#if 0
+static NTSTATUS
+AddRegistryEntry(
+       IN PCWSTR PortTypeName,
+       IN PUNICODE_STRING DeviceName,
+       IN PCWSTR RegistryPath)
+{
+       UNICODE_STRING PathU = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DEVICEMAP");
+       OBJECT_ATTRIBUTES ObjectAttributes;
+       HANDLE hDeviceMapKey = (HANDLE)-1;
+       HANDLE hPortKey = (HANDLE)-1;
+       UNICODE_STRING PortTypeNameU;
+       NTSTATUS Status;
+
+       InitializeObjectAttributes(&ObjectAttributes, &PathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);
+       Status = ZwOpenKey(&hDeviceMapKey, 0, &ObjectAttributes);
+       if (!NT_SUCCESS(Status))
+       {
+               DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
+               goto cleanup;
+       }
+
+       RtlInitUnicodeString(&PortTypeNameU, PortTypeName);
+       InitializeObjectAttributes(&ObjectAttributes, &PortTypeNameU, OBJ_KERNEL_HANDLE, hDeviceMapKey, NULL);
+       Status = ZwCreateKey(&hPortKey, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_VOLATILE, NULL);
+       if (!NT_SUCCESS(Status))
+       {
+               DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status);
+               goto cleanup;
+       }
+
+       Status = ZwSetValueKey(hPortKey, DeviceName, 0, REG_SZ, (PVOID)RegistryPath, wcslen(RegistryPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
+       if (!NT_SUCCESS(Status))
+       {
+               DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status);
+               goto cleanup;
+       }
+
+       Status = STATUS_SUCCESS;
+
+cleanup:
+       if (hDeviceMapKey != (HANDLE)-1)
+               ZwClose(hDeviceMapKey);
+       if (hPortKey != (HANDLE)-1)
+               ZwClose(hPortKey);
+       return Status;
+}
+
 static NTSTATUS
 AddDevice_Keyboard(
        IN PDRIVER_OBJECT DriverObject,
        IN PDEVICE_OBJECT Pdo)
 {
-       UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardClass0");
+       UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardPortUSB");
        PDEVICE_OBJECT Fdo;
        NTSTATUS Status;
 
+       Status = AddRegistryEntry(L"KeyboardPort", &DeviceName, L"REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\usbport");
+       if (!NT_SUCCESS(Status))
+       {
+               DPRINT1("USBMP: AddRegistryEntry() for usb keyboard driver failed with status 0x%08lx\n", Status);
+               return Status;
+       }
+
        Status = IoCreateDevice(DriverObject,
                8, // debug
                &DeviceName,
@@ -100,10 +153,17 @@ AddDevice_Mouse(
        IN PDRIVER_OBJECT DriverObject,
        IN PDEVICE_OBJECT Pdo)
 {
-       UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\PointerClass0");
+       UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\PointerPortUSB");
        PDEVICE_OBJECT Fdo;
        NTSTATUS Status;
 
+       Status = AddRegistryEntry(L"PointerPort", &DeviceName, L"REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\usbport");
+       if (!NT_SUCCESS(Status))
+       {
+               DPRINT1("USBMP: AddRegistryEntry() for usb mouse driver failed with status 0x%08lx\n", Status);
+               return Status;
+       }
+
        Status = IoCreateDevice(DriverObject,
                8, // debug
                &DeviceName,
@@ -123,7 +183,6 @@ AddDevice_Mouse(
 
        return STATUS_SUCCESS;
 }
-#endif
 
 NTSTATUS STDCALL
 AddDevice(
@@ -140,16 +199,6 @@ AddDevice(
        PUSBMP_DEVICE_EXTENSION DeviceExtension;
        ULONG DeviceNumber;
 
-       /* FIXME: actually, we prevent multiple USB controllers on a computer */
-       static BOOLEAN xbox_workaround = FALSE;
-
-       DPRINT("USBMP: AddDevice called\n");
-       
-       if (xbox_workaround)
-               // Fail for any other host controller than the first
-               return STATUS_INSUFFICIENT_RESOURCES;
-       xbox_workaround = TRUE;
-
        // Allocate driver extension now
        DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
        if (DriverExtension == NULL)
@@ -168,7 +217,7 @@ AddDevice(
        }
 
        // Create a unicode device name
-//     DeviceNumber = 0; //TODO: Allocate new device number every time
+       DeviceNumber = 0; //TODO: Allocate new device number every time
        swprintf(DeviceBuffer, L"\\Device\\USBFDO-%lu", DeviceNumber);
        RtlInitUnicodeString(&DeviceName, DeviceBuffer);
 
@@ -231,12 +280,10 @@ AddDevice(
 
        Status = IoCreateSymbolicLink(&LinkDeviceName, &DeviceName);
 
-       /*
        if (NT_SUCCESS(Status))
                Status = AddDevice_Keyboard(DriverObject, pdo);
        if (NT_SUCCESS(Status))
                Status = AddDevice_Mouse(DriverObject, pdo);
-       */
 
        if (!NT_SUCCESS(Status))
        {