162306a36Sopenharmony_ci.. _usb-hostside-api: 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci=========================== 462306a36Sopenharmony_ciThe Linux-USB Host Side API 562306a36Sopenharmony_ci=========================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciIntroduction to USB on Linux 862306a36Sopenharmony_ci============================ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciA Universal Serial Bus (USB) is used to connect a host, such as a PC or 1162306a36Sopenharmony_ciworkstation, to a number of peripheral devices. USB uses a tree 1262306a36Sopenharmony_cistructure, with the host as the root (the system's master), hubs as 1362306a36Sopenharmony_ciinterior nodes, and peripherals as leaves (and slaves). Modern PCs 1462306a36Sopenharmony_cisupport several such trees of USB devices, usually 1562306a36Sopenharmony_cia few USB 3.0 (5 GBit/s) or USB 3.1 (10 GBit/s) and some legacy 1662306a36Sopenharmony_ciUSB 2.0 (480 MBit/s) busses just in case. 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ciThat master/slave asymmetry was designed-in for a number of reasons, one 1962306a36Sopenharmony_cibeing ease of use. It is not physically possible to mistake upstream and 2062306a36Sopenharmony_cidownstream or it does not matter with a type C plug (or they are built into the 2162306a36Sopenharmony_ciperipheral). Also, the host software doesn't need to deal with 2262306a36Sopenharmony_cidistributed auto-configuration since the pre-designated master node 2362306a36Sopenharmony_cimanages all that. 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciKernel developers added USB support to Linux early in the 2.2 kernel 2662306a36Sopenharmony_ciseries and have been developing it further since then. Besides support 2762306a36Sopenharmony_cifor each new generation of USB, various host controllers gained support, 2862306a36Sopenharmony_cinew drivers for peripherals have been added and advanced features for latency 2962306a36Sopenharmony_cimeasurement and improved power management introduced. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciLinux can run inside USB devices as well as on the hosts that control 3262306a36Sopenharmony_cithe devices. But USB device drivers running inside those peripherals 3362306a36Sopenharmony_cidon't do the same things as the ones running inside hosts, so they've 3462306a36Sopenharmony_cibeen given a different name: *gadget drivers*. This document does not 3562306a36Sopenharmony_cicover gadget drivers. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ciUSB Host-Side API Model 3862306a36Sopenharmony_ci======================= 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ciHost-side drivers for USB devices talk to the "usbcore" APIs. There are 4162306a36Sopenharmony_citwo. One is intended for *general-purpose* drivers (exposed through 4262306a36Sopenharmony_cidriver frameworks), and the other is for drivers that are *part of the 4362306a36Sopenharmony_cicore*. Such core drivers include the *hub* driver (which manages trees 4462306a36Sopenharmony_ciof USB devices) and several different kinds of *host controller 4562306a36Sopenharmony_cidrivers*, which control individual busses. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciThe device model seen by USB drivers is relatively complex. 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci- USB supports four kinds of data transfers (control, bulk, interrupt, 5062306a36Sopenharmony_ci and isochronous). Two of them (control and bulk) use bandwidth as 5162306a36Sopenharmony_ci it's available, while the other two (interrupt and isochronous) are 5262306a36Sopenharmony_ci scheduled to provide guaranteed bandwidth. 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci- The device description model includes one or more "configurations" 5562306a36Sopenharmony_ci per device, only one of which is active at a time. Devices are supposed 5662306a36Sopenharmony_ci to be capable of operating at lower than their top 5762306a36Sopenharmony_ci speeds and may provide a BOS descriptor showing the lowest speed they 5862306a36Sopenharmony_ci remain fully operational at. 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci- From USB 3.0 on configurations have one or more "functions", which 6162306a36Sopenharmony_ci provide a common functionality and are grouped together for purposes 6262306a36Sopenharmony_ci of power management. 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci- Configurations or functions have one or more "interfaces", each of which may have 6562306a36Sopenharmony_ci "alternate settings". Interfaces may be standardized by USB "Class" 6662306a36Sopenharmony_ci specifications, or may be specific to a vendor or device. 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci USB device drivers actually bind to interfaces, not devices. Think of 6962306a36Sopenharmony_ci them as "interface drivers", though you may not see many devices 7062306a36Sopenharmony_ci where the distinction is important. *Most USB devices are simple, 7162306a36Sopenharmony_ci with only one function, one configuration, one interface, and one alternate 7262306a36Sopenharmony_ci setting.* 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci- Interfaces have one or more "endpoints", each of which supports one 7562306a36Sopenharmony_ci type and direction of data transfer such as "bulk out" or "interrupt 7662306a36Sopenharmony_ci in". The entire configuration may have up to sixteen endpoints in 7762306a36Sopenharmony_ci each direction, allocated as needed among all the interfaces. 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci- Data transfer on USB is packetized; each endpoint has a maximum 8062306a36Sopenharmony_ci packet size. Drivers must often be aware of conventions such as 8162306a36Sopenharmony_ci flagging the end of bulk transfers using "short" (including zero 8262306a36Sopenharmony_ci length) packets. 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci- The Linux USB API supports synchronous calls for control and bulk 8562306a36Sopenharmony_ci messages. It also supports asynchronous calls for all kinds of data 8662306a36Sopenharmony_ci transfer, using request structures called "URBs" (USB Request 8762306a36Sopenharmony_ci Blocks). 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciAccordingly, the USB Core API exposed to device drivers covers quite a 9062306a36Sopenharmony_cilot of territory. You'll probably need to consult the USB 3.0 9162306a36Sopenharmony_cispecification, available online from www.usb.org at no cost, as well as 9262306a36Sopenharmony_ciclass or device specifications. 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ciThe only host-side drivers that actually touch hardware (reading/writing 9562306a36Sopenharmony_ciregisters, handling IRQs, and so on) are the HCDs. In theory, all HCDs 9662306a36Sopenharmony_ciprovide the same functionality through the same API. In practice, that's 9762306a36Sopenharmony_cibecoming more true, but there are still differences 9862306a36Sopenharmony_cithat crop up especially with fault handling on the less common controllers. 9962306a36Sopenharmony_ciDifferent controllers don't 10062306a36Sopenharmony_cinecessarily report the same aspects of failures, and recovery from 10162306a36Sopenharmony_cifaults (including software-induced ones like unlinking an URB) isn't yet 10262306a36Sopenharmony_cifully consistent. Device driver authors should make a point of doing 10362306a36Sopenharmony_cidisconnect testing (while the device is active) with each different host 10462306a36Sopenharmony_cicontroller driver, to make sure drivers don't have bugs of their own as 10562306a36Sopenharmony_ciwell as to make sure they aren't relying on some HCD-specific behavior. 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci.. _usb_chapter9: 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ciUSB-Standard Types 11062306a36Sopenharmony_ci================== 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ciIn ``include/uapi/linux/usb/ch9.h`` you will find the USB data types defined 11362306a36Sopenharmony_ciin chapter 9 of the USB specification. These data types are used throughout 11462306a36Sopenharmony_ciUSB, and in APIs including this host side API, gadget APIs, usb character 11562306a36Sopenharmony_cidevices and debugfs interfaces. That file is itself included by 11662306a36Sopenharmony_ci``include/linux/usb/ch9.h``, which also contains declarations of a few 11762306a36Sopenharmony_ciutility routines for manipulating these data types; the implementations 11862306a36Sopenharmony_ciare in ``drivers/usb/common/common.c``. 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/common/common.c 12162306a36Sopenharmony_ci :export: 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ciIn addition, some functions useful for creating debugging output are 12462306a36Sopenharmony_cidefined in ``drivers/usb/common/debug.c``. 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci.. _usb_header: 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ciHost-Side Data Types and Macros 12962306a36Sopenharmony_ci=============================== 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ciThe host side API exposes several layers to drivers, some of which are 13262306a36Sopenharmony_cimore necessary than others. These support lifecycle models for host side 13362306a36Sopenharmony_cidrivers and devices, and support passing buffers through usbcore to some 13462306a36Sopenharmony_ciHCD that performs the I/O for the device driver. 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci.. kernel-doc:: include/linux/usb.h 13762306a36Sopenharmony_ci :internal: 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciUSB Core APIs 14062306a36Sopenharmony_ci============= 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ciThere are two basic I/O models in the USB API. The most elemental one is 14362306a36Sopenharmony_ciasynchronous: drivers submit requests in the form of an URB, and the 14462306a36Sopenharmony_ciURB's completion callback handles the next step. All USB transfer types 14562306a36Sopenharmony_cisupport that model, although there are special cases for control URBs 14662306a36Sopenharmony_ci(which always have setup and status stages, but may not have a data 14762306a36Sopenharmony_cistage) and isochronous URBs (which allow large packets and include 14862306a36Sopenharmony_ciper-packet fault reports). Built on top of that is synchronous API 14962306a36Sopenharmony_cisupport, where a driver calls a routine that allocates one or more URBs, 15062306a36Sopenharmony_cisubmits them, and waits until they complete. There are synchronous 15162306a36Sopenharmony_ciwrappers for single-buffer control and bulk transfers (which are awkward 15262306a36Sopenharmony_cito use in some driver disconnect scenarios), and for scatterlist based 15362306a36Sopenharmony_cistreaming i/o (bulk or interrupt). 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ciUSB drivers need to provide buffers that can be used for DMA, although 15662306a36Sopenharmony_cithey don't necessarily need to provide the DMA mapping themselves. There 15762306a36Sopenharmony_ciare APIs to use used when allocating DMA buffers, which can prevent use 15862306a36Sopenharmony_ciof bounce buffers on some systems. In some cases, drivers may be able to 15962306a36Sopenharmony_cirely on 64bit DMA to eliminate another kind of bounce buffer. 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/urb.c 16262306a36Sopenharmony_ci :export: 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/message.c 16562306a36Sopenharmony_ci :export: 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/file.c 16862306a36Sopenharmony_ci :export: 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/driver.c 17162306a36Sopenharmony_ci :export: 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/usb.c 17462306a36Sopenharmony_ci :export: 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/hub.c 17762306a36Sopenharmony_ci :export: 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ciHost Controller APIs 18062306a36Sopenharmony_ci==================== 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ciThese APIs are only for use by host controller drivers, most of which 18362306a36Sopenharmony_ciimplement standard register interfaces such as XHCI, EHCI, OHCI, or UHCI. UHCI 18462306a36Sopenharmony_ciwas one of the first interfaces, designed by Intel and also used by VIA; 18562306a36Sopenharmony_ciit doesn't do much in hardware. OHCI was designed later, to have the 18662306a36Sopenharmony_cihardware do more work (bigger transfers, tracking protocol state, and so 18762306a36Sopenharmony_cion). EHCI was designed with USB 2.0; its design has features that 18862306a36Sopenharmony_ciresemble OHCI (hardware does much more work) as well as UHCI (some parts 18962306a36Sopenharmony_ciof ISO support, TD list processing). XHCI was designed with USB 3.0. It 19062306a36Sopenharmony_cicontinues to shift support for functionality into hardware. 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ciThere are host controllers other than the "big three", although most PCI 19362306a36Sopenharmony_cibased controllers (and a few non-PCI based ones) use one of those 19462306a36Sopenharmony_ciinterfaces. Not all host controllers use DMA; some use PIO, and there is 19562306a36Sopenharmony_cialso a simulator and a virtual host controller to pipe USB over the network. 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ciThe same basic APIs are available to drivers for all those controllers. 19862306a36Sopenharmony_ciFor historical reasons they are in two layers: :c:type:`struct 19962306a36Sopenharmony_ciusb_bus <usb_bus>` is a rather thin layer that became available 20062306a36Sopenharmony_ciin the 2.2 kernels, while :c:type:`struct usb_hcd <usb_hcd>` 20162306a36Sopenharmony_ciis a more featureful layer 20262306a36Sopenharmony_cithat lets HCDs share common code, to shrink driver size and 20362306a36Sopenharmony_cisignificantly reduce hcd-specific behaviors. 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/hcd.c 20662306a36Sopenharmony_ci :export: 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/hcd-pci.c 20962306a36Sopenharmony_ci :export: 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci.. kernel-doc:: drivers/usb/core/buffer.c 21262306a36Sopenharmony_ci :internal: 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ciThe USB character device nodes 21562306a36Sopenharmony_ci============================== 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ciThis chapter presents the Linux character device nodes. You may prefer 21862306a36Sopenharmony_cito avoid writing new kernel code for your USB driver. User mode device 21962306a36Sopenharmony_cidrivers are usually packaged as applications or libraries, and may use 22062306a36Sopenharmony_cicharacter devices through some programming library that wraps it. 22162306a36Sopenharmony_ciSuch libraries include: 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and 22462306a36Sopenharmony_ci - `jUSB <http://jUSB.sourceforge.net>`__ for Java. 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ciSome old information about it can be seen at the "USB Device Filesystem" 22762306a36Sopenharmony_cisection of the USB Guide. The latest copy of the USB Guide can be found 22862306a36Sopenharmony_ciat http://www.linux-usb.org/ 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci.. note:: 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ci - They were used to be implemented via *usbfs*, but this is not part of 23362306a36Sopenharmony_ci the sysfs debug interface. 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci - This particular documentation is incomplete, especially with respect 23662306a36Sopenharmony_ci to the asynchronous mode. As of kernel 2.5.66 the code and this 23762306a36Sopenharmony_ci (new) documentation need to be cross-reviewed. 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ciWhat files are in "devtmpfs"? 24062306a36Sopenharmony_ci----------------------------- 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ciConventionally mounted at ``/dev/bus/usb/``, usbfs features include: 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci- ``/dev/bus/usb/BBB/DDD`` ... magic files exposing the each device's 24562306a36Sopenharmony_ci configuration descriptors, and supporting a series of ioctls for 24662306a36Sopenharmony_ci making device requests, including I/O to devices. (Purely for access 24762306a36Sopenharmony_ci by programs.) 24862306a36Sopenharmony_ci 24962306a36Sopenharmony_ciEach bus is given a number (``BBB``) based on when it was enumerated; within 25062306a36Sopenharmony_cieach bus, each device is given a similar number (``DDD``). Those ``BBB/DDD`` 25162306a36Sopenharmony_cipaths are not "stable" identifiers; expect them to change even if you 25262306a36Sopenharmony_cialways leave the devices plugged in to the same hub port. *Don't even 25362306a36Sopenharmony_cithink of saving these in application configuration files.* Stable 25462306a36Sopenharmony_ciidentifiers are available, for user mode applications that want to use 25562306a36Sopenharmony_cithem. HID and networking devices expose these stable IDs, so that for 25662306a36Sopenharmony_ciexample you can be sure that you told the right UPS to power down its 25762306a36Sopenharmony_cisecond server. Pleast note that it doesn't (yet) expose those IDs. 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ci/dev/bus/usb/BBB/DDD 26062306a36Sopenharmony_ci-------------------- 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ciUse these files in one of these basic ways: 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci- *They can be read,* producing first the device descriptor (18 bytes) and 26562306a36Sopenharmony_ci then the descriptors for the current configuration. See the USB 2.0 spec 26662306a36Sopenharmony_ci for details about those binary data formats. You'll need to convert most 26762306a36Sopenharmony_ci multibyte values from little endian format to your native host byte 26862306a36Sopenharmony_ci order, although a few of the fields in the device descriptor (both of 26962306a36Sopenharmony_ci the BCD-encoded fields, and the vendor and product IDs) will be 27062306a36Sopenharmony_ci byteswapped for you. Note that configuration descriptors include 27162306a36Sopenharmony_ci descriptors for interfaces, altsettings, endpoints, and maybe additional 27262306a36Sopenharmony_ci class descriptors. 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ci- *Perform USB operations* using *ioctl()* requests to make endpoint I/O 27562306a36Sopenharmony_ci requests (synchronously or asynchronously) or manage the device. These 27662306a36Sopenharmony_ci requests need the ``CAP_SYS_RAWIO`` capability, as well as filesystem 27762306a36Sopenharmony_ci access permissions. Only one ioctl request can be made on one of these 27862306a36Sopenharmony_ci device files at a time. This means that if you are synchronously reading 27962306a36Sopenharmony_ci an endpoint from one thread, you won't be able to write to a different 28062306a36Sopenharmony_ci endpoint from another thread until the read completes. This works for 28162306a36Sopenharmony_ci *half duplex* protocols, but otherwise you'd use asynchronous i/o 28262306a36Sopenharmony_ci requests. 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ciEach connected USB device has one file. The ``BBB`` indicates the bus 28562306a36Sopenharmony_cinumber. The ``DDD`` indicates the device address on that bus. Both 28662306a36Sopenharmony_ciof these numbers are assigned sequentially, and can be reused, so 28762306a36Sopenharmony_ciyou can't rely on them for stable access to devices. For example, 28862306a36Sopenharmony_ciit's relatively common for devices to re-enumerate while they are 28962306a36Sopenharmony_cistill connected (perhaps someone jostled their power supply, hub, 29062306a36Sopenharmony_cior USB cable), so a device might be ``002/027`` when you first connect 29162306a36Sopenharmony_ciit and ``002/048`` sometime later. 29262306a36Sopenharmony_ci 29362306a36Sopenharmony_ciThese files can be read as binary data. The binary data consists 29462306a36Sopenharmony_ciof first the device descriptor, then the descriptors for each 29562306a36Sopenharmony_ciconfiguration of the device. Multi-byte fields in the device descriptor 29662306a36Sopenharmony_ciare converted to host endianness by the kernel. The configuration 29762306a36Sopenharmony_cidescriptors are in bus endian format! The configuration descriptor 29862306a36Sopenharmony_ciare wTotalLength bytes apart. If a device returns less configuration 29962306a36Sopenharmony_cidescriptor data than indicated by wTotalLength there will be a hole in 30062306a36Sopenharmony_cithe file for the missing bytes. This information is also shown 30162306a36Sopenharmony_ciin text form by the ``/sys/kernel/debug/usb/devices`` file, described later. 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ciThese files may also be used to write user-level drivers for the USB 30462306a36Sopenharmony_cidevices. You would open the ``/dev/bus/usb/BBB/DDD`` file read/write, 30562306a36Sopenharmony_ciread its descriptors to make sure it's the device you expect, and then 30662306a36Sopenharmony_cibind to an interface (or perhaps several) using an ioctl call. You 30762306a36Sopenharmony_ciwould issue more ioctls to the device to communicate to it using 30862306a36Sopenharmony_cicontrol, bulk, or other kinds of USB transfers. The IOCTLs are 30962306a36Sopenharmony_cilisted in the ``<linux/usbdevice_fs.h>`` file, and at this writing the 31062306a36Sopenharmony_cisource code (``linux/drivers/usb/core/devio.c``) is the primary reference 31162306a36Sopenharmony_cifor how to access devices through those files. 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ciNote that since by default these ``BBB/DDD`` files are writable only by 31462306a36Sopenharmony_ciroot, only root can write such user mode drivers. You can selectively 31562306a36Sopenharmony_cigrant read/write permissions to other users by using ``chmod``. Also, 31662306a36Sopenharmony_ciusbfs mount options such as ``devmode=0666`` may be helpful. 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ciLife Cycle of User Mode Drivers 32062306a36Sopenharmony_ci------------------------------- 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ciSuch a driver first needs to find a device file for a device it knows 32362306a36Sopenharmony_cihow to handle. Maybe it was told about it because a ``/sbin/hotplug`` 32462306a36Sopenharmony_cievent handling agent chose that driver to handle the new device. Or 32562306a36Sopenharmony_cimaybe it's an application that scans all the ``/dev/bus/usb`` device files, 32662306a36Sopenharmony_ciand ignores most devices. In either case, it should :c:func:`read()` 32762306a36Sopenharmony_ciall the descriptors from the device file, and check them against what it 32862306a36Sopenharmony_ciknows how to handle. It might just reject everything except a particular 32962306a36Sopenharmony_civendor and product ID, or need a more complex policy. 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ciNever assume there will only be one such device on the system at a time! 33262306a36Sopenharmony_ciIf your code can't handle more than one device at a time, at least 33362306a36Sopenharmony_cidetect when there's more than one, and have your users choose which 33462306a36Sopenharmony_cidevice to use. 33562306a36Sopenharmony_ci 33662306a36Sopenharmony_ciOnce your user mode driver knows what device to use, it interacts with 33762306a36Sopenharmony_ciit in either of two styles. The simple style is to make only control 33862306a36Sopenharmony_cirequests; some devices don't need more complex interactions than those. 33962306a36Sopenharmony_ci(An example might be software using vendor-specific control requests for 34062306a36Sopenharmony_cisome initialization or configuration tasks, with a kernel driver for the 34162306a36Sopenharmony_cirest.) 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ciMore likely, you need a more complex style driver: one using non-control 34462306a36Sopenharmony_ciendpoints, reading or writing data and claiming exclusive use of an 34562306a36Sopenharmony_ciinterface. *Bulk* transfers are easiest to use, but only their sibling 34662306a36Sopenharmony_ci*interrupt* transfers work with low speed devices. Both interrupt and 34762306a36Sopenharmony_ci*isochronous* transfers offer service guarantees because their bandwidth 34862306a36Sopenharmony_ciis reserved. Such "periodic" transfers are awkward to use through usbfs, 34962306a36Sopenharmony_ciunless you're using the asynchronous calls. However, interrupt transfers 35062306a36Sopenharmony_cican also be used in a synchronous "one shot" style. 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ciYour user-mode driver should never need to worry about cleaning up 35362306a36Sopenharmony_cirequest state when the device is disconnected, although it should close 35462306a36Sopenharmony_ciits open file descriptors as soon as it starts seeing the ENODEV errors. 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_ciThe ioctl() Requests 35762306a36Sopenharmony_ci-------------------- 35862306a36Sopenharmony_ci 35962306a36Sopenharmony_ciTo use these ioctls, you need to include the following headers in your 36062306a36Sopenharmony_ciuserspace program:: 36162306a36Sopenharmony_ci 36262306a36Sopenharmony_ci #include <linux/usb.h> 36362306a36Sopenharmony_ci #include <linux/usbdevice_fs.h> 36462306a36Sopenharmony_ci #include <asm/byteorder.h> 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ciThe standard USB device model requests, from "Chapter 9" of the USB 2.0 36762306a36Sopenharmony_cispecification, are automatically included from the ``<linux/usb/ch9.h>`` 36862306a36Sopenharmony_ciheader. 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ciUnless noted otherwise, the ioctl requests described here will update 37162306a36Sopenharmony_cithe modification time on the usbfs file to which they are applied 37262306a36Sopenharmony_ci(unless they fail). A return of zero indicates success; otherwise, a 37362306a36Sopenharmony_cistandard USB error code is returned (These are documented in 37462306a36Sopenharmony_ci:ref:`usb-error-codes`). 37562306a36Sopenharmony_ci 37662306a36Sopenharmony_ciEach of these files multiplexes access to several I/O streams, one per 37762306a36Sopenharmony_ciendpoint. Each device has one control endpoint (endpoint zero) which 37862306a36Sopenharmony_cisupports a limited RPC style RPC access. Devices are configured by 37962306a36Sopenharmony_cihub_wq (in the kernel) setting a device-wide *configuration* that 38062306a36Sopenharmony_ciaffects things like power consumption and basic functionality. The 38162306a36Sopenharmony_ciendpoints are part of USB *interfaces*, which may have *altsettings* 38262306a36Sopenharmony_ciaffecting things like which endpoints are available. Many devices only 38362306a36Sopenharmony_cihave a single configuration and interface, so drivers for them will 38462306a36Sopenharmony_ciignore configurations and altsettings. 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ciManagement/Status Requests 38762306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~ 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ciA number of usbfs requests don't deal very directly with device I/O. 39062306a36Sopenharmony_ciThey mostly relate to device management and status. These are all 39162306a36Sopenharmony_cisynchronous requests. 39262306a36Sopenharmony_ci 39362306a36Sopenharmony_ciUSBDEVFS_CLAIMINTERFACE 39462306a36Sopenharmony_ci This is used to force usbfs to claim a specific interface, which has 39562306a36Sopenharmony_ci not previously been claimed by usbfs or any other kernel driver. The 39662306a36Sopenharmony_ci ioctl parameter is an integer holding the number of the interface 39762306a36Sopenharmony_ci (bInterfaceNumber from descriptor). 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ci Note that if your driver doesn't claim an interface before trying to 40062306a36Sopenharmony_ci use one of its endpoints, and no other driver has bound to it, then 40162306a36Sopenharmony_ci the interface is automatically claimed by usbfs. 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci This claim will be released by a RELEASEINTERFACE ioctl, or by 40462306a36Sopenharmony_ci closing the file descriptor. File modification time is not updated 40562306a36Sopenharmony_ci by this request. 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ciUSBDEVFS_CONNECTINFO 40862306a36Sopenharmony_ci Says whether the device is lowspeed. The ioctl parameter points to a 40962306a36Sopenharmony_ci structure like this:: 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci struct usbdevfs_connectinfo { 41262306a36Sopenharmony_ci unsigned int devnum; 41362306a36Sopenharmony_ci unsigned char slow; 41462306a36Sopenharmony_ci }; 41562306a36Sopenharmony_ci 41662306a36Sopenharmony_ci File modification time is not updated by this request. 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_ci *You can't tell whether a "not slow" device is connected at high 41962306a36Sopenharmony_ci speed (480 MBit/sec) or just full speed (12 MBit/sec).* You should 42062306a36Sopenharmony_ci know the devnum value already, it's the DDD value of the device file 42162306a36Sopenharmony_ci name. 42262306a36Sopenharmony_ci 42362306a36Sopenharmony_ciUSBDEVFS_GET_SPEED 42462306a36Sopenharmony_ci Returns the speed of the device. The speed is returned as a 42562306a36Sopenharmony_ci nummerical value in accordance with enum usb_device_speed 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ci File modification time is not updated by this request. 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ciUSBDEVFS_GETDRIVER 43062306a36Sopenharmony_ci Returns the name of the kernel driver bound to a given interface (a 43162306a36Sopenharmony_ci string). Parameter is a pointer to this structure, which is 43262306a36Sopenharmony_ci modified:: 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ci struct usbdevfs_getdriver { 43562306a36Sopenharmony_ci unsigned int interface; 43662306a36Sopenharmony_ci char driver[USBDEVFS_MAXDRIVERNAME + 1]; 43762306a36Sopenharmony_ci }; 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ci File modification time is not updated by this request. 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ciUSBDEVFS_IOCTL 44262306a36Sopenharmony_ci Passes a request from userspace through to a kernel driver that has 44362306a36Sopenharmony_ci an ioctl entry in the *struct usb_driver* it registered:: 44462306a36Sopenharmony_ci 44562306a36Sopenharmony_ci struct usbdevfs_ioctl { 44662306a36Sopenharmony_ci int ifno; 44762306a36Sopenharmony_ci int ioctl_code; 44862306a36Sopenharmony_ci void *data; 44962306a36Sopenharmony_ci }; 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ci /* user mode call looks like this. 45262306a36Sopenharmony_ci * 'request' becomes the driver->ioctl() 'code' parameter. 45362306a36Sopenharmony_ci * the size of 'param' is encoded in 'request', and that data 45462306a36Sopenharmony_ci * is copied to or from the driver->ioctl() 'buf' parameter. 45562306a36Sopenharmony_ci */ 45662306a36Sopenharmony_ci static int 45762306a36Sopenharmony_ci usbdev_ioctl (int fd, int ifno, unsigned request, void *param) 45862306a36Sopenharmony_ci { 45962306a36Sopenharmony_ci struct usbdevfs_ioctl wrapper; 46062306a36Sopenharmony_ci 46162306a36Sopenharmony_ci wrapper.ifno = ifno; 46262306a36Sopenharmony_ci wrapper.ioctl_code = request; 46362306a36Sopenharmony_ci wrapper.data = param; 46462306a36Sopenharmony_ci 46562306a36Sopenharmony_ci return ioctl (fd, USBDEVFS_IOCTL, &wrapper); 46662306a36Sopenharmony_ci } 46762306a36Sopenharmony_ci 46862306a36Sopenharmony_ci File modification time is not updated by this request. 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci This request lets kernel drivers talk to user mode code through 47162306a36Sopenharmony_ci filesystem operations even when they don't create a character or 47262306a36Sopenharmony_ci block special device. It's also been used to do things like ask 47362306a36Sopenharmony_ci devices what device special file should be used. Two pre-defined 47462306a36Sopenharmony_ci ioctls are used to disconnect and reconnect kernel drivers, so that 47562306a36Sopenharmony_ci user mode code can completely manage binding and configuration of 47662306a36Sopenharmony_ci devices. 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ciUSBDEVFS_RELEASEINTERFACE 47962306a36Sopenharmony_ci This is used to release the claim usbfs made on interface, either 48062306a36Sopenharmony_ci implicitly or because of a USBDEVFS_CLAIMINTERFACE call, before the 48162306a36Sopenharmony_ci file descriptor is closed. The ioctl parameter is an integer holding 48262306a36Sopenharmony_ci the number of the interface (bInterfaceNumber from descriptor); File 48362306a36Sopenharmony_ci modification time is not updated by this request. 48462306a36Sopenharmony_ci 48562306a36Sopenharmony_ci .. warning:: 48662306a36Sopenharmony_ci 48762306a36Sopenharmony_ci *No security check is made to ensure that the task which made 48862306a36Sopenharmony_ci the claim is the one which is releasing it. This means that user 48962306a36Sopenharmony_ci mode driver may interfere other ones.* 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_ciUSBDEVFS_RESETEP 49262306a36Sopenharmony_ci Resets the data toggle value for an endpoint (bulk or interrupt) to 49362306a36Sopenharmony_ci DATA0. The ioctl parameter is an integer endpoint number (1 to 15, 49462306a36Sopenharmony_ci as identified in the endpoint descriptor), with USB_DIR_IN added 49562306a36Sopenharmony_ci if the device's endpoint sends data to the host. 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_ci .. Warning:: 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci *Avoid using this request. It should probably be removed.* Using 50062306a36Sopenharmony_ci it typically means the device and driver will lose toggle 50162306a36Sopenharmony_ci synchronization. If you really lost synchronization, you likely 50262306a36Sopenharmony_ci need to completely handshake with the device, using a request 50362306a36Sopenharmony_ci like CLEAR_HALT or SET_INTERFACE. 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ciUSBDEVFS_DROP_PRIVILEGES 50662306a36Sopenharmony_ci This is used to relinquish the ability to do certain operations 50762306a36Sopenharmony_ci which are considered to be privileged on a usbfs file descriptor. 50862306a36Sopenharmony_ci This includes claiming arbitrary interfaces, resetting a device on 50962306a36Sopenharmony_ci which there are currently claimed interfaces from other users, and 51062306a36Sopenharmony_ci issuing USBDEVFS_IOCTL calls. The ioctl parameter is a 32 bit mask 51162306a36Sopenharmony_ci of interfaces the user is allowed to claim on this file descriptor. 51262306a36Sopenharmony_ci You may issue this ioctl more than one time to narrow said mask. 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_ciSynchronous I/O Support 51562306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~ 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_ciSynchronous requests involve the kernel blocking until the user mode 51862306a36Sopenharmony_cirequest completes, either by finishing successfully or by reporting an 51962306a36Sopenharmony_cierror. In most cases this is the simplest way to use usbfs, although as 52062306a36Sopenharmony_cinoted above it does prevent performing I/O to more than one endpoint at 52162306a36Sopenharmony_cia time. 52262306a36Sopenharmony_ci 52362306a36Sopenharmony_ciUSBDEVFS_BULK 52462306a36Sopenharmony_ci Issues a bulk read or write request to the device. The ioctl 52562306a36Sopenharmony_ci parameter is a pointer to this structure:: 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ci struct usbdevfs_bulktransfer { 52862306a36Sopenharmony_ci unsigned int ep; 52962306a36Sopenharmony_ci unsigned int len; 53062306a36Sopenharmony_ci unsigned int timeout; /* in milliseconds */ 53162306a36Sopenharmony_ci void *data; 53262306a36Sopenharmony_ci }; 53362306a36Sopenharmony_ci 53462306a36Sopenharmony_ci The ``ep`` value identifies a bulk endpoint number (1 to 15, as 53562306a36Sopenharmony_ci identified in an endpoint descriptor), masked with USB_DIR_IN when 53662306a36Sopenharmony_ci referring to an endpoint which sends data to the host from the 53762306a36Sopenharmony_ci device. The length of the data buffer is identified by ``len``; Recent 53862306a36Sopenharmony_ci kernels support requests up to about 128KBytes. *FIXME say how read 53962306a36Sopenharmony_ci length is returned, and how short reads are handled.*. 54062306a36Sopenharmony_ci 54162306a36Sopenharmony_ciUSBDEVFS_CLEAR_HALT 54262306a36Sopenharmony_ci Clears endpoint halt (stall) and resets the endpoint toggle. This is 54362306a36Sopenharmony_ci only meaningful for bulk or interrupt endpoints. The ioctl parameter 54462306a36Sopenharmony_ci is an integer endpoint number (1 to 15, as identified in an endpoint 54562306a36Sopenharmony_ci descriptor), masked with USB_DIR_IN when referring to an endpoint 54662306a36Sopenharmony_ci which sends data to the host from the device. 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_ci Use this on bulk or interrupt endpoints which have stalled, 54962306a36Sopenharmony_ci returning ``-EPIPE`` status to a data transfer request. Do not issue 55062306a36Sopenharmony_ci the control request directly, since that could invalidate the host's 55162306a36Sopenharmony_ci record of the data toggle. 55262306a36Sopenharmony_ci 55362306a36Sopenharmony_ciUSBDEVFS_CONTROL 55462306a36Sopenharmony_ci Issues a control request to the device. The ioctl parameter points 55562306a36Sopenharmony_ci to a structure like this:: 55662306a36Sopenharmony_ci 55762306a36Sopenharmony_ci struct usbdevfs_ctrltransfer { 55862306a36Sopenharmony_ci __u8 bRequestType; 55962306a36Sopenharmony_ci __u8 bRequest; 56062306a36Sopenharmony_ci __u16 wValue; 56162306a36Sopenharmony_ci __u16 wIndex; 56262306a36Sopenharmony_ci __u16 wLength; 56362306a36Sopenharmony_ci __u32 timeout; /* in milliseconds */ 56462306a36Sopenharmony_ci void *data; 56562306a36Sopenharmony_ci }; 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ci The first eight bytes of this structure are the contents of the 56862306a36Sopenharmony_ci SETUP packet to be sent to the device; see the USB 2.0 specification 56962306a36Sopenharmony_ci for details. The bRequestType value is composed by combining a 57062306a36Sopenharmony_ci ``USB_TYPE_*`` value, a ``USB_DIR_*`` value, and a ``USB_RECIP_*`` 57162306a36Sopenharmony_ci value (from ``linux/usb.h``). If wLength is nonzero, it describes 57262306a36Sopenharmony_ci the length of the data buffer, which is either written to the device 57362306a36Sopenharmony_ci (USB_DIR_OUT) or read from the device (USB_DIR_IN). 57462306a36Sopenharmony_ci 57562306a36Sopenharmony_ci At this writing, you can't transfer more than 4 KBytes of data to or 57662306a36Sopenharmony_ci from a device; usbfs has a limit, and some host controller drivers 57762306a36Sopenharmony_ci have a limit. (That's not usually a problem.) *Also* there's no way 57862306a36Sopenharmony_ci to say it's not OK to get a short read back from the device. 57962306a36Sopenharmony_ci 58062306a36Sopenharmony_ciUSBDEVFS_RESET 58162306a36Sopenharmony_ci Does a USB level device reset. The ioctl parameter is ignored. After 58262306a36Sopenharmony_ci the reset, this rebinds all device interfaces. File modification 58362306a36Sopenharmony_ci time is not updated by this request. 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ci.. warning:: 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ci *Avoid using this call* until some usbcore bugs get fixed, since 58862306a36Sopenharmony_ci it does not fully synchronize device, interface, and driver (not 58962306a36Sopenharmony_ci just usbfs) state. 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ciUSBDEVFS_SETINTERFACE 59262306a36Sopenharmony_ci Sets the alternate setting for an interface. The ioctl parameter is 59362306a36Sopenharmony_ci a pointer to a structure like this:: 59462306a36Sopenharmony_ci 59562306a36Sopenharmony_ci struct usbdevfs_setinterface { 59662306a36Sopenharmony_ci unsigned int interface; 59762306a36Sopenharmony_ci unsigned int altsetting; 59862306a36Sopenharmony_ci }; 59962306a36Sopenharmony_ci 60062306a36Sopenharmony_ci File modification time is not updated by this request. 60162306a36Sopenharmony_ci 60262306a36Sopenharmony_ci Those struct members are from some interface descriptor applying to 60362306a36Sopenharmony_ci the current configuration. The interface number is the 60462306a36Sopenharmony_ci bInterfaceNumber value, and the altsetting number is the 60562306a36Sopenharmony_ci bAlternateSetting value. (This resets each endpoint in the 60662306a36Sopenharmony_ci interface.) 60762306a36Sopenharmony_ci 60862306a36Sopenharmony_ciUSBDEVFS_SETCONFIGURATION 60962306a36Sopenharmony_ci Issues the :c:func:`usb_set_configuration()` call for the 61062306a36Sopenharmony_ci device. The parameter is an integer holding the number of a 61162306a36Sopenharmony_ci configuration (bConfigurationValue from descriptor). File 61262306a36Sopenharmony_ci modification time is not updated by this request. 61362306a36Sopenharmony_ci 61462306a36Sopenharmony_ci.. warning:: 61562306a36Sopenharmony_ci 61662306a36Sopenharmony_ci *Avoid using this call* until some usbcore bugs get fixed, since 61762306a36Sopenharmony_ci it does not fully synchronize device, interface, and driver (not 61862306a36Sopenharmony_ci just usbfs) state. 61962306a36Sopenharmony_ci 62062306a36Sopenharmony_ciAsynchronous I/O Support 62162306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~ 62262306a36Sopenharmony_ci 62362306a36Sopenharmony_ciAs mentioned above, there are situations where it may be important to 62462306a36Sopenharmony_ciinitiate concurrent operations from user mode code. This is particularly 62562306a36Sopenharmony_ciimportant for periodic transfers (interrupt and isochronous), but it can 62662306a36Sopenharmony_cibe used for other kinds of USB requests too. In such cases, the 62762306a36Sopenharmony_ciasynchronous requests described here are essential. Rather than 62862306a36Sopenharmony_cisubmitting one request and having the kernel block until it completes, 62962306a36Sopenharmony_cithe blocking is separate. 63062306a36Sopenharmony_ci 63162306a36Sopenharmony_ciThese requests are packaged into a structure that resembles the URB used 63262306a36Sopenharmony_ciby kernel device drivers. (No POSIX Async I/O support here, sorry.) It 63362306a36Sopenharmony_ciidentifies the endpoint type (``USBDEVFS_URB_TYPE_*``), endpoint 63462306a36Sopenharmony_ci(number, masked with USB_DIR_IN as appropriate), buffer and length, 63562306a36Sopenharmony_ciand a user "context" value serving to uniquely identify each request. 63662306a36Sopenharmony_ci(It's usually a pointer to per-request data.) Flags can modify requests 63762306a36Sopenharmony_ci(not as many as supported for kernel drivers). 63862306a36Sopenharmony_ci 63962306a36Sopenharmony_ciEach request can specify a realtime signal number (between SIGRTMIN and 64062306a36Sopenharmony_ciSIGRTMAX, inclusive) to request a signal be sent when the request 64162306a36Sopenharmony_cicompletes. 64262306a36Sopenharmony_ci 64362306a36Sopenharmony_ciWhen usbfs returns these urbs, the status value is updated, and the 64462306a36Sopenharmony_cibuffer may have been modified. Except for isochronous transfers, the 64562306a36Sopenharmony_ciactual_length is updated to say how many bytes were transferred; if the 64662306a36Sopenharmony_ciUSBDEVFS_URB_DISABLE_SPD flag is set ("short packets are not OK"), if 64762306a36Sopenharmony_cifewer bytes were read than were requested then you get an error report:: 64862306a36Sopenharmony_ci 64962306a36Sopenharmony_ci struct usbdevfs_iso_packet_desc { 65062306a36Sopenharmony_ci unsigned int length; 65162306a36Sopenharmony_ci unsigned int actual_length; 65262306a36Sopenharmony_ci unsigned int status; 65362306a36Sopenharmony_ci }; 65462306a36Sopenharmony_ci 65562306a36Sopenharmony_ci struct usbdevfs_urb { 65662306a36Sopenharmony_ci unsigned char type; 65762306a36Sopenharmony_ci unsigned char endpoint; 65862306a36Sopenharmony_ci int status; 65962306a36Sopenharmony_ci unsigned int flags; 66062306a36Sopenharmony_ci void *buffer; 66162306a36Sopenharmony_ci int buffer_length; 66262306a36Sopenharmony_ci int actual_length; 66362306a36Sopenharmony_ci int start_frame; 66462306a36Sopenharmony_ci int number_of_packets; 66562306a36Sopenharmony_ci int error_count; 66662306a36Sopenharmony_ci unsigned int signr; 66762306a36Sopenharmony_ci void *usercontext; 66862306a36Sopenharmony_ci struct usbdevfs_iso_packet_desc iso_frame_desc[]; 66962306a36Sopenharmony_ci }; 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_ciFor these asynchronous requests, the file modification time reflects 67262306a36Sopenharmony_ciwhen the request was initiated. This contrasts with their use with the 67362306a36Sopenharmony_cisynchronous requests, where it reflects when requests complete. 67462306a36Sopenharmony_ci 67562306a36Sopenharmony_ciUSBDEVFS_DISCARDURB 67662306a36Sopenharmony_ci *TBS* File modification time is not updated by this request. 67762306a36Sopenharmony_ci 67862306a36Sopenharmony_ciUSBDEVFS_DISCSIGNAL 67962306a36Sopenharmony_ci *TBS* File modification time is not updated by this request. 68062306a36Sopenharmony_ci 68162306a36Sopenharmony_ciUSBDEVFS_REAPURB 68262306a36Sopenharmony_ci *TBS* File modification time is not updated by this request. 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_ciUSBDEVFS_REAPURBNDELAY 68562306a36Sopenharmony_ci *TBS* File modification time is not updated by this request. 68662306a36Sopenharmony_ci 68762306a36Sopenharmony_ciUSBDEVFS_SUBMITURB 68862306a36Sopenharmony_ci *TBS* 68962306a36Sopenharmony_ci 69062306a36Sopenharmony_ciThe USB devices 69162306a36Sopenharmony_ci=============== 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_ciThe USB devices are now exported via debugfs: 69462306a36Sopenharmony_ci 69562306a36Sopenharmony_ci- ``/sys/kernel/debug/usb/devices`` ... a text file showing each of the USB 69662306a36Sopenharmony_ci devices on known to the kernel, and their configuration descriptors. 69762306a36Sopenharmony_ci You can also poll() this to learn about new devices. 69862306a36Sopenharmony_ci 69962306a36Sopenharmony_ci/sys/kernel/debug/usb/devices 70062306a36Sopenharmony_ci----------------------------- 70162306a36Sopenharmony_ci 70262306a36Sopenharmony_ciThis file is handy for status viewing tools in user mode, which can scan 70362306a36Sopenharmony_cithe text format and ignore most of it. More detailed device status 70462306a36Sopenharmony_ci(including class and vendor status) is available from device-specific 70562306a36Sopenharmony_cifiles. For information about the current format of this file, see below. 70662306a36Sopenharmony_ci 70762306a36Sopenharmony_ciThis file, in combination with the poll() system call, can also be used 70862306a36Sopenharmony_cito detect when devices are added or removed:: 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_ci int fd; 71162306a36Sopenharmony_ci struct pollfd pfd; 71262306a36Sopenharmony_ci 71362306a36Sopenharmony_ci fd = open("/sys/kernel/debug/usb/devices", O_RDONLY); 71462306a36Sopenharmony_ci pfd = { fd, POLLIN, 0 }; 71562306a36Sopenharmony_ci for (;;) { 71662306a36Sopenharmony_ci /* The first time through, this call will return immediately. */ 71762306a36Sopenharmony_ci poll(&pfd, 1, -1); 71862306a36Sopenharmony_ci 71962306a36Sopenharmony_ci /* To see what's changed, compare the file's previous and current 72062306a36Sopenharmony_ci contents or scan the filesystem. (Scanning is more precise.) */ 72162306a36Sopenharmony_ci } 72262306a36Sopenharmony_ci 72362306a36Sopenharmony_ciNote that this behavior is intended to be used for informational and 72462306a36Sopenharmony_cidebug purposes. It would be more appropriate to use programs such as 72562306a36Sopenharmony_ciudev or HAL to initialize a device or start a user-mode helper program, 72662306a36Sopenharmony_cifor instance. 72762306a36Sopenharmony_ci 72862306a36Sopenharmony_ciIn this file, each device's output has multiple lines of ASCII output. 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_ciI made it ASCII instead of binary on purpose, so that someone 73162306a36Sopenharmony_cican obtain some useful data from it without the use of an 73262306a36Sopenharmony_ciauxiliary program. However, with an auxiliary program, the numbers 73362306a36Sopenharmony_ciin the first 4 columns of each ``T:`` line (topology info: 73462306a36Sopenharmony_ciLev, Prnt, Port, Cnt) can be used to build a USB topology diagram. 73562306a36Sopenharmony_ci 73662306a36Sopenharmony_ciEach line is tagged with a one-character ID for that line:: 73762306a36Sopenharmony_ci 73862306a36Sopenharmony_ci T = Topology (etc.) 73962306a36Sopenharmony_ci B = Bandwidth (applies only to USB host controllers, which are 74062306a36Sopenharmony_ci virtualized as root hubs) 74162306a36Sopenharmony_ci D = Device descriptor info. 74262306a36Sopenharmony_ci P = Product ID info. (from Device descriptor, but they won't fit 74362306a36Sopenharmony_ci together on one line) 74462306a36Sopenharmony_ci S = String descriptors. 74562306a36Sopenharmony_ci C = Configuration descriptor info. (* = active configuration) 74662306a36Sopenharmony_ci I = Interface descriptor info. 74762306a36Sopenharmony_ci E = Endpoint descriptor info. 74862306a36Sopenharmony_ci 74962306a36Sopenharmony_ci/sys/kernel/debug/usb/devices output format 75062306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 75162306a36Sopenharmony_ci 75262306a36Sopenharmony_ciLegend:: 75362306a36Sopenharmony_ci d = decimal number (may have leading spaces or 0's) 75462306a36Sopenharmony_ci x = hexadecimal number (may have leading spaces or 0's) 75562306a36Sopenharmony_ci s = string 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_ci 75862306a36Sopenharmony_ci 75962306a36Sopenharmony_ciTopology info 76062306a36Sopenharmony_ci^^^^^^^^^^^^^ 76162306a36Sopenharmony_ci 76262306a36Sopenharmony_ci:: 76362306a36Sopenharmony_ci 76462306a36Sopenharmony_ci T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd 76562306a36Sopenharmony_ci | | | | | | | | |__MaxChildren 76662306a36Sopenharmony_ci | | | | | | | |__Device Speed in Mbps 76762306a36Sopenharmony_ci | | | | | | |__DeviceNumber 76862306a36Sopenharmony_ci | | | | | |__Count of devices at this level 76962306a36Sopenharmony_ci | | | | |__Connector/Port on Parent for this device 77062306a36Sopenharmony_ci | | | |__Parent DeviceNumber 77162306a36Sopenharmony_ci | | |__Level in topology for this bus 77262306a36Sopenharmony_ci | |__Bus number 77362306a36Sopenharmony_ci |__Topology info tag 77462306a36Sopenharmony_ci 77562306a36Sopenharmony_ciSpeed may be: 77662306a36Sopenharmony_ci 77762306a36Sopenharmony_ci ======= ====================================================== 77862306a36Sopenharmony_ci 1.5 Mbit/s for low speed USB 77962306a36Sopenharmony_ci 12 Mbit/s for full speed USB 78062306a36Sopenharmony_ci 480 Mbit/s for high speed USB (added for USB 2.0) 78162306a36Sopenharmony_ci 5000 Mbit/s for SuperSpeed USB (added for USB 3.0) 78262306a36Sopenharmony_ci ======= ====================================================== 78362306a36Sopenharmony_ci 78462306a36Sopenharmony_ciFor reasons lost in the mists of time, the Port number is always 78562306a36Sopenharmony_citoo low by 1. For example, a device plugged into port 4 will 78662306a36Sopenharmony_cishow up with ``Port=03``. 78762306a36Sopenharmony_ci 78862306a36Sopenharmony_ciBandwidth info 78962306a36Sopenharmony_ci^^^^^^^^^^^^^^ 79062306a36Sopenharmony_ci 79162306a36Sopenharmony_ci:: 79262306a36Sopenharmony_ci 79362306a36Sopenharmony_ci B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd 79462306a36Sopenharmony_ci | | | |__Number of isochronous requests 79562306a36Sopenharmony_ci | | |__Number of interrupt requests 79662306a36Sopenharmony_ci | |__Total Bandwidth allocated to this bus 79762306a36Sopenharmony_ci |__Bandwidth info tag 79862306a36Sopenharmony_ci 79962306a36Sopenharmony_ciBandwidth allocation is an approximation of how much of one frame 80062306a36Sopenharmony_ci(millisecond) is in use. It reflects only periodic transfers, which 80162306a36Sopenharmony_ciare the only transfers that reserve bandwidth. Control and bulk 80262306a36Sopenharmony_citransfers use all other bandwidth, including reserved bandwidth that 80362306a36Sopenharmony_ciis not used for transfers (such as for short packets). 80462306a36Sopenharmony_ci 80562306a36Sopenharmony_ciThe percentage is how much of the "reserved" bandwidth is scheduled by 80662306a36Sopenharmony_cithose transfers. For a low or full speed bus (loosely, "USB 1.1"), 80762306a36Sopenharmony_ci90% of the bus bandwidth is reserved. For a high speed bus (loosely, 80862306a36Sopenharmony_ci"USB 2.0") 80% is reserved. 80962306a36Sopenharmony_ci 81062306a36Sopenharmony_ci 81162306a36Sopenharmony_ciDevice descriptor info & Product ID info 81262306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 81362306a36Sopenharmony_ci 81462306a36Sopenharmony_ci:: 81562306a36Sopenharmony_ci 81662306a36Sopenharmony_ci D: Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 81762306a36Sopenharmony_ci P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 81862306a36Sopenharmony_ci 81962306a36Sopenharmony_ciwhere:: 82062306a36Sopenharmony_ci 82162306a36Sopenharmony_ci D: Ver=x.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 82262306a36Sopenharmony_ci | | | | | | |__NumberConfigurations 82362306a36Sopenharmony_ci | | | | | |__MaxPacketSize of Default Endpoint 82462306a36Sopenharmony_ci | | | | |__DeviceProtocol 82562306a36Sopenharmony_ci | | | |__DeviceSubClass 82662306a36Sopenharmony_ci | | |__DeviceClass 82762306a36Sopenharmony_ci | |__Device USB version 82862306a36Sopenharmony_ci |__Device info tag #1 82962306a36Sopenharmony_ci 83062306a36Sopenharmony_ciwhere:: 83162306a36Sopenharmony_ci 83262306a36Sopenharmony_ci P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 83362306a36Sopenharmony_ci | | | |__Product revision number 83462306a36Sopenharmony_ci | | |__Product ID code 83562306a36Sopenharmony_ci | |__Vendor ID code 83662306a36Sopenharmony_ci |__Device info tag #2 83762306a36Sopenharmony_ci 83862306a36Sopenharmony_ci 83962306a36Sopenharmony_ciString descriptor info 84062306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^ 84162306a36Sopenharmony_ci:: 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_ci S: Manufacturer=ssss 84462306a36Sopenharmony_ci | |__Manufacturer of this device as read from the device. 84562306a36Sopenharmony_ci | For USB host controller drivers (virtual root hubs) this may 84662306a36Sopenharmony_ci | be omitted, or (for newer drivers) will identify the kernel 84762306a36Sopenharmony_ci | version and the driver which provides this hub emulation. 84862306a36Sopenharmony_ci |__String info tag 84962306a36Sopenharmony_ci 85062306a36Sopenharmony_ci S: Product=ssss 85162306a36Sopenharmony_ci | |__Product description of this device as read from the device. 85262306a36Sopenharmony_ci | For older USB host controller drivers (virtual root hubs) this 85362306a36Sopenharmony_ci | indicates the driver; for newer ones, it's a product (and vendor) 85462306a36Sopenharmony_ci | description that often comes from the kernel's PCI ID database. 85562306a36Sopenharmony_ci |__String info tag 85662306a36Sopenharmony_ci 85762306a36Sopenharmony_ci S: SerialNumber=ssss 85862306a36Sopenharmony_ci | |__Serial Number of this device as read from the device. 85962306a36Sopenharmony_ci | For USB host controller drivers (virtual root hubs) this is 86062306a36Sopenharmony_ci | some unique ID, normally a bus ID (address or slot name) that 86162306a36Sopenharmony_ci | can't be shared with any other device. 86262306a36Sopenharmony_ci |__String info tag 86362306a36Sopenharmony_ci 86462306a36Sopenharmony_ci 86562306a36Sopenharmony_ci 86662306a36Sopenharmony_ciConfiguration descriptor info 86762306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 86862306a36Sopenharmony_ci:: 86962306a36Sopenharmony_ci 87062306a36Sopenharmony_ci C:* #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA 87162306a36Sopenharmony_ci | | | | | |__MaxPower in mA 87262306a36Sopenharmony_ci | | | | |__Attributes 87362306a36Sopenharmony_ci | | | |__ConfiguratioNumber 87462306a36Sopenharmony_ci | | |__NumberOfInterfaces 87562306a36Sopenharmony_ci | |__ "*" indicates the active configuration (others are " ") 87662306a36Sopenharmony_ci |__Config info tag 87762306a36Sopenharmony_ci 87862306a36Sopenharmony_ciUSB devices may have multiple configurations, each of which act 87962306a36Sopenharmony_cirather differently. For example, a bus-powered configuration 88062306a36Sopenharmony_cimight be much less capable than one that is self-powered. Only 88162306a36Sopenharmony_cione device configuration can be active at a time; most devices 88262306a36Sopenharmony_cihave only one configuration. 88362306a36Sopenharmony_ci 88462306a36Sopenharmony_ciEach configuration consists of one or more interfaces. Each 88562306a36Sopenharmony_ciinterface serves a distinct "function", which is typically bound 88662306a36Sopenharmony_cito a different USB device driver. One common example is a USB 88762306a36Sopenharmony_cispeaker with an audio interface for playback, and a HID interface 88862306a36Sopenharmony_cifor use with software volume control. 88962306a36Sopenharmony_ci 89062306a36Sopenharmony_ciInterface descriptor info (can be multiple per Config) 89162306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 89262306a36Sopenharmony_ci:: 89362306a36Sopenharmony_ci 89462306a36Sopenharmony_ci I:* If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=ssss 89562306a36Sopenharmony_ci | | | | | | | | |__Driver name 89662306a36Sopenharmony_ci | | | | | | | | or "(none)" 89762306a36Sopenharmony_ci | | | | | | | |__InterfaceProtocol 89862306a36Sopenharmony_ci | | | | | | |__InterfaceSubClass 89962306a36Sopenharmony_ci | | | | | |__InterfaceClass 90062306a36Sopenharmony_ci | | | | |__NumberOfEndpoints 90162306a36Sopenharmony_ci | | | |__AlternateSettingNumber 90262306a36Sopenharmony_ci | | |__InterfaceNumber 90362306a36Sopenharmony_ci | |__ "*" indicates the active altsetting (others are " ") 90462306a36Sopenharmony_ci |__Interface info tag 90562306a36Sopenharmony_ci 90662306a36Sopenharmony_ciA given interface may have one or more "alternate" settings. 90762306a36Sopenharmony_ciFor example, default settings may not use more than a small 90862306a36Sopenharmony_ciamount of periodic bandwidth. To use significant fractions 90962306a36Sopenharmony_ciof bus bandwidth, drivers must select a non-default altsetting. 91062306a36Sopenharmony_ci 91162306a36Sopenharmony_ciOnly one setting for an interface may be active at a time, and 91262306a36Sopenharmony_cionly one driver may bind to an interface at a time. Most devices 91362306a36Sopenharmony_cihave only one alternate setting per interface. 91462306a36Sopenharmony_ci 91562306a36Sopenharmony_ci 91662306a36Sopenharmony_ciEndpoint descriptor info (can be multiple per Interface) 91762306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 91862306a36Sopenharmony_ci 91962306a36Sopenharmony_ci:: 92062306a36Sopenharmony_ci 92162306a36Sopenharmony_ci E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=dddss 92262306a36Sopenharmony_ci | | | | |__Interval (max) between transfers 92362306a36Sopenharmony_ci | | | |__EndpointMaxPacketSize 92462306a36Sopenharmony_ci | | |__Attributes(EndpointType) 92562306a36Sopenharmony_ci | |__EndpointAddress(I=In,O=Out) 92662306a36Sopenharmony_ci |__Endpoint info tag 92762306a36Sopenharmony_ci 92862306a36Sopenharmony_ciThe interval is nonzero for all periodic (interrupt or isochronous) 92962306a36Sopenharmony_ciendpoints. For high speed endpoints the transfer interval may be 93062306a36Sopenharmony_cimeasured in microseconds rather than milliseconds. 93162306a36Sopenharmony_ci 93262306a36Sopenharmony_ciFor high speed periodic endpoints, the ``EndpointMaxPacketSize`` reflects 93362306a36Sopenharmony_cithe per-microframe data transfer size. For "high bandwidth" 93462306a36Sopenharmony_ciendpoints, that can reflect two or three packets (for up to 93562306a36Sopenharmony_ci3KBytes every 125 usec) per endpoint. 93662306a36Sopenharmony_ci 93762306a36Sopenharmony_ciWith the Linux-USB stack, periodic bandwidth reservations use the 93862306a36Sopenharmony_citransfer intervals and sizes provided by URBs, which can be less 93962306a36Sopenharmony_cithan those found in endpoint descriptor. 94062306a36Sopenharmony_ci 94162306a36Sopenharmony_ciUsage examples 94262306a36Sopenharmony_ci~~~~~~~~~~~~~~ 94362306a36Sopenharmony_ci 94462306a36Sopenharmony_ciIf a user or script is interested only in Topology info, for 94562306a36Sopenharmony_ciexample, use something like ``grep ^T: /sys/kernel/debug/usb/devices`` 94662306a36Sopenharmony_cifor only the Topology lines. A command like 94762306a36Sopenharmony_ci``grep -i ^[tdp]: /sys/kernel/debug/usb/devices`` can be used to list 94862306a36Sopenharmony_cionly the lines that begin with the characters in square brackets, 94962306a36Sopenharmony_ciwhere the valid characters are TDPCIE. With a slightly more able 95062306a36Sopenharmony_ciscript, it can display any selected lines (for example, only T, D, 95162306a36Sopenharmony_ciand P lines) and change their output format. (The ``procusb`` 95262306a36Sopenharmony_ciPerl script is the beginning of this idea. It will list only 95362306a36Sopenharmony_ciselected lines [selected from TBDPSCIE] or "All" lines from 95462306a36Sopenharmony_ci``/sys/kernel/debug/usb/devices``.) 95562306a36Sopenharmony_ci 95662306a36Sopenharmony_ciThe Topology lines can be used to generate a graphic/pictorial 95762306a36Sopenharmony_ciof the USB devices on a system's root hub. (See more below 95862306a36Sopenharmony_cion how to do this.) 95962306a36Sopenharmony_ci 96062306a36Sopenharmony_ciThe Interface lines can be used to determine what driver is 96162306a36Sopenharmony_cibeing used for each device, and which altsetting it activated. 96262306a36Sopenharmony_ci 96362306a36Sopenharmony_ciThe Configuration lines could be used to list maximum power 96462306a36Sopenharmony_ci(in milliamps) that a system's USB devices are using. 96562306a36Sopenharmony_ciFor example, ``grep ^C: /sys/kernel/debug/usb/devices``. 96662306a36Sopenharmony_ci 96762306a36Sopenharmony_ci 96862306a36Sopenharmony_ciHere's an example, from a system which has a UHCI root hub, 96962306a36Sopenharmony_cian external hub connected to the root hub, and a mouse and 97062306a36Sopenharmony_cia serial converter connected to the external hub. 97162306a36Sopenharmony_ci 97262306a36Sopenharmony_ci:: 97362306a36Sopenharmony_ci 97462306a36Sopenharmony_ci T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 97562306a36Sopenharmony_ci B: Alloc= 28/900 us ( 3%), #Int= 2, #Iso= 0 97662306a36Sopenharmony_ci D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 97762306a36Sopenharmony_ci P: Vendor=0000 ProdID=0000 Rev= 0.00 97862306a36Sopenharmony_ci S: Product=USB UHCI Root Hub 97962306a36Sopenharmony_ci S: SerialNumber=dce0 98062306a36Sopenharmony_ci C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA 98162306a36Sopenharmony_ci I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 98262306a36Sopenharmony_ci E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms 98362306a36Sopenharmony_ci 98462306a36Sopenharmony_ci T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 98562306a36Sopenharmony_ci D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 98662306a36Sopenharmony_ci P: Vendor=0451 ProdID=1446 Rev= 1.00 98762306a36Sopenharmony_ci C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA 98862306a36Sopenharmony_ci I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 98962306a36Sopenharmony_ci E: Ad=81(I) Atr=03(Int.) MxPS= 1 Ivl=255ms 99062306a36Sopenharmony_ci 99162306a36Sopenharmony_ci T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 99262306a36Sopenharmony_ci D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 99362306a36Sopenharmony_ci P: Vendor=04b4 ProdID=0001 Rev= 0.00 99462306a36Sopenharmony_ci C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA 99562306a36Sopenharmony_ci I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 99662306a36Sopenharmony_ci E: Ad=81(I) Atr=03(Int.) MxPS= 3 Ivl= 10ms 99762306a36Sopenharmony_ci 99862306a36Sopenharmony_ci T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 99962306a36Sopenharmony_ci D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 100062306a36Sopenharmony_ci P: Vendor=0565 ProdID=0001 Rev= 1.08 100162306a36Sopenharmony_ci S: Manufacturer=Peracom Networks, Inc. 100262306a36Sopenharmony_ci S: Product=Peracom USB to Serial Converter 100362306a36Sopenharmony_ci C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA 100462306a36Sopenharmony_ci I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 100562306a36Sopenharmony_ci E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl= 16ms 100662306a36Sopenharmony_ci E: Ad=01(O) Atr=02(Bulk) MxPS= 16 Ivl= 16ms 100762306a36Sopenharmony_ci E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl= 8ms 100862306a36Sopenharmony_ci 100962306a36Sopenharmony_ci 101062306a36Sopenharmony_ciSelecting only the ``T:`` and ``I:`` lines from this (for example, by using 101162306a36Sopenharmony_ci``procusb ti``), we have 101262306a36Sopenharmony_ci 101362306a36Sopenharmony_ci:: 101462306a36Sopenharmony_ci 101562306a36Sopenharmony_ci T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 101662306a36Sopenharmony_ci T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 101762306a36Sopenharmony_ci I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 101862306a36Sopenharmony_ci T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 101962306a36Sopenharmony_ci I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 102062306a36Sopenharmony_ci T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 102162306a36Sopenharmony_ci I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 102262306a36Sopenharmony_ci 102362306a36Sopenharmony_ci 102462306a36Sopenharmony_ciPhysically this looks like (or could be converted to):: 102562306a36Sopenharmony_ci 102662306a36Sopenharmony_ci +------------------+ 102762306a36Sopenharmony_ci | PC/root_hub (12)| Dev# = 1 102862306a36Sopenharmony_ci +------------------+ (nn) is Mbps. 102962306a36Sopenharmony_ci Level 0 | CN.0 | CN.1 | [CN = connector/port #] 103062306a36Sopenharmony_ci +------------------+ 103162306a36Sopenharmony_ci / 103262306a36Sopenharmony_ci / 103362306a36Sopenharmony_ci +-----------------------+ 103462306a36Sopenharmony_ci Level 1 | Dev#2: 4-port hub (12)| 103562306a36Sopenharmony_ci +-----------------------+ 103662306a36Sopenharmony_ci |CN.0 |CN.1 |CN.2 |CN.3 | 103762306a36Sopenharmony_ci +-----------------------+ 103862306a36Sopenharmony_ci \ \____________________ 103962306a36Sopenharmony_ci \_____ \ 104062306a36Sopenharmony_ci \ \ 104162306a36Sopenharmony_ci +--------------------+ +--------------------+ 104262306a36Sopenharmony_ci Level 2 | Dev# 3: mouse (1.5)| | Dev# 4: serial (12)| 104362306a36Sopenharmony_ci +--------------------+ +--------------------+ 104462306a36Sopenharmony_ci 104562306a36Sopenharmony_ci 104662306a36Sopenharmony_ci 104762306a36Sopenharmony_ciOr, in a more tree-like structure (ports [Connectors] without 104862306a36Sopenharmony_ciconnections could be omitted):: 104962306a36Sopenharmony_ci 105062306a36Sopenharmony_ci PC: Dev# 1, root hub, 2 ports, 12 Mbps 105162306a36Sopenharmony_ci |_ CN.0: Dev# 2, hub, 4 ports, 12 Mbps 105262306a36Sopenharmony_ci |_ CN.0: Dev #3, mouse, 1.5 Mbps 105362306a36Sopenharmony_ci |_ CN.1: 105462306a36Sopenharmony_ci |_ CN.2: Dev #4, serial, 12 Mbps 105562306a36Sopenharmony_ci |_ CN.3: 105662306a36Sopenharmony_ci |_ CN.1: 1057