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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
<table class="head">
<tr>
<td class="head-ltitle">USB(4)</td>
<td class="head-vol">Device Drivers Manual</td>
<td class="head-rtitle">USB(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">usb</code> — <span class="Nd">Universal
Serial Bus driver</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="Cd">ehci* at cardbus? function ?</code>
<br/>
<code class="Cd">ehci* at pci? dev ? function ?</code>
<br/>
<code class="Cd">ohci* at cardbus? function ?</code>
<br/>
<code class="Cd">ohci* at pci? dev ? function ?</code>
<br/>
<code class="Cd">xhci* at pci? dev ? function ?</code>
<br/>
<code class="Cd">slhci* at isa? port ? irq ?</code>
<br/>
<code class="Cd">slhci* at pcmcia? function ?</code>
<br/>
<code class="Cd">uhci* at cardbus? function ?</code>
<br/>
<code class="Cd">uhci* at pci? dev ? function ?</code>
<br/>
<code class="Cd">usb* at ehci?</code>
<br/>
<code class="Cd">usb* at ohci?</code>
<br/>
<code class="Cd">usb* at uhci?</code>
<br/>
<code class="Cd">usb* at slhci?</code>
<br/>
<code class="Cd">uhub* at usb?</code>
<br/>
<code class="Cd">uhub* at uhub? port ? configuration ? interface ? vendor ?
product ? release ?</code>
<br/>
<code class="Cd">XX* at uhub? port ? configuration ? interface ? vendor ?
product ? release ?</code></p>
<p class="Pp">
<br/>
<code class="Cd">options USBVERBOSE</code></p>
<p class="Pp">
<br/>
<code class="In">#include <<a class="In">dev/usb/usb.h</a>></code>
<br/>
<code class="In">#include
<<a class="In">dev/usb/usbhid.h</a>></code></p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp"><span class="Ux">NetBSD</span> provides machine-independent bus
support and drivers for USB devices.</p>
<p class="Pp">The <span class="Ux">NetBSD</span> <code class="Nm">usb</code>
driver has three layers (like <a class="Xr">scsi(4)</a> and
<a class="Xr">pcmcia(4)</a>): the controller, the bus, and the device layer.
The controller attaches to a physical bus (like <a class="Xr">pci(4)</a>).
The USB bus attaches to the controller and the root hub attaches to the bus.
Further devices, which may include further hubs, attach to other hubs. The
attachment forms the same tree structure as the physical USB device tree.
For each USB device there may be additional drivers attached to it.</p>
<p class="Pp">The <code class="Cm">uhub</code> device controls USB hubs and must
always be present since there is at least a root hub in any USB system.</p>
<p class="Pp"><span class="Ux">NetBSD</span> supports the following
machine-independent USB drivers:</p>
<section class="Ss">
<h2 class="Ss" id="Storage_devices"><a class="permalink" href="#Storage_devices">Storage
devices</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">umass(4)</a></dt>
<dd>USB Mass Storage Devices, e.g., external disk drives</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Wired_network_interfaces"><a class="permalink" href="#Wired_network_interfaces">Wired
network interfaces</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">aue(4)</a></dt>
<dd>ADMtek AN986/ADM8511 Pegasus family 10/100 USB Ethernet device</dd>
<dt><a class="Xr">axe(4)</a></dt>
<dd>ASIX Electronics AX88172/AX88178/AX88772 10/100/Gigabit USB Ethernet
device</dd>
<dt><a class="Xr">axen(4)</a></dt>
<dd>ASIX Electronics AX88178a/AX88179 10/100/Gigabit USB Ethernet device</dd>
<dt><a class="Xr">cdce(4)</a></dt>
<dd>USB Communication Device Class Ethernet device</dd>
<dt><a class="Xr">cue(4)</a></dt>
<dd>CATC USB-EL1201A USB Ethernet device</dd>
<dt><a class="Xr">kue(4)</a></dt>
<dd>Kawasaki LSI KL5KUSB101B USB Ethernet device</dd>
<dt><a class="Xr">mos(4)</a></dt>
<dd>MosChip MCS7730/7830/7832 10/100 USB Ethernet device</dd>
<dt><a class="Xr">mue(4)</a></dt>
<dd>Microchip LAN75xx/LAN78xx 10/100/Gigabit USB Ethernet device</dd>
<dt><a class="Xr">ncm(4)</a></dt>
<dd>USB Network Control Model Ethernet device</dd>
<dt><a class="Xr">udav(4)</a></dt>
<dd>Davicom DM9601 10/100 USB Ethernet device</dd>
<dt><a class="Xr">ure(4)</a></dt>
<dd>Realtek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device</dd>
<dt><a class="Xr">url(4)</a></dt>
<dd>Realtek RTL8150L 10/100 USB Ethernet device</dd>
<dt><a class="Xr">urndis(4)</a></dt>
<dd>USB Remote NDIS Ethernet device</dd>
<dt><a class="Xr">usmsc(4)</a></dt>
<dd>SMSC LAN95xx 10/100 USB Ethernet device</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Wireless_network_interfaces"><a class="permalink" href="#Wireless_network_interfaces">Wireless
network interfaces</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">atu(4)</a></dt>
<dd>Atmel AT76C50x IEEE 802.11b wireless network device</dd>
<dt><a class="Xr">ral(4)</a></dt>
<dd>Ralink Technology USB IEEE 802.11b/g wireless network device</dd>
<dt><a class="Xr">rum(4)</a></dt>
<dd>Ralink Technology USB IEEE 802.11a/b/g wireless network device</dd>
<dt><a class="Xr">run(4)</a></dt>
<dd>Ralink Technology USB IEEE 802.11a/b/g/n wireless network device</dd>
<dt><a class="Xr">ubt(4)</a></dt>
<dd>USB Bluetooth dongles</dd>
<dt><a class="Xr">upgt(4)</a></dt>
<dd>Conexant/Intersil PrismGT SoftMAC USB 802.11b/g wireless network
device</dd>
<dt><a class="Xr">urtwn(4)</a></dt>
<dd>Realtek RTL8188CU/RTL8192CU USB IEEE 802.11b/g/n wireless network
device</dd>
<dt><a class="Xr">zyd(4)</a></dt>
<dd>ZyDAS ZD1211/ZD1211B USB IEEE 802.11b/g wireless network device</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Serial_and_parallel_interfaces"><a class="permalink" href="#Serial_and_parallel_interfaces">Serial
and parallel interfaces</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">uark(4)</a></dt>
<dd>Arkmicro Technologies ARK3116 based USB serial adapters</dd>
<dt><a class="Xr">ubsa(4)</a></dt>
<dd>Belkin USB serial adapter</dd>
<dt><a class="Xr">uchcom(4)</a></dt>
<dd>WinChipHead CH341/340 based USB serial adapter</dd>
<dt><a class="Xr">ucom(4)</a></dt>
<dd>USB tty support</dd>
<dt><a class="Xr">ucycom(4)</a></dt>
<dd>Cypress microcontroller based USB serial adapter</dd>
<dt><a class="Xr">uftdi(4)</a></dt>
<dd>FT8U100AX USB serial adapter</dd>
<dt><a class="Xr">ugensa(4)</a></dt>
<dd>USB generic serial adapter</dd>
<dt><a class="Xr">uipaq(4)</a></dt>
<dd>iPAQ USB units</dd>
<dt><a class="Xr">ukyopon(4)</a></dt>
<dd>USB Kyocera AIR-EDGE PHONE device</dd>
<dt><a class="Xr">ulpt(4)</a></dt>
<dd>USB printer support</dd>
<dt><a class="Xr">umct(4)</a></dt>
<dd>MCT USB-RS232 USB serial adapter</dd>
<dt><a class="Xr">umodem(4)</a></dt>
<dd>USB modem support</dd>
<dt><a class="Xr">uplcom(4)</a></dt>
<dd>Prolific PL-2303 USB serial adapter</dd>
<dt><a class="Xr">uslsa(4)</a></dt>
<dd>Silicon Laboratories CP2101/CP2102 based USB serial adapter</dd>
<dt><a class="Xr">uvisor(4)</a></dt>
<dd>USB Handspring Visor</dd>
<dt><a class="Xr">uvscom(4)</a></dt>
<dd>SUNTAC Slipper U VS-10U USB serial adapter</dd>
<dt><a class="Xr">uxrcom(4)</a></dt>
<dd>Exar XR21V141x USB serial adapter</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Cellular_WAN_interfaces"><a class="permalink" href="#Cellular_WAN_interfaces">Cellular
WAN interfaces</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">u3g(4)</a></dt>
<dd>USB 3G modems</dd>
<dt><a class="Xr">uhmodem(4)</a></dt>
<dd>Huawei 3G wireless modems</dd>
<dt><a class="Xr">uhso(4)</a></dt>
<dd>Option N.V. Wireless WAN modems</dd>
<dt><a class="Xr">umb(4)</a></dt>
<dd>USB Mobile Broadband Interface Model (MBIM) devices</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Audio_devices"><a class="permalink" href="#Audio_devices">Audio
devices</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">uaudio(4)</a></dt>
<dd>USB audio devices</dd>
<dt><a class="Xr">umidi(4)</a></dt>
<dd>USB MIDI devices</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Video_devices"><a class="permalink" href="#Video_devices">Video
devices</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">pseye(4)</a></dt>
<dd>Sony PlayStation Eye webcam device driver</dd>
<dt><a class="Xr">udl(4)</a></dt>
<dd>DisplayLink DL-1x0/1x5 USB display devices</dd>
<dt><a class="Xr">uvideo(4)</a></dt>
<dd>USB video class devices (e.g. webcams, capture cards)</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Radio_receiver_devices"><a class="permalink" href="#Radio_receiver_devices">Radio
receiver devices</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">slurm(4)</a></dt>
<dd>Silicon Labs USB FM radios</dd>
<dt><a class="Xr">udsbr(4)</a></dt>
<dd>D-Link DSB-R100 USB radio device</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Human_Interface_Devices"><a class="permalink" href="#Human_Interface_Devices">Human
Interface Devices</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">uatp(4)</a></dt>
<dd>Apple trackpads</dd>
<dt><a class="Xr">uep(4)</a></dt>
<dd>eGalax touch panel controllers</dd>
<dt><a class="Xr">uhid(4)</a></dt>
<dd>Generic driver for Human Interface Devices</dd>
<dt><a class="Xr">uhidev(4)</a></dt>
<dd>Base driver for all Human Interface Devices</dd>
<dt><a class="Xr">uintuos(4)</a></dt>
<dd>Wacom Intuos drawing tablets</dd>
<dt><a class="Xr">ukbd(4)</a></dt>
<dd>USB keyboards that follow the boot protocol</dd>
<dt><a class="Xr">ums(4)</a></dt>
<dd>USB mouse devices</dd>
<dt><a class="Xr">uthum(4)</a></dt>
<dd>TEMPer and TEMPerHUM temperature and humidity sensors</dd>
<dt><a class="Xr">uts(4)</a></dt>
<dd>Generic driver for touchscreens and touch digitizers</dd>
</dl>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Miscellaneous_devices"><a class="permalink" href="#Miscellaneous_devices">Miscellaneous
devices</a></h2>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt><a class="Xr">stuirda(4)</a></dt>
<dd>Sigmaltel 4116/4220 USB-IrDA bridge</dd>
<dt><a class="Xr">ualea(4)</a></dt>
<dd>USB Araneus Alea I/II random number generators</dd>
<dt><a class="Xr">uberry(4)</a></dt>
<dd>Battery charging RIM BlackBerry phones via USB</dd>
<dt><a class="Xr">ugen(4)</a></dt>
<dd>USB generic devices</dd>
<dt><a class="Xr">uipad(4)</a></dt>
<dd>Battery charging iOS devices via USB</dd>
<dt><a class="Xr">uirda(4)</a></dt>
<dd>USB IrDA bridges</dd>
<dt><a class="Xr">upl(4)</a></dt>
<dd>Prolific based host-to-host adapters</dd>
<dt><a class="Xr">usscanner(4)</a></dt>
<dd>SCSI-over-USB scanners</dd>
<dt><a class="Xr">ustir(4)</a></dt>
<dd>SigmaTel STIr4200 USB IrDA bridges</dd>
<dt><a class="Xr">utoppy(4)</a></dt>
<dd>Topfield TF5000PVR range of digital video recorders</dd>
</dl>
</div>
</section>
</section>
<section class="Sh">
<h1 class="Sh" id="INTRODUCTION_TO_USB"><a class="permalink" href="#INTRODUCTION_TO_USB">INTRODUCTION
TO USB</a></h1>
<p class="Pp">The USB 1.x is a 12 Mb/s serial bus with 1.5 Mb/s for low speed
devices. USB 2.x handles 480 Mb/s. Each USB has a host controller that is
the master of the bus; all other devices on the bus only speak when spoken
to.</p>
<p class="Pp">There can be up to 127 devices (apart from the host controller) on
a bus, each with its own address. The addresses are assigned dynamically by
the host when each device is attached to the bus.</p>
<p class="Pp">Within each device there can be up to 16 endpoints. Each endpoint
is individually addressed and the addresses are static. Each of these
endpoints will communicate in one of four different modes: control,
isochronous, bulk, or interrupt. A device always has at least one endpoint.
This endpoint has address 0 and is a control endpoint and is used to give
commands to and extract basic data, such as descriptors, from the device.
Each endpoint, except the control endpoint, is unidirectional.</p>
<p class="Pp">The endpoints in a device are grouped into interfaces. An
interface is a logical unit within a device; e.g., a compound device with
both a keyboard and a trackball would present one interface for each. An
interface can sometimes be set into different modes, called alternate
settings, which affects how it operates. Different alternate settings can
have different endpoints within it.</p>
<p class="Pp">A device may operate in different configurations. Depending on the
configuration the device may present different sets of endpoints and
interfaces.</p>
<p class="Pp">Each device located on a hub has several
<a class="Xr">config(1)</a> locators:</p>
<dl class="Bl-tag Bl-compact">
<dt><code class="Cd">port</code></dt>
<dd>this is the number of the port on closest upstream hub.</dd>
<dt><code class="Cd">configuration</code></dt>
<dd>this is the configuration the device must be in for this driver to attach.
This locator does not set the configuration; it is iterated by the bus
enumeration.</dd>
<dt><code class="Cd">interface</code></dt>
<dd>this is the interface number within a device that an interface driver
attaches to.</dd>
<dt><code class="Cd">vendor</code></dt>
<dd>this is the 16 bit vendor id of the device.</dd>
<dt><code class="Cd">product</code></dt>
<dd>this is the 16 bit product id of the device.</dd>
<dt><code class="Cd">release</code></dt>
<dd>this is the 16 bit release (revision) number of the device.</dd>
</dl>
The first locator can be used to pin down a particular device according to its
physical position in the device tree. The last three locators can be used to
pin down a particular device according to what device it actually is.
<p class="Pp">The bus enumeration of the USB bus proceeds in several steps:</p>
<ol class="Bl-enum">
<li>Any device specific driver can attach to the device.</li>
<li>If none is found, any device class specific driver can attach.</li>
<li>If none is found, all configurations are iterated over. For each
configuration all the interface are iterated over and interface drivers
can attach. If any interface driver attached in a certain configuration
the iteration over configurations is stopped.</li>
<li>If still no drivers have been found, the generic USB driver can
attach.</li>
</ol>
</section>
<section class="Sh">
<h1 class="Sh" id="USB_CONTROLLER_INTERFACE"><a class="permalink" href="#USB_CONTROLLER_INTERFACE">USB
CONTROLLER INTERFACE</a></h1>
<p class="Pp">Use the following to get access to the USB specific structures and
defines.</p>
<div class="Bd Pp Li">
<pre>#include <dev/usb/usb.h></pre>
</div>
<p class="Pp">The <span class="Pa">/dev/usbN</span> can be opened and a few
operations can be performed on it. The <a class="Xr">poll(2)</a> system call
will say that I/O is possible on the controller device when a USB device has
been connected or disconnected to the bus.</p>
<p class="Pp">The following <a class="Xr">ioctl(2)</a> commands are supported on
the controller device:</p>
<dl class="Bl-tag">
<dt id="USB_DEVICEINFO"><a class="permalink" href="#USB_DEVICEINFO"><code class="Dv">USB_DEVICEINFO</code></a>
<var class="Fa">struct usb_device_info</var></dt>
<dd>This command can be used to retrieve some information about a device on
the bus. The <var class="Va">addr</var> field should be filled before the
call and the other fields will be filled by information about the device
on that address. Should no such device exist an error is reported.
<div class="Bd Pp Li">
<pre>struct usb_device_info {
uint8_t udi_bus;
uint8_t udi_addr;
usb_event_cookie_t udi_cookie;
char udi_product[USB_MAX_ENCODED_STRING_LEN];
char udi_vendor[USB_MAX_ENCODED_STRING_LEN];
char udi_release[8];
char udi_serial[USB_MAX_ENCODED_STRING_LEN];
uint16_t udi_productNo;
uint16_t udi_vendorNo;
uint16_t udi_releaseNo;
uint8_t udi_class;
uint8_t udi_subclass;
uint8_t udi_protocol;
uint8_t udi_config;
uint8_t udi_speed;
#define USB_SPEED_LOW 1
#define USB_SPEED_FULL 2
#define USB_SPEED_HIGH 3
int udi_power;
int udi_nports;
char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
uint8_t udi_ports[16];
#define USB_PORT_ENABLED 0xff
#define USB_PORT_SUSPENDED 0xfe
#define USB_PORT_POWERED 0xfd
#define USB_PORT_DISABLED 0xfc
};</pre>
</div>
<p class="Pp">The <var class="Va">product</var>,
<var class="Va">vendor</var>, <var class="Va">release</var>, and
<var class="Va">serial</var> fields contain self-explanatory
descriptions of the device.</p>
<p class="Pp">The <var class="Va">class</var> field contains the device
class.</p>
<p class="Pp">The <var class="Va">config</var> field shows the current
configuration of the device.</p>
<p class="Pp">The <var class="Va">lowspeed</var> field is set if the device
is a USB low speed device.</p>
<p class="Pp">The <var class="Va">power</var> field shows the power
consumption in milli-amps drawn at 5 volts, or zero if the device is
self powered.</p>
<p class="Pp">If the device is a hub the <var class="Va">nports</var> field
is non-zero and the <var class="Va">ports</var> field contains the
addresses of the connected devices. If no device is connected to a port
one of the <var class="Va">USB_PORT_*</var> values indicates its
status.</p>
</dd>
<dt id="USB_DEVICESTATS"><a class="permalink" href="#USB_DEVICESTATS"><code class="Dv">USB_DEVICESTATS</code></a>
<var class="Fa">struct usb_device_stats</var></dt>
<dd>This command retrieves statistics about the controller.
<div class="Bd Pp Li">
<pre>struct usb_device_stats {
u_long uds_requests[4];
};</pre>
</div>
<p class="Pp">The <var class="Va">requests</var> field is indexed by the
transfer kind, i.e. <var class="Va">UE_*</var>, and indicates how many
transfers of each kind have been completed by the controller.</p>
</dd>
<dt id="USB_REQUEST"><a class="permalink" href="#USB_REQUEST"><code class="Dv">USB_REQUEST</code></a>
<var class="Fa">struct usb_ctl_request</var></dt>
<dd>This command can be used to execute arbitrary requests on the control
pipe. This is
<a class="permalink" href="#DANGEROUS"><i class="Em" id="DANGEROUS">DANGEROUS</i></a>
and should be used with great care since it can destroy the bus
integrity.</dd>
</dl>
<p class="Pp" id="UGETW">The include file
<code class="In"><<a class="In">dev/usb/usb.h</a>></code> contains
definitions for the types used by the various <a class="Xr">ioctl(2)</a>
calls. The naming convention of the fields for the various USB descriptors
exactly follows the naming in the USB specification. Byte sized fields can
be accessed directly, but word (16 bit) sized fields must be access by the
<a class="permalink" href="#UGETW"><code class="Fn">UGETW</code></a>(<var class="Fa">field</var>)
and
<a class="permalink" href="#USETW"><code class="Fn" id="USETW">USETW</code></a>(<var class="Fa">field</var>,
<var class="Fa">value</var>) macros to handle byte order and alignment
properly.</p>
<p class="Pp">The include file
<code class="In"><<a class="In">dev/usb/usbhid.h</a>></code> similarly
contains the definitions for Human Interface Devices (HID).</p>
</section>
<section class="Sh">
<h1 class="Sh" id="USB_EVENT_INTERFACE"><a class="permalink" href="#USB_EVENT_INTERFACE">USB
EVENT INTERFACE</a></h1>
<p class="Pp">All USB events are reported via the
<span class="Pa">/dev/usb</span> device. This devices can be opened for
reading and each <a class="Xr">read(2)</a> will yield an event record (if
something has happened). The <a class="Xr">poll(2)</a> system call can be
used to determine if an event record is available for reading.</p>
<p class="Pp">The event record has the following definition:</p>
<div class="Bd Pp Li">
<pre>struct usb_event {
int ue_type;
#define USB_EVENT_CTRLR_ATTACH 1
#define USB_EVENT_CTRLR_DETACH 2
#define USB_EVENT_DEVICE_ATTACH 3
#define USB_EVENT_DEVICE_DETACH 4
#define USB_EVENT_DRIVER_ATTACH 5
#define USB_EVENT_DRIVER_DETACH 6
struct timespec ue_time;
union {
struct {
int ue_bus;
} ue_ctrlr;
struct usb_device_info ue_device;
struct {
usb_event_cookie_t ue_cookie;
char ue_devname[16];
} ue_driver;
} u;
};</pre>
</div>
<p class="Pp">The <var class="Va">ue_type</var> field identifies the type of
event that is described. The possible events are attach/detach of a host
controller, a device, or a device driver. The union contains information
pertinent to the different types of events.</p>
<p class="Pp">The <var class="Va">ue_bus</var> contains the number of the USB
bus for host controller events.</p>
<p class="Pp">The <var class="Va">ue_device</var> record contains information
about the device in a device event event.</p>
<p class="Pp">The <var class="Va">ue_cookie</var> is an opaque value that
uniquely determines which device a device driver has been attached to (i.e.,
it equals the cookie value in the device that the driver attached to). The
<var class="Va">ue_devname</var> contains the name of the device (driver) as
seen in, e.g., kernel messages.</p>
<p class="Pp">Note that there is a separation between device and device driver
events. A device event is generated when a physical USB device is attached
or detached. A single USB device may have zero, one, or many device drivers
associated with it.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="KERNEL_THREADS"><a class="permalink" href="#KERNEL_THREADS">KERNEL
THREADS</a></h1>
<p class="Pp">For each USB bus, i.e., for each host controller, there is a
kernel thread that handles attach and detach of devices on that bus. The
thread is named <var class="Va">usbN</var> where <var class="Va">N</var> is
the bus number.</p>
<p class="Pp">In addition there is a kernel thread,
<var class="Va">usbtask</var>, which handles various minor tasks that are
initiated from an interrupt context, but need to sleep, e.g., time-out abort
of transfers.</p>
</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">usbhidaction(1)</a>, <a class="Xr">usbhidctl(1)</a>,
<a class="Xr">cardbus(4)</a>, <a class="Xr">ehci(4)</a>,
<a class="Xr">isa(4)</a>, <a class="Xr">ohci(4)</a>,
<a class="Xr">pci(4)</a>, <a class="Xr">pcmcia(4)</a>,
<a class="Xr">slhci(4)</a>, <a class="Xr">uhci(4)</a>,
<a class="Xr">xhci(4)</a>, <a class="Xr">usbdevs(8)</a></p>
<p class="Pp"><cite class="Rs"><span class="RsT">Universal Serial Bus
Specifications Documents</span>,
<a class="RsU" href="http://www.usb.org/developers/docs/">http://www.usb.org/developers/docs/</a>.</cite></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">usb</code> driver appeared in
<span class="Ux">NetBSD 1.4</span>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="BUGS"><a class="permalink" href="#BUGS">BUGS</a></h1>
<p class="Pp">There should be a serial number locator, but
<span class="Ux">NetBSD</span> does not have string valued locators.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">April 1, 2025</td>
<td class="foot-os">NetBSD 10.1</td>
</tr>
</table>
|