From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH] usb: add pcap support.
Date: Tue, 19 Jan 2021 22:01:51 +0100 [thread overview]
Message-ID: <97b56d63-870c-2c41-b20c-96411301dc62@redhat.com> (raw)
In-Reply-To: <20210119194452.2148048-1-kraxel@redhat.com>
On 1/19/21 8:44 PM, Gerd Hoffmann wrote:
> Log all traffic of a specific usb device to a pcap file for later
> inspection. File format is compatible with linux usb monitor.
>
> Usage:
> qemu -device usb-${somedevice},pcap=file.pcap
> wireshark file.pcap
Great!
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> include/hw/usb.h | 8 ++
> hw/usb/bus.c | 16 +++
> hw/usb/core.c | 17 ++++
> hw/usb/pcap.c | 242 +++++++++++++++++++++++++++++++++++++++++++++
> hw/usb/meson.build | 1 +
> 5 files changed, 284 insertions(+)
> create mode 100644 hw/usb/pcap.c
...
> diff --git a/hw/usb/pcap.c b/hw/usb/pcap.c
> new file mode 100644
> index 000000000000..d3162d65e5fe
> --- /dev/null
> +++ b/hw/usb/pcap.c
> @@ -0,0 +1,242 @@
Missing license.
> +#include "qemu/osdep.h"
> +#include "hw/usb.h"
> +
> +#define PCAP_MAGIC 0xa1b2c3d4
> +#define PCAP_MAJOR 2
> +#define PCAP_MINOR 4
> +
> +/* https://wiki.wireshark.org/Development/LibpcapFileFormat */
> +
> +struct pcap_hdr {
> + uint32_t magic_number; /* magic number */
> + uint16_t version_major; /* major version number */
> + uint16_t version_minor; /* minor version number */
> + int32_t thiszone; /* GMT to local correction */
> + uint32_t sigfigs; /* accuracy of timestamps */
> + uint32_t snaplen; /* max length of captured packets, in octets */
> + uint32_t network; /* data link type */
> +};
QEMU_PACKED?
> +
> +struct pcaprec_hdr {
> + uint32_t ts_sec; /* timestamp seconds */
> + uint32_t ts_usec; /* timestamp microseconds */
> + uint32_t incl_len; /* number of octets of packet saved in file */
> + uint32_t orig_len; /* actual length of packet */
> +};
QEMU_PACKED?
> +
> +/* https://www.tcpdump.org/linktypes.html */
> +/* linux: Documentation/usb/usbmon.rst */
> +/* linux: drivers/usb/mon/mon_bin.c */
> +
> +#define LINKTYPE_USB_LINUX 189 /* first 48 bytes only */
> +#define LINKTYPE_USB_LINUX_MMAPPED 220 /* full 64 byte header */
> +
> +struct usbmon_packet {
> + uint64_t id; /* 0: URB ID - from submission to callback */
> + unsigned char type; /* 8: Same as text; extensible. */
> + unsigned char xfer_type; /* ISO (0), Intr, Control, Bulk (3) */
> + unsigned char epnum; /* Endpoint number and transfer direction */
> + unsigned char devnum; /* Device address */
> + uint16_t busnum; /* 12: Bus number */
> + char flag_setup; /* 14: Same as text */
> + char flag_data; /* 15: Same as text; Binary zero is OK. */
> + int64_t ts_sec; /* 16: gettimeofday */
> + int32_t ts_usec; /* 24: gettimeofday */
> + int32_t status; /* 28: */
> + unsigned int length; /* 32: Length of data (submitted or actual) */
> + unsigned int len_cap; /* 36: Delivered length */
> + union { /* 40: */
> + unsigned char setup[8]; /* Only for Control S-type */
> + struct iso_rec { /* Only for ISO */
> + int32_t error_count;
> + int32_t numdesc;
> + } iso;
> + } s;
> + int32_t interval; /* 48: Only for Interrupt and ISO */
> + int32_t start_frame; /* 52: For ISO */
> + uint32_t xfer_flags; /* 56: copy of URB's transfer_flags */
> + uint32_t ndesc; /* 60: Actual number of ISO descriptors */
> +}; /* 64 total length */
QEMU_PACKED?
Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
next prev parent reply other threads:[~2021-01-19 21:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-19 19:44 [PATCH] usb: add pcap support Gerd Hoffmann
2021-01-19 21:01 ` Philippe Mathieu-Daudé [this message]
2021-01-20 9:13 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=97b56d63-870c-2c41-b20c-96411301dc62@redhat.com \
--to=philmd@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).