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)
18 DRIVER_ADD_DEVICE USBCCGP_AddDevice
;
23 PDRIVER_OBJECT DriverObject
,
24 PDEVICE_OBJECT PhysicalDeviceObject
)
27 PDEVICE_OBJECT DeviceObject
;
28 PFDO_DEVICE_EXTENSION FDODeviceExtension
;
30 /* Lets create the device */
31 Status
= IoCreateDevice(DriverObject
,
32 sizeof(FDO_DEVICE_EXTENSION
),
35 FILE_AUTOGENERATED_DEVICE_NAME
,
38 if (!NT_SUCCESS(Status
))
40 /* Failed to create device */
41 DPRINT1("USBCCGP_AddDevice failed to create device with %x\n", Status
);
45 /* Get device extension */
46 FDODeviceExtension
= (PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
48 /* Init device extension */
49 RtlZeroMemory(FDODeviceExtension
, sizeof(FDO_DEVICE_EXTENSION
));
50 FDODeviceExtension
->Common
.IsFDO
= TRUE
;
51 FDODeviceExtension
->DriverObject
= DriverObject
;
52 FDODeviceExtension
->PhysicalDeviceObject
= PhysicalDeviceObject
;
53 InitializeListHead(&FDODeviceExtension
->ResetPortListHead
);
54 InitializeListHead(&FDODeviceExtension
->CyclePortListHead
);
55 KeInitializeSpinLock(&FDODeviceExtension
->Lock
);
57 FDODeviceExtension
->NextDeviceObject
= IoAttachDeviceToDeviceStack(DeviceObject
,
58 PhysicalDeviceObject
);
59 if (!FDODeviceExtension
->NextDeviceObject
)
61 /* Failed to attach */
62 DPRINT1("USBCCGP_AddDevice failed to attach device\n");
63 IoDeleteDevice(DeviceObject
);
64 return STATUS_DEVICE_REMOVED
;
67 /* Set device flags */
68 DeviceObject
->Flags
|= DO_BUFFERED_IO
| DO_POWER_PAGABLE
;
70 /* Device is initialized */
71 DeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
73 /* Device initialized */
80 PDEVICE_OBJECT DeviceObject
,
83 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
84 PFDO_DEVICE_EXTENSION FDODeviceExtension
;
86 /* Get common device extension */
87 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
90 if (DeviceExtension
->IsFDO
)
92 /* Forward and forget */
93 IoSkipCurrentIrpStackLocation(Irp
);
96 FDODeviceExtension
= (PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
98 /* Call lower driver */
99 return IoCallDriver(FDODeviceExtension
->NextDeviceObject
, Irp
);
103 /* Pdo not supported */
104 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
105 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
106 return STATUS_NOT_SUPPORTED
;
113 PDEVICE_OBJECT DeviceObject
,
116 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
117 PIO_STACK_LOCATION IoStack
;
119 /* Get common device extension */
120 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
122 /* Get current stack location */
123 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
125 if (IoStack
->MajorFunction
== IRP_MJ_CREATE
|| IoStack
->MajorFunction
== IRP_MJ_CLOSE
)
127 /* Dispatch to default handler */
128 return USBCCGP_CreateClose(DeviceObject
, Irp
);
131 if (DeviceExtension
->IsFDO
)
133 /* Handle request for FDO */
134 return FDO_Dispatch(DeviceObject
, Irp
);
138 /* Handle request for PDO */
139 return PDO_Dispatch(DeviceObject
, Irp
);
145 USBCCGP_Unload(PDRIVER_OBJECT DriverObject
)
147 DPRINT("[USBCCGP] Unload\n");
153 PDRIVER_OBJECT DriverObject
,
154 PUNICODE_STRING RegistryPath
)
157 /* Initialize driver object */
158 DPRINT("[USBCCGP] DriverEntry\n");
159 DriverObject
->DriverExtension
->AddDevice
= USBCCGP_AddDevice
;
160 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = USBCCGP_Dispatch
;
161 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = USBCCGP_Dispatch
;
162 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = USBCCGP_Dispatch
;
163 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = USBCCGP_Dispatch
;
164 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = USBCCGP_Dispatch
;
165 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = USBCCGP_Dispatch
;
166 DriverObject
->MajorFunction
[IRP_MJ_SYSTEM_CONTROL
] = USBCCGP_Dispatch
;
167 DriverObject
->DriverUnload
= USBCCGP_Unload
;
169 /* FIMXE query GenericCompositeUSBDeviceString */
171 return STATUS_SUCCESS
;