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