[HIDCLASS]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Sun, 5 Feb 2012 15:36:00 +0000 (15:36 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Sun, 5 Feb 2012 15:36:00 +0000 (15:36 +0000)
- Check if attaching to device stack failed. In that case fail the request
[HIDUSB]
- Always set SupriseRemovalOk
[USBCCGP] [HIDCLASS] [USBHUB] [USBSTOR]
- Check if the pdo is still in the pdo list. Only call IoDeleteDevice in that case

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

drivers/hid/hidclass/hidclass.c
drivers/hid/hidclass/pdo.c
drivers/hid/hidusb/hidusb.c
drivers/usb/usbccgp/pdo.c
drivers/usb/usbehci_new/usb_request.cpp
drivers/usb/usbhub_new/pdo.c
drivers/usb/usbohci/usb_queue.cpp
drivers/usb/usbstor/pdo.c
drivers/usb/usbstor/usbstor.h

index 3b6a662..39c31c4 100644 (file)
@@ -79,11 +79,18 @@ HidClassAddDevice(
     RtlZeroMemory(FDODeviceExtension, sizeof(HIDCLASS_FDO_EXTENSION));
 
     /* initialize device extension */
+    FDODeviceExtension->Common.IsFDO = TRUE;
+    FDODeviceExtension->Common.DriverExtension = DriverExtension;
     FDODeviceExtension->Common.HidDeviceExtension.PhysicalDeviceObject = PhysicalDeviceObject;
     FDODeviceExtension->Common.HidDeviceExtension.MiniDeviceExtension = (PVOID)((ULONG_PTR)FDODeviceExtension + sizeof(HIDCLASS_FDO_EXTENSION));
     FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject = IoAttachDeviceToDeviceStack(NewDeviceObject, PhysicalDeviceObject);
-    FDODeviceExtension->Common.IsFDO = TRUE;
-    FDODeviceExtension->Common.DriverExtension = DriverExtension;
+    if (FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject == NULL)
+    {
+        /* no PDO */
+        IoDeleteDevice(NewDeviceObject);
+        DPRINT1("[HIDCLASS] failed to attach to device stack\n");
+        return STATUS_DEVICE_REMOVED;
+    }
 
     /* sanity check */
     ASSERT(FDODeviceExtension->Common.HidDeviceExtension.NextDeviceObject);
index c5045b8..b97ae57 100644 (file)
@@ -354,7 +354,7 @@ HidClassPDO_PnP(
     NTSTATUS Status;
     PPNP_BUS_INFORMATION BusInformation;
     PDEVICE_RELATIONS DeviceRelation;
-    ULONG Index;
+    ULONG Index, bFound;
 
     //
     // get device extension
@@ -535,6 +535,7 @@ HidClassPDO_PnP(
            //
            // remove us from the fdo's pdo list
            //
+           bFound = FALSE;
            for(Index = 0; Index < PDODeviceExtension->FDODeviceExtension->DeviceRelations->Count; Index++)
            {
                if (PDODeviceExtension->FDODeviceExtension->DeviceRelations->Objects[Index] == DeviceObject)
@@ -542,6 +543,7 @@ HidClassPDO_PnP(
                    //
                    // remove us
                    //
+                   bFound = TRUE;
                    PDODeviceExtension->FDODeviceExtension->DeviceRelations->Objects[Index] = NULL;
                    break;
                }
@@ -551,8 +553,11 @@ HidClassPDO_PnP(
             Irp->IoStatus.Status = STATUS_SUCCESS;
             IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-            /* Delete our device object*/
-            IoDeleteDevice(DeviceObject);
+            if (bFound)
+            {
+                /* Delete our device object*/
+                IoDeleteDevice(DeviceObject);
+            }
 
             return STATUS_SUCCESS;
         }
index 40ac22d..6913892 100644 (file)
@@ -1662,19 +1662,10 @@ HidPnp(
                 Status = Irp->IoStatus.Status;
             }
 
-            if (NT_SUCCESS(Status))
-            {
-                //
-                // driver supports D1 & D2
-                //
-                IoStack->Parameters.DeviceCapabilities.Capabilities->DeviceD1 = TRUE;
-                IoStack->Parameters.DeviceCapabilities.Capabilities->DeviceD2 = TRUE;
-
-                //
-                // don't need to safely remove
-                //
-                IoStack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE;
-            }
+            //
+            // don't need to safely remove
+            //
+            IoStack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE;
 
             //
             // done
index a78f7ce..3d7cb01 100644 (file)
@@ -307,7 +307,7 @@ PDO_HandlePnp(
     PIO_STACK_LOCATION IoStack;
     PPDO_DEVICE_EXTENSION PDODeviceExtension;
     NTSTATUS Status;
-    ULONG Index;
+    ULONG Index, bFound;
 
     //
     // get current stack location
@@ -355,6 +355,7 @@ PDO_HandlePnp(
            //
            // remove us from the fdo's pdo list
            //
+           bFound = FALSE;
            for(Index = 0; Index < PDODeviceExtension->FDODeviceExtension->FunctionDescriptorCount; Index++)
            {
                if (PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] == DeviceObject)
@@ -363,6 +364,7 @@ PDO_HandlePnp(
                    // remove us
                    //
                    PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] = NULL;
+                   bFound = TRUE;
                    break;
                }
            }
@@ -373,10 +375,13 @@ PDO_HandlePnp(
            Irp->IoStatus.Status = STATUS_SUCCESS;
            IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-           //
-           // Delete the device object
-           //
-           IoDeleteDevice(DeviceObject);
+           if (bFound)
+           {
+               //
+               // Delete the device object
+               //
+               IoDeleteDevice(DeviceObject);
+           }
            return STATUS_SUCCESS;
        }
        case IRP_MN_QUERY_CAPABILITIES:
index aff29cb..8a0d630 100644 (file)
@@ -743,7 +743,7 @@ CUSBRequest::BuildControlTransferQueueHead(
         //
         // no buffer, setup in descriptor
         //
-        m_TransferDescriptors[1]->Token.Bits.PIDCode = PID_CODE_IN_TOKEN;
+        m_TransferDescriptors[1]->Token.Bits.PIDCode = PID_CODE_OUT_TOKEN;
         m_TransferDescriptors[1]->Token.Bits.TotalBytesToTransfer = 0;
 
         //
index 89e87f7..fadaa57 100644 (file)
@@ -486,6 +486,7 @@ USBHUB_PdoHandlePnp(
     ULONG_PTR Information = 0;
     PHUB_CHILDDEVICE_EXTENSION UsbChildExtension;
     ULONG Index;
+    ULONG bFound;
     PDEVICE_RELATIONS DeviceRelation;
 
     UsbChildExtension = (PHUB_CHILDDEVICE_EXTENSION)DeviceObject->DeviceExtension;
@@ -577,19 +578,21 @@ USBHUB_PdoHandlePnp(
 
             DPRINT1("IRP_MJ_PNP / IRP_MN_REMOVE_DEVICE\n");
 
-            /* Remove the device */
-            Status = HubInterface->RemoveUsbDevice(HubDeviceExtension->UsbDInterface.BusContext, UsbChildExtension->UsbDeviceHandle, 0);
-
-            /* FIXME handle error */
-            ASSERT(Status == STATUS_SUCCESS);
-
             /* remove us from pdo list */
+            bFound = FALSE;
             for(Index = 0; Index < USB_MAXCHILDREN; Index++)
             {
                 if (HubDeviceExtension->ChildDeviceObject[Index] == DeviceObject)
                 {
+                     /* Remove the device */
+                     Status = HubInterface->RemoveUsbDevice(HubDeviceExtension->UsbDInterface.BusContext, UsbChildExtension->UsbDeviceHandle, 0);
+
+                     /* FIXME handle error */
+                     ASSERT(Status == STATUS_SUCCESS);
+
                     /* remove us */
                     HubDeviceExtension->ChildDeviceObject[Index] = NULL;
+                    bFound = TRUE;
                     break;
                 }
             }
@@ -598,8 +601,12 @@ USBHUB_PdoHandlePnp(
             Irp->IoStatus.Status = STATUS_SUCCESS;
             IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-            /* Delete the device object */
-            IoDeleteDevice(DeviceObject);
+            if (bFound)
+            {
+                /* Delete the device object */
+                IoDeleteDevice(DeviceObject);
+            }
+
             return STATUS_SUCCESS;
         }
         case IRP_MN_QUERY_DEVICE_RELATIONS:
index dabc458..67d425b 100644 (file)
@@ -622,75 +622,84 @@ CUSBQueue::TransferDescriptorCompletionCallback(
 
     DPRINT("CUSBQueue::TransferDescriptorCompletionCallback transfer descriptor %x\n", TransferDescriptorLogicalAddress);
 
-    //
-    // find transfer descriptor in control list
-    //
-    Status = FindTransferDescriptorInEndpoint(m_ControlHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
-    if (NT_SUCCESS(Status))
+    do
     {
         //
-        // cleanup endpoint
+        // find transfer descriptor in control list
         //
-        CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
+        Status = FindTransferDescriptorInEndpoint(m_ControlHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
+        if (NT_SUCCESS(Status))
+        {
+            //
+            // cleanup endpoint
+            //
+            CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
 
-        //
-        // done
-        //
-        return;
-    }
+            //
+            // done
+            //
+            continue;
+        }
 
-    //
-    // find transfer descriptor in bulk list
-    //
-    Status = FindTransferDescriptorInEndpoint(m_BulkHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
-    if (NT_SUCCESS(Status))
-    {
         //
-        // cleanup endpoint
+        // find transfer descriptor in bulk list
         //
-        CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
+        Status = FindTransferDescriptorInEndpoint(m_BulkHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
+        if (NT_SUCCESS(Status))
+        {
+            //
+            // cleanup endpoint
+            //
+            CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
 
-        //
-        // done
-        //
-        return;
-    }
+            //
+            // done
+            //
+            continue;
+        }
 
-    //
-    // find transfer descriptor in interrupt list
-    //
-    Status = FindTransferDescriptorInInterruptHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
-    if (NT_SUCCESS(Status))
-    {
         //
-        // cleanup endpoint
+        // find transfer descriptor in interrupt list
         //
-        CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
+        Status = FindTransferDescriptorInInterruptHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
+        if (NT_SUCCESS(Status))
+        {
+            //
+            // cleanup endpoint
+            //
+            CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
 
-        //
-        // done
-        //
-        return;
-    }
+            //
+            // done
+            //
+            continue;
+        }
 
-    //
-    // last try: find the descriptor in isochronous list
-    //
-    Status = FindTransferDescriptorInIsochronousHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
-    if (NT_SUCCESS(Status))
-    {
         //
-        // cleanup endpoint
+        // last try: find the descriptor in isochronous list
         //
-        DPRINT1("ISO endpoint complete\n");
-ASSERT(FALSE);
-        CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
+        Status = FindTransferDescriptorInIsochronousHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
+        if (NT_SUCCESS(Status))
+        {
+            //
+            // cleanup endpoint
+            //
+            DPRINT1("ISO endpoint complete\n");
+            ASSERT(FALSE);
+            CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
+
+            //
+            // done
+            //
+            continue;
+        }
 
         //
-        // done
+        // no more completed descriptors found
         //
         return;
-    }
+
+    }while(TRUE);
 
     //
     // hardware reported dead endpoint completed
index 3361351..eda74dd 100644 (file)
@@ -773,6 +773,7 @@ USBSTOR_PdoHandlePnp(
     PPDO_DEVICE_EXTENSION DeviceExtension;
     NTSTATUS Status;
     PDEVICE_CAPABILITIES Caps;
+    ULONG bDelete;
 
     //
     // get current stack location
@@ -845,13 +846,31 @@ USBSTOR_PdoHandlePnp(
        {
            DPRINT1("IRP_MN_REMOVE_DEVICE\n");
 
+           if(*DeviceExtension->PDODeviceObject != NULL)
+           {
+               //
+               // clear entry in FDO pdo list
+               //
+               *DeviceExtension->PDODeviceObject = NULL;
+               bDelete = TRUE;
+           }
+           else
+           {
+               //
+               // device object already marked for deletion
+               //
+               bDelete = FALSE;
+           }
+
            /* Complete the IRP */
            Irp->IoStatus.Status = STATUS_SUCCESS;
            IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-           /* Delete the device object */
-           IoDeleteDevice(DeviceObject);
-
+           if (bDelete)
+           {
+               /* Delete the device object */
+               IoDeleteDevice(DeviceObject);
+           }
            return STATUS_SUCCESS;
        }
        case IRP_MN_QUERY_CAPABILITIES:
@@ -880,7 +899,10 @@ USBSTOR_PdoHandlePnp(
            // if we're not claimed it's ok
            //
            if (DeviceExtension->Claimed)
+           {
                Status = STATUS_UNSUCCESSFUL;
+               DPRINT1("[USBSTOR] Request %x fails because device is still claimed\n", IoStack->MinorFunction);
+           }
            else
                Status = STATUS_SUCCESS;
            break;
@@ -961,6 +983,7 @@ USBSTOR_CreatePDO(
     RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
     PDODeviceExtension->Common.IsFDO = FALSE;
     PDODeviceExtension->LowerDeviceObject = DeviceObject;
+    PDODeviceExtension->PDODeviceObject = ChildDeviceObject;
 
     //
     // set device flags
index 7c0e0d4..b2b9e33 100644 (file)
@@ -79,6 +79,7 @@ typedef struct
     UCHAR Claimed;                                                                       // indicating if it has been claimed by upper driver
     ULONG BlockLength;                                                                   // length of block
     ULONG LastLogicBlockAddress;                                                         // last block address
+    PDEVICE_OBJECT *PDODeviceObject;                                                     // entry in pdo list
 }PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
 
 //