[2193471] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
---|
| 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 usb
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief Standard USB descriptors.
|
---|
| 34 | */
|
---|
| 35 | #ifndef LIBUSB_DESCRIPTOR_H_
|
---|
| 36 | #define LIBUSB_DESCRIPTOR_H_
|
---|
| 37 |
|
---|
| 38 | #include <ipc/ipc.h>
|
---|
| 39 | #include <async.h>
|
---|
| 40 |
|
---|
| 41 | /** Descriptor type. */
|
---|
| 42 | typedef enum {
|
---|
| 43 | USB_DESCTYPE_DEVICE = 1,
|
---|
| 44 | USB_DESCTYPE_CONFIGURATION = 2,
|
---|
| 45 | USB_DESCTYPE_STRING = 3,
|
---|
| 46 | USB_DESCTYPE_INTERFACE = 4,
|
---|
[73301a0] | 47 | USB_DESCTYPE_ENDPOINT = 5,
|
---|
| 48 | USB_DESCTYPE_HID = 0x21,
|
---|
| 49 | USB_DESCTYPE_HID_REPORT = 0x22,
|
---|
| 50 | USB_DESCTYPE_HID_PHYSICAL = 0x23,
|
---|
[bbfb86c] | 51 | USB_DESCTYPE_HUB = 0x29,
|
---|
[73301a0] | 52 | /* USB_DESCTYPE_ = */
|
---|
[2193471] | 53 | } usb_descriptor_type_t;
|
---|
| 54 |
|
---|
| 55 | /** Standard USB device descriptor.
|
---|
| 56 | */
|
---|
| 57 | typedef struct {
|
---|
| 58 | /** Size of this descriptor in bytes. */
|
---|
| 59 | uint8_t length;
|
---|
| 60 | /** Descriptor type (USB_DESCTYPE_DEVICE). */
|
---|
| 61 | uint8_t descriptor_type;
|
---|
| 62 | /** USB specification release number.
|
---|
| 63 | * The number shall be coded as binary-coded decimal (BCD).
|
---|
| 64 | */
|
---|
| 65 | uint16_t usb_spec_version;
|
---|
| 66 | /** Device class. */
|
---|
| 67 | uint8_t device_class;
|
---|
| 68 | /** Device sub-class. */
|
---|
| 69 | uint8_t device_subclass;
|
---|
| 70 | /** Device protocol. */
|
---|
| 71 | uint8_t device_protocol;
|
---|
| 72 | /** Maximum packet size for endpoint zero.
|
---|
| 73 | * Valid values are only 8, 16, 32, 64).
|
---|
| 74 | */
|
---|
| 75 | uint8_t max_packet_size;
|
---|
| 76 | /** Vendor ID. */
|
---|
| 77 | uint16_t vendor_id;
|
---|
| 78 | /** Product ID. */
|
---|
| 79 | uint16_t product_id;
|
---|
| 80 | /** Device release number (in BCD). */
|
---|
| 81 | uint16_t device_version;
|
---|
| 82 | /** Manufacturer descriptor index. */
|
---|
| 83 | uint8_t str_manufacturer;
|
---|
| 84 | /** Product descriptor index. */
|
---|
| 85 | uint8_t str_product;
|
---|
| 86 | /** Device serial number desriptor index. */
|
---|
| 87 | uint8_t str_serial_number;
|
---|
| 88 | /** Number of possible configurations. */
|
---|
| 89 | uint8_t configuration_count;
|
---|
| 90 | } __attribute__ ((packed)) usb_standard_device_descriptor_t;
|
---|
| 91 |
|
---|
| 92 | /** Standard USB configuration descriptor.
|
---|
| 93 | */
|
---|
| 94 | typedef struct {
|
---|
| 95 | /** Size of this descriptor in bytes. */
|
---|
| 96 | uint8_t length;
|
---|
| 97 | /** Descriptor type (USB_DESCTYPE_CONFIGURATION). */
|
---|
| 98 | uint8_t descriptor_type;
|
---|
| 99 | /** Total length of all data of this configuration.
|
---|
| 100 | * This includes the combined length of all descriptors
|
---|
| 101 | * (configuration, interface, endpoint, class-specific and
|
---|
| 102 | * vendor-specific) valid for this configuration.
|
---|
| 103 | */
|
---|
| 104 | uint16_t total_length;
|
---|
| 105 | /** Number of possible interfaces under this configuration. */
|
---|
| 106 | uint8_t interface_count;
|
---|
| 107 | /** Configuration value used when setting this configuration. */
|
---|
| 108 | uint8_t configuration_number;
|
---|
| 109 | /** String descriptor describing this configuration. */
|
---|
| 110 | uint8_t str_configuration;
|
---|
| 111 | /** Attribute bitmap. */
|
---|
| 112 | uint8_t attributes;
|
---|
| 113 | /** Maximum power consumption from the USB under this configuration.
|
---|
| 114 | * Expressed in 2mA unit (e.g. 50 ~ 100mA).
|
---|
| 115 | */
|
---|
| 116 | uint8_t max_power;
|
---|
| 117 | } __attribute__ ((packed)) usb_standard_configuration_descriptor_t;
|
---|
| 118 |
|
---|
| 119 | /** Standard USB interface descriptor.
|
---|
| 120 | */
|
---|
| 121 | typedef struct {
|
---|
| 122 | /** Size of this descriptor in bytes. */
|
---|
| 123 | uint8_t length;
|
---|
| 124 | /** Descriptor type (USB_DESCTYPE_INTERFACE). */
|
---|
| 125 | uint8_t descriptor_type;
|
---|
| 126 | /** Number of interface.
|
---|
| 127 | * Zero-based index into array of interfaces for current configuration.
|
---|
| 128 | */
|
---|
| 129 | uint8_t interface_number;
|
---|
| 130 | /** Alternate setting for value in interface_number. */
|
---|
| 131 | uint8_t alternate_setting;
|
---|
| 132 | /** Number of endpoints used by this interface.
|
---|
| 133 | * This number must exclude usage of endpoint zero
|
---|
| 134 | * (default control pipe).
|
---|
| 135 | */
|
---|
| 136 | uint8_t endpoint_count;
|
---|
| 137 | /** Class code. */
|
---|
| 138 | uint8_t interface_class;
|
---|
| 139 | /** Subclass code. */
|
---|
| 140 | uint8_t interface_subclass;
|
---|
| 141 | /** Protocol code. */
|
---|
| 142 | uint8_t interface_protocol;
|
---|
| 143 | /** String descriptor describing this interface. */
|
---|
| 144 | uint8_t str_interface;
|
---|
| 145 | } __attribute__ ((packed)) usb_standard_interface_descriptor_t;
|
---|
| 146 |
|
---|
| 147 | /** Standard USB endpoint descriptor.
|
---|
| 148 | */
|
---|
| 149 | typedef struct {
|
---|
| 150 | /** Size of this descriptor in bytes. */
|
---|
| 151 | uint8_t length;
|
---|
| 152 | /** Descriptor type (USB_DESCTYPE_ENDPOINT). */
|
---|
| 153 | uint8_t descriptor_type;
|
---|
| 154 | /** Endpoint address together with data flow direction. */
|
---|
| 155 | uint8_t endpoint_address;
|
---|
| 156 | /** Endpoint attributes.
|
---|
| 157 | * Includes transfer type (usb_transfer_type_t).
|
---|
| 158 | */
|
---|
| 159 | uint8_t attributes;
|
---|
| 160 | /** Maximum packet size. */
|
---|
| 161 | uint16_t max_packet_size;
|
---|
| 162 | /** Polling interval in milliseconds.
|
---|
| 163 | * Ignored for bulk and control endpoints.
|
---|
| 164 | * Isochronous endpoints must use value 1.
|
---|
| 165 | * Interrupt endpoints any value from 1 to 255.
|
---|
| 166 | */
|
---|
| 167 | uint8_t poll_interval;
|
---|
| 168 | } __attribute__ ((packed)) usb_standard_endpoint_descriptor_t;
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 | /* TODO: string descriptors. */
|
---|
| 172 |
|
---|
| 173 | #endif
|
---|
| 174 | /**
|
---|
| 175 | * @}
|
---|
| 176 | */
|
---|