2 * PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/usb/usbccgp/usbccgp.c
5 * PURPOSE: USB device driver.
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
17 DRIVER_ADD_DEVICE USBCCGP_AddDevice
;
22 PDRIVER_OBJECT DriverObject
,
23 PDEVICE_OBJECT PhysicalDeviceObject
)
26 PDEVICE_OBJECT DeviceObject
;
27 PFDO_DEVICE_EXTENSION FDODeviceExtension
;
29 // lets create the device
30 Status
= IoCreateDevice(DriverObject
, sizeof(FDO_DEVICE_EXTENSION
), NULL
, FILE_DEVICE_USB
, FILE_AUTOGENERATED_DEVICE_NAME
, FALSE
, &DeviceObject
);
31 if (!NT_SUCCESS(Status
))
33 // failed to create device
34 DPRINT1("USBCCGP_AddDevice failed to create device with %x\n", Status
);
38 // get device extension
39 FDODeviceExtension
= (PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
41 // init device extension
42 RtlZeroMemory(FDODeviceExtension
, sizeof(FDO_DEVICE_EXTENSION
));
43 FDODeviceExtension
->Common
.IsFDO
= TRUE
;
44 FDODeviceExtension
->DriverObject
= DriverObject
;
45 FDODeviceExtension
->PhysicalDeviceObject
= PhysicalDeviceObject
;
46 InitializeListHead(&FDODeviceExtension
->ResetPortListHead
);
47 InitializeListHead(&FDODeviceExtension
->CyclePortListHead
);
48 KeInitializeSpinLock(&FDODeviceExtension
->Lock
);
50 FDODeviceExtension
->NextDeviceObject
= IoAttachDeviceToDeviceStack(DeviceObject
, PhysicalDeviceObject
);
51 if (!FDODeviceExtension
->NextDeviceObject
)
54 DPRINT1("USBCCGP_AddDevice failed to attach device\n");
55 IoDeleteDevice(DeviceObject
);
56 return STATUS_DEVICE_REMOVED
;
60 DeviceObject
->Flags
|= DO_BUFFERED_IO
| DO_POWER_PAGABLE
;
62 // device is initialized
63 DeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
72 PDEVICE_OBJECT DeviceObject
,
75 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
76 PFDO_DEVICE_EXTENSION FDODeviceExtension
;
78 // get common device extension
79 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
82 if (DeviceExtension
->IsFDO
)
85 IoSkipCurrentIrpStackLocation(Irp
);
88 FDODeviceExtension
= (PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
91 return IoCallDriver(FDODeviceExtension
->NextDeviceObject
, Irp
);
96 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
97 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
98 return STATUS_NOT_SUPPORTED
;
105 PDEVICE_OBJECT DeviceObject
,
108 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
109 PIO_STACK_LOCATION IoStack
;
111 // get common device extension
112 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
114 // get current stack location
115 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
117 if (IoStack
->MajorFunction
== IRP_MJ_CREATE
|| IoStack
->MajorFunction
== IRP_MJ_CLOSE
)
119 // dispatch to default handler
120 return USBCCGP_CreateClose(DeviceObject
, Irp
);
123 if (DeviceExtension
->IsFDO
)
125 // handle request for FDO
126 return FDO_Dispatch(DeviceObject
, Irp
);
130 // handle request for PDO
131 return PDO_Dispatch(DeviceObject
, Irp
);
138 PDRIVER_OBJECT DriverObject
,
139 PUNICODE_STRING RegistryPath
)
142 // initialize driver object
143 DPRINT("[USBCCGP] DriverEntry\n");
144 DriverObject
->DriverExtension
->AddDevice
= USBCCGP_AddDevice
;
145 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = USBCCGP_Dispatch
;
146 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = USBCCGP_Dispatch
;
147 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = USBCCGP_Dispatch
;
148 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = USBCCGP_Dispatch
;
149 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = USBCCGP_Dispatch
;
150 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = USBCCGP_Dispatch
;
152 // FIMXE query GenericCompositeUSBDeviceString
154 return STATUS_SUCCESS
;