OSDev.org

The Place to Start for Operating System Developers
It is currently Sun May 16, 2021 12:49 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: USB Packet Logging in PCAP format
PostPosted: Sun Apr 18, 2021 1:02 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 776
Location: USA
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


Top
 Profile  
 
 Post subject: Re: USB Packet Logging in PCAP format
PostPosted: Sun Apr 18, 2021 2:14 pm 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 901
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].


Top
 Profile  
 
 Post subject: Re: USB Packet Logging in PCAP format
PostPosted: Tue Apr 20, 2021 8:52 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 2593
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.


Top
 Profile  
 
 Post subject: Re: USB Packet Logging in PCAP format
PostPosted: Tue Apr 20, 2021 4:24 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 776
Location: USA
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: stlw and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group