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