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
;
280 return Irp
->IoStatus
.Status
;
286 ASSERT(DeviceString
!= NULL
);
291 Buffer
= AllocateItem(NonPagedPool
, DeviceString
->Length
+ sizeof(WCHAR
));
297 return STATUS_INSUFFICIENT_RESOURCES
;
303 RtlCopyMemory(Buffer
, DeviceString
->Buffer
, DeviceString
->Length
);
304 Buffer
[DeviceString
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
305 Irp
->IoStatus
.Information
= (ULONG_PTR
)Buffer
;
307 return STATUS_SUCCESS
;
312 PDEVICE_OBJECT DeviceObject
,
315 PIO_STACK_LOCATION IoStack
;
316 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
321 // get current stack location
323 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
326 // get device extension
328 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
333 ASSERT(PDODeviceExtension
->Common
.IsFDO
== FALSE
);
335 switch(IoStack
->MinorFunction
)
337 case IRP_MN_QUERY_DEVICE_RELATIONS
:
340 // handle device relations
342 Status
= USBCCGP_PdoHandleDeviceRelations(DeviceObject
, Irp
);
345 case IRP_MN_QUERY_DEVICE_TEXT
:
348 // handle query device text
350 Status
= USBCCGP_PdoHandleQueryDeviceText(DeviceObject
, Irp
);
353 case IRP_MN_QUERY_ID
:
358 Status
= USBCCGP_PdoHandleQueryId(DeviceObject
, Irp
);
361 case IRP_MN_REMOVE_DEVICE
:
364 // remove us from the fdo's pdo list
367 for(Index
= 0; Index
< PDODeviceExtension
->FDODeviceExtension
->FunctionDescriptorCount
; Index
++)
369 if (PDODeviceExtension
->FDODeviceExtension
->ChildPDO
[Index
] == DeviceObject
)
374 PDODeviceExtension
->FDODeviceExtension
->ChildPDO
[Index
] = NULL
;
383 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
384 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
389 // Delete the device object
391 IoDeleteDevice(DeviceObject
);
393 return STATUS_SUCCESS
;
395 case IRP_MN_QUERY_CAPABILITIES
:
398 // copy device capabilities
400 RtlCopyMemory(IoStack
->Parameters
.DeviceCapabilities
.Capabilities
, &PDODeviceExtension
->Capabilities
, sizeof(DEVICE_CAPABILITIES
));
402 /* Complete the IRP */
403 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
404 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
405 return STATUS_SUCCESS
;
407 case IRP_MN_QUERY_REMOVE_DEVICE
:
408 case IRP_MN_QUERY_STOP_DEVICE
:
413 Status
= STATUS_SUCCESS
;
416 case IRP_MN_START_DEVICE
:
421 DPRINT("[USBCCGP] PDO IRP_MN_START\n");
422 Status
= STATUS_SUCCESS
;
425 case IRP_MN_QUERY_INTERFACE
:
428 // forward to lower device object
430 IoSkipCurrentIrpStackLocation(Irp
);
431 return IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
438 Status
= Irp
->IoStatus
.Status
;
446 if (Status
!= STATUS_PENDING
)
451 Irp
->IoStatus
.Status
= Status
;
456 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
467 USBCCGP_BuildConfigurationDescriptor(
468 PDEVICE_OBJECT DeviceObject
,
471 PIO_STACK_LOCATION IoStack
;
472 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
473 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
;
474 PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
475 ULONG TotalSize
, Index
;
479 UCHAR InterfaceNumber
;
482 // get current stack location
484 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
486 DPRINT("USBCCGP_BuildConfigurationDescriptor\n");
489 // get device extension
491 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
494 // get configuration descriptor
496 ConfigurationDescriptor
= PDODeviceExtension
->ConfigurationDescriptor
;
499 // calculate size of configuration descriptor
501 TotalSize
= sizeof(USB_CONFIGURATION_DESCRIPTOR
);
503 for(Index
= 0; Index
< PDODeviceExtension
->FunctionDescriptor
->NumberOfInterfaces
; Index
++)
506 // get current interface descriptor
508 InterfaceDescriptor
= PDODeviceExtension
->FunctionDescriptor
->InterfaceDescriptorList
[Index
];
509 InterfaceNumber
= InterfaceDescriptor
->bInterfaceNumber
;
512 // add to size and move to next descriptor
514 TotalSize
+= InterfaceDescriptor
->bLength
;
515 InterfaceDescriptor
= (PUSB_INTERFACE_DESCRIPTOR
)((ULONG_PTR
)InterfaceDescriptor
+ InterfaceDescriptor
->bLength
);
519 if ((ULONG_PTR
)InterfaceDescriptor
>= ((ULONG_PTR
)ConfigurationDescriptor
+ ConfigurationDescriptor
->wTotalLength
))
522 // reached end of configuration descriptor
528 // association descriptors are removed
530 if (InterfaceDescriptor
->bDescriptorType
!= USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE
)
532 if (InterfaceDescriptor
->bDescriptorType
== USB_INTERFACE_DESCRIPTOR_TYPE
)
534 if (InterfaceNumber
!= InterfaceDescriptor
->bInterfaceNumber
)
537 // reached next descriptor
543 // include alternate descriptor
550 TotalSize
+= InterfaceDescriptor
->bLength
;
554 // move to next descriptor
556 InterfaceDescriptor
= (PUSB_INTERFACE_DESCRIPTOR
)((ULONG_PTR
)InterfaceDescriptor
+ InterfaceDescriptor
->bLength
);
561 // now allocate temporary buffer for the configuration descriptor
563 Buffer
= AllocateItem(NonPagedPool
, TotalSize
);
567 // failed to allocate buffer
569 DPRINT1("[USBCCGP] Failed to allocate %lu Bytes\n", TotalSize
);
570 return STATUS_INSUFFICIENT_RESOURCES
;
574 // first copy the configuration descriptor
576 RtlCopyMemory(Buffer
, ConfigurationDescriptor
, sizeof(USB_CONFIGURATION_DESCRIPTOR
));
577 BufferPtr
= (PUCHAR
)((ULONG_PTR
)Buffer
+ ConfigurationDescriptor
->bLength
);
579 for(Index
= 0; Index
< PDODeviceExtension
->FunctionDescriptor
->NumberOfInterfaces
; Index
++)
582 // get current interface descriptor
584 InterfaceDescriptor
= PDODeviceExtension
->FunctionDescriptor
->InterfaceDescriptorList
[Index
];
585 InterfaceNumber
= InterfaceDescriptor
->bInterfaceNumber
;
588 // copy descriptor and move to next descriptor
590 RtlCopyMemory(BufferPtr
, InterfaceDescriptor
, InterfaceDescriptor
->bLength
);
591 BufferPtr
+= InterfaceDescriptor
->bLength
;
592 InterfaceDescriptor
= (PUSB_INTERFACE_DESCRIPTOR
)((ULONG_PTR
)InterfaceDescriptor
+ InterfaceDescriptor
->bLength
);
596 if ((ULONG_PTR
)InterfaceDescriptor
>= ((ULONG_PTR
)ConfigurationDescriptor
+ ConfigurationDescriptor
->wTotalLength
))
599 // reached end of configuration descriptor
605 // association descriptors are removed
607 if (InterfaceDescriptor
->bDescriptorType
!= USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE
)
609 if (InterfaceDescriptor
->bDescriptorType
== USB_INTERFACE_DESCRIPTOR_TYPE
)
611 if (InterfaceNumber
!= InterfaceDescriptor
->bInterfaceNumber
)
614 // reached next descriptor
620 // include alternate descriptor
622 DPRINT("InterfaceDescriptor %p Alternate %x InterfaceNumber %x\n", InterfaceDescriptor
, InterfaceDescriptor
->bAlternateSetting
, InterfaceDescriptor
->bInterfaceNumber
);
628 RtlCopyMemory(BufferPtr
, InterfaceDescriptor
, InterfaceDescriptor
->bLength
);
629 BufferPtr
+= InterfaceDescriptor
->bLength
;
633 // move to next descriptor
635 InterfaceDescriptor
= (PUSB_INTERFACE_DESCRIPTOR
)((ULONG_PTR
)InterfaceDescriptor
+ InterfaceDescriptor
->bLength
);
640 // modify configuration descriptor
642 ConfigurationDescriptor
= Buffer
;
643 ConfigurationDescriptor
->wTotalLength
= TotalSize
;
644 ConfigurationDescriptor
->bNumInterfaces
= PDODeviceExtension
->FunctionDescriptor
->NumberOfInterfaces
;
649 Urb
= (PURB
)IoStack
->Parameters
.Others
.Argument1
;
655 RtlCopyMemory(Urb
->UrbControlDescriptorRequest
.TransferBuffer
, Buffer
, min(TotalSize
, Urb
->UrbControlDescriptorRequest
.TransferBufferLength
));
660 Urb
->UrbControlDescriptorRequest
.TransferBufferLength
= TotalSize
;
670 return STATUS_SUCCESS
;
674 USBCCGP_PDOSelectConfiguration(
675 PDEVICE_OBJECT DeviceObject
,
678 PIO_STACK_LOCATION IoStack
;
679 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
681 PUSBD_INTERFACE_INFORMATION InterfaceInformation
;
682 ULONG InterfaceIndex
, Length
;
683 PUSBD_INTERFACE_LIST_ENTRY Entry
;
684 ULONG NeedSelect
, FoundInterface
;
688 // get current stack location
690 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
693 // get device extension
695 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
700 Urb
= (PURB
)IoStack
->Parameters
.Others
.Argument1
;
704 // is there already an configuration handle
706 if (Urb
->UrbSelectConfiguration
.ConfigurationHandle
)
711 return STATUS_SUCCESS
;
715 //C_ASSERT(sizeof(struct _URB_HEADER) == 16);
716 //C_ASSERT(FIELD_OFFSET(struct _URB_SELECT_CONFIGURATION, Interface.Length) == 24);
717 //C_ASSERT(sizeof(USBD_INTERFACE_INFORMATION) == 36);
718 //C_ASSERT(sizeof(struct _URB_SELECT_CONFIGURATION) == 0x3C);
720 // available buffer length
721 Length
= Urb
->UrbSelectConfiguration
.Hdr
.Length
- FIELD_OFFSET(struct _URB_SELECT_CONFIGURATION
, Interface
.Length
);
724 // check all interfaces
726 InterfaceInformation
= &Urb
->UrbSelectConfiguration
.Interface
;
731 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
);
732 ASSERT(InterfaceInformation
->Length
);
734 // search for the interface in the local interface list
736 FoundInterface
= FALSE
;
737 for(InterfaceIndex
= 0; InterfaceIndex
< PDODeviceExtension
->FunctionDescriptor
->NumberOfInterfaces
; InterfaceIndex
++)
739 if (PDODeviceExtension
->FunctionDescriptor
->InterfaceDescriptorList
[InterfaceIndex
]->bInterfaceNumber
== InterfaceInformation
->InterfaceNumber
)
741 // found interface entry
742 FoundInterface
= TRUE
;
752 DPRINT1("InterfaceInformation InterfaceNumber %x Alternative %x NumberOfPipes %x not found\n", InterfaceInformation
->InterfaceNumber
, InterfaceInformation
->AlternateSetting
, InterfaceInformation
->NumberOfPipes
);
754 return STATUS_INVALID_PARAMETER
;
758 // now query the total interface list
761 for(InterfaceIndex
= 0; InterfaceIndex
< PDODeviceExtension
->InterfaceListCount
; InterfaceIndex
++)
763 if (PDODeviceExtension
->InterfaceList
[InterfaceIndex
].Interface
->InterfaceNumber
== InterfaceInformation
->InterfaceNumber
)
768 Entry
= &PDODeviceExtension
->InterfaceList
[InterfaceIndex
];
779 // corruption detected
785 if (Entry
->InterfaceDescriptor
->bAlternateSetting
== InterfaceInformation
->AlternateSetting
)
788 for(InterfaceIndex
= 0; InterfaceIndex
< InterfaceInformation
->NumberOfPipes
; InterfaceIndex
++)
790 if (InterfaceInformation
->Pipes
[InterfaceIndex
].MaximumTransferSize
!= Entry
->Interface
->Pipes
[InterfaceIndex
].MaximumTransferSize
)
802 // need select as the interface number differ
810 // interface is already selected
812 ASSERT(Length
>= Entry
->Interface
->Length
);
813 RtlCopyMemory(InterfaceInformation
, Entry
->Interface
, Entry
->Interface
->Length
);
816 // adjust remaining buffer size
818 ASSERT(Entry
->Interface
->Length
);
819 Length
-= Entry
->Interface
->Length
;
822 // move to next output interface information
824 InterfaceInformation
= (PUSBD_INTERFACE_INFORMATION
)((ULONG_PTR
)InterfaceInformation
+ Entry
->Interface
->Length
);
831 DPRINT1("Selecting InterfaceIndex %lu AlternateSetting %lu NumberOfPipes %lu\n", InterfaceInformation
->InterfaceNumber
, InterfaceInformation
->AlternateSetting
, InterfaceInformation
->NumberOfPipes
);
832 ASSERT(InterfaceInformation
->Length
== Entry
->Interface
->Length
);
837 NewUrb
= AllocateItem(NonPagedPool
, GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceInformation
->NumberOfPipes
));
843 return STATUS_INSUFFICIENT_RESOURCES
;
847 // now prepare interface urb
849 UsbBuildSelectInterfaceRequest(NewUrb
, GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceInformation
->NumberOfPipes
), PDODeviceExtension
->ConfigurationHandle
, InterfaceInformation
->InterfaceNumber
, InterfaceInformation
->AlternateSetting
);
852 // now select the interface
854 Status
= USBCCGP_SyncUrbRequest(PDODeviceExtension
->NextDeviceObject
, NewUrb
);
855 DPRINT1("SelectInterface Status %x\n", Status
);
857 if (!NT_SUCCESS(Status
))
866 // update configuration info
868 ASSERT(Entry
->Interface
->Length
>= NewUrb
->UrbSelectInterface
.Interface
.Length
);
869 ASSERT(Length
>= NewUrb
->UrbSelectInterface
.Interface
.Length
);
870 RtlCopyMemory(Entry
->Interface
, &NewUrb
->UrbSelectInterface
.Interface
, NewUrb
->UrbSelectInterface
.Interface
.Length
);
873 // update provided interface information
875 ASSERT(Length
>= Entry
->Interface
->Length
);
876 RtlCopyMemory(InterfaceInformation
, Entry
->Interface
, Entry
->Interface
->Length
);
879 // decrement remaining buffer size
881 ASSERT(Entry
->Interface
->Length
);
882 Length
-= Entry
->Interface
->Length
;
885 // adjust output buffer offset
887 InterfaceInformation
= (PUSBD_INTERFACE_INFORMATION
)((ULONG_PTR
)InterfaceInformation
+ Entry
->Interface
->Length
);
898 // store configuration handle
900 Urb
->UrbSelectConfiguration
.ConfigurationHandle
= PDODeviceExtension
->ConfigurationHandle
;
902 DPRINT1("[USBCCGP] SelectConfiguration Function %x Completed\n", PDODeviceExtension
->FunctionDescriptor
->FunctionNumber
);
907 return STATUS_SUCCESS
;
911 PDO_HandleInternalDeviceControl(
912 PDEVICE_OBJECT DeviceObject
,
915 PIO_STACK_LOCATION IoStack
;
916 PPDO_DEVICE_EXTENSION PDODeviceExtension
;
921 // get current stack location
923 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
926 // get device extension
928 PDODeviceExtension
= (PPDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
930 if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_USB_SUBMIT_URB
)
935 Urb
= (PURB
)IoStack
->Parameters
.Others
.Argument1
;
937 DPRINT("IOCTL_INTERNAL_USB_SUBMIT_URB Function %x\n", Urb
->UrbHeader
.Function
);
939 if (Urb
->UrbHeader
.Function
== URB_FUNCTION_SELECT_CONFIGURATION
)
942 // select configuration
944 Status
= USBCCGP_PDOSelectConfiguration(DeviceObject
, Irp
);
945 Irp
->IoStatus
.Status
= Status
;
946 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
949 else if (Urb
->UrbHeader
.Function
== URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
)
951 if(Urb
->UrbControlDescriptorRequest
.DescriptorType
== USB_DEVICE_DESCRIPTOR_TYPE
)
954 // is the buffer big enough
956 if (Urb
->UrbControlDescriptorRequest
.TransferBufferLength
< sizeof(USB_DEVICE_DESCRIPTOR
))
959 // invalid buffer size
961 DPRINT1("[USBCCGP] invalid device descriptor size %lu\n", Urb
->UrbControlDescriptorRequest
.TransferBufferLength
);
962 Urb
->UrbControlDescriptorRequest
.TransferBufferLength
= sizeof(USB_DEVICE_DESCRIPTOR
);
963 Irp
->IoStatus
.Status
= STATUS_INVALID_BUFFER_SIZE
;
964 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
965 return STATUS_INVALID_BUFFER_SIZE
;
969 // copy device descriptor
971 ASSERT(Urb
->UrbControlDescriptorRequest
.TransferBuffer
);
972 RtlCopyMemory(Urb
->UrbControlDescriptorRequest
.TransferBuffer
, &PDODeviceExtension
->DeviceDescriptor
, sizeof(USB_DEVICE_DESCRIPTOR
));
973 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
974 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
975 return STATUS_SUCCESS
;
977 else if (Urb
->UrbControlDescriptorRequest
.DescriptorType
== USB_CONFIGURATION_DESCRIPTOR_TYPE
)
980 // build configuration descriptor
982 Status
= USBCCGP_BuildConfigurationDescriptor(DeviceObject
, Irp
);
983 Irp
->IoStatus
.Status
= Status
;
984 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
987 else if (Urb
->UrbControlDescriptorRequest
.DescriptorType
== USB_STRING_DESCRIPTOR_TYPE
)
989 PUSB_STRING_DESCRIPTOR StringDescriptor
;
992 // get the requested string descriptor
994 ASSERT(Urb
->UrbControlDescriptorRequest
.TransferBuffer
);
995 Status
= USBCCGP_GetDescriptor(PDODeviceExtension
->FDODeviceExtension
->NextDeviceObject
,
996 USB_STRING_DESCRIPTOR_TYPE
,
997 Urb
->UrbControlDescriptorRequest
.TransferBufferLength
,
998 Urb
->UrbControlDescriptorRequest
.Index
,
999 Urb
->UrbControlDescriptorRequest
.LanguageId
,
1000 (PVOID
*)&StringDescriptor
);
1001 if (NT_SUCCESS(Status
))
1003 if (StringDescriptor
->bLength
== 2)
1005 FreeItem(StringDescriptor
);
1006 Status
= STATUS_DEVICE_DATA_ERROR
;
1010 RtlCopyMemory(Urb
->UrbControlDescriptorRequest
.TransferBuffer
,
1011 StringDescriptor
->bString
,
1012 StringDescriptor
->bLength
+ sizeof(WCHAR
));
1013 FreeItem(StringDescriptor
);
1014 Status
= STATUS_SUCCESS
;
1017 Irp
->IoStatus
.Status
= Status
;
1018 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1024 IoSkipCurrentIrpStackLocation(Irp
);
1025 Status
= IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
1029 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_USB_GET_PORT_STATUS
)
1031 IoSkipCurrentIrpStackLocation(Irp
);
1032 Status
= IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
1035 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_USB_RESET_PORT
)
1037 IoSkipCurrentIrpStackLocation(Irp
);
1038 Status
= IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
1041 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_USB_CYCLE_PORT
)
1043 IoSkipCurrentIrpStackLocation(Irp
);
1044 Status
= IoCallDriver(PDODeviceExtension
->NextDeviceObject
, Irp
);
1050 DPRINT1("IOCTL %x\n", IoStack
->Parameters
.DeviceIoControl
.IoControlCode
);
1051 DPRINT1("InputBufferLength %lu\n", IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
);
1052 DPRINT1("OutputBufferLength %lu\n", IoStack
->Parameters
.DeviceIoControl
.OutputBufferLength
);
1053 DPRINT1("Type3InputBuffer %p\n", IoStack
->Parameters
.DeviceIoControl
.Type3InputBuffer
);
1057 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
1058 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1059 return STATUS_NOT_IMPLEMENTED
;
1065 PDEVICE_OBJECT DeviceObject
,
1068 PIO_STACK_LOCATION IoStack
;
1071 /* get stack location */
1072 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1074 switch(IoStack
->MajorFunction
)
1077 return PDO_HandlePnp(DeviceObject
, Irp
);
1078 case IRP_MJ_INTERNAL_DEVICE_CONTROL
:
1079 return PDO_HandleInternalDeviceControl(DeviceObject
, Irp
);
1081 DPRINT1("PDO_Dispatch Function %x not implemented\n", IoStack
->MajorFunction
);
1082 Status
= Irp
->IoStatus
.Status
;
1083 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);