OSDev.org
https://forum.osdev.org/

USB Packet Logging in PCAP format
https://forum.osdev.org/viewtopic.php?f=2&t=42879
Page 1 of 1

Author:  BenLunt [ Sun Apr 18, 2021 1:02 pm ]
Post subject:  USB Packet Logging in PCAP format

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

Here is an example for an attached MSD device:
Code:
-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:
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

Author:  Korona [ Sun Apr 18, 2021 2:14 pm ]
Post subject:  Re: USB Packet Logging in PCAP format

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!

Author:  rdos [ Tue Apr 20, 2021 8:52 am ]
Post subject:  Re: USB Packet Logging in PCAP format

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.

Author:  BenLunt [ Tue Apr 20, 2021 4:24 pm ]
Post subject:  Re: USB Packet Logging in PCAP format

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/