[USB]
[reactos.git] / reactos / drivers / input / kbdclass / kbdclass.c
index 3cf6c95..e1bbe58 100644 (file)
@@ -824,6 +824,72 @@ HandleReadIrp(
        return Status;
 }
 
+static NTSTATUS NTAPI
+ClassPnp(
+       IN PDEVICE_OBJECT DeviceObject,
+       IN PIRP Irp)
+{
+       PPORT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
+       PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
+       OBJECT_ATTRIBUTES ObjectAttributes;
+       IO_STATUS_BLOCK Iosb;
+       NTSTATUS Status;
+       
+       switch (IrpSp->MinorFunction)
+       {
+               case IRP_MN_START_DEVICE:
+                   Status = ForwardIrpAndWait(DeviceObject, Irp);
+                       if (NT_SUCCESS(Status))
+                       {
+                               InitializeObjectAttributes(&ObjectAttributes,
+                                                                                  &DeviceExtension->InterfaceName,
+                                                                                  OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
+                                                                                  NULL,
+                                                                                  NULL);
+
+                               Status = ZwOpenFile(&DeviceExtension->FileHandle,
+                                                                       FILE_READ_DATA,
+                                                                       &ObjectAttributes,
+                                                                       &Iosb,
+                                                                       0,
+                                                                       0);
+                               if (!NT_SUCCESS(Status))
+                                       DeviceExtension->FileHandle = NULL;
+                       }
+                       else
+                               DeviceExtension->FileHandle = NULL;
+                       Irp->IoStatus.Status = Status;
+                       IoCompleteRequest(Irp, IO_NO_INCREMENT);
+                       return Status;
+                       
+               case IRP_MN_REMOVE_DEVICE:
+               case IRP_MN_STOP_DEVICE:
+                       if (DeviceExtension->FileHandle)
+                       {
+                               ZwClose(DeviceExtension->FileHandle);
+                               DeviceExtension->FileHandle = NULL;
+                       }
+                       Status = STATUS_SUCCESS;
+                       break;
+
+               default:
+                       Status = Irp->IoStatus.Status;
+                       break;
+       }
+
+       Irp->IoStatus.Status = Status;
+       if (NT_SUCCESS(Status) || Status == STATUS_NOT_SUPPORTED)
+       {
+               IoSkipCurrentIrpStackLocation(Irp);
+               return IoCallDriver(DeviceExtension->LowerDevice, Irp);
+       }
+       else
+       {
+               IoCompleteRequest(Irp, IO_NO_INCREMENT);
+               return Status;
+       }
+}
+
 static VOID NTAPI
 ClassStartIo(
        IN PDEVICE_OBJECT DeviceObject,
@@ -1021,6 +1087,7 @@ DriverEntry(
        DriverObject->MajorFunction[IRP_MJ_CLOSE]          = ClassClose;
        DriverObject->MajorFunction[IRP_MJ_CLEANUP]        = ClassCleanup;
        DriverObject->MajorFunction[IRP_MJ_READ]           = ClassRead;
+       DriverObject->MajorFunction[IRP_MJ_PNP]            = ClassPnp;
        DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ClassDeviceControl;
        DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = ForwardIrpAndForget;
        DriverObject->DriverStartIo                        = ClassStartIo;