Skip to content

valdaarhun/usb-devices-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

usb-devices-rs

This is the rust implementation of the usb-devices utility provided in the usbutils package for Linux. It's used to gather information on USB devices and present it in a format similar to what's exposed in the usbfs or debugfs pseudo filesystems.

Further details can be found in the man page usb-devices(1).

Technical Overview

Details of the USB buses in the system and the devices connected to them are gathered by walking through /sys/bus/usb/devices/usbN. Each usbN directory corresponds to the usbN root hub. The following information is gathered when walking through the USB device hierarchy:

  • Topology

Prefixed by 'T:', this indicates which bus the device is on. The level of a device is calculated while walking through the root hub's directory tree. The parent of a device is the device number of the hub that it's connected to. This is 0 for the root hub. Each parent-port pair is unique.

Port is reported as:

  1. 0 if level=0. This is the root hub.
  2. port-1 for every other device where port is the last port value in the devpath - <busnum>-<port[.port]>.

Count indicates the number of the device based on the enumeration order within that level. It's 1-indexed but is 00 for the root hub device.

MaxChld pertains only to hubs. It indicates the max number of devices that can be connected to this hub.

  • Device descriptor

Lines prefixed by 'D:' and 'P:' are used to report the device descriptor. This describes the USB device as a whole.

The revision is reported as XX.YY where XX is the revmajor given by the first 2 digits of bcdDevice and YY is the revminor given by the last 2 digits of bcdDevice.

  • Vendor strings

Prefixed by 'S:', these are vendor and product strings corresponding to the device. They are optional.

  • Configuration descriptor

Prefixed by 'C:', this reports details related to the various configurations that a USB device can have. Most devices usually have only one configuration descriptor.

#Ifs reports the number of interfaces the device has for the given configuration and matches the number of 'I:' lines.

  • Interface descriptor

Prefixed by 'I:', this reports information from the interface descriptor.

#EPs reports the number of endpoints corresponding to the described interface. The number of 'E:' lines for the given 'I:' line matches this number.

  • Endpoint descriptor

Prefixed by 'E:', this reports information from the endpoint descriptor. Endpoint 0 is not displayed.

MxPS is calculated as:

(wMaxPacketSize & 0x7FF) * (1 + ((wMaxPacketSize >> 11) & 0x3))
--- Bits 0 through 10            --- Bits 11 and 12
--- size                         --- multiplicity value

Directories in the USB portion of the sysfs tree

The USB portion of the sysfs tree is at /sys/bus/usb/devices/usb* where each usb* is a root hub device.

Directories corresponding to devices attached to a particular hub can be matched by: <busnum>-[0-9]+(\.[0-9]+)*$.

Directories corresponding to interfaces for a particular USB device can be matched by: <busnum>-*:?.*.

Directories corresponding to endpoints for a particular USB interface can be matched by: ep_??.

Usage

$ cargo build --release
$ cd ./target/release
$ ./usb-devices-rs

References

About

Rust implementation of "usb-devices".

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages