Update B_USB_RAW_COMMAND_GET_DESCRIPTOR to support retrieving

up to total_length a configuration descriptor.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42907 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2011-10-25 06:19:49 +00:00
parent 62605d2824
commit cc6dd72fbb

View File

@ -545,21 +545,31 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
return B_BUFFER_OVERFLOW;
size_t actualLength = 0;
uint8 firstTwoBytes[2];
uint8 firstBytes[4];
size_t bytesNeeded =
command->descriptor.type == USB_DESCRIPTOR_CONFIGURATION ?
4 : 2;
if (gUSBModule->get_descriptor(device->device,
command->descriptor.type, command->descriptor.index,
command->descriptor.language_id, firstTwoBytes, 2,
command->descriptor.language_id, firstBytes, bytesNeeded,
&actualLength) < B_OK
|| actualLength != 2
|| firstTwoBytes[1] != command->descriptor.type) {
|| actualLength != bytesNeeded
|| firstBytes[1] != command->descriptor.type) {
command->descriptor.status = B_USB_RAW_STATUS_ABORTED;
command->descriptor.length = 0;
return B_OK;
}
uint8 descriptorLength = MIN(firstTwoBytes[0],
command->descriptor.length);
uint8 descriptorLength = firstBytes[0];
if (command->descriptor.type == USB_DESCRIPTOR_CONFIGURATION) {
// configuration complete descriptor total length is
// bigger than just its header size
descriptorLength =
((usb_configuration_descriptor*)firstBytes)->total_length;
}
descriptorLength = MIN(descriptorLength, command->descriptor.length);
uint8 *descriptorBuffer = (uint8 *)malloc(descriptorLength);
if (descriptorBuffer == NULL) {
command->descriptor.status = B_USB_RAW_STATUS_ABORTED;