2012-01-26 13:45:59 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: drivers/usb/usbccgp/misc.c
|
|
|
|
* PURPOSE: USB device driver.
|
|
|
|
* PROGRAMMERS:
|
|
|
|
* Michael Martin (michael.martin@reactos.org)
|
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
|
|
|
* Cameron Gutman
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "usbccgp.h"
|
|
|
|
|
2014-01-02 14:14:39 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Driver verifier */
|
2012-01-26 13:45:59 +00:00
|
|
|
IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine;
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_SyncForwardIrpCompletionRoutine(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
2012-05-28 10:49:44 +00:00
|
|
|
PIRP Irp,
|
2012-01-26 13:45:59 +00:00
|
|
|
PVOID Context)
|
|
|
|
{
|
|
|
|
if (Irp->PendingReturned)
|
|
|
|
{
|
|
|
|
KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
|
|
|
|
}
|
|
|
|
return STATUS_MORE_PROCESSING_REQUIRED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBCCGP_SyncForwardIrp(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
KEVENT Event;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Initialize event */
|
2012-01-26 13:45:59 +00:00
|
|
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Copy irp stack location */
|
2012-01-26 13:45:59 +00:00
|
|
|
IoCopyCurrentIrpStackLocationToNext(Irp);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Set completion routine */
|
|
|
|
IoSetCompletionRoutine(Irp,
|
|
|
|
USBSTOR_SyncForwardIrpCompletionRoutine,
|
|
|
|
&Event,
|
|
|
|
TRUE,
|
|
|
|
TRUE,
|
|
|
|
TRUE);
|
2012-01-26 13:45:59 +00:00
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Call driver */
|
2012-01-26 13:45:59 +00:00
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Check if pending */
|
2012-01-26 13:45:59 +00:00
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Wait for the request to finish */
|
2012-01-26 13:45:59 +00:00
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Copy status code */
|
2012-01-26 13:45:59 +00:00
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
}
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Done */
|
2012-01-26 13:45:59 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
USBCCGP_SyncUrbRequest(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
OUT PURB UrbRequest)
|
|
|
|
{
|
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
KEVENT Event;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Allocate irp */
|
2012-01-26 13:45:59 +00:00
|
|
|
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
|
|
|
|
if (!Irp)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* No memory */
|
2012-01-26 13:45:59 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Initialize event */
|
2012-01-26 13:45:59 +00:00
|
|
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Get next stack location */
|
2012-01-26 13:45:59 +00:00
|
|
|
IoStack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Initialize stack location */
|
2012-01-26 13:45:59 +00:00
|
|
|
IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
|
|
|
|
IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
|
|
|
|
IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
|
|
|
|
IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Setup completion routine */
|
|
|
|
IoSetCompletionRoutine(Irp,
|
|
|
|
USBSTOR_SyncForwardIrpCompletionRoutine,
|
|
|
|
&Event,
|
|
|
|
TRUE,
|
|
|
|
TRUE,
|
|
|
|
TRUE);
|
2012-01-26 13:45:59 +00:00
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Call driver */
|
2012-01-26 13:45:59 +00:00
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Check if request is pending */
|
2012-01-26 13:45:59 +00:00
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Wait for completion */
|
2012-01-26 13:45:59 +00:00
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Update status */
|
2012-01-26 13:45:59 +00:00
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
}
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Free irp */
|
2012-01-26 13:45:59 +00:00
|
|
|
IoFreeIrp(Irp);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Done */
|
2012-01-26 13:45:59 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
PVOID
|
|
|
|
AllocateItem(
|
|
|
|
IN POOL_TYPE PoolType,
|
|
|
|
IN ULONG ItemSize)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Allocate item */
|
2012-01-26 13:45:59 +00:00
|
|
|
PVOID Item = ExAllocatePoolWithTag(PoolType, ItemSize, USBCCPG_TAG);
|
|
|
|
|
|
|
|
if (Item)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Zero item */
|
2012-01-26 13:45:59 +00:00
|
|
|
RtlZeroMemory(Item, ItemSize);
|
|
|
|
}
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Return element */
|
2012-01-26 13:45:59 +00:00
|
|
|
return Item;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FreeItem(
|
|
|
|
IN PVOID Item)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Free item */
|
2012-01-26 13:45:59 +00:00
|
|
|
ExFreePoolWithTag(Item, USBCCPG_TAG);
|
|
|
|
}
|
|
|
|
|
2012-01-27 18:04:39 +00:00
|
|
|
VOID
|
|
|
|
DumpFunctionDescriptor(
|
|
|
|
IN PUSBC_FUNCTION_DESCRIPTOR FunctionDescriptor,
|
|
|
|
IN ULONG FunctionDescriptorCount)
|
|
|
|
{
|
2012-01-30 10:41:52 +00:00
|
|
|
ULONG Index, SubIndex;
|
2012-01-27 18:04:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
DPRINT1("FunctionCount %lu\n", FunctionDescriptorCount);
|
2012-05-28 10:49:44 +00:00
|
|
|
for (Index = 0; Index < FunctionDescriptorCount; Index++)
|
2012-01-27 18:04:39 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Function %lu\n", Index);
|
|
|
|
DPRINT1("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
|
2012-05-28 10:15:58 +00:00
|
|
|
DPRINT1("HardwareId %S\n", FunctionDescriptor[Index].HardwareId.Buffer);
|
|
|
|
DPRINT1("CompatibleId %S\n", FunctionDescriptor[Index].CompatibleId.Buffer);
|
2012-01-27 18:04:39 +00:00
|
|
|
DPRINT1("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
|
|
|
|
DPRINT1("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);
|
2012-01-30 10:41:52 +00:00
|
|
|
|
|
|
|
for(SubIndex = 0; SubIndex < FunctionDescriptor[Index].NumberOfInterfaces; SubIndex++)
|
|
|
|
{
|
2012-02-23 00:37:41 +00:00
|
|
|
DPRINT1(" Index %lu Interface %p\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]);
|
|
|
|
DPRINT1(" Index %lu Interface InterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
|
|
|
|
DPRINT1(" Index %lu Interface Alternate %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting );
|
|
|
|
DPRINT1(" Index %lu bLength %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bLength);
|
|
|
|
DPRINT1(" Index %lu bDescriptorType %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bDescriptorType);
|
|
|
|
DPRINT1(" Index %lu bInterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
|
|
|
|
DPRINT1(" Index %lu bAlternateSetting %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting);
|
|
|
|
DPRINT1(" Index %lu bNumEndpoints %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bNumEndpoints);
|
|
|
|
DPRINT1(" Index %lu bInterfaceClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceClass);
|
|
|
|
DPRINT1(" Index %lu bInterfaceSubClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceSubClass);
|
|
|
|
DPRINT1(" Index %lu bInterfaceProtocol %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceProtocol);
|
|
|
|
DPRINT1(" Index %lu iInterface %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->iInterface);
|
2012-01-30 10:41:52 +00:00
|
|
|
}
|
2012-01-27 18:04:39 +00:00
|
|
|
}
|
2014-02-03 10:50:41 +00:00
|
|
|
}
|