usb: support for retrieving full configuration descriptors
In USB, the interface and endpoint descriptors, and possibly other vendor-specific descriptors, are nested inside the configuration descriptors. This makes it possible to retrieve the complete information about a configuration in one single call. Our drivers do this, and so does libusb (the Device Kit doesn't, it only cares about individual descriptors and does not provide access to the vendor-specific ones). The driver did not expose the full descriptor, only the part that belongs strictly to the configuration. libusb worked around this by getting the descriptor from the device directly, using a control transfer. This should be ok, but apparently some devices get confused when you do this too often or at unexpected times. These changes introduce a variation of the GET_CONFIGURATION_DESCRIPTOR ioctl that allows the caller to specify a size. This way, one can get the complete descriptor (after getting the configuration-only part to figure out the size needed, most likely). The data is copied from structures stored by the driver, so no further communication with the device is necessary, making this safe to the problems mentioned above, and faster. Change-Id: Id97e40ea0d45b8c051ae8548486c4751fc6aad2a Reviewed-on: https://review.haiku-os.org/453 Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
1d404e45f1
commit
b24d095e90
@@ -1,15 +1,17 @@
|
||||
/*
|
||||
* Copyright 2006-2010, Haiku Inc. All rights reserved.
|
||||
* Copyright 2006-2018, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Lotz <[email protected]>
|
||||
* Adrien Destugues <[email protected]>
|
||||
*/
|
||||
|
||||
#include "usb_raw.h"
|
||||
|
||||
#include <KernelExport.h>
|
||||
#include <Drivers.h>
|
||||
#include <algorithm>
|
||||
#include <lock.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
@@ -311,7 +313,12 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
}
|
||||
|
||||
case B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR:
|
||||
case B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC:
|
||||
{
|
||||
if (op == B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC
|
||||
&& length < sizeof(command.config_etc))
|
||||
return B_BUFFER_OVERFLOW;
|
||||
|
||||
if (length < sizeof(command.config))
|
||||
return B_BUFFER_OVERFLOW;
|
||||
|
||||
@@ -322,10 +329,15 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
if (configurationInfo == NULL)
|
||||
break;
|
||||
|
||||
size_t sizeToCopy = sizeof(usb_configuration_descriptor);
|
||||
if (op == B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC) {
|
||||
sizeToCopy = std::min(command.config_etc.length,
|
||||
(size_t)configurationInfo->descr->total_length);
|
||||
}
|
||||
|
||||
if (!IS_USER_ADDRESS(command.config.descriptor)
|
||||
|| user_memcpy(command.config.descriptor,
|
||||
configurationInfo->descr,
|
||||
sizeof(usb_configuration_descriptor)) != B_OK) {
|
||||
configurationInfo->descr, sizeToCopy) != B_OK) {
|
||||
return B_BAD_ADDRESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ typedef enum {
|
||||
B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR_ETC,
|
||||
B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR_ETC,
|
||||
B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR_ETC,
|
||||
B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC,
|
||||
|
||||
B_USB_RAW_COMMAND_SET_CONFIGURATION = 0x3000,
|
||||
B_USB_RAW_COMMAND_SET_FEATURE,
|
||||
@@ -74,6 +75,13 @@ typedef union {
|
||||
uint32 config_index;
|
||||
} config;
|
||||
|
||||
struct {
|
||||
status_t status;
|
||||
usb_configuration_descriptor *descriptor;
|
||||
uint32 config_index;
|
||||
size_t length;
|
||||
} config_etc;
|
||||
|
||||
struct {
|
||||
status_t status;
|
||||
uint32 alternate_info;
|
||||
|
||||
Reference in New Issue
Block a user