[USB-BRINGUP-TRUNK]
authorCameron Gutman <aicommander@gmail.com>
Sat, 21 Jan 2012 02:59:46 +0000 (02:59 +0000)
committerCameron Gutman <aicommander@gmail.com>
Sat, 21 Jan 2012 02:59:46 +0000 (02:59 +0000)
- Open a file handle to the port driver like Windows does
- USB mice are working now

svn path=/branches/usb-bringup-trunk/; revision=55041

drivers/input/kbdclass/kbdclass.c
drivers/input/kbdclass/kbdclass.h
drivers/input/mouclass/mouclass.c
drivers/input/mouclass/mouclass.h

index 3cf6c95..03be367 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))
+       {
+               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;
index f68386e..8defeb6 100644 (file)
@@ -48,6 +48,7 @@ typedef struct _PORT_DEVICE_EXTENSION
        PORT_DEVICE_STATE PnpState;
        PDEVICE_OBJECT LowerDevice;
        PDEVICE_OBJECT ClassDO;
+       HANDLE FileHandle;
        UNICODE_STRING InterfaceName;
 } PORT_DEVICE_EXTENSION, *PPORT_DEVICE_EXTENSION;
 
index 99818bb..6622633 100644 (file)
@@ -800,6 +800,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))
+       {
+               IoSkipCurrentIrpStackLocation(Irp);
+               return IoCallDriver(DeviceExtension->LowerDevice, Irp);
+       }
+       else
+       {
+               IoCompleteRequest(Irp, IO_NO_INCREMENT);
+               return Status;
+       }
+}
+
 static VOID NTAPI
 ClassStartIo(
        IN PDEVICE_OBJECT DeviceObject,
@@ -993,6 +1059,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;
index cd70bee..5bf7e15 100644 (file)
@@ -48,6 +48,7 @@ typedef struct _PORT_DEVICE_EXTENSION
        PORT_DEVICE_STATE PnpState;
        PDEVICE_OBJECT LowerDevice;
        PDEVICE_OBJECT ClassDO;
+       HANDLE FileHandle;
        UNICODE_STRING InterfaceName;
 } PORT_DEVICE_EXTENSION, *PPORT_DEVICE_EXTENSION;