2001-11-20 14:13:36 +00:00
|
|
|
.\" $NetBSD: ugen.4,v 1.13 2001/09/11 22:52:54 wiz 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.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2018-04-24 17:46:33 +00:00
|
|
|
.Dd April 24, 2018
|
2001-11-20 14:13:36 +00:00
|
|
|
.Dt UGEN 4
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm ugen
|
|
|
|
.Nd USB generic device support
|
|
|
|
.Sh SYNOPSIS
|
2012-07-22 21:43:46 +00:00
|
|
|
.Nm
|
|
|
|
is integrated into the
|
|
|
|
.Xr usb 4
|
|
|
|
kernel module.
|
2001-11-20 14:13:36 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
driver provides support for all USB devices that do not have
|
2001-11-22 11:56:54 +00:00
|
|
|
a special driver.
|
|
|
|
It supports access to all parts of the device,
|
2001-11-20 14:13:36 +00:00
|
|
|
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.
|
2001-11-22 11:56:54 +00:00
|
|
|
Each USB device can have up to 16 endpoints.
|
|
|
|
Each of these endpoints
|
2001-11-20 14:13:36 +00:00
|
|
|
will communicate in one of four different modes: control, isochronous,
|
2001-11-22 11:56:54 +00:00
|
|
|
bulk, or interrupt.
|
|
|
|
Each of the endpoints will have a different
|
|
|
|
device node.
|
|
|
|
The four least significant bits in the minor device
|
2012-07-22 21:43:46 +00:00
|
|
|
number determine which endpoint the device accesses, and the rest
|
|
|
|
of the bits determine which USB device.
|
2001-11-20 14:13:36 +00:00
|
|
|
.Pp
|
2012-07-22 21:43:46 +00:00
|
|
|
If an endpoint address is used both for input and output, the device
|
2001-11-20 14:13:36 +00:00
|
|
|
can be opened for both read or write.
|
|
|
|
.Pp
|
2012-07-22 21:43:46 +00:00
|
|
|
To find out which endpoints exist, there are a series of
|
2001-11-20 14:13:36 +00:00
|
|
|
.Xr ioctl 2
|
2012-07-22 21:43:46 +00:00
|
|
|
operations on the control endpoint that return the USB descriptors
|
2001-11-20 14:13:36 +00:00
|
|
|
of the device, configurations, interfaces, and endpoints.
|
|
|
|
.Pp
|
|
|
|
The control transfer mode can only happen on the control endpoint
|
2001-11-22 11:56:54 +00:00
|
|
|
which is always endpoint 0.
|
2012-07-22 21:43:46 +00:00
|
|
|
The control endpoint accepts a request
|
|
|
|
and may respond with an answer to such a request.
|
|
|
|
Control requests
|
2001-11-20 14:13:36 +00:00
|
|
|
are issued by
|
|
|
|
.Xr ioctl 2
|
|
|
|
calls.
|
|
|
|
.\" .Pp
|
|
|
|
.\" The isochronous transfer mode can be in or out depending on the
|
2001-11-22 11:56:54 +00:00
|
|
|
.\" endpoint.
|
|
|
|
.\" To perform I/O on an isochronous endpoint
|
2001-11-20 14:13:36 +00:00
|
|
|
.\" .Xr read 2
|
|
|
|
.\" and
|
|
|
|
.\" .Xr write 2
|
|
|
|
.\" should be used.
|
2001-11-22 11:56:54 +00:00
|
|
|
.\" Before any I/O operations can take place the transfer rate in
|
|
|
|
.\" bytes/second has to be set.
|
|
|
|
.\" This is done with
|
2001-11-20 14:13:36 +00:00
|
|
|
.\" .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
|
2001-11-22 11:56:54 +00:00
|
|
|
endpoint.
|
|
|
|
To perform I/O on a bulk endpoint
|
2001-11-20 14:13:36 +00:00
|
|
|
.Xr read 2
|
|
|
|
and
|
|
|
|
.Xr write 2
|
|
|
|
should be used.
|
2001-11-22 11:56:54 +00:00
|
|
|
All I/O operations on a bulk endpoint are unbuffered.
|
2001-11-20 14:13:36 +00:00
|
|
|
.Pp
|
2003-02-28 19:28:29 +00:00
|
|
|
The interrupt transfer mode can be in or out depending on the
|
|
|
|
endpoint.
|
|
|
|
To perform I/O on an interrupt endpoint
|
2001-11-20 14:13:36 +00:00
|
|
|
.Xr read 2
|
2003-02-28 19:28:29 +00:00
|
|
|
and
|
|
|
|
.Xr write 2
|
2001-11-22 11:56:54 +00:00
|
|
|
should be used.
|
|
|
|
A moderate amount of buffering is done
|
2001-11-20 14:13:36 +00:00
|
|
|
by the driver.
|
|
|
|
.Pp
|
|
|
|
All endpoints handle the following
|
|
|
|
.Xr ioctl 2
|
|
|
|
calls:
|
2001-11-22 11:56:54 +00:00
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Dv USB_SET_SHORT_XFER Pq Vt int
|
|
|
|
Allow short read transfer.
|
|
|
|
Normally a transfer from the device
|
2001-11-20 14:13:36 +00:00
|
|
|
which is shorter than the request specified is reported as an
|
|
|
|
error.
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_SET_TIMEOUT Pq Vt int
|
2012-07-22 21:43:46 +00:00
|
|
|
Set the timeout on the device operations
|
|
|
|
The time is specified in milliseconds.
|
2001-11-22 11:56:54 +00:00
|
|
|
The value 0 is used to indicate that there is
|
2001-11-20 14:13:36 +00:00
|
|
|
no timeout.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The control endpoint (endpoint 0) handles the following
|
|
|
|
.Xr ioctl 2
|
|
|
|
calls:
|
2001-11-22 11:56:54 +00:00
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Dv USB_GET_CONFIG Pq Vt int
|
2001-11-20 14:13:36 +00:00
|
|
|
Get the device configuration number.
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_SET_CONFIG Pq Vt int
|
2001-11-20 14:13:36 +00:00
|
|
|
Set the device into the given configuration number.
|
2001-11-22 11:56:54 +00:00
|
|
|
.Pp
|
2001-11-20 14:13:36 +00:00
|
|
|
This operation can only be performed when the control endpoint
|
|
|
|
is the sole open endpoint.
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_ALTINTERFACE Pq Vt "struct usb_alt_interface"
|
2001-11-20 14:13:36 +00:00
|
|
|
Get the alternative setting number for the interface with the given
|
|
|
|
index.
|
|
|
|
The
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va uai_config_index
|
2001-11-20 14:13:36 +00:00
|
|
|
is ignored in this call.
|
|
|
|
.Bd -literal
|
|
|
|
struct usb_alt_interface {
|
2003-09-24 04:53:50 +00:00
|
|
|
int uai_config_index;
|
|
|
|
int uai_interface_index;
|
|
|
|
int uai_alt_no;
|
2001-11-20 14:13:36 +00:00
|
|
|
};
|
|
|
|
.Ed
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_SET_ALTINTERFACE Pq Vt "struct usb_alt_interface"
|
2001-11-20 14:13:36 +00:00
|
|
|
Set the alternative setting to the given number in the interface with the
|
|
|
|
given index.
|
|
|
|
The
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va uai_config_index
|
2001-11-20 14:13:36 +00:00
|
|
|
is ignored in this call.
|
2001-11-22 11:56:54 +00:00
|
|
|
.Pp
|
2001-11-20 14:13:36 +00:00
|
|
|
This operation can only be performed when no endpoints for the interface
|
|
|
|
are open.
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_NO_ALT Pq Vt "struct usb_alt_interface"
|
2001-11-20 14:13:36 +00:00
|
|
|
Return the number of different alternate settings in the
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va uai_alt_no
|
2001-11-20 14:13:36 +00:00
|
|
|
field.
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_DEVICE_DESC Pq Vt usb_device_descriptor_t
|
2001-11-20 14:13:36 +00:00
|
|
|
Return the device descriptor.
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_CONFIG_DESC Pq Vt "struct usb_config_desc"
|
2001-11-20 14:13:36 +00:00
|
|
|
Return the descriptor for the configuration with the given index.
|
2012-07-22 21:43:46 +00:00
|
|
|
For convenience, the current configuration can be specified by
|
2001-11-20 14:13:36 +00:00
|
|
|
.Dv USB_CURRENT_CONFIG_INDEX .
|
|
|
|
.Bd -literal
|
|
|
|
struct usb_config_desc {
|
2003-09-24 04:53:50 +00:00
|
|
|
int ucd_config_index;
|
|
|
|
usb_config_descriptor_t ucd_desc;
|
2001-11-20 14:13:36 +00:00
|
|
|
};
|
|
|
|
.Ed
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_INTERFACE_DESC Pq Vt "struct usb_interface_desc"
|
2001-11-20 14:13:36 +00:00
|
|
|
Return the interface descriptor for an interface specified by its
|
|
|
|
configuration index, interface index, and alternative index.
|
2012-07-22 21:43:46 +00:00
|
|
|
For convenience, the current alternative can be specified by
|
2001-11-20 14:13:36 +00:00
|
|
|
.Dv USB_CURRENT_ALT_INDEX .
|
|
|
|
.Bd -literal
|
|
|
|
struct usb_interface_desc {
|
2003-09-24 04:53:50 +00:00
|
|
|
int uid_config_index;
|
|
|
|
int uid_interface_index;
|
|
|
|
int uid_alt_index;
|
|
|
|
usb_interface_descriptor_t uid_desc;
|
2001-11-20 14:13:36 +00:00
|
|
|
};
|
|
|
|
.Ed
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_ENDPOINT_DESC Pq Vt "struct usb_endpoint_desc"
|
2001-11-20 14:13:36 +00:00
|
|
|
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 {
|
2003-09-24 04:53:50 +00:00
|
|
|
int ued_config_index;
|
|
|
|
int ued_interface_index;
|
|
|
|
int ued_alt_index;
|
|
|
|
int ued_endpoint_index;
|
|
|
|
usb_endpoint_descriptor_t ued_desc;
|
2001-11-20 14:13:36 +00:00
|
|
|
};
|
|
|
|
.Ed
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_FULL_DESC Pq Vt "struct usb_full_desc"
|
2001-11-20 14:13:36 +00:00
|
|
|
Return all the descriptors for the given configuration.
|
|
|
|
.Bd -literal
|
|
|
|
struct usb_full_desc {
|
2003-09-24 04:53:50 +00:00
|
|
|
int ufd_config_index;
|
|
|
|
u_int ufd_size;
|
|
|
|
u_char *ufd_data;
|
2001-11-20 14:13:36 +00:00
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
The
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va ufd_data
|
2001-11-22 11:56:54 +00:00
|
|
|
field should point to a memory area of the size given in the
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va ufd_size
|
2001-11-22 11:56:54 +00:00
|
|
|
field.
|
|
|
|
The proper size can be determined by first issuing a
|
2001-11-20 14:13:36 +00:00
|
|
|
.Dv USB_GET_CONFIG_DESC
|
|
|
|
and inspecting the
|
2001-11-22 11:56:54 +00:00
|
|
|
.Va wTotalLength
|
2001-11-20 14:13:36 +00:00
|
|
|
field.
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_STRING_DESC Pq Vt "struct usb_string_desc"
|
|
|
|
Get a string descriptor for the given language ID and
|
2001-11-20 14:13:36 +00:00
|
|
|
string index.
|
|
|
|
.Bd -literal
|
|
|
|
struct usb_string_desc {
|
2003-09-24 04:53:50 +00:00
|
|
|
int usd_string_index;
|
|
|
|
int usd_language_id;
|
|
|
|
usb_string_descriptor_t usd_desc;
|
2001-11-20 14:13:36 +00:00
|
|
|
};
|
|
|
|
.Ed
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_DO_REQUEST Pq Vt "struct usb_ctl_request"
|
2001-11-20 14:13:36 +00:00
|
|
|
Send a USB request to the device on the control endpoint.
|
|
|
|
Any data sent to/from the device is located at
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va ucr_data .
|
2001-11-20 14:13:36 +00:00
|
|
|
The size of the transferred data is determined from the
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va ucr_request .
|
2001-11-20 14:13:36 +00:00
|
|
|
The
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va ucr_addr
|
2001-11-20 14:13:36 +00:00
|
|
|
field is ignored in this call.
|
|
|
|
The
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va ucr_flags
|
2001-11-20 14:13:36 +00:00
|
|
|
field can be used to flag that the request is allowed to
|
2012-07-22 21:43:46 +00:00
|
|
|
be shorter than the requested size, and
|
2003-09-24 05:55:59 +00:00
|
|
|
.Va ucr_actlen
|
2001-11-20 14:13:36 +00:00
|
|
|
will contain the actual size on completion.
|
|
|
|
.Bd -literal
|
|
|
|
struct usb_ctl_request {
|
2003-09-24 04:53:50 +00:00
|
|
|
int ucr_addr;
|
|
|
|
usb_device_request_t ucr_request;
|
|
|
|
void *ucr_data;
|
|
|
|
int ucr_flags;
|
2001-11-20 14:13:36 +00:00
|
|
|
#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
|
2003-09-24 04:53:50 +00:00
|
|
|
int ucr_actlen; /* actual length transferred */
|
2001-11-20 14:13:36 +00:00
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
This is a dangerous operation in that it can perform arbitrary operations
|
2001-11-22 11:56:54 +00:00
|
|
|
on the device.
|
|
|
|
Some of the most dangerous (e.g., changing the device
|
2001-11-20 14:13:36 +00:00
|
|
|
address) are not allowed.
|
2001-11-22 11:56:54 +00:00
|
|
|
.It Dv USB_GET_DEVICEINFO Pq Vt "struct usb_device_info"
|
|
|
|
Get an information summary for the device.
|
2012-07-22 21:43:46 +00:00
|
|
|
This call will not issue any USB transactions.
|
2001-11-20 14:13:36 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2012-07-22 21:43:46 +00:00
|
|
|
Note that there are two different ways of addressing configurations,
|
|
|
|
interfaces, alternatives, and endpoints: by index or by number.
|
2001-11-20 14:13:36 +00:00
|
|
|
The index is the ordinal number (starting from 0) of the descriptor
|
2001-11-22 11:56:54 +00:00
|
|
|
as presented by the device.
|
|
|
|
The number is the respective number of
|
|
|
|
the entity as found in its descriptor.
|
|
|
|
Enumeration of descriptors
|
2012-07-22 21:43:46 +00:00
|
|
|
uses the index, getting and setting typically uses numbers.
|
2001-11-20 14:13:36 +00:00
|
|
|
.Pp
|
|
|
|
Example:
|
2001-11-22 11:56:54 +00:00
|
|
|
all endpoints (except the control endpoint) for the current configuration
|
2001-11-20 14:13:36 +00:00
|
|
|
can be found by iterating the
|
2001-11-22 11:56:54 +00:00
|
|
|
.Va interface_index
|
2001-11-20 14:13:36 +00:00
|
|
|
from 0 to
|
2001-11-22 11:56:54 +00:00
|
|
|
.Va config_desc->bNumInterface Ns \-1
|
2012-07-22 21:43:46 +00:00
|
|
|
and for each of these, iterating the
|
2001-11-22 11:56:54 +00:00
|
|
|
.Va endpoint_index
|
2001-11-20 14:13:36 +00:00
|
|
|
from 0 to
|
2001-11-22 11:56:54 +00:00
|
|
|
.Va interface_desc->bNumEndpoints .
|
2001-11-20 14:13:36 +00:00
|
|
|
The
|
2001-11-22 11:56:54 +00:00
|
|
|
.Va config_index
|
2012-07-22 21:43:46 +00:00
|
|
|
should be set to
|
2001-11-20 14:13:36 +00:00
|
|
|
.Dv USB_CURRENT_CONFIG_INDEX
|
|
|
|
and
|
2001-11-22 11:56:54 +00:00
|
|
|
.Va alt_index
|
2001-11-20 14:13:36 +00:00
|
|
|
should be set to
|
|
|
|
.Dv USB_CURRENT_ALT_INDEX .
|
2018-04-24 17:46:33 +00:00
|
|
|
.Sh SYSCTL VARIABLES
|
|
|
|
The following variables are available as both
|
|
|
|
.Xr sysctl 8
|
|
|
|
variables and
|
|
|
|
.Xr loader 8
|
|
|
|
tunables:
|
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Va hw.usb.ugen.debug
|
2017-08-04 08:56:31 +00:00
|
|
|
Debug output level, where 0 is debugging disabled and larger values increase
|
|
|
|
debug message verbosity.
|
|
|
|
Default is 0.
|
2019-02-23 09:34:57 +00:00
|
|
|
.El
|
2001-11-20 14:13:36 +00:00
|
|
|
.Sh FILES
|
2014-05-16 16:28:09 +00:00
|
|
|
.Bl -tag -width ".Pa /dev/ugen Ns Ar N Ns Pa \&. Ns Ar E" -compact
|
|
|
|
.It Pa /dev/ugen Ns Ar N Ns Pa \&. Ns Ar E
|
2001-11-20 14:13:36 +00:00
|
|
|
Endpoint
|
2014-05-16 16:28:09 +00:00
|
|
|
.Ar E
|
2001-11-20 14:13:36 +00:00
|
|
|
of device
|
2001-11-22 11:56:54 +00:00
|
|
|
.Ar N .
|
2001-11-20 14:13:36 +00:00
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr usb 4
|
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
driver
|
|
|
|
appeared in
|
|
|
|
.Nx 1.4 .
|
|
|
|
.\" .Sh BUGS
|
|
|
|
.\" The driver is not yet finished; there is no access to isochronous endpoints.
|