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