2012-01-26 03:42:56 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2012-01-26 13:45:59 +00:00
|
|
|
* FILE: drivers/usb/usbccgp/usbccgp.c
|
2012-01-26 03:42:56 +00:00
|
|
|
* 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 03:42:56 +00:00
|
|
|
DRIVER_ADD_DEVICE USBCCGP_AddDevice;
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBCCGP_AddDevice(
|
|
|
|
PDRIVER_OBJECT DriverObject,
|
|
|
|
PDEVICE_OBJECT PhysicalDeviceObject)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Lets create the device */
|
|
|
|
Status = IoCreateDevice(DriverObject,
|
|
|
|
sizeof(FDO_DEVICE_EXTENSION),
|
|
|
|
NULL,
|
|
|
|
FILE_DEVICE_USB,
|
|
|
|
FILE_AUTOGENERATED_DEVICE_NAME,
|
|
|
|
FALSE,
|
|
|
|
&DeviceObject);
|
2012-01-26 03:42:56 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Failed to create device */
|
2012-01-26 03:42:56 +00:00
|
|
|
DPRINT1("USBCCGP_AddDevice failed to create device with %x\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Get device extension */
|
2012-01-26 03:42:56 +00:00
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Init device extension */
|
2012-01-26 03:42:56 +00:00
|
|
|
RtlZeroMemory(FDODeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
|
|
|
|
FDODeviceExtension->Common.IsFDO = TRUE;
|
|
|
|
FDODeviceExtension->DriverObject = DriverObject;
|
|
|
|
FDODeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
|
2012-02-03 16:03:42 +00:00
|
|
|
InitializeListHead(&FDODeviceExtension->ResetPortListHead);
|
|
|
|
InitializeListHead(&FDODeviceExtension->CyclePortListHead);
|
|
|
|
KeInitializeSpinLock(&FDODeviceExtension->Lock);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
FDODeviceExtension->NextDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject,
|
|
|
|
PhysicalDeviceObject);
|
2012-01-26 03:42:56 +00:00
|
|
|
if (!FDODeviceExtension->NextDeviceObject)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Failed to attach */
|
2012-01-26 03:42:56 +00:00
|
|
|
DPRINT1("USBCCGP_AddDevice failed to attach device\n");
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
return STATUS_DEVICE_REMOVED;
|
|
|
|
}
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Set device flags */
|
2012-01-26 03:42:56 +00:00
|
|
|
DeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Device is initialized */
|
2012-01-26 03:42:56 +00:00
|
|
|
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Device initialized */
|
2012-01-26 03:42:56 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBCCGP_CreateClose(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
PCOMMON_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Get common device extension */
|
2012-01-26 03:42:56 +00:00
|
|
|
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Is it a fdo */
|
2012-01-26 03:42:56 +00:00
|
|
|
if (DeviceExtension->IsFDO)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Forward and forget */
|
2012-01-26 03:42:56 +00:00
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Get fdo */
|
2012-01-26 03:42:56 +00:00
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Call lower driver */
|
2012-01-26 03:42:56 +00:00
|
|
|
return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Pdo not supported */
|
2012-01-26 03:42:56 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
USBCCGP_Dispatch(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
PCOMMON_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Get common device extension */
|
2012-01-26 03:42:56 +00:00
|
|
|
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Get current stack location */
|
2012-01-26 03:42:56 +00:00
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
if (IoStack->MajorFunction == IRP_MJ_CREATE || IoStack->MajorFunction == IRP_MJ_CLOSE)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Dispatch to default handler */
|
2012-01-26 03:42:56 +00:00
|
|
|
return USBCCGP_CreateClose(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceExtension->IsFDO)
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Handle request for FDO */
|
2012-01-26 03:42:56 +00:00
|
|
|
return FDO_Dispatch(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Handle request for PDO */
|
2012-01-26 03:42:56 +00:00
|
|
|
return PDO_Dispatch(DeviceObject, Irp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 21:24:36 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
USBCCGP_Unload(PDRIVER_OBJECT DriverObject)
|
|
|
|
{
|
|
|
|
DPRINT("[USBCCGP] Unload\n");
|
|
|
|
}
|
|
|
|
|
2012-01-26 03:42:56 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
DriverEntry(
|
|
|
|
PDRIVER_OBJECT DriverObject,
|
|
|
|
PUNICODE_STRING RegistryPath)
|
|
|
|
{
|
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* Initialize driver object */
|
2012-02-12 02:53:34 +00:00
|
|
|
DPRINT("[USBCCGP] DriverEntry\n");
|
2012-01-26 03:42:56 +00:00
|
|
|
DriverObject->DriverExtension->AddDevice = USBCCGP_AddDevice;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = USBCCGP_Dispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = USBCCGP_Dispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = USBCCGP_Dispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = USBCCGP_Dispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_POWER] = USBCCGP_Dispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_PNP] = USBCCGP_Dispatch;
|
2013-05-24 17:36:14 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = USBCCGP_Dispatch;
|
|
|
|
DriverObject->DriverUnload = USBCCGP_Unload;
|
2012-01-26 03:42:56 +00:00
|
|
|
|
2012-02-25 00:35:40 +00:00
|
|
|
/* FIMXE query GenericCompositeUSBDeviceString */
|
2012-01-26 03:42:56 +00:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|