summaryrefslogtreecommitdiff
path: root/static/freebsd/man4/ugen.4 3.html
blob: ad797d0fbf163df6b3ce399665646b207774be43 (plain)
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
<table class="head">
  <tr>
    <td class="head-ltitle">UGEN(4)</td>
    <td class="head-vol">Device Drivers Manual</td>
    <td class="head-rtitle">UGEN(4)</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">ugen</code> &#x2014; <span class="Nd">USB generic
    device support</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<table class="Nm">
  <tr>
    <td><code class="Nm">ugen</code></td>
    <td>is integrated into the <a class="Xr">usb(4)</a> kernel module.</td>
  </tr>
</table>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The <code class="Nm">ugen</code> 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.</p>
<p class="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.</p>
<p class="Pp">If an endpoint address is used both for input and output, the
    device can be opened for both read or write.</p>
<p class="Pp">To find out which endpoints exist, there are a series of
    <a class="Xr">ioctl(2)</a> operations on the control endpoint that return
    the USB descriptors of the device, configurations, interfaces, and
    endpoints.</p>
<p class="Pp">The control transfer mode can only happen on the control endpoint
    which is always endpoint 0. The control endpoint accepts a request and may
    respond with an answer to such a request. Control requests are issued by
    <a class="Xr">ioctl(2)</a> calls.</p>
<p class="Pp">The bulk transfer mode can be in or out depending on the endpoint.
    To perform I/O on a bulk endpoint <a class="Xr">read(2)</a> and
    <a class="Xr">write(2)</a> should be used. All I/O operations on a bulk
    endpoint are unbuffered.</p>
<p class="Pp">The interrupt transfer mode can be in or out depending on the
    endpoint. To perform I/O on an interrupt endpoint <a class="Xr">read(2)</a>
    and <a class="Xr">write(2)</a> should be used. A moderate amount of
    buffering is done by the driver.</p>
<p class="Pp">All endpoints handle the following <a class="Xr">ioctl(2)</a>
    calls:</p>
<dl class="Bl-tag">
  <dt id="USB_SET_SHORT_XFER"><a class="permalink" href="#USB_SET_SHORT_XFER"><code class="Dv">USB_SET_SHORT_XFER</code></a>
    (<var class="Vt">int</var>)</dt>
  <dd>Allow short read transfer. Normally a transfer from the device which is
      shorter than the request specified is reported as an error.</dd>
  <dt id="USB_SET_TIMEOUT"><a class="permalink" href="#USB_SET_TIMEOUT"><code class="Dv">USB_SET_TIMEOUT</code></a>
    (<var class="Vt">int</var>)</dt>
  <dd>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.</dd>
</dl>
<p class="Pp">The control endpoint (endpoint 0) handles the following
    <a class="Xr">ioctl(2)</a> calls:</p>
<dl class="Bl-tag">
  <dt id="USB_GET_CONFIG"><a class="permalink" href="#USB_GET_CONFIG"><code class="Dv">USB_GET_CONFIG</code></a>
    (<var class="Vt">int</var>)</dt>
  <dd>Get the device configuration number.</dd>
  <dt id="USB_SET_CONFIG"><a class="permalink" href="#USB_SET_CONFIG"><code class="Dv">USB_SET_CONFIG</code></a>
    (<var class="Vt">int</var>)</dt>
  <dd>Set the device into the given configuration number.
    <p class="Pp">This operation can only be performed when the control endpoint
        is the sole open endpoint.</p>
  </dd>
  <dt id="USB_GET_ALTINTERFACE"><a class="permalink" href="#USB_GET_ALTINTERFACE"><code class="Dv">USB_GET_ALTINTERFACE</code></a>
    (<var class="Vt">struct usb_alt_interface</var>)</dt>
  <dd>Get the alternative setting number for the interface with the given index.
      The <var class="Va">uai_config_index</var> is ignored in this call.
    <div class="Bd Pp Li">
    <pre>struct usb_alt_interface {
	int	uai_config_index;
	int	uai_interface_index;
	int	uai_alt_no;
};</pre>
    </div>
  </dd>
  <dt id="USB_SET_ALTINTERFACE"><a class="permalink" href="#USB_SET_ALTINTERFACE"><code class="Dv">USB_SET_ALTINTERFACE</code></a>
    (<var class="Vt">struct usb_alt_interface</var>)</dt>
  <dd>Set the alternative setting to the given number in the interface with the
      given index. The <var class="Va">uai_config_index</var> is ignored in this
      call.
    <p class="Pp">This operation can only be performed when no endpoints for the
        interface are open.</p>
  </dd>
  <dt id="USB_GET_NO_ALT"><a class="permalink" href="#USB_GET_NO_ALT"><code class="Dv">USB_GET_NO_ALT</code></a>
    (<var class="Vt">struct usb_alt_interface</var>)</dt>
  <dd>Return the number of different alternate settings in the
      <var class="Va">uai_alt_no</var> field.</dd>
  <dt id="USB_GET_DEVICE_DESC"><a class="permalink" href="#USB_GET_DEVICE_DESC"><code class="Dv">USB_GET_DEVICE_DESC</code></a>
    (<var class="Vt">usb_device_descriptor_t</var>)</dt>
  <dd>Return the device descriptor.</dd>
  <dt id="USB_GET_CONFIG_DESC"><a class="permalink" href="#USB_GET_CONFIG_DESC"><code class="Dv">USB_GET_CONFIG_DESC</code></a>
    (<var class="Vt">struct usb_config_desc</var>)</dt>
  <dd>Return the descriptor for the configuration with the given index. For
      convenience, the current configuration can be specified by
      <code class="Dv">USB_CURRENT_CONFIG_INDEX</code>.
    <div class="Bd Pp Li">
    <pre>struct usb_config_desc {
	int	ucd_config_index;
	usb_config_descriptor_t ucd_desc;
};</pre>
    </div>
  </dd>
  <dt id="USB_GET_INTERFACE_DESC"><a class="permalink" href="#USB_GET_INTERFACE_DESC"><code class="Dv">USB_GET_INTERFACE_DESC</code></a>
    (<var class="Vt">struct usb_interface_desc</var>)</dt>
  <dd>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
      <code class="Dv">USB_CURRENT_ALT_INDEX</code>.
    <div class="Bd Pp Li">
    <pre>struct usb_interface_desc {
	int	uid_config_index;
	int	uid_interface_index;
	int	uid_alt_index;
	usb_interface_descriptor_t uid_desc;
};</pre>
    </div>
  </dd>
  <dt id="USB_GET_ENDPOINT_DESC"><a class="permalink" href="#USB_GET_ENDPOINT_DESC"><code class="Dv">USB_GET_ENDPOINT_DESC</code></a>
    (<var class="Vt">struct usb_endpoint_desc</var>)</dt>
  <dd>Return the endpoint descriptor for the endpoint specified by its
      configuration index, interface index, alternative index, and endpoint
      index.
    <div class="Bd Pp Li">
    <pre>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;
};</pre>
    </div>
  </dd>
  <dt id="USB_GET_FULL_DESC"><a class="permalink" href="#USB_GET_FULL_DESC"><code class="Dv">USB_GET_FULL_DESC</code></a>
    (<var class="Vt">struct usb_full_desc</var>)</dt>
  <dd>Return all the descriptors for the given configuration.
    <div class="Bd Pp Li">
    <pre>struct usb_full_desc {
	int	ufd_config_index;
	u_int	ufd_size;
	u_char	*ufd_data;
};</pre>
    </div>
    The <var class="Va">ufd_data</var> field should point to a memory area of
      the size given in the <var class="Va">ufd_size</var> field. The proper
      size can be determined by first issuing a
      <code class="Dv">USB_GET_CONFIG_DESC</code> and inspecting the
      <var class="Va">wTotalLength</var> field.</dd>
  <dt id="USB_GET_STRING_DESC"><a class="permalink" href="#USB_GET_STRING_DESC"><code class="Dv">USB_GET_STRING_DESC</code></a>
    (<var class="Vt">struct usb_string_desc</var>)</dt>
  <dd>Get a string descriptor for the given language ID and string index.
    <div class="Bd Pp Li">
    <pre>struct usb_string_desc {
	int	usd_string_index;
	int	usd_language_id;
	usb_string_descriptor_t usd_desc;
};</pre>
    </div>
  </dd>
  <dt id="USB_DO_REQUEST"><a class="permalink" href="#USB_DO_REQUEST"><code class="Dv">USB_DO_REQUEST</code></a>
    (<var class="Vt">struct usb_ctl_request</var>)</dt>
  <dd>Send a USB request to the device on the control endpoint. Any data sent
      to/from the device is located at <var class="Va">ucr_data</var>. The size
      of the transferred data is determined from the
      <var class="Va">ucr_request</var>. The <var class="Va">ucr_addr</var>
      field is ignored in this call. The <var class="Va">ucr_flags</var> field
      can be used to flag that the request is allowed to be shorter than the
      requested size, and <var class="Va">ucr_actlen</var> will contain the
      actual size on completion.
    <div class="Bd Pp Li">
    <pre>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 */
};</pre>
    </div>
    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.</dd>
  <dt id="USB_GET_DEVICEINFO"><a class="permalink" href="#USB_GET_DEVICEINFO"><code class="Dv">USB_GET_DEVICEINFO</code></a>
    (<var class="Vt">struct usb_device_info</var>)</dt>
  <dd>Get an information summary for the device. This call will not issue any
      USB transactions.</dd>
</dl>
<p class="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 uses the
    index, getting and setting typically uses numbers.</p>
<p class="Pp">Example: all endpoints (except the control endpoint) for the
    current configuration can be found by iterating the
    <var class="Va">interface_index</var> from 0 to
    <var class="Va">config_desc-&gt;bNumInterface</var>-1 and for each of these,
    iterating the <var class="Va">endpoint_index</var> from 0 to
    <var class="Va">interface_desc-&gt;bNumEndpoints</var>. The
    <var class="Va">config_index</var> should be set to
    <code class="Dv">USB_CURRENT_CONFIG_INDEX</code> and
    <var class="Va">alt_index</var> should be set to
    <code class="Dv">USB_CURRENT_ALT_INDEX</code>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYSCTL_VARIABLES"><a class="permalink" href="#SYSCTL_VARIABLES">SYSCTL
  VARIABLES</a></h1>
<p class="Pp">The following variables are available as both
    <a class="Xr">sysctl(8)</a> variables and <a class="Xr">loader(8)</a>
    tunables:</p>
<dl class="Bl-tag">
  <dt id="hw.usb.ugen.debug"><var class="Va">hw.usb.ugen.debug</var></dt>
  <dd>Debug output level, where 0 is debugging disabled and larger values
      increase debug message verbosity. Default is 0.</dd>
</dl>
</section>
<section class="Sh">
<h1 class="Sh" id="FILES"><a class="permalink" href="#FILES">FILES</a></h1>
<dl class="Bl-tag Bl-compact">
  <dt><span class="Pa">/dev/usb/B.D.E</span></dt>
  <dd>Endpoint <var class="Ar">E</var> of device <var class="Ar">D</var> at bus
      <var class="Ar">B</var>.</dd>
  <dt><span class="Pa">/dev/ugenB.D</span></dt>
  <dd>Control endpoint, 0, of device <var class="Ar">D</var> at bus
      <var class="Ar">B</var>.</dd>
</dl>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
  ALSO</a></h1>
<p class="Pp"><a class="Xr">usb(4)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">The <code class="Nm">ugen</code> driver appeared in
    <span class="Ux">NetBSD 1.4</span>.</p>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">May 14, 2021</td>
    <td class="foot-os">FreeBSD 15.0</td>
  </tr>
</table>