Home | History | Annotate | Line # | Download | only in usb
usb.h revision 1.48.2.1
      1  1.48.2.1   minoura /*	$NetBSD: usb.h,v 1.48.2.1 2000/06/22 17:08:42 minoura 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.48.2.1   minoura  * 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.48.2.1   minoura typedef u_int8_t uDWord[4];
     85  1.48.2.1   minoura 
     86  1.48.2.1   minoura #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
     87  1.48.2.1   minoura 
     88  1.48.2.1   minoura #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.48.2.1   minoura #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.48.2.1   minoura #define UGETDW(w) (*(u_int32_t *)(w))
    104  1.48.2.1   minoura #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
    105       1.1  augustss #endif
    106       1.1  augustss 
    107  1.48.2.1   minoura #define UPACKED __attribute__((__packed__))
    108  1.48.2.1   minoura 
    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.48.2.1   minoura } 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.36  augustss #define  UDESC_CS_DEVICE	0x21	/* class specific */
    162      1.36  augustss #define  UDESC_CS_CONFIG	0x22
    163      1.36  augustss #define  UDESC_CS_STRING	0x23
    164      1.36  augustss #define  UDESC_CS_INTERFACE	0x24
    165      1.36  augustss #define  UDESC_CS_ENDPOINT	0x25
    166      1.36  augustss #define  UDESC_HUB		0x29
    167       1.1  augustss #define UR_SET_DESCRIPTOR	0x07
    168       1.1  augustss #define UR_GET_CONFIG		0x08
    169       1.1  augustss #define UR_SET_CONFIG		0x09
    170       1.1  augustss #define UR_GET_INTERFACE	0x0a
    171       1.1  augustss #define UR_SET_INTERFACE	0x0b
    172       1.1  augustss #define UR_SYNCH_FRAME		0x0c
    173       1.1  augustss 
    174       1.1  augustss /* Feature numbers */
    175       1.8  augustss #define UF_ENDPOINT_HALT	0
    176       1.1  augustss #define UF_DEVICE_REMOTE_WAKEUP	1
    177       1.1  augustss 
    178       1.1  augustss #define USB_MAX_IPACKET		8 /* maximum size of the initial packet */
    179       1.1  augustss 
    180       1.1  augustss typedef struct {
    181       1.1  augustss 	uByte		bLength;
    182       1.1  augustss 	uByte		bDescriptorType;
    183       1.1  augustss 	uByte		bDescriptorSubtype;
    184  1.48.2.1   minoura } UPACKED usb_descriptor_t;
    185       1.1  augustss 
    186       1.1  augustss typedef struct {
    187       1.1  augustss 	uByte		bLength;
    188       1.1  augustss 	uByte		bDescriptorType;
    189       1.1  augustss 	uWord		bcdUSB;
    190       1.1  augustss 	uByte		bDeviceClass;
    191       1.1  augustss 	uByte		bDeviceSubClass;
    192       1.1  augustss 	uByte		bDeviceProtocol;
    193       1.1  augustss 	uByte		bMaxPacketSize;
    194       1.1  augustss 	/* The fields below are not part of the initial descriptor. */
    195       1.1  augustss 	uWord		idVendor;
    196       1.1  augustss 	uWord		idProduct;
    197       1.1  augustss 	uWord		bcdDevice;
    198       1.1  augustss 	uByte		iManufacturer;
    199       1.1  augustss 	uByte		iProduct;
    200       1.1  augustss 	uByte		iSerialNumber;
    201       1.1  augustss 	uByte		bNumConfigurations;
    202  1.48.2.1   minoura } UPACKED usb_device_descriptor_t;
    203       1.1  augustss #define USB_DEVICE_DESCRIPTOR_SIZE 18
    204       1.1  augustss 
    205       1.1  augustss typedef struct {
    206       1.1  augustss 	uByte		bLength;
    207       1.1  augustss 	uByte		bDescriptorType;
    208       1.1  augustss 	uWord		wTotalLength;
    209       1.1  augustss 	uByte		bNumInterface;
    210       1.1  augustss 	uByte		bConfigurationValue;
    211       1.1  augustss 	uByte		iConfiguration;
    212       1.1  augustss 	uByte		bmAttributes;
    213       1.1  augustss #define UC_BUS_POWERED		0x80
    214       1.1  augustss #define UC_SELF_POWERED		0x40
    215       1.1  augustss #define UC_REMOTE_WAKEUP	0x20
    216       1.1  augustss 	uByte		bMaxPower; /* max current in 2 mA units */
    217       1.1  augustss #define UC_POWER_FACTOR 2
    218  1.48.2.1   minoura } UPACKED usb_config_descriptor_t;
    219       1.1  augustss #define USB_CONFIG_DESCRIPTOR_SIZE 9
    220       1.1  augustss 
    221       1.1  augustss typedef struct {
    222       1.1  augustss 	uByte		bLength;
    223       1.1  augustss 	uByte		bDescriptorType;
    224       1.1  augustss 	uByte		bInterfaceNumber;
    225       1.1  augustss 	uByte		bAlternateSetting;
    226       1.1  augustss 	uByte		bNumEndpoints;
    227       1.1  augustss 	uByte		bInterfaceClass;
    228       1.1  augustss 	uByte		bInterfaceSubClass;
    229       1.1  augustss 	uByte		bInterfaceProtocol;
    230       1.1  augustss 	uByte		iInterface;
    231  1.48.2.1   minoura } UPACKED usb_interface_descriptor_t;
    232       1.1  augustss #define USB_INTERFACE_DESCRIPTOR_SIZE 9
    233       1.1  augustss 
    234       1.1  augustss typedef struct {
    235       1.1  augustss 	uByte		bLength;
    236       1.1  augustss 	uByte		bDescriptorType;
    237       1.1  augustss 	uByte		bEndpointAddress;
    238      1.31  augustss #define UE_GET_DIR(a)	((a) & 0x80)
    239      1.36  augustss #define UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
    240      1.31  augustss #define UE_DIR_IN	0x80
    241      1.31  augustss #define UE_DIR_OUT	0x00
    242       1.1  augustss #define UE_ADDR		0x0f
    243       1.6  augustss #define UE_GET_ADDR(a)	((a) & UE_ADDR)
    244       1.1  augustss 	uByte		bmAttributes;
    245       1.1  augustss #define UE_XFERTYPE	0x03
    246      1.10  augustss #define  UE_CONTROL	0x00
    247      1.10  augustss #define  UE_ISOCHRONOUS	0x01
    248      1.10  augustss #define  UE_BULK	0x02
    249      1.10  augustss #define  UE_INTERRUPT	0x03
    250      1.36  augustss #define UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
    251      1.10  augustss #define UE_ISO_TYPE	0x0c
    252      1.10  augustss #define  UE_ISO_ASYNC	0x04
    253      1.10  augustss #define  UE_ISO_ADAPT	0x08
    254      1.10  augustss #define  UE_ISO_SYNC	0x0c
    255      1.38  augustss #define UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
    256       1.1  augustss 	uWord		wMaxPacketSize;
    257       1.1  augustss 	uByte		bInterval;
    258  1.48.2.1   minoura } UPACKED usb_endpoint_descriptor_t;
    259       1.1  augustss #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
    260       1.1  augustss 
    261       1.1  augustss typedef struct {
    262       1.1  augustss 	uByte		bLength;
    263       1.1  augustss 	uByte		bDescriptorType;
    264       1.1  augustss 	uWord		bString[127];
    265  1.48.2.1   minoura } UPACKED usb_string_descriptor_t;
    266       1.1  augustss #define USB_MAX_STRING_LEN 128
    267      1.15  augustss #define USB_LANGUAGE_TABLE 0	/* # of the string language id table */
    268       1.1  augustss 
    269       1.1  augustss /* Hub specific request */
    270       1.1  augustss #define UR_GET_BUS_STATE	0x02
    271       1.1  augustss 
    272       1.1  augustss /* Hub features */
    273       1.1  augustss #define UHF_C_HUB_LOCAL_POWER	0
    274       1.1  augustss #define UHF_C_HUB_OVER_CURRENT	1
    275       1.1  augustss #define UHF_PORT_CONNECTION	0
    276       1.1  augustss #define UHF_PORT_ENABLE		1
    277       1.1  augustss #define UHF_PORT_SUSPEND	2
    278       1.1  augustss #define UHF_PORT_OVER_CURRENT	3
    279       1.1  augustss #define UHF_PORT_RESET		4
    280       1.1  augustss #define UHF_PORT_POWER		8
    281       1.1  augustss #define UHF_PORT_LOW_SPEED	9
    282       1.1  augustss #define UHF_C_PORT_CONNECTION	16
    283       1.1  augustss #define UHF_C_PORT_ENABLE	17
    284       1.1  augustss #define UHF_C_PORT_SUSPEND	18
    285       1.1  augustss #define UHF_C_PORT_OVER_CURRENT	19
    286       1.1  augustss #define UHF_C_PORT_RESET	20
    287       1.1  augustss 
    288       1.1  augustss typedef struct {
    289       1.1  augustss 	uByte		bDescLength;
    290       1.1  augustss 	uByte		bDescriptorType;
    291       1.1  augustss 	uByte		bNbrPorts;
    292       1.8  augustss 	uWord		wHubCharacteristics;
    293       1.1  augustss #define UHD_PWR			0x03
    294       1.1  augustss #define UHD_PWR_GANGED		0x00
    295       1.1  augustss #define UHD_PWR_INDIVIDUAL	0x01
    296       1.1  augustss #define UHD_PWR_NO_SWITCH	0x02
    297       1.1  augustss #define UHD_COMPOUND		0x04
    298       1.1  augustss #define UHD_OC			0x18
    299       1.1  augustss #define UHD_OC_GLOBAL		0x00
    300       1.1  augustss #define UHD_OC_INDIVIDUAL	0x08
    301       1.1  augustss #define UHD_OC_NONE		0x10
    302       1.1  augustss 	uByte		bPwrOn2PwrGood;	/* delay in 2 ms units */
    303       1.1  augustss #define UHD_PWRON_FACTOR 2
    304       1.1  augustss 	uByte		bHubContrCurrent;
    305       1.8  augustss 	uByte		DeviceRemovable[32]; /* max 255 ports */
    306       1.8  augustss #define UHD_NOT_REMOV(desc, i) \
    307       1.8  augustss     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
    308      1.46  augustss 	/* deprecated */ uByte		PortPowerCtrlMask[1];
    309  1.48.2.1   minoura } UPACKED usb_hub_descriptor_t;
    310      1.46  augustss #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
    311       1.1  augustss 
    312       1.1  augustss typedef struct {
    313       1.1  augustss 	uWord		wStatus;
    314       1.1  augustss /* Device status flags */
    315       1.1  augustss #define UDS_SELF_POWERED		0x0001
    316       1.1  augustss #define UDS_REMOTE_WAKEUP		0x0002
    317       1.8  augustss /* Endpoint status flags */
    318       1.8  augustss #define UES_HALT			0x0001
    319  1.48.2.1   minoura } UPACKED usb_status_t;
    320       1.1  augustss 
    321       1.1  augustss typedef struct {
    322       1.1  augustss 	uWord		wHubStatus;
    323       1.1  augustss #define UHS_LOCAL_POWER			0x0001
    324       1.1  augustss #define UHS_OVER_CURRENT		0x0002
    325       1.1  augustss 	uWord		wHubChange;
    326  1.48.2.1   minoura } UPACKED usb_hub_status_t;
    327       1.1  augustss 
    328       1.1  augustss typedef struct {
    329       1.1  augustss 	uWord		wPortStatus;
    330       1.1  augustss #define UPS_CURRENT_CONNECT_STATUS	0x0001
    331       1.1  augustss #define UPS_PORT_ENABLED		0x0002
    332       1.1  augustss #define UPS_SUSPEND			0x0004
    333       1.1  augustss #define UPS_OVERCURRENT_INDICATOR	0x0008
    334       1.1  augustss #define UPS_RESET			0x0010
    335       1.1  augustss #define UPS_PORT_POWER			0x0100
    336       1.1  augustss #define UPS_LOW_SPEED			0x0200
    337       1.1  augustss 	uWord		wPortChange;
    338       1.1  augustss #define UPS_C_CONNECT_STATUS		0x0001
    339       1.1  augustss #define UPS_C_PORT_ENABLED		0x0002
    340       1.1  augustss #define UPS_C_SUSPEND			0x0004
    341       1.1  augustss #define UPS_C_OVERCURRENT_INDICATOR	0x0008
    342       1.1  augustss #define UPS_C_PORT_RESET		0x0010
    343  1.48.2.1   minoura } UPACKED usb_port_status_t;
    344       1.1  augustss 
    345      1.41  augustss /* Device class codes */
    346      1.41  augustss #define UDCLASS_AUDIO		0x00
    347      1.41  augustss #define UDCLASS_COMM		0x02
    348      1.41  augustss #define UDCLASS_HID		0x00
    349      1.41  augustss #define UDCLASS_HUB		0x09
    350      1.41  augustss #define  UDSUBCLASS_HUB		0
    351      1.41  augustss #define UDCLASS_MASS		0x00
    352      1.41  augustss 
    353      1.41  augustss /* Interface class codes */
    354      1.41  augustss #define UICLASS_UNSPEC		0x00
    355      1.41  augustss 
    356      1.41  augustss #define UICLASS_AUDIO		0x01
    357      1.41  augustss #define  UISUBCLASS_AUDIOCONTROL	1
    358      1.41  augustss #define  UISUBCLASS_AUDIOSTREAM		2
    359      1.41  augustss #define  UISUBCLASS_MIDISTREAM		3
    360      1.41  augustss 
    361      1.41  augustss #define UICLASS_CDC		0x02 /* communication */
    362      1.41  augustss #define	 UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
    363      1.41  augustss #define  UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
    364      1.41  augustss #define	 UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
    365      1.41  augustss #define	 UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
    366      1.41  augustss #define	 UISUBCLASS_CAPI_CONTROLMODEL		5
    367      1.41  augustss #define	 UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
    368      1.41  augustss #define	 UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
    369      1.41  augustss #define   UIPROTO_CDC_AT			1
    370      1.41  augustss 
    371      1.41  augustss #define UICLASS_HID		0x03
    372      1.41  augustss #define  UISUBCLASS_BOOT	1
    373      1.41  augustss #define  UIPROTO_BOOT_KEYBOARD	1
    374      1.41  augustss 
    375      1.41  augustss #define UICLASS_PHYSICAL	0x05
    376      1.41  augustss 
    377      1.41  augustss #define UICLASS_PRINTER		0x07
    378      1.41  augustss #define  UISUBCLASS_PRINTER	1
    379      1.41  augustss #define  UIPROTO_PRINTER_UNI	1
    380      1.41  augustss #define  UIPROTO_PRINTER_BI	2
    381      1.41  augustss 
    382      1.41  augustss #define UICLASS_MASS		0x08
    383      1.41  augustss #define  UISUBCLASS_RBC		1
    384      1.41  augustss #define  UISUBCLASS_SFF8020I	2
    385      1.41  augustss #define  UISUBCLASS_QIC157	3
    386      1.41  augustss #define  UISUBCLASS_UFI		4
    387      1.41  augustss #define  UISUBCLASS_SFF8070I	5
    388      1.41  augustss #define  UISUBCLASS_SCSI	6
    389      1.41  augustss #define  UIPROTO_MASS_CBI_I	0
    390      1.41  augustss #define  UIPROTO_MASS_CBI	1
    391      1.43  augustss #define  UIPROTO_MASS_BBB	2
    392      1.43  augustss #define  UIPROTO_MASS_BBB_P	80	/* 'P' for the Iomega Zip drive */
    393      1.41  augustss 
    394      1.41  augustss #define UICLASS_HUB		0x09
    395      1.41  augustss #define  UISUBCLASS_HUB		0
    396      1.41  augustss 
    397      1.41  augustss #define UICLASS_CDC_DATA	0x0a
    398      1.41  augustss #define  UISUBCLASS_DATA		0
    399      1.41  augustss #define   UIPROTO_DATA_ISDNBRI		0x30    /* Physical iface */
    400      1.41  augustss #define   UIPROTO_DATA_HDLC		0x31    /* HDLC */
    401      1.41  augustss #define   UIPROTO_DATA_TRANSPARENT	0x32    /* Transparent */
    402      1.41  augustss #define   UIPROTO_DATA_Q921M		0x50    /* Management for Q921 */
    403      1.41  augustss #define   UIPROTO_DATA_Q921		0x51    /* Data for Q921 */
    404      1.41  augustss #define   UIPROTO_DATA_Q921TM		0x52    /* TEI multiplexer for Q921 */
    405      1.41  augustss #define   UIPROTO_DATA_V42BIS		0x90    /* Data compression */
    406      1.41  augustss #define   UIPROTO_DATA_Q931		0x91    /* Euro-ISDN */
    407      1.41  augustss #define   UIPROTO_DATA_V120		0x92    /* V.24 rate adaption */
    408      1.41  augustss #define   UIPROTO_DATA_CAPI		0x93    /* CAPI 2.0 commands */
    409      1.41  augustss #define   UIPROTO_DATA_HOST_BASED	0xfd    /* Host based driver */
    410      1.41  augustss #define   UIPROTO_DATA_PUF		0xfe    /* see Prot. Unit Func. Desc.*/
    411      1.41  augustss #define   UIPROTO_DATA_VENDOR		0xff    /* Vendor specific */
    412      1.41  augustss 
    413      1.41  augustss #define UICLASS_FIRM_UPD	0x0c
    414      1.41  augustss 
    415      1.41  augustss #define UICLASS_APPL_SPEC	0xfe
    416      1.41  augustss #define UICLASS_VENDOR		0xff
    417      1.36  augustss 
    418       1.1  augustss 
    419       1.1  augustss #define USB_HUB_MAX_DEPTH 5
    420       1.1  augustss 
    421       1.6  augustss /*
    422       1.6  augustss  * Minimum time a device needs to be powered down to go through
    423      1.11  augustss  * a power cycle.  XXX Are these time in the spec?
    424       1.6  augustss  */
    425      1.11  augustss #define USB_POWER_DOWN_TIME	200 /* ms */
    426       1.9  augustss #define USB_PORT_POWER_DOWN_TIME	100 /* ms */
    427       1.6  augustss 
    428       1.8  augustss #if 0
    429       1.9  augustss /* These are the values from the spec. */
    430       1.1  augustss #define USB_PORT_RESET_DELAY	10  /* ms */
    431       1.8  augustss #define USB_PORT_RESET_SETTLE	10  /* ms */
    432       1.1  augustss #define USB_PORT_POWERUP_DELAY	100 /* ms */
    433       1.8  augustss #define USB_SET_ADDRESS_SETTLE	2   /* ms */
    434      1.44  augustss #define USB_RESUME_DELAY	(20*5)  /* ms */
    435      1.22  augustss #define USB_RESUME_WAIT		10  /* ms */
    436      1.22  augustss #define USB_RESUME_RECOVERY	10  /* ms */
    437      1.45  augustss #define USB_EXTRA_POWER_UP_TIME	0   /* ms */
    438       1.8  augustss #else
    439       1.9  augustss /* Allow for marginal (i.e. non-conforming) devices. */
    440      1.18  augustss #define USB_PORT_RESET_DELAY	50  /* ms */
    441      1.11  augustss #define USB_PORT_RESET_RECOVERY	50  /* ms */
    442       1.8  augustss #define USB_PORT_POWERUP_DELAY	200 /* ms */
    443       1.8  augustss #define USB_SET_ADDRESS_SETTLE	10  /* ms */
    444      1.22  augustss #define USB_RESUME_DELAY	(50*5)  /* ms */
    445      1.22  augustss #define USB_RESUME_WAIT		50  /* ms */
    446      1.22  augustss #define USB_RESUME_RECOVERY	50  /* ms */
    447      1.45  augustss #define USB_EXTRA_POWER_UP_TIME	20  /* ms */
    448       1.8  augustss #endif
    449       1.1  augustss 
    450       1.1  augustss #define USB_MIN_POWER		100 /* mA */
    451       1.1  augustss #define USB_MAX_POWER		500 /* mA */
    452       1.1  augustss 
    453      1.11  augustss #define USB_BUS_RESET_DELAY	100 /* ms XXX?*/
    454      1.47  augustss 
    455      1.47  augustss 
    456      1.47  augustss #define USB_UNCONFIG_NO 0
    457      1.47  augustss #define USB_UNCONFIG_INDEX (-1)
    458       1.1  augustss 
    459       1.1  augustss /*** ioctl() related stuff ***/
    460       1.1  augustss 
    461       1.1  augustss struct usb_ctl_request {
    462       1.1  augustss 	int	addr;
    463       1.1  augustss 	usb_device_request_t request;
    464       1.1  augustss 	void	*data;
    465      1.12  augustss 	int	flags;
    466      1.33  augustss #define USBD_SHORT_XFER_OK	0x04	/* allow short reads */
    467      1.17  augustss 	int	actlen;		/* actual length transferred */
    468       1.1  augustss };
    469       1.1  augustss 
    470       1.6  augustss struct usb_alt_interface {
    471       1.7  augustss 	int	config_index;
    472       1.6  augustss 	int	interface_index;
    473       1.6  augustss 	int	alt_no;
    474       1.6  augustss };
    475       1.6  augustss 
    476       1.6  augustss #define USB_CURRENT_CONFIG_INDEX (-1)
    477       1.6  augustss #define USB_CURRENT_ALT_INDEX (-1)
    478       1.6  augustss 
    479       1.6  augustss struct usb_config_desc {
    480       1.6  augustss 	int	config_index;
    481       1.6  augustss 	usb_config_descriptor_t desc;
    482       1.6  augustss };
    483       1.6  augustss 
    484       1.6  augustss struct usb_interface_desc {
    485       1.6  augustss 	int	config_index;
    486       1.6  augustss 	int	interface_index;
    487       1.6  augustss 	int	alt_index;
    488       1.6  augustss 	usb_interface_descriptor_t desc;
    489       1.6  augustss };
    490       1.6  augustss 
    491       1.6  augustss struct usb_endpoint_desc {
    492       1.6  augustss 	int	config_index;
    493       1.6  augustss 	int	interface_index;
    494       1.6  augustss 	int	alt_index;
    495       1.6  augustss 	int	endpoint_index;
    496       1.6  augustss 	usb_endpoint_descriptor_t desc;
    497       1.6  augustss };
    498       1.6  augustss 
    499       1.6  augustss struct usb_full_desc {
    500       1.6  augustss 	int	config_index;
    501       1.6  augustss 	u_int	size;
    502       1.6  augustss 	u_char	*data;
    503       1.1  augustss };
    504       1.1  augustss 
    505       1.7  augustss struct usb_string_desc {
    506       1.7  augustss 	int	string_index;
    507       1.7  augustss 	int	language_id;
    508       1.7  augustss 	usb_string_descriptor_t desc;
    509       1.7  augustss };
    510       1.7  augustss 
    511       1.1  augustss struct usb_ctl_report_desc {
    512       1.1  augustss 	int	size;
    513       1.1  augustss 	u_char	data[1024];	/* filled data size will vary */
    514       1.1  augustss };
    515       1.1  augustss 
    516      1.40  augustss typedef struct { u_int32_t cookie; } usb_event_cookie_t;
    517      1.40  augustss 
    518      1.40  augustss #define USB_MAX_DEVNAMES 4
    519      1.40  augustss #define USB_MAX_DEVNAMELEN 16
    520       1.1  augustss struct usb_device_info {
    521      1.40  augustss 	u_int8_t	bus;
    522      1.14  augustss 	u_int8_t	addr;	/* device address */
    523      1.40  augustss 	usb_event_cookie_t cookie;
    524      1.14  augustss 	char		product[USB_MAX_STRING_LEN];
    525      1.14  augustss 	char		vendor[USB_MAX_STRING_LEN];
    526      1.20  augustss 	char		release[8];
    527      1.14  augustss 	u_int16_t	productNo;
    528      1.14  augustss 	u_int16_t	vendorNo;
    529      1.40  augustss 	u_int16_t	releaseNo;
    530      1.14  augustss 	u_int8_t	class;
    531      1.40  augustss 	u_int8_t	subclass;
    532      1.40  augustss 	u_int8_t	protocol;
    533      1.14  augustss 	u_int8_t	config;
    534      1.14  augustss 	u_int8_t	lowspeed;
    535      1.14  augustss 	int		power;	/* power consumption in mA, 0 if selfpowered */
    536      1.14  augustss 	int		nports;
    537      1.40  augustss 	char		devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
    538      1.14  augustss 	u_int8_t	ports[16];/* hub only: addresses of devices on ports */
    539       1.1  augustss #define USB_PORT_ENABLED 0xff
    540       1.1  augustss #define USB_PORT_SUSPENDED 0xfe
    541       1.1  augustss #define USB_PORT_POWERED 0xfd
    542       1.1  augustss #define USB_PORT_DISABLED 0xfc
    543       1.1  augustss };
    544       1.1  augustss 
    545       1.2  augustss struct usb_ctl_report {
    546      1.35  augustss 	int	report;
    547       1.2  augustss 	u_char	data[1024];	/* filled data size will vary */
    548       1.2  augustss };
    549       1.2  augustss 
    550       1.3  augustss struct usb_device_stats {
    551       1.3  augustss 	u_long	requests[4];	/* indexed by transfer type UE_* */
    552      1.35  augustss };
    553      1.35  augustss 
    554      1.35  augustss /* Events that can be read from /dev/usb */
    555      1.35  augustss struct usb_event {
    556      1.35  augustss 	int			ue_type;
    557      1.40  augustss #define USB_EVENT_CTRLR_ATTACH 1
    558      1.40  augustss #define USB_EVENT_CTRLR_DETACH 2
    559      1.40  augustss #define USB_EVENT_DEVICE_ATTACH 3
    560      1.40  augustss #define USB_EVENT_DEVICE_DETACH 4
    561      1.40  augustss #define USB_EVENT_DRIVER_ATTACH 5
    562      1.40  augustss #define USB_EVENT_DRIVER_DETACH 6
    563      1.35  augustss 	struct timespec		ue_time;
    564      1.40  augustss 	union {
    565      1.40  augustss 		struct {
    566      1.40  augustss 			int			ue_bus;
    567      1.40  augustss 		} ue_ctrlr;
    568      1.40  augustss 		struct usb_device_info		ue_device;
    569      1.40  augustss 		struct {
    570      1.40  augustss 			usb_event_cookie_t	ue_cookie;
    571      1.40  augustss 			char			ue_devname[16];
    572      1.40  augustss 		} ue_driver;
    573      1.40  augustss 	} u;
    574       1.3  augustss };
    575       1.3  augustss 
    576       1.1  augustss /* USB controller */
    577       1.1  augustss #define USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
    578       1.1  augustss #define USB_SETDEBUG		_IOW ('U', 2, int)
    579       1.1  augustss #define USB_DISCOVER		_IO  ('U', 3)
    580       1.1  augustss #define USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
    581       1.3  augustss #define USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
    582       1.1  augustss 
    583       1.1  augustss /* Generic HID device */
    584       1.1  augustss #define USB_GET_REPORT_DESC	_IOR ('U', 21, struct usb_ctl_report_desc)
    585       1.2  augustss #define USB_SET_IMMED		_IOW ('U', 22, int)
    586       1.2  augustss #define USB_GET_REPORT		_IOWR('U', 23, struct usb_ctl_report)
    587      1.42  augustss #define USB_SET_REPORT		_IOW ('U', 24, struct usb_ctl_report)
    588       1.1  augustss 
    589       1.1  augustss /* Generic USB device */
    590       1.6  augustss #define USB_GET_CONFIG		_IOR ('U', 100, int)
    591       1.6  augustss #define USB_SET_CONFIG		_IOW ('U', 101, int)
    592       1.6  augustss #define USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
    593       1.7  augustss #define USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
    594       1.6  augustss #define USB_GET_NO_ALT		_IOWR('U', 104, struct usb_alt_interface)
    595       1.6  augustss #define USB_GET_DEVICE_DESC	_IOR ('U', 105, usb_device_descriptor_t)
    596       1.7  augustss #define USB_GET_CONFIG_DESC	_IOWR('U', 106, struct usb_config_desc)
    597       1.6  augustss #define USB_GET_INTERFACE_DESC	_IOWR('U', 107, struct usb_interface_desc)
    598       1.6  augustss #define USB_GET_ENDPOINT_DESC	_IOWR('U', 108, struct usb_endpoint_desc)
    599       1.7  augustss #define USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_full_desc)
    600       1.7  augustss #define USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_string_desc)
    601       1.7  augustss #define USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
    602       1.7  augustss #define USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
    603      1.16  augustss #define USB_SET_SHORT_XFER	_IOW ('U', 113, int)
    604      1.29  augustss #define USB_SET_TIMEOUT		_IOW ('U', 114, int)
    605      1.24  augustss 
    606      1.24  augustss /* Modem device */
    607      1.24  augustss #define USB_GET_CM_OVER_DATA	_IOR ('U', 130, int)
    608      1.24  augustss #define USB_SET_CM_OVER_DATA	_IOW ('U', 131, int)
    609       1.1  augustss 
    610       1.1  augustss #endif /* _USB_H_ */
    611