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