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