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