| 1 | /*
|
|---|
| 2 | * Copyright (c) 2012 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 |
|
|---|
| 29 | /** @addtogroup libusb
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * Standard USB request format.
|
|---|
| 34 | */
|
|---|
| 35 | #ifndef LIBUSB_REQUEST_H_
|
|---|
| 36 | #define LIBUSB_REQUEST_H_
|
|---|
| 37 |
|
|---|
| 38 | #include <sys/types.h>
|
|---|
| 39 |
|
|---|
| 40 | /** Standard device request. */
|
|---|
| 41 | typedef enum {
|
|---|
| 42 | USB_DEVREQ_GET_STATUS = 0,
|
|---|
| 43 | USB_DEVREQ_CLEAR_FEATURE = 1,
|
|---|
| 44 | USB_DEVREQ_SET_FEATURE = 3,
|
|---|
| 45 | USB_DEVREQ_SET_ADDRESS = 5,
|
|---|
| 46 | USB_DEVREQ_GET_DESCRIPTOR = 6,
|
|---|
| 47 | USB_DEVREQ_SET_DESCRIPTOR = 7,
|
|---|
| 48 | USB_DEVREQ_GET_CONFIGURATION = 8,
|
|---|
| 49 | USB_DEVREQ_SET_CONFIGURATION = 9,
|
|---|
| 50 | USB_DEVREQ_GET_INTERFACE = 10,
|
|---|
| 51 | USB_DEVREQ_SET_INTERFACE = 11,
|
|---|
| 52 | USB_DEVREQ_SYNCH_FRAME = 12,
|
|---|
| 53 | USB_DEVREQ_LAST_STD
|
|---|
| 54 | } usb_stddevreq_t;
|
|---|
| 55 |
|
|---|
| 56 | /** USB device status - device is self powered (opposed to bus powered). */
|
|---|
| 57 | #define USB_DEVICE_STATUS_SELF_POWERED ((uint16_t)(1 << 0))
|
|---|
| 58 |
|
|---|
| 59 | /** USB device status - remote wake-up signaling is enabled. */
|
|---|
| 60 | #define USB_DEVICE_STATUS_REMOTE_WAKEUP ((uint16_t)(1 << 1))
|
|---|
| 61 |
|
|---|
| 62 | /** USB endpoint status - endpoint is halted (stalled). */
|
|---|
| 63 | #define USB_ENDPOINT_STATUS_HALTED ((uint16_t)(1 << 0))
|
|---|
| 64 |
|
|---|
| 65 | /** USB feature selector - endpoint halt (stall). */
|
|---|
| 66 | #define USB_FEATURE_SELECTOR_ENDPOINT_HALT (0)
|
|---|
| 67 |
|
|---|
| 68 | /** USB feature selector - device remote wake-up. */
|
|---|
| 69 | #define USB_FEATURE_SELECTOR_REMOTE_WAKEUP (1)
|
|---|
| 70 |
|
|---|
| 71 | /** Device request setup packet.
|
|---|
| 72 | * The setup packet describes the request.
|
|---|
| 73 | */
|
|---|
| 74 | typedef struct {
|
|---|
| 75 | /** Request type.
|
|---|
| 76 | * The type combines transfer direction, request type and
|
|---|
| 77 | * intended recipient.
|
|---|
| 78 | */
|
|---|
| 79 | uint8_t request_type;
|
|---|
| 80 | #define SETUP_REQUEST_TYPE_DEVICE_TO_HOST (1 << 7)
|
|---|
| 81 | #define SETUP_REQUEST_TYPE_GET_TYPE(rt) ((rt >> 5) & 0x3)
|
|---|
| 82 | #define SETUP_REQUEST_TYPE_GET_RECIPIENT(rec) (rec & 0x1f)
|
|---|
| 83 | #define SETUP_REQUEST_TO_HOST(type, recipient) \
|
|---|
| 84 | (uint8_t)((1 << 7) | ((type & 0x3) << 5) | (recipient & 0x1f))
|
|---|
| 85 | #define SETUP_REQUEST_TO_DEVICE(type, recipient) \
|
|---|
| 86 | (uint8_t)(((type & 0x3) << 5) | (recipient & 0x1f))
|
|---|
| 87 |
|
|---|
| 88 | /** Request identification. */
|
|---|
| 89 | uint8_t request;
|
|---|
| 90 | /** Main parameter to the request. */
|
|---|
| 91 | union __attribute__ ((packed)) {
|
|---|
| 92 | uint16_t value;
|
|---|
| 93 | /* FIXME: add #ifdefs according to host endianness */
|
|---|
| 94 | struct __attribute__ ((packed)) {
|
|---|
| 95 | uint8_t value_low;
|
|---|
| 96 | uint8_t value_high;
|
|---|
| 97 | };
|
|---|
| 98 | };
|
|---|
| 99 | /** Auxiliary parameter to the request.
|
|---|
| 100 | * Typically, it is offset to something.
|
|---|
| 101 | */
|
|---|
| 102 | uint16_t index;
|
|---|
| 103 | /** Length of extra data. */
|
|---|
| 104 | uint16_t length;
|
|---|
| 105 | } __attribute__ ((packed)) usb_device_request_setup_packet_t;
|
|---|
| 106 |
|
|---|
| 107 | int assert[(sizeof(usb_device_request_setup_packet_t) == 8) ? 1: -1];
|
|---|
| 108 |
|
|---|
| 109 | int usb_request_needs_toggle_reset(
|
|---|
| 110 | const usb_device_request_setup_packet_t *request);
|
|---|
| 111 |
|
|---|
| 112 | #endif
|
|---|
| 113 | /**
|
|---|
| 114 | * @}
|
|---|
| 115 | */
|
|---|