Home | History | Annotate | Line # | Download | only in usb
usbdi.h revision 1.1
      1 /*	$NetBSD: usbdi.h,v 1.1 1998/07/12 19:52:01 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Author: Lennart Augustsson <augustss (at) carlstedt.se>
      8  *         Carlstedt Research & Technology
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 typedef struct usbd_bus		*usbd_bus_handle;
     40 typedef struct usbd_device	*usbd_device_handle;
     41 typedef struct usbd_interface	*usbd_interface_handle;
     42 typedef struct usbd_pipe	*usbd_pipe_handle;
     43 typedef struct usbd_request	*usbd_request_handle;
     44 typedef void			*usbd_private_handle;
     45 
     46 typedef enum {
     47 	USBD_ENDPOINT_ACTIVE,
     48 	USBD_ENDPOINT_STALLED,
     49 } usbd_endpoint_state;
     50 
     51 typedef enum {
     52 	USBD_PIPE_ACTIVE,
     53 	USBD_PIPE_STALLED,
     54 	USBD_PIPE_IDLE,
     55 } usbd_pipe_state;
     56 
     57 typedef enum {
     58 	USBD_INTERFACE_ACTIVE,
     59 	USBD_INTERFACE_STALLED,
     60 	USBD_INTERFACE_IDLE,
     61 } usbd_interface_state;
     62 
     63 typedef enum {
     64 	USBD_DEVICE_ATTACHED,
     65 	USBD_DEVICE_POWERED,
     66 	USBD_DEVICE_DEFAULT,
     67 	USBD_DEVICE_ADDRESSED,
     68 	USBD_DEVICE_CONFIGURED,
     69 	USBD_DEVICE_SUSPENDED,
     70 } usbd_device_state;
     71 
     72 typedef enum {
     73 	USBD_NORMAL_COMPLETION = 0,
     74 	USBD_IN_PROGRESS,
     75 	/* errors */
     76 	USBD_PENDING_REQUESTS,
     77 	USBD_NOT_STARTED,
     78 	USBD_INVAL,
     79 	USBD_IS_IDLE,
     80 	USBD_NOMEM,
     81 	USBD_CANCELLED,
     82 	USBD_BAD_ADDRESS,
     83 	USBD_IN_USE,
     84 	USBD_INTERFACE_NOT_ACTIVE,
     85 	USBD_NO_ADDR,
     86 	USBD_SET_ADDR_FAILED,
     87 	USBD_NO_POWER,
     88 	USBD_TOO_DEEP,
     89 	USBD_IOERROR,
     90 	USBD_NOT_CONFIGURED,
     91 	USBD_TIMEOUT,
     92 	USBD_SHORT_XFER,
     93 	USBD_STALLED,
     94 
     95 	USBD_XXX,
     96 } usbd_status;
     97 
     98 typedef int usbd_lock_token;
     99 
    100 typedef void (*usbd_callback) __P((usbd_request_handle, usbd_private_handle,
    101 				   usbd_status));
    102 
    103 /* Open flags */
    104 #define USBD_EXCLUSIVE_USE	0x01
    105 
    106 /* Request flags */
    107 #define USBD_XFER_OUT		0x01
    108 #define USBD_XFER_IN		0x02
    109 #define USBD_SHORT_XFER_OK	0x04
    110 
    111 #define USBD_NO_TIMEOUT 0
    112 #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
    113 
    114 usbd_status usbd_open_pipe
    115 	__P((usbd_interface_handle iface, u_int8_t address,
    116 	     u_int8_t flags, usbd_pipe_handle *pipe));
    117 usbd_status usbd_close_pipe	__P((usbd_pipe_handle pipe));
    118 usbd_status usbd_transfer	__P((usbd_request_handle req));
    119 usbd_request_handle usbd_alloc_request	__P((void));
    120 usbd_status usbd_free_request	__P((usbd_request_handle reqh));
    121 usbd_status usbd_setup_request
    122 	__P((usbd_request_handle reqh, usbd_pipe_handle pipe,
    123 	     usbd_private_handle priv, void *buffer,
    124 	     u_int32_t length, u_int16_t flags, u_int32_t timeout,
    125 	     usbd_callback));
    126 usbd_status usbd_setup_device_request
    127 	__P((usbd_request_handle reqh, usb_device_request_t *req));
    128 usbd_status usbd_setup_default_request
    129 	__P((usbd_request_handle reqh, usbd_device_handle dev,
    130 	     usbd_private_handle priv, u_int32_t timeout,
    131 	     usb_device_request_t *req,  void *buffer,
    132 	     u_int32_t length, u_int16_t flags, usbd_callback));
    133 usbd_status usbd_set_request_timeout
    134 	__P((usbd_request_handle reqh, u_int32_t timeout));
    135 usbd_status usbd_get_request_status
    136 	__P((usbd_request_handle reqh, usbd_private_handle *priv,
    137 	     void **buffer, u_int32_t *count, usbd_status *status));
    138 usbd_status usbd_request_device_data
    139 	__P((usbd_request_handle reqh, usb_device_request_t *req));
    140 usb_descriptor_t *usbd_get_descriptor
    141 	__P((usbd_interface_handle *iface, u_int8_t desc_type));
    142 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
    143 	__P((usbd_interface_handle iface, u_int8_t address));
    144 usbd_status usbd_set_configuration
    145 	__P((usbd_device_handle dev, u_int16_t conf));
    146 usbd_status usbd_retry_request
    147 	__P((usbd_request_handle reqh, u_int32_t retry_count));
    148 usbd_status usbd_abort_pipe __P((usbd_pipe_handle pipe));
    149 usbd_status usbd_abort_interface __P((usbd_interface_handle iface));
    150 usbd_status usbd_reset_pipe __P((usbd_pipe_handle pipe));
    151 usbd_status usbd_reset_interface __P((usbd_interface_handle iface));
    152 usbd_status usbd_clear_endpoint_stall __P((usbd_pipe_handle pipe));
    153 usbd_status usbd_set_pipe_state
    154 	__P((usbd_pipe_handle pipe, usbd_pipe_state state));
    155 usbd_status usbd_get_pipe_state
    156 	__P((usbd_pipe_handle pipe, usbd_pipe_state *state,
    157 	     u_int32_t *endpoint_state, u_int32_t *request_count));
    158 usbd_status usbd_set_interface_state
    159 	__P((usbd_interface_handle iface, usbd_interface_state state));
    160 usbd_status usbd_get_interface_state
    161 	__P((usbd_interface_handle iface, usbd_interface_state *state));
    162 usbd_status usbd_get_device_state
    163 	__P((usbd_device_handle dev, usbd_device_state *state));
    164 usbd_status usbd_set_device_state
    165 	__P((usbd_device_handle dev, usbd_device_state state));
    166 usbd_status usbd_device_address
    167 	__P((usbd_device_handle dev, u_int8_t *address));
    168 usbd_status usbd_endpoint_address
    169 	__P((usbd_pipe_handle dev, u_int8_t *address));
    170 usbd_status usbd_endpoint_count
    171 	__P((usbd_interface_handle dev, u_int8_t *count));
    172 usbd_status usbd_interface_count
    173 	__P((usbd_device_handle dev, u_int8_t *count));
    174 u_int8_t usbd_bus_count __P((void));
    175 usbd_status usbd_get_bus_handle __P((u_int8_t index, usbd_bus_handle *bus));
    176 usbd_status usbd_get_root_hub
    177 	__P((usbd_bus_handle bus, usbd_device_handle *dev));
    178 usbd_status usbd_port_count __P((usbd_device_handle hub, u_int8_t *nports));
    179 usbd_status usbd_hub2device_handle
    180 	__P((usbd_device_handle hub, u_int8_t port, usbd_device_handle *dev));
    181 usbd_status usbd_request2pipe_handle
    182 	__P((usbd_request_handle reqh, usbd_pipe_handle *pipe));
    183 usbd_status usbd_pipe2interface_handle
    184 	__P((usbd_pipe_handle pipe, usbd_interface_handle *iface));
    185 usbd_status usbd_interface2device_handle
    186 	__P((usbd_interface_handle iface, usbd_device_handle *dev));
    187 usbd_status usbd_device2bus_handle
    188 	__P((usbd_device_handle dev, usbd_bus_handle *bus));
    189 usbd_status usbd_device2interface_handle
    190 	__P((usbd_device_handle dev, u_int8_t ifaceno,
    191 	     usbd_interface_handle *iface));
    192 usbd_status usbd_set_interface_private_handle
    193 	__P((usbd_interface_handle iface, usbd_private_handle priv));
    194 usbd_status usbd_get_interface_private_handle
    195 	__P((usbd_interface_handle iface, usbd_private_handle *priv));
    196 usbd_status usbd_reference_pipe __P((usbd_pipe_handle pipe));
    197 usbd_status usbd_dereference_pipe __P((usbd_pipe_handle pipe));
    198 usbd_lock_token usbd_lock __P((void));
    199 void usbd_unlock __P((usbd_lock_token tok));
    200 
    201 /* Non-standard */
    202 usbd_status usbd_sync_transfer	__P((usbd_request_handle req));
    203 usbd_status usbd_open_pipe_intr
    204 	__P((usbd_interface_handle iface, u_int8_t address,
    205 	     u_int8_t flags, usbd_pipe_handle *pipe,
    206 	     usbd_private_handle priv, void *buffer,
    207 	     u_int32_t length, usbd_callback));
    208 usbd_status usbd_do_request
    209 	__P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
    210 usb_interface_descriptor_t *usbd_get_interface_descriptor
    211 	__P((usbd_interface_handle iface));
    212 usb_config_descriptor_t *usbd_get_config_descriptor
    213 	__P((usbd_device_handle dev));
    214 usb_device_descriptor_t *usbd_get_device_descriptor
    215 	__P((usbd_device_handle dev));
    216 
    217 /* NetBSD attachment information */
    218 
    219 /* Attach data */
    220 struct usb_attach_arg {
    221 	int			port;
    222 	struct usbd_device     *device;
    223 	struct usbd_interface  *iface;
    224 	int			usegeneric;
    225 };
    226 
    227 /* Match codes. */
    228 /* First five codes is for a whole device. */
    229 #define UMATCH_VENDOR_PRODUCT_REV			14
    230 #define UMATCH_VENDOR_PRODUCT				13
    231 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			12
    232 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		11
    233 #define UMATCH_DEVCLASS_DEVSUBCLASS			10
    234 /* Next six codes are for interfaces. */
    235 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		 9
    236 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		 8
    237 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		 7
    238 #define UMATCH_VENDOR_IFACESUBCLASS			 6
    239 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	 5
    240 #define UMATCH_IFACECLASS_IFACESUBCLASS			 4
    241 #define UMATCH_IFACECLASS				 3
    242 #define UMATCH_IFACECLASS_GENERIC			 2
    243 /* Generic driver */
    244 #define UMATCH_GENERIC					 1
    245 /* No match */
    246 #define UMATCH_NONE					 0
    247 
    248 void usbd_devinfo __P((usbd_device_handle, int, char *));
    249 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle));
    250 void usbd_set_disco __P((usbd_pipe_handle, void (*)(void *), void *));
    251