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/pdo.c
5 * PURPOSE: USB device driver.
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
15 USBCCGP_PdoHandleQueryDeviceText(
16 IN PDEVICE_OBJECT DeviceObject
,
20 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
23 // get device extension
25 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
28 // is there a device description
30 if (PDODeviceExtension
->FunctionDescriptor
->FunctionDescription
.Length
)
35 Buffer
= AllocateItem(NonPagedPool
, PDODeviceExtension
->FunctionDescriptor
->FunctionDescription
.Length
+ sizeof(WCHAR
));
41 return STATUS_INSUFFICIENT_RESOURCES
;
47 Irp
->IoStatus
.Information
= (ULONG_PTR
)Buffer
;
48 RtlCopyMemory(Buffer
, PDODeviceExtension
->FunctionDescriptor
->FunctionDescription
.Buffer
, PDODeviceExtension
->FunctionDescriptor
->FunctionDescription
.Length
);
49 return STATUS_SUCCESS
;
53 // FIXME use GenericCompositeUSBDeviceString
56 return Irp
->IoStatus
.Status
;
60 USBCCGP_PdoHandleDeviceRelations(
61 IN PDEVICE_OBJECT DeviceObject
,
64 PDEVICE_RELATIONS DeviceRelations
;
65 PIO_STACK_LOCATION IoStack
;
67 DPRINT1("USBCCGP_PdoHandleDeviceRelations\n");
70 // get current irp stack location
72 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
75 // check if relation type is BusRelations
77 if (IoStack
->Parameters
.QueryDeviceRelations
.Type
!= TargetDeviceRelation
)
80 // PDO handles only target device relation
82 return Irp
->IoStatus
.Status
;
86 // allocate device relations
88 DeviceRelations
= (PDEVICE_RELATIONS
)AllocateItem(PagedPool
, sizeof(DEVICE_RELATIONS
));
94 return STATUS_INSUFFICIENT_RESOURCES
;
98 // initialize device relations
100 DeviceRelations
->Count
= 1;
101 DeviceRelations
->Objects
[0] = DeviceObject
;
102 ObReferenceObject(DeviceObject
);
107 Irp
->IoStatus
.Information
= (ULONG_PTR
)DeviceRelations
;
110 // completed successfully
112 return STATUS_SUCCESS
;
116 USBCCGP_PdoHandleQueryId(
117 PDEVICE_OBJECT DeviceObject
,
120 PIO_STACK_LOCATION IoStack
;
121 PUNICODE_STRING DeviceString
= NULL
;
122 UNICODE_STRING TempString
;
123 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
128 // get current irp stack location
130 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
133 // get device extension
135 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
138 if (IoStack
->Parameters
.QueryId
.IdType
== BusQueryDeviceID
)
141 // handle query device id
143 Status
= USBCCGP_SyncForwardIrp(PDODeviceExtension
->NextDeviceObject
, Irp
);
146 // FIXME append interface id
151 else if (IoStack
->Parameters
.QueryId
.IdType
== BusQueryHardwareIDs
)
154 // handle instance id
156 DeviceString
= &PDODeviceExtension
->FunctionDescriptor
->HardwareId
;
158 else if (IoStack
->Parameters
.QueryId
.IdType
== BusQueryInstanceID
)
161 // handle instance id
163 RtlInitUnicodeString(&TempString
, L
"0000");
164 DeviceString
= &TempString
;
166 else if (IoStack
->Parameters
.QueryId
.IdType
== BusQueryCompatibleIDs
)
169 // handle instance id
171 DeviceString
= &PDODeviceExtension
->FunctionDescriptor
->CompatibleId
;
177 ASSERT(DeviceString
!= NULL
);
182 Buffer
= AllocateItem(NonPagedPool
, DeviceString
->Length
+ sizeof(WCHAR
));
188 return STATUS_INSUFFICIENT_RESOURCES
;
194 Irp
->IoStatus
.Information
= (ULONG_PTR
)Buffer
;
195 RtlCopyMemory(Buffer
, DeviceString
->Buffer
, DeviceString
->Length
);
196 return STATUS_SUCCESS
;
201 PDEVICE_OBJECT DeviceObject
,
204 PIO_STACK_LOCATION IoStack
;
205 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
209 // get current stack location
211 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
214 // get device extension
216 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
221 ASSERT(PDODeviceExtension
->Common
.IsFDO
== FALSE
);
223 switch(IoStack
->MinorFunction
)
225 case IRP_MN_QUERY_DEVICE_RELATIONS
:
228 // handle device relations
230 Status
= USBCCGP_PdoHandleDeviceRelations(DeviceObject
, Irp
);
233 case IRP_MN_QUERY_DEVICE_TEXT
:
236 // handle query device text
238 Status
= USBCCGP_PdoHandleQueryDeviceText(DeviceObject
, Irp
);
241 case IRP_MN_QUERY_ID
:
246 Status
= USBCCGP_PdoHandleQueryId(DeviceObject
, Irp
);
249 case IRP_MN_REMOVE_DEVICE
:
251 DPRINT1("IRP_MN_REMOVE_DEVICE\n");
253 /* Complete the IRP */
254 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
255 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
257 /* Delete the device object */
258 IoDeleteDevice(DeviceObject
);
260 return STATUS_SUCCESS
;
262 case IRP_MN_QUERY_CAPABILITIES
:
265 // copy device capabilities
267 RtlCopyMemory(IoStack
->Parameters
.DeviceCapabilities
.Capabilities
, &PDODeviceExtension
->Capabilities
, sizeof(DEVICE_CAPABILITIES
));
269 /* Complete the IRP */
270 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
271 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
272 return STATUS_SUCCESS
;
274 case IRP_MN_START_DEVICE
:
279 DPRINT1("[USBCCGP] PDO IRP_MN_START\n");
280 Status
= STATUS_SUCCESS
;
288 Status
= Irp
->IoStatus
.Status
;
295 if (Status
!= STATUS_PENDING
)
300 Irp
->IoStatus
.Status
= Status
;
305 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
318 PDEVICE_OBJECT DeviceObject
,
321 PIO_STACK_LOCATION IoStack
;
324 /* get stack location */
325 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
327 switch(IoStack
->MajorFunction
)
330 return PDO_HandlePnp(DeviceObject
, Irp
);
332 DPRINT1("PDO_Dispatch Function %x not implemented\n", IoStack
->MajorFunction
);
334 Status
= Irp
->IoStatus
.Status
;
335 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);