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