USB Packet Logging in PCAP format

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Post Reply
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

USB Packet Logging in PCAP format

Post by BenLunt »

Recently QEMU added USB Packet Logging in the PCAP format for viewing with WireShark. Add the following PCAP parameter to your device:

Code: Select all

pcap=uhci.pcap
Here is an example for an attached MSD device:

Code: Select all

-device ich9-usb-uhci3 -drive id=my_usb_disk,file=usbfile.img,if=none ^
-device usb-storage,drive=my_usb_disk,pcap=uhci.pcap
QEMU will now send all incoming and outgoing USB packets to a file named 'uhci.pcap'. Then you can open this file with WireShark and see the USB traffic. This is similar to if you were running your code on real hardware and had a hardware packet capture device.

With this new announcement by QEMU, I realized that I have most of this function already in Bochs, all I needed to do was send it to a file. Therefore, if you prefer to use Bochs, update to the latest SVN and use the following bochrc.txt option:

Code: Select all

usb_uhci: enabled=1, port1=disk, options1="path:D:\path\to\usb\image\file\usbimg.img,pcap:D:\path\to\capture\file\capture.pcap"
Whether you use QEMU or Bochs (or both), this is a nice new feature to see all of the USB traffic for your installed devices and hopefully helps with your USB driver development.

Cheers,
Ben
- http://www.fysnet.net/the_universal_serial_bus.htm
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: USB Packet Logging in PCAP format

Post by Korona »

Oh, that looks very handy for debugging USB. I wish I had that functionality when I started our USB stack.

Thanks for letting us know!
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
rdos
Member
Member
Posts: 3279
Joined: Wed Oct 01, 2008 1:55 pm

Re: USB Packet Logging in PCAP format

Post by rdos »

So, how exactly can you save this information from inside your own USB drivers? I have a function to save network packets to cap format, but what is saved in the USB version? For instance, information about device address and pipe is not part of the data that is sent over USB, so it must saved in some kind of header.
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: USB Packet Logging in PCAP format

Post by BenLunt »

rdos wrote:So, how exactly can you save this information from inside your own USB drivers? I have a function to save network packets to cap format, but what is saved in the USB version? For instance, information about device address and pipe is not part of the data that is sent over USB, so it must saved in some kind of header.
Hi,

If you have a look at the Bochs PCAP source file, you will see that I made a few notes pointing to other files explaining the format of the packets. Specifically the third URL mentioned gives information about the packet. Within that information is the Device number, the Endpoint number, and transfer type, as well as other information.

Ben
Post Reply