Added USB packet logging support in PCAP format (patch #560 by Ben Lunt).
- Added new files with small changes, output can be viewed with Wireshark. - FIXME: Windows ports crash with original Win98 guest and USB disk connected. - TODO: mention new feature in documentation.
This commit is contained in:
parent
719592e2f3
commit
b19a7b1042
@ -57,7 +57,8 @@ BX_INCDIRS = -I.. -I../.. -I$(srcdir)/.. -I$(srcdir)/../.. -I../../@INSTRUMENT_D
|
||||
LOCAL_CXXFLAGS = $(MCH_CFLAGS)
|
||||
|
||||
OBJS_THAT_CANNOT_BE_PLUGINS = \
|
||||
usb_common.o
|
||||
usb_common.o \
|
||||
usb_pcap.o
|
||||
|
||||
OBJS_THAT_CAN_BE_PLUGINS = \
|
||||
@USBHC_OBJS@ \
|
||||
@ -169,78 +170,86 @@ uhci_core.o: uhci_core.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h uhci_core.h
|
||||
../pci.h usb_common.h usb_pcap.h uhci_core.h
|
||||
usb_common.o: usb_common.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h
|
||||
usb_pcap.h usb_common.h
|
||||
usb_ehci.o: usb_ehci.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h uhci_core.h ../../qemu-queue.h usb_ehci.h
|
||||
../pci.h usb_common.h usb_pcap.h uhci_core.h ../../qemu-queue.h \
|
||||
usb_ehci.h
|
||||
usb_floppy.o: usb_floppy.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h ../hdimage/hdimage.h usb_floppy.h
|
||||
usb_common.h usb_pcap.h ../hdimage/hdimage.h usb_floppy.h
|
||||
usb_hid.o: usb_hid.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h usb_hid.h
|
||||
usb_common.h usb_pcap.h usb_hid.h
|
||||
usb_hub.o: usb_hub.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h usb_hub.h
|
||||
usb_common.h usb_pcap.h usb_hub.h
|
||||
usb_msd.o: usb_msd.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h ../hdimage/cdrom.h ../hdimage/hdimage.h scsi_device.h \
|
||||
usb_msd.h
|
||||
usb_common.h usb_pcap.h ../hdimage/cdrom.h ../hdimage/hdimage.h \
|
||||
scsi_device.h usb_msd.h
|
||||
usb_ohci.o: usb_ohci.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h usb_ohci.h
|
||||
../pci.h usb_common.h usb_pcap.h usb_ohci.h
|
||||
usb_pcap.o: usb_pcap.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_pcap.h usb_common.h
|
||||
usb_printer.o: usb_printer.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h usb_printer.h
|
||||
usb_common.h usb_pcap.h usb_printer.h
|
||||
usb_uhci.o: usb_uhci.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h uhci_core.h usb_uhci.h
|
||||
../pci.h usb_common.h usb_pcap.h uhci_core.h usb_uhci.h
|
||||
usb_xhci.o: usb_xhci.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h usb_xhci.h
|
||||
../pci.h usb_common.h usb_pcap.h usb_xhci.h
|
||||
scsi_device.lo: scsi_device.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
@ -254,75 +263,83 @@ uhci_core.lo: uhci_core.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h uhci_core.h
|
||||
../pci.h usb_common.h usb_pcap.h uhci_core.h
|
||||
usb_common.lo: usb_common.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h
|
||||
usb_pcap.h usb_common.h
|
||||
usb_ehci.lo: usb_ehci.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h uhci_core.h ../../qemu-queue.h usb_ehci.h
|
||||
../pci.h usb_common.h usb_pcap.h uhci_core.h ../../qemu-queue.h \
|
||||
usb_ehci.h
|
||||
usb_floppy.lo: usb_floppy.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h ../hdimage/hdimage.h usb_floppy.h
|
||||
usb_common.h usb_pcap.h ../hdimage/hdimage.h usb_floppy.h
|
||||
usb_hid.lo: usb_hid.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h usb_hid.h
|
||||
usb_common.h usb_pcap.h usb_hid.h
|
||||
usb_hub.lo: usb_hub.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h usb_hub.h
|
||||
usb_common.h usb_pcap.h usb_hub.h
|
||||
usb_msd.lo: usb_msd.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h ../hdimage/cdrom.h ../hdimage/hdimage.h scsi_device.h \
|
||||
usb_msd.h
|
||||
usb_common.h usb_pcap.h ../hdimage/cdrom.h ../hdimage/hdimage.h \
|
||||
scsi_device.h usb_msd.h
|
||||
usb_ohci.lo: usb_ohci.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h usb_ohci.h
|
||||
../pci.h usb_common.h usb_pcap.h usb_ohci.h
|
||||
usb_pcap.lo: usb_pcap.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_pcap.h usb_common.h
|
||||
usb_printer.lo: usb_printer.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
usb_common.h usb_printer.h
|
||||
usb_common.h usb_pcap.h usb_printer.h
|
||||
usb_uhci.lo: usb_uhci.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h uhci_core.h usb_uhci.h
|
||||
../pci.h usb_common.h usb_pcap.h uhci_core.h usb_uhci.h
|
||||
usb_xhci.lo: usb_xhci.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
|
||||
../../osdep.h ../../gui/paramtree.h ../../logio.h ../../cpudb.h \
|
||||
../../instrument/stubs/instrument.h ../../misc/bswap.h ../../plugin.h \
|
||||
../../extplugin.h ../../param_names.h ../../pc_system.h \
|
||||
../../bx_debug/debug.h ../../config.h ../../osdep.h \
|
||||
../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
|
||||
../pci.h usb_common.h usb_xhci.h
|
||||
../pci.h usb_common.h usb_pcap.h usb_xhci.h
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#if BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB
|
||||
|
||||
//#include "usb_pcap.h"
|
||||
#include "usb_pcap.h"
|
||||
#include "usb_common.h"
|
||||
|
||||
#define LOG_THIS bx_usbdev_ctl.
|
||||
@ -574,7 +574,7 @@ void usb_device_c::set_debug_mode()
|
||||
|
||||
void usb_device_c::set_pcap_mode(const char *pcap_name)
|
||||
{
|
||||
d.pcap_mode = 0; //(d.pcapture.create_pcap(pcap_name) >= 0);
|
||||
d.pcap_mode = (d.pcapture.create_pcap(pcap_name) >= 0);
|
||||
}
|
||||
|
||||
// Send an internal message to a USB device
|
||||
@ -606,7 +606,7 @@ void usb_device_c::usb_dump_packet(Bit8u *data, unsigned size, int bus, int dev_
|
||||
}
|
||||
|
||||
if (d.pcap_mode) {
|
||||
// d.pcapture.write_packet(data, size, bus, dev_addr, ep, type, is_setup, can_append);
|
||||
d.pcapture.write_packet(data, size, bus, dev_addr, ep, type, is_setup, can_append);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ typedef void USBCallback(int event, USBPacket *packet, void *dev, int port);
|
||||
|
||||
class usb_device_c;
|
||||
|
||||
//#include "usb_pcap.h"
|
||||
#include "usb_pcap.h"
|
||||
|
||||
struct USBPacket {
|
||||
int pid;
|
||||
@ -251,7 +251,7 @@ protected:
|
||||
bx_list_c *sr;
|
||||
|
||||
bool pcap_mode;
|
||||
// pcap_image_t pcapture;
|
||||
pcap_image_t pcapture;
|
||||
} d;
|
||||
|
||||
int handle_control_common(int request, int value, int index, int length, Bit8u *data);
|
||||
|
198
bochs/iodev/usb/usb_pcap.cc
Normal file
198
bochs/iodev/usb/usb_pcap.cc
Normal file
@ -0,0 +1,198 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id$
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2021 Benjamin D Lunt (fys [at] fysnet [dot] net)
|
||||
// Copyright (C) 2002-2021 The Bochs Project
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// Notes by Ben Lunt:
|
||||
//
|
||||
// Experimental writing of packets to a Packet Capture (pcap) file for WireShark.
|
||||
// This will create a pcap formatted file of all packets sent to a
|
||||
// specific device. The using a pcap viewer, such as WireShark, you can
|
||||
// see what packets have been sent on the "wire" as well as let the viewer
|
||||
// give you details.
|
||||
//
|
||||
// References used:
|
||||
// https://wiki.wireshark.org/Development/LibpcapFileFormat
|
||||
// http://www.tcpdump.org/linktypes.html
|
||||
// https://www.kernel.org/doc/Documentation/usb/usbmon.txt
|
||||
// Other references (May or may not be added):
|
||||
// https://desowin.org/usbpcap/captureformat.html
|
||||
// http://www.tcpdump.org/linktypes/LINKTYPE_USB_DARWIN.html
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "iodev.h"
|
||||
|
||||
#if BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB
|
||||
|
||||
#include "usb_pcap.h"
|
||||
#include "usb_common.h"
|
||||
|
||||
#ifdef linux
|
||||
#include <linux/fs.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
/*** base class pcap_image_t ***/
|
||||
|
||||
pcap_image_t::pcap_image_t()
|
||||
{
|
||||
fd = -1;
|
||||
last_pos = 0;
|
||||
time_usecs = 0;
|
||||
}
|
||||
|
||||
pcap_image_t::~pcap_image_t()
|
||||
{
|
||||
if (fd > -1)
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
|
||||
int pcap_image_t::create_pcap(const char *pathname)
|
||||
{
|
||||
pcap_hdr_t header;
|
||||
|
||||
if (strlen(pathname) == 0)
|
||||
return 0;
|
||||
|
||||
fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC
|
||||
#ifdef O_BINARY
|
||||
| O_BINARY
|
||||
#endif
|
||||
, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP
|
||||
);
|
||||
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
// else write the header
|
||||
header.magic_number = 0xA1B2C3D4; // noted as little endian
|
||||
header.version_major = 0x0002; // major version number
|
||||
header.version_minor = 0x0004; // minor version number
|
||||
header.thiszone = 0; // GMT to local correction
|
||||
header.sigfigs = 0; // accuracy of timestamps
|
||||
header.snaplen = 0x00040000; // max length of captured packets, in octets
|
||||
header.network = BX_PCAP_LINKTYPE; // data link type (http://www.tcpdump.org/linktypes.html)
|
||||
write(fd, &header, sizeof(pcap_hdr_t));
|
||||
|
||||
// This relies on the fact that the time_t epoc is the same
|
||||
// epoc that the WireShark uses. We want it in Microseconds as well.
|
||||
// TODO: I only tested that this epoc is the same for a Windows Host.
|
||||
// * One will need to test for a non-Win32 host to make sure the epoc is the same.
|
||||
time_t mtime;
|
||||
time(&mtime);
|
||||
time_usecs = (Bit64u) mtime * 1000000; // 'NOW' in mS
|
||||
|
||||
#if BX_PCAP_APPEND_PACKETS
|
||||
last_pos = sizeof(sizeof(pcap_hdr_t));
|
||||
last_ep = 0xFF;
|
||||
#endif
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
void pcap_image_t::write_packet(void *data, int len, int bus, int dev_addr, int ep, int type, bool is_setup, bool can_append)
|
||||
{
|
||||
// if we haven't opened the file, do nothing
|
||||
if ((fd < 0) || (len == 0) || (data == NULL))
|
||||
return;
|
||||
|
||||
#if BX_PCAP_APPEND_PACKETS
|
||||
// can we append it to the last packet?
|
||||
// To make WireShark understand the packets, we need to
|
||||
// append like packets. i.e.: All IN packets of the GET_DESCRIPTOR request
|
||||
// need to be one (1) packet here for WireShark.
|
||||
if (can_append) {
|
||||
if ((last_packet.xfer_type == type) &&
|
||||
(last_ep == ep) &&
|
||||
(last_packet.devnum == dev_addr)) {
|
||||
last_hdr.incl_len += len;
|
||||
last_hdr.orig_len += len;
|
||||
last_packet.length += len;
|
||||
last_packet.len_cap += len;
|
||||
lseek(fd, last_pos, SEEK_SET); // seek to last pos
|
||||
write(fd, &last_hdr, sizeof(pcaprec_hdr_t));
|
||||
write(fd, &last_packet, sizeof(struct usbmon_packet));
|
||||
lseek(fd, 0, SEEK_END); // move to end of file again
|
||||
write(fd, data, len);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Bit32u length = sizeof(struct usbmon_packet) + ((!is_setup) ? len : 0);
|
||||
|
||||
const Bit64u t = time_usecs + bx_pc_system.time_usec();
|
||||
Bit64u seconds = (t / 1000000);
|
||||
Bit32u usecs = (Bit32u) (t % 1000000);
|
||||
|
||||
pcaprec_hdr_t header;
|
||||
header.ts_sec = (Bit32u) seconds; // timestamp seconds
|
||||
header.ts_usec = usecs; // timestamp microseconds
|
||||
header.incl_len = length; // number of octets of packet saved in file
|
||||
header.orig_len = length; // actual length of packet
|
||||
|
||||
struct usbmon_packet usb_hdr;
|
||||
usb_hdr.id = 0;
|
||||
usb_hdr.type = (ep & 0x80) ? 'C' : 'S';
|
||||
usb_hdr.xfer_type = type;
|
||||
usb_hdr.epnum = ep & 0x7F;
|
||||
usb_hdr.devnum = dev_addr;
|
||||
usb_hdr.busnum = 0;
|
||||
usb_hdr.flag_setup = (is_setup) ? 0 : '-';
|
||||
usb_hdr.flag_data = '='; // ???
|
||||
usb_hdr.ts_sec = seconds;
|
||||
usb_hdr.ts_usec = usecs;
|
||||
usb_hdr.status = 0; // assume success each time?
|
||||
usb_hdr.length = length - sizeof(struct usbmon_packet);
|
||||
usb_hdr.len_cap = length;
|
||||
if (is_setup)
|
||||
memcpy(usb_hdr.setup, data, 8);
|
||||
else
|
||||
memset(usb_hdr.setup, 0, 8);
|
||||
#if BX_PCAP_LINKTYPE == 220
|
||||
usb_hdr.interval = 0;
|
||||
usb_hdr.start_frame = 0;
|
||||
usb_hdr.xfer_flags = 0;
|
||||
usb_hdr.ndesc = 0; // we don't support ISO's, so the count is always zero
|
||||
#endif
|
||||
|
||||
#if BX_PCAP_APPEND_PACKETS
|
||||
// save current position
|
||||
last_pos = lseek(fd, 0, SEEK_CUR);
|
||||
#endif
|
||||
|
||||
write(fd, &header, sizeof(pcaprec_hdr_t));
|
||||
write(fd, &usb_hdr, sizeof(struct usbmon_packet));
|
||||
if (length > sizeof(struct usbmon_packet))
|
||||
write(fd, data, length - sizeof(struct usbmon_packet));
|
||||
|
||||
#if BX_PCAP_APPEND_PACKETS
|
||||
// save this for next time
|
||||
last_ep = ep;
|
||||
memcpy(&last_hdr, &header, sizeof(pcaprec_hdr_t));
|
||||
memcpy(&last_packet, &usb_hdr, sizeof(struct usbmon_packet));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
114
bochs/iodev/usb/usb_pcap.h
Normal file
114
bochs/iodev/usb/usb_pcap.h
Normal file
@ -0,0 +1,114 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id$
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2005-2021 The Bochs Project
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#ifndef BX_USB_PCAP_H
|
||||
#define BX_USB_PCAP_H
|
||||
|
||||
#define BX_PCAP_LINKTYPE 189
|
||||
//#define BX_PCAP_LINKTYPE 220
|
||||
|
||||
// define this to non-zero to append like packets so that WireShark will parse them correctly
|
||||
// define this to zero so that you can see each (ex: 8-byte) packet sent across the 'wire'
|
||||
#define BX_PCAP_APPEND_PACKETS 1
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(push, 1)
|
||||
#elif defined(__MWERKS__) && defined(macintosh)
|
||||
#pragma options align=packed
|
||||
#endif
|
||||
|
||||
typedef struct pcap_hdr_s {
|
||||
Bit32u magic_number; /* magic number */
|
||||
Bit16u version_major; /* major version number */
|
||||
Bit16u version_minor; /* minor version number */
|
||||
Bit32s thiszone; /* GMT to local correction */
|
||||
Bit32u sigfigs; /* accuracy of timestamps */
|
||||
Bit32u snaplen; /* max length of captured packets, in octets */
|
||||
Bit32u network; /* data link type */
|
||||
}
|
||||
#if !defined(_MSC_VER)
|
||||
GCC_ATTRIBUTE((packed))
|
||||
#endif
|
||||
pcap_hdr_t;
|
||||
|
||||
typedef struct pcaprec_hdr_s {
|
||||
Bit32u ts_sec; /* timestamp seconds */
|
||||
Bit32u ts_usec; /* timestamp microseconds */
|
||||
Bit32u incl_len; /* number of octets of packet saved in file */
|
||||
Bit32u orig_len; /* actual length of packet */
|
||||
}
|
||||
#if !defined(_MSC_VER)
|
||||
GCC_ATTRIBUTE((packed))
|
||||
#endif
|
||||
pcaprec_hdr_t;
|
||||
|
||||
struct usbmon_packet {
|
||||
Bit64u id;
|
||||
Bit8u type;
|
||||
Bit8u xfer_type;
|
||||
Bit8u epnum;
|
||||
Bit8u devnum;
|
||||
Bit16u busnum;
|
||||
Bit8s flag_setup;
|
||||
Bit8s flag_data;
|
||||
Bit64s ts_sec;
|
||||
Bit32s ts_usec;
|
||||
Bit32u status;
|
||||
Bit32u length;
|
||||
Bit32u len_cap;
|
||||
Bit8u setup[8];
|
||||
#if BX_PCAP_LINKTYPE == 220
|
||||
Bit32u interval;
|
||||
Bit32u start_frame;
|
||||
Bit32u xfer_flags;
|
||||
Bit32u ndesc;
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(pop)
|
||||
#elif defined(__MWERKS__) && defined(macintosh)
|
||||
#pragma options align=reset
|
||||
#endif
|
||||
|
||||
// base class
|
||||
class BOCHSAPI_MSVCONLY pcap_image_t
|
||||
{
|
||||
public:
|
||||
// Default constructor
|
||||
pcap_image_t();
|
||||
~pcap_image_t();
|
||||
|
||||
// append a packet to the pcap file
|
||||
int create_pcap(const char *filename);
|
||||
void write_packet(void *data, int len, int bus, int dev_addr, int ep, int type, bool is_setup, bool can_append);
|
||||
|
||||
private:
|
||||
int fd;
|
||||
off_t last_pos;
|
||||
|
||||
Bit8u last_ep;
|
||||
pcaprec_hdr_t last_hdr;
|
||||
struct usbmon_packet last_packet;
|
||||
|
||||
Bit64u time_usecs;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user