# # Set the following 4 variables. The host system is the system where # the software will be built; the target system is where it will run. # They are almost always the same. # On Nt systems, the ROOT path MUST be of the form `drive:/path' ROOT=/usr/hh/vm/inferno/inferno-os # # Specify the flavour of Tk (std for standard builds) # TKSTYLE=std # # Except for building kernels, SYSTARG must always be the same as SYSHOST # SYSHOST=Plan9 # build system OS type (AIX, Hp, Inferno, Irix, Linux, MacOSX, Nt, Plan9, Solaris) SYSTARG=Plan9 # target system OS type (AIX, Hp, Inferno, Irix, Linux, Nt, Plan9, Solaris) # # specify the architecture of the target system - Plan 9 imports it from the # environment; for other systems it is usually just hard-coded # #OBJTYPE=386 # target system object type (eg, 386, arm, mips, power, s800, sparc) OBJTYPE=$objtype # # no changes required beyond this point # OBJDIR=$SYSTARG/$OBJTYPE <$ROOT/mkfiles/mkhost-$SYSHOST # variables appropriate for host system <$ROOT/mkfiles/mkfile-$SYSTARG-$OBJTYPE # variables used to build target object type
Tue Dec 1 08:57:16 EST 2026
return -1;
sp = "full";
if(sts & PSslow)
sp = "low";
if(sts & PShigh)
sp = "high";
}
dprint(2, "%s: %s: port %d: attached status %s %#ux, speed %s\n", argv0,
d->dir, p,
stsstr(sts, d->isusb3), sts, sp);
if((sts & PSenable) == 0){
dprint(2, "%s: %s: port %d: not enabled?\n", argv0, d->dir, p);
return -1;
}
pp->sts = sts;
pp->state = Pattached;
if(devctl(d, "newdev %s %d", sp, p) < 0){
fprint(2, "%s: %s: port %d: newdev: %r\n", argv0, d->dir, p);
return -1;
}
seek(d->cfd, 0, 0);
nr = read(d->cfd, buf, sizeof(buf)-1);
if(nr <= 0){
if(nr == 0) werrstr("eof");
fprint(2, "%s: %s: port %d: newdev: %r\n", argv0, d->dir, p);
return -1;
}
buf[nr] = 0;
snprint(fname, sizeof(fname), "/dev/usb/%s", buf);
nd = opendev(fname);
if(nd == nil){
fprint(2, "%s: %s: port %d: opendev: %r\n", argv0, d->dir, p);
return -1;
}
pp->dev = nd;
nd->depth = d->depth+1;
nd->isusb3 = d->isusb3;
if(usbdebug > 2)
devctl(nd, "debug 1");
for(i=1;; i++){
if(opendevdata(nd, ORDWR) >= 0)
break;
if(i >= 10){
dprint(2, "%s: %s: opendevdata: %r\n", argv0, nd->dir);
return -1;
}
if((sts = portstatus(h, p)) == -1)
return -1;
if((sts & PSenable) == 0)
return -1;
sleep(i*50);
}
/*
* for xhci, this command is ignored by the driver as the device address
* has already been assigned by the controller firmware when opening ep0.
*/
if(usbcmd(nd, Rh2d|Rstd|Rdev, Rsetaddress, nd->id&0x7f, 0, nil, 0) <
0){
dprint(2, "%s: %s: port %d: setaddress: %r\n", argv0, d->dir,
p);
return -1;
}
if(devctl(nd, "address") < 0){
dprint(2, "%s: %s: port %d: set address: %r\n", argv0, d->dir,
p);
return -1;
}
mp=getmaxpkt(nd);
if(mp < 0){
dprint(2, "%s: %s: port %d: getmaxpkt: %r\n", argv0, d->dir,
p);
return -1;
}
dprint(2, "%s; %s: port %d: maxpkt %d\n", argv0, d->dir, p, mp);
/* force reopen in configdev() after setting maxpkt */
close(nd->dfd);
nd->dfd = -1;
devctl(nd, "maxpkt %d", mp);
if(configdev(nd) < 0){
dprint(2, "%s: %s: port %d: configdev: %r\n", argv0, d->dir,
p);
return -1;
}
/* assign stable name based on device descriptor */
assignhname(nd);
/*
* We always set conf #1. BUG.
*/
if(usbcmd(nd, Rh2d|Rstd|Rdev, Rsetconf, 1, 0, nil, 0) < 0){
fprint(2, "%s: %s: port %d: setconf: %r\n", argv0, d->dir, p);
if(usbcmd(nd, Rh2d|Rstd|Rdev, Rsetconf, 1, 0, nil, 0) < 0)
return -1;
}
pp->state = Pconfigured;
dprint(2, "%s: %s: port %d: configured: %s\n", argv0, d->dir, p,
nd->dir);
/*
* Hubs are handled directly by this process avoiding
* concurrent operation so that at most one device
* has the config address in use.
*/
if(nd->usb->class == Clhub){
pp->hub = newhub(nd->dir, nd);
if(pp->hub == nil)
return -1;
return 0;
}
/* close control endpoint so driver can open it */
close(nd->dfd);
nd->dfd = -1;
/* set device info for ctl file */
devctl(nd, "info %s csp %#08lux vid %#.4ux did %#.4ux %q %q %s",
classname(Class(nd->usb->csp)), nd->usb->csp,
nd->usb->vid, nd->usb->did,
nd->usb->vendor, nd->usb->product, nd->hname);
/* notify driver */
attachdev(nd);
return 0;
}
static void
portdetach(Hub *h, int p)
{
Dev *d;
Port *pp;
d = h->dev;
pp = &h->port[p];
if(pp->state == Pdisabled)
return;
dprint(2, "%s: %s: port %d: detached\n", argv0, d->dir, p);
if(pp->dev != nil){
devctl(pp->dev, "detach");
if(pp->state == Pconfigured
&& pp->dev->usb->class != Clhub)
detachdev(pp->dev);
Tue Dec 1 08:56:33 EST 2026
NUSB(2) NUSB(2)
NAME
usbcmd, classname, closedev, configdev, devctl, getdev,
loaddevstr, opendev, opendevdata, openep, unstall - USB
device driver library
SYNOPSIS
#include <u.h>
#include <libc.h>
#include "../lib/usb.h"
struct Dev {
Ref;
char* dir; /* path for the endpoint dir */
int id; /* usb id for device or ep. number */
int dfd; /* descriptor for the data file */
int cfd; /* descriptor for the control file */
int isusb3; /* this is a usb3 device */
int depth; /* hub depth for usb3 hubs */
int maxpkt; /* cached from usb description */
Usbdev* usb; /* USB description */
Ep* ep; /* endpoint from epopen() */
void* aux; /* for the device driver */
char* hname; /* hash name, unique for device */
};
struct Usbdev {
int ver; /* usb version */
ulong csp; /* USB class/subclass/proto */
int vid; /* vendor id */
int did; /* product (device) id */
int dno; /* device release number */
char* vendor;
char* product;
char* serial;
int vsid;
int psid;
int ssid;
int class; /* from descriptor */
int nconf; /* from descriptor */
Conf* conf[Nconf]; /* configurations */
Ep* ep[Epmax+1]; /* all endpoints in device (chained), indexed
by address */
Desc* ddesc[Nddesc]; /* (raw) device specific descriptors */
};
struct Ep {
Iface* iface; /* the endpoint belongs to */
Conf* conf; /* the endpoint belongs to */
int id; /* endpoint number: (id & Epmax) == endpoint address */
uchar dir; /* direction, Ein/Eout/Eboth */
uchar type; /* Econtrol, Eiso, Ebulk, Eintr */
int attrib;
int pollival;
int maxpkt; /* max. packet size */
int ntds; /* nb. of Tds per µframe */
/* chain of endpoints with same address (used in different
interfaces/altsettings) */
Ep* next;
void* aux; /* for the driver program */
};
struct Iface {
int id; /* interface number */
int alt; /* altsetting for this interface */
ulong csp; /* USB class/subclass/proto */
Iface* next; /* chain of interfaces of different altsettings */
Ep* ep[Nep]; /* consecutive array of endpoints in this interface
(not including ep0) */
void* aux; /* for the driver program */
};
struct Conf {
int cval; /* value for set configuration */
int attrib;
int milliamps; /* maximum power in this config. */
Iface* iface[Niface]; /* up to 16 interfaces */
};
struct Desc {
Conf* conf; /* where this descriptor was read */
Iface* iface; /* last iface before desc in conf. */
Ep* ep; /* last endpt before desc in conf. */
DDesc data; /* unparsed standard USB descriptor */
};
struct DDesc {
uchar bLength;
uchar bDescriptorType;
uchar bbytes[1];
/* extra bytes allocated here to keep the rest of it */
};
#define Class(csp) ((csp)&0xff)
#define Subclass(csp) (((csp)>>8)&0xff)
#define Proto(csp) (((csp)>>16)&0xff)
#define CSP(c, s, p) ((c) | ((s)<<8) | ((p)<<16))
#define GET2(p) ...
#define PUT2(p,v) ...
#define GET4(p) ...
#define PUT4(p,v) ...
#define dprint if(usbdebug)fprint
#define ddprint if(usbdebug > 1)fprint
int Ufmt(Fmt *f);
char* classname(int c);
void closedev(Dev *d);
int configdev(Dev *d);
int devctl(Dev *dev, char *fmt, ...);
void* emallocz(ulong size, int zero);
char* estrdup(char *s);
char* hexstr(void *a, int n);
char* loaddevstr(Dev *d, int sid);
Dev* opendev(char *fn);
int opendevdata(Dev *d, int mode);
Dev* openep(Dev *d, Ep *e);
int unstall(Dev *dev, Dev *ep, int dir);
int usbcmd(Dev *d, int type, int req,
int value, int index, uchar *data, int count);
Dev* getdev(char *devid);
extern int usbdebug; /* more messages for bigger values */
DESCRIPTION
This library provides convenience structures and functions
to write USB device drivers. It is not intended for user
programs using USB devices. See usb(3) for a description of
the interfaces provided for that purpose.
Usb drivers rely on usb(3) to perform I/O through USB as
well as on usbd to perform the initial configuration for the
device's setup endpoint. The rest of the work is up to the
driver and is where this library may help.
An endpoint as provided by usb(3) is represented by a Dev
data structure. The setup endpoint for a device represents
the USB device, because it is the means to configure and
operate the device. This structure is reference counted.
Functions creating Devs adjust the number of references to
one, initially. The driver is free to call incref (in
lock(2)) to add references and closedev to drop references
(and release resources when the last one vanishes). As an
aid to the driver, the field aux may keep driver-specific
data.
Dev.dir holds the path for the endpoint's directory.
The field id keeps the device number for setup endpoints and
the endpoint number for all other endpoints. The endpoint
number identifies devusb endpoint and is unique within a
device. For example, it would be 3 for /dev/usb/ep3.0 and 1
for /dev/usb/ep3.1. It is easy to remember this because the
former is created to operate on the device, while the later
has been created as a particular endpoint to perform I/O.
The field ep holds the endpoint structure that was passed in
epopen which gives easy access to the endpoint configura-
tion.
Fields dfd and cfd keep the data and control file descrip-
tors, respectively. When a Dev is created the control file
is open, initially. Opening the data file requires calling
opendevdata with the appropriate mode.
When the device configuration information has been loaded
(see below), maxpkt holds the maximum packet size (in bytes)
for the endpoint and usb keeps the rest of the USB informa-
tion.
Most of the information in usb comes from parsing various
device and configuration descriptors provided by the device,
by calling one of the functions described later. Only
descriptors unknown to the library are kept unparsed at
usb.ddesc as an aid for the driver (which should know how to
parse them and what to do with the information).
Configuration
Getdev is the primary entry point for device setup. It takes
a numeric device address or device path which usually gets
passed to drivers as a program argument and sets up the
device, retuning a configured Dev representing the setup
endpoint of the device.
Opendev creates a Dev for the endpoint with directory fn.
Usually, the endpoint is a setup endpoint representing a
device. The endpoint control file is open, but the data file
is not. The USB description is void. In most cases drivers
call getdev and openep and do not call this function
directly.
Configdev opens the data file for the device supplied and
loads and parses its configuration information. After cal-
ling it, the device is ready for I/O and the USB description
in Dev.usb is valid. In most cases drivers call getdev and
do not call this function directly.
Control requests for an endpoint may be written by calling
devctl in the style of print(2). It is better not to call
print directly because the control request should be issued
as a single write system call. See usb(3) for a list of
available control requests (not to be confused with USB con-
trol transfers performed on a control endpoint).
Input/Output
Opendevdata opens the data file for the device according to
the given mode. The mode must match that of the endpoint,
doing otherwise is considered an error. Actual I/O is per-
formed by reading/writing the descriptor kept in the dfd
field of Dev.
For control endpoints, it is not necessary to call read and
write directly. Instead, usbcmd issues a USB control
request to the device d (not to be confused with a usb(3)
control request sent to its control file). Usbcmd retries
the control request several times upon failure because some
devices require it. The format of requests is fixed per the
USB standard: type is the type of request and req identifies
the request. Arguments value and index are parameters to the
request and the last two arguments, data and count, are
similar to read and write arguments. However, data may be
nil if no transfer (other than the control request) has to
take place. The library header file includes numerous sym-
bols defined to help writing the type and arguments for a
request.
The return value from usbcmd is the number of bytes
transferred, zero to indicate a stall and -1 to indicate an
error.
A common request is to unstall an endpoint that has been
stalled due to some reason by the device (eg., when read or
write indicate a count of zero bytes read or written on the
endpoint). The function unstall does this. It is given the
device that stalled the endpoint, dev, the stalled endpoint,
ep, and the direction of the stall (one of Ein or Eout).
The function takes care of notifying the device of the
unstall as well as notifying the kernel.
Tools
Class returns the class part of the number given, represent-
ing a CSP. Subclass does the same for the device subclass
and Proto for the protocol. The counterpart is CSP, which
builds a CSP from the device class, subclass, and protocol.
For some classes, classname knows the name (for those with
constants in the library header file).
The macros GET2 and PUT2 get and put a (little-endian) two-
byte value and are useful to parse descriptors and replies
for control requests.
Functions emallocz and estrdup are similar to mallocz and
strdup but abort program operation upon failure.
The function Ufmt is a format routine suitable for
fmtinstall(2) to print a Dev data structure. The auxiliary
hexstr returns a string representing a dump (in hexadecimal)
of n bytes starting at a. The string is allocated using
malloc(2) and memory must be released by the caller.
Loaddevstr returns the string obtained by reading the device
string descriptor number sid.
SOURCE
/sys/src/cmd/nusb/lib
SEE ALSO
usb(3), nusb(4).
BUGS
Not heavily exercised yet.
Tue Dec 1 08:52:07 EST 2026
term% sed -n '380,460p' /sys/src/cmd/nusb/usbd/hub.c
case 0x0A:
/* Compliance */
*e++ = 'C';
break;
case 0x0B:
/* Loopback */
*e++ = 'L';
break;
}
} else {
if(sts&PSslow)
*e++ = 'l';
if(sts&PShigh)
*e++ = 'h';
if(sts&PSchange)
*e++ = 'c';
if(sts&PSstatuschg)
*e++ = 's';
if(sts&PSsuspend)
*e++ = 'z';
}
if(e == s)
*e++ = '-';
*e = 0;
return s;
}
static int
getmaxpkt(Dev *d)
{
uchar buf[8];
DDev *dd;
if(d->isusb3)
return 512;
dd = (DDev*)buf;
if(usbcmd(d, Rd2h|Rstd|Rdev, Rgetdesc, Ddev<<8|0, 0, buf,
sizeof(buf)) != sizeof(buf))
return -1;
return dd->bMaxPacketSize0;
}
/*
* BUG: does not consider max. power avail.
*/
static int
portattach(Hub *h, int p)
{
Dev *nd, *d;
Port *pp;
char *sp, fname[80], buf[40];
int mp, nr, i;
u32int sts;
d = h->dev;
pp = &h->port[p];
if(pp->state != Pdisabled)
return -1;
/*
* prevent repeated attaches in short succession as it is a indication
* for a reset loop or a very flanky device.
*/
if(pp->acount && nowms - pp->atime >= Attachdelay)
pp->acount = 0;
pp->atime = nowms;
if(++pp->acount > Attachcount){
fprint(2, "%s: %s: port %d: too many attaches in short
succession\n",
argv0, d->dir, p);
/* don't call portfail() */
return 1;
}
if(d->isusb3){
sts = pp->sts;
sp = "super";
} else {
if(portfeature(h, p, Fportreset, 1) < 0){
dprint(2, "%s: %s: port %d: set reset: %r\n", argv0,
d->dir, p);
return -1;
}
sleep(d->depth<0? Rootresetdelay: Portresetdelay);
if((sts = portstatus(h, p)) == -1)
return -1;
term% grep -n 'required.*attempts' /sys/src/cmd/nusb/*/*.[ch]
/sys/src/cmd/nusb/lib/dev.c:451: fprint(2, "%s: usbcmd: %s: %s required %d
attempts (%s)\n",
Tue Dec 1 08:46:23 EST 2026
ep6.0 enabled control rw speed full maxpkt 8 ntds 1 pollival 0 samplesz 0 hz 0 uframes 0 hub 2 port 2 rootport 1 addr 6 busy term% grep -n getdesc /sys/src/cmd/nusb/usbd/*.[ch] /sys/src/cmd/nusb/usbd/hub.c:28: getdesc(Usbdev *d, uchar typ) /sys/src/cmd/nusb/usbd/hub.c:133: dd = getdesc(h->dev->usb, dt); /sys/src/cmd/nusb/usbd/hub.c:135: nr = usbcmd(h->dev, Rd2h|Rclass|Rdev, Rgetdesc, dt<<8|0, 0, buf, sizeof buf); /sys/src/cmd/nusb/usbd/hub.c:137: fprint(2, "%s: %s: getdesc hub: %r\n", argv0, h->dev->dir); /sys/src/cmd/nusb/usbd/hub.c:416: if(usbcmd(d, Rd2h|Rstd|Rdev, Rgetdesc, Ddev<<8|0, 0, buf, sizeof(buf)) != sizeof(buf)) USB\VID_1A86&PID_7523&REV_0254
Tue Dec 1 08:33:12 EST 2026
USB(3) USB(3)
NAME
usb - USB Host Controller Interface
SYNOPSIS
bind -a #u /dev
/dev/usb
/dev/usb/ctl
/dev/usb/epN.M
/dev/usb/epN.M/data
/dev/usb/epN.M/ctl
...
DESCRIPTION
The Universal Serial Bus is a complex yet popular bus for
connecting all kind of devices to a computer. It is a
tree-shaped bus that provides both communication and (lim-
ited) power to devices. Branching points in the tree are
provided by devices called hubs. Hubs provide ports where
USB devices (also hubs) can be attached.
Most PCs have one or more USB controllers called host con-
trollers. Each one has a built-in hub called a root hub
providing several ports. In some cases, more hubs are
built-in and attached to a root hub port. The topology of
the network is a tree with at most 127 nodes, counting both
internal and leaf nodes.
Host controllers come in four flavours: UHCI and OHCI for
USB 1 (up to 12 Mb/s), EHCI for USB 2 (up to 480 Mb/s) and
XHCI for USB 3 (up to 5 Gb/s).
The USB bus is fully controlled by the host; all devices are
polled. Hubs are passive in the sense that they do not poll
the devices attached to them. The host polls those devices
and the hubs merely route the messages.
Devices may be added to or removed from the bus at any time.
When a device is attached, the host queries it to determine
its type and speed. The querying process is standardized.
The first level of querying is the same for all devices, the
next is somewhat specialized for particular classes of
devices (such as mice, keyboards, or audio devices). Spe-
cialization continues as subclasses and subsubclasses are
explored.
Enumeration of the bus and initial configuration of devices
is done by a user-level program, usbd. Device drivers are
implemented by separate user programs, although some of them
may be statically linked into usbd.
The kernel device described in this page is responsible for
providing I/O for using the devices through so called
endpoints. Access to the host controller is hidden from user
programs, which see just a set of endpoints. After system
initialization, some endpoints are created by the device to
permit I/O to root hubs. All other devices must be config-
ured by usbd.
Devices and Endpoints
A device includes one or more functions (e.g., audio output,
volume control buttons, mouse input, etc.) Communication
with device functions is performed by some combination of
issuing control requests to, sending data to, and receiving
data from device endpoints. Endpoints can be understood as
addresses in the bus. There are several types:
Control Their main use is to configure devices. Writ-
ing a message with a specific format (specified
in the USB specification) issues a request to
the device. If the request implies a reply, a
read can be made next to retrieve the requested
data (if the write succeeded).
Interrupt Used to send and receive messages to or from a
specific device function (e.g., to read events
from a mouse).
Bulk Used to send and receive larger amounts of data
through streams (e.g., to write blocks to a
disk).
Isochronous Used to send and receive data in a timely
manner (e.g., to write audio samples to a
speaker).
All USB devices include at least a control endpoint to per-
form device configuration. This is called the setup end-
point or endpoint zero. After configuring a device, other
endpoints may be created as dictated by the device to per-
form actual I/O.
Operation
Bus enumeration and device configuration is performed by
usbd and not by this driver. The driver provides an inter-
face to access existing endpoints (initially those for the
built-in root hubs), to create and configure other ones, and
to perform I/O through them.
Each directory /dev/usb/epN.M represents an endpoint, where
N is a number identifying a device and M is a number identi-
fying one of its endpoints.
For each device attached to the bus, and configured by usbd,
an endpoint zero (a setup endpoint) is provided at
/dev/usb/epN.0 for configuring the device. This is always a
control endpoint and represents the device itself.
The device driver may use the setup endpoint to issue con-
trol requests and perhaps to create more endpoints for the
device. Each new endpoint created has its own directory as
said above. For example, if the driver for the device
/dev/usb/epN.0 creates the endpoint number 3 for that
device, a directory /dev/usb/epN.3 will be available to
access that endpoint.
All endpoint directories contain two files: data and ctl.
The former has mode bit DMEXCL set and can be open by only
one process at a time.
data
The data file is used to perform actual I/O. In general,
reading from it retrieves data from the endpoint and writing
into it sends data to the endpoint. For control endpoints,
writing to this file issues a control request (which may
include data); if the request retrieves data from the
device, a following read on the file will provide such data.
USB errors reported by the endpoint upon I/O failures are
passed to the user process through the error string. I/O
stalls not resulting from an error, usually an indication
from the device, are reported by indicating that the number
of bytes transferred has been zero. In most cases, the
correct course of action after noticing the stall is for the
device driver to issue a `clear halt' request (see unstall
in nusb(2)) to resume I/O. The most common error is
`crc/timeout' indicating problems in communication with the
device (e.g., a physical detach of the device or a wiring
problem).
For control and isochronous transfers, there is an implicit
timeout performed by the kernel and it is not necessary for
applications to place their own timers. For other transfer
types, the kernel will not time out any operation by default
(but see the `timeout' control request).
ctl and status
The ctl file can be read to learn about the endpoint. It
contains information that can be used to locate a particular
device (or endpoint). It also accepts writes with textual
control requests described later.
This may result from the read of an endpoint control file:
(the first line is wrapped to make it fit here)
enabled control rw speed full maxpkt 64 pollival 0
samplesz 0 hz 0 hub 1 port 3 busy
storage csp 0x500608 vid 0x951 did 0x1613 Kingston 'DT 101 II'
The first line contains status information. The rest is
information supplied by usbd as an aid to locate devices.
The status information includes:
Device state One of config, enabled, and detached. An
endpoint starts in the config state, and
accepts control commands written to its ctl
file to configure the endpoint. When config-
ured, the state is enabled and the data file
is used as described above (several control
requests can still be issued to its ctl file,
but most will not be accepted from now on).
Upon severe errors, perhaps a physical
detachment from the bus, the endpoint enters
the detached state and no further I/O is
accepted on it. Files for an endpoint
(including its directory) vanish when the
device is detached and its files are no
longer open. Root hubs may not be detached.
Endpoint type control, iso, interrupt, or bulk, indicating
the type of transfer supported by the end-
point.
Endpoint mode One of r, w, or rw, depending on the direc-
tion of the endpoint (in, out, or inout).
Speed low (1.5 Mb/s), full (12 Mb/s), high (480
Mb/s) or super (5 Gb/s).
Maximum packet size
Used when performing I/O on the data file.
Polling interval
The polling period expressed as a number of
µframes (for high-speed endpoints) or frames
(for low- and full-speed endpoints). Note
that a µframe takes 125 µs while a frame
takes 1 ms. This is only of relevance for
interrupt and isochronous endpoints. This
value determines how often I/O happens. Note
that the control request adjusting the pol-
ling interval does not use these units, to
make things easier for USB device drivers.
Sample size Number of bytes per I/O sample (isochronous
endpoints only).
Frequency Number of samples per second (Hertz).
Hub address Device address of the hub where the device is
attached.
Port number Port number (in the hub) where the device is
attached.
Usage `busy' while the data file is open and `idle'
otherwise. This is useful to avoid disturb-
ing endpoints already run by a device driver.
The second line contains information describing the device:
Class name As provided by the device itself.
CSP Class, Subclass, and Protocol for the
device. If the device contains different
functions and has more CSPs, all of them
will be listed. The first one is that of
the device itself. For example, a mouse and
keyboard combo may identify itself as a key-
board but then include two CSPs, one for the
keyboard and another one for the mouse.
Vid and Did Vendor and device identifiers.
Device strings Provided by the device and identifying the
manufacturer and type of device.
For example, to find a mouse not yet in use by a driver,
scan the ctl files for enabled, idle, and csp 0x020103. A
mouse belongs to class 3 (in the least significant byte),
human interface device, subclass 1, boot, protocol 2, mouse
(protocol 1 would be the keyboard). USB class, subclass and
proto codes can be found at http://www.usb.org.
Control requests
Endpoint control files accept the following requests. In
most cases the driver does not issue them, leaving the task
to either usbd or the usb driver library documented in
nusb(2). Except for detach, reset, clrhalt, address and
debug commands, changing the settings of an endpoint while
its data file is held open is prohibited. The settings are
applied by the driver when the data file is opend.
detach Prevent further I/O on the device (delete the
endpoint) and remove its file interface as soon
as no process is using their files.
reset Request usbd to perform a port reset on the hub
that the device is attached to. This causes the
device to be re-enumerated.
maxpkt n Set the maximum packet size to n bytes.
pollival n Only for interrupt and isochronous endpoints.
Set the polling interval as a function of the
value n given by the endpoint descriptor. The
interval value used is the period n in bus time
units for low- and full-speed interrupt end-
points. Otherwise, the actual interval is 2n
and not n. Bus time units are 1 ms for low- and
full-speed endpoints and 125 µs for high-speed
endpoints. In most cases, the device driver may
ignore all this and issue the control request
supplying the polling interval value as found in
the endpoint descriptor. The kernel adjusts the
value according to the endpoint configuration
and converts it into the number of frames or
µframes between two consecutive polls.
samplesz n Use n as the number of bytes per sample.
hz n Use n as the number of samples per second.
ntds n Use n as the number of transactions per frame
(or µframe), as reported by the descriptor.
uframes n If n is set to 1 for an isochronous endpoint,
read(2) from the data file will not cross μframe
boundaries.
clrhalt Clear the halt condition for an endpoint. Used
to recover from a stall caused by a device to
signal its driver (usually due to an unknown
request or a failure to complete one).
info string Replaces description information in ctl with
string. Usbd uses this to add device descrip-
tions.
address Tell this driver that the device has been given
an address, which causes the device to enter the
enabled state.
name str Generates an additional file name, str, for the
data file of the endpoint. This file name
appears in the root directory of the `#u' tree.
For example, this is used by the audio device
driver to make the data file also available as
/dev/audio.
debug n Enable debugging of the endpoint. N is an
integer; larger values make diagnostics more
verbose. `0' stops debugging diagnostics. `1'
causes just problem reports. Bigger values
report almost everything.
timeout n Enable time-outs for the endpoint. Transfers
are timed out by the kernel after n ms. This
should not be used for control and isochronous
endpoints, which are always timed out.
Setup endpoints (those represented by epN.0 directories)
also accept the following requests:
new n type mode
Creates a new endpoint with number n of the given type
(ctl, bulk, intr, or iso). Mode may be r, w, or rw,
which creates, respectively, an input, output, or
input/output endpoint.
hub n [ttt] [mtt]
Tell this driver that the endpoint corresponds to a hub
device by setting the number of ports to n and option-
ally set the transaction translator think-time ttt and
multi transaction-translator mode mtt for high-speed
hubs.
Setup endpoints for hub devices also accept
newdev {low|full|high|super} port
Create a new setup endpoint to represent a new device.
The first argument is the device speed. Port is the
port number where the device is attached (the hub is
implied by the endpoint where the control request is
issued).
The file /dev/usb/ctl provides all the information provided
by the various ctl files when read. It accepts several
requests that refer to the entire driver and not to particu-
lar endpoints:
debug n Sets the global debug flag to n.
FILES
#u/usb root of the USB interface
SOURCE
/sys/src/9/port/usb.h
/sys/src/9/port/devusb.c
/sys/src/9/*/usb*.c
SEE ALSO
nusb(2), nusb(4), plan9.ini(8)
BUGS
USB controllers limit the speed of all their ports to that
of the slowest device connected to any one of them.
Isochronous input streams are not implemented for OHCI.
Some EHCI controllers drop completion interrupts and so must
be polled, which hurts throughput.
Tue Dec 1 08:11:52 EST 2026
NUSB(4) NUSB(4)
NAME
audio, disk, ether, kb, serial, ptp, usbd - Universal Serial
Bus drivers
SYNOPSIS
nusb/audio devid
nusb/cam [ -d ] devid
nusb/disk [ -d ] devid
nusb/ether [ -dD ] [ -t ethertype ] [ -a addr ] devid
nusb/kb [ -d ] devid
nusb/joy [ -d ] [ -b deadband ] devid
nusb/serial [ -d ] devid
nusb/ptp [ -dD ] devid
nusb/usbd [ -dD ]
DESCRIPTION
These programs drive USB devices of specific classes via
usb(3). Usually they are started by nusbrc(8) upon attach-
ment of the device to the bus. All drivers except usbd take
the decimal usb devid of the device they should handle as
their last argument. A driver's instance handles only one
device at a time.
Drivers that provide file systems make them available as
shares under /shr (see shr(3)) or /shr/usb (which is bound
after /dev by nusbrc(8)).
Options -d and -D trigger debug diagnostics and file system
debugging diagnostics for most drivers. Repeating any one of
these may increase verbosity.
Hubs
Usbd enumerates the tree of USB hubs and configures the
device on attachment. It provides a filesystem with the
files usbevent and usbhubctl (usually seen as /dev/usbevent
and /dev/usbhubctl).
When the usbevent file is read, it returns a 6-column,
space-separated line of text, one for each event. The
columns are: attach or detach followed by addr vid did csp
and hname. The addr is the decimal device address assigned.
Vid and did are formatted as 4 digit hexadecimal. Csp is
the device class, subclass, protocol identifier formatted as
6 digit hexadecimal. Usbd assigns a stable device identif-
ier based on the device descriptor for hname. This informa-
tion is read by nusbrc(8) and the addr and hname are passed
to a suitable driver as devid in the form addr:hname.
The usbhubctl file provides per-port power switching control
(PPPS) by writing the following 4-column command format:
portpower or portindicator followed by hub, port and the
state on or off where hub selects the hub device (using its
device address addr or hname) and port is the decimal port
number (counting from 1).
Keyboards and mice
Kb supports USB keyboards and mice either as separate USB
devices or as a single combined USB device. Scan codes from
the keyboard are sent to /dev/kbin to let kbdfs(8) process
them. Mouse events are sent to /dev/mousein in the same
way. A file /dev/hidNctl supports setting keyboard repeat
and delay setting, the unit is milliseconds.
Joysticks
Joy parses data packets from a given endpoint and prints
back any changes in the device's axes or buttons. Buttons
are identified via an integer id.
Directional buttons are reported either as buttons or axes
with 3 positions: 0, 128, and 255 for left (or up), center
and right (or down) respectively. Messages are in the form
axis id position.
A deadband in the range of [0.0,1.0] can be set with the -b
option to filter out input below a threshold on all analog
axes.
On/off buttons are reported as either down or up respec-
tively. Messages are in the form down|up id.
Disks
Disk configures and manages USB mass storage devices. It
provides a file system (usually seen under /dev) that
includes one directory per storage device, named sdUN[.M] in
correspondence with the USB device identifier and the
storage unit number (or LUN). The LUN is omitted for single
lun devices.
The storage device directory contains the usual files served
by sd(3): data, raw, and ctl.
The ctl file supplies the device geometry and partitions
when read. Ptp configures and exposes a camera's (and often
a mobile device's) storage to allow transferring data via
the Picture Transfer Protocol (PTP).
Ethernet
Ether handles USB ethernet devices. The file system provided
is compatible with ether(3) and added to the share usbnet
(see shr(3)) which is bound after /net by nusbrc(8) so the
device will appear as /net/etherUN. Without specifying the
-t option, the device is assumed to be a CDC compliant eth-
ernet communication device. Other devices might require set-
ting an explicit ethertype, such as rndis, smsc, url,
lan78xx, aue, a88772, a88178, or a88179 (see nusbrc(8)). On
devices that support it, the mac address can be set using
the -a addr option.
Serial and JTAG ports
Serial provides a file system (usually seen under /dev) that
includes one directory per USB serial port, named eiaUN or
eiaUN[.M]. In this directory there are two files, eiaU,
similar to eiaN in uart(3), and eiaUctl, which admits writes
in the same format as eiaNctl in uart(3). Reading from
eiaUctl gives the serial port's settings in the same format
as eiaNstatus in uart(3). Options are similar to those of
disk.
JTAG ports are similar but the files are named jtag and
jtagctl.
Audio devices
Audio configures and manages a USB audio device. It imple-
ments a file system (normally seen under /dev), exporting
audioUN , volumeUN and other files that have the same seman-
tics as audio(3)).
Camera devices
Cam configures and exposes a USB camera device's capabili-
ties, implementing a file system compatible with camv(1),
under a directory named camN[.M]. It provides the following
files: desc, showing all of the device's internal descrip-
tors and their values; format, listing admissible image
resolutions and framerates; ctl, the picture settings con-
trol file; frame, which captures and outputs a single video
frame as an image(6) file; and video, streaming video in a
preset format, resolution and framerate. In particular,
reading from the ctl file yields a space-separated list of
parameter settings, where the second and third columns
correspond to key-value pairs, and an optional fourth column
corresponds to the range of possible numerical values (for-
matted as minimum/increment/maximum). The same pairs can be
written to the file to configure the camera. Currently,
only the YUY2 video format is supported.
SOURCE
/sys/src/cmd/nusb
SEE ALSO
camv(1), joy(1), audio(3), ether(3), mouse(3), sd(3),
uart(3), usb(3), shr(3), image(6), nusbrc(8), kbdfs(8)
HISTORY
Joy first appeared in 9front (March, 2014).
Cam first appeared in 9front (March, 2018).
BUGS
The various device drivers are generic USB drivers and may
work only for certain devices of each class.
USB ATA storage devices are not supported.
The serial driver works only for the Prolific chip and Ftdi,
and control of the dcd and dsr signals and some of the extra
features are not implemented. For Ftdi, only the Sheevaplug
and Guruplug have been tried. There is support for the EHCI
debug port, but it loses bytes.
USB video format settings cannot be changed while camv(1) is
running, and must be set manually by writing them to
cam(4)'sctl file before starting the viewer.
Tue Dec 1 08:11:33 EST 2026
ep1.0 enabled control rw speed high maxpkt 64 ntds 1 pollival 0 samplesz 0 hz 0 uframes 0 hub 0 port 0 rootport 0 addr 0 busy roothub csp 0x000009 ports 1 dwcotg ep2.0 enabled control rw speed high maxpkt 64 ntds 1 pollival 0 samplesz 0 hz 0 uframes 0 hub 1 port 1 rootport 1 addr 2 busy hub csp 0x020009 ports 5 vid 0x0424 did 0x9514 none <nil> cf4bb dwcotg ep3.0 enabled control rw speed high maxpkt 64 ntds 1 pollival 0 samplesz 0 hz 0 uframes 0 hub 2 port 1 rootport 1 addr 3 busy vendor csp 0x0100ff vid 0x0424 did 0xec00 none <nil> fb8b8 dwcotg ep3.1 enabled bulk r speed high maxpkt 512 ntds 1 pollival 0 samplesz 0 hz 0 uframes 0 hub 2 port 1 rootport 1 addr 3 busy ep3.2 enabled bulk w speed high maxpkt 512 ntds 1 pollival 0 samplesz 0 hz 0 uframes 0 hub 2 port 1 rootport 1 addr 3 busy ep3.3 enabled interrupt r speed high maxpkt 16 ntds 1 pollival 8 samplesz 0 hz 0 uframes 0 hub 2 port 1 rootport 1 addr 3 idle ep4.0 enabled control rw speed low maxpkt 8 ntds 1 pollival 0 samplesz 0 hz 0 uframes 0 hub 2 port 5 rootport 1 addr 4 busy hid csp 0x010103 vid 0xc0f4 did 0x05e0 SZH 'usb keyboard' e4ac9 dwcotg ep4.1 enabled interrupt r speed low maxpkt 8 ntds 1 pollival 10 samplesz 0 hz 0 uframes 0 hub 2 port 5 rootport 1 addr 4 busy ep4.2 enabled interrupt r speed low maxpkt 8 ntds 1 pollival 10 samplesz 0 hz 0 uframes 0 hub 2 port 5 rootport 1 addr 4 busy ep5.0 enabled control rw speed full maxpkt 64 ntds 1 pollival 0 samplesz 0 hz 0 uframes 0 hub 2 port 4 rootport 1 addr 5 busy hid csp 0x020103 vid 0x0951 did 0x16e4 Kingston 'HyperX Pulsefire Raid' 8cae6 dwcotg ep5.1 enabled interrupt r speed full maxpkt 8 ntds 1 pollival 1 samplesz 0 hz 0 uframes 0 hub 2 port 4 rootport 1 addr 5 busy ep5.2 enabled interrupt r speed full maxpkt 8 ntds 1 pollival 1 samplesz 0 hz 0 uframes 0 hub 2 port 4 rootport 1 addr 5 busy ep5.3 enabled interrupt r speed full maxpkt 8 ntds 1 pollival 1 samplesz 0 hz 0 uframes 0 hub 2 port 4 rootport 1 addr 5 busy
Tue Dec 1 08:02:09 EST 2026
UART(3) UART(3)
NAME
uart, eia - serial communication control
SYNOPSIS
bind -a #t /dev
/dev/eia0
/dev/eia0ctl
/dev/eia0status
/dev/eia1
/dev/eia1ctl
/dev/eia1status
...
DESCRIPTION
The serial line devices serve a one-level directory, giving
access to the serial ports. Device n is accessed through
eian (the data file), eianctl (the control file), and
eianstatus (the read-only status file). Reads of the data
file will block until at least one byte is available. The
control file configures the port. It accepts the following
commands:
bn Set the baud rate to n.
cn Set hangup on DCD if n is non-zero; else clear it.
dn Set DTR if n is non-zero; else clear it.
en Set hangup on DSR if n is non-zero; else clear it.
f Flush output queue.
h Close input and output queues.
in Enable/disable the FIFOs. If n is zero the FIFOs are
disabled; otherwise n is taken as a trigger level for
the FIFOs. The trigger levels supported are device
dependant, but usually include 1, 4 and 8. An unrecog-
nised, but non-zero, value of n causes the maximum-
supported trigger level to be set.
kn Send a break lasting n milliseconds.
ln Set number of bits per byte to n. Legal values are 5,
6, 7, or 8.
mn Obey modem CTS signal if n is non-zero; else clear it.
n Make writes non-blocking.
pc Set parity to odd if c is o, to even if c is e; else
set no parity.
qn Set input and output queue limits to n.
rn Set RTS if n is non-zero; else clear it.
sn Set number of stop bits to n. Legal values are 1 or 2.
wn Set the uart clock timer to n times 100us.
The status files contain a textual representation of the
status of the line, in the format of the commands used on
the control file.
SOURCE
/sys/src/9/port/devuart.c
/sys/src/9/*/uart*.c
Tue Dec 1 05:51:23 EST 2026
Zdravo, htio sam znati vašu cijenu.
Tue Dec 1 02:01:50 EST 2026
#!/bin/rc
DNSSERVER='1.1.1.1 9.9.9.9'
# We need to do our own flags for dns
kill dns | rc
ndb/dns -r -s
# Physical ethernet ports (management on 0)
elan=0
ewan=1
eiot=3
# WAN address on the fw side
twan=10.255.0.254
# Using non-canonical bind names, careful.
for(n in /net.wan /net.iot /net.larpa /net.wg)
aux/stub -d $n
# From 4 port intel nic
bind '#I1' /net.wan
bind '#I3' /net.iot
bind '#I4' /net.larpa
bind '#I5' /net.wg
# Apply rules before we wire
if(! cat /lib/ndb/fw >/net/fw)
echo 'cpurc: /lib/ndb/fw did not load correctly' >[1=2]
# Wire each stack to the firewall
fn fwifc {
s=$1
z=$2
a=$3
<$s/ipifc/clone {
ifc=$s/ipifc/`{read}
>$ifc/ctl {
echo bind fw $z
echo add $a 255.255.255.0
echo iprouting 1
}
}
}
fwifc /net lan 10.255.0.10
fwifc /net.wan wan $twan
fwifc /net.iot iot 10.255.0.30
fwifc /net.larpa larpa 10.255.0.40
fwifc /net.wg wg 10.255.0.50
# Add routes
for(s in /net /net.iot /net.larpa)
echo add 0.0.0.0 /96 $twan >/$s/iproute
# Configure routes
echo add 10.0.1.0 255.255.255.0 10.255.0.10 >/net.wan/iproute
echo add 10.0.30.0 255.255.255.0 10.255.0.30 >/net.wan/iproute
echo add 10.0.40.0 255.255.255.0 10.255.0.40 >/net.wan/iproute
echo add 10.0.50.0 255.255.255.0 10.255.0.50 >/net.wan/iproute
# Configure the wg routes for LAN
echo add 10.0.1.0 255.255.255.0 10.255.0.10 >/net.wg/iproute
echo add 10.0.50.0 255.255.255.0 10.255.0.50 >/net/iproute
# Configure the larpa route for LAN - for now we don't share any hosts
echo add 10.0.1.0 255.255.255.0 10.255.0.10 >/net.larpa/iproute
echo add 10.0.40.0 255.255.255.0 10.255.0.40 >/net/iproute
echo add 10.0.1.53 255.255.255.255 >/net/ipifc/0/ctl
# Bind the ports inside the router
bind -a '#l'$eiot /net.iot
bind -a '#l'$ewan /net.wan
# Set base address for each
ip/ipconfig -x /net.iot ether /net.iot/ether$eiot 10.0.30.1 255.255.255.0
# Start up iot services
ndb/cs -x /net.iot
ndb/dns -x /net.iot -s
ip/dhcpd -x /net.iot 10.0.30.100 100
# Start up our Omada controller container
#vmx -M 2G -n ea:deadbeeffeed!ether0 -d /lib/vmx/debian.img -m /lib/vmx/initrd
/lib/vmx/vmlinuz 'root=/dev/vda1 rootfstype=ext4' &
# Wireguard, gets a whole /24
ip/wg -x /net.wg -o /net.wan -c /cfg/routey/wg.conf 10.0.50.1 255.255.255.0
# Each larpanet peer gets a 31
ip/wg -x /net.larpa -o /net.wan -c /cfg/routey/amber.conf 10.0.40.10
255.255.255.254
#ip/wg -x /net.larpa -o /net.wan -c /cfg/routey/calico.conf 10.0.40.12
255.255.255.254
#ip/wg -x /net.larpa -o /net.wan -c /cfg/routey/coneja.conf 10.0.40.14
255.255.255.254
#ip/wg -x /net.larpa -o /net.wan -c /cfg/routey/mustelid.conf 10.0.40.16
255.255.255.254
#ip/wg -x /net.larpa -o /net.wan -c /cfg/routey/copal.conf 10.0.40.18
255.255.255.254
# We have no bgp yet
# Now the ISP uplink, -t for NAT (DHCP, but we could try for static as well)
ip/ipconfig -x /net.wan -t ether /net.wan/ether$ewan
ip/dhcpd -x /net 10.0.1.20 235