xref: /freebsd/sys/dev/usb/usb.h (revision 6990ffd8a95caaba6858ad44ff1b3157d1efba8f)
1 /*	$NetBSD: usb.h,v 1.38 1999/10/20 21:02:39 augustss Exp $	*/
2 /*	$FreeBSD$	*/
3 
4 /*
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Lennart Augustsson (lennart@augustsson.net) at
10  * Carlstedt Research & Technology.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *        This product includes software developed by the NetBSD
23  *        Foundation, Inc. and its contributors.
24  * 4. Neither the name of The NetBSD Foundation nor the names of its
25  *    contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 
42 #ifndef _USB_H_
43 #define _USB_H_
44 
45 #include <sys/types.h>
46 #include <sys/time.h>
47 
48 #if defined(__NetBSD__) || defined(__OpenBSD__)
49 #include <sys/ioctl.h>
50 
51 #if defined(_KERNEL)
52 #include <dev/usb/usb_port.h>
53 #endif /* _KERNEL */
54 
55 #elif defined(__FreeBSD__)
56 #if defined(_KERNEL)
57 #include <sys/malloc.h>
58 
59 MALLOC_DECLARE(M_USB);
60 MALLOC_DECLARE(M_USBDEV);
61 MALLOC_DECLARE(M_USBHC);
62 
63 #include <dev/usb/usb_port.h>
64 #endif /* _KERNEL */
65 #endif /* __FreeBSD__ */
66 
67 /* these three defines are used by usbd to autoload the usb kld */
68 #define USB_KLD		"usb"		/* name of usb module */
69 #define USB_UHUB	"usb/uhub"	/* root hub */
70 
71 #define USB_MAX_DEVICES 128
72 #define USB_START_ADDR 0
73 
74 #define USB_CONTROL_ENDPOINT 0
75 #define USB_MAX_ENDPOINTS 16
76 
77 #define USB_FRAMES_PER_SECOND 1000
78 
79 /*
80  * The USB records contain some unaligned little-endian word
81  * components.  The U[SG]ETW macros take care of both the alignment
82  * and endian problem and should always be used to access 16 bit
83  * values.
84  */
85 typedef u_int8_t uByte;
86 typedef u_int8_t uWord[2];
87 #define UGETW(w) ((w)[0] | ((w)[1] << 8))
88 #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
89 #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
90 typedef u_int8_t uDWord[4];
91 #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
92 #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
93 		     (w)[1] = (u_int8_t)((v) >> 8), \
94 		     (w)[2] = (u_int8_t)((v) >> 16), \
95 		     (w)[3] = (u_int8_t)((v) >> 24))
96 /*
97  * On little-endian machines that can handle unanliged accesses
98  * (e.g. i386) these macros can be replaced by the following.
99  */
100 #if 0
101 #define UGETW(w) (*(u_int16_t *)(w))
102 #define USETW(w,v) (*(u_int16_t *)(w) = (v))
103 #endif
104 
105 typedef struct {
106 	uByte		bmRequestType;
107 	uByte		bRequest;
108 	uWord		wValue;
109 	uWord		wIndex;
110 	uWord		wLength;
111 } usb_device_request_t;
112 
113 #define UT_WRITE		0x00
114 #define UT_READ			0x80
115 #define UT_STANDARD		0x00
116 #define UT_CLASS		0x20
117 #define UT_VENDOR		0x40
118 #define UT_DEVICE		0x00
119 #define UT_INTERFACE		0x01
120 #define UT_ENDPOINT		0x02
121 #define UT_OTHER		0x03
122 
123 #define UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
124 #define UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
125 #define UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
126 #define UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
127 #define UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
128 #define UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
129 #define UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
130 #define UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
131 #define UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
132 #define UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
133 #define UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
134 #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
135 #define UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
136 #define UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
137 #define UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
138 #define UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
139 #define UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
140 #define UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
141 #define UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
142 #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
143 #define UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
144 #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
145 
146 /* Requests */
147 #define UR_GET_STATUS		0x00
148 #define UR_CLEAR_FEATURE	0x01
149 #define UR_SET_FEATURE		0x03
150 #define UR_SET_ADDRESS		0x05
151 #define UR_GET_DESCRIPTOR	0x06
152 #define  UDESC_DEVICE		0x01
153 #define  UDESC_CONFIG		0x02
154 #define  UDESC_STRING		0x03
155 #define  UDESC_INTERFACE	0x04
156 #define  UDESC_ENDPOINT		0x05
157 #define  UDESC_CS_DEVICE	0x21	/* class specific */
158 #define  UDESC_CS_CONFIG	0x22
159 #define  UDESC_CS_STRING	0x23
160 #define  UDESC_CS_INTERFACE	0x24
161 #define  UDESC_CS_ENDPOINT	0x25
162 #define  UDESC_HUB		0x29
163 #define UR_SET_DESCRIPTOR	0x07
164 #define UR_GET_CONFIG		0x08
165 #define UR_SET_CONFIG		0x09
166 #define UR_GET_INTERFACE	0x0a
167 #define UR_SET_INTERFACE	0x0b
168 #define UR_SYNCH_FRAME		0x0c
169 
170 /* Feature numbers */
171 #define UF_ENDPOINT_HALT	0
172 #define UF_DEVICE_REMOTE_WAKEUP	1
173 
174 #define USB_MAX_IPACKET		8 /* maximum size of the initial packet */
175 
176 typedef struct {
177 	uByte		bLength;
178 	uByte		bDescriptorType;
179 	uByte		bDescriptorSubtype;
180 } usb_descriptor_t;
181 
182 typedef struct {
183 	uByte		bLength;
184 	uByte		bDescriptorType;
185 	uWord		bcdUSB;
186 	uByte		bDeviceClass;
187 	uByte		bDeviceSubClass;
188 	uByte		bDeviceProtocol;
189 	uByte		bMaxPacketSize;
190 	/* The fields below are not part of the initial descriptor. */
191 	uWord		idVendor;
192 	uWord		idProduct;
193 	uWord		bcdDevice;
194 	uByte		iManufacturer;
195 	uByte		iProduct;
196 	uByte		iSerialNumber;
197 	uByte		bNumConfigurations;
198 } usb_device_descriptor_t;
199 #define USB_DEVICE_DESCRIPTOR_SIZE 18
200 
201 typedef struct {
202 	uByte		bLength;
203 	uByte		bDescriptorType;
204 	uWord		wTotalLength;
205 	uByte		bNumInterface;
206 	uByte		bConfigurationValue;
207 	uByte		iConfiguration;
208 	uByte		bmAttributes;
209 #define UC_BUS_POWERED		0x80
210 #define UC_SELF_POWERED		0x40
211 #define UC_REMOTE_WAKEUP	0x20
212 	uByte		bMaxPower; /* max current in 2 mA units */
213 #define UC_POWER_FACTOR 2
214 } usb_config_descriptor_t;
215 #define USB_CONFIG_DESCRIPTOR_SIZE 9
216 
217 typedef struct {
218 	uByte		bLength;
219 	uByte		bDescriptorType;
220 	uByte		bInterfaceNumber;
221 	uByte		bAlternateSetting;
222 	uByte		bNumEndpoints;
223 	uByte		bInterfaceClass;
224 	uByte		bInterfaceSubClass;
225 	uByte		bInterfaceProtocol;
226 	uByte		iInterface;
227 } usb_interface_descriptor_t;
228 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
229 
230 typedef struct {
231 	uByte		bLength;
232 	uByte		bDescriptorType;
233 	uByte		bEndpointAddress;
234 #define UE_GET_DIR(a)	((a) & 0x80)
235 #define UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
236 #define UE_DIR_IN	0x80
237 #define UE_DIR_OUT	0x00
238 #define UE_ADDR		0x0f
239 #define UE_GET_ADDR(a)	((a) & UE_ADDR)
240 	uByte		bmAttributes;
241 #define UE_XFERTYPE	0x03
242 #define  UE_CONTROL	0x00
243 #define  UE_ISOCHRONOUS	0x01
244 #define  UE_BULK	0x02
245 #define  UE_INTERRUPT	0x03
246 #define UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
247 #define UE_ISO_TYPE	0x0c
248 #define  UE_ISO_ASYNC	0x04
249 #define  UE_ISO_ADAPT	0x08
250 #define  UE_ISO_SYNC	0x0c
251 #define UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
252 	uWord		wMaxPacketSize;
253 	uByte		bInterval;
254 } usb_endpoint_descriptor_t;
255 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
256 
257 typedef struct {
258 	uByte		bLength;
259 	uByte		bDescriptorType;
260 	uWord		bString[127];
261 } usb_string_descriptor_t;
262 #define USB_MAX_STRING_LEN 128
263 #define USB_LANGUAGE_TABLE 0	/* # of the string language id table */
264 
265 /* Hub specific request */
266 #define UR_GET_BUS_STATE	0x02
267 
268 /* Hub features */
269 #define UHF_C_HUB_LOCAL_POWER	0
270 #define UHF_C_HUB_OVER_CURRENT	1
271 #define UHF_PORT_CONNECTION	0
272 #define UHF_PORT_ENABLE		1
273 #define UHF_PORT_SUSPEND	2
274 #define UHF_PORT_OVER_CURRENT	3
275 #define UHF_PORT_RESET		4
276 #define UHF_PORT_POWER		8
277 #define UHF_PORT_LOW_SPEED	9
278 #define UHF_C_PORT_CONNECTION	16
279 #define UHF_C_PORT_ENABLE	17
280 #define UHF_C_PORT_SUSPEND	18
281 #define UHF_C_PORT_OVER_CURRENT	19
282 #define UHF_C_PORT_RESET	20
283 
284 typedef struct {
285 	uByte		bDescLength;
286 	uByte		bDescriptorType;
287 	uByte		bNbrPorts;
288 	uWord		wHubCharacteristics;
289 #define UHD_PWR			0x03
290 #define UHD_PWR_GANGED		0x00
291 #define UHD_PWR_INDIVIDUAL	0x01
292 #define UHD_PWR_NO_SWITCH	0x02
293 #define UHD_COMPOUND		0x04
294 #define UHD_OC			0x18
295 #define UHD_OC_GLOBAL		0x00
296 #define UHD_OC_INDIVIDUAL	0x08
297 #define UHD_OC_NONE		0x10
298 	uByte		bPwrOn2PwrGood;	/* delay in 2 ms units */
299 #define UHD_PWRON_FACTOR 2
300 	uByte		bHubContrCurrent;
301 	uByte		DeviceRemovable[32]; /* max 255 ports */
302 #define UHD_NOT_REMOV(desc, i) \
303     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
304 	/* deprecated uByte		PortPowerCtrlMask[]; */
305 } usb_hub_descriptor_t;
306 #define USB_HUB_DESCRIPTOR_SIZE 8
307 
308 typedef struct {
309 	uWord		wStatus;
310 /* Device status flags */
311 #define UDS_SELF_POWERED		0x0001
312 #define UDS_REMOTE_WAKEUP		0x0002
313 /* Endpoint status flags */
314 #define UES_HALT			0x0001
315 } usb_status_t;
316 
317 typedef struct {
318 	uWord		wHubStatus;
319 #define UHS_LOCAL_POWER			0x0001
320 #define UHS_OVER_CURRENT		0x0002
321 	uWord		wHubChange;
322 } usb_hub_status_t;
323 
324 typedef struct {
325 	uWord		wPortStatus;
326 #define UPS_CURRENT_CONNECT_STATUS	0x0001
327 #define UPS_PORT_ENABLED		0x0002
328 #define UPS_SUSPEND			0x0004
329 #define UPS_OVERCURRENT_INDICATOR	0x0008
330 #define UPS_RESET			0x0010
331 #define UPS_PORT_POWER			0x0100
332 #define UPS_LOW_SPEED			0x0200
333 	uWord		wPortChange;
334 #define UPS_C_CONNECT_STATUS		0x0001
335 #define UPS_C_PORT_ENABLED		0x0002
336 #define UPS_C_SUSPEND			0x0004
337 #define UPS_C_OVERCURRENT_INDICATOR	0x0008
338 #define UPS_C_PORT_RESET		0x0010
339 } usb_port_status_t;
340 
341 #define UCLASS_UNSPEC		0
342 #define UCLASS_AUDIO		1
343 #define  USUBCLASS_AUDIOCONTROL	1
344 #define  USUBCLASS_AUDIOSTREAM	2
345 #define  USUBCLASS_MIDISTREAM	3
346 #define UCLASS_CDC		2 /* communication */
347 #define	 USUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
348 #define  USUBCLASS_ABSTRACT_CONTROL_MODEL	2
349 #define	 USUBCLASS_TELEPHONE_CONTROL_MODEL	3
350 #define	 USUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
351 #define	 USUBCLASS_CAPI_CONTROLMODEL		5
352 #define	 USUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
353 #define	 USUBCLASS_ATM_NETWORKING_CONTROL_MODEL	7
354 #define   UPROTO_CDC_AT		1
355 #define UCLASS_HID		3
356 #define  USUBCLASS_BOOT	 	1
357 #define UCLASS_PRINTER		7
358 #define  USUBCLASS_PRINTER	1
359 #define  UPROTO_PRINTER_UNI	1
360 #define  UPROTO_PRINTER_BI	2
361 #define UCLASS_MASS		8
362 #define  USUBCLASS_RBC		1
363 #define  USUBCLASS_SFF8020I	2
364 #define  USUBCLASS_QIC157	3
365 #define  USUBCLASS_UFI		4
366 #define  USUBCLASS_SFF8070I	5
367 #define  USUBCLASS_SCSI		6
368 #define  UPROTO_MASS_CBI_I	0
369 #define  UPROTO_MASS_CBI	1
370 #define  UPROTO_MASS_BBB	2
371 #define  UPROTO_MASS_BBB_P	80	/* 'P' for the Iomega Zip drive */
372 #define UCLASS_HUB		9
373 #define  USUBCLASS_HUB		0
374 #define UCLASS_DATA		10
375 #define  USUBCLASS_DATA		0
376 #define   UPROTO_DATA_ISDNBRI		0x30    /* Physical iface */
377 #define   UPROTO_DATA_HDLC		0x31    /* HDLC */
378 #define   UPROTO_DATA_TRANSPARENT	0x32    /* Transparent */
379 #define   UPROTO_DATA_Q921M		0x50    /* Management for Q921 */
380 #define   UPROTO_DATA_Q921		0x51    /* Data for Q921 */
381 #define   UPROTO_DATA_Q921TM		0x52    /* TEI multiplexer for Q921 */
382 #define   UPROTO_DATA_V42BIS		0x90    /* Data compression */
383 #define   UPROTO_DATA_Q931		0x91    /* Euro-ISDN */
384 #define   UPROTO_DATA_V120		0x92    /* V.24 rate adaption */
385 #define   UPROTO_DATA_CAPI		0x93    /* CAPI 2.0 commands */
386 #define   UPROTO_DATA_HOST_BASED	0xfd    /* Host based driver */
387 #define   UPROTO_DATA_PUF		0xfe    /* see Prot. Unit Func. Desc.*/
388 #define   UPROTO_DATA_VENDOR		0xff    /* Vendor specific */
389 #define UCLASS_VENDOR_DA		0xfe	/* Doug Ambrisko */
390 #define  USUBCLASS_DA			0xda	/* Doug Ambrisko */
391 
392 
393 #define USB_HUB_MAX_DEPTH 5
394 
395 /*
396  * Minimum time a device needs to be powered down to go through
397  * a power cycle.  XXX Are these time in the spec?
398  */
399 #define USB_POWER_DOWN_TIME	200 /* ms */
400 #define USB_PORT_POWER_DOWN_TIME	100 /* ms */
401 
402 #if 0
403 /* These are the values from the spec. */
404 #define USB_PORT_RESET_DELAY	10  /* ms */
405 #define USB_PORT_RESET_SETTLE	10  /* ms */
406 #define USB_PORT_POWERUP_DELAY	100 /* ms */
407 #define USB_SET_ADDRESS_SETTLE	2   /* ms */
408 #define USB_RESUME_TIME		(20*5)  /* ms */
409 #define USB_RESUME_WAIT		10  /* ms */
410 #define USB_RESUME_RECOVERY	10  /* ms */
411 #define USB_EXTRA_POWER_UP_TIME	0   /* ms */
412 #else
413 /* Allow for marginal (i.e. non-conforming) devices. */
414 #define USB_PORT_RESET_DELAY	50  /* ms */
415 #define USB_PORT_RESET_RECOVERY	50  /* ms */
416 #define USB_PORT_POWERUP_DELAY	200 /* ms */
417 #define USB_SET_ADDRESS_SETTLE	10  /* ms */
418 #define USB_RESUME_DELAY	(50*5)  /* ms */
419 #define USB_RESUME_WAIT		50  /* ms */
420 #define USB_RESUME_RECOVERY	50  /* ms */
421 #define USB_EXTRA_POWER_UP_TIME	20  /* ms */
422 #endif
423 
424 #define USB_MIN_POWER		100 /* mA */
425 #define USB_MAX_POWER		500 /* mA */
426 
427 #define USB_BUS_RESET_DELAY	100 /* ms XXX?*/
428 
429 #define USB_UNCONFIG_NO		0
430 #define USB_UNCONFIG_INDEX	(-1)
431 
432 /*** ioctl() related stuff ***/
433 
434 struct usb_ctl_request {
435 	int	addr;
436 	usb_device_request_t request;
437 	void	*data;
438 	int	flags;
439 #define USBD_SHORT_XFER_OK	0x04	/* allow short reads */
440 	int	actlen;		/* actual length transferred */
441 };
442 
443 struct usb_alt_interface {
444 	int	config_index;
445 	int	interface_index;
446 	int	alt_no;
447 };
448 
449 #define USB_CURRENT_CONFIG_INDEX (-1)
450 #define USB_CURRENT_ALT_INDEX (-1)
451 
452 struct usb_config_desc {
453 	int	config_index;
454 	usb_config_descriptor_t desc;
455 };
456 
457 struct usb_interface_desc {
458 	int	config_index;
459 	int	interface_index;
460 	int	alt_index;
461 	usb_interface_descriptor_t desc;
462 };
463 
464 struct usb_endpoint_desc {
465 	int	config_index;
466 	int	interface_index;
467 	int	alt_index;
468 	int	endpoint_index;
469 	usb_endpoint_descriptor_t desc;
470 };
471 
472 struct usb_full_desc {
473 	int	config_index;
474 	u_int	size;
475 	u_char	*data;
476 };
477 
478 struct usb_string_desc {
479 	int	string_index;
480 	int	language_id;
481 	usb_string_descriptor_t desc;
482 };
483 
484 struct usb_ctl_report_desc {
485 	int	size;
486 	u_char	data[1024];	/* filled data size will vary */
487 };
488 
489 struct usb_device_info {
490 	u_int8_t	bus;				/* bus number */
491 	u_int8_t	addr;				/* device address */
492 #	define		MAXDEVNAMELEN	10		/* number of drivers */
493 #	define		MAXDEVNAMES	4		/* attached drivers */
494 	char		devnames[MAXDEVNAMES][MAXDEVNAMELEN];
495 							/* device names */
496 	char		product[USB_MAX_STRING_LEN];	/* iProduct */
497 	char		vendor[USB_MAX_STRING_LEN];	/* iManufacturer */
498 	char		release[8];			/* string of releaseNo*/
499 	u_int16_t	productNo;			/* idProduct */
500 	u_int16_t	vendorNo;			/* idVendor */
501 	u_int16_t	releaseNo;			/* bcdDevice */
502 	u_int8_t	class;				/* bDeviceClass */
503 	u_int8_t	subclass;			/* bDeviceSubclass */
504 	u_int8_t	protocol;			/* bDeviceProtocol */
505 	u_int8_t	config;				/* config index */
506 	u_int8_t	lowspeed;			/* lowsped yes/no */
507 	int		power;	/* power consumption in mA, 0 if selfpowered */
508 	int		nports;				/* 0 if not hub */
509 	u_int8_t	ports[16];/* hub only: addresses of devices on ports */
510 #define USB_PORT_ENABLED 0xff
511 #define USB_PORT_SUSPENDED 0xfe
512 #define USB_PORT_POWERED 0xfd
513 #define USB_PORT_DISABLED 0xfc
514 };
515 
516 struct usb_ctl_report {
517 	int	report;
518 	u_char	data[1024];	/* filled data size will vary */
519 };
520 
521 struct usb_device_stats {
522 	u_long	requests[4];	/* indexed by transfer type UE_* */
523 };
524 
525 typedef struct { u_int32_t cookie; } usb_event_cookie_t;
526 /* Events that can be read from /dev/usb */
527 struct usb_event {
528 	int			ue_type;
529 #define USB_EVENT_ATTACH 1
530 #define USB_EVENT_DETACH 2
531 	struct usb_device_info	ue_device;
532 	struct timespec		ue_time;
533 	usb_event_cookie_t	ue_cookie;
534 };
535 
536 /* USB controller */
537 #define USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
538 #define USB_SETDEBUG		_IOW ('U', 2, int)
539 #define USB_DISCOVER		_IO  ('U', 3)
540 #define USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
541 #define USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
542 
543 /* Generic HID device */
544 #define USB_GET_REPORT_DESC	_IOR ('U', 21, struct usb_ctl_report_desc)
545 #define USB_SET_IMMED		_IOW ('U', 22, int)
546 #define USB_GET_REPORT		_IOWR('U', 23, struct usb_ctl_report)
547 #define USB_SET_REPORT		_IOW ('U', 24, struct usb_ctl_report)
548 
549 /* Generic USB device */
550 #define USB_GET_CONFIG		_IOR ('U', 100, int)
551 #define USB_SET_CONFIG		_IOW ('U', 101, int)
552 #define USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
553 #define USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
554 #define USB_GET_NO_ALT		_IOWR('U', 104, struct usb_alt_interface)
555 #define USB_GET_DEVICE_DESC	_IOR ('U', 105, usb_device_descriptor_t)
556 #define USB_GET_CONFIG_DESC	_IOWR('U', 106, struct usb_config_desc)
557 #define USB_GET_INTERFACE_DESC	_IOWR('U', 107, struct usb_interface_desc)
558 #define USB_GET_ENDPOINT_DESC	_IOWR('U', 108, struct usb_endpoint_desc)
559 #define USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_full_desc)
560 #define USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_string_desc)
561 #define USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
562 #define USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
563 #define USB_SET_SHORT_XFER	_IOW ('U', 113, int)
564 #define USB_SET_TIMEOUT		_IOW ('U', 114, int)
565 
566 /* Modem device */
567 #define USB_GET_CM_OVER_DATA	_IOR ('U', 130, int)
568 #define USB_SET_CM_OVER_DATA	_IOW ('U', 131, int)
569 
570 #endif /* _USB_H_ */
571