[USBCCGP]

- Formatting, no code changes

svn path=/trunk/; revision=55847
This commit is contained in:
Johannes Anderwald 2012-02-25 00:35:40 +00:00
parent e188a743cb
commit 494fa29ffa
5 changed files with 221 additions and 427 deletions

View file

@ -18,14 +18,10 @@ FDO_QueryCapabilitiesCompletionRoutine(
IN PIRP Irp, IN PIRP Irp,
IN PVOID Context) IN PVOID Context)
{ {
// /* Set event */
// set event
//
KeSetEvent((PRKEVENT)Context, 0, FALSE); KeSetEvent((PRKEVENT)Context, 0, FALSE);
// /* Completion is done in the HidClassFDO_QueryCapabilities routine */
// completion is done in the HidClassFDO_QueryCapabilities routine
//
return STATUS_MORE_PROCESSING_REQUIRED; return STATUS_MORE_PROCESSING_REQUIRED;
} }
@ -40,85 +36,62 @@ FDO_QueryCapabilities(
PIO_STACK_LOCATION IoStack; PIO_STACK_LOCATION IoStack;
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
// /* Get device extension */
// get device extension
//
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(FDODeviceExtension->Common.IsFDO); ASSERT(FDODeviceExtension->Common.IsFDO);
// /* Init event */
// init event
//
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
// /* Now allocte the irp */
// now allocte the irp
//
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
if (!Irp) if (!Irp)
{ {
// /* No memory */
// no memory
//
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }
// /* Get next stack location */
// get next stack location
//
IoStack = IoGetNextIrpStackLocation(Irp); IoStack = IoGetNextIrpStackLocation(Irp);
// /* Init stack location */
// init stack location
//
IoStack->MajorFunction = IRP_MJ_PNP; IoStack->MajorFunction = IRP_MJ_PNP;
IoStack->MinorFunction = IRP_MN_QUERY_CAPABILITIES; IoStack->MinorFunction = IRP_MN_QUERY_CAPABILITIES;
IoStack->Parameters.DeviceCapabilities.Capabilities = Capabilities; IoStack->Parameters.DeviceCapabilities.Capabilities = Capabilities;
// /* Set completion routine */
// set completion routine IoSetCompletionRoutine(Irp,
// FDO_QueryCapabilitiesCompletionRoutine,
IoSetCompletionRoutine(Irp, FDO_QueryCapabilitiesCompletionRoutine, (PVOID)&Event, TRUE, TRUE, TRUE); (PVOID)&Event,
TRUE,
TRUE,
TRUE);
// /* Init capabilities */
// init capabilities
//
RtlZeroMemory(Capabilities, sizeof(DEVICE_CAPABILITIES)); RtlZeroMemory(Capabilities, sizeof(DEVICE_CAPABILITIES));
Capabilities->Size = sizeof(DEVICE_CAPABILITIES); Capabilities->Size = sizeof(DEVICE_CAPABILITIES);
Capabilities->Version = 1; // FIXME hardcoded constant Capabilities->Version = 1; // FIXME hardcoded constant
Capabilities->Address = MAXULONG; Capabilities->Address = MAXULONG;
Capabilities->UINumber = MAXULONG; Capabilities->UINumber = MAXULONG;
// /* Pnp irps have default completion code */
// pnp irps have default completion code
//
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
// /* Call lower device */
// call lower device
//
Status = IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp); Status = IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
if (Status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
// /* Wait for completion */
// wait for completion
//
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
} }
// /* Get status */
// get status
//
Status = Irp->IoStatus.Status; Status = Irp->IoStatus.Status;
// /* Complete request */
// complete request
//
IoFreeIrp(Irp); IoFreeIrp(Irp);
// /* Done */
// done
//
return Status; return Status;
} }
@ -133,85 +106,58 @@ FDO_DeviceRelations(
PIO_STACK_LOCATION IoStack; PIO_STACK_LOCATION IoStack;
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
// /* Get device extension */
// get device extension
//
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
// /* Get current irp stack location */
// get current irp stack location
//
IoStack = IoGetCurrentIrpStackLocation(Irp); IoStack = IoGetCurrentIrpStackLocation(Irp);
// /* Check if relation type is BusRelations */
// check if relation type is BusRelations
//
if (IoStack->Parameters.QueryDeviceRelations.Type != BusRelations) if (IoStack->Parameters.QueryDeviceRelations.Type != BusRelations)
{ {
// /* FDO always only handles bus relations */
// FDO always only handles bus relations
//
return USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp); return USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp);
} }
// /* Go through array and count device objects */
// go through array and count device objects
//
for(Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++) for(Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++)
{ {
if (FDODeviceExtension->ChildPDO[Index]) if (FDODeviceExtension->ChildPDO[Index])
{ {
// /* Child pdo */
// child pdo
//
DeviceCount++; DeviceCount++;
} }
} }
// /* Allocate device relations */
// allocate device relations DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool,
// sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0));
DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0));
if (!DeviceRelations) if (!DeviceRelations)
{ {
// /* No memory */
// no memory
//
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }
// /* Add device objects */
// add device objects
//
for(Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++) for(Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++)
{ {
if (FDODeviceExtension->ChildPDO[Index]) if (FDODeviceExtension->ChildPDO[Index])
{ {
// /* Store child pdo */
// store child pdo
//
DeviceRelations->Objects[DeviceRelations->Count] = FDODeviceExtension->ChildPDO[Index]; DeviceRelations->Objects[DeviceRelations->Count] = FDODeviceExtension->ChildPDO[Index];
// /* Add reference */
// add reference
//
ObReferenceObject(FDODeviceExtension->ChildPDO[Index]); ObReferenceObject(FDODeviceExtension->ChildPDO[Index]);
// /* Increment count */
// increment count
//
DeviceRelations->Count++; DeviceRelations->Count++;
} }
} }
// /* Store result */
// store result
//
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations; Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
// /* Request completed successfully */
// request completed successfully
//
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -225,56 +171,45 @@ FDO_CreateChildPdo(
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
ULONG Index; ULONG Index;
// /* Get device extension */
// get device extension
//
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(FDODeviceExtension->Common.IsFDO); ASSERT(FDODeviceExtension->Common.IsFDO);
// /* Lets create array for the child PDO */
// lets create array for the child PDO FDODeviceExtension->ChildPDO = AllocateItem(NonPagedPool,
// sizeof(PDEVICE_OBJECT) * FDODeviceExtension->FunctionDescriptorCount);
FDODeviceExtension->ChildPDO = AllocateItem(NonPagedPool, sizeof(PDEVICE_OBJECT) * FDODeviceExtension->FunctionDescriptorCount);
if (!FDODeviceExtension->ChildPDO) if (!FDODeviceExtension->ChildPDO)
{ {
// /* No memory */
// no memory
//
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }
// /* Create pdo for each function */
// create pdo for each function
//
for(Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++) for(Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++)
{ {
// /* Create the PDO */
// create the PDO Status = IoCreateDevice(FDODeviceExtension->DriverObject,
// sizeof(PDO_DEVICE_EXTENSION),
Status = IoCreateDevice(FDODeviceExtension->DriverObject, sizeof(PDO_DEVICE_EXTENSION), NULL, FILE_DEVICE_USB, FILE_AUTOGENERATED_DEVICE_NAME, FALSE, &PDODeviceObject); NULL,
FILE_DEVICE_USB,
FILE_AUTOGENERATED_DEVICE_NAME,
FALSE,
&PDODeviceObject);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// /* Failed to create device object */
// failed to create device object
//
DPRINT1("IoCreateDevice failed with %x\n", Status); DPRINT1("IoCreateDevice failed with %x\n", Status);
return Status; return Status;
} }
// /* Store in array */
// store in array
//
FDODeviceExtension->ChildPDO[Index] = PDODeviceObject; FDODeviceExtension->ChildPDO[Index] = PDODeviceObject;
// /* Get device extension */
// get device extension
//
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension; PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension;
RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION)); RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
// /* Init device extension */
// init device extension
//
PDODeviceExtension->Common.IsFDO = FALSE; PDODeviceExtension->Common.IsFDO = FALSE;
PDODeviceExtension->FunctionDescriptor = &FDODeviceExtension->FunctionDescriptor[Index]; PDODeviceExtension->FunctionDescriptor = &FDODeviceExtension->FunctionDescriptor[Index];
PDODeviceExtension->NextDeviceObject = DeviceObject; PDODeviceExtension->NextDeviceObject = DeviceObject;
@ -287,25 +222,17 @@ FDO_CreateChildPdo(
RtlCopyMemory(&PDODeviceExtension->Capabilities, &FDODeviceExtension->Capabilities, sizeof(DEVICE_CAPABILITIES)); RtlCopyMemory(&PDODeviceExtension->Capabilities, &FDODeviceExtension->Capabilities, sizeof(DEVICE_CAPABILITIES));
RtlCopyMemory(&PDODeviceExtension->DeviceDescriptor, &FDODeviceExtension->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR)); RtlCopyMemory(&PDODeviceExtension->DeviceDescriptor, &FDODeviceExtension->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR));
// /* Patch the stack size */
// patch the stack size
//
PDODeviceObject->StackSize = DeviceObject->StackSize + 1; PDODeviceObject->StackSize = DeviceObject->StackSize + 1;
// /* Set device flags */
// set device flags
//
PDODeviceObject->Flags |= DO_DIRECT_IO | DO_MAP_IO_BUFFER; PDODeviceObject->Flags |= DO_DIRECT_IO | DO_MAP_IO_BUFFER;
// /* Device is initialized */
// device is initialized
//
PDODeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; PDODeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
} }
// /* Done */
// done
//
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -317,93 +244,81 @@ FDO_StartDevice(
NTSTATUS Status; NTSTATUS Status;
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
// /* Get device extension */
// get device extension
//
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(FDODeviceExtension->Common.IsFDO); ASSERT(FDODeviceExtension->Common.IsFDO);
// /* First start lower device */
// first start lower device
//
Status = USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp); Status = USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// /* Failed to start lower device */
// failed to start lower device
//
DPRINT1("FDO_StartDevice lower device failed to start with %x\n", Status); DPRINT1("FDO_StartDevice lower device failed to start with %x\n", Status);
return Status; return Status;
} }
// get descriptors /* Get descriptors */
Status = USBCCGP_GetDescriptors(DeviceObject); Status = USBCCGP_GetDescriptors(DeviceObject);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// failed to start lower device /* Failed to start lower device */
DPRINT1("FDO_StartDevice failed to get descriptors with %x\n", Status); DPRINT1("FDO_StartDevice failed to get descriptors with %x\n", Status);
return Status; return Status;
} }
// get capabilities /* Get capabilities */
Status = FDO_QueryCapabilities(DeviceObject, &FDODeviceExtension->Capabilities); Status = FDO_QueryCapabilities(DeviceObject,
&FDODeviceExtension->Capabilities);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// failed to start lower device /* Failed to start lower device */
DPRINT1("FDO_StartDevice failed to get capabilities with %x\n", Status); DPRINT1("FDO_StartDevice failed to get capabilities with %x\n", Status);
return Status; return Status;
} }
// now select the configuration /* Now select the configuration */
Status = USBCCGP_SelectConfiguration(DeviceObject, FDODeviceExtension); Status = USBCCGP_SelectConfiguration(DeviceObject, FDODeviceExtension);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// failed to select interface /* Failed to select interface */
DPRINT1("FDO_StartDevice failed to get capabilities with %x\n", Status); DPRINT1("FDO_StartDevice failed to get capabilities with %x\n", Status);
return Status; return Status;
} }
// query bus interface /* Query bus interface */
USBCCGP_QueryInterface(FDODeviceExtension->NextDeviceObject, &FDODeviceExtension->BusInterface); USBCCGP_QueryInterface(FDODeviceExtension->NextDeviceObject,
&FDODeviceExtension->BusInterface);
// now enumerate the functions /* Now enumerate the functions */
Status = USBCCGP_EnumerateFunctions(DeviceObject); Status = USBCCGP_EnumerateFunctions(DeviceObject);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// failed to enumerate functions /* Failed to enumerate functions */
DPRINT1("Failed to enumerate functions with %x\n", Status); DPRINT1("Failed to enumerate functions with %x\n", Status);
return Status; return Status;
} }
// /* Sanity checks */
// sanity checks
//
ASSERT(FDODeviceExtension->FunctionDescriptorCount); ASSERT(FDODeviceExtension->FunctionDescriptorCount);
ASSERT(FDODeviceExtension->FunctionDescriptor); ASSERT(FDODeviceExtension->FunctionDescriptor);
DumpFunctionDescriptor(FDODeviceExtension->FunctionDescriptor, FDODeviceExtension->FunctionDescriptorCount); DumpFunctionDescriptor(FDODeviceExtension->FunctionDescriptor,
FDODeviceExtension->FunctionDescriptorCount);
// /* Now create the pdo */
// now create the pdo
//
Status = FDO_CreateChildPdo(DeviceObject); Status = FDO_CreateChildPdo(DeviceObject);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// /* Failed */
// failed
//
DPRINT1("FDO_CreateChildPdo failed with %x\n", Status); DPRINT1("FDO_CreateChildPdo failed with %x\n", Status);
return Status; return Status;
} }
// /* Inform pnp manager of new device objects */
// inform pnp manager of new device objects IoInvalidateDeviceRelations(FDODeviceExtension->PhysicalDeviceObject,
// BusRelations);
IoInvalidateDeviceRelations(FDODeviceExtension->PhysicalDeviceObject, BusRelations);
// /* Done */
// done
//
DPRINT("[USBCCGP] FDO initialized successfully\n"); DPRINT("[USBCCGP] FDO initialized successfully\n");
return Status; return Status;
} }
@ -416,36 +331,27 @@ FDO_CloseConfiguration(
PURB Urb; PURB Urb;
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
// get device extension /* Get device extension */
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(FDODeviceExtension->Common.IsFDO); ASSERT(FDODeviceExtension->Common.IsFDO);
// /* Now allocate the urb */
// now allocate the urb Urb = USBD_CreateConfigurationRequestEx(FDODeviceExtension->ConfigurationDescriptor,
// FDODeviceExtension->InterfaceList);
Urb = USBD_CreateConfigurationRequestEx(FDODeviceExtension->ConfigurationDescriptor, FDODeviceExtension->InterfaceList);
if (!Urb) if (!Urb)
{ {
// /* No memory */
// no memory
//
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }
// /* Clear configuration descriptor to make it an unconfigure request */
// clear configuration descriptor to make it an unconfigure request
//
Urb->UrbSelectConfiguration.ConfigurationDescriptor = NULL; Urb->UrbSelectConfiguration.ConfigurationDescriptor = NULL;
// /* Submit urb */
// submit urb
//
Status = USBCCGP_SyncUrbRequest(FDODeviceExtension->NextDeviceObject, Urb); Status = USBCCGP_SyncUrbRequest(FDODeviceExtension->NextDeviceObject, Urb);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// /* Failed to set configuration */
// failed to set configuration
//
DPRINT1("USBCCGP_SyncUrbRequest failed to unconfigure device\n", Status); DPRINT1("USBCCGP_SyncUrbRequest failed to unconfigure device\n", Status);
} }
@ -463,72 +369,59 @@ FDO_HandlePnp(
NTSTATUS Status; NTSTATUS Status;
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
// get device extension /* Get device extension */
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(FDODeviceExtension->Common.IsFDO); ASSERT(FDODeviceExtension->Common.IsFDO);
// get stack location /* Get stack location */
IoStack = IoGetCurrentIrpStackLocation(Irp); IoStack = IoGetCurrentIrpStackLocation(Irp);
DPRINT("[USBCCGP] PnP Minor %x\n", IoStack->MinorFunction); DPRINT("[USBCCGP] PnP Minor %x\n", IoStack->MinorFunction);
switch(IoStack->MinorFunction) switch(IoStack->MinorFunction)
{ {
case IRP_MN_REMOVE_DEVICE: case IRP_MN_REMOVE_DEVICE:
{ {
// // Unconfigure device */
// unconfigure device
//
DPRINT1("[USBCCGP] FDO IRP_MN_REMOVE\n"); DPRINT1("[USBCCGP] FDO IRP_MN_REMOVE\n");
FDO_CloseConfiguration(DeviceObject); FDO_CloseConfiguration(DeviceObject);
/* Send the IRP down the stack */ /* Send the IRP down the stack */
Status = USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp); Status = USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject,
Irp);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
// /* Detach from the device stack */
// Detach from the device stack
//
IoDetachDevice(FDODeviceExtension->NextDeviceObject); IoDetachDevice(FDODeviceExtension->NextDeviceObject);
// /* Delete the device object */
// Delete the device object
//
IoDeleteDevice(DeviceObject); IoDeleteDevice(DeviceObject);
} }
// /* Request completed */
// request completed
//
break; break;
} }
case IRP_MN_START_DEVICE: case IRP_MN_START_DEVICE:
{ {
// /* Start the device */
// start the device
//
Status = FDO_StartDevice(DeviceObject, Irp); Status = FDO_StartDevice(DeviceObject, Irp);
break; break;
} }
case IRP_MN_QUERY_DEVICE_RELATIONS: case IRP_MN_QUERY_DEVICE_RELATIONS:
{ {
// /* Handle device relations */
// handle device relations
//
Status = FDO_DeviceRelations(DeviceObject, Irp); Status = FDO_DeviceRelations(DeviceObject, Irp);
break; break;
} }
case IRP_MN_QUERY_CAPABILITIES: case IRP_MN_QUERY_CAPABILITIES:
{ {
// /* Copy capabilities */
// copy capabilities RtlCopyMemory(IoStack->Parameters.DeviceCapabilities.Capabilities,
// &FDODeviceExtension->Capabilities,
RtlCopyMemory(IoStack->Parameters.DeviceCapabilities.Capabilities, &FDODeviceExtension->Capabilities, sizeof(DEVICE_CAPABILITIES)); sizeof(DEVICE_CAPABILITIES));
Status = USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp); Status = USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
// /* Surprise removal ok */
// surprise removal ok
//
IoStack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE; IoStack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE;
} }
break; break;
@ -536,31 +429,23 @@ FDO_HandlePnp(
case IRP_MN_QUERY_REMOVE_DEVICE: case IRP_MN_QUERY_REMOVE_DEVICE:
case IRP_MN_QUERY_STOP_DEVICE: case IRP_MN_QUERY_STOP_DEVICE:
{ {
// /* Sure */
// sure
//
Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Status = STATUS_SUCCESS;
// /* Forward irp to next device object */
// forward irp to next device object
//
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp); return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
} }
default: default:
{ {
// /* Forward irp to next device object */
// forward irp to next device object
//
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp); return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
} }
} }
// /* Complete request */
// complete request
//
Irp->IoStatus.Status = Status; Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT); IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status; return Status;
@ -580,86 +465,60 @@ FDO_HandleResetCyclePort(
PIRP ListIrp; PIRP ListIrp;
KIRQL OldLevel; KIRQL OldLevel;
// /* Get device extension */
// get device extension
//
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(FDODeviceExtension->Common.IsFDO); ASSERT(FDODeviceExtension->Common.IsFDO);
// get stack location /* Get stack location */
IoStack = IoGetCurrentIrpStackLocation(Irp); IoStack = IoGetCurrentIrpStackLocation(Irp);
DPRINT("FDO_HandleResetCyclePort IOCTL %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode); DPRINT("FDO_HandleResetCyclePort IOCTL %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT) if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT)
{ {
// /* Use reset port list */
// use reset port list
//
ListHead = &FDODeviceExtension->ResetPortListHead; ListHead = &FDODeviceExtension->ResetPortListHead;
ResetActive = &FDODeviceExtension->ResetPortActive; ResetActive = &FDODeviceExtension->ResetPortActive;
} }
else else
{ {
// /* Use cycle port list */
// use cycle port list
//
ListHead = &FDODeviceExtension->CyclePortListHead; ListHead = &FDODeviceExtension->CyclePortListHead;
ResetActive = &FDODeviceExtension->CyclePortActive; ResetActive = &FDODeviceExtension->CyclePortActive;
} }
// /* Acquire lock */
// acquire lock
//
KeAcquireSpinLock(&FDODeviceExtension->Lock, &OldLevel); KeAcquireSpinLock(&FDODeviceExtension->Lock, &OldLevel);
if (*ResetActive) if (*ResetActive)
{ {
// /* Insert into pending list */
// insert into pending list
//
InsertTailList(ListHead, &Irp->Tail.Overlay.ListEntry); InsertTailList(ListHead, &Irp->Tail.Overlay.ListEntry);
// /* Mark irp pending */
// mark irp pending
//
IoMarkIrpPending(Irp); IoMarkIrpPending(Irp);
Status = STATUS_PENDING; Status = STATUS_PENDING;
// /* Release lock */
// release lock
//
KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel); KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
} }
else else
{ {
// /* Mark reset active */
// mark reset active
//
*ResetActive = TRUE; *ResetActive = TRUE;
// /* Release lock */
// release lock
//
KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel); KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
// /* Forward request synchronized */
// forward request synchronized
//
USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp); USBCCGP_SyncForwardIrp(FDODeviceExtension->NextDeviceObject, Irp);
// /* Reacquire lock */
// reacquire lock
//
KeAcquireSpinLock(&FDODeviceExtension->Lock, &OldLevel); KeAcquireSpinLock(&FDODeviceExtension->Lock, &OldLevel);
// /* Mark reset as completed */
// mark reset as completed
//
*ResetActive = FALSE; *ResetActive = FALSE;
// /* Move all requests into temporary list */
// move all requests into temporary list
//
InitializeListHead(&TempList); InitializeListHead(&TempList);
while(!IsListEmpty(ListHead)) while(!IsListEmpty(ListHead))
{ {
@ -667,29 +526,21 @@ FDO_HandleResetCyclePort(
InsertTailList(&TempList, Entry); InsertTailList(&TempList, Entry);
} }
// /* Release lock */
// release lock
//
KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel); KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
// /* Complete pending irps */
// complete pending irps
//
while(!IsListEmpty(&TempList)) while(!IsListEmpty(&TempList))
{ {
Entry = RemoveHeadList(&TempList); Entry = RemoveHeadList(&TempList);
ListIrp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry); ListIrp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
// /* Complete request with status success */
// complete request with status success
//
Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NO_INCREMENT); IoCompleteRequest(Irp, IO_NO_INCREMENT);
} }
// /* Status success */
// status success
//
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }
@ -707,37 +558,29 @@ FDO_HandleInternalDeviceControl(
NTSTATUS Status; NTSTATUS Status;
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
// /* Get device extension */
// get device extension
//
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
ASSERT(FDODeviceExtension->Common.IsFDO); ASSERT(FDODeviceExtension->Common.IsFDO);
// get stack location /* Get stack location */
IoStack = IoGetCurrentIrpStackLocation(Irp); IoStack = IoGetCurrentIrpStackLocation(Irp);
if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT || if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT ||
IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_CYCLE_PORT) IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_CYCLE_PORT)
{ {
// /* Handle reset / cycle ports */
// handle reset / cycle ports
//
Status = FDO_HandleResetCyclePort(DeviceObject, Irp); Status = FDO_HandleResetCyclePort(DeviceObject, Irp);
DPRINT("FDO_HandleResetCyclePort Status %x\n", Status); DPRINT("FDO_HandleResetCyclePort Status %x\n", Status);
if (Status != STATUS_PENDING) if (Status != STATUS_PENDING)
{ {
// /* Complete request */
// complete request
//
Irp->IoStatus.Status = Status; Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT); IoCompleteRequest(Irp, IO_NO_INCREMENT);
} }
return Status; return Status;
} }
// /* Forward and forget request */
// forward and forget request
//
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp); return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
} }
@ -750,7 +593,7 @@ FDO_Dispatch(
PIO_STACK_LOCATION IoStack; PIO_STACK_LOCATION IoStack;
NTSTATUS Status; NTSTATUS Status;
/* get stack location */ /* Get stack location */
IoStack = IoGetCurrentIrpStackLocation(Irp); IoStack = IoGetCurrentIrpStackLocation(Irp);
switch(IoStack->MajorFunction) switch(IoStack->MajorFunction)
@ -768,5 +611,3 @@ FDO_Dispatch(
} }
} }

View file

@ -22,26 +22,18 @@ USBCCGP_QueryInterface(
IO_STATUS_BLOCK IoStatus; IO_STATUS_BLOCK IoStatus;
PIO_STACK_LOCATION Stack; PIO_STACK_LOCATION Stack;
// /* Sanity checks */
// sanity checks
//
ASSERT(DeviceObject); ASSERT(DeviceObject);
// /* Initialize event */
// initialize event
//
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
// /* Init interface */
// init interface
//
RtlZeroMemory(BusInterface, sizeof(USBC_DEVICE_CONFIGURATION_INTERFACE_V1)); RtlZeroMemory(BusInterface, sizeof(USBC_DEVICE_CONFIGURATION_INTERFACE_V1));
BusInterface->Version = USBC_DEVICE_CONFIGURATION_INTERFACE_VERSION_1; BusInterface->Version = USBC_DEVICE_CONFIGURATION_INTERFACE_VERSION_1;
BusInterface->Size = sizeof(USBC_DEVICE_CONFIGURATION_INTERFACE_V1); BusInterface->Size = sizeof(USBC_DEVICE_CONFIGURATION_INTERFACE_V1);
// /* Create irp */
// create irp
//
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP, Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
DeviceObject, DeviceObject,
NULL, NULL,
@ -366,10 +358,10 @@ USBCCGP_InitFunctionDescriptor(
// get interface description // get interface description
// //
Status = USBCCGP_GetStringDescriptor(FDODeviceExtension->NextDeviceObject, Status = USBCCGP_GetStringDescriptor(FDODeviceExtension->NextDeviceObject,
100 * sizeof(WCHAR), 100 * sizeof(WCHAR),
Descriptor->iFunction, Descriptor->iFunction,
0x0409, //FIXME 0x0409, //FIXME
(PVOID*)&DescriptionBuffer); (PVOID*)&DescriptionBuffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// //
@ -530,10 +522,10 @@ USBCCG_InitIdsWithInterfaceDescriptor(
// get interface description // get interface description
// //
Status = USBCCGP_GetStringDescriptor(FDODeviceExtension->NextDeviceObject, Status = USBCCGP_GetStringDescriptor(FDODeviceExtension->NextDeviceObject,
100 * sizeof(WCHAR), 100 * sizeof(WCHAR),
Descriptor->iInterface, Descriptor->iInterface,
0x0409, //FIXME 0x0409, //FIXME
(PVOID*)&DescriptionBuffer); (PVOID*)&DescriptionBuffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// //

View file

@ -11,9 +11,7 @@
#include "usbccgp.h" #include "usbccgp.h"
// /* Driver verifier */
// driver verifier
//
IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine; IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine;
NTSTATUS NTSTATUS
@ -39,46 +37,34 @@ USBCCGP_SyncForwardIrp(
KEVENT Event; KEVENT Event;
NTSTATUS Status; NTSTATUS Status;
// /* Initialize event */
// initialize event
//
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
// /* Copy irp stack location */
// copy irp stack location
//
IoCopyCurrentIrpStackLocationToNext(Irp); IoCopyCurrentIrpStackLocationToNext(Irp);
// /* Set completion routine */
// set completion routine IoSetCompletionRoutine(Irp,
// USBSTOR_SyncForwardIrpCompletionRoutine,
IoSetCompletionRoutine(Irp, USBSTOR_SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE); &Event,
TRUE,
TRUE,
TRUE);
/* Call driver */
//
// call driver
//
Status = IoCallDriver(DeviceObject, Irp); Status = IoCallDriver(DeviceObject, Irp);
// /* Check if pending */
// check if pending
//
if (Status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
// /* Wait for the request to finish */
// wait for the request to finish
//
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
// /* Copy status code */
// copy status code
//
Status = Irp->IoStatus.Status; Status = Irp->IoStatus.Status;
} }
// /* Done */
// done
//
return Status; return Status;
} }
@ -92,72 +78,52 @@ USBCCGP_SyncUrbRequest(
KEVENT Event; KEVENT Event;
NTSTATUS Status; NTSTATUS Status;
// /* Allocate irp */
// allocate irp
//
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
if (!Irp) if (!Irp)
{ {
// /* No memory */
// no memory
//
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }
// /* Initialize event */
// initialize event
//
KeInitializeEvent(&Event, NotificationEvent, FALSE); KeInitializeEvent(&Event, NotificationEvent, FALSE);
/* Get next stack location */
//
// get next stack location
//
IoStack = IoGetNextIrpStackLocation(Irp); IoStack = IoGetNextIrpStackLocation(Irp);
// /* Initialize stack location */
// initialize stack location
//
IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB; IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest; IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length; IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Status = STATUS_SUCCESS;
// /* Setup completion routine */
// setup completion routine IoSetCompletionRoutine(Irp,
// USBSTOR_SyncForwardIrpCompletionRoutine,
IoSetCompletionRoutine(Irp, USBSTOR_SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE); &Event,
TRUE,
TRUE,
TRUE);
// /* Call driver */
// call driver
//
Status = IoCallDriver(DeviceObject, Irp); Status = IoCallDriver(DeviceObject, Irp);
// /* Check if request is pending */
// check if request is pending
//
if (Status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
// /* Wait for completion */
// wait for completion
//
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
// /* Update status */
// update status
//
Status = Irp->IoStatus.Status; Status = Irp->IoStatus.Status;
} }
// /* Free irp */
// free irp
//
IoFreeIrp(Irp); IoFreeIrp(Irp);
// /* Done */
// done
//
return Status; return Status;
} }
@ -166,22 +132,16 @@ AllocateItem(
IN POOL_TYPE PoolType, IN POOL_TYPE PoolType,
IN ULONG ItemSize) IN ULONG ItemSize)
{ {
// /* Allocate item */
// allocate item
//
PVOID Item = ExAllocatePoolWithTag(PoolType, ItemSize, USBCCPG_TAG); PVOID Item = ExAllocatePoolWithTag(PoolType, ItemSize, USBCCPG_TAG);
if (Item) if (Item)
{ {
// /* Zero item */
// zero item
//
RtlZeroMemory(Item, ItemSize); RtlZeroMemory(Item, ItemSize);
} }
// /* Return element */
// return element
//
return Item; return Item;
} }
@ -189,9 +149,7 @@ VOID
FreeItem( FreeItem(
IN PVOID Item) IN PVOID Item)
{ {
// /* Free item */
// free item
//
ExFreePoolWithTag(Item, USBCCPG_TAG); ExFreePoolWithTag(Item, USBCCPG_TAG);
} }

View file

@ -11,9 +11,7 @@
#include "usbccgp.h" #include "usbccgp.h"
// /* Driver verifier */
// driver verifier
//
DRIVER_ADD_DEVICE USBCCGP_AddDevice; DRIVER_ADD_DEVICE USBCCGP_AddDevice;
NTSTATUS NTSTATUS
@ -26,19 +24,25 @@ USBCCGP_AddDevice(
PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT DeviceObject;
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
// lets create the device /* Lets create the device */
Status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_EXTENSION), NULL, FILE_DEVICE_USB, FILE_AUTOGENERATED_DEVICE_NAME, FALSE, &DeviceObject); Status = IoCreateDevice(DriverObject,
sizeof(FDO_DEVICE_EXTENSION),
NULL,
FILE_DEVICE_USB,
FILE_AUTOGENERATED_DEVICE_NAME,
FALSE,
&DeviceObject);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
// failed to create device /* Failed to create device */
DPRINT1("USBCCGP_AddDevice failed to create device with %x\n", Status); DPRINT1("USBCCGP_AddDevice failed to create device with %x\n", Status);
return Status; return Status;
} }
// get device extension /* Get device extension */
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
// init device extension /* Init device extension */
RtlZeroMemory(FDODeviceExtension, sizeof(FDO_DEVICE_EXTENSION)); RtlZeroMemory(FDODeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
FDODeviceExtension->Common.IsFDO = TRUE; FDODeviceExtension->Common.IsFDO = TRUE;
FDODeviceExtension->DriverObject = DriverObject; FDODeviceExtension->DriverObject = DriverObject;
@ -47,22 +51,23 @@ USBCCGP_AddDevice(
InitializeListHead(&FDODeviceExtension->CyclePortListHead); InitializeListHead(&FDODeviceExtension->CyclePortListHead);
KeInitializeSpinLock(&FDODeviceExtension->Lock); KeInitializeSpinLock(&FDODeviceExtension->Lock);
FDODeviceExtension->NextDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject); FDODeviceExtension->NextDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject,
PhysicalDeviceObject);
if (!FDODeviceExtension->NextDeviceObject) if (!FDODeviceExtension->NextDeviceObject)
{ {
// failed to attach /* Failed to attach */
DPRINT1("USBCCGP_AddDevice failed to attach device\n"); DPRINT1("USBCCGP_AddDevice failed to attach device\n");
IoDeleteDevice(DeviceObject); IoDeleteDevice(DeviceObject);
return STATUS_DEVICE_REMOVED; return STATUS_DEVICE_REMOVED;
} }
// set device flags /* Set device flags */
DeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE; DeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
// device is initialized /* Device is initialized */
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
// device initialized /* Device initialized */
return Status; return Status;
} }
@ -75,24 +80,24 @@ USBCCGP_CreateClose(
PCOMMON_DEVICE_EXTENSION DeviceExtension; PCOMMON_DEVICE_EXTENSION DeviceExtension;
PFDO_DEVICE_EXTENSION FDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension;
// get common device extension /* Get common device extension */
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension; DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
// is it a fdo /* Is it a fdo */
if (DeviceExtension->IsFDO) if (DeviceExtension->IsFDO)
{ {
// forward and forget /* Forward and forget */
IoSkipCurrentIrpStackLocation(Irp); IoSkipCurrentIrpStackLocation(Irp);
// get fdo /* Get fdo */
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
// call lower driver /* Call lower driver */
return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp); return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
} }
else else
{ {
// pdo not supported /* Pdo not supported */
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
IoCompleteRequest(Irp, IO_NO_INCREMENT); IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_NOT_SUPPORTED; return STATUS_NOT_SUPPORTED;
@ -108,26 +113,26 @@ USBCCGP_Dispatch(
PCOMMON_DEVICE_EXTENSION DeviceExtension; PCOMMON_DEVICE_EXTENSION DeviceExtension;
PIO_STACK_LOCATION IoStack; PIO_STACK_LOCATION IoStack;
// get common device extension /* Get common device extension */
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension; DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
// get current stack location /* Get current stack location */
IoStack = IoGetCurrentIrpStackLocation(Irp); IoStack = IoGetCurrentIrpStackLocation(Irp);
if (IoStack->MajorFunction == IRP_MJ_CREATE || IoStack->MajorFunction == IRP_MJ_CLOSE) if (IoStack->MajorFunction == IRP_MJ_CREATE || IoStack->MajorFunction == IRP_MJ_CLOSE)
{ {
// dispatch to default handler /* Dispatch to default handler */
return USBCCGP_CreateClose(DeviceObject, Irp); return USBCCGP_CreateClose(DeviceObject, Irp);
} }
if (DeviceExtension->IsFDO) if (DeviceExtension->IsFDO)
{ {
// handle request for FDO /* Handle request for FDO */
return FDO_Dispatch(DeviceObject, Irp); return FDO_Dispatch(DeviceObject, Irp);
} }
else else
{ {
// handle request for PDO /* Handle request for PDO */
return PDO_Dispatch(DeviceObject, Irp); return PDO_Dispatch(DeviceObject, Irp);
} }
} }
@ -139,7 +144,7 @@ DriverEntry(
PUNICODE_STRING RegistryPath) PUNICODE_STRING RegistryPath)
{ {
// initialize driver object /* Initialize driver object */
DPRINT("[USBCCGP] DriverEntry\n"); DPRINT("[USBCCGP] DriverEntry\n");
DriverObject->DriverExtension->AddDevice = USBCCGP_AddDevice; DriverObject->DriverExtension->AddDevice = USBCCGP_AddDevice;
DriverObject->MajorFunction[IRP_MJ_CREATE] = USBCCGP_Dispatch; DriverObject->MajorFunction[IRP_MJ_CREATE] = USBCCGP_Dispatch;
@ -149,7 +154,7 @@ DriverEntry(
DriverObject->MajorFunction[IRP_MJ_POWER] = USBCCGP_Dispatch; DriverObject->MajorFunction[IRP_MJ_POWER] = USBCCGP_Dispatch;
DriverObject->MajorFunction[IRP_MJ_PNP] = USBCCGP_Dispatch; DriverObject->MajorFunction[IRP_MJ_PNP] = USBCCGP_Dispatch;
// FIMXE query GenericCompositeUSBDeviceString /* FIMXE query GenericCompositeUSBDeviceString */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }

View file

@ -10,17 +10,16 @@
#include <usbioctl.h> #include <usbioctl.h>
#include <usbdlib.h> #include <usbdlib.h>
// /* FIXME:
// FIXME: #include <usbprotocoldefs.h> */
// #include <usbprotocoldefs.h>
//
#include <usb.h> #include <usb.h>
#include <stdio.h> #include <stdio.h>
#include <wdmguid.h> #include <wdmguid.h>
typedef struct typedef struct
{ {
BOOLEAN IsFDO; // is device a FDO or PDO BOOLEAN IsFDO; // is device a FDO or PDO
}COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION; }COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
typedef struct typedef struct
@ -60,10 +59,9 @@ typedef struct
USBD_CONFIGURATION_HANDLE ConfigurationHandle; // configuration handle USBD_CONFIGURATION_HANDLE ConfigurationHandle; // configuration handle
PUSBD_INTERFACE_LIST_ENTRY InterfaceList; // interface list PUSBD_INTERFACE_LIST_ENTRY InterfaceList; // interface list
ULONG InterfaceListCount; // interface list count ULONG InterfaceListCount; // interface list count
PFDO_DEVICE_EXTENSION FDODeviceExtension; // pointer to fdo's pdo list PFDO_DEVICE_EXTENSION FDODeviceExtension; // pointer to fdo's pdo list
}PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION; }PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
/* descriptor.c */
NTSTATUS NTSTATUS
USBCCGP_GetDescriptors( USBCCGP_GetDescriptors(