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