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)
15 DRIVER_ADD_DEVICE USBCCGP_AddDevice
;
20 PDRIVER_OBJECT DriverObject
,
21 PDEVICE_OBJECT PhysicalDeviceObject
)
24 PDEVICE_OBJECT DeviceObject
;
25 PFDO_DEVICE_EXTENSION FDODeviceExtension
;
27 /* Lets create the device */
28 Status
= IoCreateDevice(DriverObject
,
29 sizeof(FDO_DEVICE_EXTENSION
),
32 FILE_AUTOGENERATED_DEVICE_NAME
,
35 if (!NT_SUCCESS(Status
))
37 /* Failed to create device */
38 DPRINT1("USBCCGP_AddDevice failed to create device with %x\n", Status
);
42 /* Get device extension */
43 FDODeviceExtension
= (PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
45 /* Init device extension */
46 RtlZeroMemory(FDODeviceExtension
, sizeof(FDO_DEVICE_EXTENSION
));
47 FDODeviceExtension
->Common
.IsFDO
= TRUE
;
48 FDODeviceExtension
->DriverObject
= DriverObject
;
49 FDODeviceExtension
->PhysicalDeviceObject
= PhysicalDeviceObject
;
50 InitializeListHead(&FDODeviceExtension
->ResetPortListHead
);
51 InitializeListHead(&FDODeviceExtension
->CyclePortListHead
);
52 KeInitializeSpinLock(&FDODeviceExtension
->Lock
);
54 FDODeviceExtension
->NextDeviceObject
= IoAttachDeviceToDeviceStack(DeviceObject
,
55 PhysicalDeviceObject
);
56 if (!FDODeviceExtension
->NextDeviceObject
)
58 /* Failed to attach */
59 DPRINT1("USBCCGP_AddDevice failed to attach device\n");
60 IoDeleteDevice(DeviceObject
);
61 return STATUS_DEVICE_REMOVED
;
64 /* Set device flags */
65 DeviceObject
->Flags
|= DO_BUFFERED_IO
| DO_POWER_PAGABLE
;
67 /* Device is initialized */
68 DeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
70 /* Device initialized */
77 PDEVICE_OBJECT DeviceObject
,
80 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
81 PFDO_DEVICE_EXTENSION FDODeviceExtension
;
83 /* Get common device extension */
84 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
87 if (DeviceExtension
->IsFDO
)
89 /* Forward and forget */
90 IoSkipCurrentIrpStackLocation(Irp
);
93 FDODeviceExtension
= (PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
95 /* Call lower driver */
96 return IoCallDriver(FDODeviceExtension
->NextDeviceObject
, Irp
);
100 /* Pdo not supported */
101 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
102 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
103 return STATUS_NOT_SUPPORTED
;
110 PDEVICE_OBJECT DeviceObject
,
113 PCOMMON_DEVICE_EXTENSION DeviceExtension
;
114 PIO_STACK_LOCATION IoStack
;
116 /* Get common device extension */
117 DeviceExtension
= (PCOMMON_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
119 /* Get current stack location */
120 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
122 if (IoStack
->MajorFunction
== IRP_MJ_CREATE
|| IoStack
->MajorFunction
== IRP_MJ_CLOSE
)
124 /* Dispatch to default handler */
125 return USBCCGP_CreateClose(DeviceObject
, Irp
);
128 if (DeviceExtension
->IsFDO
)
130 /* Handle request for FDO */
131 return FDO_Dispatch(DeviceObject
, Irp
);
135 /* Handle request for PDO */
136 return PDO_Dispatch(DeviceObject
, Irp
);
142 USBCCGP_Unload(PDRIVER_OBJECT DriverObject
)
144 DPRINT("[USBCCGP] Unload\n");
150 PDRIVER_OBJECT DriverObject
,
151 PUNICODE_STRING RegistryPath
)
154 /* Initialize driver object */
155 DPRINT("[USBCCGP] DriverEntry\n");
156 DriverObject
->DriverExtension
->AddDevice
= USBCCGP_AddDevice
;
157 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = USBCCGP_Dispatch
;
158 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = USBCCGP_Dispatch
;
159 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = USBCCGP_Dispatch
;
160 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = USBCCGP_Dispatch
;
161 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = USBCCGP_Dispatch
;
162 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = USBCCGP_Dispatch
;
163 DriverObject
->MajorFunction
[IRP_MJ_SYSTEM_CONTROL
] = USBCCGP_Dispatch
;
164 DriverObject
->DriverUnload
= USBCCGP_Unload
;
166 /* FIMXE query GenericCompositeUSBDeviceString */
168 return STATUS_SUCCESS
;