qemu-patch-raspberry4/hw/usb
Nick Rosbrook 0dbe4768b9 usb-host: use correct altsetting in usb_host_ep_update
In order to keep track of the alternate setting that should be used for
a given interface, the USBDevice struct keeps an array of alternate
setting values, which is indexed by the interface number. In
usb_host_set_interface, when this array is updated, usb_host_ep_update
is called as a result. However, when usb_host_ep_update accesses the
active libusb_config_descriptor, it indexes udev->altsetting with the
loop variable, rather than the interface number.

With the simple trace backend enable, this behavior can be seen:

  [...]

  usb_xhci_xfer_start 0.440 pid=1215 xfer=0x5596a4b85930 slotid=0x1 epid=0x1 streamid=0x0
  usb_packet_state_change 1.703 pid=1215 bus=0x1 port=b'1' ep=0x0 p=0x5596a4b85938 o=b'undef' n=b'setup'
  usb_host_req_control 2.269 pid=1215 bus=0x1 addr=0x5 p=0x5596a4b85938 req=0x10b value=0x1 index=0xd
  usb_host_set_interface 0.449 pid=1215 bus=0x1 addr=0x5 interface=0xd alt=0x1
  usb_host_parse_config 2542.648 pid=1215 bus=0x1 addr=0x5 value=0x2 active=0x1
  usb_host_parse_interface 1.804 pid=1215 bus=0x1 addr=0x5 num=0xc alt=0x0 active=0x1
  usb_host_parse_endpoint 2.012 pid=1215 bus=0x1 addr=0x5 ep=0x2 dir=b'in' type=b'int' active=0x1
  usb_host_parse_interface 1.598 pid=1215 bus=0x1 addr=0x5 num=0xd alt=0x0 active=0x1
  usb_host_req_emulated 3.593 pid=1215 bus=0x1 addr=0x5 p=0x5596a4b85938 status=0x0
  usb_packet_state_change 2.550 pid=1215 bus=0x1 port=b'1' ep=0x0 p=0x5596a4b85938 o=b'setup' n=b'complete'
  usb_xhci_xfer_success 4.298 pid=1215 xfer=0x5596a4b85930 bytes=0x0

  [...]

In particular, it is seen that although usb_host_set_interface sets the
alternate setting of interface 0xd to 0x1, usb_host_ep_update uses 0x0
as the alternate setting due to using the incorrect index to
udev->altsetting.

Fix this problem by getting the interface number from the active
libusb_config_descriptor, and then using that as the index to
udev->altsetting.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
Message-Id: <20210201213021.500277-1-rosbrookn@ainfosec.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-02-17 14:29:12 +01:00
..
bus.c usb: add pcap support. 2021-01-22 14:51:35 +01:00
ccid-card-emulated.c hw/usb: Use lock guard macros 2020-09-28 13:13:58 +02:00
ccid-card-passthru.c hw/usb: Fix bad printf format specifiers 2021-01-22 14:51:35 +01:00
ccid.h Use OBJECT_DECLARE_TYPE when possible 2020-09-18 14:12:32 -04:00
chipidea.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
combined-packet.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
core.c usb: add pcap support. 2021-01-22 14:51:35 +01:00
desc-msos.c usb: use local path for local headers 2018-06-01 19:20:38 +03:00
desc.c usb: use local path for local headers 2018-06-01 19:20:38 +03:00
desc.h all: Clean up includes 2016-02-23 12:43:05 +00:00
dev-audio.c Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
dev-hid.c Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
dev-hub.c Remove superfluous timer_del() calls 2021-01-08 15:13:38 +00:00
dev-mtp.c Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
dev-network.c Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
dev-serial.c qdev: Move softmmu properties to qdev-properties-system.h 2020-12-18 15:20:17 -05:00
dev-smartcard-reader.c hw/usb: Fix bad printf format specifiers 2021-01-22 14:51:35 +01:00
dev-storage.c block: Separate blk_is_writable() and blk_supports_write_perm() 2021-01-27 20:45:20 +01:00
dev-uas.c hw/usb/dev-uas: Report command additional adb length as unsupported 2021-01-22 14:51:35 +01:00
dev-wacom.c Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
hcd-dwc2.c hw/usb/hcd-dwc2: fix divide-by-zero in dwc2_handle_packet() 2020-10-19 09:17:21 +02:00
hcd-dwc2.h Use OBJECT_DECLARE_TYPE when possible 2020-09-18 14:12:32 -04:00
hcd-dwc3.c usb: Add DWC3 model 2020-12-15 12:04:30 +00:00
hcd-ehci-pci.c qdev: Unrealize must not fail 2020-05-15 07:08:14 +02:00
hcd-ehci-sysbus.c hw/arm/npcm7xx: Add EHCI and OHCI controllers 2020-10-27 11:10:21 +00:00
hcd-ehci.c hw/usb: Fix bad printf format specifiers 2021-01-22 14:51:35 +01:00
hcd-ehci.h hw/arm/npcm7xx: Add EHCI and OHCI controllers 2020-10-27 11:10:21 +00:00
hcd-musb.c exec/cpu-common: Move MUSB specific typedefs to 'hw/usb/hcd-musb.h' 2020-06-12 11:20:15 -04:00
hcd-ohci-pci.c Remove superfluous timer_del() calls 2021-01-08 15:13:38 +00:00
hcd-ohci.c usb: Fix Lesser GPL version number 2020-11-15 16:40:48 +01:00
hcd-ohci.h Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
hcd-uhci.c Remove superfluous timer_del() calls 2021-01-08 15:13:38 +00:00
hcd-xhci-nec.c usb: Fix Lesser GPL version number 2020-11-15 16:40:48 +01:00
hcd-xhci-pci.c hw/usb: Convert to qdev_realize() 2021-01-22 14:51:35 +01:00
hcd-xhci-pci.h usb: Fix Lesser GPL version number 2020-11-15 16:40:48 +01:00
hcd-xhci-sysbus.c hw/usb: Convert to qdev_realize() 2021-01-22 14:51:35 +01:00
hcd-xhci-sysbus.h usb/xhci: add include/hw/usb/xhci.h header file 2020-10-21 11:36:19 +02:00
hcd-xhci.c Remove superfluous timer_del() calls 2021-01-08 15:13:38 +00:00
hcd-xhci.h hw/usb/hcd-xhci: Fix extraneous format-truncation error on 32-bit hosts 2021-01-22 14:51:35 +01:00
host-libusb.c usb-host: use correct altsetting in usb_host_ep_update 2021-02-17 14:29:12 +01:00
host-stub.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
host.h usb-host: move legacy cmd line bits 2013-02-19 12:30:05 +01:00
imx-usb-phy.c hw/usb: Add basic i.MX USB Phy support 2020-03-17 11:23:14 +00:00
Kconfig usb: xlnx-usb-subsystem: Add xilinx usb subsystem 2020-12-15 12:04:30 +00:00
libhw.c Include hw/hw.h exactly where needed 2019-08-16 13:31:52 +02:00
meson.build usb: add pcap support. 2021-01-22 14:51:35 +01:00
pcap.c usb: add pcap support. 2021-01-22 14:51:35 +01:00
quirks-ftdi-ids.h usbredir: Add support for buffered bulk input (v2) 2013-01-08 10:56:58 +01:00
quirks-pl2303-ids.h usbredir: Add support for buffered bulk input (v2) 2013-01-08 10:56:58 +01:00
quirks.c hw/usb/quirks: Use smaller types to reduce .rodata by 10KiB 2020-03-16 23:02:25 +01:00
quirks.h hw/usb/quirks: Use smaller types to reduce .rodata by 10KiB 2020-03-16 23:02:25 +01:00
redirect.c Remove superfluous timer_del() calls 2021-01-08 15:13:38 +00:00
trace-events usb-storage: switch trace events 2020-11-16 09:11:21 +01:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
tusb6010.c Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
u2f-emulated.c usb: fix u2f build 2020-09-21 09:44:54 +02:00
u2f-passthru.c util: rename qemu_open() to qemu_open_old() 2020-09-16 10:33:48 +01:00
u2f.c hw/usb: Add U2F key base class implementation 2020-08-31 08:10:47 +02:00
u2f.h hw/usb: Add U2F key base class 2020-08-31 08:10:47 +02:00
xen-usb.c xen: Fix and improve handling of device_add usb-host errors 2020-05-27 07:45:17 +02:00
xlnx-usb-subsystem.c usb: xlnx-usb-subsystem: Add xilinx usb subsystem 2020-12-15 12:04:30 +00:00
xlnx-versal-usb2-ctrl-regs.c usb: Add versal-usb2-ctrl-regs module 2020-12-15 12:04:30 +00:00