[41b96b4] | 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
|
---|
[81dce9f] | 32 | * @brief OHCI driver
|
---|
[41b96b4] | 33 | */
|
---|
| 34 | #include <assert.h>
|
---|
| 35 | #include <errno.h>
|
---|
| 36 | #include <str_error.h>
|
---|
| 37 |
|
---|
| 38 | #include <usb/debug.h>
|
---|
| 39 |
|
---|
[bab71635] | 40 | #include "root_hub.h"
|
---|
[d8421c4] | 41 | #include "usb/classes/classes.h"
|
---|
[66a54cc] | 42 | #include "usb/devdrv.h"
|
---|
[4d0c40b] | 43 | #include <usb/request.h>
|
---|
| 44 | #include <usb/classes/hub.h>
|
---|
| 45 |
|
---|
[0368669c] | 46 | /**
|
---|
| 47 | * standart device descriptor for ohci root hub
|
---|
| 48 | */
|
---|
[8b74997f] | 49 | static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = {
|
---|
| 50 | .configuration_count = 1,
|
---|
| 51 | .descriptor_type = USB_DESCTYPE_DEVICE,
|
---|
| 52 | .device_class = USB_CLASS_HUB,
|
---|
| 53 | .device_protocol = 0,
|
---|
| 54 | .device_subclass = 0,
|
---|
| 55 | .device_version = 0,
|
---|
| 56 | .length = sizeof (usb_standard_device_descriptor_t),
|
---|
| 57 | /// \TODO this value is guessed
|
---|
| 58 | .max_packet_size = 8,
|
---|
| 59 | .vendor_id = 0x16db,
|
---|
| 60 | .product_id = 0x0001,
|
---|
| 61 | /// \TODO these values migt be different
|
---|
| 62 | .str_serial_number = 0,
|
---|
| 63 | .usb_spec_version = 0x110,
|
---|
[b3f655f] | 64 | };
|
---|
| 65 |
|
---|
[0368669c] | 66 | /**
|
---|
| 67 | * standart configuration descriptor with filled common values
|
---|
| 68 | * for ohci root hubs
|
---|
| 69 | */
|
---|
[8b74997f] | 70 | static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = {
|
---|
[b3f655f] | 71 | /// \TODO some values are default or guessed
|
---|
[8b74997f] | 72 | .attributes = 1 << 7,
|
---|
[b3f655f] | 73 | .configuration_number = 1,
|
---|
| 74 | .descriptor_type = USB_DESCTYPE_CONFIGURATION,
|
---|
| 75 | .interface_count = 1,
|
---|
[8b74997f] | 76 | .length = sizeof (usb_standard_configuration_descriptor_t),
|
---|
[b3f655f] | 77 | .max_power = 100,
|
---|
| 78 | .str_configuration = 0,
|
---|
| 79 | };
|
---|
| 80 |
|
---|
[0368669c] | 81 | /**
|
---|
| 82 | * standart ohci root hub interface descriptor
|
---|
| 83 | */
|
---|
[8b74997f] | 84 | static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor = {
|
---|
[b3f655f] | 85 | .alternate_setting = 0,
|
---|
| 86 | .descriptor_type = USB_DESCTYPE_INTERFACE,
|
---|
| 87 | .endpoint_count = 1,
|
---|
| 88 | .interface_class = USB_CLASS_HUB,
|
---|
| 89 | /// \TODO is this correct?
|
---|
| 90 | .interface_number = 1,
|
---|
| 91 | .interface_protocol = 0,
|
---|
| 92 | .interface_subclass = 0,
|
---|
[8b74997f] | 93 | .length = sizeof (usb_standard_interface_descriptor_t),
|
---|
[b3f655f] | 94 | .str_interface = 0,
|
---|
| 95 | };
|
---|
| 96 |
|
---|
[0368669c] | 97 | /**
|
---|
| 98 | * standart ohci root hub endpoint descriptor
|
---|
| 99 | */
|
---|
[8b74997f] | 100 | static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor = {
|
---|
[b3f655f] | 101 | .attributes = USB_TRANSFER_INTERRUPT,
|
---|
| 102 | .descriptor_type = USB_DESCTYPE_ENDPOINT,
|
---|
[8b74997f] | 103 | .endpoint_address = 1 + (1 << 7),
|
---|
| 104 | .length = sizeof (usb_standard_endpoint_descriptor_t),
|
---|
[b3f655f] | 105 | .max_packet_size = 8,
|
---|
| 106 | .poll_interval = 255,
|
---|
| 107 | };
|
---|
[41b96b4] | 108 |
|
---|
[8123695a] | 109 | static const uint32_t hub_clear_feature_valid_mask =
|
---|
[8b74997f] | 110 | (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) |
|
---|
| 111 | (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
|
---|
[8123695a] | 112 |
|
---|
| 113 | static const uint32_t hub_clear_feature_by_writing_one_mask =
|
---|
| 114 | 1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
|
---|
| 115 |
|
---|
| 116 | static const uint32_t hub_set_feature_valid_mask =
|
---|
[f35b294] | 117 | (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
|
---|
| 118 | (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
|
---|
[8123695a] | 119 |
|
---|
[8b74997f] | 120 |
|
---|
[8123695a] | 121 | static const uint32_t hub_set_feature_direct_mask =
|
---|
| 122 | (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
|
---|
| 123 |
|
---|
| 124 | static const uint32_t port_set_feature_valid_mask =
|
---|
[8b74997f] | 125 | (1 << USB_HUB_FEATURE_PORT_ENABLE) |
|
---|
| 126 | (1 << USB_HUB_FEATURE_PORT_SUSPEND) |
|
---|
| 127 | (1 << USB_HUB_FEATURE_PORT_RESET) |
|
---|
| 128 | (1 << USB_HUB_FEATURE_PORT_POWER);
|
---|
[8123695a] | 129 |
|
---|
| 130 | static const uint32_t port_clear_feature_valid_mask =
|
---|
[8b74997f] | 131 | (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
|
---|
| 132 | (1 << USB_HUB_FEATURE_PORT_SUSPEND) |
|
---|
| 133 | (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) |
|
---|
| 134 | (1 << USB_HUB_FEATURE_PORT_POWER) |
|
---|
| 135 | (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) |
|
---|
| 136 | (1 << USB_HUB_FEATURE_C_PORT_ENABLE) |
|
---|
| 137 | (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) |
|
---|
| 138 | (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
|
---|
| 139 | (1 << USB_HUB_FEATURE_C_PORT_RESET);
|
---|
| 140 | //note that USB_HUB_FEATURE_PORT_POWER bit is translated into
|
---|
| 141 | //USB_HUB_FEATURE_PORT_LOW_SPEED
|
---|
| 142 |
|
---|
| 143 | static const uint32_t port_status_change_mask =
|
---|
| 144 | (1<< USB_HUB_FEATURE_C_PORT_CONNECTION) |
|
---|
| 145 | (1<< USB_HUB_FEATURE_C_PORT_ENABLE) |
|
---|
| 146 | (1<< USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
|
---|
| 147 | (1<< USB_HUB_FEATURE_C_PORT_RESET) |
|
---|
| 148 | (1<< USB_HUB_FEATURE_C_PORT_SUSPEND);
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | static void usb_create_serialized_hub_descriptor(rh_t *instance,
|
---|
| 152 | uint8_t ** out_result,
|
---|
| 153 | size_t * out_size);
|
---|
| 154 |
|
---|
| 155 | static void rh_init_descriptors(rh_t *instance);
|
---|
| 156 |
|
---|
| 157 | static int process_get_port_status_request(rh_t *instance, uint16_t port,
|
---|
| 158 | usb_transfer_batch_t * request);
|
---|
| 159 |
|
---|
| 160 | static int process_get_hub_status_request(rh_t *instance,
|
---|
| 161 | usb_transfer_batch_t * request);
|
---|
| 162 |
|
---|
| 163 | static int process_get_status_request(rh_t *instance,
|
---|
| 164 | usb_transfer_batch_t * request);
|
---|
| 165 |
|
---|
| 166 | static void create_interrupt_mask(rh_t *instance, void ** buffer,
|
---|
| 167 | size_t * buffer_size);
|
---|
| 168 |
|
---|
| 169 | static int process_get_descriptor_request(rh_t *instance,
|
---|
| 170 | usb_transfer_batch_t *request);
|
---|
| 171 |
|
---|
| 172 | static int process_get_configuration_request(rh_t *instance,
|
---|
| 173 | usb_transfer_batch_t *request);
|
---|
| 174 |
|
---|
| 175 | static int process_hub_feature_set_request(rh_t *instance, uint16_t feature);
|
---|
| 176 |
|
---|
| 177 | static int process_hub_feature_clear_request(rh_t *instance,
|
---|
| 178 | uint16_t feature);
|
---|
| 179 |
|
---|
| 180 | static int process_port_feature_set_request(rh_t *instance,
|
---|
| 181 | uint16_t feature, uint16_t port);
|
---|
| 182 |
|
---|
| 183 | static int process_port_feature_clear_request(rh_t *instance,
|
---|
| 184 | uint16_t feature, uint16_t port);
|
---|
| 185 |
|
---|
| 186 | static int process_address_set_request(rh_t *instance,
|
---|
| 187 | uint16_t address);
|
---|
| 188 |
|
---|
| 189 | static int process_request_with_output(rh_t *instance,
|
---|
| 190 | usb_transfer_batch_t *request);
|
---|
| 191 |
|
---|
| 192 | static int process_request_with_input(rh_t *instance,
|
---|
| 193 | usb_transfer_batch_t *request);
|
---|
| 194 |
|
---|
| 195 | static int process_request_without_data(rh_t *instance,
|
---|
| 196 | usb_transfer_batch_t *request);
|
---|
[8123695a] | 197 |
|
---|
[8b74997f] | 198 | static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request);
|
---|
[8123695a] | 199 |
|
---|
| 200 |
|
---|
| 201 |
|
---|
[8b74997f] | 202 |
|
---|
| 203 |
|
---|
| 204 | /** Root hub initialization
|
---|
| 205 | * @return Error code.
|
---|
| 206 | */
|
---|
| 207 | int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs) {
|
---|
| 208 | assert(instance);
|
---|
| 209 | //instance->address = -1;
|
---|
| 210 | instance->registers = regs;
|
---|
| 211 | instance->device = dev;
|
---|
[112d159] | 212 | instance->port_count =
|
---|
| 213 | (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
|
---|
[8b74997f] | 214 | rh_init_descriptors(instance);
|
---|
| 215 | // set port power mode to no-power-switching
|
---|
| 216 | instance->registers->rh_desc_a =
|
---|
| 217 | instance->registers->rh_desc_a | (1<<9);
|
---|
| 218 |
|
---|
| 219 | usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
|
---|
| 220 |
|
---|
| 221 | //start generic usb hub driver
|
---|
| 222 |
|
---|
| 223 | /* TODO: implement */
|
---|
| 224 | return EOK;
|
---|
| 225 | }
|
---|
| 226 | /*----------------------------------------------------------------------------*/
|
---|
| 227 |
|
---|
| 228 | /**
|
---|
| 229 | * process root hub request
|
---|
| 230 | *
|
---|
| 231 | * @param instance root hub instance
|
---|
| 232 | * @param request structure containing both request and response information
|
---|
| 233 | * @return error code
|
---|
| 234 | */
|
---|
| 235 | int rh_request(rh_t *instance, usb_transfer_batch_t *request) {
|
---|
| 236 | assert(instance);
|
---|
| 237 | assert(request);
|
---|
| 238 | int opResult;
|
---|
| 239 | if (request->transfer_type == USB_TRANSFER_CONTROL) {
|
---|
| 240 | usb_log_info("Root hub got CONTROL packet\n");
|
---|
| 241 | opResult = process_ctrl_request(instance, request);
|
---|
| 242 | } else if (request->transfer_type == USB_TRANSFER_INTERRUPT) {
|
---|
| 243 | usb_log_info("Root hub got INTERRUPT packet\n");
|
---|
| 244 | void * buffer;
|
---|
| 245 | create_interrupt_mask(instance, &buffer,
|
---|
| 246 | &(request->transfered_size));
|
---|
| 247 | memcpy(request->transport_buffer, buffer,
|
---|
| 248 | request->transfered_size);
|
---|
| 249 | opResult = EOK;
|
---|
| 250 | } else {
|
---|
| 251 | opResult = EINVAL;
|
---|
| 252 | }
|
---|
[4b39af4] | 253 | usb_transfer_batch_finish_error(request, opResult);
|
---|
[8b74997f] | 254 | return EOK;
|
---|
| 255 | }
|
---|
[8123695a] | 256 |
|
---|
[8b74997f] | 257 | /*----------------------------------------------------------------------------*/
|
---|
[8123695a] | 258 |
|
---|
| 259 |
|
---|
[8b74997f] | 260 | void rh_interrupt(rh_t *instance) {
|
---|
| 261 | usb_log_info("Whoa whoa wait, I`m not supposed to receive any "
|
---|
| 262 | "interrupts, am I?\n");
|
---|
| 263 | /* TODO: implement? */
|
---|
| 264 | }
|
---|
| 265 | /*----------------------------------------------------------------------------*/
|
---|
[8123695a] | 266 |
|
---|
[66a54cc] | 267 | /**
|
---|
| 268 | * Create hub descriptor used in hub-driver <-> hub communication
|
---|
| 269 | *
|
---|
| 270 | * This means creating byt array from data in root hub registers. For more
|
---|
| 271 | * info see usb hub specification.
|
---|
| 272 | *
|
---|
| 273 | * @param instance root hub instance
|
---|
| 274 | * @param@out out_result pointer to resultant serialized descriptor
|
---|
| 275 | * @param@out out_size size of serialized descriptor
|
---|
| 276 | */
|
---|
| 277 | static void usb_create_serialized_hub_descriptor(rh_t *instance,
|
---|
[8b74997f] | 278 | uint8_t ** out_result,
|
---|
| 279 | size_t * out_size) {
|
---|
[66a54cc] | 280 | //base size
|
---|
| 281 | size_t size = 7;
|
---|
| 282 | //variable size according to port count
|
---|
| 283 | size_t var_size = instance->port_count / 8 +
|
---|
[8b74997f] | 284 | ((instance->port_count % 8 > 0) ? 1 : 0);
|
---|
[66a54cc] | 285 | size += 2 * var_size;
|
---|
| 286 | uint8_t * result = (uint8_t*) malloc(size);
|
---|
[8b74997f] | 287 | bzero(result, size);
|
---|
[66a54cc] | 288 | //size
|
---|
| 289 | result[0] = size;
|
---|
| 290 | //descriptor type
|
---|
| 291 | result[1] = USB_DESCTYPE_HUB;
|
---|
| 292 | result[2] = instance->port_count;
|
---|
| 293 | uint32_t hub_desc_reg = instance->registers->rh_desc_a;
|
---|
| 294 | result[3] =
|
---|
[8b74997f] | 295 | ((hub_desc_reg >> 8) % 2) +
|
---|
| 296 | (((hub_desc_reg >> 9) % 2) << 1) +
|
---|
| 297 | (((hub_desc_reg >> 10) % 2) << 2) +
|
---|
| 298 | (((hub_desc_reg >> 11) % 2) << 3) +
|
---|
| 299 | (((hub_desc_reg >> 12) % 2) << 4);
|
---|
[66a54cc] | 300 | result[4] = 0;
|
---|
| 301 | result[5] = /*descriptor->pwr_on_2_good_time*/ 50;
|
---|
| 302 | result[6] = 50;
|
---|
| 303 |
|
---|
| 304 | int port;
|
---|
| 305 | for (port = 1; port <= instance->port_count; ++port) {
|
---|
[8b74997f] | 306 | uint8_t is_non_removable =
|
---|
| 307 | instance->registers->rh_desc_b >> port % 2;
|
---|
| 308 | result[7 + port / 8] +=
|
---|
| 309 | is_non_removable << (port % 8);
|
---|
[66a54cc] | 310 | }
|
---|
| 311 | size_t i;
|
---|
| 312 | for (i = 0; i < var_size; ++i) {
|
---|
| 313 | result[7 + var_size + i] = 255;
|
---|
| 314 | }
|
---|
| 315 | (*out_result) = result;
|
---|
| 316 | (*out_size) = size;
|
---|
| 317 | }
|
---|
[8b74997f] | 318 | /*----------------------------------------------------------------------------*/
|
---|
[66a54cc] | 319 |
|
---|
| 320 | /** initialize hub descriptors
|
---|
| 321 | *
|
---|
| 322 | * Initialized are device and full configuration descriptor. These need to
|
---|
| 323 | * be initialized only once per hub.
|
---|
| 324 | * @instance root hub instance
|
---|
| 325 | */
|
---|
[8b74997f] | 326 | static void rh_init_descriptors(rh_t *instance) {
|
---|
[66a54cc] | 327 | memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
|
---|
[8b74997f] | 328 | sizeof (ohci_rh_device_descriptor)
|
---|
| 329 | );
|
---|
[66a54cc] | 330 | usb_standard_configuration_descriptor_t descriptor;
|
---|
[8b74997f] | 331 | memcpy(&descriptor, &ohci_rh_conf_descriptor,
|
---|
| 332 | sizeof (ohci_rh_conf_descriptor));
|
---|
[66a54cc] | 333 | uint8_t * hub_descriptor;
|
---|
| 334 | size_t hub_desc_size;
|
---|
| 335 | usb_create_serialized_hub_descriptor(instance, &hub_descriptor,
|
---|
[8b74997f] | 336 | &hub_desc_size);
|
---|
[66a54cc] | 337 |
|
---|
| 338 | descriptor.total_length =
|
---|
[8b74997f] | 339 | sizeof (usb_standard_configuration_descriptor_t) +
|
---|
| 340 | sizeof (usb_standard_endpoint_descriptor_t) +
|
---|
| 341 | sizeof (usb_standard_interface_descriptor_t) +
|
---|
| 342 | hub_desc_size;
|
---|
| 343 |
|
---|
[66a54cc] | 344 | uint8_t * full_config_descriptor =
|
---|
[8b74997f] | 345 | (uint8_t*) malloc(descriptor.total_length);
|
---|
| 346 | memcpy(full_config_descriptor, &descriptor, sizeof (descriptor));
|
---|
| 347 | memcpy(full_config_descriptor + sizeof (descriptor),
|
---|
| 348 | &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor));
|
---|
| 349 | memcpy(full_config_descriptor + sizeof (descriptor) +
|
---|
| 350 | sizeof (ohci_rh_iface_descriptor),
|
---|
| 351 | &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor));
|
---|
| 352 | memcpy(full_config_descriptor + sizeof (descriptor) +
|
---|
| 353 | sizeof (ohci_rh_iface_descriptor) +
|
---|
| 354 | sizeof (ohci_rh_ep_descriptor),
|
---|
| 355 | hub_descriptor, hub_desc_size);
|
---|
| 356 |
|
---|
[66a54cc] | 357 | instance->descriptors.configuration = full_config_descriptor;
|
---|
| 358 | instance->descriptors.configuration_size = descriptor.total_length;
|
---|
| 359 | }
|
---|
[41b96b4] | 360 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 361 |
|
---|
[f3da9b2] | 362 | /**
|
---|
| 363 | * create answer to port status_request
|
---|
| 364 | *
|
---|
| 365 | * Copy content of corresponding port status register to answer buffer.
|
---|
| 366 | *
|
---|
| 367 | * @param instance root hub instance
|
---|
| 368 | * @param port port number, counted from 1
|
---|
| 369 | * @param request structure containing both request and response information
|
---|
| 370 | * @return error code
|
---|
| 371 | */
|
---|
[4d0c40b] | 372 | static int process_get_port_status_request(rh_t *instance, uint16_t port,
|
---|
[8b74997f] | 373 | usb_transfer_batch_t * request) {
|
---|
| 374 | if (port < 1 || port > instance->port_count)
|
---|
[4d0c40b] | 375 | return EINVAL;
|
---|
[8b74997f] | 376 | uint32_t * uint32_buffer = (uint32_t*) request->transport_buffer;
|
---|
[d8421c4] | 377 | request->transfered_size = 4;
|
---|
[8b74997f] | 378 | uint32_buffer[0] = instance->registers->rh_port_status[port - 1];
|
---|
| 379 | #if 0
|
---|
| 380 | int i;
|
---|
| 381 | for (i = 0; i < instance->port_count; ++i) {
|
---|
| 382 | usb_log_debug("port status %d,x%x\n",
|
---|
| 383 | instance->registers->rh_port_status[i],
|
---|
| 384 | instance->registers->rh_port_status[i]);
|
---|
| 385 | }
|
---|
| 386 | #endif
|
---|
[4d0c40b] | 387 | return EOK;
|
---|
| 388 | }
|
---|
[8b74997f] | 389 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 390 |
|
---|
[f3da9b2] | 391 | /**
|
---|
| 392 | * create answer to port status_request
|
---|
| 393 | *
|
---|
| 394 | * Copy content of hub status register to answer buffer.
|
---|
| 395 | *
|
---|
| 396 | * @param instance root hub instance
|
---|
| 397 | * @param request structure containing both request and response information
|
---|
| 398 | * @return error code
|
---|
| 399 | */
|
---|
[d8421c4] | 400 | static int process_get_hub_status_request(rh_t *instance,
|
---|
[8b74997f] | 401 | usb_transfer_batch_t * request) {
|
---|
| 402 | uint32_t * uint32_buffer = (uint32_t*) request->transport_buffer;
|
---|
[d8421c4] | 403 | request->transfered_size = 4;
|
---|
[8b74997f] | 404 | //bits, 0,1,16,17
|
---|
| 405 | uint32_t mask = 1 | (1 << 1) | (1 << 16) | (1 << 17);
|
---|
[4d0c40b] | 406 | uint32_buffer[0] = mask & instance->registers->rh_status;
|
---|
| 407 | return EOK;
|
---|
| 408 | }
|
---|
[8b74997f] | 409 | /*----------------------------------------------------------------------------*/
|
---|
[d8421c4] | 410 |
|
---|
[f3da9b2] | 411 | /**
|
---|
| 412 | * create answer to status request
|
---|
| 413 | *
|
---|
| 414 | * This might be either hub status or port status request. If neither,
|
---|
| 415 | * ENOTSUP is returned.
|
---|
| 416 | * @param instance root hub instance
|
---|
| 417 | * @param request structure containing both request and response information
|
---|
| 418 | * @return error code
|
---|
| 419 | */
|
---|
[d8421c4] | 420 | static int process_get_status_request(rh_t *instance,
|
---|
[8b74997f] | 421 | usb_transfer_batch_t * request) {
|
---|
[d8421c4] | 422 | size_t buffer_size = request->buffer_size;
|
---|
| 423 | usb_device_request_setup_packet_t * request_packet =
|
---|
[8b74997f] | 424 | (usb_device_request_setup_packet_t*)
|
---|
| 425 | request->setup_buffer;
|
---|
[d8421c4] | 426 |
|
---|
| 427 | usb_hub_bm_request_type_t request_type = request_packet->request_type;
|
---|
[8b74997f] | 428 | if (buffer_size < 4/*request_packet->length*/) {///\TODO
|
---|
[d8421c4] | 429 | usb_log_warning("requested more data than buffer size\n");
|
---|
| 430 | return EINVAL;
|
---|
| 431 | }
|
---|
[4d0c40b] | 432 |
|
---|
[8b74997f] | 433 | if (request_type == USB_HUB_REQ_TYPE_GET_HUB_STATUS)
|
---|
[d8421c4] | 434 | return process_get_hub_status_request(instance, request);
|
---|
[8b74997f] | 435 | if (request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS)
|
---|
| 436 | return process_get_port_status_request(instance,
|
---|
| 437 | request_packet->index,
|
---|
| 438 | request);
|
---|
[4d0c40b] | 439 | return ENOTSUP;
|
---|
| 440 | }
|
---|
[8b74997f] | 441 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 442 |
|
---|
[f3da9b2] | 443 | /**
|
---|
| 444 | * create answer to status interrupt consisting of change bitmap
|
---|
| 445 | *
|
---|
| 446 | * Result contains bitmap where bit 0 indicates change on hub and
|
---|
| 447 | * bit i indicates change on i`th port (i>0). For more info see
|
---|
[8b74997f] | 448 | * Hub and Port status bitmap specification in USB specification
|
---|
| 449 | * (chapter 11.13.4)
|
---|
[f3da9b2] | 450 | * @param instance root hub instance
|
---|
| 451 | * @param@out buffer pointer to created interrupt mas
|
---|
| 452 | * @param@out buffer_size size of created interrupt mask
|
---|
| 453 | */
|
---|
[d8421c4] | 454 | static void create_interrupt_mask(rh_t *instance, void ** buffer,
|
---|
[8b74997f] | 455 | size_t * buffer_size) {
|
---|
[d8421c4] | 456 | int bit_count = instance->port_count + 1;
|
---|
[8b74997f] | 457 | (*buffer_size) = (bit_count / 8) + ((bit_count % 8 == 0) ? 0 : 1);
|
---|
| 458 |
|
---|
[d8421c4] | 459 | (*buffer) = malloc(*buffer_size);
|
---|
[8b74997f] | 460 | uint8_t * bitmap = (uint8_t*) (*buffer);
|
---|
| 461 | uint32_t mask = (1 << (USB_HUB_FEATURE_C_HUB_LOCAL_POWER + 16))
|
---|
| 462 | | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
|
---|
| 463 | bzero(bitmap, (*buffer_size));
|
---|
| 464 | if (instance->registers->rh_status & mask) {
|
---|
[d8421c4] | 465 | bitmap[0] = 1;
|
---|
| 466 | }
|
---|
| 467 | int port;
|
---|
[8b74997f] | 468 | mask = port_status_change_mask;
|
---|
| 469 | for (port = 1; port <= instance->port_count; ++port) {
|
---|
| 470 | if (mask & instance->registers->rh_port_status[port - 1]) {
|
---|
| 471 | bitmap[(port) / 8] += 1 << (port % 8);
|
---|
[d8421c4] | 472 | }
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
[8b74997f] | 475 | /*----------------------------------------------------------------------------*/
|
---|
| 476 |
|
---|
[f3da9b2] | 477 | /**
|
---|
| 478 | * create answer to a descriptor request
|
---|
| 479 | *
|
---|
| 480 | * This might be a request for standard (configuration, device, endpoint or
|
---|
| 481 | * interface) or device specific (hub) descriptor.
|
---|
| 482 | * @param instance root hub instance
|
---|
| 483 | * @param request structure containing both request and response information
|
---|
| 484 | * @return error code
|
---|
| 485 | */
|
---|
[4d0c40b] | 486 | static int process_get_descriptor_request(rh_t *instance,
|
---|
[8b74997f] | 487 | usb_transfer_batch_t *request) {
|
---|
[4d0c40b] | 488 | usb_device_request_setup_packet_t * setup_request =
|
---|
[8b74997f] | 489 | (usb_device_request_setup_packet_t*) request->setup_buffer;
|
---|
[d8421c4] | 490 | size_t size;
|
---|
[aee6c73] | 491 | const void * result_descriptor = NULL;
|
---|
[b3f655f] | 492 | const uint16_t setup_request_value = setup_request->value_high;
|
---|
[8b74997f] | 493 | //(setup_request->value_low << 8);
|
---|
[b3f655f] | 494 | bool del = false;
|
---|
[8b74997f] | 495 | switch (setup_request_value) {
|
---|
| 496 | case USB_DESCTYPE_HUB:
|
---|
| 497 | {
|
---|
[0368669c] | 498 | uint8_t * descriptor;
|
---|
| 499 | usb_create_serialized_hub_descriptor(
|
---|
| 500 | instance, &descriptor, &size);
|
---|
| 501 | result_descriptor = descriptor;
|
---|
[8b74997f] | 502 | if (result_descriptor) del = true;
|
---|
[0368669c] | 503 | break;
|
---|
| 504 | }
|
---|
[8b74997f] | 505 | case USB_DESCTYPE_DEVICE:
|
---|
| 506 | {
|
---|
[0368669c] | 507 | usb_log_debug("USB_DESCTYPE_DEVICE\n");
|
---|
| 508 | result_descriptor = &ohci_rh_device_descriptor;
|
---|
[8b74997f] | 509 | size = sizeof (ohci_rh_device_descriptor);
|
---|
[0368669c] | 510 | break;
|
---|
| 511 | }
|
---|
[8b74997f] | 512 | case USB_DESCTYPE_CONFIGURATION:
|
---|
| 513 | {
|
---|
[0368669c] | 514 | usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
|
---|
[66a54cc] | 515 | result_descriptor = instance->descriptors.configuration;
|
---|
| 516 | size = instance->descriptors.configuration_size;
|
---|
[0368669c] | 517 | break;
|
---|
| 518 | }
|
---|
[8b74997f] | 519 | case USB_DESCTYPE_INTERFACE:
|
---|
| 520 | {
|
---|
[0368669c] | 521 | usb_log_debug("USB_DESCTYPE_INTERFACE\n");
|
---|
| 522 | result_descriptor = &ohci_rh_iface_descriptor;
|
---|
[8b74997f] | 523 | size = sizeof (ohci_rh_iface_descriptor);
|
---|
[0368669c] | 524 | break;
|
---|
| 525 | }
|
---|
[8b74997f] | 526 | case USB_DESCTYPE_ENDPOINT:
|
---|
| 527 | {
|
---|
[0368669c] | 528 | usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
|
---|
| 529 | result_descriptor = &ohci_rh_ep_descriptor;
|
---|
[8b74997f] | 530 | size = sizeof (ohci_rh_ep_descriptor);
|
---|
[0368669c] | 531 | break;
|
---|
| 532 | }
|
---|
[8b74997f] | 533 | default:
|
---|
| 534 | {
|
---|
| 535 | usb_log_debug("USB_DESCTYPE_EINVAL %d \n",
|
---|
| 536 | setup_request->value);
|
---|
| 537 | usb_log_debug("\ttype %d\n\trequest %d\n\tvalue "
|
---|
| 538 | "%d\n\tindex %d\n\tlen %d\n ",
|
---|
| 539 | setup_request->request_type,
|
---|
| 540 | setup_request->request,
|
---|
| 541 | setup_request_value,
|
---|
| 542 | setup_request->index,
|
---|
| 543 | setup_request->length
|
---|
| 544 | );
|
---|
[0368669c] | 545 | return EINVAL;
|
---|
| 546 | }
|
---|
[4d0c40b] | 547 | }
|
---|
[8b74997f] | 548 | if (request->buffer_size < size) {
|
---|
[d8421c4] | 549 | size = request->buffer_size;
|
---|
| 550 | }
|
---|
| 551 | request->transfered_size = size;
|
---|
[8b74997f] | 552 | memcpy(request->transport_buffer, result_descriptor, size);
|
---|
[0368669c] | 553 | if (del)
|
---|
[b3f655f] | 554 | free(result_descriptor);
|
---|
[4d0c40b] | 555 | return EOK;
|
---|
| 556 | }
|
---|
[8b74997f] | 557 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 558 |
|
---|
[f3da9b2] | 559 | /**
|
---|
| 560 | * answer to get configuration request
|
---|
| 561 | *
|
---|
| 562 | * Root hub works independently on the configuration.
|
---|
| 563 | * @param instance root hub instance
|
---|
| 564 | * @param request structure containing both request and response information
|
---|
| 565 | * @return error code
|
---|
| 566 | */
|
---|
[8b74997f] | 567 | static int process_get_configuration_request(rh_t *instance,
|
---|
| 568 | usb_transfer_batch_t *request) {
|
---|
[4d0c40b] | 569 | //set and get configuration requests do not have any meaning, only dummy
|
---|
| 570 | //values are returned
|
---|
[8b74997f] | 571 | if (request->buffer_size != 1)
|
---|
[4d0c40b] | 572 | return EINVAL;
|
---|
[ccbcd895] | 573 | request->transport_buffer[0] = 1;
|
---|
[d8421c4] | 574 | request->transfered_size = 1;
|
---|
[4d0c40b] | 575 | return EOK;
|
---|
| 576 | }
|
---|
[8b74997f] | 577 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 578 |
|
---|
[f3da9b2] | 579 | /**
|
---|
[8123695a] | 580 | * process feature-enabling request on hub
|
---|
[8b74997f] | 581 | *
|
---|
[f3da9b2] | 582 | * @param instance root hub instance
|
---|
| 583 | * @param feature feature selector
|
---|
| 584 | * @return error code
|
---|
| 585 | */
|
---|
[4d0c40b] | 586 | static int process_hub_feature_set_request(rh_t *instance,
|
---|
[8b74997f] | 587 | uint16_t feature) {
|
---|
| 588 | if (!((1 << feature) & hub_set_feature_valid_mask))
|
---|
[4d0c40b] | 589 | return EINVAL;
|
---|
[f35b294] | 590 | if(feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)
|
---|
| 591 | feature = USB_HUB_FEATURE_C_HUB_LOCAL_POWER << 16;
|
---|
[4d0c40b] | 592 | instance->registers->rh_status =
|
---|
[8b74997f] | 593 | (instance->registers->rh_status | (1 << feature))
|
---|
| 594 | & (~hub_clear_feature_by_writing_one_mask);
|
---|
[4d0c40b] | 595 | return EOK;
|
---|
| 596 | }
|
---|
[8b74997f] | 597 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 598 |
|
---|
[f3da9b2] | 599 | /**
|
---|
[8123695a] | 600 | * process feature-disabling request on hub
|
---|
| 601 | *
|
---|
| 602 | * @param instance root hub instance
|
---|
| 603 | * @param feature feature selector
|
---|
| 604 | * @return error code
|
---|
| 605 | */
|
---|
| 606 | static int process_hub_feature_clear_request(rh_t *instance,
|
---|
[8b74997f] | 607 | uint16_t feature) {
|
---|
| 608 | if (!((1 << feature) & hub_clear_feature_valid_mask))
|
---|
[8123695a] | 609 | return EINVAL;
|
---|
| 610 | //is the feature cleared directly?
|
---|
[8b74997f] | 611 | if ((1 << feature) & hub_set_feature_direct_mask) {
|
---|
[8123695a] | 612 | instance->registers->rh_status =
|
---|
[8b74997f] | 613 | (instance->registers->rh_status & (~(1 << feature)))
|
---|
| 614 | & (~hub_clear_feature_by_writing_one_mask);
|
---|
| 615 | } else {//the feature is cleared by writing '1'
|
---|
[8123695a] | 616 | instance->registers->rh_status =
|
---|
[8b74997f] | 617 | (instance->registers->rh_status
|
---|
| 618 | & (~hub_clear_feature_by_writing_one_mask))
|
---|
| 619 | | (1 << feature);
|
---|
[8123695a] | 620 | }
|
---|
| 621 | return EOK;
|
---|
| 622 | }
|
---|
[8b74997f] | 623 | /*----------------------------------------------------------------------------*/
|
---|
[8123695a] | 624 |
|
---|
| 625 | /**
|
---|
| 626 | * process feature-enabling request on hub
|
---|
[8b74997f] | 627 | *
|
---|
[f3da9b2] | 628 | * @param instance root hub instance
|
---|
| 629 | * @param feature feature selector
|
---|
| 630 | * @param port port number, counted from 1
|
---|
| 631 | * @param enable enable or disable the specified feature
|
---|
| 632 | * @return error code
|
---|
| 633 | */
|
---|
[4d0c40b] | 634 | static int process_port_feature_set_request(rh_t *instance,
|
---|
[8b74997f] | 635 | uint16_t feature, uint16_t port) {
|
---|
| 636 | if (!((1 << feature) & port_set_feature_valid_mask))
|
---|
[4d0c40b] | 637 | return EINVAL;
|
---|
[8b74997f] | 638 | if (port < 1 || port > instance->port_count)
|
---|
[4d0c40b] | 639 | return EINVAL;
|
---|
| 640 | instance->registers->rh_port_status[port - 1] =
|
---|
[8b74997f] | 641 | (instance->registers->rh_port_status[port - 1] | (1 << feature))
|
---|
| 642 | & (~port_clear_feature_valid_mask);
|
---|
[8123695a] | 643 | /// \TODO any error?
|
---|
| 644 | return EOK;
|
---|
| 645 | }
|
---|
[8b74997f] | 646 | /*----------------------------------------------------------------------------*/
|
---|
[8123695a] | 647 |
|
---|
| 648 | /**
|
---|
| 649 | * process feature-disabling request on hub
|
---|
| 650 | *
|
---|
| 651 | * @param instance root hub instance
|
---|
| 652 | * @param feature feature selector
|
---|
| 653 | * @param port port number, counted from 1
|
---|
| 654 | * @param enable enable or disable the specified feature
|
---|
| 655 | * @return error code
|
---|
| 656 | */
|
---|
| 657 | static int process_port_feature_clear_request(rh_t *instance,
|
---|
[8b74997f] | 658 | uint16_t feature, uint16_t port) {
|
---|
| 659 | if (!((1 << feature) & port_clear_feature_valid_mask))
|
---|
[8123695a] | 660 | return EINVAL;
|
---|
[8b74997f] | 661 | if (port < 1 || port > instance->port_count)
|
---|
[8123695a] | 662 | return EINVAL;
|
---|
[8b74997f] | 663 | if (feature == USB_HUB_FEATURE_PORT_POWER)
|
---|
[8123695a] | 664 | feature = USB_HUB_FEATURE_PORT_LOW_SPEED;
|
---|
[8b74997f] | 665 | if (feature == USB_HUB_FEATURE_PORT_SUSPEND)
|
---|
[8123695a] | 666 | feature = USB_HUB_FEATURE_PORT_OVER_CURRENT;
|
---|
| 667 | instance->registers->rh_port_status[port - 1] =
|
---|
[8b74997f] | 668 | (instance->registers->rh_port_status[port - 1]
|
---|
| 669 | & (~port_clear_feature_valid_mask))
|
---|
| 670 | | (1 << feature);
|
---|
[4d0c40b] | 671 | /// \TODO any error?
|
---|
| 672 | return EOK;
|
---|
[d8421c4] | 673 | }
|
---|
[8b74997f] | 674 | /*----------------------------------------------------------------------------*/
|
---|
[8123695a] | 675 |
|
---|
[f3da9b2] | 676 | /**
|
---|
| 677 | * register address to this device
|
---|
[8b74997f] | 678 | *
|
---|
[f3da9b2] | 679 | * @param instance root hub instance
|
---|
| 680 | * @param address new address
|
---|
| 681 | * @return error code
|
---|
| 682 | */
|
---|
[d8421c4] | 683 | static int process_address_set_request(rh_t *instance,
|
---|
[8b74997f] | 684 | uint16_t address) {
|
---|
[d8421c4] | 685 | instance->address = address;
|
---|
| 686 | return EOK;
|
---|
[4d0c40b] | 687 | }
|
---|
[8b74997f] | 688 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 689 |
|
---|
[f3da9b2] | 690 | /**
|
---|
| 691 | * process one of requests that requere output data
|
---|
| 692 | *
|
---|
| 693 | * Request can be one of USB_DEVREQ_GET_STATUS, USB_DEVREQ_GET_DESCRIPTOR or
|
---|
| 694 | * USB_DEVREQ_GET_CONFIGURATION.
|
---|
| 695 | * @param instance root hub instance
|
---|
| 696 | * @param request structure containing both request and response information
|
---|
| 697 | * @return error code
|
---|
| 698 | */
|
---|
[4d0c40b] | 699 | static int process_request_with_output(rh_t *instance,
|
---|
[8b74997f] | 700 | usb_transfer_batch_t *request) {
|
---|
[4d0c40b] | 701 | usb_device_request_setup_packet_t * setup_request =
|
---|
[8b74997f] | 702 | (usb_device_request_setup_packet_t*) request->setup_buffer;
|
---|
| 703 | if (setup_request->request == USB_DEVREQ_GET_STATUS) {
|
---|
[d8421c4] | 704 | usb_log_debug("USB_DEVREQ_GET_STATUS\n");
|
---|
| 705 | return process_get_status_request(instance, request);
|
---|
[4d0c40b] | 706 | }
|
---|
[8b74997f] | 707 | if (setup_request->request == USB_DEVREQ_GET_DESCRIPTOR) {
|
---|
[d8421c4] | 708 | usb_log_debug("USB_DEVREQ_GET_DESCRIPTOR\n");
|
---|
[4d0c40b] | 709 | return process_get_descriptor_request(instance, request);
|
---|
| 710 | }
|
---|
[8b74997f] | 711 | if (setup_request->request == USB_DEVREQ_GET_CONFIGURATION) {
|
---|
[d8421c4] | 712 | usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
|
---|
| 713 | return process_get_configuration_request(instance, request);
|
---|
[4d0c40b] | 714 | }
|
---|
| 715 | return ENOTSUP;
|
---|
| 716 | }
|
---|
[8b74997f] | 717 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 718 |
|
---|
[f3da9b2] | 719 | /**
|
---|
| 720 | * process one of requests that carry input data
|
---|
| 721 | *
|
---|
| 722 | * Request can be one of USB_DEVREQ_SET_DESCRIPTOR or
|
---|
| 723 | * USB_DEVREQ_SET_CONFIGURATION.
|
---|
| 724 | * @param instance root hub instance
|
---|
| 725 | * @param request structure containing both request and response information
|
---|
| 726 | * @return error code
|
---|
| 727 | */
|
---|
[4d0c40b] | 728 | static int process_request_with_input(rh_t *instance,
|
---|
[8b74997f] | 729 | usb_transfer_batch_t *request) {
|
---|
[4d0c40b] | 730 | usb_device_request_setup_packet_t * setup_request =
|
---|
[8b74997f] | 731 | (usb_device_request_setup_packet_t*) request->setup_buffer;
|
---|
[d8421c4] | 732 | request->transfered_size = 0;
|
---|
[8b74997f] | 733 | if (setup_request->request == USB_DEVREQ_SET_DESCRIPTOR) {
|
---|
[4d0c40b] | 734 | return ENOTSUP;
|
---|
| 735 | }
|
---|
[8b74997f] | 736 | if (setup_request->request == USB_DEVREQ_SET_CONFIGURATION) {
|
---|
[4d0c40b] | 737 | //set and get configuration requests do not have any meaning,
|
---|
| 738 | //only dummy values are returned
|
---|
| 739 | return EOK;
|
---|
| 740 | }
|
---|
| 741 | return ENOTSUP;
|
---|
| 742 | }
|
---|
[8b74997f] | 743 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 744 |
|
---|
[f3da9b2] | 745 | /**
|
---|
| 746 | * process one of requests that do not request nor carry additional data
|
---|
| 747 | *
|
---|
| 748 | * Request can be one of USB_DEVREQ_CLEAR_FEATURE, USB_DEVREQ_SET_FEATURE or
|
---|
| 749 | * USB_DEVREQ_SET_ADDRESS.
|
---|
| 750 | * @param instance root hub instance
|
---|
| 751 | * @param request structure containing both request and response information
|
---|
| 752 | * @return error code
|
---|
| 753 | */
|
---|
[4d0c40b] | 754 | static int process_request_without_data(rh_t *instance,
|
---|
[8b74997f] | 755 | usb_transfer_batch_t *request) {
|
---|
[4d0c40b] | 756 | usb_device_request_setup_packet_t * setup_request =
|
---|
[8b74997f] | 757 | (usb_device_request_setup_packet_t*) request->setup_buffer;
|
---|
[d8421c4] | 758 | request->transfered_size = 0;
|
---|
[8b74997f] | 759 | if (setup_request->request == USB_DEVREQ_CLEAR_FEATURE) {
|
---|
| 760 | if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE) {
|
---|
[d8421c4] | 761 | usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
|
---|
[8123695a] | 762 | return process_hub_feature_clear_request(instance,
|
---|
[8b74997f] | 763 | setup_request->value);
|
---|
[d8421c4] | 764 | }
|
---|
[8b74997f] | 765 | if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
|
---|
[d8421c4] | 766 | usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
|
---|
[8123695a] | 767 | return process_port_feature_clear_request(instance,
|
---|
[8b74997f] | 768 | setup_request->value,
|
---|
| 769 | setup_request->index);
|
---|
[8123695a] | 770 | }
|
---|
| 771 | usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
|
---|
[8b74997f] | 772 | setup_request->request_type);
|
---|
[8123695a] | 773 | return EINVAL;
|
---|
| 774 | }
|
---|
[8b74997f] | 775 | if (setup_request->request == USB_DEVREQ_SET_FEATURE) {
|
---|
| 776 | if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE) {
|
---|
[8123695a] | 777 | usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
|
---|
| 778 | return process_hub_feature_set_request(instance,
|
---|
[8b74997f] | 779 | setup_request->value);
|
---|
[8123695a] | 780 | }
|
---|
[8b74997f] | 781 | if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
|
---|
[8123695a] | 782 | usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
|
---|
| 783 | return process_port_feature_set_request(instance,
|
---|
[8b74997f] | 784 | setup_request->value,
|
---|
| 785 | setup_request->index);
|
---|
[d8421c4] | 786 | }
|
---|
[8b74997f] | 787 | usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
|
---|
| 788 | setup_request->request_type);
|
---|
[d8421c4] | 789 | return EINVAL;
|
---|
[4d0c40b] | 790 | }
|
---|
[8b74997f] | 791 | if (setup_request->request == USB_DEVREQ_SET_ADDRESS) {
|
---|
[d8421c4] | 792 | usb_log_debug("USB_DEVREQ_SET_ADDRESS\n");
|
---|
[8b74997f] | 793 | return process_address_set_request(instance,
|
---|
| 794 | setup_request->value);
|
---|
[4d0c40b] | 795 | }
|
---|
[8b74997f] | 796 | usb_log_debug("USB_DEVREQ_SET_ENOTSUP %d\n",
|
---|
| 797 | setup_request->request_type);
|
---|
[4d0c40b] | 798 | return ENOTSUP;
|
---|
| 799 | }
|
---|
[8b74997f] | 800 | /*----------------------------------------------------------------------------*/
|
---|
[4d0c40b] | 801 |
|
---|
[f3da9b2] | 802 | /**
|
---|
| 803 | * process hub control request
|
---|
| 804 | *
|
---|
| 805 | * If needed, writes answer into the request structure.
|
---|
| 806 | * Request can be one of
|
---|
| 807 | * USB_DEVREQ_GET_STATUS,
|
---|
| 808 | * USB_DEVREQ_GET_DESCRIPTOR,
|
---|
| 809 | * USB_DEVREQ_GET_CONFIGURATION,
|
---|
| 810 | * USB_DEVREQ_CLEAR_FEATURE,
|
---|
| 811 | * USB_DEVREQ_SET_FEATURE,
|
---|
| 812 | * USB_DEVREQ_SET_ADDRESS,
|
---|
| 813 | * USB_DEVREQ_SET_DESCRIPTOR or
|
---|
| 814 | * USB_DEVREQ_SET_CONFIGURATION.
|
---|
| 815 | *
|
---|
| 816 | * @param instance root hub instance
|
---|
| 817 | * @param request structure containing both request and response information
|
---|
| 818 | * @return error code
|
---|
| 819 | */
|
---|
[8b74997f] | 820 | static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request) {
|
---|
| 821 | if (!request->setup_buffer) {
|
---|
| 822 | usb_log_error("root hub received empty transaction?");
|
---|
| 823 | return EINVAL;
|
---|
| 824 | }
|
---|
[f3da9b2] | 825 | int opResult;
|
---|
[8b74997f] | 826 | if (sizeof (usb_device_request_setup_packet_t) > request->setup_size) {
|
---|
| 827 | usb_log_error("setup packet too small\n");
|
---|
| 828 | return EINVAL;
|
---|
| 829 | }
|
---|
| 830 | usb_log_info("CTRL packet: %s.\n",
|
---|
| 831 | usb_debug_str_buffer(
|
---|
| 832 | (const uint8_t *) request->setup_buffer, 8, 8));
|
---|
| 833 | usb_device_request_setup_packet_t * setup_request =
|
---|
| 834 | (usb_device_request_setup_packet_t*)
|
---|
| 835 | request->setup_buffer;
|
---|
| 836 | switch (setup_request->request) {
|
---|
| 837 | case USB_DEVREQ_GET_STATUS:
|
---|
| 838 | case USB_DEVREQ_GET_DESCRIPTOR:
|
---|
| 839 | case USB_DEVREQ_GET_CONFIGURATION:
|
---|
[f3da9b2] | 840 | usb_log_debug("processing request with output\n");
|
---|
[8b74997f] | 841 | opResult = process_request_with_output(
|
---|
| 842 | instance, request);
|
---|
| 843 | break;
|
---|
| 844 | case USB_DEVREQ_CLEAR_FEATURE:
|
---|
| 845 | case USB_DEVREQ_SET_FEATURE:
|
---|
| 846 | case USB_DEVREQ_SET_ADDRESS:
|
---|
| 847 | usb_log_debug("processing request without "
|
---|
| 848 | "additional data\n");
|
---|
| 849 | opResult = process_request_without_data(
|
---|
| 850 | instance, request);
|
---|
| 851 | break;
|
---|
| 852 | case USB_DEVREQ_SET_DESCRIPTOR:
|
---|
| 853 | case USB_DEVREQ_SET_CONFIGURATION:
|
---|
| 854 | usb_log_debug("processing request with "
|
---|
| 855 | "input\n");
|
---|
| 856 | opResult = process_request_with_input(
|
---|
| 857 | instance, request);
|
---|
| 858 | break;
|
---|
| 859 | default:
|
---|
| 860 | usb_log_warning("received unsuported request: "
|
---|
| 861 | "%d\n",
|
---|
| 862 | setup_request->request
|
---|
| 863 | );
|
---|
[f3da9b2] | 864 | opResult = ENOTSUP;
|
---|
| 865 | }
|
---|
| 866 | return opResult;
|
---|
| 867 | }
|
---|
[4d0c40b] | 868 |
|
---|
[41b96b4] | 869 | /**
|
---|
| 870 | * @}
|
---|
| 871 | */
|
---|