Page 1 of 1

USB Packet Logging in PCAP format

Posted: Sun Apr 18, 2021 1:02 pm
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

Re: USB Packet Logging in PCAP format

Posted: Sun Apr 18, 2021 2:14 pm
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!

Re: USB Packet Logging in PCAP format

Posted: Tue Apr 20, 2021 8:52 am
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.

Re: USB Packet Logging in PCAP format

Posted: Tue Apr 20, 2021 4:24 pm
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