Files
ShengYi Hung 749318f2ae libusb: capsicumize libusb
FreeBSD's libusb has three components: libusb01, libusb10, and libusb20.

libusb20 handles communication with character devices. We now requires a
backend context for libusb20. The backend context contains contains the
capsicumized usbctrl fd and usb directory (/dev/usb) fd so that the
library user can enter the capiblity mode safely while using libusb.

libusb10 is updated to support capabilities via a context option. Since
libusb allows general read/write access, we preserve all possible
capabilities when passing backend context to libusb20. It is the
responsibility of the libusb user to call cap_enter() at an appropriate
time.

All base system tools using libusb and libusb20 have been updated to
support Capsicum.

Reviewed by:    adrian, markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51865
2026-08-14 23:09:08 +08:00
..
…
…
…
…
…
…

As I dug my own way through the documentation of libusb 2.0 that ships
with FreeBSD 8+ as the OS'es own USB library API, I noticed there are
only few code examples around under /usr/src (namely, usbconfig
itself).

The libusb20(3) man page is a starting point, but it's a reference
manual, nothing less, nothing more.  Using just a reference, it's not
very easy to start writing your own code based on that.

So I started writing my own examples, to "get a feeling" about how to
use the library.  I covered two typical scenarios which are common for
a number of devices.

The first one is called "bulk", and uses bulk output (host to device)
and input transfers to talk to an USB device.

The second one is called "control", and can use both control output
and input transfers, as well as so-called interrupt transfers.  The
latter are used for data that are being reported frequently or
repeatedly, like position updates from a pointing device (mouse).
Despite of its name, the host has to poll devices for their interrupt
transfers on each USB frame (i.e., each 1 ms).

Recommended reading is the USB 3.0 specification (the older 2.0 one
would do as well), to be found under

http://www.usb.org/developers/docs/

as well as documents for individual USB device classes where
appropriate.

Feel free to be liberal in the licensing of these examples: while the
beer-ware license mandates to keep the license notice, this only
applies to modifications of the original examples itself.  For
copy&pasting (even a larger) piece of an example into your own work, I
won't imply you have to reproduce the beer-ware license text there.
Feel free to credit my name in your derived work if you want.

Dresden, July 2012
Joerg Wunsch <[email protected]>