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