From 5aa70ae1108840c0fbdb3413654ff4536792ef5e Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 6 Apr 2008 19:59:24 +0000 Subject: [PATCH] * Add a AlternateAt() method to the BUSBInterface class that can retrieve the usb_interface_descriptor of an alternate interface without having to switch to it. * Add some reserve bytes to all classes and add some reserved virtual slots where the objects are publically constructable. * Remove the source compatibilty defines that were briding the old USB* with the new BUSB* class names. * Implement the usb_raw side of getting an alternate interface descriptor. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24842 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/libs/usb/USBKit.h | 49 ++++++++++++++----- .../kernel/drivers/bus/usb/usb_raw.cpp | 28 +++++++++++ src/add-ons/kernel/drivers/bus/usb/usb_raw.h | 2 + src/libs/usb/USBInterface.cpp | 22 +++++++++ 4 files changed, 89 insertions(+), 12 deletions(-) diff --git a/headers/libs/usb/USBKit.h b/headers/libs/usb/USBKit.h index c10a9e4f52..07189e66fd 100644 --- a/headers/libs/usb/USBKit.h +++ b/headers/libs/usb/USBKit.h @@ -11,14 +11,6 @@ #include -// Keep compatibility with original USBKit classes -#define USBRoster BUSBRoster -#define USBDevice BUSBDevice -#define USBConfiguration BUSBConfiguration -#define USBInterface BUSBInterface -#define USBEndpoint BUSBEndpoint - - class BUSBRoster; class BUSBDevice; class BUSBConfiguration; @@ -54,7 +46,14 @@ virtual void DeviceRemoved(BUSBDevice *device) = 0; void Stop(); private: +virtual void _ReservedUSBRoster1(); +virtual void _ReservedUSBRoster2(); +virtual void _ReservedUSBRoster3(); +virtual void _ReservedUSBRoster4(); +virtual void _ReservedUSBRoster5(); + void *fLooper; + uint32 fReserved[10]; }; @@ -138,6 +137,12 @@ virtual status_t InitCheck(); void *data) const; private: +virtual void _ReservedUSBDevice1(); +virtual void _ReservedUSBDevice2(); +virtual void _ReservedUSBDevice3(); +virtual void _ReservedUSBDevice4(); +virtual void _ReservedUSBDevice5(); + char *fPath; int fRawFD; @@ -148,6 +153,8 @@ private: mutable char *fManufacturerString; mutable char *fProductString; mutable char *fSerialNumberString; + + uint32 fReserved[10]; }; @@ -195,6 +202,8 @@ friend class BUSBDevice; BUSBInterface **fInterfaces; mutable char *fConfigurationString; + + uint32 fReserved[10]; }; @@ -238,14 +247,26 @@ public: const BUSBEndpoint *EndpointAt(uint32 index) const; // Using CountAlternates() you can retrieve the number of alternate - // interfaces at this interface index. Note that this interface itself + // interfaces for this interface. Note that this interface itself // counts as an alternate so an alternate count of one really means // that you are currently using the sole interface present. + // AlternateAt() returns the interface descriptor of the alternate + // interface with the specified index. Using that you can peek at the + // information contained in the descriptor without having to switch + // to this alternate interface. Note that the alternate index set in + // the interface descriptor returned is not necessarily the same index + // you used to get the descriptor. Always use the zero based index you + // used to get the information with and not the values of the returned + // descriptor as the stack will handle that translation internally. + // The interface descriptor returned was allocated by new and is yours. + // You need to delete it when you're done with it. // With SetAlternate() you can switch this BUSBInterface object to the - // alternate at the specified index. Note that all endpoints retrieved - // through EndpointAt() will become invalid and be deleted as soon as - // you set an alternate. + // alternate interface at the specified index. Note that all endpoints + // retrieved through EndpointAt() will become invalid and will be + // deleted as soon as you set an alternate interface (even if the + // resulting interface is the same you were using before). uint32 CountAlternates() const; + usb_interface_descriptor *AlternateAt(uint32 alternateIndex); status_t SetAlternate(uint32 alternateIndex); private: @@ -264,6 +285,8 @@ friend class BUSBConfiguration; BUSBEndpoint **fEndpoints; mutable char *fInterfaceString; + + uint32 fReserved[10]; }; @@ -331,6 +354,8 @@ friend class BUSBInterface; int fRawFD; usb_endpoint_descriptor fDescriptor; + + uint32 fReserved[10]; }; #endif diff --git a/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp b/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp index e3ee5287b3..892be8fd27 100644 --- a/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp +++ b/src/add-ons/kernel/drivers/bus/usb/usb_raw.cpp @@ -290,6 +290,34 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length) return B_OK; } + case RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR: { + const usb_configuration_info *configurationInfo = + gUSBModule->get_nth_configuration(device->device, + command->alternate.config_index); + if (!configurationInfo) { + command->alternate.status = RAW_STATUS_INVALID_CONFIGURATION; + return B_OK; + } + + if (command->alternate.interface_index >= configurationInfo->interface_count) { + command->alternate.status = RAW_STATUS_INVALID_INTERFACE; + return B_OK; + } + + const usb_interface_list *interfaceList = + &configurationInfo->interface[command->alternate.interface_index]; + if (command->alternate.alternate_index >= interfaceList->alt_count) { + command->alternate.status = RAW_STATUS_INVALID_INTERFACE; + return B_OK; + } + + memcpy(command->alternate.descriptor, + &interfaceList->alt[command->alternate.alternate_index], + sizeof(usb_interface_descriptor)); + command->alternate.status = RAW_STATUS_SUCCESS; + return B_OK; + } + case RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR: { const usb_configuration_info *configurationInfo = gUSBModule->get_nth_configuration(device->device, diff --git a/src/add-ons/kernel/drivers/bus/usb/usb_raw.h b/src/add-ons/kernel/drivers/bus/usb/usb_raw.h index b4824ada4c..318b371c8f 100644 --- a/src/add-ons/kernel/drivers/bus/usb/usb_raw.h +++ b/src/add-ons/kernel/drivers/bus/usb/usb_raw.h @@ -24,6 +24,7 @@ typedef enum { RAW_COMMAND_GET_STRING_DESCRIPTOR, RAW_COMMAND_GET_GENERIC_DESCRIPTOR, RAW_COMMAND_GET_ALT_INTERFACE_COUNT, + RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, RAW_COMMAND_SET_CONFIGURATION = 0x3000, RAW_COMMAND_SET_FEATURE, @@ -83,6 +84,7 @@ typedef union { struct { status_t status; uint32 *alternate_count; + usb_interface_descriptor *descriptor; uint32 config_index; uint32 interface_index; uint32 alternate_index; diff --git a/src/libs/usb/USBInterface.cpp b/src/libs/usb/USBInterface.cpp index c69047e379..988d63cb56 100644 --- a/src/libs/usb/USBInterface.cpp +++ b/src/libs/usb/USBInterface.cpp @@ -157,6 +157,28 @@ BUSBInterface::CountAlternates() const } +usb_interface_descriptor * +BUSBInterface::AlternateAt(uint32 alternateIndex) +{ + usb_interface_descriptor *descriptor = new usb_interface_descriptor; + if (descriptor == NULL) + return NULL; + + raw_command command; + command.alternate.descriptor = descriptor; + command.alternate.config_index = fConfiguration->Index(); + command.alternate.interface_index = fIndex; + command.alternate.alternate_index = alternateIndex; + if (ioctl(fRawFD, RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, &command, + sizeof(command)) || command.alternate.status != RAW_STATUS_SUCCESS) { + delete descriptor; + return NULL; + } + + return descriptor; +} + + status_t BUSBInterface::SetAlternate(uint32 alternateIndex) {