FreeBSD/Linux Kernel Cross Reference
sys/dev/usb/usb.h
1 /* $FreeBSD$ */
2 /*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
5 * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 /*
30 * This file contains standard definitions for the following USB
31 * protocol versions:
32 *
33 * USB v1.0
34 * USB v1.1
35 * USB v2.0
36 * USB v3.0
37 */
38
39 #ifndef _USB_STANDARD_H_
40 #define _USB_STANDARD_H_
41
42 #if defined(_KERNEL)
43 #include "opt_usb.h"
44
45 /* Declare parent SYSCTL USB node. */
46 #ifdef SYSCTL_DECL
47 SYSCTL_DECL(_hw_usb);
48 #endif
49
50 #include <sys/malloc.h>
51
52 MALLOC_DECLARE(M_USB);
53 MALLOC_DECLARE(M_USBDEV);
54 MALLOC_DECLARE(M_USBHC);
55 #endif /* _KERNEL */
56
57 #include <dev/usb/usb_endian.h>
58 #include <dev/usb/usb_freebsd.h>
59
60 #define USB_STACK_VERSION 2000 /* 2.0 */
61
62 /* Definition of some hardcoded USB constants. */
63
64 #define USB_MAX_IPACKET 8 /* initial USB packet size */
65 #define USB_EP_MAX (2*16) /* hardcoded */
66 #define USB_ROOT_HUB_ADDR 1 /* index */
67 #define USB_MIN_DEVICES 2 /* unused + root HUB */
68 #define USB_UNCONFIG_INDEX 0xFF /* internal use only */
69 #define USB_IFACE_INDEX_ANY 0xFF /* internal use only */
70 #define USB_START_ADDR 0 /* default USB device BUS address
71 * after USB bus reset */
72 #define USB_CONTROL_ENDPOINT 0 /* default control endpoint */
73
74 #define USB_FRAMES_PER_SECOND_FS 1000 /* full speed */
75 #define USB_FRAMES_PER_SECOND_HS 8000 /* high speed */
76
77 #define USB_FS_BYTES_PER_HS_UFRAME 188 /* bytes */
78 #define USB_HS_MICRO_FRAMES_MAX 8 /* units */
79
80 #define USB_ISOC_TIME_MAX 128 /* ms */
81
82 /*
83 * Minimum time a device needs to be powered down to go through a
84 * power cycle. These values are not in the USB specification.
85 */
86 #define USB_POWER_DOWN_TIME 200 /* ms */
87 #define USB_PORT_POWER_DOWN_TIME 100 /* ms */
88
89 /* Definition of software USB power modes */
90 #define USB_POWER_MODE_OFF 0 /* turn off device */
91 #define USB_POWER_MODE_ON 1 /* always on */
92 #define USB_POWER_MODE_SAVE 2 /* automatic suspend and resume */
93 #define USB_POWER_MODE_SUSPEND 3 /* force suspend */
94 #define USB_POWER_MODE_RESUME 4 /* force resume */
95
96 #if 0
97 /* These are the values from the USB specification. */
98 #define USB_PORT_RESET_DELAY 10 /* ms */
99 #define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
100 #define USB_PORT_RESET_RECOVERY 10 /* ms */
101 #define USB_PORT_POWERUP_DELAY 100 /* ms */
102 #define USB_PORT_RESUME_DELAY 20 /* ms */
103 #define USB_SET_ADDRESS_SETTLE 2 /* ms */
104 #define USB_RESUME_DELAY (20*5) /* ms */
105 #define USB_RESUME_WAIT 10 /* ms */
106 #define USB_RESUME_RECOVERY 10 /* ms */
107 #define USB_EXTRA_POWER_UP_TIME 0 /* ms */
108 #else
109 /* Allow for marginal and non-conforming devices. */
110 #define USB_PORT_RESET_DELAY 50 /* ms */
111 #define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
112 #define USB_PORT_RESET_RECOVERY 250 /* ms */
113 #define USB_PORT_POWERUP_DELAY 300 /* ms */
114 #define USB_PORT_RESUME_DELAY (20*2) /* ms */
115 #define USB_SET_ADDRESS_SETTLE 10 /* ms */
116 #define USB_RESUME_DELAY (50*5) /* ms */
117 #define USB_RESUME_WAIT 50 /* ms */
118 #define USB_RESUME_RECOVERY 50 /* ms */
119 #define USB_EXTRA_POWER_UP_TIME 20 /* ms */
120 #endif
121
122 #define USB_MIN_POWER 100 /* mA */
123 #define USB_MAX_POWER 500 /* mA */
124
125 #define USB_BUS_RESET_DELAY 100 /* ms */
126
127 /*
128 * USB record layout in memory:
129 *
130 * - USB config 0
131 * - USB interfaces
132 * - USB alternative interfaces
133 * - USB endpoints
134 *
135 * - USB config 1
136 * - USB interfaces
137 * - USB alternative interfaces
138 * - USB endpoints
139 */
140
141 /* Declaration of USB records */
142
143 struct usb_device_request {
144 uByte bmRequestType;
145 uByte bRequest;
146 uWord wValue;
147 uWord wIndex;
148 uWord wLength;
149 } __packed;
150 typedef struct usb_device_request usb_device_request_t;
151
152 #define UT_WRITE 0x00
153 #define UT_READ 0x80
154 #define UT_STANDARD 0x00
155 #define UT_CLASS 0x20
156 #define UT_VENDOR 0x40
157 #define UT_DEVICE 0x00
158 #define UT_INTERFACE 0x01
159 #define UT_ENDPOINT 0x02
160 #define UT_OTHER 0x03
161
162 #define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
163 #define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
164 #define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
165 #define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
166 #define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
167 #define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
168 #define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
169 #define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
170 #define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
171 #define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
172 #define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
173 #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
174 #define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
175 #define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
176 #define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
177 #define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
178 #define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
179 #define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
180 #define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
181 #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
182 #define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
183 #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
184
185 /* Requests */
186 #define UR_GET_STATUS 0x00
187 #define UR_CLEAR_FEATURE 0x01
188 #define UR_SET_FEATURE 0x03
189 #define UR_SET_ADDRESS 0x05
190 #define UR_GET_DESCRIPTOR 0x06
191 #define UDESC_DEVICE 0x01
192 #define UDESC_CONFIG 0x02
193 #define UDESC_STRING 0x03
194 #define USB_LANGUAGE_TABLE 0x00 /* language ID string index */
195 #define UDESC_INTERFACE 0x04
196 #define UDESC_ENDPOINT 0x05
197 #define UDESC_DEVICE_QUALIFIER 0x06
198 #define UDESC_OTHER_SPEED_CONFIGURATION 0x07
199 #define UDESC_INTERFACE_POWER 0x08
200 #define UDESC_OTG 0x09
201 #define UDESC_DEBUG 0x0A
202 #define UDESC_IFACE_ASSOC 0x0B /* interface association */
203 #define UDESC_BOS 0x0F /* binary object store */
204 #define UDESC_DEVICE_CAPABILITY 0x10
205 #define UDESC_CS_DEVICE 0x21 /* class specific */
206 #define UDESC_CS_CONFIG 0x22
207 #define UDESC_CS_STRING 0x23
208 #define UDESC_CS_INTERFACE 0x24
209 #define UDESC_CS_ENDPOINT 0x25
210 #define UDESC_HUB 0x29
211 #define UDESC_ENDPOINT_SS_COMP 0x30 /* super speed */
212 #define UR_SET_DESCRIPTOR 0x07
213 #define UR_GET_CONFIG 0x08
214 #define UR_SET_CONFIG 0x09
215 #define UR_GET_INTERFACE 0x0a
216 #define UR_SET_INTERFACE 0x0b
217 #define UR_SYNCH_FRAME 0x0c
218 #define UR_SET_SEL 0x30
219 #define UR_ISOCH_DELAY 0x31
220
221 /* HUB specific request */
222 #define UR_GET_BUS_STATE 0x02
223 #define UR_CLEAR_TT_BUFFER 0x08
224 #define UR_RESET_TT 0x09
225 #define UR_GET_TT_STATE 0x0a
226 #define UR_STOP_TT 0x0b
227 #define UR_SET_HUB_DEPTH 0x0c
228 #define UR_GET_PORT_ERR_COUNT 0x0d
229
230 /* Feature numbers */
231 #define UF_ENDPOINT_HALT 0
232 #define UF_DEVICE_REMOTE_WAKEUP 1
233 #define UF_TEST_MODE 2
234 #define UF_U1_ENABLE 0x30
235 #define UF_U2_ENABLE 0x31
236 #define UF_LTM_ENABLE 0x32
237
238 /* HUB specific features */
239 #define UHF_C_HUB_LOCAL_POWER 0
240 #define UHF_C_HUB_OVER_CURRENT 1
241 #define UHF_PORT_CONNECTION 0
242 #define UHF_PORT_ENABLE 1
243 #define UHF_PORT_SUSPEND 2
244 #define UHF_PORT_OVER_CURRENT 3
245 #define UHF_PORT_RESET 4
246 #define UHF_PORT_LINK_STATE 5
247 #define UHF_PORT_POWER 8
248 #define UHF_PORT_LOW_SPEED 9
249 #define UHF_C_PORT_CONNECTION 16
250 #define UHF_C_PORT_ENABLE 17
251 #define UHF_C_PORT_SUSPEND 18
252 #define UHF_C_PORT_OVER_CURRENT 19
253 #define UHF_C_PORT_RESET 20
254 #define UHF_PORT_TEST 21
255 #define UHF_PORT_INDICATOR 22
256
257 /* SuperSpeed HUB specific features */
258 #define UHF_PORT_U1_TIMEOUT 23
259 #define UHF_PORT_U2_TIMEOUT 24
260 #define UHF_C_PORT_LINK_STATE 25
261 #define UHF_C_PORT_CONFIG_ERROR 26
262 #define UHF_PORT_REMOTE_WAKE_MASK 27
263 #define UHF_BH_PORT_RESET 28
264 #define UHF_C_BH_PORT_RESET 29
265 #define UHF_FORCE_LINKPM_ACCEPT 30
266
267 struct usb_descriptor {
268 uByte bLength;
269 uByte bDescriptorType;
270 uByte bDescriptorSubtype;
271 } __packed;
272 typedef struct usb_descriptor usb_descriptor_t;
273
274 struct usb_device_descriptor {
275 uByte bLength;
276 uByte bDescriptorType;
277 uWord bcdUSB;
278 #define UD_USB_2_0 0x0200
279 #define UD_USB_3_0 0x0300
280 #define UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02)
281 #define UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03)
282 uByte bDeviceClass;
283 uByte bDeviceSubClass;
284 uByte bDeviceProtocol;
285 uByte bMaxPacketSize;
286 /* The fields below are not part of the initial descriptor. */
287 uWord idVendor;
288 uWord idProduct;
289 uWord bcdDevice;
290 uByte iManufacturer;
291 uByte iProduct;
292 uByte iSerialNumber;
293 uByte bNumConfigurations;
294 } __packed;
295 typedef struct usb_device_descriptor usb_device_descriptor_t;
296
297 /* Binary Device Object Store (BOS) */
298 struct usb_bos_descriptor {
299 uByte bLength;
300 uByte bDescriptorType;
301 uWord wTotalLength;
302 uByte bNumDeviceCaps;
303 } __packed;
304 typedef struct usb_bos_descriptor usb_bos_descriptor_t;
305
306 /* Binary Device Object Store Capability */
307 struct usb_bos_cap_descriptor {
308 uByte bLength;
309 uByte bDescriptorType;
310 uByte bDevCapabilityType;
311 #define USB_DEVCAP_RESERVED 0x00
312 #define USB_DEVCAP_WUSB 0x01
313 #define USB_DEVCAP_USB2EXT 0x02
314 #define USB_DEVCAP_SUPER_SPEED 0x03
315 #define USB_DEVCAP_CONTAINER_ID 0x04
316 /* data ... */
317 } __packed;
318 typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
319
320 struct usb_devcap_usb2ext_descriptor {
321 uByte bLength;
322 uByte bDescriptorType;
323 uByte bDevCapabilityType;
324 uByte bmAttributes;
325 #define USB_V2EXT_LPM 0x02
326 } __packed;
327 typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
328
329 struct usb_devcap_ss_descriptor {
330 uByte bLength;
331 uByte bDescriptorType;
332 uByte bDevCapabilityType;
333 uByte bmAttributes;
334 uWord wSpeedsSupported;
335 uByte bFunctionaltySupport;
336 uByte bU1DevExitLat;
337 uByte bU2DevExitLat;
338 } __packed;
339 typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
340
341 struct usb_devcap_container_id_descriptor {
342 uByte bLength;
343 uByte bDescriptorType;
344 uByte bDevCapabilityType;
345 uByte bReserved;
346 uByte ContainerID;
347 } __packed;
348 typedef struct usb_devcap_container_id_descriptor
349 usb_devcap_container_id_descriptor_t;
350
351 /* Device class codes */
352 #define UDCLASS_IN_INTERFACE 0x00
353 #define UDCLASS_COMM 0x02
354 #define UDCLASS_HUB 0x09
355 #define UDSUBCLASS_HUB 0x00
356 #define UDPROTO_FSHUB 0x00
357 #define UDPROTO_HSHUBSTT 0x01
358 #define UDPROTO_HSHUBMTT 0x02
359 #define UDCLASS_DIAGNOSTIC 0xdc
360 #define UDCLASS_WIRELESS 0xe0
361 #define UDSUBCLASS_RF 0x01
362 #define UDPROTO_BLUETOOTH 0x01
363 #define UDCLASS_VENDOR 0xff
364
365 struct usb_config_descriptor {
366 uByte bLength;
367 uByte bDescriptorType;
368 uWord wTotalLength;
369 uByte bNumInterface;
370 uByte bConfigurationValue;
371 #define USB_UNCONFIG_NO 0
372 uByte iConfiguration;
373 uByte bmAttributes;
374 #define UC_BUS_POWERED 0x80
375 #define UC_SELF_POWERED 0x40
376 #define UC_REMOTE_WAKEUP 0x20
377 uByte bMaxPower; /* max current in 2 mA units */
378 #define UC_POWER_FACTOR 2
379 } __packed;
380 typedef struct usb_config_descriptor usb_config_descriptor_t;
381
382 struct usb_interface_descriptor {
383 uByte bLength;
384 uByte bDescriptorType;
385 uByte bInterfaceNumber;
386 uByte bAlternateSetting;
387 uByte bNumEndpoints;
388 uByte bInterfaceClass;
389 uByte bInterfaceSubClass;
390 uByte bInterfaceProtocol;
391 uByte iInterface;
392 } __packed;
393 typedef struct usb_interface_descriptor usb_interface_descriptor_t;
394
395 struct usb_interface_assoc_descriptor {
396 uByte bLength;
397 uByte bDescriptorType;
398 uByte bFirstInterface;
399 uByte bInterfaceCount;
400 uByte bFunctionClass;
401 uByte bFunctionSubClass;
402 uByte bFunctionProtocol;
403 uByte iFunction;
404 } __packed;
405 typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
406
407 /* Interface class codes */
408 #define UICLASS_UNSPEC 0x00
409 #define UICLASS_AUDIO 0x01 /* audio */
410 #define UISUBCLASS_AUDIOCONTROL 1
411 #define UISUBCLASS_AUDIOSTREAM 2
412 #define UISUBCLASS_MIDISTREAM 3
413
414 #define UICLASS_CDC 0x02 /* communication */
415 #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
416 #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
417 #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
418 #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
419 #define UISUBCLASS_CAPI_CONTROLMODEL 5
420 #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
421 #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
422 #define UISUBCLASS_WIRELESS_HANDSET_CM 8
423 #define UISUBCLASS_DEVICE_MGMT 9
424 #define UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
425 #define UISUBCLASS_OBEX 11
426 #define UISUBCLASS_ETHERNET_EMULATION_MODEL 12
427 #define UISUBCLASS_NETWORK_CONTROL_MODEL 13
428
429 #define UIPROTO_CDC_AT 1
430
431 #define UICLASS_HID 0x03
432 #define UISUBCLASS_BOOT 1
433 #define UIPROTO_BOOT_KEYBOARD 1
434 #define UIPROTO_MOUSE 2
435
436 #define UICLASS_PHYSICAL 0x05
437 #define UICLASS_IMAGE 0x06
438 #define UISUBCLASS_SIC 1 /* still image class */
439 #define UICLASS_PRINTER 0x07
440 #define UISUBCLASS_PRINTER 1
441 #define UIPROTO_PRINTER_UNI 1
442 #define UIPROTO_PRINTER_BI 2
443 #define UIPROTO_PRINTER_1284 3
444
445 #define UICLASS_MASS 0x08
446 #define UISUBCLASS_RBC 1
447 #define UISUBCLASS_SFF8020I 2
448 #define UISUBCLASS_QIC157 3
449 #define UISUBCLASS_UFI 4
450 #define UISUBCLASS_SFF8070I 5
451 #define UISUBCLASS_SCSI 6
452 #define UIPROTO_MASS_CBI_I 0
453 #define UIPROTO_MASS_CBI 1
454 #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
455 #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
456
457 #define UICLASS_HUB 0x09
458 #define UISUBCLASS_HUB 0
459 #define UIPROTO_FSHUB 0
460 #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
461 #define UIPROTO_HSHUBMTT 1
462
463 #define UICLASS_CDC_DATA 0x0a
464 #define UISUBCLASS_DATA 0x00
465 #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
466 #define UIPROTO_DATA_HDLC 0x31 /* HDLC */
467 #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
468 #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
469 #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
470 #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
471 #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
472 #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
473 #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
474 #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
475 #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
476 #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc. */
477 #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
478 #define UIPROTO_DATA_NCM 0x01 /* Network Control Model */
479
480 #define UICLASS_SMARTCARD 0x0b
481 #define UICLASS_FIRM_UPD 0x0c
482 #define UICLASS_SECURITY 0x0d
483 #define UICLASS_DIAGNOSTIC 0xdc
484 #define UICLASS_WIRELESS 0xe0
485 #define UISUBCLASS_RF 0x01
486 #define UIPROTO_BLUETOOTH 0x01
487
488 #define UICLASS_IAD 0xEF /* Interface Association Descriptor */
489
490 #define UICLASS_APPL_SPEC 0xfe
491 #define UISUBCLASS_FIRMWARE_DOWNLOAD 1
492 #define UISUBCLASS_IRDA 2
493 #define UIPROTO_IRDA 0
494
495 #define UICLASS_VENDOR 0xff
496 #define UISUBCLASS_XBOX360_CONTROLLER 0x5d
497 #define UIPROTO_XBOX360_GAMEPAD 0x01
498
499 struct usb_endpoint_descriptor {
500 uByte bLength;
501 uByte bDescriptorType;
502 uByte bEndpointAddress;
503 #define UE_GET_DIR(a) ((a) & 0x80)
504 #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
505 #define UE_DIR_IN 0x80 /* IN-token endpoint, fixed */
506 #define UE_DIR_OUT 0x00 /* OUT-token endpoint, fixed */
507 #define UE_DIR_RX 0xfd /* for internal use only! */
508 #define UE_DIR_TX 0xfe /* for internal use only! */
509 #define UE_DIR_ANY 0xff /* for internal use only! */
510 #define UE_ADDR 0x0f
511 #define UE_ADDR_ANY 0xff /* for internal use only! */
512 #define UE_GET_ADDR(a) ((a) & UE_ADDR)
513 uByte bmAttributes;
514 #define UE_XFERTYPE 0x03
515 #define UE_CONTROL 0x00
516 #define UE_ISOCHRONOUS 0x01
517 #define UE_BULK 0x02
518 #define UE_INTERRUPT 0x03
519 #define UE_BULK_INTR 0xfe /* for internal use only! */
520 #define UE_TYPE_ANY 0xff /* for internal use only! */
521 #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
522 #define UE_ISO_TYPE 0x0c
523 #define UE_ISO_ASYNC 0x04
524 #define UE_ISO_ADAPT 0x08
525 #define UE_ISO_SYNC 0x0c
526 #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
527 uWord wMaxPacketSize;
528 #define UE_ZERO_MPS 0xFFFF /* for internal use only */
529 uByte bInterval;
530 } __packed;
531 typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
532
533 struct usb_endpoint_ss_comp_descriptor {
534 uByte bLength;
535 uByte bDescriptorType;
536 uWord bMaxBurst;
537 uByte bmAttributes;
538 uWord wBytesPerInterval;
539 } __packed;
540 typedef struct usb_endpoint_ss_comp_descriptor
541 usb_endpoint_ss_comp_descriptor_t;
542
543 struct usb_string_descriptor {
544 uByte bLength;
545 uByte bDescriptorType;
546 uWord bString[126];
547 uByte bUnused;
548 } __packed;
549 typedef struct usb_string_descriptor usb_string_descriptor_t;
550
551 #define USB_MAKE_STRING_DESC(m,name) \
552 struct name { \
553 uByte bLength; \
554 uByte bDescriptorType; \
555 uByte bData[sizeof((uint8_t []){m})]; \
556 } __packed; \
557 static const struct name name = { \
558 .bLength = sizeof(struct name), \
559 .bDescriptorType = UDESC_STRING, \
560 .bData = { m }, \
561 }
562
563 struct usb_hub_descriptor {
564 uByte bDescLength;
565 uByte bDescriptorType;
566 uByte bNbrPorts;
567 uWord wHubCharacteristics;
568 #define UHD_PWR 0x0003
569 #define UHD_PWR_GANGED 0x0000
570 #define UHD_PWR_INDIVIDUAL 0x0001
571 #define UHD_PWR_NO_SWITCH 0x0002
572 #define UHD_COMPOUND 0x0004
573 #define UHD_OC 0x0018
574 #define UHD_OC_GLOBAL 0x0000
575 #define UHD_OC_INDIVIDUAL 0x0008
576 #define UHD_OC_NONE 0x0010
577 #define UHD_TT_THINK 0x0060
578 #define UHD_TT_THINK_8 0x0000
579 #define UHD_TT_THINK_16 0x0020
580 #define UHD_TT_THINK_24 0x0040
581 #define UHD_TT_THINK_32 0x0060
582 #define UHD_PORT_IND 0x0080
583 uByte bPwrOn2PwrGood; /* delay in 2 ms units */
584 #define UHD_PWRON_FACTOR 2
585 uByte bHubContrCurrent;
586 uByte DeviceRemovable[32]; /* max 255 ports */
587 #define UHD_NOT_REMOV(desc, i) \
588 (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
589 uByte PortPowerCtrlMask[1]; /* deprecated */
590 } __packed;
591 typedef struct usb_hub_descriptor usb_hub_descriptor_t;
592
593 struct usb_hub_ss_descriptor {
594 uByte bDescLength;
595 uByte bDescriptorType;
596 uByte bNbrPorts; /* max 15 */
597 uWord wHubCharacteristics;
598 uByte bPwrOn2PwrGood; /* delay in 2 ms units */
599 uByte bHubContrCurrent;
600 uByte bHubHdrDecLat;
601 uWord wHubDelay;
602 uByte DeviceRemovable[2]; /* max 15 ports */
603 } __packed;
604 typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
605
606 /* minimum HUB descriptor (8-ports maximum) */
607 struct usb_hub_descriptor_min {
608 uByte bDescLength;
609 uByte bDescriptorType;
610 uByte bNbrPorts;
611 uWord wHubCharacteristics;
612 uByte bPwrOn2PwrGood;
613 uByte bHubContrCurrent;
614 uByte DeviceRemovable[1];
615 uByte PortPowerCtrlMask[1];
616 } __packed;
617 typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
618
619 struct usb_device_qualifier {
620 uByte bLength;
621 uByte bDescriptorType;
622 uWord bcdUSB;
623 uByte bDeviceClass;
624 uByte bDeviceSubClass;
625 uByte bDeviceProtocol;
626 uByte bMaxPacketSize0;
627 uByte bNumConfigurations;
628 uByte bReserved;
629 } __packed;
630 typedef struct usb_device_qualifier usb_device_qualifier_t;
631
632 struct usb_otg_descriptor {
633 uByte bLength;
634 uByte bDescriptorType;
635 uByte bmAttributes;
636 #define UOTG_SRP 0x01
637 #define UOTG_HNP 0x02
638 } __packed;
639 typedef struct usb_otg_descriptor usb_otg_descriptor_t;
640
641 /* OTG feature selectors */
642 #define UOTG_B_HNP_ENABLE 3
643 #define UOTG_A_HNP_SUPPORT 4
644 #define UOTG_A_ALT_HNP_SUPPORT 5
645
646 struct usb_status {
647 uWord wStatus;
648 /* Device status flags */
649 #define UDS_SELF_POWERED 0x0001
650 #define UDS_REMOTE_WAKEUP 0x0002
651 /* Endpoint status flags */
652 #define UES_HALT 0x0001
653 } __packed;
654 typedef struct usb_status usb_status_t;
655
656 struct usb_hub_status {
657 uWord wHubStatus;
658 #define UHS_LOCAL_POWER 0x0001
659 #define UHS_OVER_CURRENT 0x0002
660 uWord wHubChange;
661 } __packed;
662 typedef struct usb_hub_status usb_hub_status_t;
663
664 struct usb_port_status {
665 uWord wPortStatus;
666 #define UPS_CURRENT_CONNECT_STATUS 0x0001
667 #define UPS_PORT_ENABLED 0x0002
668 #define UPS_SUSPEND 0x0004
669 #define UPS_OVERCURRENT_INDICATOR 0x0008
670 #define UPS_RESET 0x0010
671 #define UPS_PORT_POWER 0x0100
672 #define UPS_LOW_SPEED 0x0200
673 #define UPS_HIGH_SPEED 0x0400
674 #define UPS_PORT_TEST 0x0800
675 #define UPS_PORT_INDICATOR 0x1000
676 #define UPS_PORT_MODE_DEVICE 0x8000 /* currently FreeBSD specific */
677 uWord wPortChange;
678 #define UPS_C_CONNECT_STATUS 0x0001
679 #define UPS_C_PORT_ENABLED 0x0002
680 #define UPS_C_SUSPEND 0x0004
681 #define UPS_C_OVERCURRENT_INDICATOR 0x0008
682 #define UPS_C_PORT_RESET 0x0010
683 } __packed;
684 typedef struct usb_port_status usb_port_status_t;
685
686 /*
687 * The "USB_SPEED" macros defines all the supported USB speeds.
688 */
689 enum usb_dev_speed {
690 USB_SPEED_VARIABLE,
691 USB_SPEED_LOW,
692 USB_SPEED_FULL,
693 USB_SPEED_HIGH,
694 USB_SPEED_SUPER,
695 };
696 #define USB_SPEED_MAX (USB_SPEED_SUPER+1)
697
698 /*
699 * The "USB_REV" macros defines all the supported USB revisions.
700 */
701 enum usb_revision {
702 USB_REV_UNKNOWN,
703 USB_REV_PRE_1_0,
704 USB_REV_1_0,
705 USB_REV_1_1,
706 USB_REV_2_0,
707 USB_REV_2_5,
708 USB_REV_3_0
709 };
710 #define USB_REV_MAX (USB_REV_3_0+1)
711
712 /*
713 * Supported host contoller modes.
714 */
715 enum usb_hc_mode {
716 USB_MODE_HOST, /* initiates transfers */
717 USB_MODE_DEVICE, /* bus transfer target */
718 USB_MODE_DUAL /* can be host or device */
719 };
720 #define USB_MODE_MAX (USB_MODE_DUAL+1)
721
722 /*
723 * The "USB_MODE" macros defines all the supported device states.
724 */
725 enum usb_dev_state {
726 USB_STATE_DETACHED,
727 USB_STATE_ATTACHED,
728 USB_STATE_POWERED,
729 USB_STATE_ADDRESSED,
730 USB_STATE_CONFIGURED,
731 };
732 #define USB_STATE_MAX (USB_STATE_CONFIGURED+1)
733 #endif /* _USB_STANDARD_H_ */
Cache object: 3526cfc8da3fd29165b7a3f27c7bd4ba
|