| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Matus Dekanek
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libusb
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * @brief USB hub related structures.
|
|---|
| 34 | */
|
|---|
| 35 | #ifndef LIBUSB_CLASS_HUB_H_
|
|---|
| 36 | #define LIBUSB_CLASS_HUB_H_
|
|---|
| 37 |
|
|---|
| 38 | #include <sys/types.h>
|
|---|
| 39 |
|
|---|
| 40 | /** Hub class feature selector.
|
|---|
| 41 | * @warning The constants are not unique (feature selectors are used
|
|---|
| 42 | * for hub and port).
|
|---|
| 43 | */
|
|---|
| 44 | typedef enum {
|
|---|
| 45 | USB_HUB_FEATURE_C_HUB_LOCAL_POWER = 0,
|
|---|
| 46 | USB_HUB_FEATURE_C_HUB_OVER_CURRENT = 1,
|
|---|
| 47 | USB_HUB_FEATURE_PORT_CONNECTION = 0,
|
|---|
| 48 | USB_HUB_FEATURE_PORT_ENABLE = 1,
|
|---|
| 49 | USB_HUB_FEATURE_PORT_SUSPEND = 2,
|
|---|
| 50 | USB_HUB_FEATURE_PORT_OVER_CURRENT = 3,
|
|---|
| 51 | USB_HUB_FEATURE_PORT_RESET = 4,
|
|---|
| 52 | USB_HUB_FEATURE_PORT_POWER = 8,
|
|---|
| 53 | USB_HUB_FEATURE_PORT_LOW_SPEED = 9,
|
|---|
| 54 | USB_HUB_FEATURE_C_PORT_CONNECTION = 16,
|
|---|
| 55 | USB_HUB_FEATURE_C_PORT_ENABLE = 17,
|
|---|
| 56 | USB_HUB_FEATURE_C_PORT_SUSPEND = 18,
|
|---|
| 57 | USB_HUB_FEATURE_C_PORT_OVER_CURRENT = 19,
|
|---|
| 58 | USB_HUB_FEATURE_C_PORT_RESET = 20,
|
|---|
| 59 | /* USB_HUB_FEATURE_ = , */
|
|---|
| 60 | } usb_hub_class_feature_t;
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | /**
|
|---|
| 64 | * @brief usb hub descriptor
|
|---|
| 65 | *
|
|---|
| 66 | * For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2
|
|---|
| 67 | */
|
|---|
| 68 | typedef struct usb_hub_descriptor_type {
|
|---|
| 69 | /** Number of bytes in this descriptor, including this byte */
|
|---|
| 70 | //uint8_t bDescLength;
|
|---|
| 71 |
|
|---|
| 72 | /** Descriptor Type, value: 29H for hub descriptor */
|
|---|
| 73 | //uint8_t bDescriptorType;
|
|---|
| 74 |
|
|---|
| 75 | /** Number of downstream ports that this hub supports */
|
|---|
| 76 | uint8_t ports_count;
|
|---|
| 77 |
|
|---|
| 78 | /**
|
|---|
| 79 | D1...D0: Logical Power Switching Mode
|
|---|
| 80 | 00: Ganged power switching (all ports power at
|
|---|
| 81 | once)
|
|---|
| 82 | 01: Individual port power switching
|
|---|
| 83 | 1X: Reserved. Used only on 1.0 compliant hubs
|
|---|
| 84 | that implement no power switching.
|
|---|
| 85 | D2: Identifies a Compound Device
|
|---|
| 86 | 0: Hub is not part of a compound device
|
|---|
| 87 | 1: Hub is part of a compound device
|
|---|
| 88 | D4...D3: Over-current Protection Mode
|
|---|
| 89 | 00: Global Over-current Protection. The hub
|
|---|
| 90 | reports over-current as a summation of all
|
|---|
| 91 | ports current draw, without a breakdown of
|
|---|
| 92 | individual port over-current status.
|
|---|
| 93 | 01: Individual Port Over-current Protection. The
|
|---|
| 94 | hub reports over-current on a per-port basis.
|
|---|
| 95 | Each port has an over-current indicator.
|
|---|
| 96 | 1X: No Over-current Protection. This option is
|
|---|
| 97 | allowed only for bus-powered hubs that do not
|
|---|
| 98 | implement over-current protection.
|
|---|
| 99 | D15...D5:
|
|---|
| 100 | Reserved
|
|---|
| 101 | */
|
|---|
| 102 | uint16_t hub_characteristics;
|
|---|
| 103 |
|
|---|
| 104 | /**
|
|---|
| 105 | Time (in 2ms intervals) from the time the power-on
|
|---|
| 106 | sequence begins on a port until power is good on that
|
|---|
| 107 | port. The USB System Software uses this value to
|
|---|
| 108 | determine how long to wait before accessing a
|
|---|
| 109 | powered-on port.
|
|---|
| 110 | */
|
|---|
| 111 | uint8_t pwr_on_2_good_time;
|
|---|
| 112 |
|
|---|
| 113 | /**
|
|---|
| 114 | Maximum current requirements of the Hub Controller
|
|---|
| 115 | electronics in mA.
|
|---|
| 116 | */
|
|---|
| 117 | uint8_t current_requirement;
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | Indicates if a port has a removable device attached.
|
|---|
| 121 | This field is reported on byte-granularity. Within a
|
|---|
| 122 | byte, if no port exists for a given location, the field
|
|---|
| 123 | representing the port characteristics returns 0.
|
|---|
| 124 | Bit value definition:
|
|---|
| 125 | 0B - Device is removable
|
|---|
| 126 | 1B - Device is non-removable
|
|---|
| 127 | This is a bitmap corresponding to the individual ports
|
|---|
| 128 | on the hub:
|
|---|
| 129 | Bit 0: Reserved for future use
|
|---|
| 130 | Bit 1: Port 1
|
|---|
| 131 | Bit 2: Port 2
|
|---|
| 132 | ....
|
|---|
| 133 | Bit n: Port n (implementation-dependent, up to a
|
|---|
| 134 | maximum of 255 ports).
|
|---|
| 135 | */
|
|---|
| 136 | uint8_t * devices_removable;
|
|---|
| 137 |
|
|---|
| 138 | /**
|
|---|
| 139 | This field exists for reasons of compatibility with
|
|---|
| 140 | software written for 1.0 compliant devices. All bits in
|
|---|
| 141 | this field should be set to 1B. This field has one bit for
|
|---|
| 142 | each port on the hub with additional pad bits, if
|
|---|
| 143 | necessary, to make the number of bits in the field an
|
|---|
| 144 | integer multiple of 8.
|
|---|
| 145 | */
|
|---|
| 146 | //uint8_t * port_pwr_ctrl_mask;
|
|---|
| 147 | } usb_hub_descriptor_t;
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | /** @brief usb hub specific request types.
|
|---|
| 152 | *
|
|---|
| 153 | * For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2
|
|---|
| 154 | */
|
|---|
| 155 | typedef enum {
|
|---|
| 156 | /** This request resets a value reported in the hub status. */
|
|---|
| 157 | USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE = 0x20,
|
|---|
| 158 | /** This request resets a value reported in the port status. */
|
|---|
| 159 | USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE = 0x23,
|
|---|
| 160 | /** This is an optional per-port diagnostic request that returns the bus state value, as sampled at the last EOF2 point. */
|
|---|
| 161 | USB_HUB_REQ_TYPE_GET_STATE = 0xA3,
|
|---|
| 162 | /** This request returns the hub descriptor. */
|
|---|
| 163 | USB_HUB_REQ_TYPE_GET_DESCRIPTOR = 0xA0,
|
|---|
| 164 | /** This request returns the current hub status and the states that have changed since the previous acknowledgment. */
|
|---|
| 165 | USB_HUB_REQ_TYPE_GET_HUB_STATUS = 0xA0,
|
|---|
| 166 | /** This request returns the current port status and the current value of the port status change bits. */
|
|---|
| 167 | USB_HUB_REQ_TYPE_GET_PORT_STATUS = 0xA3,
|
|---|
| 168 | /** This request overwrites the hub descriptor. */
|
|---|
| 169 | USB_HUB_REQ_TYPE_SET_DESCRIPTOR = 0x20,
|
|---|
| 170 | /** This request sets a value reported in the hub status. */
|
|---|
| 171 | USB_HUB_REQ_TYPE_SET_HUB_FEATURE = 0x20,
|
|---|
| 172 | /** This request sets a value reported in the port status. */
|
|---|
| 173 | USB_HUB_REQ_TYPE_SET_PORT_FEATURE = 0x23
|
|---|
| 174 | } usb_hub_bm_request_type_t;
|
|---|
| 175 |
|
|---|
| 176 | /** @brief hub class request codes*/
|
|---|
| 177 | /// \TODO these are duplicit to standart descriptors
|
|---|
| 178 | typedef enum {
|
|---|
| 179 | /** */
|
|---|
| 180 | USB_HUB_REQUEST_GET_STATUS = 0,
|
|---|
| 181 | /** */
|
|---|
| 182 | USB_HUB_REQUEST_CLEAR_FEATURE = 1,
|
|---|
| 183 | /** */
|
|---|
| 184 | USB_HUB_REQUEST_GET_STATE = 2,
|
|---|
| 185 | /** */
|
|---|
| 186 | USB_HUB_REQUEST_SET_FEATURE = 3,
|
|---|
| 187 | /** */
|
|---|
| 188 | USB_HUB_REQUEST_GET_DESCRIPTOR = 6,
|
|---|
| 189 | /** */
|
|---|
| 190 | USB_HUB_REQUEST_SET_DESCRIPTOR = 7
|
|---|
| 191 | } usb_hub_request_t;
|
|---|
| 192 |
|
|---|
| 193 | /**
|
|---|
| 194 | * Maximum size of usb hub descriptor in bytes
|
|---|
| 195 | */
|
|---|
| 196 | extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE;
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 | #endif
|
|---|
| 205 | /**
|
|---|
| 206 | * @}
|
|---|
| 207 | */
|
|---|