Home | History | Annotate | Line # | Download | only in usb
usb.h revision 1.51.4.2
      1  1.51.4.2   thorpej /*	$NetBSD: usb.h,v 1.51.4.2 2002/01/10 19:59:05 thorpej Exp $	*/
      2      1.39  augustss /*	$FreeBSD: src/sys/dev/usb/usb.h,v 1.14 1999/11/17 22:33:46 n_hibma Exp $	*/
      3       1.1  augustss 
      4       1.1  augustss /*
      5       1.1  augustss  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      6       1.1  augustss  * All rights reserved.
      7       1.1  augustss  *
      8       1.4  augustss  * This code is derived from software contributed to The NetBSD Foundation
      9      1.48  augustss  * by Lennart Augustsson (lennart (at) augustsson.net) at
     10       1.4  augustss  * Carlstedt Research & Technology.
     11       1.1  augustss  *
     12       1.1  augustss  * Redistribution and use in source and binary forms, with or without
     13       1.1  augustss  * modification, are permitted provided that the following conditions
     14       1.1  augustss  * are met:
     15       1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     16       1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     17       1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     18       1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     19       1.1  augustss  *    documentation and/or other materials provided with the distribution.
     20       1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     21       1.1  augustss  *    must display the following acknowledgement:
     22       1.1  augustss  *        This product includes software developed by the NetBSD
     23       1.1  augustss  *        Foundation, Inc. and its contributors.
     24       1.1  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     25       1.1  augustss  *    contributors may be used to endorse or promote products derived
     26       1.1  augustss  *    from this software without specific prior written permission.
     27       1.1  augustss  *
     28       1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     29       1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     30       1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     31       1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     32       1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     33       1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     34       1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     35       1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     36       1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     37       1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38       1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     39       1.1  augustss  */
     40       1.1  augustss 
     41       1.1  augustss 
     42       1.1  augustss #ifndef _USB_H_
     43       1.1  augustss #define _USB_H_
     44       1.1  augustss 
     45       1.1  augustss #include <sys/types.h>
     46      1.37  augustss #include <sys/time.h>
     47      1.36  augustss 
     48      1.25  augustss #if defined(__NetBSD__) || defined(__OpenBSD__)
     49       1.1  augustss #include <sys/ioctl.h>
     50       1.8  augustss 
     51       1.8  augustss #if defined(_KERNEL)
     52       1.8  augustss #include <dev/usb/usb_port.h>
     53       1.8  augustss #endif /* _KERNEL */
     54       1.8  augustss 
     55       1.8  augustss #elif defined(__FreeBSD__)
     56      1.36  augustss #if defined(KERNEL)
     57       1.8  augustss #include <sys/malloc.h>
     58       1.8  augustss 
     59       1.8  augustss MALLOC_DECLARE(M_USB);
     60       1.8  augustss MALLOC_DECLARE(M_USBDEV);
     61      1.23  augustss MALLOC_DECLARE(M_USBHC);
     62       1.8  augustss 
     63       1.8  augustss #include <dev/usb/usb_port.h>
     64       1.8  augustss #endif /* KERNEL */
     65       1.8  augustss #endif /* __FreeBSD__ */
     66       1.8  augustss 
     67       1.1  augustss 
     68       1.1  augustss #define USB_MAX_DEVICES 128
     69       1.1  augustss #define USB_START_ADDR 0
     70       1.1  augustss 
     71       1.1  augustss #define USB_CONTROL_ENDPOINT 0
     72       1.1  augustss #define USB_MAX_ENDPOINTS 16
     73       1.1  augustss 
     74      1.10  augustss #define USB_FRAMES_PER_SECOND 1000
     75      1.10  augustss 
     76       1.1  augustss /*
     77       1.1  augustss  * The USB records contain some unaligned little-endian word
     78       1.1  augustss  * components.  The U[SG]ETW macros take care of both the alignment
     79      1.50  augustss  * and endian problem and should always be used to access non-byte
     80       1.1  augustss  * values.
     81       1.1  augustss  */
     82       1.1  augustss typedef u_int8_t uByte;
     83       1.1  augustss typedef u_int8_t uWord[2];
     84      1.50  augustss typedef u_int8_t uDWord[4];
     85      1.50  augustss 
     86      1.50  augustss #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
     87      1.50  augustss 
     88      1.50  augustss #if 1
     89       1.1  augustss #define UGETW(w) ((w)[0] | ((w)[1] << 8))
     90       1.1  augustss #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
     91      1.16  augustss #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
     92      1.16  augustss #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
     93      1.16  augustss 		     (w)[1] = (u_int8_t)((v) >> 8), \
     94      1.16  augustss 		     (w)[2] = (u_int8_t)((v) >> 16), \
     95      1.16  augustss 		     (w)[3] = (u_int8_t)((v) >> 24))
     96      1.50  augustss #else
     97       1.1  augustss /*
     98       1.1  augustss  * On little-endian machines that can handle unanliged accesses
     99       1.1  augustss  * (e.g. i386) these macros can be replaced by the following.
    100       1.1  augustss  */
    101       1.1  augustss #define UGETW(w) (*(u_int16_t *)(w))
    102       1.1  augustss #define USETW(w,v) (*(u_int16_t *)(w) = (v))
    103      1.50  augustss #define UGETDW(w) (*(u_int32_t *)(w))
    104      1.50  augustss #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
    105       1.1  augustss #endif
    106       1.1  augustss 
    107      1.49  augustss #define UPACKED __attribute__((__packed__))
    108      1.49  augustss 
    109       1.1  augustss typedef struct {
    110       1.1  augustss 	uByte		bmRequestType;
    111       1.1  augustss 	uByte		bRequest;
    112       1.1  augustss 	uWord		wValue;
    113       1.1  augustss 	uWord		wIndex;
    114       1.1  augustss 	uWord		wLength;
    115      1.49  augustss } UPACKED usb_device_request_t;
    116       1.1  augustss 
    117       1.1  augustss #define UT_WRITE		0x00
    118       1.1  augustss #define UT_READ			0x80
    119       1.1  augustss #define UT_STANDARD		0x00
    120       1.1  augustss #define UT_CLASS		0x20
    121       1.1  augustss #define UT_VENDOR		0x40
    122       1.1  augustss #define UT_DEVICE		0x00
    123       1.1  augustss #define UT_INTERFACE		0x01
    124       1.1  augustss #define UT_ENDPOINT		0x02
    125       1.1  augustss #define UT_OTHER		0x03
    126       1.1  augustss 
    127       1.1  augustss #define UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
    128       1.1  augustss #define UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
    129       1.1  augustss #define UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
    130       1.1  augustss #define UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
    131       1.1  augustss #define UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
    132       1.1  augustss #define UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
    133       1.1  augustss #define UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
    134       1.1  augustss #define UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
    135       1.1  augustss #define UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
    136      1.30  augustss #define UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
    137       1.1  augustss #define UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
    138       1.1  augustss #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
    139       1.1  augustss #define UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
    140      1.30  augustss #define UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
    141      1.13  augustss #define UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
    142      1.13  augustss #define UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
    143      1.13  augustss #define UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
    144      1.30  augustss #define UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
    145      1.13  augustss #define UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
    146      1.13  augustss #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
    147      1.13  augustss #define UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
    148      1.30  augustss #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
    149       1.1  augustss 
    150       1.1  augustss /* Requests */
    151       1.1  augustss #define UR_GET_STATUS		0x00
    152       1.1  augustss #define UR_CLEAR_FEATURE	0x01
    153       1.1  augustss #define UR_SET_FEATURE		0x03
    154       1.1  augustss #define UR_SET_ADDRESS		0x05
    155       1.1  augustss #define UR_GET_DESCRIPTOR	0x06
    156      1.36  augustss #define  UDESC_DEVICE		0x01
    157      1.36  augustss #define  UDESC_CONFIG		0x02
    158      1.36  augustss #define  UDESC_STRING		0x03
    159      1.36  augustss #define  UDESC_INTERFACE	0x04
    160      1.36  augustss #define  UDESC_ENDPOINT		0x05
    161  1.51.4.2   thorpej #define  UDESC_DEVICE_QUALIFIER	0x06
    162  1.51.4.2   thorpej #define  UDESC_OTHER_SPEED_CONFIGURATION 0x07
    163  1.51.4.2   thorpej #define  UDESC_INTERFACE_POWER	0x08
    164  1.51.4.2   thorpej #define  UDESC_OTG		0x09
    165      1.36  augustss #define  UDESC_CS_DEVICE	0x21	/* class specific */
    166      1.36  augustss #define  UDESC_CS_CONFIG	0x22
    167      1.36  augustss #define  UDESC_CS_STRING	0x23
    168      1.36  augustss #define  UDESC_CS_INTERFACE	0x24
    169      1.36  augustss #define  UDESC_CS_ENDPOINT	0x25
    170      1.36  augustss #define  UDESC_HUB		0x29
    171       1.1  augustss #define UR_SET_DESCRIPTOR	0x07
    172       1.1  augustss #define UR_GET_CONFIG		0x08
    173       1.1  augustss #define UR_SET_CONFIG		0x09
    174       1.1  augustss #define UR_GET_INTERFACE	0x0a
    175       1.1  augustss #define UR_SET_INTERFACE	0x0b
    176       1.1  augustss #define UR_SYNCH_FRAME		0x0c
    177       1.1  augustss 
    178       1.1  augustss /* Feature numbers */
    179       1.8  augustss #define UF_ENDPOINT_HALT	0
    180       1.1  augustss #define UF_DEVICE_REMOTE_WAKEUP	1
    181  1.51.4.2   thorpej #define UF_TEST_MODE		2
    182       1.1  augustss 
    183       1.1  augustss #define USB_MAX_IPACKET		8 /* maximum size of the initial packet */
    184       1.1  augustss 
    185  1.51.4.2   thorpej #define USB_2_MAX_CTRL_PACKET	64
    186  1.51.4.2   thorpej #define USB_2_MAX_BULK_PACKET	512
    187  1.51.4.2   thorpej 
    188       1.1  augustss typedef struct {
    189       1.1  augustss 	uByte		bLength;
    190       1.1  augustss 	uByte		bDescriptorType;
    191       1.1  augustss 	uByte		bDescriptorSubtype;
    192      1.49  augustss } UPACKED usb_descriptor_t;
    193       1.1  augustss 
    194       1.1  augustss typedef struct {
    195       1.1  augustss 	uByte		bLength;
    196       1.1  augustss 	uByte		bDescriptorType;
    197       1.1  augustss 	uWord		bcdUSB;
    198  1.51.4.2   thorpej #define UD_USB_2_0		0x0200
    199  1.51.4.2   thorpej #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
    200       1.1  augustss 	uByte		bDeviceClass;
    201       1.1  augustss 	uByte		bDeviceSubClass;
    202       1.1  augustss 	uByte		bDeviceProtocol;
    203       1.1  augustss 	uByte		bMaxPacketSize;
    204       1.1  augustss 	/* The fields below are not part of the initial descriptor. */
    205       1.1  augustss 	uWord		idVendor;
    206       1.1  augustss 	uWord		idProduct;
    207       1.1  augustss 	uWord		bcdDevice;
    208       1.1  augustss 	uByte		iManufacturer;
    209       1.1  augustss 	uByte		iProduct;
    210       1.1  augustss 	uByte		iSerialNumber;
    211       1.1  augustss 	uByte		bNumConfigurations;
    212      1.49  augustss } UPACKED usb_device_descriptor_t;
    213       1.1  augustss #define USB_DEVICE_DESCRIPTOR_SIZE 18
    214       1.1  augustss 
    215       1.1  augustss typedef struct {
    216       1.1  augustss 	uByte		bLength;
    217       1.1  augustss 	uByte		bDescriptorType;
    218       1.1  augustss 	uWord		wTotalLength;
    219       1.1  augustss 	uByte		bNumInterface;
    220       1.1  augustss 	uByte		bConfigurationValue;
    221       1.1  augustss 	uByte		iConfiguration;
    222       1.1  augustss 	uByte		bmAttributes;
    223       1.1  augustss #define UC_BUS_POWERED		0x80
    224       1.1  augustss #define UC_SELF_POWERED		0x40
    225       1.1  augustss #define UC_REMOTE_WAKEUP	0x20
    226       1.1  augustss 	uByte		bMaxPower; /* max current in 2 mA units */
    227       1.1  augustss #define UC_POWER_FACTOR 2
    228      1.49  augustss } UPACKED usb_config_descriptor_t;
    229       1.1  augustss #define USB_CONFIG_DESCRIPTOR_SIZE 9
    230       1.1  augustss 
    231       1.1  augustss typedef struct {
    232       1.1  augustss 	uByte		bLength;
    233       1.1  augustss 	uByte		bDescriptorType;
    234       1.1  augustss 	uByte		bInterfaceNumber;
    235       1.1  augustss 	uByte		bAlternateSetting;
    236       1.1  augustss 	uByte		bNumEndpoints;
    237       1.1  augustss 	uByte		bInterfaceClass;
    238       1.1  augustss 	uByte		bInterfaceSubClass;
    239       1.1  augustss 	uByte		bInterfaceProtocol;
    240       1.1  augustss 	uByte		iInterface;
    241      1.49  augustss } UPACKED usb_interface_descriptor_t;
    242       1.1  augustss #define USB_INTERFACE_DESCRIPTOR_SIZE 9
    243       1.1  augustss 
    244       1.1  augustss typedef struct {
    245       1.1  augustss 	uByte		bLength;
    246       1.1  augustss 	uByte		bDescriptorType;
    247       1.1  augustss 	uByte		bEndpointAddress;
    248      1.31  augustss #define UE_GET_DIR(a)	((a) & 0x80)
    249      1.36  augustss #define UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
    250      1.31  augustss #define UE_DIR_IN	0x80
    251      1.31  augustss #define UE_DIR_OUT	0x00
    252       1.1  augustss #define UE_ADDR		0x0f
    253       1.6  augustss #define UE_GET_ADDR(a)	((a) & UE_ADDR)
    254       1.1  augustss 	uByte		bmAttributes;
    255       1.1  augustss #define UE_XFERTYPE	0x03
    256      1.10  augustss #define  UE_CONTROL	0x00
    257      1.10  augustss #define  UE_ISOCHRONOUS	0x01
    258      1.10  augustss #define  UE_BULK	0x02
    259      1.10  augustss #define  UE_INTERRUPT	0x03
    260      1.36  augustss #define UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
    261      1.10  augustss #define UE_ISO_TYPE	0x0c
    262      1.10  augustss #define  UE_ISO_ASYNC	0x04
    263      1.10  augustss #define  UE_ISO_ADAPT	0x08
    264      1.10  augustss #define  UE_ISO_SYNC	0x0c
    265      1.38  augustss #define UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
    266       1.1  augustss 	uWord		wMaxPacketSize;
    267       1.1  augustss 	uByte		bInterval;
    268      1.49  augustss } UPACKED usb_endpoint_descriptor_t;
    269       1.1  augustss #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
    270       1.1  augustss 
    271       1.1  augustss typedef struct {
    272       1.1  augustss 	uByte		bLength;
    273       1.1  augustss 	uByte		bDescriptorType;
    274       1.1  augustss 	uWord		bString[127];
    275      1.49  augustss } UPACKED usb_string_descriptor_t;
    276       1.1  augustss #define USB_MAX_STRING_LEN 128
    277      1.15  augustss #define USB_LANGUAGE_TABLE 0	/* # of the string language id table */
    278       1.1  augustss 
    279       1.1  augustss /* Hub specific request */
    280       1.1  augustss #define UR_GET_BUS_STATE	0x02
    281  1.51.4.2   thorpej #define UR_CLEAR_TT_BUFFER	0x08
    282  1.51.4.2   thorpej #define UR_RESET_TT		0x09
    283  1.51.4.2   thorpej #define UR_GET_TT_STATE		0x0a
    284  1.51.4.2   thorpej #define UR_STOP_TT		0x0b
    285       1.1  augustss 
    286       1.1  augustss /* Hub features */
    287       1.1  augustss #define UHF_C_HUB_LOCAL_POWER	0
    288       1.1  augustss #define UHF_C_HUB_OVER_CURRENT	1
    289       1.1  augustss #define UHF_PORT_CONNECTION	0
    290       1.1  augustss #define UHF_PORT_ENABLE		1
    291       1.1  augustss #define UHF_PORT_SUSPEND	2
    292       1.1  augustss #define UHF_PORT_OVER_CURRENT	3
    293       1.1  augustss #define UHF_PORT_RESET		4
    294       1.1  augustss #define UHF_PORT_POWER		8
    295       1.1  augustss #define UHF_PORT_LOW_SPEED	9
    296       1.1  augustss #define UHF_C_PORT_CONNECTION	16
    297       1.1  augustss #define UHF_C_PORT_ENABLE	17
    298       1.1  augustss #define UHF_C_PORT_SUSPEND	18
    299       1.1  augustss #define UHF_C_PORT_OVER_CURRENT	19
    300       1.1  augustss #define UHF_C_PORT_RESET	20
    301  1.51.4.2   thorpej #define UHF_PORT_TEST		21
    302  1.51.4.2   thorpej #define UHF_PORT_INDICATOR	22
    303       1.1  augustss 
    304       1.1  augustss typedef struct {
    305       1.1  augustss 	uByte		bDescLength;
    306       1.1  augustss 	uByte		bDescriptorType;
    307       1.1  augustss 	uByte		bNbrPorts;
    308       1.8  augustss 	uWord		wHubCharacteristics;
    309  1.51.4.2   thorpej #define UHD_PWR			0x0003
    310  1.51.4.2   thorpej #define  UHD_PWR_GANGED		0x0000
    311  1.51.4.2   thorpej #define  UHD_PWR_INDIVIDUAL	0x0001
    312  1.51.4.2   thorpej #define  UHD_PWR_NO_SWITCH	0x0002
    313  1.51.4.2   thorpej #define UHD_COMPOUND		0x0004
    314  1.51.4.2   thorpej #define UHD_OC			0x0018
    315  1.51.4.2   thorpej #define  UHD_OC_GLOBAL		0x0000
    316  1.51.4.2   thorpej #define  UHD_OC_INDIVIDUAL	0x0008
    317  1.51.4.2   thorpej #define  UHD_OC_NONE		0x0010
    318  1.51.4.2   thorpej #define UHD_TT_THINK		0x0060
    319  1.51.4.2   thorpej #define  UHD_TT_THINK_8		0x0000
    320  1.51.4.2   thorpej #define  UHD_TT_THINK_16	0x0020
    321  1.51.4.2   thorpej #define  UHD_TT_THINK_24	0x0040
    322  1.51.4.2   thorpej #define  UHD_TT_THINK_32	0x0060
    323  1.51.4.2   thorpej #define UHD_PORT_IND		0x0080
    324       1.1  augustss 	uByte		bPwrOn2PwrGood;	/* delay in 2 ms units */
    325       1.1  augustss #define UHD_PWRON_FACTOR 2
    326       1.1  augustss 	uByte		bHubContrCurrent;
    327       1.8  augustss 	uByte		DeviceRemovable[32]; /* max 255 ports */
    328       1.8  augustss #define UHD_NOT_REMOV(desc, i) \
    329       1.8  augustss     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
    330      1.46  augustss 	/* deprecated */ uByte		PortPowerCtrlMask[1];
    331      1.49  augustss } UPACKED usb_hub_descriptor_t;
    332      1.46  augustss #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
    333       1.1  augustss 
    334       1.1  augustss typedef struct {
    335  1.51.4.2   thorpej 	uByte		bLength;
    336  1.51.4.2   thorpej 	uByte		bDescriptorType;
    337  1.51.4.2   thorpej 	uWord		bcdUSB;
    338  1.51.4.2   thorpej 	uByte		bDeviceClass;
    339  1.51.4.2   thorpej 	uByte		bDeviceSubClass;
    340  1.51.4.2   thorpej 	uByte		bDeviceProtocol;
    341  1.51.4.2   thorpej 	uByte		bMaxPacketSize0;
    342  1.51.4.2   thorpej 	uByte		bNumConfigurations;
    343  1.51.4.2   thorpej 	uByte		bReserved;
    344  1.51.4.2   thorpej } UPACKED usb_device_qualifier_t;
    345  1.51.4.2   thorpej #define USB_DEVICE_QUALIFIER_SIZE 10
    346  1.51.4.2   thorpej 
    347  1.51.4.2   thorpej typedef struct {
    348  1.51.4.2   thorpej 	uByte		bLength;
    349  1.51.4.2   thorpej 	uByte		bDescriptorType;
    350  1.51.4.2   thorpej 	uByte		bmAttributes;
    351  1.51.4.2   thorpej #define UOTG_SRP	0x01
    352  1.51.4.2   thorpej #define UOTG_HNP	0x02
    353  1.51.4.2   thorpej } UPACKED usb_otg_descriptor_t;
    354  1.51.4.2   thorpej 
    355  1.51.4.2   thorpej /* OTG feature selectors */
    356  1.51.4.2   thorpej #define UOTG_B_HNP_ENABLE	3
    357  1.51.4.2   thorpej #define UOTG_A_HNP_SUPPORT	4
    358  1.51.4.2   thorpej #define UOTG_A_ALT_HNP_SUPPORT	5
    359  1.51.4.2   thorpej 
    360  1.51.4.2   thorpej typedef struct {
    361       1.1  augustss 	uWord		wStatus;
    362       1.1  augustss /* Device status flags */
    363       1.1  augustss #define UDS_SELF_POWERED		0x0001
    364       1.1  augustss #define UDS_REMOTE_WAKEUP		0x0002
    365       1.8  augustss /* Endpoint status flags */
    366       1.8  augustss #define UES_HALT			0x0001
    367      1.49  augustss } UPACKED usb_status_t;
    368       1.1  augustss 
    369       1.1  augustss typedef struct {
    370       1.1  augustss 	uWord		wHubStatus;
    371       1.1  augustss #define UHS_LOCAL_POWER			0x0001
    372       1.1  augustss #define UHS_OVER_CURRENT		0x0002
    373       1.1  augustss 	uWord		wHubChange;
    374      1.49  augustss } UPACKED usb_hub_status_t;
    375       1.1  augustss 
    376       1.1  augustss typedef struct {
    377       1.1  augustss 	uWord		wPortStatus;
    378       1.1  augustss #define UPS_CURRENT_CONNECT_STATUS	0x0001
    379       1.1  augustss #define UPS_PORT_ENABLED		0x0002
    380       1.1  augustss #define UPS_SUSPEND			0x0004
    381       1.1  augustss #define UPS_OVERCURRENT_INDICATOR	0x0008
    382       1.1  augustss #define UPS_RESET			0x0010
    383       1.1  augustss #define UPS_PORT_POWER			0x0100
    384       1.1  augustss #define UPS_LOW_SPEED			0x0200
    385  1.51.4.2   thorpej #define UPS_HIGH_SPEED			0x0400
    386  1.51.4.2   thorpej #define UPS_PORT_TEST			0x0800
    387  1.51.4.2   thorpej #define UPS_PORT_INDICATOR		0x1000
    388       1.1  augustss 	uWord		wPortChange;
    389       1.1  augustss #define UPS_C_CONNECT_STATUS		0x0001
    390       1.1  augustss #define UPS_C_PORT_ENABLED		0x0002
    391       1.1  augustss #define UPS_C_SUSPEND			0x0004
    392       1.1  augustss #define UPS_C_OVERCURRENT_INDICATOR	0x0008
    393       1.1  augustss #define UPS_C_PORT_RESET		0x0010
    394      1.49  augustss } UPACKED usb_port_status_t;
    395       1.1  augustss 
    396      1.41  augustss /* Device class codes */
    397      1.41  augustss #define UDCLASS_AUDIO		0x00
    398      1.41  augustss #define UDCLASS_COMM		0x02
    399      1.41  augustss #define UDCLASS_HID		0x00
    400      1.41  augustss #define UDCLASS_HUB		0x09
    401      1.41  augustss #define  UDSUBCLASS_HUB		0
    402  1.51.4.2   thorpej #define  UDPROTO_FSHUB		0
    403  1.51.4.2   thorpej #define  UDPROTO_HSHUBSTT	1
    404  1.51.4.2   thorpej #define  UDPROTO_HSHUBMTT	2
    405      1.41  augustss #define UDCLASS_MASS		0x00
    406      1.41  augustss 
    407      1.41  augustss /* Interface class codes */
    408      1.41  augustss #define UICLASS_UNSPEC		0x00
    409      1.41  augustss 
    410      1.41  augustss #define UICLASS_AUDIO		0x01
    411      1.41  augustss #define  UISUBCLASS_AUDIOCONTROL	1
    412      1.41  augustss #define  UISUBCLASS_AUDIOSTREAM		2
    413      1.41  augustss #define  UISUBCLASS_MIDISTREAM		3
    414      1.41  augustss 
    415      1.41  augustss #define UICLASS_CDC		0x02 /* communication */
    416      1.41  augustss #define	 UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
    417      1.41  augustss #define  UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
    418      1.41  augustss #define	 UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
    419      1.41  augustss #define	 UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
    420      1.41  augustss #define	 UISUBCLASS_CAPI_CONTROLMODEL		5
    421      1.41  augustss #define	 UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
    422      1.41  augustss #define	 UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
    423      1.41  augustss #define   UIPROTO_CDC_AT			1
    424      1.41  augustss 
    425      1.41  augustss #define UICLASS_HID		0x03
    426      1.41  augustss #define  UISUBCLASS_BOOT	1
    427      1.41  augustss #define  UIPROTO_BOOT_KEYBOARD	1
    428      1.41  augustss 
    429      1.41  augustss #define UICLASS_PHYSICAL	0x05
    430      1.41  augustss 
    431      1.41  augustss #define UICLASS_PRINTER		0x07
    432      1.41  augustss #define  UISUBCLASS_PRINTER	1
    433      1.41  augustss #define  UIPROTO_PRINTER_UNI	1
    434      1.41  augustss #define  UIPROTO_PRINTER_BI	2
    435  1.51.4.1     lukem #define  UIPROTO_PRINTER_1284	3
    436      1.41  augustss 
    437      1.41  augustss #define UICLASS_MASS		0x08
    438      1.41  augustss #define  UISUBCLASS_RBC		1
    439      1.41  augustss #define  UISUBCLASS_SFF8020I	2
    440      1.41  augustss #define  UISUBCLASS_QIC157	3
    441      1.41  augustss #define  UISUBCLASS_UFI		4
    442      1.41  augustss #define  UISUBCLASS_SFF8070I	5
    443      1.41  augustss #define  UISUBCLASS_SCSI	6
    444      1.41  augustss #define  UIPROTO_MASS_CBI_I	0
    445      1.41  augustss #define  UIPROTO_MASS_CBI	1
    446  1.51.4.2   thorpej #define  UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
    447  1.51.4.2   thorpej #define  UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
    448      1.41  augustss 
    449      1.41  augustss #define UICLASS_HUB		0x09
    450      1.41  augustss #define  UISUBCLASS_HUB		0
    451  1.51.4.2   thorpej #define  UIPROTO_FSHUB		0
    452  1.51.4.2   thorpej #define  UIPROTO_HSHUBSTT	0 /* Yes, same as previous */
    453  1.51.4.2   thorpej #define  UIPROTO_HSHUBMTT	1
    454      1.41  augustss 
    455      1.41  augustss #define UICLASS_CDC_DATA	0x0a
    456      1.41  augustss #define  UISUBCLASS_DATA		0
    457      1.41  augustss #define   UIPROTO_DATA_ISDNBRI		0x30    /* Physical iface */
    458      1.41  augustss #define   UIPROTO_DATA_HDLC		0x31    /* HDLC */
    459      1.41  augustss #define   UIPROTO_DATA_TRANSPARENT	0x32    /* Transparent */
    460      1.41  augustss #define   UIPROTO_DATA_Q921M		0x50    /* Management for Q921 */
    461      1.41  augustss #define   UIPROTO_DATA_Q921		0x51    /* Data for Q921 */
    462      1.41  augustss #define   UIPROTO_DATA_Q921TM		0x52    /* TEI multiplexer for Q921 */
    463      1.41  augustss #define   UIPROTO_DATA_V42BIS		0x90    /* Data compression */
    464      1.41  augustss #define   UIPROTO_DATA_Q931		0x91    /* Euro-ISDN */
    465      1.41  augustss #define   UIPROTO_DATA_V120		0x92    /* V.24 rate adaption */
    466      1.41  augustss #define   UIPROTO_DATA_CAPI		0x93    /* CAPI 2.0 commands */
    467      1.41  augustss #define   UIPROTO_DATA_HOST_BASED	0xfd    /* Host based driver */
    468      1.41  augustss #define   UIPROTO_DATA_PUF		0xfe    /* see Prot. Unit Func. Desc.*/
    469      1.41  augustss #define   UIPROTO_DATA_VENDOR		0xff    /* Vendor specific */
    470      1.41  augustss 
    471      1.41  augustss #define UICLASS_FIRM_UPD	0x0c
    472      1.41  augustss 
    473      1.41  augustss #define UICLASS_APPL_SPEC	0xfe
    474  1.51.4.2   thorpej #define  UISUBCLASS_FIRMWARE_DOWNLOAD	1
    475  1.51.4.2   thorpej #define  UISUBCLASS_IRDA		2
    476  1.51.4.2   thorpej #define  UIPROTO_IRDA			0
    477  1.51.4.2   thorpej 
    478      1.41  augustss #define UICLASS_VENDOR		0xff
    479      1.36  augustss 
    480       1.1  augustss 
    481       1.1  augustss #define USB_HUB_MAX_DEPTH 5
    482       1.1  augustss 
    483       1.6  augustss /*
    484       1.6  augustss  * Minimum time a device needs to be powered down to go through
    485      1.11  augustss  * a power cycle.  XXX Are these time in the spec?
    486       1.6  augustss  */
    487      1.11  augustss #define USB_POWER_DOWN_TIME	200 /* ms */
    488       1.9  augustss #define USB_PORT_POWER_DOWN_TIME	100 /* ms */
    489       1.6  augustss 
    490       1.8  augustss #if 0
    491       1.9  augustss /* These are the values from the spec. */
    492       1.1  augustss #define USB_PORT_RESET_DELAY	10  /* ms */
    493  1.51.4.2   thorpej #define USB_PORT_ROOT_RESET_DELAY 50  /* ms */
    494       1.8  augustss #define USB_PORT_RESET_SETTLE	10  /* ms */
    495       1.1  augustss #define USB_PORT_POWERUP_DELAY	100 /* ms */
    496       1.8  augustss #define USB_SET_ADDRESS_SETTLE	2   /* ms */
    497      1.44  augustss #define USB_RESUME_DELAY	(20*5)  /* ms */
    498      1.22  augustss #define USB_RESUME_WAIT		10  /* ms */
    499      1.22  augustss #define USB_RESUME_RECOVERY	10  /* ms */
    500      1.45  augustss #define USB_EXTRA_POWER_UP_TIME	0   /* ms */
    501       1.8  augustss #else
    502       1.9  augustss /* Allow for marginal (i.e. non-conforming) devices. */
    503      1.18  augustss #define USB_PORT_RESET_DELAY	50  /* ms */
    504  1.51.4.2   thorpej #define USB_PORT_ROOT_RESET_DELAY 250  /* ms */
    505      1.11  augustss #define USB_PORT_RESET_RECOVERY	50  /* ms */
    506  1.51.4.2   thorpej #define USB_PORT_POWERUP_DELAY	300 /* ms */
    507       1.8  augustss #define USB_SET_ADDRESS_SETTLE	10  /* ms */
    508      1.22  augustss #define USB_RESUME_DELAY	(50*5)  /* ms */
    509      1.22  augustss #define USB_RESUME_WAIT		50  /* ms */
    510      1.22  augustss #define USB_RESUME_RECOVERY	50  /* ms */
    511      1.45  augustss #define USB_EXTRA_POWER_UP_TIME	20  /* ms */
    512       1.8  augustss #endif
    513       1.1  augustss 
    514       1.1  augustss #define USB_MIN_POWER		100 /* mA */
    515       1.1  augustss #define USB_MAX_POWER		500 /* mA */
    516       1.1  augustss 
    517      1.11  augustss #define USB_BUS_RESET_DELAY	100 /* ms XXX?*/
    518      1.47  augustss 
    519      1.47  augustss 
    520      1.47  augustss #define USB_UNCONFIG_NO 0
    521      1.47  augustss #define USB_UNCONFIG_INDEX (-1)
    522       1.1  augustss 
    523       1.1  augustss /*** ioctl() related stuff ***/
    524       1.1  augustss 
    525       1.1  augustss struct usb_ctl_request {
    526       1.1  augustss 	int	addr;
    527       1.1  augustss 	usb_device_request_t request;
    528       1.1  augustss 	void	*data;
    529      1.12  augustss 	int	flags;
    530      1.33  augustss #define USBD_SHORT_XFER_OK	0x04	/* allow short reads */
    531      1.17  augustss 	int	actlen;		/* actual length transferred */
    532       1.1  augustss };
    533       1.1  augustss 
    534       1.6  augustss struct usb_alt_interface {
    535       1.7  augustss 	int	config_index;
    536       1.6  augustss 	int	interface_index;
    537       1.6  augustss 	int	alt_no;
    538       1.6  augustss };
    539       1.6  augustss 
    540       1.6  augustss #define USB_CURRENT_CONFIG_INDEX (-1)
    541       1.6  augustss #define USB_CURRENT_ALT_INDEX (-1)
    542       1.6  augustss 
    543       1.6  augustss struct usb_config_desc {
    544       1.6  augustss 	int	config_index;
    545       1.6  augustss 	usb_config_descriptor_t desc;
    546       1.6  augustss };
    547       1.6  augustss 
    548       1.6  augustss struct usb_interface_desc {
    549       1.6  augustss 	int	config_index;
    550       1.6  augustss 	int	interface_index;
    551       1.6  augustss 	int	alt_index;
    552       1.6  augustss 	usb_interface_descriptor_t desc;
    553       1.6  augustss };
    554       1.6  augustss 
    555       1.6  augustss struct usb_endpoint_desc {
    556       1.6  augustss 	int	config_index;
    557       1.6  augustss 	int	interface_index;
    558       1.6  augustss 	int	alt_index;
    559       1.6  augustss 	int	endpoint_index;
    560       1.6  augustss 	usb_endpoint_descriptor_t desc;
    561       1.6  augustss };
    562       1.6  augustss 
    563       1.6  augustss struct usb_full_desc {
    564       1.6  augustss 	int	config_index;
    565       1.6  augustss 	u_int	size;
    566       1.6  augustss 	u_char	*data;
    567       1.1  augustss };
    568       1.1  augustss 
    569       1.7  augustss struct usb_string_desc {
    570       1.7  augustss 	int	string_index;
    571       1.7  augustss 	int	language_id;
    572       1.7  augustss 	usb_string_descriptor_t desc;
    573       1.7  augustss };
    574       1.7  augustss 
    575       1.1  augustss struct usb_ctl_report_desc {
    576       1.1  augustss 	int	size;
    577       1.1  augustss 	u_char	data[1024];	/* filled data size will vary */
    578       1.1  augustss };
    579       1.1  augustss 
    580      1.40  augustss typedef struct { u_int32_t cookie; } usb_event_cookie_t;
    581      1.40  augustss 
    582      1.40  augustss #define USB_MAX_DEVNAMES 4
    583      1.40  augustss #define USB_MAX_DEVNAMELEN 16
    584       1.1  augustss struct usb_device_info {
    585      1.40  augustss 	u_int8_t	bus;
    586      1.14  augustss 	u_int8_t	addr;	/* device address */
    587      1.40  augustss 	usb_event_cookie_t cookie;
    588      1.14  augustss 	char		product[USB_MAX_STRING_LEN];
    589      1.14  augustss 	char		vendor[USB_MAX_STRING_LEN];
    590      1.20  augustss 	char		release[8];
    591      1.14  augustss 	u_int16_t	productNo;
    592      1.14  augustss 	u_int16_t	vendorNo;
    593      1.40  augustss 	u_int16_t	releaseNo;
    594      1.14  augustss 	u_int8_t	class;
    595      1.40  augustss 	u_int8_t	subclass;
    596      1.40  augustss 	u_int8_t	protocol;
    597      1.14  augustss 	u_int8_t	config;
    598  1.51.4.2   thorpej 	u_int8_t	speed;
    599  1.51.4.2   thorpej #define USB_SPEED_LOW  1
    600  1.51.4.2   thorpej #define USB_SPEED_FULL 2
    601  1.51.4.2   thorpej #define USB_SPEED_HIGH 3
    602      1.14  augustss 	int		power;	/* power consumption in mA, 0 if selfpowered */
    603      1.14  augustss 	int		nports;
    604      1.40  augustss 	char		devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
    605      1.14  augustss 	u_int8_t	ports[16];/* hub only: addresses of devices on ports */
    606       1.1  augustss #define USB_PORT_ENABLED 0xff
    607       1.1  augustss #define USB_PORT_SUSPENDED 0xfe
    608       1.1  augustss #define USB_PORT_POWERED 0xfd
    609       1.1  augustss #define USB_PORT_DISABLED 0xfc
    610       1.1  augustss };
    611       1.1  augustss 
    612       1.2  augustss struct usb_ctl_report {
    613      1.35  augustss 	int	report;
    614       1.2  augustss 	u_char	data[1024];	/* filled data size will vary */
    615       1.2  augustss };
    616       1.2  augustss 
    617       1.3  augustss struct usb_device_stats {
    618       1.3  augustss 	u_long	requests[4];	/* indexed by transfer type UE_* */
    619      1.35  augustss };
    620      1.35  augustss 
    621      1.35  augustss /* Events that can be read from /dev/usb */
    622      1.35  augustss struct usb_event {
    623      1.35  augustss 	int			ue_type;
    624      1.40  augustss #define USB_EVENT_CTRLR_ATTACH 1
    625      1.40  augustss #define USB_EVENT_CTRLR_DETACH 2
    626      1.40  augustss #define USB_EVENT_DEVICE_ATTACH 3
    627      1.40  augustss #define USB_EVENT_DEVICE_DETACH 4
    628      1.40  augustss #define USB_EVENT_DRIVER_ATTACH 5
    629      1.40  augustss #define USB_EVENT_DRIVER_DETACH 6
    630      1.51  augustss #define USB_EVENT_IS_ATTACH(n) ((n) == USB_EVENT_CTRLR_ATTACH || (n) == USB_EVENT_DEVICE_ATTACH || (n) == USB_EVENT_DRIVER_ATTACH)
    631      1.35  augustss 	struct timespec		ue_time;
    632      1.40  augustss 	union {
    633      1.40  augustss 		struct {
    634      1.40  augustss 			int			ue_bus;
    635      1.40  augustss 		} ue_ctrlr;
    636      1.40  augustss 		struct usb_device_info		ue_device;
    637      1.40  augustss 		struct {
    638      1.40  augustss 			usb_event_cookie_t	ue_cookie;
    639      1.40  augustss 			char			ue_devname[16];
    640      1.40  augustss 		} ue_driver;
    641      1.40  augustss 	} u;
    642       1.3  augustss };
    643       1.3  augustss 
    644       1.1  augustss /* USB controller */
    645       1.1  augustss #define USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
    646       1.1  augustss #define USB_SETDEBUG		_IOW ('U', 2, int)
    647       1.1  augustss #define USB_DISCOVER		_IO  ('U', 3)
    648       1.1  augustss #define USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
    649       1.3  augustss #define USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
    650       1.1  augustss 
    651       1.1  augustss /* Generic HID device */
    652       1.1  augustss #define USB_GET_REPORT_DESC	_IOR ('U', 21, struct usb_ctl_report_desc)
    653       1.2  augustss #define USB_SET_IMMED		_IOW ('U', 22, int)
    654       1.2  augustss #define USB_GET_REPORT		_IOWR('U', 23, struct usb_ctl_report)
    655      1.42  augustss #define USB_SET_REPORT		_IOW ('U', 24, struct usb_ctl_report)
    656  1.51.4.2   thorpej #define USB_GET_REPORT_ID	_IOR ('U', 25, int)
    657       1.1  augustss 
    658       1.1  augustss /* Generic USB device */
    659       1.6  augustss #define USB_GET_CONFIG		_IOR ('U', 100, int)
    660       1.6  augustss #define USB_SET_CONFIG		_IOW ('U', 101, int)
    661       1.6  augustss #define USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
    662       1.7  augustss #define USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
    663       1.6  augustss #define USB_GET_NO_ALT		_IOWR('U', 104, struct usb_alt_interface)
    664       1.6  augustss #define USB_GET_DEVICE_DESC	_IOR ('U', 105, usb_device_descriptor_t)
    665       1.7  augustss #define USB_GET_CONFIG_DESC	_IOWR('U', 106, struct usb_config_desc)
    666       1.6  augustss #define USB_GET_INTERFACE_DESC	_IOWR('U', 107, struct usb_interface_desc)
    667       1.6  augustss #define USB_GET_ENDPOINT_DESC	_IOWR('U', 108, struct usb_endpoint_desc)
    668       1.7  augustss #define USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_full_desc)
    669       1.7  augustss #define USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_string_desc)
    670       1.7  augustss #define USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
    671       1.7  augustss #define USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
    672      1.16  augustss #define USB_SET_SHORT_XFER	_IOW ('U', 113, int)
    673      1.29  augustss #define USB_SET_TIMEOUT		_IOW ('U', 114, int)
    674      1.24  augustss 
    675      1.24  augustss /* Modem device */
    676      1.24  augustss #define USB_GET_CM_OVER_DATA	_IOR ('U', 130, int)
    677      1.24  augustss #define USB_SET_CM_OVER_DATA	_IOW ('U', 131, int)
    678       1.1  augustss 
    679       1.1  augustss #endif /* _USB_H_ */
    680