1.\" $NetBSD: ugen.4,v 1.21 2005/11/23 08:56:08 augustss 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.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd November 22, 2005 38.Dt UGEN 4 39.Os 40.Sh NAME 41.Nm ugen 42.Nd USB generic device support 43.Sh SYNOPSIS 44.Cd "ugen* at uhub? flags N" 45.Sh DESCRIPTION 46The 47.Nm 48driver provides support for all USB devices that do not have 49a special driver. It supports access to all parts of the device, 50but not in a way that is as convenient as a special purpose driver. 51.Pp 52Normally the 53.Nm 54driver is used when no other driver attaches to a device. 55If 56.Dq flags 1 57is specified, the 58.Nm 59will instead attach with a very high priority and always be used. 60Together with the 61.Cd vendor 62and 63.Cd product 64locators this can be used to force the 65.Nm 66driver to be used for a certain 67device. 68.Pp 69There can be up to 127 USB devices connected to a USB bus. 70Each USB device can have up to 16 endpoints. Each of these endpoints 71will communicate in one of four different modes: control, isochronous, 72bulk, or interrupt. Each of the endpoints will have a different 73device node. The four least significant bits in the minor device 74number determines which endpoint the device accesses and the rest 75of the bits determines which USB device. 76.Pp 77If an endpoint address is used both for input and output the device 78can be opened for both read or write. 79.Pp 80To find out what endpoints that exist there are a series of 81.Xr ioctl 2 82operation on the control endpoint that returns the USB descriptors 83of the device, configurations, interfaces, and endpoints. 84.Pp 85The control transfer mode can only happen on the control endpoint 86which is always endpoint 0. The control endpoint accepts request 87and may respond with an answer to such request. Control request 88are issued by 89.Xr ioctl 2 90calls. 91.\" .Pp 92.\" The isochronous transfer mode can be in or out depending on the 93.\" endpoint. To perform IO on an isochronous endpoint 94.\" .Xr read 2 95.\" and 96.\" .Xr write 2 97.\" should be used. 98.\" Before any IO operations can take place the transfer rate in 99.\" bytes/second has to be set. This is done with 100.\" .Xr ioctl 2 101.\" .Dv USB_SET_ISO_RATE . 102.\" Performing this call sets up a buffer corresponding to 103.\" about 1 second of data. 104.Pp 105The bulk transfer mode can be in or out depending on the 106endpoint. To perform IO on a bulk endpoint 107.Xr read 2 108and 109.Xr write 2 110should be used. 111All IO operations on a bulk endpoint are unbuffered. 112.Pp 113The interrupt transfer mode can be in or out depending on the 114endpoint. 115To perform IO on an interrupt endpoint 116.Xr read 2 117and 118.Xr write 2 119should be used. 120A moderate amount of buffering is done 121by the driver. 122.Pp 123All endpoints handle the following 124.Xr ioctl 2 125calls: 126.Pp 127.Bl -tag -width indent -compact 128.It Dv USB_SET_SHORT_XFER (int) 129Allow short read transfer. Normally a transfer from the device 130which is shorter than the request specified is reported as an 131error. 132.It Dv USB_SET_TIMEOUT (int) 133Set the timeout on the device operations, the time is specified 134in milliseconds. The 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.Pp 142.Bl -tag -width indent -compact 143.It Dv USB_GET_CONFIG (int) 144Get the device configuration number. 145.It Dv USB_SET_CONFIG (int) 146Set the device into the given configuration number. 147.br 148This operation can only be performed when the control endpoint 149is the sole open endpoint. 150.It Dv USB_GET_ALTINTERFACE (struct usb_alt_interface) 151Get the alternative setting number for the interface with the given 152index. 153The 154.Dv config_index 155is ignored in this call. 156.Bd -literal 157struct usb_alt_interface { 158 int uai_config_index; 159 int aui_interface_index; 160 int uai_alt_no; 161}; 162.Ed 163.It Dv USB_SET_ALTINTERFACE (struct usb_alt_interface) 164Set the alternative setting to the given number in the interface with the 165given index. 166The 167.Dv uai_config_index 168is ignored in this call. 169.br 170This operation can only be performed when no endpoints for the interface 171are open. 172.It Dv USB_GET_NO_ALT (struct usb_alt_interface) 173Return the number of different alternate settings in the 174.Dv aui_alt_no 175field. 176.It Dv USB_GET_DEVICE_DESC (usb_device_descriptor_t) 177Return the device descriptor. 178.It Dv USB_GET_CONFIG_DESC (struct usb_config_desc) 179Return the descriptor for the configuration with the given index. 180For convenience the current configuration can be specified by 181.Dv USB_CURRENT_CONFIG_INDEX . 182.Bd -literal 183struct usb_config_desc { 184 int ucd_config_index; 185 usb_config_descriptor_t ucd_desc; 186}; 187.Ed 188.It Dv USB_GET_INTERFACE_DESC (struct usb_interface_desc) 189Return the interface descriptor for an interface specified by its 190configuration index, interface index, and alternative index. 191For convenience the current alternative can be specified by 192.Dv USB_CURRENT_ALT_INDEX . 193.Bd -literal 194struct usb_interface_desc { 195 int uid_config_index; 196 int uid_interface_index; 197 int uid_alt_index; 198 usb_interface_descriptor_t uid_desc; 199}; 200.Ed 201.It Dv USB_GET_ENDPOINT_DESC (struct usb_endpoint_desc) 202Return the endpoint descriptor for the endpoint specified by its 203configuration index, interface index, alternative index, and 204endpoint index. 205.Bd -literal 206struct usb_endpoint_desc { 207 int ued_config_index; 208 int ued_interface_index; 209 int ued_alt_index; 210 int ued_endpoint_index; 211 usb_endpoint_descriptor_t ued_desc; 212}; 213.Ed 214.It Dv USB_GET_FULL_DESC (struct usb_full_desc) 215Return all the descriptors for the given configuration. 216.Bd -literal 217struct usb_full_desc { 218 int ufd_config_index; 219 u_int ufd_size; 220 u_char *ufd_data; 221}; 222.Ed 223The 224.Dv ufd_data 225field should point to a memory area of the size given in the 226.Dv ufd_size 227field. The proper size can be determined by first issuing a 228.Dv USB_GET_CONFIG_DESC 229and inspecting the 230.Dv wTotalLength 231field. 232.It Dv USB_GET_STRING_DESC (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 243Send a USB request to the device on the control endpoint. 244Any data sent to/from the device is located at 245.Dv data . 246The size of the transferred data is determined from the 247.Dv request . 248The 249.Dv ucr_addr 250field is ignored in this call. 251The 252.Dv ucr_flags 253field can be used to flag that the request is allowed to 254be shorter than the requested size, and the 255.Dv ucr_actlen 256field will 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. Some of the most dangerous (e.g., changing the device 269address) are not allowed. 270.It Dv USB_GET_DEVICEINFO (struct usb_device_info) 271Get an information summary for the device. This call will not 272issue any USB transactions. 273.El 274.Pp 275Note that there are two different ways of addressing configurations, interfaces, 276alternatives, and endpoints: by index or by number. 277The index is the ordinal number (starting from 0) of the descriptor 278as presented by the device. The number is the respective number of 279the entity as found in its descriptor. Enumeration of descriptors 280use the index, getting and setting typically uses numbers. 281.Pp 282Example: 283All endpoints (except the control endpoint) for the current configuration 284can be found by iterating the 285.Dv interface_index 286from 0 to 287.Dv config_desc-\*[Gt]bNumInterface-1 288and for each of these iterating the 289.Dv endpoint_index 290from 0 to 291.Dv interface_desc-\*[Gt]bNumEndpoints . 292The 293.Dv config_index 294should set to 295.Dv USB_CURRENT_CONFIG_INDEX 296and 297.Dv alt_index 298should be set to 299.Dv USB_CURRENT_ALT_INDEX . 300.Sh FILES 301.Bl -tag -width Pa 302.It Pa /dev/ugenN.EE 303Endpoint 304.Pa EE 305of device 306.Pa N . 307.El 308.Sh SEE ALSO 309.Xr usb 4 310.Sh HISTORY 311The 312.Nm 313driver 314appeared in 315.Nx 1.4 . 316.\" .Sh BUGS 317.\" The driver is not yet finished; there is no access to isochronous endpoints. 318