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