1 #ifndef MINIX_USB_CH9_H
2 #define MINIX_USB_CH9_H
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * The USB records contain some unaligned little-endian word
42 * components. The U[SG]ETW macros take care of both the alignment
43 * and endian problem and should always be used to access non-byte
47 #include <minix/types.h>
50 typedef u8_t uWord
[2];
51 typedef u8_t uDWord
[4];
53 #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
56 #define UGETW(w) ((w)[0] | ((w)[1] << 8))
57 #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
58 #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
59 #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
60 (w)[1] = (u_int8_t)((v) >> 8), \
61 (w)[2] = (u_int8_t)((v) >> 16), \
62 (w)[3] = (u_int8_t)((v) >> 24))
65 * On little-endian machines that can handle unanliged accesses
66 * (e.g. i386) these macros can be replaced by the following.
68 #define UGETW(w) (*(u_int16_t *)(w))
69 #define USETW(w,v) (*(u_int16_t *)(w) = (v))
70 #define UGETDW(w) (*(u_int32_t *)(w))
71 #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
74 #define UPACKED __attribute__((__packed__))
77 #define UR_GET_STATUS 0x00
78 #define UR_CLEAR_FEATURE 0x01
79 #define UR_SET_FEATURE 0x03
80 #define UR_SET_ADDRESS 0x05
81 #define UR_GET_DESCRIPTOR 0x06
82 #define UDESC_DEVICE 0x01
83 #define UDESC_CONFIG 0x02
84 #define UDESC_STRING 0x03
85 #define USB_LANGUAGE_TABLE 0x00 /* language ID string index */
86 #define UDESC_INTERFACE 0x04
87 #define UDESC_ENDPOINT 0x05
88 #define UDESC_DEVICE_QUALIFIER 0x06
89 #define UDESC_OTHER_SPEED_CONFIGURATION 0x07
90 #define UDESC_INTERFACE_POWER 0x08
91 #define UDESC_OTG 0x09
92 #define UDESC_DEBUG 0x0A
93 #define UDESC_IFACE_ASSOC 0x0B /* interface association */
94 #define UDESC_BOS 0x0F /* binary object store */
95 #define UDESC_DEVICE_CAPABILITY 0x10
96 #define UDESC_CS_DEVICE 0x21 /* class specific */
97 #define UDESC_CS_CONFIG 0x22
98 #define UDESC_CS_STRING 0x23
99 #define UDESC_CS_INTERFACE 0x24
100 #define UDESC_CS_ENDPOINT 0x25
101 #define UDESC_HUB 0x29
102 #define UDESC_ENDPOINT_SS_COMP 0x30 /* super speed */
103 #define UR_SET_DESCRIPTOR 0x07
104 #define UR_GET_CONFIG 0x08
105 #define UR_SET_CONFIG 0x09
106 #define UR_GET_INTERFACE 0x0a
107 #define UR_SET_INTERFACE 0x0b
108 #define UR_SYNCH_FRAME 0x0c
109 #define UR_SET_SEL 0x30
110 #define UR_ISOCH_DELAY 0x31
116 uByte bDescriptorType
;
117 uByte bDescriptorSubtype
;
118 } UPACKED usb_descriptor_t
;
123 uByte bDescriptorType
;
125 #define UD_USB_2_0 0x0200
126 #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
128 uByte bDeviceSubClass
;
129 uByte bDeviceProtocol
;
130 uByte bMaxPacketSize
;
131 /* The fields below are not part of the initial descriptor. */
138 uByte bNumConfigurations
;
139 } UPACKED usb_device_descriptor_t
;
140 #define USB_DEVICE_DESCRIPTOR_SIZE 18
144 uByte bDescriptorType
;
147 uByte bConfigurationValue
;
148 uByte iConfiguration
;
150 #define UC_BUS_POWERED 0x80
151 #define UC_SELF_POWERED 0x40
152 #define UC_REMOTE_WAKEUP 0x20
153 uByte bMaxPower
; /* max current in 2 mA units */
154 #define UC_POWER_FACTOR 2
155 } UPACKED usb_config_descriptor_t
;
156 #define USB_CONFIG_DESCRIPTOR_SIZE 9
160 uByte bDescriptorType
;
161 uByte bInterfaceNumber
;
162 uByte bAlternateSetting
;
164 uByte bInterfaceClass
;
165 uByte bInterfaceSubClass
;
166 uByte bInterfaceProtocol
;
168 } UPACKED usb_interface_descriptor_t
;
169 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
173 uByte bDescriptorType
;
174 uByte bEndpointAddress
;
175 #define UE_GET_DIR(a) ((a) & 0x80)
176 #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
177 #define UE_DIR_IN 0x80
178 #define UE_DIR_OUT 0x00
180 #define UE_GET_ADDR(a) ((a) & UE_ADDR)
182 #define UE_XFERTYPE 0x03
183 #define UE_CONTROL 0x00
184 #define UE_ISOCHRONOUS 0x01
186 #define UE_INTERRUPT 0x03
187 #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
188 #define UE_ISO_TYPE 0x0c
189 #define UE_ISO_ASYNC 0x04
190 #define UE_ISO_ADAPT 0x08
191 #define UE_ISO_SYNC 0x0c
192 #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
193 uWord wMaxPacketSize
;
195 } UPACKED usb_endpoint_descriptor_t
;
196 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
200 uByte bDescriptorType
;
202 } UPACKED usb_string_descriptor_t
;
204 #define USB_MAX_STRING_LEN 128
205 #define USB_MAX_ENCODED_STRING_LEN (USB_MAX_STRING_LEN * 3) /* UTF8 */
207 struct usb_device_request
{
214 typedef struct usb_device_request usb_device_request_t
;