From 820049768b4b3c1d9ba0c40509f778c314bd3f91 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Thu, 2 Feb 2012 10:17:14 +0000 Subject: [PATCH] [USBCCGP] - Remove hacks used for broken usbd driver - Implement IRP_MN_REMOVE for FDO & PDO svn path=/branches/usb-bringup-trunk/; revision=55372 --- drivers/usb/usbccgp/descriptor.c | 5 ++--- drivers/usb/usbccgp/fdo.c | 25 ++++++++++++++++++++++++- drivers/usb/usbccgp/pdo.c | 25 +++++++++++++++++++++---- drivers/usb/usbccgp/usbccgp.h | 1 + 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/drivers/usb/usbccgp/descriptor.c b/drivers/usb/usbccgp/descriptor.c index f4c30e96d5b..e8e74f8ba5f 100644 --- a/drivers/usb/usbccgp/descriptor.c +++ b/drivers/usb/usbccgp/descriptor.c @@ -259,8 +259,6 @@ AllocateInterfaceDescriptorsArray( return STATUS_SUCCESS; } - - NTSTATUS NTAPI USBCCGP_ScanConfigurationDescriptor( @@ -281,7 +279,7 @@ USBCCGP_ScanConfigurationDescriptor( // // count all interface descriptors // - DescriptorCount = CountInterfaceDescriptors(ConfigurationDescriptor); + DescriptorCount = ConfigurationDescriptor->bNumInterfaces; // // allocate array holding the interface descriptors @@ -302,6 +300,7 @@ USBCCGP_ScanConfigurationDescriptor( // parse configuration descriptor // InterfaceDescriptor = USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor, ConfigurationDescriptor, InterfaceIndex, -1, -1, -1, -1); + ASSERT(InterfaceDescriptor); if (InterfaceDescriptor) { // diff --git a/drivers/usb/usbccgp/fdo.c b/drivers/usb/usbccgp/fdo.c index fe89da13ad0..d4bfacf30ac 100644 --- a/drivers/usb/usbccgp/fdo.c +++ b/drivers/usb/usbccgp/fdo.c @@ -279,6 +279,7 @@ FDO_CreateChildPdo( PDODeviceExtension->FunctionDescriptor = &FDODeviceExtension->FunctionDescriptor[Index]; PDODeviceExtension->NextDeviceObject = FDODeviceExtension->NextDeviceObject; //DeviceObject; HACK PDODeviceExtension->FunctionIndex = Index; + PDODeviceExtension->FDODeviceExtension = FDODeviceExtension; PDODeviceExtension->InterfaceList = FDODeviceExtension->InterfaceList; PDODeviceExtension->InterfaceListCount = FDODeviceExtension->InterfaceListCount; PDODeviceExtension->ConfigurationHandle = FDODeviceExtension->ConfigurationHandle; @@ -423,9 +424,31 @@ FDO_HandlePnp( // get stack location IoStack = IoGetCurrentIrpStackLocation(Irp); - DPRINT1("[USBCCGP] PnP Minor %x\n", IoStack->MinorFunction); + DPRINT1("[USBCCGP] PnP Minor %x\n", IoStack->MinorFunction); switch(IoStack->MinorFunction) { + case IRP_MN_REMOVE_DEVICE: + { + /* Send the IRP down the stack */ + Status = USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp); + if (NT_SUCCESS(Status)) + { + // + // Detach from the device stack + // + IoDetachDevice(FDODeviceExtension->NextDeviceObject); + + // + // Delete the device object + // + IoDeleteDevice(DeviceObject); + } + + // + // request completed + // + break; + } case IRP_MN_START_DEVICE: { // diff --git a/drivers/usb/usbccgp/pdo.c b/drivers/usb/usbccgp/pdo.c index 22d06979ce2..9d7180dc666 100644 --- a/drivers/usb/usbccgp/pdo.c +++ b/drivers/usb/usbccgp/pdo.c @@ -307,6 +307,7 @@ PDO_HandlePnp( PIO_STACK_LOCATION IoStack; PPDO_DEVICE_EXTENSION PDODeviceExtension; NTSTATUS Status; + ULONG Index; // // get current stack location @@ -351,15 +352,31 @@ PDO_HandlePnp( } case IRP_MN_REMOVE_DEVICE: { - DPRINT1("IRP_MN_REMOVE_DEVICE\n"); + // + // remove us from the fdo's pdo list + // + for(Index = 0; Index < PDODeviceExtension->FDODeviceExtension->FunctionDescriptorCount; Index++) + { + if (PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] == DeviceObject) + { + // + // remove us + // + PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] = NULL; + break; + } + } - /* Complete the IRP */ + // + // Complete the IRP + // Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT); - /* Delete the device object */ + // + // Delete the device object + // IoDeleteDevice(DeviceObject); - return STATUS_SUCCESS; } case IRP_MN_QUERY_CAPABILITIES: diff --git a/drivers/usb/usbccgp/usbccgp.h b/drivers/usb/usbccgp/usbccgp.h index 04134fe4d54..55e08064612 100644 --- a/drivers/usb/usbccgp/usbccgp.h +++ b/drivers/usb/usbccgp/usbccgp.h @@ -55,6 +55,7 @@ typedef struct USBD_CONFIGURATION_HANDLE ConfigurationHandle; // configuration handle PUSBD_INTERFACE_LIST_ENTRY InterfaceList; // interface list ULONG InterfaceListCount; // interface list count + PFDO_DEVICE_EXTENSION FDODeviceExtension; // pointer to fdo's pdo list }PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION; /* descriptor.c */