Merge 14551:14980 from trunk
[reactos.git] / reactos / drivers / dd / serial / pnp.c
index 211f7ae..04e08f1 100644 (file)
@@ -26,12 +26,14 @@ SerialAddDeviceInternal(
        NTSTATUS Status;
        WCHAR DeviceNameBuffer[32];
        UNICODE_STRING DeviceName;
-       //UNICODE_STRING SymbolicLinkName;
        static ULONG DeviceNumber = 0;
        static ULONG ComPortNumber = 1;
-
+       
        DPRINT("Serial: SerialAddDeviceInternal called\n");
-   
+       
+       ASSERT(DriverObject);
+       ASSERT(Pdo);
+       
        /* Create new device object */
        swprintf(DeviceNameBuffer, L"\\Device\\Serial%lu", DeviceNumber);
        RtlInitUnicodeString(&DeviceName, DeviceNameBuffer);
@@ -52,23 +54,13 @@ SerialAddDeviceInternal(
        RtlZeroMemory(DeviceExtension, sizeof(SERIAL_DEVICE_EXTENSION));
        
        /* Register device interface */
-#if 0 /* FIXME: activate */
-       Status = IoRegisterDeviceInterface(Pdo, &GUID_DEVINTERFACE_COMPORT, NULL, &SymbolicLinkName);
+       Status = IoRegisterDeviceInterface(Pdo, &GUID_DEVINTERFACE_COMPORT, NULL, &DeviceExtension->SerialInterfaceName);
        if (!NT_SUCCESS(Status))
        {
                DPRINT("Serial: IoRegisterDeviceInterface() failed with status 0x%08x\n", Status);
                goto ByeBye;
        }
-       DPRINT1("Serial: IoRegisterDeviceInterface() returned '%wZ'\n", &SymbolicLinkName);
-       Status = IoSetDeviceInterfaceState(&SymbolicLinkName, TRUE);
-       if (!NT_SUCCESS(Status))
-       {
-               DPRINT("Serial: IoSetDeviceInterfaceState() failed with status 0x%08x\n", Status);
-               goto ByeBye;
-       }
-       RtlFreeUnicodeString(&SymbolicLinkName);
-#endif
-
+       
        DeviceExtension->SerialPortNumber = DeviceNumber++;
        if (pComPortNumber == NULL)
                DeviceExtension->ComPort = ComPortNumber++;
@@ -125,12 +117,10 @@ SerialAddDevice(
        if (Pdo == NULL)
                return STATUS_SUCCESS;
        
-       /* We have here a PDO that does not correspond to a legacy
-        * serial port. So call the internal AddDevice function.
+       /* We have here a PDO not null. It represents a real serial
+        * port. So call the internal AddDevice function.
         */
        return SerialAddDeviceInternal(DriverObject, Pdo, UartUnknown, NULL, NULL);
-
-
 }
 
 NTSTATUS STDCALL
@@ -160,6 +150,8 @@ SerialPnpStartDevice(
        
        DeviceExtension = (PSERIAL_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
        
+       ASSERT(ResourceList);
+       ASSERT(DeviceExtension);
        ASSERT(DeviceExtension->PnpState == dsStopped);
        
        DeviceExtension->BaudRate = 19200 | SERIAL_BAUD_USER;
@@ -251,6 +243,15 @@ SerialPnpStartDevice(
                return Status;
        }
        
+       /* Activate serial interface */
+       Status = IoSetDeviceInterfaceState(&DeviceExtension->SerialInterfaceName, TRUE);
+       if (!NT_SUCCESS(Status))
+       {
+               DPRINT("Serial: IoSetDeviceInterfaceState() failed with status 0x%08x\n", Status);
+               IoDeleteSymbolicLink(&LinkName);
+               return Status;
+       }
+       
        /* Connect interrupt and enable them */
        Status = IoConnectInterrupt(
                &DeviceExtension->Interrupt, SerialInterruptService,
@@ -261,6 +262,7 @@ SerialPnpStartDevice(
        if (!NT_SUCCESS(Status))
        {
                DPRINT("Serial: IoConnectInterrupt() failed with status 0x%08x\n", Status);
+               IoSetDeviceInterfaceState(&DeviceExtension->SerialInterfaceName, FALSE);
                IoDeleteSymbolicLink(&LinkName);
                return Status;
        }
@@ -363,6 +365,7 @@ SerialPnp(
                        IoAcquireRemoveLock
                        IoReleaseRemoveLockAndWait
                        pass request to DeviceExtension-LowerDriver
+                       disable interface
                        IoDeleteDevice(Fdo) and/or IoDetachDevice
                        break;
                }*/