Revert r42812. As pointed by Michael, one can use

BUSBDevice::GetDescriptor() to retrieve whatever descriptor, including a 
complete configuration descriptor.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42905 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2011-10-24 21:02:14 +00:00
parent d5c8ef5d69
commit 1ce29039cd
4 changed files with 13 additions and 62 deletions
+1 -2
View File
@@ -204,8 +204,7 @@ friend class BUSBDevice;
mutable char * fConfigurationString;
usb_configuration_descriptor* fFullDescriptor;
uint32 fReserved[9];
uint32 fReserved[10];
};
+5 -18
View File
@@ -300,36 +300,23 @@ 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 (length < sizeof(command->config))
return B_BUFFER_OVERFLOW;
size_t descriptorLength = sizeof(usb_configuration_descriptor);
if (op == B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC) {
if (length < sizeof(command->config_etc))
return B_BUFFER_OVERFLOW;
descriptorLength = command->config_etc.length;
}
const usb_configuration_info *configurationInfo =
usb_raw_get_configuration(device, command->config.config_index,
&command->config.status);
if (configurationInfo == NULL)
return B_OK;
const usb_configuration_descriptor* descriptor
= configurationInfo->descr;
if (user_memcpy(command->config.descriptor, descriptor,
min_c(descriptorLength, descriptor->total_length)) != B_OK) {
if (user_memcpy(command->config.descriptor,
configurationInfo->descr,
sizeof(usb_configuration_descriptor)) != B_OK) {
return B_BAD_ADDRESS;
}
if (op == B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC
&& descriptor->total_length > descriptorLength)
command->config.status = B_USB_RAW_STATUS_NO_MEMORY;
else
command->config.status = B_USB_RAW_STATUS_SUCCESS;
command->config.status = B_USB_RAW_STATUS_SUCCESS;
return B_OK;
}
@@ -22,7 +22,6 @@ typedef enum {
B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR,
B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT,
B_USB_RAW_COMMAND_GET_ACTIVE_ALT_INTERFACE_INDEX,
B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC,
B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR_ETC,
B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR_ETC,
B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR_ETC,
@@ -75,13 +74,6 @@ 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;
+6 -33
View File
@@ -8,12 +8,9 @@
#include <USBKit.h>
#include <usb_raw.h>
#include <new>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <new>
BUSBConfiguration::BUSBConfiguration(BUSBDevice *device, uint32 index, int rawFD)
@@ -21,36 +18,14 @@ BUSBConfiguration::BUSBConfiguration(BUSBDevice *device, uint32 index, int rawFD
fIndex(index),
fRawFD(rawFD),
fInterfaces(NULL),
fConfigurationString(NULL),
fFullDescriptor(NULL)
fConfigurationString(NULL)
{
usb_raw_command command;
command.config.descriptor = &fDescriptor;
command.config.config_index = fIndex;
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR,
&command, sizeof(command))
|| command.config.status != B_USB_RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR, &command,
sizeof(command)) || command.config.status != B_USB_RAW_STATUS_SUCCESS)
memset(&fDescriptor, 0, sizeof(fDescriptor));
} else {
// Got the descriptor header, retrieve the whole descriptor
size_t length = fDescriptor.total_length;
fFullDescriptor = (usb_configuration_descriptor*)malloc(length);
if (fFullDescriptor != NULL) {
command.config_etc.descriptor = fFullDescriptor;
command.config_etc.config_index = fIndex;
command.config_etc.length = length;
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC,
&command, sizeof(command))
|| command.config_etc.status != B_USB_RAW_STATUS_SUCCESS) {
free(fFullDescriptor);
fFullDescriptor = NULL;
}
}
}
fInterfaces = new(std::nothrow) BUSBInterface *[
fDescriptor.number_interfaces];
@@ -66,8 +41,6 @@ BUSBConfiguration::BUSBConfiguration(BUSBDevice *device, uint32 index, int rawFD
BUSBConfiguration::~BUSBConfiguration()
{
free(fFullDescriptor);
delete[] fConfigurationString;
if (fInterfaces != NULL) {
for (int32 i = 0; i < fDescriptor.number_interfaces; i++)
@@ -112,7 +85,7 @@ BUSBConfiguration::ConfigurationString() const
const usb_configuration_descriptor *
BUSBConfiguration::Descriptor() const
{
return (fFullDescriptor != NULL) ? fFullDescriptor : &fDescriptor;
return &fDescriptor;
}