[haiku-commits] r42905 - in haiku/trunk: headers/os/device src/add-ons/kernel/drivers/bus/usb src/kits/device

  • From: philippe.houdoin@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 24 Oct 2011 23:02:14 +0200 (CEST)

Author: phoudoin
Date: 2011-10-24 23:02:14 +0200 (Mon, 24 Oct 2011)
New Revision: 42905
Changeset: https://dev.haiku-os.org/changeset/42905

Modified:
   haiku/trunk/headers/os/device/USBKit.h
   haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp
   haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.h
   haiku/trunk/src/kits/device/USBConfiguration.cpp
Log:
Revert r42812. As pointed by Michael, one can use 
BUSBDevice::GetDescriptor() to retrieve whatever descriptor, including a 
complete configuration descriptor.


Modified: haiku/trunk/headers/os/device/USBKit.h
===================================================================
--- haiku/trunk/headers/os/device/USBKit.h      2011-10-24 17:53:22 UTC (rev 
42904)
+++ haiku/trunk/headers/os/device/USBKit.h      2011-10-24 21:02:14 UTC (rev 
42905)
@@ -204,8 +204,7 @@
 
 mutable        char *                                          
fConfigurationString;
 
-               usb_configuration_descriptor*   fFullDescriptor;
-               uint32                                          fReserved[9];
+               uint32                                          fReserved[10];
 };
 
 

Modified: haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp  2011-10-24 
17:53:22 UTC (rev 42904)
+++ haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp  2011-10-24 
21:02:14 UTC (rev 42905)
@@ -300,36 +300,23 @@
                }
 
                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;
                }
 

Modified: haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.h
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.h    2011-10-24 
17:53:22 UTC (rev 42904)
+++ haiku/trunk/src/add-ons/kernel/drivers/bus/usb/usb_raw.h    2011-10-24 
21:02:14 UTC (rev 42905)
@@ -22,11 +22,10 @@
        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,
-       
+
        B_USB_RAW_COMMAND_SET_CONFIGURATION = 0x3000,
        B_USB_RAW_COMMAND_SET_FEATURE,
        B_USB_RAW_COMMAND_CLEAR_FEATURE,
@@ -77,13 +76,6 @@
 
        struct {
                status_t                                                status;
-               usb_configuration_descriptor    *descriptor;
-               uint32                                                  
config_index;
-               size_t                                                  length;
-       } config_etc;
-
-       struct {
-               status_t                                                status;
                uint32                                                  
alternate_info;
                uint32                                                  
config_index;
                uint32                                                  
interface_index;

Modified: haiku/trunk/src/kits/device/USBConfiguration.cpp
===================================================================
--- haiku/trunk/src/kits/device/USBConfiguration.cpp    2011-10-24 17:53:22 UTC 
(rev 42904)
+++ haiku/trunk/src/kits/device/USBConfiguration.cpp    2011-10-24 21:02:14 UTC 
(rev 42905)
@@ -8,50 +8,25 @@
 
 #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)
        :       fDevice(device),
                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];
        if (fInterfaces == NULL)
@@ -66,8 +41,6 @@
 
 BUSBConfiguration::~BUSBConfiguration()
 {
-       free(fFullDescriptor);
-
        delete[] fConfigurationString;
        if (fInterfaces != NULL) {
                for (int32 i = 0; i < fDescriptor.number_interfaces; i++)
@@ -112,7 +85,7 @@
 const usb_configuration_descriptor *
 BUSBConfiguration::Descriptor() const
 {
-       return (fFullDescriptor != NULL) ? fFullDescriptor : &fDescriptor;
+       return &fDescriptor;
 }
 
 


Other related posts:

  • » [haiku-commits] r42905 - in haiku/trunk: headers/os/device src/add-ons/kernel/drivers/bus/usb src/kits/device - philippe . houdoin