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