[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 4/6] hw/usb/bus.c: PCAP adding 0xA in Windows version
From: |
Thomas Huth |
Subject: |
[PULL 4/6] hw/usb/bus.c: PCAP adding 0xA in Windows version |
Date: |
Fri, 1 Mar 2024 09:09:51 +0100 |
From: Benjamin David Lunt <benlunt@fysnet.net>
Since Windows text files use CRLFs for all \n, the Windows version of QEMU
inserts a CR in the PCAP stream when a LF is encountered when using USB PCAP
files. This is due to the fact that the PCAP file is opened as TEXT instead
of BINARY.
To show an example, when using a very common protocol to USB disks, the BBB
protocol uses a 10-byte command packet. For example, the READ_CAPACITY(10)
command will have a command block length of 10 (0xA). When this 10-byte
command (part of the 31-byte CBW) is placed into the PCAP file, the Windows
file manager inserts a 0xD before the 0xA, turning the 31-byte CBW into a
32-byte CBW.
Actual CBW:
0040 55 53 42 43 01 00 00 00 08 00 00 00 80 00 0a 25 USBC...........%
0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...............
PCAP CBW
0040 55 53 42 43 01 00 00 00 08 00 00 00 80 00 0d 0a USBC............
0050 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 %..............
I believe simply opening the PCAP file as BINARY instead of TEXT will fix
this issue.
Cc: qemu-stable@nongnu.org
Resolves: https://bugs.launchpad.net/qemu/+bug/2054889
Signed-off-by: Benjamin David Lunt <benlunt@fysnet.net>
Message-ID: <000101da6823$ce1bbf80$6a533e80$@fysnet.net>
[thuth: Break long line to avoid checkpatch.pl error]
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
hw/usb/bus.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 796769fadb..bfab2807d7 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -260,13 +260,14 @@ static void usb_qdev_realize(DeviceState *qdev, Error
**errp)
}
if (dev->pcap_filename) {
- int fd = qemu_open_old(dev->pcap_filename, O_CREAT | O_WRONLY |
O_TRUNC, 0666);
+ int fd = qemu_open_old(dev->pcap_filename,
+ O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0666);
if (fd < 0) {
error_setg(errp, "open %s failed", dev->pcap_filename);
usb_qdev_unrealize(qdev);
return;
}
- dev->pcap = fdopen(fd, "w");
+ dev->pcap = fdopen(fd, "wb");
usb_pcap_init(dev->pcap);
}
}
--
2.44.0
- [PULL 0/6] Misc fixes (libqos vring, Kconfig, TLS io channels, ...), Thomas Huth, 2024/03/01
- [PULL 1/6] libqos/virtio.c: init all elems in qvring_indirect_desc_setup(), Thomas Huth, 2024/03/01
- [PULL 3/6] hw/intc/Kconfig: Fix GIC settings when using "--without-default-devices", Thomas Huth, 2024/03/01
- [PULL 2/6] libqos/virtio.c: fix 'avail_event' offset in qvring_init(), Thomas Huth, 2024/03/01
- [PULL 6/6] chardev/char-socket: Fix TLS io channels sending too much data to the backend, Thomas Huth, 2024/03/01
- [PULL 5/6] tests/unit/test-util-sockets: Remove temporary file after test, Thomas Huth, 2024/03/01
- [PULL 4/6] hw/usb/bus.c: PCAP adding 0xA in Windows version,
Thomas Huth <=
- Re: [PULL 0/6] Misc fixes (libqos vring, Kconfig, TLS io channels, ...), Peter Maydell, 2024/03/01