[HIDCLASS][USBHUB]
[reactos.git] / reactos / drivers / hid / hidclass / fdo.c
index 84ae429..3b1ccbd 100644 (file)
@@ -10,6 +10,9 @@
 
 #include "precomp.h"
 
+#define NDEBUG
+#include <debug.h>
+
 NTSTATUS
 NTAPI
 HidClassFDO_QueryCapabilitiesCompletionRoutine(
@@ -20,7 +23,7 @@ HidClassFDO_QueryCapabilitiesCompletionRoutine(
     //
     // set event
     //
-    KeSetEvent((PRKEVENT)Context, 0, FALSE);
+    KeSetEvent(Context, 0, FALSE);
 
     //
     // completion is done in the HidClassFDO_QueryCapabilities routine
@@ -42,7 +45,7 @@ HidClassFDO_QueryCapabilities(
     //
     // get device extension
     //
-    FDODeviceExtension = (PHIDCLASS_FDO_EXTENSION)DeviceObject->DeviceExtension;
+    FDODeviceExtension = DeviceObject->DeviceExtension;
     ASSERT(FDODeviceExtension->Common.IsFDO);
 
     //
@@ -77,7 +80,7 @@ HidClassFDO_QueryCapabilities(
     //
     // set completion routine
     //
-    IoSetCompletionRoutine(Irp, HidClassFDO_QueryCapabilitiesCompletionRoutine, (PVOID)&Event, TRUE, TRUE, TRUE);
+    IoSetCompletionRoutine(Irp, HidClassFDO_QueryCapabilitiesCompletionRoutine, &Event, TRUE, TRUE, TRUE);
 
     //
     // init capabilities
@@ -131,7 +134,7 @@ HidClassFDO_DispatchRequestSynchronousCompletion(
     //
     // signal event
     //
-    KeSetEvent((PRKEVENT)Context, 0, FALSE);
+    KeSetEvent(Context, 0, FALSE);
 
     //
     // done
@@ -158,7 +161,7 @@ HidClassFDO_DispatchRequestSynchronous(
     //
     // get device extension
     //
-    CommonDeviceExtension = (PHIDCLASS_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+    CommonDeviceExtension = DeviceObject->DeviceExtension;
 
     //
     // set completion routine
@@ -182,9 +185,13 @@ HidClassFDO_DispatchRequestSynchronous(
     IoStack->DeviceObject = DeviceObject;
 
     //
-    // call driver
+    // sanity check
+    //
+    ASSERT(CommonDeviceExtension->DriverExtension->MajorFunction[IoStack->MajorFunction] != NULL);
+
+    //
+    // call minidriver (hidusb)
     //
-    DPRINT("IoStack MajorFunction %x MinorFunction %x\n", IoStack->MajorFunction, IoStack->MinorFunction);
     Status = CommonDeviceExtension->DriverExtension->MajorFunction[IoStack->MajorFunction](DeviceObject, Irp);
 
     //
@@ -206,6 +213,53 @@ HidClassFDO_DispatchRequestSynchronous(
     return Status;
 }
 
+NTSTATUS
+HidClassFDO_DispatchRequest(
+    IN PDEVICE_OBJECT DeviceObject,
+    IN PIRP Irp)
+{
+    PHIDCLASS_COMMON_DEVICE_EXTENSION CommonDeviceExtension;
+    NTSTATUS Status;
+    PIO_STACK_LOCATION IoStack;
+
+    //
+    // get device extension
+    //
+    CommonDeviceExtension = DeviceObject->DeviceExtension;
+
+    ASSERT(Irp->CurrentLocation > 0);
+
+    //
+    // create stack location
+    //
+    IoSetNextIrpStackLocation(Irp);
+
+    //
+    // get next stack location
+    //
+    IoStack = IoGetCurrentIrpStackLocation(Irp);
+
+    //
+    // store device object
+    //
+    IoStack->DeviceObject = DeviceObject;
+
+    //
+    // sanity check
+    //
+    ASSERT(CommonDeviceExtension->DriverExtension->MajorFunction[IoStack->MajorFunction] != NULL);
+
+    //
+    // call driver
+    //
+    Status = CommonDeviceExtension->DriverExtension->MajorFunction[IoStack->MajorFunction](DeviceObject, Irp);
+
+    //
+    // done
+    //
+    return Status;
+}
+
 NTSTATUS
 HidClassFDO_GetDescriptors(
     IN PDEVICE_OBJECT DeviceObject)
@@ -218,7 +272,7 @@ HidClassFDO_GetDescriptors(
     //
     // get device extension
     //
-    FDODeviceExtension = (PHIDCLASS_FDO_EXTENSION)DeviceObject->DeviceExtension;
+    FDODeviceExtension = DeviceObject->DeviceExtension;
     ASSERT(FDODeviceExtension->Common.IsFDO);
 
     //
@@ -294,7 +348,9 @@ HidClassFDO_GetDescriptors(
     //
     // now allocate space for the report descriptor
     //
-    FDODeviceExtension->ReportDescriptor = (PUCHAR)ExAllocatePool(NonPagedPool, FDODeviceExtension->HidDescriptor.DescriptorList[0].wReportLength);
+    FDODeviceExtension->ReportDescriptor = ExAllocatePoolWithTag(NonPagedPool,
+                                                                 FDODeviceExtension->HidDescriptor.DescriptorList[0].wReportLength,
+                                                                 HIDCLASS_TAG);
     if (!FDODeviceExtension->ReportDescriptor)
     {
         //
@@ -328,6 +384,7 @@ HidClassFDO_GetDescriptors(
     //
     // completed successfully
     //
+    IoFreeIrp(Irp);
     return STATUS_SUCCESS;
 }
 
@@ -343,7 +400,7 @@ HidClassFDO_StartDevice(
     //
     // get device extension
     //
-    FDODeviceExtension = (PHIDCLASS_FDO_EXTENSION)DeviceObject->DeviceExtension;
+    FDODeviceExtension = DeviceObject->DeviceExtension;
     ASSERT(FDODeviceExtension->Common.IsFDO);
 
     //
@@ -409,6 +466,13 @@ HidClassFDO_RemoveDevice(
     IN PIRP Irp)
 {
     NTSTATUS Status;
+    PHIDCLASS_FDO_EXTENSION FDODeviceExtension;
+
+    //
+    // get device extension
+    //
+    FDODeviceExtension = DeviceObject->DeviceExtension;
+    ASSERT(FDODeviceExtension->Common.IsFDO);
 
     /* FIXME cleanup */
 
@@ -423,6 +487,13 @@ HidClassFDO_RemoveDevice(
     //
     Irp->IoStatus.Status = Status;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+    //
+    // detach and delete device
+    //
+    IoDetachDevice(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject);
+    IoDeleteDevice(DeviceObject);
+
     return Status;
 }
 
@@ -438,13 +509,15 @@ HidClassFDO_CopyDeviceRelations(
     //
     // get device extension
     //
-    FDODeviceExtension = (PHIDCLASS_FDO_EXTENSION)DeviceObject->DeviceExtension;
+    FDODeviceExtension = DeviceObject->DeviceExtension;
     ASSERT(FDODeviceExtension->Common.IsFDO);
 
     //
     // allocate result
     //
-    DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePool(NonPagedPool, sizeof(DEVICE_RELATIONS) + (FDODeviceExtension->DeviceRelations->Count-1) * sizeof(PDEVICE_OBJECT));
+    DeviceRelations = ExAllocatePoolWithTag(NonPagedPool,
+                                            sizeof(DEVICE_RELATIONS) + (FDODeviceExtension->DeviceRelations->Count - 1) * sizeof(PDEVICE_OBJECT),
+                                            HIDCLASS_TAG);
     if (!DeviceRelations)
     {
         //
@@ -495,7 +568,7 @@ HidClassFDO_DeviceRelations(
     //
     // get device extension
     //
-    FDODeviceExtension = (PHIDCLASS_FDO_EXTENSION)DeviceObject->DeviceExtension;
+    FDODeviceExtension = DeviceObject->DeviceExtension;
     ASSERT(FDODeviceExtension->Common.IsFDO);
 
     //
@@ -566,7 +639,7 @@ HidClassFDO_PnP(
     //
     // get device extension
     //
-    FDODeviceExtension = (PHIDCLASS_FDO_EXTENSION)DeviceObject->DeviceExtension;
+    FDODeviceExtension = DeviceObject->DeviceExtension;
     ASSERT(FDODeviceExtension->Common.IsFDO);
 
     //
@@ -602,14 +675,8 @@ HidClassFDO_PnP(
             //
             // dispatch to mini driver
             //
-           IoSkipCurrentIrpStackLocation(Irp);
-           Status = HidClassFDO_DispatchRequestSynchronous(DeviceObject, Irp);
-
-           //
-           // complete request
-           //
-           Irp->IoStatus.Status = Status;
-           IoCompleteRequest(Irp, IO_NO_INCREMENT);
+           IoCopyCurrentIrpStackLocationToNext(Irp);
+           Status = HidClassFDO_DispatchRequest(DeviceObject, Irp);
            return Status;
         }
     }