usb.h revision 1.101 1 /* $NetBSD: usb.h,v 1.101 2013/03/21 12:47:16 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 (at) 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 DWC_OTG_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 UR_SET_DESCRIPTOR 0x07
249 #define UR_GET_CONFIG 0x08
250 #define UR_SET_CONFIG 0x09
251 #define UR_GET_INTERFACE 0x0a
252 #define UR_SET_INTERFACE 0x0b
253 #define UR_SYNCH_FRAME 0x0c
254
255 /*
256 * Feature selectors. USB 2.0 spec, table 9-6 and OTG and EH suppliment,
257 * table 6-2
258 */
259 #define UF_ENDPOINT_HALT 0
260 #define UF_DEVICE_REMOTE_WAKEUP 1
261 #define UF_TEST_MODE 2
262 #define UF_DEVICE_B_HNP_ENABLE 3
263 #define UF_DEVICE_A_HNP_SUPPORT 4
264 #define UF_DEVICE_A_ALT_HNP_SUPPORT 5
265
266 #define USB_MAX_IPACKET 8 /* maximum size of the initial packet */
267
268 #define USB_2_MAX_CTRL_PACKET 64
269 #define USB_2_MAX_BULK_PACKET 512
270
271 typedef struct {
272 uByte bLength;
273 uByte bDescriptorType;
274 } UPACKED usb_descriptor_t;
275
276 typedef struct {
277 uByte bLength;
278 uByte bDescriptorType;
279 uWord bcdUSB;
280 #define UD_USB_2_0 0x0200
281 #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
282 uByte bDeviceClass;
283 uByte bDeviceSubClass;
284 uByte bDeviceProtocol;
285 uByte bMaxPacketSize;
286 /* The fields below are not part of the initial descriptor. */
287 uWord idVendor;
288 uWord idProduct;
289 uWord bcdDevice;
290 uByte iManufacturer;
291 uByte iProduct;
292 uByte iSerialNumber;
293 uByte bNumConfigurations;
294 } UPACKED usb_device_descriptor_t;
295 #define USB_DEVICE_DESCRIPTOR_SIZE 18
296
297 typedef struct {
298 uByte bLength;
299 uByte bDescriptorType;
300 uWord wTotalLength;
301 uByte bNumInterface;
302 uByte bConfigurationValue;
303 uByte iConfiguration;
304 uByte bmAttributes;
305 #define UC_ATTR_MBO 0x80
306 #define UC_SELF_POWERED 0x40
307 #define UC_REMOTE_WAKEUP 0x20
308 uByte bMaxPower; /* max current in 2 mA units */
309 #define UC_POWER_FACTOR 2
310 } UPACKED usb_config_descriptor_t;
311 #define USB_CONFIG_DESCRIPTOR_SIZE 9
312
313 typedef struct {
314 uByte bLength;
315 uByte bDescriptorType;
316 uByte bInterfaceNumber;
317 uByte bAlternateSetting;
318 uByte bNumEndpoints;
319 uByte bInterfaceClass;
320 uByte bInterfaceSubClass;
321 uByte bInterfaceProtocol;
322 uByte iInterface;
323 } UPACKED usb_interface_descriptor_t;
324 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
325
326 typedef struct {
327 uByte bLength;
328 uByte bDescriptorType;
329 uByte bFirstInterface;
330 uByte bInterfaceCount;
331 uByte bFunctionClass;
332 uByte bFunctionSubClass;
333 uByte bFunctionProtocol;
334 uByte iFunction;
335 } UPACKED usb_interface_assoc_descriptor_t;
336 #define USB_INTERFACE_ASSOC_DESCRIPTOR_SIZE 8
337
338 typedef struct {
339 uByte bLength;
340 uByte bDescriptorType;
341 uByte bEndpointAddress;
342 #define UE_GET_DIR(a) ((a) & 0x80)
343 #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
344 #define UE_DIR_IN 0x80
345 #define UE_DIR_OUT 0x00
346 #define UE_ADDR 0x0f
347 #define UE_GET_ADDR(a) ((a) & UE_ADDR)
348 uByte bmAttributes;
349 #define UE_XFERTYPE 0x03
350 #define UE_CONTROL 0x00
351 #define UE_ISOCHRONOUS 0x01
352 #define UE_BULK 0x02
353 #define UE_INTERRUPT 0x03
354 #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
355 #define UE_ISO_TYPE 0x0c
356 #define UE_ISO_ASYNC 0x04
357 #define UE_ISO_ADAPT 0x08
358 #define UE_ISO_SYNC 0x0c
359 #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
360 uWord wMaxPacketSize;
361 #define UE_GET_TRANS(a) (((a) >> 11) & 0x3)
362 #define UE_GET_SIZE(a) ((a) & 0x7ff)
363 uByte bInterval;
364 } UPACKED usb_endpoint_descriptor_t;
365 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
366
367 typedef struct {
368 uByte bLength;
369 uByte bDescriptorType;
370 uWord bString[126];
371 } UPACKED usb_string_descriptor_t;
372 #define USB_MAX_STRING_LEN 128
373 #define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
374 #define USB_MAX_ENCODED_STRING_LEN (USB_MAX_STRING_LEN * 3) /* UTF8 */
375
376 /* Hub specific request */
377 #define UR_GET_BUS_STATE 0x02
378 #define UR_CLEAR_TT_BUFFER 0x08
379 #define UR_RESET_TT 0x09
380 #define UR_GET_TT_STATE 0x0a
381 #define UR_STOP_TT 0x0b
382
383 /*
384 * Hub features from USB 2.0 spec, table 11-17 and updated by the
385 * LPM ECN table 4-7.
386 */
387 #define UHF_C_HUB_LOCAL_POWER 0
388 #define UHF_C_HUB_OVER_CURRENT 1
389 #define UHF_PORT_CONNECTION 0
390 #define UHF_PORT_ENABLE 1
391 #define UHF_PORT_SUSPEND 2
392 #define UHF_PORT_OVER_CURRENT 3
393 #define UHF_PORT_RESET 4
394 #define UHF_PORT_POWER 8
395 #define UHF_PORT_LOW_SPEED 9
396 #define UHF_PORT_L1 10
397 #define UHF_C_PORT_CONNECTION 16
398 #define UHF_C_PORT_ENABLE 17
399 #define UHF_C_PORT_SUSPEND 18
400 #define UHF_C_PORT_OVER_CURRENT 19
401 #define UHF_C_PORT_RESET 20
402 #define UHF_PORT_TEST 21
403 #define UHF_PORT_INDICATOR 22
404 #define UHF_C_PORT_L1 23
405
406 typedef struct {
407 uByte bDescLength;
408 uByte bDescriptorType;
409 uByte bNbrPorts;
410 uWord wHubCharacteristics;
411 #define UHD_PWR 0x0003
412 #define UHD_PWR_GANGED 0x0000
413 #define UHD_PWR_INDIVIDUAL 0x0001
414 #define UHD_PWR_NO_SWITCH 0x0002
415 #define UHD_COMPOUND 0x0004
416 #define UHD_OC 0x0018
417 #define UHD_OC_GLOBAL 0x0000
418 #define UHD_OC_INDIVIDUAL 0x0008
419 #define UHD_OC_NONE 0x0010
420 #define UHD_TT_THINK 0x0060
421 #define UHD_TT_THINK_8 0x0000
422 #define UHD_TT_THINK_16 0x0020
423 #define UHD_TT_THINK_24 0x0040
424 #define UHD_TT_THINK_32 0x0060
425 #define UHD_PORT_IND 0x0080
426 uByte bPwrOn2PwrGood; /* delay in 2 ms units */
427 #define UHD_PWRON_FACTOR 2
428 uByte bHubContrCurrent;
429 uByte DeviceRemovable[32]; /* max 255 ports */
430 #define UHD_NOT_REMOV(desc, i) \
431 (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
432 /* deprecated */ uByte PortPowerCtrlMask[1];
433 } UPACKED usb_hub_descriptor_t;
434 #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
435
436 typedef struct {
437 uByte bLength;
438 uByte bDescriptorType;
439 uWord bcdUSB;
440 uByte bDeviceClass;
441 uByte bDeviceSubClass;
442 uByte bDeviceProtocol;
443 uByte bMaxPacketSize0;
444 uByte bNumConfigurations;
445 uByte bReserved;
446 } UPACKED usb_device_qualifier_t;
447 #define USB_DEVICE_QUALIFIER_SIZE 10
448
449 typedef struct {
450 uByte bLength;
451 uByte bDescriptorType;
452 uByte bmAttributes;
453 #define UOTG_SRP 0x01
454 #define UOTG_HNP 0x02
455 } UPACKED usb_otg_descriptor_t;
456
457 /* OTG feature selectors */
458 #define UOTG_B_HNP_ENABLE 3
459 #define UOTG_A_HNP_SUPPORT 4
460 #define UOTG_A_ALT_HNP_SUPPORT 5
461
462 typedef struct {
463 uByte bLength;
464 uByte bDescriptorType;
465 uByte bDebugInEndpoint;
466 uByte bDebugOutEndpoint;
467 } UPACKED usb_debug_descriptor_t;
468
469 typedef struct {
470 uWord wStatus;
471 /* Device status flags */
472 #define UDS_SELF_POWERED 0x0001
473 #define UDS_REMOTE_WAKEUP 0x0002
474 /* Endpoint status flags */
475 #define UES_HALT 0x0001
476 } UPACKED usb_status_t;
477
478 typedef struct {
479 uWord wHubStatus;
480 #define UHS_LOCAL_POWER 0x0001
481 #define UHS_OVER_CURRENT 0x0002
482 uWord wHubChange;
483 } UPACKED usb_hub_status_t;
484
485 typedef struct {
486 uWord wPortStatus;
487 #define UPS_CURRENT_CONNECT_STATUS 0x0001
488 #define UPS_PORT_ENABLED 0x0002
489 #define UPS_SUSPEND 0x0004
490 #define UPS_OVERCURRENT_INDICATOR 0x0008
491 #define UPS_RESET 0x0010
492 #define UPS_PORT_POWER 0x0100
493 #define UPS_FULL_SPEED 0x0000 /* for completeness */
494 #define UPS_LOW_SPEED 0x0200
495 #define UPS_HIGH_SPEED 0x0400
496 #define UPS_PORT_TEST 0x0800
497 #define UPS_PORT_INDICATOR 0x1000
498 uWord wPortChange;
499 #define UPS_C_CONNECT_STATUS 0x0001
500 #define UPS_C_PORT_ENABLED 0x0002
501 #define UPS_C_SUSPEND 0x0004
502 #define UPS_C_OVERCURRENT_INDICATOR 0x0008
503 #define UPS_C_PORT_RESET 0x0010
504 } UPACKED usb_port_status_t;
505
506 /* Device class codes */
507 #define UDCLASS_IN_INTERFACE 0x00
508 #define UDCLASS_COMM 0x02
509 #define UDCLASS_HUB 0x09
510 #define UDSUBCLASS_HUB 0x00
511 #define UDPROTO_FSHUB 0x00
512 #define UDPROTO_HSHUBSTT 0x01
513 #define UDPROTO_HSHUBMTT 0x02
514 #define UDCLASS_DIAGNOSTIC 0xdc
515 #define UDCLASS_WIRELESS 0xe0
516 #define UDSUBCLASS_RF 0x01
517 #define UDPROTO_BLUETOOTH 0x01
518 #define UDCLASS_VENDOR 0xff
519
520 /* Interface class codes */
521 #define UICLASS_UNSPEC 0x00
522
523 #define UICLASS_AUDIO 0x01
524 #define UISUBCLASS_AUDIOCONTROL 1
525 #define UISUBCLASS_AUDIOSTREAM 2
526 #define UISUBCLASS_MIDISTREAM 3
527
528 #define UICLASS_VIDEO 0x0E
529 #define UISUBCLASS_VIDEOCONTROL 1
530 #define UISUBCLASS_VIDEOSTREAMING 2
531 #define UISUBCLASS_VIDEOCOLLECTION 3
532
533 #define UICLASS_CDC 0x02 /* communication */
534 #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
535 #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
536 #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
537 #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
538 #define UISUBCLASS_CAPI_CONTROLMODEL 5
539 #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
540 #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
541 #define UIPROTO_CDC_NOCLASS 0 /* no class specific
542 protocol required */
543 #define UIPROTO_CDC_AT 1
544
545 #define UICLASS_HID 0x03
546 #define UISUBCLASS_BOOT 1
547 #define UIPROTO_BOOT_KEYBOARD 1
548 #define UIPROTO_MOUSE 2
549
550 #define UICLASS_PHYSICAL 0x05
551
552 #define UICLASS_IMAGE 0x06
553
554 #define UICLASS_PRINTER 0x07
555 #define UISUBCLASS_PRINTER 1
556 #define UIPROTO_PRINTER_UNI 1
557 #define UIPROTO_PRINTER_BI 2
558 #define UIPROTO_PRINTER_1284 3
559
560 #define UICLASS_MASS 0x08
561 #define UISUBCLASS_RBC 1
562 #define UISUBCLASS_SFF8020I 2
563 #define UISUBCLASS_QIC157 3
564 #define UISUBCLASS_UFI 4
565 #define UISUBCLASS_SFF8070I 5
566 #define UISUBCLASS_SCSI 6
567 #define UIPROTO_MASS_CBI_I 0
568 #define UIPROTO_MASS_CBI 1
569 #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
570 #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
571
572 #define UICLASS_HUB 0x09
573 #define UISUBCLASS_HUB 0
574 #define UIPROTO_FSHUB 0
575 #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
576 #define UIPROTO_HSHUBMTT 1
577
578 #define UICLASS_CDC_DATA 0x0a
579 #define UISUBCLASS_DATA 0
580 #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
581 #define UIPROTO_DATA_HDLC 0x31 /* HDLC */
582 #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
583 #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
584 #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
585 #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
586 #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
587 #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
588 #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
589 #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
590 #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
591 #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
592 #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
593
594 #define UICLASS_SMARTCARD 0x0b
595
596 /*#define UICLASS_FIRM_UPD 0x0c*/
597
598 #define UICLASS_SECURITY 0x0d
599
600 #define UICLASS_DIAGNOSTIC 0xdc
601
602 #define UICLASS_WIRELESS 0xe0
603 #define UISUBCLASS_RF 0x01
604 #define UIPROTO_BLUETOOTH 0x01
605 #define UIPROTO_RNDIS 0x03
606
607 #define UICLASS_APPL_SPEC 0xfe
608 #define UISUBCLASS_FIRMWARE_DOWNLOAD 1
609 #define UISUBCLASS_IRDA 2
610 #define UIPROTO_IRDA 0
611
612 #define UICLASS_VENDOR 0xff
613
614
615 #define USB_HUB_MAX_DEPTH 5
616
617 /*
618 * Minimum time a device needs to be powered down to go through
619 * a power cycle. XXX Are these time in the spec?
620 */
621 #define USB_POWER_DOWN_TIME 200 /* ms */
622 #define USB_PORT_POWER_DOWN_TIME 100 /* ms */
623
624 #if 0
625 /* These are the values from the spec. */
626 #define USB_PORT_RESET_DELAY 10 /* ms */
627 #define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
628 #define USB_PORT_RESET_RECOVERY 10 /* ms */
629 #define USB_PORT_POWERUP_DELAY 100 /* ms */
630 #define USB_SET_ADDRESS_SETTLE 2 /* ms */
631 #define USB_RESUME_DELAY (20*5) /* ms */
632 #define USB_RESUME_WAIT 10 /* ms */
633 #define USB_RESUME_RECOVERY 10 /* ms */
634 #define USB_EXTRA_POWER_UP_TIME 0 /* ms */
635 #else
636 /* Allow for marginal (i.e. non-conforming) devices. */
637 #define USB_PORT_RESET_DELAY 50 /* ms */
638 #define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
639 #define USB_PORT_RESET_RECOVERY 250 /* ms */
640 #define USB_PORT_POWERUP_DELAY 300 /* ms */
641 #define USB_SET_ADDRESS_SETTLE 10 /* ms */
642 #define USB_RESUME_DELAY (50*5) /* ms */
643 #define USB_RESUME_WAIT 50 /* ms */
644 #define USB_RESUME_RECOVERY 50 /* ms */
645 #define USB_EXTRA_POWER_UP_TIME 20 /* ms */
646 #endif
647
648 #define USB_MIN_POWER 100 /* mA */
649 #define USB_MAX_POWER 500 /* mA */
650
651 #define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
652
653
654 #define USB_UNCONFIG_NO 0
655 #define USB_UNCONFIG_INDEX (-1)
656
657
658 /* Packet IDs */
659 #define UPID_RESERVED 0xf0
660 #define UPID_OUT 0xe1
661 #define UPID_ACK 0xd2
662 #define UPID_DATA0 0xc3
663 #define UPID_PING 0xb4
664 #define UPID_SOF 0xa5
665 #define UPID_NYET 0x96
666 #define UPID_DATA2 0x87
667 #define UPID_SPLIT 0x78
668 #define UPID_IN 0x69
669 #define UPID_NAK 0x5a
670 #define UPID_DATA1 0x4b
671 #define UPID_ERR 0x3c
672 #define UPID_PREAMBLE 0x3c
673 #define UPID_SETUP 0x2d
674 #define UPID_STALL 0x1e
675 #define UPID_MDATA 0x0f
676
677
678 /*** ioctl() related stuff ***/
679
680 struct usb_ctl_request {
681 int ucr_addr;
682 usb_device_request_t ucr_request;
683 void *ucr_data;
684 int ucr_flags;
685 #define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
686 int ucr_actlen; /* actual length transferred */
687 };
688
689 struct usb_alt_interface {
690 int uai_config_index;
691 int uai_interface_index;
692 int uai_alt_no;
693 };
694
695 #define USB_CURRENT_CONFIG_INDEX (-1)
696 #define USB_CURRENT_ALT_INDEX (-1)
697
698 struct usb_config_desc {
699 int ucd_config_index;
700 usb_config_descriptor_t ucd_desc;
701 };
702
703 struct usb_interface_desc {
704 int uid_config_index;
705 int uid_interface_index;
706 int uid_alt_index;
707 usb_interface_descriptor_t uid_desc;
708 };
709
710 struct usb_endpoint_desc {
711 int ued_config_index;
712 int ued_interface_index;
713 int ued_alt_index;
714 int ued_endpoint_index;
715 usb_endpoint_descriptor_t ued_desc;
716 };
717
718 struct usb_full_desc {
719 int ufd_config_index;
720 u_int ufd_size;
721 u_char *ufd_data;
722 };
723
724 struct usb_string_desc {
725 int usd_string_index;
726 int usd_language_id;
727 usb_string_descriptor_t usd_desc;
728 };
729
730 struct usb_ctl_report_desc {
731 int ucrd_size;
732 u_char ucrd_data[1024]; /* filled data size will vary */
733 };
734
735 typedef struct { u_int32_t cookie; } usb_event_cookie_t;
736
737 #define USB_MAX_DEVNAMES 4
738 #define USB_MAX_DEVNAMELEN 16
739 struct usb_device_info {
740 u_int8_t udi_bus;
741 u_int8_t udi_addr; /* device address */
742 usb_event_cookie_t udi_cookie;
743 char udi_product[USB_MAX_ENCODED_STRING_LEN];
744 char udi_vendor[USB_MAX_ENCODED_STRING_LEN];
745 char udi_release[8];
746 char udi_serial[USB_MAX_ENCODED_STRING_LEN];
747 u_int16_t udi_productNo;
748 u_int16_t udi_vendorNo;
749 u_int16_t udi_releaseNo;
750 u_int8_t udi_class;
751 u_int8_t udi_subclass;
752 u_int8_t udi_protocol;
753 u_int8_t udi_config;
754 u_int8_t udi_speed;
755 #define USB_SPEED_LOW 1
756 #define USB_SPEED_FULL 2
757 #define USB_SPEED_HIGH 3
758 int udi_power; /* power consumption in mA, 0 if selfpowered */
759 int udi_nports;
760 char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
761 u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
762 #define USB_PORT_ENABLED 0xff
763 #define USB_PORT_SUSPENDED 0xfe
764 #define USB_PORT_POWERED 0xfd
765 #define USB_PORT_DISABLED 0xfc
766 };
767
768 /* <=3.0 had this layout of the structure */
769 struct usb_device_info_old {
770 u_int8_t udi_bus;
771 u_int8_t udi_addr; /* device address */
772 usb_event_cookie_t udi_cookie;
773 char udi_product[USB_MAX_STRING_LEN];
774 char udi_vendor[USB_MAX_STRING_LEN];
775 char udi_release[8];
776 u_int16_t udi_productNo;
777 u_int16_t udi_vendorNo;
778 u_int16_t udi_releaseNo;
779 u_int8_t udi_class;
780 u_int8_t udi_subclass;
781 u_int8_t udi_protocol;
782 u_int8_t udi_config;
783 u_int8_t udi_speed;
784 int udi_power; /* power consumption in mA, 0 if selfpowered */
785 int udi_nports;
786 char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
787 u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
788 };
789
790 struct usb_ctl_report {
791 int ucr_report;
792 u_char ucr_data[1024]; /* filled data size will vary */
793 };
794
795 struct usb_device_stats {
796 u_long uds_requests[4]; /* indexed by transfer type UE_* */
797 };
798
799 struct usb_bulk_ra_wb_opt {
800 u_int ra_wb_buffer_size;
801 u_int ra_wb_request_size;
802 };
803
804 /* Events that can be read from /dev/usb */
805 struct usb_event {
806 int ue_type;
807 #define USB_EVENT_CTRLR_ATTACH 1
808 #define USB_EVENT_CTRLR_DETACH 2
809 #define USB_EVENT_DEVICE_ATTACH 3
810 #define USB_EVENT_DEVICE_DETACH 4
811 #define USB_EVENT_DRIVER_ATTACH 5
812 #define USB_EVENT_DRIVER_DETACH 6
813 #define USB_EVENT_IS_ATTACH(n) ((n) == USB_EVENT_CTRLR_ATTACH || (n) == USB_EVENT_DEVICE_ATTACH || (n) == USB_EVENT_DRIVER_ATTACH)
814 #define USB_EVENT_IS_DETACH(n) ((n) == USB_EVENT_CTRLR_DETACH || (n) == USB_EVENT_DEVICE_DETACH || (n) == USB_EVENT_DRIVER_DETACH)
815 struct timespec ue_time;
816 union {
817 struct {
818 int ue_bus;
819 } ue_ctrlr;
820 struct usb_device_info ue_device;
821 struct {
822 usb_event_cookie_t ue_cookie;
823 char ue_devname[16];
824 } ue_driver;
825 } u;
826 };
827
828 /* old <=3.0 compat event */
829 struct usb_event_old {
830 int ue_type;
831 struct timespec ue_time;
832 union {
833 struct {
834 int ue_bus;
835 } ue_ctrlr;
836 struct usb_device_info_old ue_device;
837 struct {
838 usb_event_cookie_t ue_cookie;
839 char ue_devname[16];
840 } ue_driver;
841 } u;
842 };
843
844
845 /* USB controller */
846 #define USB_REQUEST _IOWR('U', 1, struct usb_ctl_request)
847 #define USB_SETDEBUG _IOW ('U', 2, int)
848 #define USB_DISCOVER _IO ('U', 3)
849 #define USB_DEVICEINFO _IOWR('U', 4, struct usb_device_info)
850 #define USB_DEVICEINFO_OLD _IOWR('U', 4, struct usb_device_info_old)
851 #define USB_DEVICESTATS _IOR ('U', 5, struct usb_device_stats)
852
853 /* Generic HID device */
854 #define USB_GET_REPORT_DESC _IOR ('U', 21, struct usb_ctl_report_desc)
855 #define USB_SET_IMMED _IOW ('U', 22, int)
856 #define USB_GET_REPORT _IOWR('U', 23, struct usb_ctl_report)
857 #define USB_SET_REPORT _IOW ('U', 24, struct usb_ctl_report)
858 #define USB_GET_REPORT_ID _IOR ('U', 25, int)
859
860 /* Generic USB device */
861 #define USB_GET_CONFIG _IOR ('U', 100, int)
862 #define USB_SET_CONFIG _IOW ('U', 101, int)
863 #define USB_GET_ALTINTERFACE _IOWR('U', 102, struct usb_alt_interface)
864 #define USB_SET_ALTINTERFACE _IOWR('U', 103, struct usb_alt_interface)
865 #define USB_GET_NO_ALT _IOWR('U', 104, struct usb_alt_interface)
866 #define USB_GET_DEVICE_DESC _IOR ('U', 105, usb_device_descriptor_t)
867 #define USB_GET_CONFIG_DESC _IOWR('U', 106, struct usb_config_desc)
868 #define USB_GET_INTERFACE_DESC _IOWR('U', 107, struct usb_interface_desc)
869 #define USB_GET_ENDPOINT_DESC _IOWR('U', 108, struct usb_endpoint_desc)
870 #define USB_GET_FULL_DESC _IOWR('U', 109, struct usb_full_desc)
871 #define USB_GET_STRING_DESC _IOWR('U', 110, struct usb_string_desc)
872 #define USB_DO_REQUEST _IOWR('U', 111, struct usb_ctl_request)
873 #define USB_GET_DEVICEINFO _IOR ('U', 112, struct usb_device_info)
874 #define USB_GET_DEVICEINFO_OLD _IOR ('U', 112, struct usb_device_info_old)
875 #define USB_SET_SHORT_XFER _IOW ('U', 113, int)
876 #define USB_SET_TIMEOUT _IOW ('U', 114, int)
877 #define USB_SET_BULK_RA _IOW ('U', 115, int)
878 #define USB_SET_BULK_WB _IOW ('U', 116, int)
879 #define USB_SET_BULK_RA_OPT _IOW ('U', 117, struct usb_bulk_ra_wb_opt)
880 #define USB_SET_BULK_WB_OPT _IOW ('U', 118, struct usb_bulk_ra_wb_opt)
881
882 /* Modem device */
883 #define USB_GET_CM_OVER_DATA _IOR ('U', 130, int)
884 #define USB_SET_CM_OVER_DATA _IOW ('U', 131, int)
885
886 #endif /* _USB_H_ */
887