| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
|---|
| 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 | /** @addtogroup drvusbohci
|
|---|
| 29 | * @{
|
|---|
| 30 | */
|
|---|
| 31 | /** @file
|
|---|
| 32 | * @brief OHCI driver
|
|---|
| 33 | */
|
|---|
| 34 | #include <assert.h>
|
|---|
| 35 | #include <errno.h>
|
|---|
| 36 | #include <str_error.h>
|
|---|
| 37 | #include <fibril_synch.h>
|
|---|
| 38 |
|
|---|
| 39 | #include <usb/debug.h>
|
|---|
| 40 | #include <usb/dev/request.h>
|
|---|
| 41 | #include <usb/classes/hub.h>
|
|---|
| 42 |
|
|---|
| 43 | #include "root_hub.h"
|
|---|
| 44 | #include <usb/classes/classes.h>
|
|---|
| 45 | #include <usb/classes/hub.h>
|
|---|
| 46 | #include <usb/dev/driver.h>
|
|---|
| 47 | #include "ohci_regs.h"
|
|---|
| 48 |
|
|---|
| 49 | /**
|
|---|
| 50 | * standart device descriptor for ohci root hub
|
|---|
| 51 | */
|
|---|
| 52 | static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = {
|
|---|
| 53 | .configuration_count = 1,
|
|---|
| 54 | .descriptor_type = USB_DESCTYPE_DEVICE,
|
|---|
| 55 | .device_class = USB_CLASS_HUB,
|
|---|
| 56 | .device_protocol = 0,
|
|---|
| 57 | .device_subclass = 0,
|
|---|
| 58 | .device_version = 0,
|
|---|
| 59 | .length = sizeof(usb_standard_device_descriptor_t),
|
|---|
| 60 | .max_packet_size = 64,
|
|---|
| 61 | .vendor_id = 0x16db, /* HelenOS does not have USB vendor ID assigned.*/
|
|---|
| 62 | .product_id = 0x0001,
|
|---|
| 63 | .str_serial_number = 0,
|
|---|
| 64 | .usb_spec_version = 0x110,
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | /**
|
|---|
| 68 | * standart configuration descriptor with filled common values
|
|---|
| 69 | * for ohci root hubs
|
|---|
| 70 | */
|
|---|
| 71 | static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = {
|
|---|
| 72 | .attributes = 1 << 7,
|
|---|
| 73 | .configuration_number = 1,
|
|---|
| 74 | .descriptor_type = USB_DESCTYPE_CONFIGURATION,
|
|---|
| 75 | .interface_count = 1,
|
|---|
| 76 | .length = sizeof(usb_standard_configuration_descriptor_t),
|
|---|
| 77 | .max_power = 0, /* root hubs don't need no power */
|
|---|
| 78 | .str_configuration = 0,
|
|---|
| 79 | };
|
|---|
| 80 |
|
|---|
| 81 | /**
|
|---|
| 82 | * standart ohci root hub interface descriptor
|
|---|
| 83 | */
|
|---|
| 84 | static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor = {
|
|---|
| 85 | .alternate_setting = 0,
|
|---|
| 86 | .descriptor_type = USB_DESCTYPE_INTERFACE,
|
|---|
| 87 | .endpoint_count = 1,
|
|---|
| 88 | .interface_class = USB_CLASS_HUB,
|
|---|
| 89 | .interface_number = 1,
|
|---|
| 90 | .interface_protocol = 0,
|
|---|
| 91 | .interface_subclass = 0,
|
|---|
| 92 | .length = sizeof(usb_standard_interface_descriptor_t),
|
|---|
| 93 | .str_interface = 0,
|
|---|
| 94 | };
|
|---|
| 95 |
|
|---|
| 96 | /**
|
|---|
| 97 | * standart ohci root hub endpoint descriptor
|
|---|
| 98 | */
|
|---|
| 99 | static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor = {
|
|---|
| 100 | .attributes = USB_TRANSFER_INTERRUPT,
|
|---|
| 101 | .descriptor_type = USB_DESCTYPE_ENDPOINT,
|
|---|
| 102 | .endpoint_address = 1 | (1 << 7),
|
|---|
| 103 | .length = sizeof(usb_standard_endpoint_descriptor_t),
|
|---|
| 104 | .max_packet_size = 2,
|
|---|
| 105 | .poll_interval = 255,
|
|---|
| 106 | };
|
|---|
| 107 |
|
|---|
| 108 | static void create_serialized_hub_descriptor(rh_t *instance);
|
|---|
| 109 | static void rh_init_descriptors(rh_t *instance);
|
|---|
| 110 | static uint16_t create_interrupt_mask(const rh_t *instance);
|
|---|
| 111 | static void get_status(const rh_t *instance, usb_transfer_batch_t *request);
|
|---|
| 112 | static void get_descriptor(const rh_t *instance, usb_transfer_batch_t *request);
|
|---|
| 113 | static void set_feature(const rh_t *instance, usb_transfer_batch_t *request);
|
|---|
| 114 | static void clear_feature(const rh_t *instance, usb_transfer_batch_t *request);
|
|---|
| 115 | static int set_feature_port(
|
|---|
| 116 | const rh_t *instance, uint16_t feature, uint16_t port);
|
|---|
| 117 | static int clear_feature_port(
|
|---|
| 118 | const rh_t *instance, uint16_t feature, uint16_t port);
|
|---|
| 119 | static void control_request(rh_t *instance, usb_transfer_batch_t *request);
|
|---|
| 120 | static inline void interrupt_request(
|
|---|
| 121 | usb_transfer_batch_t *request, uint16_t mask, size_t size)
|
|---|
| 122 | {
|
|---|
| 123 | assert(request);
|
|---|
| 124 | usb_transfer_batch_finish_error(request, &mask, size, EOK);
|
|---|
| 125 | usb_transfer_batch_destroy(request);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | #define TRANSFER_END_DATA(request, data, bytes) \
|
|---|
| 129 | do { \
|
|---|
| 130 | usb_transfer_batch_finish_error(request, data, bytes, EOK); \
|
|---|
| 131 | usb_transfer_batch_destroy(request); \
|
|---|
| 132 | return; \
|
|---|
| 133 | } while (0)
|
|---|
| 134 |
|
|---|
| 135 | #define TRANSFER_END(request, error) \
|
|---|
| 136 | do { \
|
|---|
| 137 | usb_transfer_batch_finish_error(request, NULL, 0, error); \
|
|---|
| 138 | usb_transfer_batch_destroy(request); \
|
|---|
| 139 | return; \
|
|---|
| 140 | } while (0)
|
|---|
| 141 |
|
|---|
| 142 | /** Root Hub driver structure initialization.
|
|---|
| 143 | *
|
|---|
| 144 | * Reads info registers and prepares descriptors. Sets power mode.
|
|---|
| 145 | */
|
|---|
| 146 | void rh_init(rh_t *instance, ohci_regs_t *regs)
|
|---|
| 147 | {
|
|---|
| 148 | assert(instance);
|
|---|
| 149 | assert(regs);
|
|---|
| 150 |
|
|---|
| 151 | instance->registers = regs;
|
|---|
| 152 | instance->port_count =
|
|---|
| 153 | (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
|
|---|
| 154 | if (instance->port_count > 15) {
|
|---|
| 155 | usb_log_warning("OHCI specification does not allow more than 15"
|
|---|
| 156 | " ports. Max 15 ports will be used");
|
|---|
| 157 | instance->port_count = 15;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | /* Don't forget the hub status bit and round up */
|
|---|
| 161 | instance->interrupt_mask_size = 1 + (instance->port_count / 8);
|
|---|
| 162 | instance->unfinished_interrupt_transfer = NULL;
|
|---|
| 163 |
|
|---|
| 164 | #if defined OHCI_POWER_SWITCH_no
|
|---|
| 165 | /* Set port power mode to no power-switching. (always on) */
|
|---|
| 166 | instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
|
|---|
| 167 |
|
|---|
| 168 | /* Set to no over-current reporting */
|
|---|
| 169 | instance->registers->rh_desc_a |= RHDA_NOCP_FLAG;
|
|---|
| 170 |
|
|---|
| 171 | #elif defined OHCI_POWER_SWITCH_ganged
|
|---|
| 172 | /* Set port power mode to no ganged power-switching. */
|
|---|
| 173 | instance->registers->rh_desc_a &= ~RHDA_NPS_FLAG;
|
|---|
| 174 | instance->registers->rh_desc_a &= ~RHDA_PSM_FLAG;
|
|---|
| 175 | instance->registers->rh_status = RHS_CLEAR_GLOBAL_POWER;
|
|---|
| 176 |
|
|---|
| 177 | /* Set to global over-current */
|
|---|
| 178 | instance->registers->rh_desc_a &= ~RHDA_NOCP_FLAG;
|
|---|
| 179 | instance->registers->rh_desc_a &= ~RHDA_OCPM_FLAG;
|
|---|
| 180 | #else
|
|---|
| 181 | /* Set port power mode to no per port power-switching. */
|
|---|
| 182 | instance->registers->rh_desc_a &= ~RHDA_NPS_FLAG;
|
|---|
| 183 | instance->registers->rh_desc_a |= RHDA_PSM_FLAG;
|
|---|
| 184 |
|
|---|
| 185 | /* Control all ports by global switch and turn them off */
|
|---|
| 186 | instance->registers->rh_desc_b &= (RHDB_PCC_MASK << RHDB_PCC_SHIFT);
|
|---|
| 187 | instance->registers->rh_status = RHS_CLEAR_GLOBAL_POWER;
|
|---|
| 188 |
|
|---|
| 189 | /* Return control to per port state */
|
|---|
| 190 | instance->registers->rh_desc_b |=
|
|---|
| 191 | ((1 << (instance->port_count + 1)) - 1) << RHDB_PCC_SHIFT;
|
|---|
| 192 |
|
|---|
| 193 | /* Set per port over-current */
|
|---|
| 194 | instance->registers->rh_desc_a &= ~RHDA_NOCP_FLAG;
|
|---|
| 195 | instance->registers->rh_desc_a |= RHDA_OCPM_FLAG;
|
|---|
| 196 | #endif
|
|---|
| 197 |
|
|---|
| 198 | fibril_mutex_initialize(&instance->guard);
|
|---|
| 199 | rh_init_descriptors(instance);
|
|---|
| 200 |
|
|---|
| 201 | usb_log_info("Root hub (%zu ports) initialized.\n",
|
|---|
| 202 | instance->port_count);
|
|---|
| 203 | }
|
|---|
| 204 | /*----------------------------------------------------------------------------*/
|
|---|
| 205 | /**
|
|---|
| 206 | * Process root hub request.
|
|---|
| 207 | *
|
|---|
| 208 | * @param instance Root hub instance
|
|---|
| 209 | * @param request Structure containing both request and response information
|
|---|
| 210 | * @return Error code
|
|---|
| 211 | */
|
|---|
| 212 | void rh_request(rh_t *instance, usb_transfer_batch_t *request)
|
|---|
| 213 | {
|
|---|
| 214 | assert(instance);
|
|---|
| 215 | assert(request);
|
|---|
| 216 |
|
|---|
| 217 | switch (request->ep->transfer_type)
|
|---|
| 218 | {
|
|---|
| 219 | case USB_TRANSFER_CONTROL:
|
|---|
| 220 | usb_log_debug("Root hub got CONTROL packet\n");
|
|---|
| 221 | control_request(instance, request);
|
|---|
| 222 | break;
|
|---|
| 223 |
|
|---|
| 224 | case USB_TRANSFER_INTERRUPT:
|
|---|
| 225 | usb_log_debug("Root hub got INTERRUPT packet\n");
|
|---|
| 226 | fibril_mutex_lock(&instance->guard);
|
|---|
| 227 | assert(instance->unfinished_interrupt_transfer == NULL);
|
|---|
| 228 | uint16_t mask = create_interrupt_mask(instance);
|
|---|
| 229 | if (mask == 0) {
|
|---|
| 230 | usb_log_debug("No changes...\n");
|
|---|
| 231 | instance->unfinished_interrupt_transfer = request;
|
|---|
| 232 | } else {
|
|---|
| 233 | usb_log_debug("Processing changes...\n");
|
|---|
| 234 | interrupt_request(
|
|---|
| 235 | request, mask, instance->interrupt_mask_size);
|
|---|
| 236 | }
|
|---|
| 237 | fibril_mutex_unlock(&instance->guard);
|
|---|
| 238 | break;
|
|---|
| 239 |
|
|---|
| 240 | default:
|
|---|
| 241 | usb_log_error("Root hub got unsupported request.\n");
|
|---|
| 242 | TRANSFER_END(request, ENOTSUP);
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 | /*----------------------------------------------------------------------------*/
|
|---|
| 246 | /**
|
|---|
| 247 | * Process interrupt on a hub device.
|
|---|
| 248 | *
|
|---|
| 249 | * If there is no pending interrupt transfer, nothing happens.
|
|---|
| 250 | * @param instance
|
|---|
| 251 | */
|
|---|
| 252 | void rh_interrupt(rh_t *instance)
|
|---|
| 253 | {
|
|---|
| 254 | assert(instance);
|
|---|
| 255 |
|
|---|
| 256 | fibril_mutex_lock(&instance->guard);
|
|---|
| 257 | if (instance->unfinished_interrupt_transfer) {
|
|---|
| 258 | usb_log_debug("Finalizing interrupt transfer\n");
|
|---|
| 259 | uint16_t mask = create_interrupt_mask(instance);
|
|---|
| 260 | interrupt_request(instance->unfinished_interrupt_transfer,
|
|---|
| 261 | mask, instance->interrupt_mask_size);
|
|---|
| 262 | instance->unfinished_interrupt_transfer = NULL;
|
|---|
| 263 | }
|
|---|
| 264 | fibril_mutex_unlock(&instance->guard);
|
|---|
| 265 | }
|
|---|
| 266 | /*----------------------------------------------------------------------------*/
|
|---|
| 267 | /**
|
|---|
| 268 | * Create hub descriptor.
|
|---|
| 269 | *
|
|---|
| 270 | * For descriptor format see USB hub specification (chapter 11.15.2.1, pg. 263)
|
|---|
| 271 | *
|
|---|
| 272 | * @param instance Root hub instance
|
|---|
| 273 | * @return Error code
|
|---|
| 274 | */
|
|---|
| 275 | void create_serialized_hub_descriptor(rh_t *instance)
|
|---|
| 276 | {
|
|---|
| 277 | assert(instance);
|
|---|
| 278 |
|
|---|
| 279 | /* 7 bytes + 2 port bit fields (port count + global bit) */
|
|---|
| 280 | size_t size = 7 + (instance->interrupt_mask_size * 2);
|
|---|
| 281 | assert(size <= HUB_DESCRIPTOR_MAX_SIZE);
|
|---|
| 282 | instance->hub_descriptor_size = size;
|
|---|
| 283 |
|
|---|
| 284 | uint32_t hub_desc = instance->registers->rh_desc_a;
|
|---|
| 285 | uint32_t port_desc = instance->registers->rh_desc_b;
|
|---|
| 286 |
|
|---|
| 287 | /* bDescLength */
|
|---|
| 288 | instance->descriptors.hub[0] = size;
|
|---|
| 289 | /* bDescriptorType */
|
|---|
| 290 | instance->descriptors.hub[1] = USB_DESCTYPE_HUB;
|
|---|
| 291 | /* bNmbrPorts */
|
|---|
| 292 | instance->descriptors.hub[2] = instance->port_count;
|
|---|
| 293 | /* wHubCharacteristics */
|
|---|
| 294 | instance->descriptors.hub[3] = 0 |
|
|---|
| 295 | /* The lowest 2 bits indicate power switching mode */
|
|---|
| 296 | (((hub_desc & RHDA_PSM_FLAG) ? 1 : 0) << 0) |
|
|---|
| 297 | (((hub_desc & RHDA_NPS_FLAG) ? 1 : 0) << 1) |
|
|---|
| 298 | /* Bit 3 indicates device type (compound device) */
|
|---|
| 299 | (((hub_desc & RHDA_DT_FLAG) ? 1 : 0) << 2) |
|
|---|
| 300 | /* Bits 4,5 indicate over-current protection mode */
|
|---|
| 301 | (((hub_desc & RHDA_OCPM_FLAG) ? 1 : 0) << 3) |
|
|---|
| 302 | (((hub_desc & RHDA_NOCP_FLAG) ? 1 : 0) << 4);
|
|---|
| 303 |
|
|---|
| 304 | /* Reserved */
|
|---|
| 305 | instance->descriptors.hub[4] = 0;
|
|---|
| 306 | /* bPwrOn2PwrGood */
|
|---|
| 307 | instance->descriptors.hub[5] =
|
|---|
| 308 | (hub_desc >> RHDA_POTPGT_SHIFT) & RHDA_POTPGT_MASK;
|
|---|
| 309 | /* bHubContrCurrent, root hubs don't need no power. */
|
|---|
| 310 | instance->descriptors.hub[6] = 0;
|
|---|
| 311 |
|
|---|
| 312 | /* Device Removable and some legacy 1.0 stuff*/
|
|---|
| 313 | instance->descriptors.hub[7] =
|
|---|
| 314 | (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK & 0xff;
|
|---|
| 315 | instance->descriptors.hub[8] = 0xff;
|
|---|
| 316 | if (instance->interrupt_mask_size == 2) {
|
|---|
| 317 | instance->descriptors.hub[8] =
|
|---|
| 318 | (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK >> 8;
|
|---|
| 319 | instance->descriptors.hub[9] = 0xff;
|
|---|
| 320 | instance->descriptors.hub[10] = 0xff;
|
|---|
| 321 | }
|
|---|
| 322 | }
|
|---|
| 323 | /*----------------------------------------------------------------------------*/
|
|---|
| 324 | /** Initialize hub descriptors.
|
|---|
| 325 | *
|
|---|
| 326 | * A full configuration descriptor is assembled. The configuration and endpoint
|
|---|
| 327 | * descriptors have local modifications.
|
|---|
| 328 | * @param instance Root hub instance
|
|---|
| 329 | * @return Error code
|
|---|
| 330 | */
|
|---|
| 331 | void rh_init_descriptors(rh_t *instance)
|
|---|
| 332 | {
|
|---|
| 333 | assert(instance);
|
|---|
| 334 |
|
|---|
| 335 | instance->descriptors.configuration = ohci_rh_conf_descriptor;
|
|---|
| 336 | instance->descriptors.interface = ohci_rh_iface_descriptor;
|
|---|
| 337 | instance->descriptors.endpoint = ohci_rh_ep_descriptor;
|
|---|
| 338 | create_serialized_hub_descriptor(instance);
|
|---|
| 339 |
|
|---|
| 340 | instance->descriptors.endpoint.max_packet_size =
|
|---|
| 341 | instance->interrupt_mask_size;
|
|---|
| 342 |
|
|---|
| 343 | instance->descriptors.configuration.total_length =
|
|---|
| 344 | sizeof(usb_standard_configuration_descriptor_t) +
|
|---|
| 345 | sizeof(usb_standard_endpoint_descriptor_t) +
|
|---|
| 346 | sizeof(usb_standard_interface_descriptor_t) +
|
|---|
| 347 | instance->hub_descriptor_size;
|
|---|
| 348 | }
|
|---|
| 349 | /*----------------------------------------------------------------------------*/
|
|---|
| 350 | /**
|
|---|
| 351 | * Create bitmap of changes to answer status interrupt.
|
|---|
| 352 | *
|
|---|
| 353 | * Result contains bitmap where bit 0 indicates change on hub and
|
|---|
| 354 | * bit i indicates change on i`th port (i>0). For more info see
|
|---|
| 355 | * Hub and Port status bitmap specification in USB specification
|
|---|
| 356 | * (chapter 11.13.4).
|
|---|
| 357 | * @param instance root hub instance
|
|---|
| 358 | * @return Mask of changes.
|
|---|
| 359 | */
|
|---|
| 360 | uint16_t create_interrupt_mask(const rh_t *instance)
|
|---|
| 361 | {
|
|---|
| 362 | assert(instance);
|
|---|
| 363 | uint16_t mask = 0;
|
|---|
| 364 |
|
|---|
| 365 | /* Only local power source change and over-current change can happen */
|
|---|
| 366 | if (instance->registers->rh_status & (RHS_LPSC_FLAG | RHS_OCIC_FLAG)) {
|
|---|
| 367 | mask |= 1;
|
|---|
| 368 | }
|
|---|
| 369 | for (size_t port = 1; port <= instance->port_count; ++port) {
|
|---|
| 370 | /* Write-clean bits are those that indicate change */
|
|---|
| 371 | if (RHPS_CHANGE_WC_MASK
|
|---|
| 372 | & instance->registers->rh_port_status[port - 1]) {
|
|---|
| 373 |
|
|---|
| 374 | mask |= (1 << port);
|
|---|
| 375 | }
|
|---|
| 376 | }
|
|---|
| 377 | /* USB is little endian */
|
|---|
| 378 | return host2uint32_t_le(mask);
|
|---|
| 379 | }
|
|---|
| 380 | /*----------------------------------------------------------------------------*/
|
|---|
| 381 | /**
|
|---|
| 382 | * Create answer to status request.
|
|---|
| 383 | *
|
|---|
| 384 | * This might be either hub status or port status request. If neither,
|
|---|
| 385 | * ENOTSUP is returned.
|
|---|
| 386 | * @param instance root hub instance
|
|---|
| 387 | * @param request structure containing both request and response information
|
|---|
| 388 | * @return error code
|
|---|
| 389 | */
|
|---|
| 390 | void get_status(const rh_t *instance, usb_transfer_batch_t *request)
|
|---|
| 391 | {
|
|---|
| 392 | assert(instance);
|
|---|
| 393 | assert(request);
|
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 | usb_device_request_setup_packet_t *request_packet =
|
|---|
| 397 | (usb_device_request_setup_packet_t*)request->setup_buffer;
|
|---|
| 398 |
|
|---|
| 399 | switch (request_packet->request_type)
|
|---|
| 400 | {
|
|---|
| 401 | case USB_HUB_REQ_TYPE_GET_HUB_STATUS:
|
|---|
| 402 | /* Hub status: just filter relevant info from rh_status reg */
|
|---|
| 403 | if (request->buffer_size < 4) {
|
|---|
| 404 | usb_log_error("Buffer(%zu) too small for hub get "
|
|---|
| 405 | "status request.\n", request->buffer_size);
|
|---|
| 406 | TRANSFER_END(request, EOVERFLOW);
|
|---|
| 407 | } else {
|
|---|
| 408 | uint32_t data = instance->registers->rh_status &
|
|---|
| 409 | (RHS_LPS_FLAG | RHS_LPSC_FLAG
|
|---|
| 410 | | RHS_OCI_FLAG | RHS_OCIC_FLAG);
|
|---|
| 411 | TRANSFER_END_DATA(request, &data, sizeof(data));
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | /* Copy appropriate rh_port_status register, OHCI designers were
|
|---|
| 415 | * kind enough to make those bit values match USB specification */
|
|---|
| 416 | case USB_HUB_REQ_TYPE_GET_PORT_STATUS:
|
|---|
| 417 | if (request->buffer_size < 4) {
|
|---|
| 418 | usb_log_error("Buffer(%zu) too small for hub get "
|
|---|
| 419 | "status request.\n", request->buffer_size);
|
|---|
| 420 | TRANSFER_END(request, EOVERFLOW);
|
|---|
| 421 | } else {
|
|---|
| 422 | unsigned port = request_packet->index;
|
|---|
| 423 | if (port < 1 || port > instance->port_count)
|
|---|
| 424 | TRANSFER_END(request, EINVAL);
|
|---|
| 425 |
|
|---|
| 426 | uint32_t data =
|
|---|
| 427 | instance->registers->rh_port_status[port - 1];
|
|---|
| 428 | TRANSFER_END_DATA(request, &data, sizeof(data));
|
|---|
| 429 | }
|
|---|
| 430 | case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE):
|
|---|
| 431 | if (request->buffer_size < 2) {
|
|---|
| 432 | usb_log_error("Buffer(%zu) too small for hub generic "
|
|---|
| 433 | "get status request.\n", request->buffer_size);
|
|---|
| 434 | TRANSFER_END(request, EOVERFLOW);
|
|---|
| 435 | } else {
|
|---|
| 436 | uint16_t data =
|
|---|
| 437 | uint16_host2usb(USB_DEVICE_STATUS_SELF_POWERED);
|
|---|
| 438 | TRANSFER_END_DATA(request, &data, sizeof(data));
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE):
|
|---|
| 442 | /* Hubs are allowed to have only one interface */
|
|---|
| 443 | if (request_packet->index != 0)
|
|---|
| 444 | TRANSFER_END(request, EINVAL);
|
|---|
| 445 | /* Fall through, as the answer will be the same: 0x0000 */
|
|---|
| 446 | case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_ENDPOINT):
|
|---|
| 447 | /* Endpoint 0 (default control) and 1 (interrupt) */
|
|---|
| 448 | if (request_packet->index >= 2)
|
|---|
| 449 | TRANSFER_END(request, EINVAL);
|
|---|
| 450 |
|
|---|
| 451 | if (request->buffer_size < 2) {
|
|---|
| 452 | usb_log_error("Buffer(%zu) too small for hub generic "
|
|---|
| 453 | "get status request.\n", request->buffer_size);
|
|---|
| 454 | TRANSFER_END(request, EOVERFLOW);
|
|---|
| 455 | } else {
|
|---|
| 456 | /* Endpoints are OK. (We don't halt) */
|
|---|
| 457 | uint16_t data = 0;
|
|---|
| 458 | TRANSFER_END_DATA(request, &data, sizeof(data));
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | default:
|
|---|
| 462 | usb_log_error("Unsupported GET_STATUS request.\n");
|
|---|
| 463 | TRANSFER_END(request, ENOTSUP);
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | }
|
|---|
| 467 | /*----------------------------------------------------------------------------*/
|
|---|
| 468 | /**
|
|---|
| 469 | * Create answer to a descriptor request.
|
|---|
| 470 | *
|
|---|
| 471 | * This might be a request for standard (configuration, device, endpoint or
|
|---|
| 472 | * interface) or device specific (hub) descriptor.
|
|---|
| 473 | * @param instance Root hub instance
|
|---|
| 474 | * @param request Structure containing both request and response information
|
|---|
| 475 | * @return Error code
|
|---|
| 476 | */
|
|---|
| 477 | void get_descriptor(const rh_t *instance, usb_transfer_batch_t *request)
|
|---|
| 478 | {
|
|---|
| 479 | assert(instance);
|
|---|
| 480 | assert(request);
|
|---|
| 481 |
|
|---|
| 482 | usb_device_request_setup_packet_t *setup_request =
|
|---|
| 483 | (usb_device_request_setup_packet_t *) request->setup_buffer;
|
|---|
| 484 | uint16_t setup_request_value = setup_request->value_high;
|
|---|
| 485 | switch (setup_request_value)
|
|---|
| 486 | {
|
|---|
| 487 | case USB_DESCTYPE_HUB:
|
|---|
| 488 | usb_log_debug2("USB_DESCTYPE_HUB\n");
|
|---|
| 489 | /* Hub descriptor was generated locally.
|
|---|
| 490 | * Class specific request. */
|
|---|
| 491 | TRANSFER_END_DATA(request, instance->descriptors.hub,
|
|---|
| 492 | instance->hub_descriptor_size);
|
|---|
| 493 |
|
|---|
| 494 | case USB_DESCTYPE_DEVICE:
|
|---|
| 495 | usb_log_debug2("USB_DESCTYPE_DEVICE\n");
|
|---|
| 496 | /* Device descriptor is shared
|
|---|
| 497 | * (No one should ask for it, as the device is already setup)
|
|---|
| 498 | * Standard USB device request. */
|
|---|
| 499 | TRANSFER_END_DATA(request, &ohci_rh_device_descriptor,
|
|---|
| 500 | sizeof(ohci_rh_device_descriptor));
|
|---|
| 501 |
|
|---|
| 502 | case USB_DESCTYPE_CONFIGURATION:
|
|---|
| 503 | usb_log_debug2("USB_DESCTYPE_CONFIGURATION\n");
|
|---|
| 504 | /* Start with configuration and add others depending on
|
|---|
| 505 | * request size. Standard USB request. */
|
|---|
| 506 | TRANSFER_END_DATA(request, &instance->descriptors,
|
|---|
| 507 | instance->descriptors.configuration.total_length);
|
|---|
| 508 |
|
|---|
| 509 | case USB_DESCTYPE_INTERFACE:
|
|---|
| 510 | usb_log_debug2("USB_DESCTYPE_INTERFACE\n");
|
|---|
| 511 | /* Use local interface descriptor. There is one and it
|
|---|
| 512 | * might be modified. Hub driver should not ask or this
|
|---|
| 513 | * descriptor as it is not part of standard requests set. */
|
|---|
| 514 | TRANSFER_END_DATA(request, &instance->descriptors.interface,
|
|---|
| 515 | sizeof(instance->descriptors.interface));
|
|---|
| 516 |
|
|---|
| 517 | case USB_DESCTYPE_ENDPOINT:
|
|---|
| 518 | /* Use local endpoint descriptor. There is one
|
|---|
| 519 | * it might have max_packet_size field modified. Hub driver
|
|---|
| 520 | * should not ask for this descriptor as it is not part
|
|---|
| 521 | * of standard requests set. */
|
|---|
| 522 | usb_log_debug2("USB_DESCTYPE_ENDPOINT\n");
|
|---|
| 523 | TRANSFER_END_DATA(request, &instance->descriptors.endpoint,
|
|---|
| 524 | sizeof(instance->descriptors.endpoint));
|
|---|
| 525 |
|
|---|
| 526 | default:
|
|---|
| 527 | usb_log_debug2("USB_DESCTYPE_EINVAL %d \n"
|
|---|
| 528 | "\ttype %d\n\trequest %d\n\tvalue "
|
|---|
| 529 | "%d\n\tindex %d\n\tlen %d\n ",
|
|---|
| 530 | setup_request->value,
|
|---|
| 531 | setup_request->request_type, setup_request->request,
|
|---|
| 532 | setup_request_value, setup_request->index,
|
|---|
| 533 | setup_request->length);
|
|---|
| 534 | TRANSFER_END(request, EINVAL);
|
|---|
| 535 | }
|
|---|
| 536 |
|
|---|
| 537 | TRANSFER_END(request, ENOTSUP);
|
|---|
| 538 | }
|
|---|
| 539 | /*----------------------------------------------------------------------------*/
|
|---|
| 540 | /**
|
|---|
| 541 | * process feature-enabling request on hub
|
|---|
| 542 | *
|
|---|
| 543 | * @param instance root hub instance
|
|---|
| 544 | * @param feature feature selector
|
|---|
| 545 | * @param port port number, counted from 1
|
|---|
| 546 | * @param enable enable or disable the specified feature
|
|---|
| 547 | * @return error code
|
|---|
| 548 | */
|
|---|
| 549 | int set_feature_port(const rh_t *instance, uint16_t feature, uint16_t port)
|
|---|
| 550 | {
|
|---|
| 551 | assert(instance);
|
|---|
| 552 |
|
|---|
| 553 | if (port < 1 || port > instance->port_count)
|
|---|
| 554 | return EINVAL;
|
|---|
| 555 |
|
|---|
| 556 | switch (feature)
|
|---|
| 557 | {
|
|---|
| 558 | case USB_HUB_FEATURE_PORT_POWER: //8
|
|---|
| 559 | /* No power switching */
|
|---|
| 560 | if (instance->registers->rh_desc_a & RHDA_NPS_FLAG)
|
|---|
| 561 | return EOK;
|
|---|
| 562 | /* Ganged power switching */
|
|---|
| 563 | if (!(instance->registers->rh_desc_a & RHDA_PSM_FLAG)) {
|
|---|
| 564 | instance->registers->rh_status = RHS_SET_GLOBAL_POWER;
|
|---|
| 565 | return EOK;
|
|---|
| 566 | }
|
|---|
| 567 | case USB_HUB_FEATURE_PORT_ENABLE: //1
|
|---|
| 568 | case USB_HUB_FEATURE_PORT_SUSPEND: //2
|
|---|
| 569 | case USB_HUB_FEATURE_PORT_RESET: //4
|
|---|
| 570 | /* Nice thing is that these shifts correspond to the position
|
|---|
| 571 | * of control bits in register */
|
|---|
| 572 | instance->registers->rh_port_status[port - 1] = (1 << feature);
|
|---|
| 573 | return EOK;
|
|---|
| 574 | default:
|
|---|
| 575 | return ENOTSUP;
|
|---|
| 576 | }
|
|---|
| 577 | }
|
|---|
| 578 | /*----------------------------------------------------------------------------*/
|
|---|
| 579 | /**
|
|---|
| 580 | * Process feature clear request.
|
|---|
| 581 | *
|
|---|
| 582 | * @param instance root hub instance
|
|---|
| 583 | * @param feature feature selector
|
|---|
| 584 | * @param port port number, counted from 1
|
|---|
| 585 | * @param enable enable or disable the specified feature
|
|---|
| 586 | * @return error code
|
|---|
| 587 | */
|
|---|
| 588 | int clear_feature_port(const rh_t *instance, uint16_t feature, uint16_t port)
|
|---|
| 589 | {
|
|---|
| 590 | assert(instance);
|
|---|
| 591 |
|
|---|
| 592 | if (port < 1 || port > instance->port_count)
|
|---|
| 593 | return EINVAL;
|
|---|
| 594 |
|
|---|
| 595 | /* Enabled features to clear: see page 269 of USB specs */
|
|---|
| 596 | switch (feature)
|
|---|
| 597 | {
|
|---|
| 598 | case USB_HUB_FEATURE_PORT_POWER: //8
|
|---|
| 599 | /* No power switching */
|
|---|
| 600 | if (instance->registers->rh_desc_a & RHDA_NPS_FLAG)
|
|---|
| 601 | return ENOTSUP;
|
|---|
| 602 | /* Ganged power switching */
|
|---|
| 603 | if (!(instance->registers->rh_desc_a & RHDA_PSM_FLAG)) {
|
|---|
| 604 | instance->registers->rh_status = RHS_CLEAR_GLOBAL_POWER;
|
|---|
| 605 | return EOK;
|
|---|
| 606 | }
|
|---|
| 607 | instance->registers->rh_port_status[port - 1] =
|
|---|
| 608 | RHPS_CLEAR_PORT_POWER;
|
|---|
| 609 | return EOK;
|
|---|
| 610 |
|
|---|
| 611 | case USB_HUB_FEATURE_PORT_ENABLE: //1
|
|---|
| 612 | instance->registers->rh_port_status[port - 1] =
|
|---|
| 613 | RHPS_CLEAR_PORT_ENABLE;
|
|---|
| 614 | return EOK;
|
|---|
| 615 |
|
|---|
| 616 | case USB_HUB_FEATURE_PORT_SUSPEND: //2
|
|---|
| 617 | instance->registers->rh_port_status[port - 1] =
|
|---|
| 618 | RHPS_CLEAR_PORT_SUSPEND;
|
|---|
| 619 | return EOK;
|
|---|
| 620 |
|
|---|
| 621 | case USB_HUB_FEATURE_C_PORT_CONNECTION: //16
|
|---|
| 622 | case USB_HUB_FEATURE_C_PORT_ENABLE: //17
|
|---|
| 623 | case USB_HUB_FEATURE_C_PORT_SUSPEND: //18
|
|---|
| 624 | case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: //19
|
|---|
| 625 | case USB_HUB_FEATURE_C_PORT_RESET: //20
|
|---|
| 626 | /* Nice thing is that these shifts correspond to the position
|
|---|
| 627 | * of control bits in register */
|
|---|
| 628 | instance->registers->rh_port_status[port - 1] = (1 << feature);
|
|---|
| 629 | return EOK;
|
|---|
| 630 |
|
|---|
| 631 | default:
|
|---|
| 632 | return ENOTSUP;
|
|---|
| 633 | }
|
|---|
| 634 | }
|
|---|
| 635 | /*----------------------------------------------------------------------------*/
|
|---|
| 636 | /**
|
|---|
| 637 | * process one of requests that do not request nor carry additional data
|
|---|
| 638 | *
|
|---|
| 639 | * Request can be one of USB_DEVREQ_CLEAR_FEATURE, USB_DEVREQ_SET_FEATURE or
|
|---|
| 640 | * USB_DEVREQ_SET_ADDRESS.
|
|---|
| 641 | * @param instance root hub instance
|
|---|
| 642 | * @param request structure containing both request and response information
|
|---|
| 643 | * @return error code
|
|---|
| 644 | */
|
|---|
| 645 | void set_feature(const rh_t *instance, usb_transfer_batch_t *request)
|
|---|
| 646 | {
|
|---|
| 647 | assert(instance);
|
|---|
| 648 | assert(request);
|
|---|
| 649 |
|
|---|
| 650 | usb_device_request_setup_packet_t *setup_request =
|
|---|
| 651 | (usb_device_request_setup_packet_t *) request->setup_buffer;
|
|---|
| 652 | switch (setup_request->request_type)
|
|---|
| 653 | {
|
|---|
| 654 | case USB_HUB_REQ_TYPE_SET_PORT_FEATURE:
|
|---|
| 655 | usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
|
|---|
| 656 | int ret = set_feature_port(instance,
|
|---|
| 657 | setup_request->value, setup_request->index);
|
|---|
| 658 | TRANSFER_END(request, ret);
|
|---|
| 659 |
|
|---|
| 660 | case USB_HUB_REQ_TYPE_SET_HUB_FEATURE:
|
|---|
| 661 | /* Chapter 11.16.2 specifies that hub can be recipient
|
|---|
| 662 | * only for C_HUB_LOCAL_POWER and C_HUB_OVER_CURRENT
|
|---|
| 663 | * features. It makes no sense to SET either. */
|
|---|
| 664 | usb_log_error("Invalid HUB set feature request.\n");
|
|---|
| 665 | TRANSFER_END(request, ENOTSUP);
|
|---|
| 666 | //TODO: Consider standard USB requests: REMOTE WAKEUP, ENDPOINT STALL
|
|---|
| 667 | default:
|
|---|
| 668 | usb_log_error("Invalid set feature request type: %d\n",
|
|---|
| 669 | setup_request->request_type);
|
|---|
| 670 | TRANSFER_END(request, ENOTSUP);
|
|---|
| 671 | }
|
|---|
| 672 | }
|
|---|
| 673 | /*----------------------------------------------------------------------------*/
|
|---|
| 674 | /**
|
|---|
| 675 | * process one of requests that do not request nor carry additional data
|
|---|
| 676 | *
|
|---|
| 677 | * Request can be one of USB_DEVREQ_CLEAR_FEATURE, USB_DEVREQ_SET_FEATURE or
|
|---|
| 678 | * USB_DEVREQ_SET_ADDRESS.
|
|---|
| 679 | * @param instance root hub instance
|
|---|
| 680 | * @param request structure containing both request and response information
|
|---|
| 681 | * @return error code
|
|---|
| 682 | */
|
|---|
| 683 | void clear_feature(const rh_t *instance, usb_transfer_batch_t *request)
|
|---|
| 684 | {
|
|---|
| 685 | assert(instance);
|
|---|
| 686 | assert(request);
|
|---|
| 687 |
|
|---|
| 688 | usb_device_request_setup_packet_t *setup_request =
|
|---|
| 689 | (usb_device_request_setup_packet_t *) request->setup_buffer;
|
|---|
| 690 |
|
|---|
| 691 | switch (setup_request->request_type)
|
|---|
| 692 | {
|
|---|
| 693 | case USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE:
|
|---|
| 694 | usb_log_debug("USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE\n");
|
|---|
| 695 | int ret = clear_feature_port(instance,
|
|---|
| 696 | setup_request->value, setup_request->index);
|
|---|
| 697 | TRANSFER_END(request, ret);
|
|---|
| 698 |
|
|---|
| 699 | case USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE:
|
|---|
| 700 | usb_log_debug("USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE\n");
|
|---|
| 701 | /*
|
|---|
| 702 | * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
|
|---|
| 703 | * C_HUB_OVER_CURRENT are supported.
|
|---|
| 704 | * C_HUB_OVER_CURRENT is represented by OHCI RHS_OCIC_FLAG.
|
|---|
| 705 | * C_HUB_LOCAL_POWER is not supported
|
|---|
| 706 | * as root hubs do not support local power status feature.
|
|---|
| 707 | * (OHCI pg. 127) */
|
|---|
| 708 | if (setup_request->value == USB_HUB_FEATURE_C_HUB_OVER_CURRENT) {
|
|---|
| 709 | instance->registers->rh_status = RHS_OCIC_FLAG;
|
|---|
| 710 | TRANSFER_END(request, EOK);
|
|---|
| 711 | }
|
|---|
| 712 | //TODO: Consider standard USB requests: REMOTE WAKEUP, ENDPOINT STALL
|
|---|
| 713 | default:
|
|---|
| 714 | usb_log_error("Invalid clear feature request type: %d\n",
|
|---|
| 715 | setup_request->request_type);
|
|---|
| 716 | TRANSFER_END(request, ENOTSUP);
|
|---|
| 717 | }
|
|---|
| 718 | }
|
|---|
| 719 | /*----------------------------------------------------------------------------*/
|
|---|
| 720 | /**
|
|---|
| 721 | * Process hub control request.
|
|---|
| 722 | *
|
|---|
| 723 | * If needed, writes answer into the request structure.
|
|---|
| 724 | * Request can be one of
|
|---|
| 725 | * USB_DEVREQ_GET_STATUS,
|
|---|
| 726 | * USB_DEVREQ_GET_DESCRIPTOR,
|
|---|
| 727 | * USB_DEVREQ_GET_CONFIGURATION,
|
|---|
| 728 | * USB_DEVREQ_CLEAR_FEATURE,
|
|---|
| 729 | * USB_DEVREQ_SET_FEATURE,
|
|---|
| 730 | * USB_DEVREQ_SET_ADDRESS,
|
|---|
| 731 | * USB_DEVREQ_SET_DESCRIPTOR or
|
|---|
| 732 | * USB_DEVREQ_SET_CONFIGURATION.
|
|---|
| 733 | *
|
|---|
| 734 | * @param instance root hub instance
|
|---|
| 735 | * @param request structure containing both request and response information
|
|---|
| 736 | * @return error code
|
|---|
| 737 | */
|
|---|
| 738 | void control_request(rh_t *instance, usb_transfer_batch_t *request)
|
|---|
| 739 | {
|
|---|
| 740 | assert(instance);
|
|---|
| 741 | assert(request);
|
|---|
| 742 |
|
|---|
| 743 | if (!request->setup_buffer) {
|
|---|
| 744 | usb_log_error("Root hub received empty transaction!");
|
|---|
| 745 | TRANSFER_END(request, EBADMEM);
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | if (sizeof(usb_device_request_setup_packet_t) > request->setup_size) {
|
|---|
| 749 | usb_log_error("Setup packet too small\n");
|
|---|
| 750 | TRANSFER_END(request, EOVERFLOW);
|
|---|
| 751 | }
|
|---|
| 752 |
|
|---|
| 753 | usb_log_debug2("CTRL packet: %s.\n",
|
|---|
| 754 | usb_debug_str_buffer((uint8_t *) request->setup_buffer, 8, 8));
|
|---|
| 755 | usb_device_request_setup_packet_t *setup_request =
|
|---|
| 756 | (usb_device_request_setup_packet_t *) request->setup_buffer;
|
|---|
| 757 | switch (setup_request->request)
|
|---|
| 758 | {
|
|---|
| 759 | case USB_DEVREQ_GET_STATUS:
|
|---|
| 760 | usb_log_debug("USB_DEVREQ_GET_STATUS\n");
|
|---|
| 761 | get_status(instance, request);
|
|---|
| 762 | break;
|
|---|
| 763 |
|
|---|
| 764 | case USB_DEVREQ_GET_DESCRIPTOR:
|
|---|
| 765 | usb_log_debug("USB_DEVREQ_GET_DESCRIPTOR\n");
|
|---|
| 766 | get_descriptor(instance, request);
|
|---|
| 767 | break;
|
|---|
| 768 |
|
|---|
| 769 | case USB_DEVREQ_GET_CONFIGURATION:
|
|---|
| 770 | usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
|
|---|
| 771 | if (request->buffer_size == 0)
|
|---|
| 772 | TRANSFER_END(request, EOVERFLOW);
|
|---|
| 773 | uint8_t config = 1;
|
|---|
| 774 | TRANSFER_END_DATA(request, &config, sizeof(config));
|
|---|
| 775 |
|
|---|
| 776 | case USB_DEVREQ_CLEAR_FEATURE:
|
|---|
| 777 | usb_log_debug2("USB_DEVREQ_CLEAR_FEATURE\n");
|
|---|
| 778 | clear_feature(instance, request);
|
|---|
| 779 | break;
|
|---|
| 780 |
|
|---|
| 781 | case USB_DEVREQ_SET_FEATURE:
|
|---|
| 782 | usb_log_debug2("USB_DEVREQ_SET_FEATURE\n");
|
|---|
| 783 | set_feature(instance, request);
|
|---|
| 784 | break;
|
|---|
| 785 |
|
|---|
| 786 | case USB_DEVREQ_SET_ADDRESS:
|
|---|
| 787 | usb_log_debug("USB_DEVREQ_SET_ADDRESS: %u\n",
|
|---|
| 788 | setup_request->value);
|
|---|
| 789 | if (uint16_usb2host(setup_request->value) > 127)
|
|---|
| 790 | TRANSFER_END(request, EINVAL);
|
|---|
| 791 |
|
|---|
| 792 | instance->address = setup_request->value;
|
|---|
| 793 | TRANSFER_END(request, EOK);
|
|---|
| 794 |
|
|---|
| 795 | case USB_DEVREQ_SET_CONFIGURATION:
|
|---|
| 796 | usb_log_debug("USB_DEVREQ_SET_CONFIGURATION: %u\n",
|
|---|
| 797 | setup_request->value);
|
|---|
| 798 | /* We have only one configuration, it's number is 1 */
|
|---|
| 799 | if (uint16_usb2host(setup_request->value) != 1)
|
|---|
| 800 | TRANSFER_END(request, EINVAL);
|
|---|
| 801 | TRANSFER_END(request, EOK);
|
|---|
| 802 |
|
|---|
| 803 | /* Both class specific and std is optional for hubs */
|
|---|
| 804 | case USB_DEVREQ_SET_DESCRIPTOR:
|
|---|
| 805 | /* Hubs have only one interface GET/SET is not supported */
|
|---|
| 806 | case USB_DEVREQ_GET_INTERFACE:
|
|---|
| 807 | case USB_DEVREQ_SET_INTERFACE:
|
|---|
| 808 | default:
|
|---|
| 809 | /* Hub class GET_STATE(2) falls in here too. */
|
|---|
| 810 | usb_log_error("Received unsupported request: %d.\n",
|
|---|
| 811 | setup_request->request);
|
|---|
| 812 | TRANSFER_END(request, ENOTSUP);
|
|---|
| 813 | }
|
|---|
| 814 | }
|
|---|
| 815 | /**
|
|---|
| 816 | * @}
|
|---|
| 817 | */
|
|---|