From dada0dff78331a31b449be7e369c162919975cbe Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Wed, 27 Apr 2022 17:02:55 +0200 Subject: [PATCH] qemu-usb: support policy labels w/o vendor/product Fixes #4492 --- repos/libports/src/lib/qemu-usb/host.cc | 38 +++++++++++++------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/repos/libports/src/lib/qemu-usb/host.cc b/repos/libports/src/lib/qemu-usb/host.cc index 7ac1634e35..0bc8f2e7f9 100644 --- a/repos/libports/src/lib/qemu-usb/host.cc +++ b/repos/libports/src/lib/qemu-usb/host.cc @@ -208,17 +208,21 @@ struct Completion : Usb::Completion */ struct Dev_info { + Session_label const label; + uint32_t const vendor, product; uint16_t const bus, dev; - Dev_info(uint16_t bus, uint16_t dev, uint32_t vendor, uint32_t product) + Dev_info(Session_label label, uint16_t bus, uint16_t dev, + uint32_t vendor, uint32_t product) : - vendor(vendor), product(product), bus(bus), dev(dev) + label(label), vendor(vendor), product(product), bus(bus), dev(dev) { } void print(Output &out) const { - Genode::print(out, Hex(bus, Hex::OMIT_PREFIX, Hex::PAD), ":", + Genode::print(out, label, " ", + Hex(bus, Hex::OMIT_PREFIX, Hex::PAD), ":", Hex(dev, Hex::OMIT_PREFIX, Hex::PAD), " (", "vendor=", Hex(vendor, Hex::OMIT_PREFIX), ", ", "product=", Hex(product, Hex::OMIT_PREFIX), ")"); @@ -232,6 +236,9 @@ struct Dev_info if (vendor && product) return vendor != other.vendor || product != other.product; + if (label.length() && other.label.length()) + return label != other.label; + return true; } }; @@ -305,12 +312,10 @@ struct Usb_host_device : List::Element return result; } - Usb_host_device(Entrypoint &ep, Allocator &alloc, - Env &env, char const *label, - Dev_info info) + Usb_host_device(Entrypoint &ep, Allocator &alloc, Env &env, Dev_info info) : - label(label), _alloc(alloc), - usb_raw(env, &_usb_alloc, label, 6*1024*1024, state_dispatcher), + _alloc(alloc), + usb_raw(env, &_usb_alloc, info.label.string(), 6*1024*1024, state_dispatcher), info(info), _ep(ep) { usb_raw.tx_channel()->sigh_ack_avail(ack_avail_dispatcher); @@ -997,21 +1002,19 @@ struct Usb_devices : List Xml_node devices_node(_devices_rom.local_addr(), _devices_rom.size()); devices_node.for_each_sub_node("device", [&] (Xml_node const &node) { - unsigned product = node.attribute_value("product_id", 0); - unsigned vendor = node.attribute_value("vendor_id", 0); - unsigned bus = node.attribute_value("bus", 0); - unsigned dev = node.attribute_value("dev", 0); + auto const product = node.attribute_value("product_id", 0u); + auto const vendor = node.attribute_value("vendor_id", 0u); + auto const bus = node.attribute_value("bus", 0u); + auto const dev = node.attribute_value("dev", 0u); + Session_label label = node.attribute_value("label", String<160>()); - Dev_info const dev_info(bus, dev, vendor, product); + Dev_info const dev_info(label, bus, dev, vendor, product); if (!node.has_attribute("label")) { error("no label found for device ", dev_info); return; } - typedef String<128> Label; - Label const label = node.attribute_value("label", Label()); - /* ignore if already created */ bool exists = false; for_each([&] (Usb_host_device &device) { @@ -1027,8 +1030,7 @@ struct Usb_devices : List try { Usb_host_device *new_device = new (_alloc) - Usb_host_device(_ep, _alloc, _env, label.string(), - dev_info); + Usb_host_device(_ep, _alloc, _env, dev_info); insert(new_device);