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