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