xref: /openbsd-src/share/man/man4/ugen.4 (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1.\"	$OpenBSD: ugen.4,v 1.15 2008/06/26 05:42:07 ray Exp $
2.\"	$NetBSD: ugen.4,v 1.7 1999/07/30 01:32:05 augustss Exp $
3.\"
4.\" Copyright (c) 1999 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.
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.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29.\" POSSIBILITY OF SUCH DAMAGE.
30.\"
31.Dd $Mdocdate: June 26 2008 $
32.Dt UGEN 4
33.Os
34.Sh NAME
35.Nm ugen
36.Nd USB generic device support
37.Sh SYNOPSIS
38.Cd "ugen* at uhub?"
39.Sh DESCRIPTION
40The
41.Nm
42driver provides support for all USB devices that do not have
43a special driver.
44It supports access to all parts of the device, but not in a way that is as
45convenient as a special purpose driver.
46.Pp
47There can be up to 127 USB devices connected to a USB bus.
48Each USB device can have up to 16 endpoints.
49Each of these endpoints will communicate in one of four different modes:
50control, isochronous, bulk, or interrupt.
51Each of the endpoints will have a different device node.
52The four least significant bits in the minor device number determine which
53endpoint the device accesses and the rest of the bits determine which
54USB device.
55.Pp
56If an endpoint address is used both for input and output the device
57can be opened for both read or write.
58.Pp
59To find out what endpoints exist there are a series of
60.Xr ioctl 2
61operations available for the control endpoint that return the USB descriptors
62of the device, configurations, interfaces, and endpoints.
63.Pp
64The control transfer mode can only happen on the control endpoint,
65which is always endpoint 0.
66Control requests are issued by
67.Xr ioctl 2
68calls.
69.\" .Pp
70.\" The isochronous transfer mode can be in or out depending on the
71.\" endpoint.  To perform I/O on an isochronous endpoint
72.\" .Xr read 2
73.\" and
74.\" .Xr write 2
75.\" should be used.
76.\" Before any I/O operations can take place the transfer rate in
77.\" bytes/second has to be set.  This is done with
78.\" .Xr ioctl 2
79.\" .Dv USB_SET_ISO_RATE .
80.\" Performing this call sets up a buffer corresponding to
81.\" about 1 second of data.
82.Pp
83The bulk transfer mode can be in or out depending on the
84endpoint.
85To perform I/O on a bulk endpoint
86.Xr read 2
87and
88.Xr write 2
89should be used.
90All I/O operations on a bulk endpoint are unbuffered.
91.Pp
92The interrupt transfer mode can only be in.
93To perform input from an interrupt endpoint
94.Xr read 2
95should be used.
96A moderate amount of buffering is done by the driver.
97.Pp
98All endpoints handle the following
99.Xr ioctl 2
100calls:
101.Pp
102.Bl -tag -width indent -compact
103.It Dv USB_SET_SHORT_XFER (int)
104Allow short read transfer.
105Normally a transfer from the device which is shorter than the request
106specified is reported as an error.
107.Pp
108.It Dv USB_SET_TIMEOUT (int)
109Set the timeout on the device operations, the time is specified
110in milliseconds.
111The value 0 is used to indicate that there is no timeout.
112.El
113.Pp
114The control endpoint (endpoint 0) handles the following
115.Xr ioctl 2
116calls:
117.Pp
118.Bl -tag -width indent -compact
119.It Dv USB_GET_CONFIG (int)
120Get the device configuration number.
121.Pp
122.It Dv USB_SET_CONFIG (int)
123Set the device into the given configuration number.
124This operation can only be performed when the control endpoint
125is the sole open endpoint.
126.Pp
127.It Dv USB_GET_ALTINTERFACE (struct usb_alt_interface)
128Get the alternative setting number for the interface with the given
129index.
130The
131.Fa uai_config_index
132is ignored in this call.
133.Bd -literal
134struct usb_alt_interface {
135	int	uai_config_index;
136	int	uai_interface_index;
137	int	uai_alt_no;
138};
139.Ed
140.Pp
141.It Dv USB_SET_ALTINTERFACE (struct usb_alt_interface)
142Set the alternative setting to the given number in the interface with the
143given index.
144The
145.Fa uai_config_index
146is ignored in this call.
147.Pp
148This operation can only be performed when no endpoints for the interface
149are open.
150.Pp
151.It Dv USB_GET_NO_ALT (struct usb_alt_interface)
152Return the number of different alternate settings in the
153.Fa uai_alt_no
154field.
155.Pp
156.It Dv USB_GET_DEVICE_DESC (usb_device_descriptor_t)
157Return the device descriptor.
158.Pp
159.It Dv USB_GET_CONFIG_DESC (struct usb_config_desc)
160Return the descriptor for the configuration with the given index.
161For convenience the current configuration can be specified by
162.Dv USB_CURRENT_CONFIG_INDEX .
163.Bd -literal
164struct usb_config_desc {
165	int	ucd_config_index;
166	usb_config_descriptor_t ucd_desc;
167};
168.Ed
169.Pp
170.It Dv USB_GET_INTERFACE_DESC (struct usb_interface_desc)
171Return the interface descriptor for an interface specified by its
172configuration index, interface index, and alternative index.
173For convenience the current alternative can be specified by
174.Dv USB_CURRENT_ALT_INDEX .
175.Bd -literal
176struct usb_interface_desc {
177	int	uid_config_index;
178	int	uid_interface_index;
179	int	uid_alt_index;
180	usb_interface_descriptor_t uid_desc;
181};
182.Ed
183.Pp
184.It Dv USB_GET_ENDPOINT_DESC (struct usb_endpoint_desc)
185Return the endpoint descriptor for the endpoint specified by its
186configuration index, interface index, alternative index, and
187endpoint index.
188.Bd -literal
189struct usb_endpoint_desc {
190	int	ued_config_index;
191	int	ued_interface_index;
192	int	ued_alt_index;
193	int	ued_endpoint_index;
194	usb_endpoint_descriptor_t ued_desc;
195};
196.Ed
197.Pp
198.It Dv USB_GET_FULL_DESC (struct usb_full_desc)
199Return all the descriptors for the given configuration.
200.Bd -literal
201struct usb_full_desc {
202	int	ufd_config_index;
203	u_int	ufd_size;
204	u_char	*ufd_data;
205};
206.Ed
207.Pp
208The
209.Fa ufd_data
210field should point to a memory area of the size given in the
211.Fa ufd_size
212field.
213The proper size can be determined by first issuing a
214.Dv USB_GET_CONFIG_DESC
215and inspecting the
216.Fa wTotalLength
217field.
218.Pp
219.It Dv USB_GET_STRING_DESC (struct usb_string_desc)
220Get a string descriptor for the given language id and
221string index.
222.Bd -literal
223struct usb_string_desc {
224	int	usd_string_index;
225	int	usd_language_id;
226	usb_string_descriptor_t usd_desc;
227};
228.Ed
229.Pp
230.It Dv USB_DO_REQUEST
231Send a USB request to the device on the control endpoint.
232Any data sent to/from the device is located at
233.Fa ucr_data .
234The size of the transferred data is determined from the
235.Fa ucr_request .
236The
237.Fa ucr_addr
238field is ignored in this call.
239.Bd -literal
240struct usb_ctl_request {
241	int	ucr_addr;
242	usb_device_request_t ucr_request;
243	void	*ucr_data;
244	int	ucr_flags;
245#define	USBD_SHORT_XFER_OK	0x04	/* allow short reads */
246	int	ucr_actlen;	/* actual length transferred */
247};
248.Ed
249.Pp
250This is a dangerous operation in that it can perform arbitrary operations
251on the device.
252Some of the most dangerous (e.g., changing the device address) are not
253allowed.
254.Pp
255.It Dv USB_GET_DEVICEINFO (struct usb_device_info)
256Get an information summary for the device.
257This call will not issue any USB transactions.
258.El
259.Pp
260Note that there are two different ways of addressing configurations, interfaces,
261alternatives, and endpoints: by index or by number.
262The index is the ordinal number (starting from 0) of the descriptor
263as presented by the device.
264The number is the respective number of the entity as found in its descriptor.
265Enumeration of descriptors use the index, getting and setting typically uses
266numbers.
267.Pp
268Example:
269All endpoints (except the control endpoint) for the current configuration
270can be found by iterating the
271.Fa interface_index
272from 0 to
273.Fa config_desc-\*(GtbNumInterface-1
274and for each of these iterating the
275.Fa endpoint_index
276from 0 to
277.Fa interface_desc-\*(GtbNumEndpoints-1 .
278The
279.Fa config_index
280should be set to
281.Dv USB_CURRENT_CONFIG_INDEX
282and
283.Fa alt_index
284should be set to
285.Dv USB_CURRENT_ALT_INDEX .
286.Sh FILES
287.Bl -tag -width Pa
288.It Pa /dev/ugenN.EE
289Endpoint
290.Pa EE
291of device
292.Pa N .
293.El
294.Sh SEE ALSO
295.Xr intro 4 ,
296.Xr uhub 4 ,
297.Xr usb 4
298.Sh HISTORY
299The
300.Nm
301driver
302appeared in
303.Ox 2.6 .
304.Sh BUGS
305The driver is not yet finished; there is no access to isochronous endpoints.
306