[0a37e14] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 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 |
|
---|
[160b75e] | 29 | /** @addtogroup libusbdev
|
---|
[0a37e14] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * Standard USB requests.
|
---|
| 34 | */
|
---|
[7d521e24] | 35 | #ifndef LIBUSBDEV_REQUEST_H_
|
---|
| 36 | #define LIBUSBDEV_REQUEST_H_
|
---|
[0a37e14] | 37 |
|
---|
| 38 | #include <sys/types.h>
|
---|
[1a6a234] | 39 | #include <l18n/langs.h>
|
---|
[0a37e14] | 40 | #include <usb/usb.h>
|
---|
[7d521e24] | 41 | #include <usb/dev/pipes.h>
|
---|
[abe8ac5] | 42 | #include <usb/descriptor.h>
|
---|
[0a37e14] | 43 |
|
---|
[915a851] | 44 | /** USB device status - device is self powered (opposed to bus powered). */
|
---|
| 45 | #define USB_DEVICE_STATUS_SELF_POWERED ((uint16_t)(1 << 0))
|
---|
| 46 |
|
---|
| 47 | /** USB device status - remote wake-up signaling is enabled. */
|
---|
| 48 | #define USB_DEVICE_STATUS_REMOTE_WAKEUP ((uint16_t)(1 << 1))
|
---|
| 49 |
|
---|
| 50 | /** USB endpoint status - endpoint is halted (stalled). */
|
---|
| 51 | #define USB_ENDPOINT_STATUS_HALTED ((uint16_t)(1 << 0))
|
---|
| 52 |
|
---|
[c19329a] | 53 | /** USB feature selector - endpoint halt (stall). */
|
---|
| 54 | #define USB_FEATURE_SELECTOR_ENDPOINT_HALT (0)
|
---|
| 55 |
|
---|
| 56 | /** USB feature selector - device remote wake-up. */
|
---|
| 57 | #define USB_FEATURE_SELECTOR_REMOTE_WAKEUP (1)
|
---|
| 58 |
|
---|
[0f21c0c] | 59 | /** Standard device request. */
|
---|
| 60 | typedef enum {
|
---|
| 61 | USB_DEVREQ_GET_STATUS = 0,
|
---|
| 62 | USB_DEVREQ_CLEAR_FEATURE = 1,
|
---|
| 63 | USB_DEVREQ_SET_FEATURE = 3,
|
---|
| 64 | USB_DEVREQ_SET_ADDRESS = 5,
|
---|
| 65 | USB_DEVREQ_GET_DESCRIPTOR = 6,
|
---|
| 66 | USB_DEVREQ_SET_DESCRIPTOR = 7,
|
---|
| 67 | USB_DEVREQ_GET_CONFIGURATION = 8,
|
---|
| 68 | USB_DEVREQ_SET_CONFIGURATION = 9,
|
---|
| 69 | USB_DEVREQ_GET_INTERFACE = 10,
|
---|
| 70 | USB_DEVREQ_SET_INTERFACE = 11,
|
---|
| 71 | USB_DEVREQ_SYNCH_FRAME = 12,
|
---|
| 72 | USB_DEVREQ_LAST_STD
|
---|
| 73 | } usb_stddevreq_t;
|
---|
| 74 |
|
---|
| 75 | /** Device request setup packet.
|
---|
| 76 | * The setup packet describes the request.
|
---|
| 77 | */
|
---|
| 78 | typedef struct {
|
---|
| 79 | /** Request type.
|
---|
| 80 | * The type combines transfer direction, request type and
|
---|
| 81 | * intended recipient.
|
---|
| 82 | */
|
---|
| 83 | uint8_t request_type;
|
---|
[095bddfc] | 84 | #define SETUP_REQUEST_TYPE_DEVICE_TO_HOST (1 << 7)
|
---|
[2f80b86] | 85 | #define SETUP_REQUEST_TYPE_GET_TYPE(rt) ((rt >> 5) & 0x3)
|
---|
[b6bade0] | 86 | #define SETUP_REQUEST_TYPE_GET_RECIPIENT(rec) (rec & 0x1f)
|
---|
| 87 | #define SETUP_REQUEST_TO_HOST(type, recipient) \
|
---|
| 88 | (uint8_t)((1 << 7) | ((type & 0x3) << 5) | (recipient & 0x1f))
|
---|
| 89 | #define SETUP_REQUEST_TO_DEVICE(type, recipient) \
|
---|
| 90 | (uint8_t)(((type & 0x3) << 5) | (recipient & 0x1f))
|
---|
[095bddfc] | 91 |
|
---|
[0f21c0c] | 92 | /** Request identification. */
|
---|
| 93 | uint8_t request;
|
---|
| 94 | /** Main parameter to the request. */
|
---|
[d69c698] | 95 | union __attribute__ ((packed)) {
|
---|
[0f21c0c] | 96 | uint16_t value;
|
---|
[a6add7a] | 97 | /* FIXME: add #ifdefs according to host endianness */
|
---|
[d69c698] | 98 | struct __attribute__ ((packed)) {
|
---|
[0f21c0c] | 99 | uint8_t value_low;
|
---|
| 100 | uint8_t value_high;
|
---|
| 101 | };
|
---|
| 102 | };
|
---|
| 103 | /** Auxiliary parameter to the request.
|
---|
| 104 | * Typically, it is offset to something.
|
---|
| 105 | */
|
---|
| 106 | uint16_t index;
|
---|
| 107 | /** Length of extra data. */
|
---|
| 108 | uint16_t length;
|
---|
| 109 | } __attribute__ ((packed)) usb_device_request_setup_packet_t;
|
---|
| 110 |
|
---|
[d69c698] | 111 | int assert[(sizeof(usb_device_request_setup_packet_t) == 8) ? 1: -1];
|
---|
| 112 |
|
---|
[a372663] | 113 | int usb_control_request_set(usb_pipe_t *,
|
---|
[a4a8cca] | 114 | usb_request_type_t, usb_request_recipient_t, uint8_t,
|
---|
| 115 | uint16_t, uint16_t, void *, size_t);
|
---|
| 116 |
|
---|
[a372663] | 117 | int usb_control_request_get(usb_pipe_t *,
|
---|
[a4a8cca] | 118 | usb_request_type_t, usb_request_recipient_t, uint8_t,
|
---|
| 119 | uint16_t, uint16_t, void *, size_t, size_t *);
|
---|
| 120 |
|
---|
[a372663] | 121 | int usb_request_get_status(usb_pipe_t *, usb_request_recipient_t,
|
---|
[9cf1c5a] | 122 | uint16_t, uint16_t *);
|
---|
[a372663] | 123 | int usb_request_clear_feature(usb_pipe_t *, usb_request_type_t,
|
---|
[9cf1c5a] | 124 | usb_request_recipient_t, uint16_t, uint16_t);
|
---|
[a372663] | 125 | int usb_request_set_feature(usb_pipe_t *, usb_request_type_t,
|
---|
[9cf1c5a] | 126 | usb_request_recipient_t, uint16_t, uint16_t);
|
---|
[a372663] | 127 | int usb_request_get_descriptor(usb_pipe_t *, usb_request_type_t,
|
---|
[3238506] | 128 | usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t,
|
---|
[ad4562c2] | 129 | size_t *);
|
---|
[a372663] | 130 | int usb_request_get_descriptor_alloc(usb_pipe_t *, usb_request_type_t,
|
---|
[ad4562c2] | 131 | usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void **, size_t *);
|
---|
[a372663] | 132 | int usb_request_get_device_descriptor(usb_pipe_t *,
|
---|
[abe8ac5] | 133 | usb_standard_device_descriptor_t *);
|
---|
[a372663] | 134 | int usb_request_get_bare_configuration_descriptor(usb_pipe_t *, int,
|
---|
[abe8ac5] | 135 | usb_standard_configuration_descriptor_t *);
|
---|
[a372663] | 136 | int usb_request_get_full_configuration_descriptor(usb_pipe_t *, int,
|
---|
[abe8ac5] | 137 | void *, size_t, size_t *);
|
---|
[a372663] | 138 | int usb_request_get_full_configuration_descriptor_alloc(usb_pipe_t *,
|
---|
[4723444] | 139 | int, void **, size_t *);
|
---|
[a372663] | 140 | int usb_request_set_descriptor(usb_pipe_t *, usb_request_type_t,
|
---|
[9cf1c5a] | 141 | usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t);
|
---|
[99a1a56] | 142 |
|
---|
[a372663] | 143 | int usb_request_get_configuration(usb_pipe_t *, uint8_t *);
|
---|
| 144 | int usb_request_set_configuration(usb_pipe_t *, uint8_t);
|
---|
| 145 | int usb_request_get_interface(usb_pipe_t *, uint8_t, uint8_t *);
|
---|
| 146 | int usb_request_set_interface(usb_pipe_t *, uint8_t, uint8_t);
|
---|
[0a37e14] | 147 |
|
---|
[a372663] | 148 | int usb_request_get_supported_languages(usb_pipe_t *,
|
---|
[1a6a234] | 149 | l18_win_locales_t **, size_t *);
|
---|
[a372663] | 150 | int usb_request_get_string(usb_pipe_t *, size_t, l18_win_locales_t,
|
---|
[b84e114] | 151 | char **);
|
---|
[1a6a234] | 152 |
|
---|
[c19329a] | 153 | int usb_request_clear_endpoint_halt(usb_pipe_t *, uint16_t);
|
---|
[19387b61] | 154 | int usb_pipe_clear_halt(usb_pipe_t *, usb_pipe_t *);
|
---|
| 155 | int usb_request_get_endpoint_status(usb_pipe_t *, usb_pipe_t *, uint16_t *);
|
---|
[c19329a] | 156 |
|
---|
[0a37e14] | 157 | #endif
|
---|
| 158 | /**
|
---|
| 159 | * @}
|
---|
| 160 | */
|
---|