| 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_HUB_LOCAL_POWER = 0,
|
|---|
| 48 | USB_HUB_FEATURE_HUB_OVER_CURRENT = 1,
|
|---|
| 49 | USB_HUB_FEATURE_PORT_CONNECTION = 0,
|
|---|
| 50 | USB_HUB_FEATURE_PORT_ENABLE = 1,
|
|---|
| 51 | USB_HUB_FEATURE_PORT_SUSPEND = 2,
|
|---|
| 52 | USB_HUB_FEATURE_PORT_OVER_CURRENT = 3,
|
|---|
| 53 | USB_HUB_FEATURE_PORT_RESET = 4,
|
|---|
| 54 | USB_HUB_FEATURE_PORT_POWER = 8,
|
|---|
| 55 | USB_HUB_FEATURE_PORT_LOW_SPEED = 9,
|
|---|
| 56 | USB_HUB_FEATURE_PORT_HIGH_SPEED = 10,
|
|---|
| 57 | USB_HUB_FEATURE_C_PORT_CONNECTION = 16,
|
|---|
| 58 | USB_HUB_FEATURE_C_PORT_ENABLE = 17,
|
|---|
| 59 | USB_HUB_FEATURE_C_PORT_SUSPEND = 18,
|
|---|
| 60 | USB_HUB_FEATURE_C_PORT_OVER_CURRENT = 19,
|
|---|
| 61 | USB_HUB_FEATURE_C_PORT_RESET = 20,
|
|---|
| 62 | USB_HUB_FEATURE_PORT_TEST = 21,
|
|---|
| 63 | USB_HUB_FEATURE_PORT_INDICATOR = 22
|
|---|
| 64 | /* USB_HUB_FEATURE_ = , */
|
|---|
| 65 | } usb_hub_class_feature_t;
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | /** Header of standard hub descriptor without the "variadic" part. */
|
|---|
| 69 | typedef struct {
|
|---|
| 70 | /** Descriptor length. */
|
|---|
| 71 | uint8_t length;
|
|---|
| 72 |
|
|---|
| 73 | /** Descriptor type (0x29). */
|
|---|
| 74 | uint8_t descriptor_type;
|
|---|
| 75 |
|
|---|
| 76 | /** Number of downstream ports. */
|
|---|
| 77 | uint8_t port_count;
|
|---|
| 78 |
|
|---|
| 79 | /** Characteristics bitmask.
|
|---|
| 80 | *
|
|---|
| 81 | * D1..D0: Logical Power Switching Mode
|
|---|
| 82 | * 00: Ganged power switching (all ports power at
|
|---|
| 83 | * once)
|
|---|
| 84 | * 01: Individual port power switching
|
|---|
| 85 | * 1X: Reserved. Used only on 1.0 compliant hubs
|
|---|
| 86 | * that implement no power switching.
|
|---|
| 87 | * D2: Identifies a Compound Device
|
|---|
| 88 | * 0: Hub is not part of a compound device
|
|---|
| 89 | * 1: Hub is part of a compound device
|
|---|
| 90 | * D4..D3: Over-current Protection Mode
|
|---|
| 91 | * 00: Global Over-current Protection. The hub
|
|---|
| 92 | * reports over-current as a summation of all
|
|---|
| 93 | * ports current draw, without a breakdown of
|
|---|
| 94 | * individual port over-current status.
|
|---|
| 95 | * 01: Individual Port Over-current Protection. The
|
|---|
| 96 | * hub reports over-current on a per-port basis.
|
|---|
| 97 | * Each port has an over-current indicator.
|
|---|
| 98 | * 1X: No Over-current Protection. This option is
|
|---|
| 99 | * allowed only for bus-powered hubs that do not
|
|---|
| 100 | * implement over-current protection.
|
|---|
| 101 | * D6..D5: TT think time
|
|---|
| 102 | * 00: At most 8 FS bit times
|
|---|
| 103 | * 01: At most 16 FS bit times
|
|---|
| 104 | * 10: At most 24 FS bit times
|
|---|
| 105 | * 11: At most 32 FS bit times
|
|---|
| 106 | * D7: Port indicators
|
|---|
| 107 | * 0: Not supported
|
|---|
| 108 | * 1: Supported
|
|---|
| 109 | * D15...D8: Reserved
|
|---|
| 110 | */
|
|---|
| 111 | uint8_t characteristics;
|
|---|
| 112 | #define HUB_CHAR_POWER_PER_PORT_FLAG (1 << 0)
|
|---|
| 113 | #define HUB_CHAR_NO_POWER_SWITCH_FLAG (1 << 1)
|
|---|
| 114 | #define HUB_CHAR_COMPOUND_DEVICE (1 << 2)
|
|---|
| 115 | #define HUB_CHAR_OC_PER_PORT_FLAG (1 << 3)
|
|---|
| 116 | #define HUB_CHAR_NO_OC_FLAG (1 << 4)
|
|---|
| 117 | #define HUB_CHAR_TT_THINK_16 (1 << 5)
|
|---|
| 118 | #define HUB_CHAR_TT_THINK_8 (1 << 6)
|
|---|
| 119 | #define HUB_CHAR_INDICATORS_FLAG (1 << 7)
|
|---|
| 120 |
|
|---|
| 121 | /** Unused part of characteristics field */
|
|---|
| 122 | uint8_t characteristics_reserved;
|
|---|
| 123 |
|
|---|
| 124 | /** Time from power-on to stabilization of current on the port.
|
|---|
| 125 | *
|
|---|
| 126 | * Time (in 2ms intervals) from the time the power-on
|
|---|
| 127 | * sequence begins on a port until power is good on that
|
|---|
| 128 | * port. The USB System Software uses this value to
|
|---|
| 129 | * determine how long to wait before accessing a
|
|---|
| 130 | * powered-on port.
|
|---|
| 131 | */
|
|---|
| 132 | uint8_t power_good_time;
|
|---|
| 133 | /** Maximum current requirements in mA.
|
|---|
| 134 | *
|
|---|
| 135 | * Maximum current requirements of the Hub Controller
|
|---|
| 136 | * electronics in mA.
|
|---|
| 137 | */
|
|---|
| 138 | uint8_t max_current;
|
|---|
| 139 | } __attribute__ ((packed)) usb_hub_descriptor_header_t;
|
|---|
| 140 |
|
|---|
| 141 | /** One bit for the device and one bit for every port */
|
|---|
| 142 | #define STATUS_BYTES(ports) ((1 + ports + 7) / 8)
|
|---|
| 143 |
|
|---|
| 144 | /** @brief usb hub specific request types.
|
|---|
| 145 | *
|
|---|
| 146 | * For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2
|
|---|
| 147 | */
|
|---|
| 148 | typedef enum {
|
|---|
| 149 | /** This request resets a value reported in the hub status. */
|
|---|
| 150 | USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE = 0x20,
|
|---|
| 151 | /** This request resets a value reported in the port status. */
|
|---|
| 152 | USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE = 0x23,
|
|---|
| 153 | /** This is an optional per-port diagnostic request that returns the bus state value, as sampled at the last EOF2 point. */
|
|---|
| 154 | USB_HUB_REQ_TYPE_GET_STATE = 0xA3,
|
|---|
| 155 | /** This request returns the hub descriptor. */
|
|---|
| 156 | USB_HUB_REQ_TYPE_GET_DESCRIPTOR = 0xA0,
|
|---|
| 157 | /** This request returns the current hub status and the states that have changed since the previous acknowledgment. */
|
|---|
| 158 | USB_HUB_REQ_TYPE_GET_HUB_STATUS = 0xA0,
|
|---|
| 159 | /** This request returns the current port status and the current value of the port status change bits. */
|
|---|
| 160 | USB_HUB_REQ_TYPE_GET_PORT_STATUS = 0xA3,
|
|---|
| 161 | /** This request overwrites the hub descriptor. */
|
|---|
| 162 | USB_HUB_REQ_TYPE_SET_DESCRIPTOR = 0x20,
|
|---|
| 163 | /** This request sets a value reported in the hub status. */
|
|---|
| 164 | USB_HUB_REQ_TYPE_SET_HUB_FEATURE = 0x20,
|
|---|
| 165 | /** This request sets a value reported in the port status. */
|
|---|
| 166 | USB_HUB_REQ_TYPE_SET_PORT_FEATURE = 0x23
|
|---|
| 167 | } usb_hub_bm_request_type_t;
|
|---|
| 168 |
|
|---|
| 169 | /** @brief hub class request codes*/
|
|---|
| 170 | /// \TODO these are duplicit to standart descriptors
|
|---|
| 171 | typedef enum {
|
|---|
| 172 | /** */
|
|---|
| 173 | USB_HUB_REQUEST_GET_STATUS = 0,
|
|---|
| 174 | /** */
|
|---|
| 175 | USB_HUB_REQUEST_CLEAR_FEATURE = 1,
|
|---|
| 176 | /** USB 1.0 only */
|
|---|
| 177 | USB_HUB_REQUEST_GET_STATE = 2,
|
|---|
| 178 | /** */
|
|---|
| 179 | USB_HUB_REQUEST_SET_FEATURE = 3,
|
|---|
| 180 | /** */
|
|---|
| 181 | USB_HUB_REQUEST_GET_DESCRIPTOR = 6,
|
|---|
| 182 | /** */
|
|---|
| 183 | USB_HUB_REQUEST_SET_DESCRIPTOR = 7,
|
|---|
| 184 | /** */
|
|---|
| 185 | USB_HUB_REQUEST_CLEAR_TT_BUFFER = 8,
|
|---|
| 186 | /** */
|
|---|
| 187 | USB_HUB_REQUEST_RESET_TT = 9,
|
|---|
| 188 | /** */
|
|---|
| 189 | USB_HUB_GET_TT_STATE = 10,
|
|---|
| 190 | /** */
|
|---|
| 191 | USB_HUB_STOP_TT = 11,
|
|---|
| 192 | } usb_hub_request_t;
|
|---|
| 193 |
|
|---|
| 194 | /**
|
|---|
| 195 | * Maximum size of usb hub descriptor in bytes
|
|---|
| 196 | */
|
|---|
| 197 | /* 7 (basic size) + 2*32 (port bitmasks) */
|
|---|
| 198 | #define USB_HUB_MAX_DESCRIPTOR_SIZE (7 + 2 * 32)
|
|---|
| 199 |
|
|---|
| 200 | #endif
|
|---|
| 201 | /**
|
|---|
| 202 | * @}
|
|---|
| 203 | */
|
|---|