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
;
21 LPWSTR GenericString
= L
"Composite USB Device";
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 Buffer
= AllocateItem(PagedPool
, (wcslen(GenericString
) + 1) * sizeof(WCHAR
));
62 return STATUS_INSUFFICIENT_RESOURCES
;
64 RtlCopyMemory(Buffer
, GenericString
, (wcslen(GenericString
) + 1) * sizeof(WCHAR
));
65 Irp
->IoStatus
.Information
= (ULONG_PTR
)Buffer
;
67 return STATUS_SUCCESS
;
71 USBCCGP_PdoHandleDeviceRelations(
72 IN PDEVICE_OBJECT DeviceObject
,
75 PDEVICE_RELATIONS DeviceRelations
;
76 PIO_STACK_LOCATION IoStack
;
78 DPRINT("USBCCGP_PdoHandleDeviceRelations\n");
81 // get current irp stack location
83 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
86 // check if relation type is BusRelations
88 if (IoStack
->Parameters
.QueryDeviceRelations
.Type
!= TargetDeviceRelation
)
91 // PDO handles only target device relation
93 return Irp
->IoStatus
.Status
;
97 // allocate device relations
99 DeviceRelations
= (PDEVICE_RELATIONS
)AllocateItem(PagedPool
, sizeof(DEVICE_RELATIONS
));
100 if (!DeviceRelations
)
105 return STATUS_INSUFFICIENT_RESOURCES
;
109 // initialize device relations
111 DeviceRelations
->Count
= 1;
112 DeviceRelations
->Objects
[0] = DeviceObject
;
113 ObReferenceObject(DeviceObject
);
118 Irp
->IoStatus
.Information
= (ULONG_PTR
)DeviceRelations
;
121 // completed successfully
123 return STATUS_SUCCESS
;
127 USBCCGP_PdoAppendInterfaceNumber(
129 IN ULONG InterfaceNumber
,
130 OUT LPWSTR
*OutString
)
132 ULONG Length
= 0, StringLength
;
136 // count length of string
141 StringLength
= wcslen(String
) + 1;
142 Length
+= StringLength
;
143 Length
+= 6; //&MI_XX
144 String
+= StringLength
;
148 // now allocate the buffer
150 String
= AllocateItem(NonPagedPool
, (Length
+ 2) * sizeof(WCHAR
));
156 return STATUS_INSUFFICIENT_RESOURCES
;
166 StringLength
= swprintf(String
, L
"%s&MI_%02x", DeviceId
, InterfaceNumber
) + 1;
167 Length
= wcslen(DeviceId
) + 1;
168 DPRINT("String %p\n", String
);
173 String
+= StringLength
;
180 return STATUS_SUCCESS
;
185 USBCCGP_PdoHandleQueryId(
186 PDEVICE_OBJECT DeviceObject
,
189 PIO_STACK_LOCATION IoStack
;
190 PUNICODE_STRING DeviceString
= NULL
;
191 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
196 // get current irp stack location
198 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
201 // get device extension
203 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
206 if (IoStack
->Parameters
.QueryId
.IdType
== BusQueryDeviceID
)
209 // handle query device id
211 Status
= USBCCGP_SyncForwardIrp(PDODeviceExtension
->NextDeviceObject
, Irp
);
212 if (NT_SUCCESS(Status
))
217 Buffer
= AllocateItem(NonPagedPool
, (wcslen((LPWSTR
)Irp
->IoStatus
.Information
) + 7) * sizeof(WCHAR
));
221 // append interface number
223 ASSERT(Irp
->IoStatus
.Information
);
224 swprintf(Buffer
, L
"%s&MI_%02x", (LPWSTR
)Irp
->IoStatus
.Information
, PDODeviceExtension
->FunctionDescriptor
->FunctionNumber
);
225 DPRINT("BusQueryDeviceID %S\n", Buffer
);
227 ExFreePool((PVOID
)Irp
->IoStatus
.Information
);
228 Irp
->IoStatus
.Information
= (ULONG_PTR
)Buffer
;
235 Status
= STATUS_INSUFFICIENT_RESOURCES
;
240 else if (IoStack
->Parameters
.QueryId
.IdType
== BusQueryHardwareIDs
)
243 // handle instance id
245 DeviceString
= &PDODeviceExtension
->FunctionDescriptor
->HardwareId
;
247 else if (IoStack
->Parameters
.QueryId
.IdType
== BusQueryInstanceID
)
250 // handle instance id
252 Buffer
= AllocateItem(NonPagedPool
, 5 * sizeof(WCHAR
));
258 return STATUS_INSUFFICIENT_RESOURCES
;
262 // use function number
264 swprintf(Buffer
, L
"%04x", PDODeviceExtension
->FunctionDescriptor
->FunctionNumber
);
265 Irp
->IoStatus
.Information
= (ULONG_PTR
)Buffer
;
266 return STATUS_SUCCESS
;
268 else if (IoStack
->Parameters
.QueryId
.IdType
== BusQueryCompatibleIDs
)
271 // handle instance id
273 DeviceString
= &PDODeviceExtension
->FunctionDescriptor
->CompatibleId
;
279 ASSERT(DeviceString
!= NULL
);
284 Buffer
= AllocateItem(NonPagedPool
, DeviceString
->Length
+ sizeof(WCHAR
));
290 return STATUS_INSUFFICIENT_RESOURCES
;
296 RtlCopyMemory(Buffer
, DeviceString
->Buffer
, DeviceString
->Length
);
297 Irp
->IoStatus
.Information
= (ULONG_PTR
)Buffer
;
299 return STATUS_SUCCESS
;
304 PDEVICE_OBJECT DeviceObject
,
307 PIO_STACK_LOCATION IoStack
;
308 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
313 // get current stack location
315 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
318 // get device extension
320 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
325 ASSERT(PDODeviceExtension
->Common
.IsFDO
== FALSE
);
327 switch(IoStack
->MinorFunction
)
329 case IRP_MN_QUERY_DEVICE_RELATIONS
:
332 // handle device relations
334 Status
= USBCCGP_PdoHandleDeviceRelations(DeviceObject
, Irp
);
337 case IRP_MN_QUERY_DEVICE_TEXT
:
340 // handle query device text
342 Status
= USBCCGP_PdoHandleQueryDeviceText(DeviceObject
, Irp
);
345 case IRP_MN_QUERY_ID
:
350 Status
= USBCCGP_PdoHandleQueryId(DeviceObject
, Irp
);
353 case IRP_MN_REMOVE_DEVICE
:
356 // remove us from the fdo's pdo list
359 for(Index
= 0; Index
< PDODeviceExtension
->FDODeviceExtension
->FunctionDescriptorCount
; Index
++)
361 if (PDODeviceExtension
->FDODeviceExtension
->ChildPDO
[Index
] == DeviceObject
)
366 PDODeviceExtension
->FDODeviceExtension
->ChildPDO
[Index
] = NULL
;
375 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
376 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
381 // Delete the device object
383 IoDeleteDevice(DeviceObject
);
385 return STATUS_SUCCESS
;
387 case IRP_MN_QUERY_CAPABILITIES
:
390 // copy device capabilities
392 RtlCopyMemory(IoStack
->Parameters
.DeviceCapabilities
.Capabilities
, &PDODeviceExtension
->Capabilities
, sizeof(DEVICE_CAPABILITIES
));
394 /* Complete the IRP */
395 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
396 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
397 return STATUS_SUCCESS
;
399 case IRP_MN_QUERY_REMOVE_DEVICE
:
400 case IRP_MN_QUERY_STOP_DEVICE
:
405 Status
= STATUS_SUCCESS
;
408 case IRP_MN_START_DEVICE
:
413 DPRINT("[USBCCGP] PDO IRP_MN_START\n");
414 Status
= STATUS_SUCCESS
;
417 case IRP_MN_QUERY_INTERFACE
:
420 // forward to lower device object
422 IoSkipCurrentIrpStackLocation(Irp
);
423 return IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
430 Status
= Irp
->IoStatus
.Status
;
438 if (Status
!= STATUS_PENDING
)
443 Irp
->IoStatus
.Status
= Status
;
448 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
459 USBCCGP_BuildConfigurationDescriptor(
460 PDEVICE_OBJECT DeviceObject
,
463 PIO_STACK_LOCATION IoStack
;
464 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
465 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
;
466 PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
467 ULONG TotalSize
, Index
;
471 UCHAR InterfaceNumber
;
474 // get current stack location
476 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
478 DPRINT("USBCCGP_BuildConfigurationDescriptor\n");
481 // get device extension
483 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
486 // get configuration descriptor
488 ConfigurationDescriptor
= PDODeviceExtension
->ConfigurationDescriptor
;
491 // calculate size of configuration descriptor
493 TotalSize
= sizeof(USB_CONFIGURATION_DESCRIPTOR
);
495 for(Index
= 0; Index
< PDODeviceExtension
->FunctionDescriptor
->NumberOfInterfaces
; Index
++)
498 // get current interface descriptor
500 InterfaceDescriptor
= PDODeviceExtension
->FunctionDescriptor
->InterfaceDescriptorList
[Index
];
501 InterfaceNumber
= InterfaceDescriptor
->bInterfaceNumber
;
504 // add to size and move to next descriptor
506 TotalSize
+= InterfaceDescriptor
->bLength
;
507 InterfaceDescriptor
= (PUSB_INTERFACE_DESCRIPTOR
)((ULONG_PTR
)InterfaceDescriptor
+ InterfaceDescriptor
->bLength
);
511 if ((ULONG_PTR
)InterfaceDescriptor
>= ((ULONG_PTR
)ConfigurationDescriptor
+ ConfigurationDescriptor
->wTotalLength
))
514 // reached end of configuration descriptor
520 // association descriptors are removed
522 if (InterfaceDescriptor
->bDescriptorType
!= USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE
)
524 if (InterfaceDescriptor
->bDescriptorType
== USB_INTERFACE_DESCRIPTOR_TYPE
)
526 if (InterfaceNumber
!= InterfaceDescriptor
->bInterfaceNumber
)
529 // reached next descriptor
535 // include alternate descriptor
542 TotalSize
+= InterfaceDescriptor
->bLength
;
546 // move to next descriptor
548 InterfaceDescriptor
= (PUSB_INTERFACE_DESCRIPTOR
)((ULONG_PTR
)InterfaceDescriptor
+ InterfaceDescriptor
->bLength
);
553 // now allocate temporary buffer for the configuration descriptor
555 Buffer
= AllocateItem(NonPagedPool
, TotalSize
);
559 // failed to allocate buffer
561 DPRINT1("[USBCCGP] Failed to allocate %lu Bytes\n", TotalSize
);
562 return STATUS_INSUFFICIENT_RESOURCES
;
566 // first copy the configuration descriptor
568 RtlCopyMemory(Buffer
, ConfigurationDescriptor
, sizeof(USB_CONFIGURATION_DESCRIPTOR
));
569 BufferPtr
= (PUCHAR
)((ULONG_PTR
)Buffer
+ ConfigurationDescriptor
->bLength
);
571 for(Index
= 0; Index
< PDODeviceExtension
->FunctionDescriptor
->NumberOfInterfaces
; Index
++)
574 // get current interface descriptor
576 InterfaceDescriptor
= PDODeviceExtension
->FunctionDescriptor
->InterfaceDescriptorList
[Index
];
577 InterfaceNumber
= InterfaceDescriptor
->bInterfaceNumber
;
580 // copy descriptor and move to next descriptor
582 RtlCopyMemory(BufferPtr
, InterfaceDescriptor
, InterfaceDescriptor
->bLength
);
583 BufferPtr
+= InterfaceDescriptor
->bLength
;
584 InterfaceDescriptor
= (PUSB_INTERFACE_DESCRIPTOR
)((ULONG_PTR
)InterfaceDescriptor
+ InterfaceDescriptor
->bLength
);
588 if ((ULONG_PTR
)InterfaceDescriptor
>= ((ULONG_PTR
)ConfigurationDescriptor
+ ConfigurationDescriptor
->wTotalLength
))
591 // reached end of configuration descriptor
597 // association descriptors are removed
599 if (InterfaceDescriptor
->bDescriptorType
!= USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE
)
601 if (InterfaceDescriptor
->bDescriptorType
== USB_INTERFACE_DESCRIPTOR_TYPE
)
603 if (InterfaceNumber
!= InterfaceDescriptor
->bInterfaceNumber
)
606 // reached next descriptor
612 // include alternate descriptor
614 DPRINT("InterfaceDescriptor %p Alternate %x InterfaceNumber %x\n", InterfaceDescriptor
, InterfaceDescriptor
->bAlternateSetting
, InterfaceDescriptor
->bInterfaceNumber
);
620 RtlCopyMemory(BufferPtr
, InterfaceDescriptor
, InterfaceDescriptor
->bLength
);
621 BufferPtr
+= InterfaceDescriptor
->bLength
;
625 // move to next descriptor
627 InterfaceDescriptor
= (PUSB_INTERFACE_DESCRIPTOR
)((ULONG_PTR
)InterfaceDescriptor
+ InterfaceDescriptor
->bLength
);
632 // modify configuration descriptor
634 ConfigurationDescriptor
= Buffer
;
635 ConfigurationDescriptor
->wTotalLength
= TotalSize
;
636 ConfigurationDescriptor
->bNumInterfaces
= PDODeviceExtension
->FunctionDescriptor
->NumberOfInterfaces
;
641 Urb
= (PURB
)IoStack
->Parameters
.Others
.Argument1
;
647 RtlCopyMemory(Urb
->UrbControlDescriptorRequest
.TransferBuffer
, Buffer
, min(TotalSize
, Urb
->UrbControlDescriptorRequest
.TransferBufferLength
));
652 Urb
->UrbControlDescriptorRequest
.TransferBufferLength
= TotalSize
;
662 return STATUS_SUCCESS
;
666 USBCCGP_PDOSelectConfiguration(
667 PDEVICE_OBJECT DeviceObject
,
670 PIO_STACK_LOCATION IoStack
;
671 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
673 PUSBD_INTERFACE_INFORMATION InterfaceInformation
;
674 ULONG InterfaceIndex
, Length
;
675 PUSBD_INTERFACE_LIST_ENTRY Entry
;
676 ULONG NeedSelect
, FoundInterface
;
680 // get current stack location
682 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
685 // get device extension
687 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
692 Urb
= (PURB
)IoStack
->Parameters
.Others
.Argument1
;
696 // is there already an configuration handle
698 if (Urb
->UrbSelectConfiguration
.ConfigurationHandle
)
703 return STATUS_SUCCESS
;
707 //C_ASSERT(sizeof(struct _URB_HEADER) == 16);
708 //C_ASSERT(FIELD_OFFSET(struct _URB_SELECT_CONFIGURATION, Interface.Length) == 24);
709 //C_ASSERT(sizeof(USBD_INTERFACE_INFORMATION) == 36);
710 //C_ASSERT(sizeof(struct _URB_SELECT_CONFIGURATION) == 0x3C);
712 // available buffer length
713 Length
= Urb
->UrbSelectConfiguration
.Hdr
.Length
- FIELD_OFFSET(struct _URB_SELECT_CONFIGURATION
, Interface
.Length
);
716 // check all interfaces
718 InterfaceInformation
= &Urb
->UrbSelectConfiguration
.Interface
;
723 DPRINT1("[USBCCGP] SelectConfiguration Function %x InterfaceNumber %x Alternative %x Length %lu InterfaceInformation->Length %lu\n", PDODeviceExtension
->FunctionDescriptor
->FunctionNumber
, InterfaceInformation
->InterfaceNumber
, InterfaceInformation
->AlternateSetting
, Length
, InterfaceInformation
->Length
);
724 ASSERT(InterfaceInformation
->Length
);
726 // search for the interface in the local interface list
728 FoundInterface
= FALSE
;
729 for(InterfaceIndex
= 0; InterfaceIndex
< PDODeviceExtension
->FunctionDescriptor
->NumberOfInterfaces
; InterfaceIndex
++)
731 if (PDODeviceExtension
->FunctionDescriptor
->InterfaceDescriptorList
[InterfaceIndex
]->bInterfaceNumber
== InterfaceInformation
->InterfaceNumber
)
733 // found interface entry
734 FoundInterface
= TRUE
;
744 DPRINT1("InterfaceInformation InterfaceNumber %x Alternative %x NumberOfPipes %x not found\n", InterfaceInformation
->InterfaceNumber
, InterfaceInformation
->AlternateSetting
, InterfaceInformation
->NumberOfPipes
);
746 return STATUS_INVALID_PARAMETER
;
750 // now query the total interface list
753 for(InterfaceIndex
= 0; InterfaceIndex
< PDODeviceExtension
->InterfaceListCount
; InterfaceIndex
++)
755 if (PDODeviceExtension
->InterfaceList
[InterfaceIndex
].Interface
->InterfaceNumber
== InterfaceInformation
->InterfaceNumber
)
760 Entry
= &PDODeviceExtension
->InterfaceList
[InterfaceIndex
];
771 // corruption detected
777 if (Entry
->InterfaceDescriptor
->bAlternateSetting
== InterfaceInformation
->AlternateSetting
)
780 for(InterfaceIndex
= 0; InterfaceIndex
< InterfaceInformation
->NumberOfPipes
; InterfaceIndex
++)
782 if (InterfaceInformation
->Pipes
[InterfaceIndex
].MaximumTransferSize
!= Entry
->Interface
->Pipes
[InterfaceIndex
].MaximumTransferSize
)
794 // need select as the interface number differ
802 // interface is already selected
804 ASSERT(Length
>= Entry
->Interface
->Length
);
805 RtlCopyMemory(InterfaceInformation
, Entry
->Interface
, Entry
->Interface
->Length
);
808 // adjust remaining buffer size
810 ASSERT(Entry
->Interface
->Length
);
811 Length
-= Entry
->Interface
->Length
;
814 // move to next output interface information
816 InterfaceInformation
= (PUSBD_INTERFACE_INFORMATION
)((ULONG_PTR
)InterfaceInformation
+ Entry
->Interface
->Length
);
823 DPRINT1("Selecting InterfaceIndex %lu AlternateSetting %lu NumberOfPipes %lu\n", InterfaceInformation
->InterfaceNumber
, InterfaceInformation
->AlternateSetting
, InterfaceInformation
->NumberOfPipes
);
824 ASSERT(InterfaceInformation
->Length
== Entry
->Interface
->Length
);
829 NewUrb
= AllocateItem(NonPagedPool
, GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceInformation
->NumberOfPipes
));
835 return STATUS_INSUFFICIENT_RESOURCES
;
839 // now prepare interface urb
841 UsbBuildSelectInterfaceRequest(NewUrb
, GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceInformation
->NumberOfPipes
), PDODeviceExtension
->ConfigurationHandle
, InterfaceInformation
->InterfaceNumber
, InterfaceInformation
->AlternateSetting
);
844 // now select the interface
846 Status
= USBCCGP_SyncUrbRequest(PDODeviceExtension
->NextDeviceObject
, NewUrb
);
847 DPRINT1("SelectInterface Status %x\n", Status
);
849 if (!NT_SUCCESS(Status
))
858 // update configuration info
860 ASSERT(Entry
->Interface
->Length
>= NewUrb
->UrbSelectInterface
.Interface
.Length
);
861 ASSERT(Length
>= NewUrb
->UrbSelectInterface
.Interface
.Length
);
862 RtlCopyMemory(Entry
->Interface
, &NewUrb
->UrbSelectInterface
.Interface
, NewUrb
->UrbSelectInterface
.Interface
.Length
);
865 // update provided interface information
867 ASSERT(Length
>= Entry
->Interface
->Length
);
868 RtlCopyMemory(InterfaceInformation
, Entry
->Interface
, Entry
->Interface
->Length
);
871 // decrement remaining buffer size
873 ASSERT(Entry
->Interface
->Length
);
874 Length
-= Entry
->Interface
->Length
;
877 // adjust output buffer offset
879 InterfaceInformation
= (PUSBD_INTERFACE_INFORMATION
)((ULONG_PTR
)InterfaceInformation
+ Entry
->Interface
->Length
);
890 // store configuration handle
892 Urb
->UrbSelectConfiguration
.ConfigurationHandle
= PDODeviceExtension
->ConfigurationHandle
;
894 DPRINT1("[USBCCGP] SelectConfiguration Function %x Completed\n", PDODeviceExtension
->FunctionDescriptor
->FunctionNumber
);
899 return STATUS_SUCCESS
;
903 PDO_HandleInternalDeviceControl(
904 PDEVICE_OBJECT DeviceObject
,
907 PIO_STACK_LOCATION IoStack
;
908 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
913 // get current stack location
915 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
918 // get device extension
920 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
922 if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_USB_SUBMIT_URB
)
927 Urb
= (PURB
)IoStack
->Parameters
.Others
.Argument1
;
929 DPRINT("IOCTL_INTERNAL_USB_SUBMIT_URB Function %x\n", Urb
->UrbHeader
.Function
);
931 if (Urb
->UrbHeader
.Function
== URB_FUNCTION_SELECT_CONFIGURATION
)
934 // select configuration
936 Status
= USBCCGP_PDOSelectConfiguration(DeviceObject
, Irp
);
937 Irp
->IoStatus
.Status
= Status
;
938 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
941 else if (Urb
->UrbHeader
.Function
== URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
)
943 if(Urb
->UrbControlDescriptorRequest
.DescriptorType
== USB_DEVICE_DESCRIPTOR_TYPE
)
946 // is the buffer big enough
948 if (Urb
->UrbControlDescriptorRequest
.TransferBufferLength
< sizeof(USB_DEVICE_DESCRIPTOR
))
951 // invalid buffer size
953 DPRINT1("[USBCCGP] invalid device descriptor size %lu\n", Urb
->UrbControlDescriptorRequest
.TransferBufferLength
);
954 Urb
->UrbControlDescriptorRequest
.TransferBufferLength
= sizeof(USB_DEVICE_DESCRIPTOR
);
955 Irp
->IoStatus
.Status
= STATUS_INVALID_BUFFER_SIZE
;
956 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
957 return STATUS_INVALID_BUFFER_SIZE
;
961 // copy device descriptor
963 ASSERT(Urb
->UrbControlDescriptorRequest
.TransferBuffer
);
964 RtlCopyMemory(Urb
->UrbControlDescriptorRequest
.TransferBuffer
, &PDODeviceExtension
->DeviceDescriptor
, sizeof(USB_DEVICE_DESCRIPTOR
));
965 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
966 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
967 return STATUS_SUCCESS
;
969 else if (Urb
->UrbControlDescriptorRequest
.DescriptorType
== USB_CONFIGURATION_DESCRIPTOR_TYPE
)
972 // build configuration descriptor
974 Status
= USBCCGP_BuildConfigurationDescriptor(DeviceObject
, Irp
);
975 Irp
->IoStatus
.Status
= Status
;
976 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
979 else if (Urb
->UrbControlDescriptorRequest
.DescriptorType
== USB_STRING_DESCRIPTOR_TYPE
)
981 PUSB_STRING_DESCRIPTOR StringDescriptor
;
984 // get the requested string descriptor
986 ASSERT(Urb
->UrbControlDescriptorRequest
.TransferBuffer
);
987 Status
= USBCCGP_GetDescriptor(PDODeviceExtension
->FDODeviceExtension
->NextDeviceObject
,
988 USB_STRING_DESCRIPTOR_TYPE
,
989 Urb
->UrbControlDescriptorRequest
.TransferBufferLength
,
990 Urb
->UrbControlDescriptorRequest
.Index
,
991 Urb
->UrbControlDescriptorRequest
.LanguageId
,
992 (PVOID
*)&StringDescriptor
);
993 if (NT_SUCCESS(Status
))
995 if (StringDescriptor
->bLength
== 2)
997 FreeItem(StringDescriptor
);
998 Status
= STATUS_DEVICE_DATA_ERROR
;
1002 RtlCopyMemory(Urb
->UrbControlDescriptorRequest
.TransferBuffer
,
1003 StringDescriptor
->bString
,
1004 StringDescriptor
->bLength
+ sizeof(WCHAR
));
1005 FreeItem(StringDescriptor
);
1006 Status
= STATUS_SUCCESS
;
1009 Irp
->IoStatus
.Status
= Status
;
1010 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1016 IoSkipCurrentIrpStackLocation(Irp
);
1017 Status
= IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
1021 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_USB_GET_PORT_STATUS
)
1023 IoSkipCurrentIrpStackLocation(Irp
);
1024 Status
= IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
1027 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_USB_RESET_PORT
)
1029 IoSkipCurrentIrpStackLocation(Irp
);
1030 Status
= IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
1033 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_USB_CYCLE_PORT
)
1035 IoSkipCurrentIrpStackLocation(Irp
);
1036 Status
= IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
1042 DPRINT1("IOCTL %x\n", IoStack
->Parameters
.DeviceIoControl
.IoControlCode
);
1043 DPRINT1("InputBufferLength %lu\n", IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
);
1044 DPRINT1("OutputBufferLength %lu\n", IoStack
->Parameters
.DeviceIoControl
.OutputBufferLength
);
1045 DPRINT1("Type3InputBuffer %p\n", IoStack
->Parameters
.DeviceIoControl
.Type3InputBuffer
);
1049 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
1050 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1051 return STATUS_NOT_IMPLEMENTED
;
1057 PDEVICE_OBJECT DeviceObject
,
1060 PIO_STACK_LOCATION IoStack
;
1063 /* get stack location */
1064 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1066 switch(IoStack
->MajorFunction
)
1069 return PDO_HandlePnp(DeviceObject
, Irp
);
1070 case IRP_MJ_INTERNAL_DEVICE_CONTROL
:
1071 return PDO_HandleInternalDeviceControl(DeviceObject
, Irp
);
1073 DPRINT1("PDO_Dispatch Function %x not implemented\n", IoStack
->MajorFunction
);
1074 Status
= Irp
->IoStatus
.Status
;
1075 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);