[b5ec347] | 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 |
|
---|
[281ebae] | 29 | /** @addtogroup drvusbhub
|
---|
[b5ec347] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[f40a1e2] | 33 | * @brief Hub driver private definitions
|
---|
[b5ec347] | 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef USBHUB_PRIVATE_H
|
---|
| 37 | #define USBHUB_PRIVATE_H
|
---|
| 38 |
|
---|
| 39 | #include "usbhub.h"
|
---|
[e080332] | 40 |
|
---|
[b5ec347] | 41 | #include <adt/list.h>
|
---|
| 42 | #include <bool.h>
|
---|
[eb1a2f4] | 43 | #include <ddf/driver.h>
|
---|
[ba5ab09] | 44 | #include <fibril_synch.h>
|
---|
[5097bed4] | 45 |
|
---|
[6bb83c7] | 46 | #include <usb/classes/hub.h>
|
---|
[b5ec347] | 47 | #include <usb/usb.h>
|
---|
[e080332] | 48 | #include <usb/debug.h>
|
---|
[7d521e24] | 49 | #include <usb/dev/request.h>
|
---|
[b5ec347] | 50 |
|
---|
| 51 | //************
|
---|
| 52 | //
|
---|
| 53 | // convenience define for malloc
|
---|
| 54 | //
|
---|
| 55 | //************
|
---|
| 56 |
|
---|
| 57 |
|
---|
[eb1a2f4] | 58 | usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device);
|
---|
[b5ec347] | 59 |
|
---|
[98d06b8] | 60 | /**
|
---|
[f40a1e2] | 61 | * Set the device request to be a get hub descriptor request.
|
---|
[98d06b8] | 62 | * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
|
---|
| 63 | * @param request
|
---|
| 64 | * @param addr
|
---|
| 65 | */
|
---|
[10096231] | 66 | static inline void usb_hub_set_descriptor_request(
|
---|
[6ab7f3e9] | 67 | usb_device_request_setup_packet_t * request
|
---|
| 68 | ) {
|
---|
[98d06b8] | 69 | request->index = 0;
|
---|
| 70 | request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
|
---|
| 71 | request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
|
---|
[10096231] | 72 | request->value_high = USB_DESCTYPE_HUB;
|
---|
| 73 | request->value_low = 0;
|
---|
[98d06b8] | 74 | request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[f40a1e2] | 77 | /**
|
---|
| 78 | * Clear feature on hub port.
|
---|
| 79 | *
|
---|
| 80 | * @param hc Host controller telephone
|
---|
| 81 | * @param address Hub address
|
---|
| 82 | * @param port_index Port
|
---|
| 83 | * @param feature Feature selector
|
---|
| 84 | * @return Operation result
|
---|
| 85 | */
|
---|
[a372663] | 86 | static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe,
|
---|
[f9a0cef] | 87 | int port_index,
|
---|
| 88 | usb_hub_class_feature_t feature) {
|
---|
[6ab7f3e9] | 89 |
|
---|
[f9a0cef] | 90 | usb_device_request_setup_packet_t clear_request = {
|
---|
| 91 | .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
|
---|
| 92 | .request = USB_DEVREQ_CLEAR_FEATURE,
|
---|
| 93 | .length = 0,
|
---|
| 94 | .index = port_index
|
---|
| 95 | };
|
---|
| 96 | clear_request.value = feature;
|
---|
[3954a63b] | 97 | return usb_pipe_control_write(pipe, &clear_request,
|
---|
[6ab7f3e9] | 98 | sizeof (clear_request), NULL, 0);
|
---|
[f9a0cef] | 99 | }
|
---|
| 100 |
|
---|
[040ab02] | 101 | /**
|
---|
| 102 | * Clear feature on hub port.
|
---|
| 103 | *
|
---|
| 104 | * @param hc Host controller telephone
|
---|
| 105 | * @param address Hub address
|
---|
| 106 | * @param port_index Port
|
---|
| 107 | * @param feature Feature selector
|
---|
| 108 | * @return Operation result
|
---|
| 109 | */
|
---|
| 110 | static inline int usb_hub_set_port_feature(usb_pipe_t *pipe,
|
---|
| 111 | int port_index,
|
---|
| 112 | usb_hub_class_feature_t feature) {
|
---|
| 113 |
|
---|
| 114 | usb_device_request_setup_packet_t clear_request = {
|
---|
[c1693dae] | 115 | .request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE,
|
---|
[040ab02] | 116 | .request = USB_DEVREQ_SET_FEATURE,
|
---|
| 117 | .length = 0,
|
---|
| 118 | .index = port_index
|
---|
| 119 | };
|
---|
| 120 | clear_request.value = feature;
|
---|
| 121 | return usb_pipe_control_write(pipe, &clear_request,
|
---|
[6ab7f3e9] | 122 | sizeof (clear_request), NULL, 0);
|
---|
[040ab02] | 123 | }
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * Clear feature on hub port.
|
---|
| 127 | *
|
---|
| 128 | * @param pipe pipe to hub control endpoint
|
---|
| 129 | * @param feature Feature selector
|
---|
| 130 | * @return Operation result
|
---|
| 131 | */
|
---|
| 132 | static inline int usb_hub_clear_feature(usb_pipe_t *pipe,
|
---|
| 133 | usb_hub_class_feature_t feature) {
|
---|
| 134 |
|
---|
| 135 | usb_device_request_setup_packet_t clear_request = {
|
---|
| 136 | .request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
|
---|
| 137 | .request = USB_DEVREQ_CLEAR_FEATURE,
|
---|
| 138 | .length = 0,
|
---|
| 139 | .index = 0
|
---|
| 140 | };
|
---|
| 141 | clear_request.value = feature;
|
---|
| 142 | return usb_pipe_control_write(pipe, &clear_request,
|
---|
[6ab7f3e9] | 143 | sizeof (clear_request), NULL, 0);
|
---|
[040ab02] | 144 | }
|
---|
| 145 |
|
---|
| 146 | /**
|
---|
| 147 | * Clear feature on hub port.
|
---|
| 148 | *
|
---|
| 149 | * @param pipe pipe to hub control endpoint
|
---|
| 150 | * @param feature Feature selector
|
---|
| 151 | * @return Operation result
|
---|
| 152 | */
|
---|
| 153 | static inline int usb_hub_set_feature(usb_pipe_t *pipe,
|
---|
| 154 | usb_hub_class_feature_t feature) {
|
---|
| 155 |
|
---|
| 156 | usb_device_request_setup_packet_t clear_request = {
|
---|
| 157 | .request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
|
---|
| 158 | .request = USB_DEVREQ_SET_FEATURE,
|
---|
| 159 | .length = 0,
|
---|
| 160 | .index = 0
|
---|
| 161 | };
|
---|
| 162 | clear_request.value = feature;
|
---|
| 163 | return usb_pipe_control_write(pipe, &clear_request,
|
---|
[6ab7f3e9] | 164 | sizeof (clear_request), NULL, 0);
|
---|
[040ab02] | 165 | }
|
---|
| 166 |
|
---|
[d493ac17] | 167 |
|
---|
[cd5b878] | 168 | void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t * descriptor);
|
---|
| 169 |
|
---|
| 170 | void usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor,
|
---|
| 171 | void * serialized_descriptor);
|
---|
| 172 |
|
---|
[5fd0dc23] | 173 | int usb_deserialize_hub_desriptor(
|
---|
| 174 | void *serialized_descriptor, size_t size, usb_hub_descriptor_t *descriptor);
|
---|
[98d06b8] | 175 |
|
---|
[b5ec347] | 176 |
|
---|
| 177 | #endif /* USBHUB_PRIVATE_H */
|
---|
| 178 |
|
---|
| 179 | /**
|
---|
| 180 | * @}
|
---|
| 181 | */
|
---|