From Fedora Project Wiki

Revision as of 17:36, 4 December 2020 by Tuju (talk | contribs)

usbmon is a mechanism for catching information on the USB bus. This is useful for debugging some kinds of USB problems. The existing usbmon documentation is very good. A rehash of the documentation is below.

Kernel module

USB module can be compiled into kernel statically, or it can be module that can be loaded into kernel. Fedora should have it statically part of the kernel.

# grep USB_MON /boot/config-5.9.*
/boot/config-5.9.11-100.fc32.x86_64:CONFIG_USB_MON=y
/boot/config-5.9.8-100.fc32.x86_64:CONFIG_USB_MON=y
/boot/config-5.9.9-100.fc32.x86_64:CONFIG_USB_MON=y

shows that it was selected to be part of monolitic kernel, rather than module (CONFIG_USB_MON=m). Hence it does not need, or can be loaded into running kernel.

If it was compiled as module, it can be loaded into kernel:

# modprobe usbmon
# lsmod | grep usbmon

should list it as module.

Capturing USB packets

First, identify which bus number of the device you want to trace. You can find this via lsusb. e.g.

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

gives bus number 2. Then do

# modprobe usbmon

This starts the usbmon tracing. To start capturing output do

# cat /sys/kernel/debug/usb/usbmon/2u > /tmp/usbmon_out

replacing 2u with your bus number (i.e. Bus003 -> 3u, Bus008 -> 8u).

This will continue to write to the file until it is terminated. The capture steps now look like

- start capturing the usbmon output to a file - Run your tests with the USB device - stop capturing the usbmon output