root / lab4 / .minix-src / include / minix / usb_ch9.h @ 14
History | View | Annotate | Download (6.72 KB)
1 | 13 | up20180614 | #ifndef MINIX_USB_CH9_H
|
---|---|---|---|
2 | #define MINIX_USB_CH9_H
|
||
3 | /*
|
||
4 | * Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||
5 | * All rights reserved.
|
||
6 | *
|
||
7 | * This code is derived from software contributed to The NetBSD Foundation
|
||
8 | * by Lennart Augustsson (lennart@augustsson.net) at
|
||
9 | * Carlstedt Research & Technology.
|
||
10 | *
|
||
11 | * Redistribution and use in source and binary forms, with or without
|
||
12 | * modification, are permitted provided that the following conditions
|
||
13 | * are met:
|
||
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.
|
||
26 | *
|
||
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.
|
||
38 | */
|
||
39 | /* USB DESCRIPTORS */
|
||
40 | /*
|
||
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
|
||
44 | * values.
|
||
45 | */
|
||
46 | |||
47 | #include <sys/types.h> |
||
48 | |||
49 | typedef u8_t uByte;
|
||
50 | typedef u8_t uWord[2]; |
||
51 | typedef u8_t uDWord[4]; |
||
52 | |||
53 | #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h)) |
||
54 | |||
55 | #if 1 |
||
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)) |
||
63 | #else
|
||
64 | /*
|
||
65 | * On little-endian machines that can handle unanliged accesses
|
||
66 | * (e.g. i386) these macros can be replaced by the following.
|
||
67 | */
|
||
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))
|
||
72 | #endif
|
||
73 | |||
74 | #define UPACKED __attribute__((__packed__))
|
||
75 | |||
76 | /* Requests */
|
||
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 |
||
111 | |||
112 | |||
113 | |||
114 | typedef struct { |
||
115 | uByte bLength; |
||
116 | uByte bDescriptorType; |
||
117 | uByte bDescriptorSubtype; |
||
118 | } UPACKED usb_descriptor_t; |
||
119 | |||
120 | |||
121 | typedef struct { |
||
122 | uByte bLength; |
||
123 | uByte bDescriptorType; |
||
124 | uWord bcdUSB; |
||
125 | #define UD_USB_2_0 0x0200 |
||
126 | #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
|
||
127 | uByte bDeviceClass; |
||
128 | uByte bDeviceSubClass; |
||
129 | uByte bDeviceProtocol; |
||
130 | uByte bMaxPacketSize; |
||
131 | /* The fields below are not part of the initial descriptor. */
|
||
132 | uWord idVendor; |
||
133 | uWord idProduct; |
||
134 | uWord bcdDevice; |
||
135 | uByte iManufacturer; |
||
136 | uByte iProduct; |
||
137 | uByte iSerialNumber; |
||
138 | uByte bNumConfigurations; |
||
139 | } UPACKED usb_device_descriptor_t; |
||
140 | #define USB_DEVICE_DESCRIPTOR_SIZE 18 |
||
141 | |||
142 | typedef struct { |
||
143 | uByte bLength; |
||
144 | uByte bDescriptorType; |
||
145 | uWord wTotalLength; |
||
146 | uByte bNumInterface; |
||
147 | uByte bConfigurationValue; |
||
148 | uByte iConfiguration; |
||
149 | uByte bmAttributes; |
||
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 |
||
157 | |||
158 | typedef struct { |
||
159 | uByte bLength; |
||
160 | uByte bDescriptorType; |
||
161 | uByte bInterfaceNumber; |
||
162 | uByte bAlternateSetting; |
||
163 | uByte bNumEndpoints; |
||
164 | uByte bInterfaceClass; |
||
165 | uByte bInterfaceSubClass; |
||
166 | uByte bInterfaceProtocol; |
||
167 | uByte iInterface; |
||
168 | } UPACKED usb_interface_descriptor_t; |
||
169 | #define USB_INTERFACE_DESCRIPTOR_SIZE 9 |
||
170 | |||
171 | typedef struct { |
||
172 | uByte bLength; |
||
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 |
||
179 | #define UE_ADDR 0x0f |
||
180 | #define UE_GET_ADDR(a) ((a) & UE_ADDR)
|
||
181 | uByte bmAttributes; |
||
182 | #define UE_XFERTYPE 0x03 |
||
183 | #define UE_CONTROL 0x00 |
||
184 | #define UE_ISOCHRONOUS 0x01 |
||
185 | #define UE_BULK 0x02 |
||
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; |
||
194 | uByte bInterval; |
||
195 | } UPACKED usb_endpoint_descriptor_t; |
||
196 | #define USB_ENDPOINT_DESCRIPTOR_SIZE 7 |
||
197 | |||
198 | typedef struct { |
||
199 | uByte bLength; |
||
200 | uByte bDescriptorType; |
||
201 | uWord bString[127];
|
||
202 | } UPACKED usb_string_descriptor_t; |
||
203 | |||
204 | #define USB_MAX_STRING_LEN 128 |
||
205 | #define USB_MAX_ENCODED_STRING_LEN (USB_MAX_STRING_LEN * 3) /* UTF8 */ |
||
206 | |||
207 | struct usb_device_request {
|
||
208 | uByte bmRequestType; |
||
209 | uByte bRequest; |
||
210 | uWord wValue; |
||
211 | uWord wIndex; |
||
212 | uWord wLength; |
||
213 | } UPACKED; |
||
214 | typedef struct usb_device_request usb_device_request_t; |
||
215 | |||
216 | |||
217 | #endif |