usb.h revision 1.112 1 /* $NetBSD: usb.h,v 1.112 2015/03/26 08:08:27 skrll Exp $ */
2 /* $FreeBSD: src/sys/dev/usb/usb.h,v 1.14 1999/11/17 22:33:46 n_hibma Exp $ */
3
4 /*
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart (at) augustsson.net) at
10 * Carlstedt Research & Technology.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35 #ifndef _USB_H_
36 #define _USB_H_
37
38 #include <sys/types.h>
39 #include <sys/time.h>
40
41 #include <sys/ioctl.h>
42
43 #if defined(_KERNEL)
44 #include <sys/mallocvar.h>
45
46 MALLOC_DECLARE(M_USB);
47 MALLOC_DECLARE(M_USBDEV);
48 MALLOC_DECLARE(M_USBHC);
49
50 #include <sys/device.h>
51
52 #endif
53
54 #ifdef USB_DEBUG
55 #define Static
56 #else
57 #define Static static
58 #endif
59
60 #define USB_STACK_VERSION 2
61
62 #define USB_MAX_DEVICES 128
63 #define USB_MIN_DEVICES 2 /* unused + root HUB */
64 #define USB_START_ADDR 0
65
66 #define USB_CONTROL_ENDPOINT 0
67 #define USB_MAX_ENDPOINTS 16
68
69 #define USB_FRAMES_PER_SECOND 1000
70 #define USB_UFRAMES_PER_FRAME 8
71
72 /*
73 * The USB records contain some unaligned little-endian word
74 * components. The U[SG]ETW macros take care of both the alignment
75 * and endian problem and should always be used to access non-byte
76 * values.
77 */
78 typedef u_int8_t uByte;
79 typedef u_int8_t uWord[2];
80 typedef u_int8_t uDWord[4];
81
82 #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
83
84 #if 1
85 #define UGETW(w) ((w)[0] | ((w)[1] << 8))
86 #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
87 #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
88 #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
89 (w)[1] = (u_int8_t)((v) >> 8), \
90 (w)[2] = (u_int8_t)((v) >> 16), \
91 (w)[3] = (u_int8_t)((v) >> 24))
92 #else
93 /*
94 * On little-endian machines that can handle unaligned accesses
95 * (e.g. i386) these macros can be replaced by the following.
96 */
97 #define UGETW(w) (*(u_int16_t *)(w))
98 #define USETW(w,v) (*(u_int16_t *)(w) = (v))
99 #define UGETDW(w) (*(u_int32_t *)(w))
100 #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
101 #endif
102
103 #define UPACKED __packed
104
105 typedef struct {
106 uByte bmRequestType;
107 uByte bRequest;
108 uWord wValue;
109 uWord wIndex;
110 uWord wLength;
111 } UPACKED usb_device_request_t;
112
113 #define UT_GET_DIR(a) ((a) & 0x80)
114 #define UT_WRITE 0x00
115 #define UT_READ 0x80
116
117 #define UT_GET_TYPE(a) ((a) & 0x60)
118 #define UT_STANDARD 0x00
119 #define UT_CLASS 0x20
120 #define UT_VENDOR 0x40
121
122 #define UT_GET_RECIPIENT(a) ((a) & 0x1f)
123 #define UT_DEVICE 0x00
124 #define UT_INTERFACE 0x01
125 #define UT_ENDPOINT 0x02
126 #define UT_OTHER 0x03
127
128 #define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
129 #define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
130 #define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
131 #define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
132 #define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
133 #define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
134 #define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
135 #define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
136 #define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
137 #define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
138 #define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
139 #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
140 #define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
141 #define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
142 #define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
143 #define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
144 #define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
145 #define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
146 #define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
147 #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
148 #define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
149 #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
150
151 /* Standard Requests Codes from the USB 2.0 spec, table 9-4 */
152 #define UR_GET_STATUS 0x00
153 #define UR_CLEAR_FEATURE 0x01
154 #define UR_SET_FEATURE 0x03
155 #define UR_SET_ADDRESS 0x05
156 #define UR_GET_DESCRIPTOR 0x06
157 #define UDESC_DEVICE 0x01
158 #define UDESC_CONFIG 0x02
159 #define UDESC_STRING 0x03
160 #define UDESC_INTERFACE 0x04
161 #define UDESC_ENDPOINT 0x05
162 #define UDESC_DEVICE_QUALIFIER 0x06
163 #define UDESC_OTHER_SPEED_CONFIGURATION 0x07
164 #define UDESC_INTERFACE_POWER 0x08
165 #define UDESC_OTG 0x09
166 #define UDESC_DEBUG 0x0a
167 #define UDESC_INTERFACE_ASSOC 0x0b
168 #define UDESC_BOS 0x0f
169 #define UDESC_DEVICE_CAPABILITY 0x10
170 #define UDESC_CS_DEVICE 0x21 /* class specific */
171 #define UDESC_CS_CONFIG 0x22
172 #define UDESC_CS_STRING 0x23
173 #define UDESC_CS_INTERFACE 0x24
174 #define UDESC_CS_ENDPOINT 0x25
175 #define UDESC_HUB 0x29
176 #define UDESC_SS_HUB 0x2a /* super speed */
177 #define UDESC_ENDPOINT_SS_COMP 0x30 /* super speed */
178 #define UDESC_ENDPOINT_ISOCH_SSP_COMP 0x31
179 #define UR_SET_DESCRIPTOR 0x07
180 #define UR_GET_CONFIG 0x08
181 #define UR_SET_CONFIG 0x09
182 #define UR_GET_INTERFACE 0x0a
183 #define UR_SET_INTERFACE 0x0b
184 #define UR_SYNCH_FRAME 0x0c
185 #define UR_SET_ENCRYPTION 0x0d
186 #define UR_GET_ENCRYPTION 0x0e
187 #define UR_SET_HANDSHAKE 0x0f
188 #define UR_GET_HANDSHAKE 0x10
189 #define UR_SET_CONNECTION 0x11
190 #define UR_SET_SECURITY_DATA 0x12
191 #define UR_GET_SECURITY_DATA 0x13
192 #define UR_SET_WUSB_DATA 0x14
193 #define UR_LOOPBACK_DATA_WRITE 0x15
194 #define UR_LOOPBACK_DATA_READ 0x16
195 #define UR_SET_INTERFACE_DS 0x17
196 #define UR_SET_SEL 0x30
197 #define UR_SET_ISOCH_DELAY 0x31
198
199 /*
200 * Feature selectors. USB 2.0 spec, table 9-6 and OTG and EH suppliment,
201 * table 6-2
202 */
203 #define UF_ENDPOINT_HALT 0
204 #define UF_INTERFACE_FUNCTION_SUSPEND 0
205 #define UF_DEVICE_REMOTE_WAKEUP 1
206 #define UF_TEST_MODE 2
207 #define UF_DEVICE_B_HNP_ENABLE 3
208 #define UF_DEVICE_A_HNP_SUPPORT 4
209 #define UF_DEVICE_A_ALT_HNP_SUPPORT 5
210 #define UF_DEVICE_WUSB_DEVICE 6
211 #define UF_U1_ENABLE 0x30
212 #define UF_U2_ENABLE 0x31
213 #define UF_LTM_ENABLE 0x32
214
215 #define USB_MAX_IPACKET 8 /* maximum size of the initial packet */
216
217 #define USB_2_MAX_CTRL_PACKET 64
218 #define USB_2_MAX_BULK_PACKET 512
219
220 #define USB_3_MAX_CTRL_PACKET 512
221
222 typedef struct {
223 uByte bLength;
224 uByte bDescriptorType;
225 } UPACKED usb_descriptor_t;
226
227 typedef struct {
228 uByte bLength;
229 uByte bDescriptorType;
230 uWord bcdUSB;
231 #define UD_USB_2_0 0x0200
232 #define UD_USB_3_0 0x0300
233 #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
234 #define UD_IS_USB3(d) (UGETW((d)->bcdUSB) >= UD_USB_3_0)
235 uByte bDeviceClass;
236 uByte bDeviceSubClass;
237 uByte bDeviceProtocol;
238 uByte bMaxPacketSize;
239 /* The fields below are not part of the initial descriptor. */
240 uWord idVendor;
241 uWord idProduct;
242 uWord bcdDevice;
243 uByte iManufacturer;
244 uByte iProduct;
245 uByte iSerialNumber;
246 uByte bNumConfigurations;
247 } UPACKED usb_device_descriptor_t;
248 #define USB_DEVICE_DESCRIPTOR_SIZE 18
249
250 typedef struct {
251 uByte bLength;
252 uByte bDescriptorType;
253 uWord wTotalLength;
254 uByte bNumInterface;
255 uByte bConfigurationValue;
256 uByte iConfiguration;
257 uByte bmAttributes;
258 #define UC_ATTR_MBO 0x80
259 #define UC_SELF_POWERED 0x40
260 #define UC_REMOTE_WAKEUP 0x20
261 uByte bMaxPower; /* max current in 2 mA units */
262 #define UC_POWER_FACTOR 2
263 #define UC_POWER_FACTOR_SS 8
264 } UPACKED usb_config_descriptor_t;
265 #define USB_CONFIG_DESCRIPTOR_SIZE 9
266
267 typedef struct {
268 uByte bLength;
269 uByte bDescriptorType;
270 uByte bInterfaceNumber;
271 uByte bAlternateSetting;
272 uByte bNumEndpoints;
273 uByte bInterfaceClass;
274 uByte bInterfaceSubClass;
275 uByte bInterfaceProtocol;
276 uByte iInterface;
277 } UPACKED usb_interface_descriptor_t;
278 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
279
280 typedef struct {
281 uByte bLength;
282 uByte bDescriptorType;
283 uByte bFirstInterface;
284 uByte bInterfaceCount;
285 uByte bFunctionClass;
286 uByte bFunctionSubClass;
287 uByte bFunctionProtocol;
288 uByte iFunction;
289 } UPACKED usb_interface_assoc_descriptor_t;
290 #define USB_INTERFACE_ASSOC_DESCRIPTOR_SIZE 8
291
292 typedef struct {
293 uByte bLength;
294 uByte bDescriptorType;
295 uByte bEndpointAddress;
296 #define UE_GET_DIR(a) ((a) & 0x80)
297 #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
298 #define UE_DIR_IN 0x80
299 #define UE_DIR_OUT 0x00
300 #define UE_ADDR 0x0f
301 #define UE_GET_ADDR(a) ((a) & UE_ADDR)
302 uByte bmAttributes;
303 #define UE_XFERTYPE 0x03
304 #define UE_CONTROL 0x00
305 #define UE_ISOCHRONOUS 0x01
306 #define UE_BULK 0x02
307 #define UE_INTERRUPT 0x03
308 #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
309 #define UE_ISO_TYPE 0x0c
310 #define UE_ISO_ASYNC 0x04
311 #define UE_ISO_ADAPT 0x08
312 #define UE_ISO_SYNC 0x0c
313 #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
314 uWord wMaxPacketSize;
315 #define UE_GET_TRANS(a) (((a) >> 11) & 0x3)
316 #define UE_GET_SIZE(a) ((a) & 0x7ff)
317 uByte bInterval;
318 } UPACKED usb_endpoint_descriptor_t;
319 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
320
321 typedef struct {
322 uByte bLength;
323 uByte bDescriptorType;
324 uByte bMaxBurst;
325 uByte bmAttributes;
326 #define UE_SSC_MAXSTREAMS(x) __SHIFTOUT(x, __BITS(4,0)) /* bulk */
327 #define UE_SSC_MULT(x) __SHIFTOUT(x, __BITS(1,0)) /* isoch */
328 #define UE_SSC_SSP_ISO(x) __SHIFTOUT(x, __BIT(7)) /* isoch */
329 /* The fields below are only valid for periodic endpoints */
330 uWord wBytesPerInterval;
331 } UPACKED usb_endpoint_ss_comp_descriptor_t;
332 #define USB_ENDPOINT_SS_COMP_DESCRIPTOR_SIZE 6
333
334 /* USB 3.0 9.6.2, Table 9-12 */
335 typedef struct {
336 uByte bLength;
337 uByte bDescriptorType;
338 uWord wTotalLength;
339 uByte bNumDeviceCaps;
340 } UPACKED usb_bos_descriptor_t;
341 #define USB_BOS_DESCRIPTOR_SIZE 5
342
343 /* common members of device capability descriptors */
344 typedef struct {
345 uByte bLength;
346 uByte bDescriptorType;
347 uByte bDevCapabilityType;
348 /* Table 9-14 */
349 #define USB_DEVCAP_RESERVED 0x00
350 #define USB_DEVCAP_WUSB 0x01
351 #define USB_DEVCAP_USB2EXT 0x02
352 #define USB_DEVCAP_SUPER_SPEED 0x03
353 #define USB_DEVCAP_CONTAINER_ID 0x04
354 #define USB_DEVCAP_PLATFORM 0x05
355 #define USB_DEVCAP_POWER_DELIVERY_CAPABILITY 0x06
356 #define USB_DEVCAP_BATTERY_INFO_CAPABILITY 0x07
357 #define USB_DEVCAP_PD_CONSUMER_PORT_CAPABILITY 0x08
358 #define USB_DEVCAP_PD_PROVIDER_PORT_CAPABILITY 0x09
359 #define USB_DEVCAP_SUPERSPEED_PLUS 0x0a
360 #define USB_DEVCAP_PRECISION_TIME_MEASUREMENT 0x0b
361 #define USB_DEVCAP_WUSB_EXT 0x0c
362 /* data ... */
363 } UPACKED usb_device_capability_descriptor_t;
364 #define USB_DEVICE_CAPABILITY_DESCRIPTOR_SIZE 3 /* at least */
365
366 /* 9.6.2.1 */
367 typedef struct {
368 uByte bLength;
369 uByte bDescriptorType;
370 uByte bDevCapabilityType;
371 uDWord bmAttributes;
372 #define USB_DEVCAP_USB2EXT_LPM __BIT(1)
373 } UPACKED usb_devcap_usb2ext_descriptor_t;
374 #define USB_DEVCAP_USB2EXT_DESCRIPTOR_SIZE 7
375
376 /* 9.6.2.2 */
377 typedef struct {
378 uByte bLength;
379 uByte bDescriptorType;
380 uByte bDevCapabilityType;
381 uByte bmAttributes;
382 #define USB_DEVCAP_SS_LTM __BIT(1)
383 uWord wSpeedsSupported;
384 #define USB_DEVCAP_SS_SPEED_LS __BIT(0)
385 #define USB_DEVCAP_SS_SPEED_FS __BIT(1)
386 #define USB_DEVCAP_SS_SPEED_HS __BIT(2)
387 #define USB_DEVCAP_SS_SPEED_SS __BIT(3)
388 uByte bFunctionalitySupport;
389 uByte bU1DevExitLat;
390 uWord wU2DevExitLat;
391 } UPACKED usb_devcap_ss_descriptor_t;
392 #define USB_DEVCAP_SS_DESCRIPTOR_SIZE 10
393
394 /* 9.6.2.4 */
395 typedef struct {
396 uByte bLength;
397 uByte bDescriptorType;
398 uByte bDevCapabilityType;
399 uByte bReserved;
400 uByte ContainerID[16];
401 } UPACKED usb_devcap_container_id_descriptor_t;
402 #define USB_DEVCAP_CONTAINER_ID_DESCRIPTOR_SIZE 20
403
404 typedef struct {
405 uByte bLength;
406 uByte bDescriptorType;
407 uByte bDevCapabilityType;
408 uByte bReserved;
409 uByte PlatformCapabilityUUID[16];
410 uByte CapabilityData[0];
411 } UPACKED usb_devcap_platform_descriptor_t;
412 #define USB_DEVCAP_PLATFORM_DESCRIPTOR_SIZE 20
413
414 typedef struct {
415 uByte bLength;
416 uByte bDescriptorType;
417 uByte bDevCapabilityType;
418 uByte bReserved;
419 uDWord bmAttributes;
420 uWord wFunctionalitySupport;
421 uWord wReserved;
422 uDWord bmSublinkSpeedAttr[0];
423 } UPACKED usb_devcap_ssp_descriptor_t;
424 #define USB_DEVCAP_SSP_DESCRIPTOR_SIZE 12 /* variable length */
425
426 typedef struct {
427 uByte bLength;
428 uByte bDescriptorType;
429 uWord bString[126];
430 } UPACKED usb_string_descriptor_t;
431 #define USB_MAX_STRING_LEN 128
432 #define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
433 #define USB_MAX_ENCODED_STRING_LEN (USB_MAX_STRING_LEN * 3) /* UTF8 */
434
435 /* Hub specific request */
436 #define UR_GET_BUS_STATE 0x02
437 #define UR_CLEAR_TT_BUFFER 0x08
438 #define UR_RESET_TT 0x09
439 #define UR_GET_TT_STATE 0x0a
440 #define UR_STOP_TT 0x0b
441 #define UR_SET_HUB_DEPTH 0x0c
442 #define UR_GET_PORT_ERR_COUNT 0x0d
443
444 /*
445 * Hub features from USB 2.0 spec, table 11-17 and updated by the
446 * LPM ECN table 4-7.
447 */
448 #define UHF_C_HUB_LOCAL_POWER 0
449 #define UHF_C_HUB_OVER_CURRENT 1
450 #define UHF_PORT_CONNECTION 0
451 #define UHF_PORT_ENABLE 1
452 #define UHF_PORT_SUSPEND 2
453 #define UHF_PORT_OVER_CURRENT 3
454 #define UHF_PORT_RESET 4
455 #define UHF_PORT_LINK_STATE 5
456 #define UHF_PORT_POWER 8
457 #define UHF_PORT_LOW_SPEED 9
458 #define UHF_PORT_L1 10
459 #define UHF_C_PORT_CONNECTION 16
460 #define UHF_C_PORT_ENABLE 17
461 #define UHF_C_PORT_SUSPEND 18
462 #define UHF_C_PORT_OVER_CURRENT 19
463 #define UHF_C_PORT_RESET 20
464 #define UHF_PORT_TEST 21
465 #define UHF_PORT_INDICATOR 22
466 #define UHF_C_PORT_L1 23
467
468 /* SS HUB specific features */
469 #define UHF_PORT_U1_TIMEOUT 23
470 #define UHF_PORT_U2_TIMEOUT 24
471 #define UHF_C_PORT_LINK_STATE 25
472 #define UHF_C_PORT_CONFIG_ERROR 26
473 #define UHF_PORT_REMOTE_WAKE_MASK 27
474 #define UHF_BH_PORT_RESET 28
475 #define UHF_C_BH_PORT_RESET 29
476 #define UHF_FORCE_LINKPM_ACCEPT 30
477
478 typedef struct {
479 uByte bDescLength;
480 uByte bDescriptorType;
481 uByte bNbrPorts;
482 #define UHD_NPORTS_MAX 255
483 uWord wHubCharacteristics;
484 #define UHD_PWR 0x0003
485 #define UHD_PWR_GANGED 0x0000
486 #define UHD_PWR_INDIVIDUAL 0x0001
487 #define UHD_PWR_NO_SWITCH 0x0002
488 #define UHD_COMPOUND 0x0004
489 #define UHD_OC 0x0018
490 #define UHD_OC_GLOBAL 0x0000
491 #define UHD_OC_INDIVIDUAL 0x0008
492 #define UHD_OC_NONE 0x0010
493 #define UHD_TT_THINK 0x0060
494 #define UHD_TT_THINK_8 0x0000
495 #define UHD_TT_THINK_16 0x0020
496 #define UHD_TT_THINK_24 0x0040
497 #define UHD_TT_THINK_32 0x0060
498 #define UHD_PORT_IND 0x0080
499 uByte bPwrOn2PwrGood; /* delay in 2 ms units */
500 #define UHD_PWRON_FACTOR 2
501 uByte bHubContrCurrent;
502 uByte DeviceRemovable[32]; /* max 255 ports */
503 #define UHD_NOT_REMOV(desc, i) \
504 (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
505 /* deprecated */ uByte PortPowerCtrlMask[1];
506 } UPACKED usb_hub_descriptor_t;
507 #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
508
509 typedef struct {
510 uByte bLength;
511 uByte bDescriptorType;
512 uByte bNbrPorts;
513 #define UHD_SS_NPORTS_MAX 15
514 uWord wHubCharacteristics;
515 uByte bPwrOn2PwrGood; /* delay in 2 ms units */
516 uByte bHubContrCurrent;
517 uByte bHubHdrDecLat;
518 uWord wHubDelay; /* forward delay in nanosec */
519 uByte DeviceRemovable[2]; /* max 15 ports */
520 } UPACKED usb_hub_ss_descriptor_t;
521 #define USB_HUB_SS_DESCRIPTOR_SIZE 12
522
523 typedef struct {
524 uByte bLength;
525 uByte bDescriptorType;
526 uWord bcdUSB;
527 uByte bDeviceClass;
528 uByte bDeviceSubClass;
529 uByte bDeviceProtocol;
530 uByte bMaxPacketSize0;
531 uByte bNumConfigurations;
532 uByte bReserved;
533 } UPACKED usb_device_qualifier_t;
534 #define USB_DEVICE_QUALIFIER_SIZE 10
535
536 typedef struct {
537 uByte bLength;
538 uByte bDescriptorType;
539 uByte bmAttributes;
540 #define UOTG_SRP 0x01
541 #define UOTG_HNP 0x02
542 } UPACKED usb_otg_descriptor_t;
543
544 /* OTG feature selectors */
545 #define UOTG_B_HNP_ENABLE 3
546 #define UOTG_A_HNP_SUPPORT 4
547 #define UOTG_A_ALT_HNP_SUPPORT 5
548
549 typedef struct {
550 uByte bLength;
551 uByte bDescriptorType;
552 uByte bDebugInEndpoint;
553 uByte bDebugOutEndpoint;
554 } UPACKED usb_debug_descriptor_t;
555
556 typedef struct {
557 uWord wStatus;
558 /* Device status flags */
559 #define UDS_SELF_POWERED 0x0001
560 #define UDS_REMOTE_WAKEUP 0x0002
561 /* Endpoint status flags */
562 #define UES_HALT 0x0001
563 } UPACKED usb_status_t;
564
565 typedef struct {
566 uWord wHubStatus;
567 #define UHS_LOCAL_POWER 0x0001
568 #define UHS_OVER_CURRENT 0x0002
569 uWord wHubChange;
570 } UPACKED usb_hub_status_t;
571
572 typedef struct {
573 uWord wPortStatus;
574 #define UPS_CURRENT_CONNECT_STATUS 0x0001
575 #define UPS_PORT_ENABLED 0x0002
576 #define UPS_SUSPEND 0x0004
577 #define UPS_OVERCURRENT_INDICATOR 0x0008
578 #define UPS_RESET 0x0010
579 #define UPS_PORT_L1 0x0020
580 #define UPS_PORT_LS_GET(x) __SHIFTOUT(x, __BITS(8,5))
581 #define UPS_PORT_LS_U0 0x00
582 #define UPS_PORT_LS_U1 0x01
583 #define UPS_PORT_LS_U2 0x02
584 #define UPS_PORT_LS_U3 0x03
585 #define UPS_PORT_LS_SS_DIS 0x04
586 #define UPS_PORT_LS_RX_DET 0x05
587 #define UPS_PORT_LS_SS_INA 0x06
588 #define UPS_PORT_LS_POLL 0x07
589 #define UPS_PORT_LS_RECOVER 0x08
590 #define UPS_PORT_LS_HOT_RST 0x09
591 #define UPS_PORT_LS_COMP_MODE 0x0a
592 #define UPS_PORT_LS_LOOPBACK 0x0b
593 #define UPS_PORT_LS_RESUME 0x0f
594 #define UPS_PORT_POWER 0x0100
595 #define UPS_PORT_POWER_SS 0x0200
596 #define UPS_FULL_SPEED 0x0000 /* for completeness */
597 #define UPS_LOW_SPEED 0x0200
598 #define UPS_HIGH_SPEED 0x0400
599 #define UPS_SUPER_SPEED 0x0800
600 #define UPS_PORT_TEST 0x0800
601 #define UPS_PORT_INDICATOR 0x1000
602 uWord wPortChange;
603 #define UPS_C_CONNECT_STATUS 0x0001
604 #define UPS_C_PORT_ENABLED 0x0002
605 #define UPS_C_SUSPEND 0x0004
606 #define UPS_C_OVERCURRENT_INDICATOR 0x0008
607 #define UPS_C_PORT_RESET 0x0010
608 #define UPS_C_PORT_L1 0x0020
609 #define UPS_C_BH_PORT_RESET 0x0020
610 #define UPS_C_PORT_LINK_STATE 0x0040
611 #define UPS_C_PORT_CONFIG_ERROR 0x0080
612 } UPACKED usb_port_status_t;
613
614 /* Device class codes */
615 #define UDCLASS_IN_INTERFACE 0x00
616 #define UDCLASS_COMM 0x02
617 #define UDCLASS_HUB 0x09
618 #define UDSUBCLASS_HUB 0x00
619 #define UDPROTO_FSHUB 0x00
620 #define UDPROTO_HSHUBSTT 0x01
621 #define UDPROTO_HSHUBMTT 0x02
622 #define UDPROTO_SSHUB 0x03
623 #define UDCLASS_DIAGNOSTIC 0xdc
624 #define UDCLASS_WIRELESS 0xe0
625 #define UDSUBCLASS_RF 0x01
626 #define UDPROTO_BLUETOOTH 0x01
627 #define UDCLASS_VENDOR 0xff
628
629 /* Interface class codes */
630 #define UICLASS_UNSPEC 0x00
631
632 #define UICLASS_AUDIO 0x01
633 #define UISUBCLASS_AUDIOCONTROL 1
634 #define UISUBCLASS_AUDIOSTREAM 2
635 #define UISUBCLASS_MIDISTREAM 3
636
637 #define UICLASS_VIDEO 0x0e
638 #define UISUBCLASS_VIDEOCONTROL 1
639 #define UISUBCLASS_VIDEOSTREAMING 2
640 #define UISUBCLASS_VIDEOCOLLECTION 3
641
642 #define UICLASS_CDC 0x02 /* communication */
643 #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
644 #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
645 #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
646 #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
647 #define UISUBCLASS_CAPI_CONTROLMODEL 5
648 #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
649 #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
650 #define UIPROTO_CDC_NOCLASS 0 /* no class specific
651 protocol required */
652 #define UIPROTO_CDC_AT 1
653
654 #define UICLASS_HID 0x03
655 #define UISUBCLASS_BOOT 1
656 #define UIPROTO_BOOT_KEYBOARD 1
657 #define UIPROTO_MOUSE 2
658
659 #define UICLASS_PHYSICAL 0x05
660
661 #define UICLASS_IMAGE 0x06
662
663 #define UICLASS_PRINTER 0x07
664 #define UISUBCLASS_PRINTER 1
665 #define UIPROTO_PRINTER_UNI 1
666 #define UIPROTO_PRINTER_BI 2
667 #define UIPROTO_PRINTER_1284 3
668
669 #define UICLASS_MASS 0x08
670 #define UISUBCLASS_RBC 1
671 #define UISUBCLASS_SFF8020I 2
672 #define UISUBCLASS_QIC157 3
673 #define UISUBCLASS_UFI 4
674 #define UISUBCLASS_SFF8070I 5
675 #define UISUBCLASS_SCSI 6
676 #define UIPROTO_MASS_CBI_I 0
677 #define UIPROTO_MASS_CBI 1
678 #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
679 #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
680 #define UIPROTO_MASS_UAS 98 /* USB Attached SCSI */
681
682 #define UICLASS_HUB 0x09
683 #define UISUBCLASS_HUB 0
684 #define UIPROTO_FSHUB 0
685 #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
686 #define UIPROTO_HSHUBMTT 1
687
688 #define UICLASS_CDC_DATA 0x0a
689 #define UISUBCLASS_DATA 0
690 #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
691 #define UIPROTO_DATA_HDLC 0x31 /* HDLC */
692 #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
693 #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
694 #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
695 #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
696 #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
697 #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
698 #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
699 #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
700 #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
701 #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
702 #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
703
704 #define UICLASS_SMARTCARD 0x0b
705
706 /*#define UICLASS_FIRM_UPD 0x0c*/
707
708 #define UICLASS_SECURITY 0x0d
709
710 #define UICLASS_DIAGNOSTIC 0xdc
711
712 #define UICLASS_WIRELESS 0xe0
713 #define UISUBCLASS_RF 0x01
714 #define UIPROTO_BLUETOOTH 0x01
715 #define UIPROTO_RNDIS 0x03
716
717 #define UICLASS_APPL_SPEC 0xfe
718 #define UISUBCLASS_FIRMWARE_DOWNLOAD 1
719 #define UISUBCLASS_IRDA 2
720 #define UIPROTO_IRDA 0
721
722 #define UICLASS_VENDOR 0xff
723
724
725 #define USB_HUB_MAX_DEPTH 5
726
727 /*
728 * Minimum time a device needs to be powered down to go through
729 * a power cycle. XXX Are these time in the spec?
730 */
731 #define USB_POWER_DOWN_TIME 200 /* ms */
732 #define USB_PORT_POWER_DOWN_TIME 100 /* ms */
733
734 #if 0
735 /* These are the values from the spec. */
736 #define USB_PORT_RESET_DELAY 10 /* ms */
737 #define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
738 #define USB_PORT_RESET_RECOVERY 10 /* ms */
739 #define USB_PORT_POWERUP_DELAY 100 /* ms */
740 #define USB_SET_ADDRESS_SETTLE 2 /* ms */
741 #define USB_RESUME_DELAY (20*5) /* ms */
742 #define USB_RESUME_WAIT 10 /* ms */
743 #define USB_RESUME_RECOVERY 10 /* ms */
744 #define USB_EXTRA_POWER_UP_TIME 0 /* ms */
745 #else
746 /* Allow for marginal (i.e. non-conforming) devices. */
747 #define USB_PORT_RESET_DELAY 50 /* ms */
748 #define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
749 #define USB_PORT_RESET_RECOVERY 250 /* ms */
750 #define USB_PORT_POWERUP_DELAY 300 /* ms */
751 #define USB_SET_ADDRESS_SETTLE 10 /* ms */
752 #define USB_RESUME_DELAY (50*5) /* ms */
753 #define USB_RESUME_WAIT 50 /* ms */
754 #define USB_RESUME_RECOVERY 50 /* ms */
755 #define USB_EXTRA_POWER_UP_TIME 20 /* ms */
756 #endif
757
758 #define USB_MIN_POWER 100 /* mA */
759 #define USB_MIN_POWER_SS 150 /* mA */
760 #define USB_MAX_POWER 500 /* mA */
761 #define USB_MAX_POWER_SS 900 /* mA */
762
763 #define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
764
765
766 #define USB_UNCONFIG_NO 0
767 #define USB_UNCONFIG_INDEX (-1)
768
769
770 /* Packet IDs */
771 #define UPID_RESERVED 0xf0
772 #define UPID_OUT 0xe1
773 #define UPID_ACK 0xd2
774 #define UPID_DATA0 0xc3
775 #define UPID_PING 0xb4
776 #define UPID_SOF 0xa5
777 #define UPID_NYET 0x96
778 #define UPID_DATA2 0x87
779 #define UPID_SPLIT 0x78
780 #define UPID_IN 0x69
781 #define UPID_NAK 0x5a
782 #define UPID_DATA1 0x4b
783 #define UPID_ERR 0x3c
784 #define UPID_PREAMBLE 0x3c
785 #define UPID_SETUP 0x2d
786 #define UPID_STALL 0x1e
787 #define UPID_MDATA 0x0f
788
789
790 /*** ioctl() related stuff ***/
791
792 struct usb_ctl_request {
793 int ucr_addr;
794 usb_device_request_t ucr_request;
795 void *ucr_data;
796 int ucr_flags;
797 #define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
798 int ucr_actlen; /* actual length transferred */
799 };
800
801 struct usb_alt_interface {
802 int uai_config_index;
803 int uai_interface_index;
804 int uai_alt_no;
805 };
806
807 #define USB_CURRENT_CONFIG_INDEX (-1)
808 #define USB_CURRENT_ALT_INDEX (-1)
809
810 struct usb_config_desc {
811 int ucd_config_index;
812 usb_config_descriptor_t ucd_desc;
813 };
814
815 struct usb_interface_desc {
816 int uid_config_index;
817 int uid_interface_index;
818 int uid_alt_index;
819 usb_interface_descriptor_t uid_desc;
820 };
821
822 struct usb_endpoint_desc {
823 int ued_config_index;
824 int ued_interface_index;
825 int ued_alt_index;
826 int ued_endpoint_index;
827 usb_endpoint_descriptor_t ued_desc;
828 };
829
830 struct usb_full_desc {
831 int ufd_config_index;
832 u_int ufd_size;
833 u_char *ufd_data;
834 };
835
836 struct usb_string_desc {
837 int usd_string_index;
838 int usd_language_id;
839 usb_string_descriptor_t usd_desc;
840 };
841
842 struct usb_ctl_report_desc {
843 int ucrd_size;
844 u_char ucrd_data[1024]; /* filled data size will vary */
845 };
846
847 typedef struct { u_int32_t cookie; } usb_event_cookie_t;
848
849 #define USB_MAX_DEVNAMES 4
850 #define USB_MAX_DEVNAMELEN 16
851 struct usb_device_info {
852 u_int8_t udi_bus;
853 u_int8_t udi_addr; /* device address */
854 usb_event_cookie_t udi_cookie;
855 char udi_product[USB_MAX_ENCODED_STRING_LEN];
856 char udi_vendor[USB_MAX_ENCODED_STRING_LEN];
857 char udi_release[8];
858 char udi_serial[USB_MAX_ENCODED_STRING_LEN];
859 u_int16_t udi_productNo;
860 u_int16_t udi_vendorNo;
861 u_int16_t udi_releaseNo;
862 u_int8_t udi_class;
863 u_int8_t udi_subclass;
864 u_int8_t udi_protocol;
865 u_int8_t udi_config;
866 u_int8_t udi_speed;
867 #define USB_SPEED_LOW 1
868 #define USB_SPEED_FULL 2
869 #define USB_SPEED_HIGH 3
870 #define USB_SPEED_SUPER 4
871 int udi_power; /* power consumption in mA, 0 if selfpowered */
872 int udi_nports;
873 char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
874 u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
875 #define USB_PORT_ENABLED 0xff
876 #define USB_PORT_SUSPENDED 0xfe
877 #define USB_PORT_POWERED 0xfd
878 #define USB_PORT_DISABLED 0xfc
879 };
880
881 /* <=3.0 had this layout of the structure */
882 struct usb_device_info_old {
883 u_int8_t udi_bus;
884 u_int8_t udi_addr; /* device address */
885 usb_event_cookie_t udi_cookie;
886 char udi_product[USB_MAX_STRING_LEN];
887 char udi_vendor[USB_MAX_STRING_LEN];
888 char udi_release[8];
889 u_int16_t udi_productNo;
890 u_int16_t udi_vendorNo;
891 u_int16_t udi_releaseNo;
892 u_int8_t udi_class;
893 u_int8_t udi_subclass;
894 u_int8_t udi_protocol;
895 u_int8_t udi_config;
896 u_int8_t udi_speed;
897 int udi_power; /* power consumption in mA, 0 if selfpowered */
898 int udi_nports;
899 char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
900 u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
901 };
902
903 struct usb_ctl_report {
904 int ucr_report;
905 u_char ucr_data[1024]; /* filled data size will vary */
906 };
907
908 struct usb_device_stats {
909 u_long uds_requests[4]; /* indexed by transfer type UE_* */
910 };
911
912 struct usb_bulk_ra_wb_opt {
913 u_int ra_wb_buffer_size;
914 u_int ra_wb_request_size;
915 };
916
917 /* Events that can be read from /dev/usb */
918 struct usb_event {
919 int ue_type;
920 #define USB_EVENT_CTRLR_ATTACH 1
921 #define USB_EVENT_CTRLR_DETACH 2
922 #define USB_EVENT_DEVICE_ATTACH 3
923 #define USB_EVENT_DEVICE_DETACH 4
924 #define USB_EVENT_DRIVER_ATTACH 5
925 #define USB_EVENT_DRIVER_DETACH 6
926 #define USB_EVENT_IS_ATTACH(n) ((n) == USB_EVENT_CTRLR_ATTACH || (n) == USB_EVENT_DEVICE_ATTACH || (n) == USB_EVENT_DRIVER_ATTACH)
927 #define USB_EVENT_IS_DETACH(n) ((n) == USB_EVENT_CTRLR_DETACH || (n) == USB_EVENT_DEVICE_DETACH || (n) == USB_EVENT_DRIVER_DETACH)
928 struct timespec ue_time;
929 union {
930 struct {
931 int ue_bus;
932 } ue_ctrlr;
933 struct usb_device_info ue_device;
934 struct {
935 usb_event_cookie_t ue_cookie;
936 char ue_devname[16];
937 } ue_driver;
938 } u;
939 };
940
941 /* old <=3.0 compat event */
942 struct usb_event_old {
943 int ue_type;
944 struct timespec ue_time;
945 union {
946 struct {
947 int ue_bus;
948 } ue_ctrlr;
949 struct usb_device_info_old ue_device;
950 struct {
951 usb_event_cookie_t ue_cookie;
952 char ue_devname[16];
953 } ue_driver;
954 } u;
955 };
956
957
958 /* USB controller */
959 #define USB_REQUEST _IOWR('U', 1, struct usb_ctl_request)
960 #define USB_SETDEBUG _IOW ('U', 2, int)
961 #define USB_DISCOVER _IO ('U', 3)
962 #define USB_DEVICEINFO _IOWR('U', 4, struct usb_device_info)
963 #define USB_DEVICEINFO_OLD _IOWR('U', 4, struct usb_device_info_old)
964 #define USB_DEVICESTATS _IOR ('U', 5, struct usb_device_stats)
965
966 /* Generic HID device */
967 #define USB_GET_REPORT_DESC _IOR ('U', 21, struct usb_ctl_report_desc)
968 #define USB_SET_IMMED _IOW ('U', 22, int)
969 #define USB_GET_REPORT _IOWR('U', 23, struct usb_ctl_report)
970 #define USB_SET_REPORT _IOW ('U', 24, struct usb_ctl_report)
971 #define USB_GET_REPORT_ID _IOR ('U', 25, int)
972
973 /* Generic USB device */
974 #define USB_GET_CONFIG _IOR ('U', 100, int)
975 #define USB_SET_CONFIG _IOW ('U', 101, int)
976 #define USB_GET_ALTINTERFACE _IOWR('U', 102, struct usb_alt_interface)
977 #define USB_SET_ALTINTERFACE _IOWR('U', 103, struct usb_alt_interface)
978 #define USB_GET_NO_ALT _IOWR('U', 104, struct usb_alt_interface)
979 #define USB_GET_DEVICE_DESC _IOR ('U', 105, usb_device_descriptor_t)
980 #define USB_GET_CONFIG_DESC _IOWR('U', 106, struct usb_config_desc)
981 #define USB_GET_INTERFACE_DESC _IOWR('U', 107, struct usb_interface_desc)
982 #define USB_GET_ENDPOINT_DESC _IOWR('U', 108, struct usb_endpoint_desc)
983 #define USB_GET_FULL_DESC _IOWR('U', 109, struct usb_full_desc)
984 #define USB_GET_STRING_DESC _IOWR('U', 110, struct usb_string_desc)
985 #define USB_DO_REQUEST _IOWR('U', 111, struct usb_ctl_request)
986 #define USB_GET_DEVICEINFO _IOR ('U', 112, struct usb_device_info)
987 #define USB_GET_DEVICEINFO_OLD _IOR ('U', 112, struct usb_device_info_old)
988 #define USB_SET_SHORT_XFER _IOW ('U', 113, int)
989 #define USB_SET_TIMEOUT _IOW ('U', 114, int)
990 #define USB_SET_BULK_RA _IOW ('U', 115, int)
991 #define USB_SET_BULK_WB _IOW ('U', 116, int)
992 #define USB_SET_BULK_RA_OPT _IOW ('U', 117, struct usb_bulk_ra_wb_opt)
993 #define USB_SET_BULK_WB_OPT _IOW ('U', 118, struct usb_bulk_ra_wb_opt)
994
995 /* Modem device */
996 #define USB_GET_CM_OVER_DATA _IOR ('U', 130, int)
997 #define USB_SET_CM_OVER_DATA _IOW ('U', 131, int)
998
999 #endif /* _USB_H_ */
1000