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