[USBCCGP]

- Fix retrieving string descriptors

svn path=/trunk/; revision=55818
This commit is contained in:
Johannes Anderwald 2012-02-22 21:26:36 +00:00
parent 17f35a7781
commit eadaa2c3de
3 changed files with 71 additions and 6 deletions

View file

@ -94,6 +94,64 @@ USBCCGP_GetDescriptor(
return Status;
}
NTSTATUS
NTAPI
USBCCGP_GetStringDescriptor(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG DescriptorLength,
IN UCHAR DescriptorIndex,
IN LANGID LanguageId,
OUT PVOID *OutDescriptor)
{
NTSTATUS Status;
PUSB_STRING_DESCRIPTOR StringDescriptor;
ULONG Size;
PVOID Buffer;
// retrieve descriptor
Status = USBCCGP_GetDescriptor(DeviceObject, USB_STRING_DESCRIPTOR_TYPE, DescriptorLength, DescriptorIndex, LanguageId, OutDescriptor);
if (!NT_SUCCESS(Status))
{
// failed
return Status;
}
// get descriptor structure
StringDescriptor = (PUSB_STRING_DESCRIPTOR)*OutDescriptor;
// sanity check
ASSERT(StringDescriptor->bLength < DescriptorLength - 2);
if (StringDescriptor->bLength == 2)
{
// invalid descriptor
FreeItem(StringDescriptor);
return STATUS_DEVICE_DATA_ERROR;
}
// calculate size
Size = StringDescriptor->bLength + sizeof(WCHAR);
// allocate buffer
Buffer = AllocateItem(NonPagedPool, Size);
if (!Buffer)
{
// no memory
FreeItem(StringDescriptor);
return STATUS_INSUFFICIENT_RESOURCES;
}
// copy result
RtlCopyMemory(Buffer, StringDescriptor->bString, Size - FIELD_OFFSET(USB_STRING_DESCRIPTOR, bString));
// free buffer
FreeItem(StringDescriptor);
// store result
*OutDescriptor = (PVOID)Buffer;
return STATUS_SUCCESS;
}
NTSTATUS
USBCCGP_GetDescriptors(

View file

@ -365,8 +365,7 @@ USBCCGP_InitFunctionDescriptor(
//
// get interface description
//
Status = USBCCGP_GetDescriptor(FDODeviceExtension->NextDeviceObject,
USB_STRING_DESCRIPTOR_TYPE,
Status = USBCCGP_GetStringDescriptor(FDODeviceExtension->NextDeviceObject,
100 * sizeof(WCHAR),
Descriptor->iFunction,
0x0409, //FIXME
@ -530,10 +529,9 @@ USBCCG_InitIdsWithInterfaceDescriptor(
//
// get interface description
//
Status = USBCCGP_GetDescriptor(FDODeviceExtension->NextDeviceObject,
USB_STRING_DESCRIPTOR_TYPE,
100 * sizeof(WCHAR),
Descriptor->iInterface,
Status = USBCCGP_GetStringDescriptor(FDODeviceExtension->NextDeviceObject,
100 * sizeof(WCHAR),
Descriptor->iInterface,
0x0409, //FIXME
(PVOID*)&DescriptionBuffer);
if (!NT_SUCCESS(Status))

View file

@ -84,6 +84,15 @@ USBCCGP_GetDescriptor(
IN LANGID LanguageId,
OUT PVOID *OutDescriptor);
NTSTATUS
NTAPI
USBCCGP_GetStringDescriptor(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG DescriptorLength,
IN UCHAR DescriptorIndex,
IN LANGID LanguageId,
OUT PVOID *OutDescriptor);
ULONG
CountInterfaceDescriptors(
IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor);