From aff94ca6da90b92503558b6ba7aa68e1180afd87 Mon Sep 17 00:00:00 2001 From: Zach Reizner Date: Mon, 18 Mar 2019 20:58:31 -0700 Subject: usb: support for listing attached usb devices Originally, crosvm would list details about an attached usb device for a given port. This change allows getting details about multiple ports at once. This is intended to simplify command line usage and downstream consumers like concierge. TEST=various vmc commands Chrome UI for handling USB devices BUG=chromium:831850 Change-Id: I55681a7fea7425c897a22a579dcc15567683ef54 Reviewed-on: https://chromium-review.googlesource.com/1529765 Commit-Ready: Zach Reizner Tested-by: Zach Reizner Tested-by: kokoro Reviewed-by: Zach Reizner --- vm_control/src/lib.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'vm_control/src/lib.rs') diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs index 25902ea..0744b53 100644 --- a/vm_control/src/lib.rs +++ b/vm_control/src/lib.rs @@ -88,6 +88,13 @@ impl Default for VmRunMode { } } +/// The maximum number of devices that can be listed in one `UsbControlCommand`. +/// +/// This value was set to be equal to `xhci_regs::MAX_PORTS` for convenience, but it is not +/// necessary for correctness. Importing that value directly would be overkill because it would +/// require adding a big dependency for a single const. +pub const USB_CONTROL_MAX_PORTS: usize = 16; + #[derive(MsgOnSocket, Debug)] pub enum BalloonControlCommand { /// Set the size of the VM's balloon. @@ -129,10 +136,23 @@ pub enum UsbControlCommand { port: u8, }, ListDevice { - port: u8, + ports: [u8; USB_CONTROL_MAX_PORTS], }, } +#[derive(MsgOnSocket, Copy, Clone, Debug, Default)] +pub struct UsbControlAttachedDevice { + pub port: u8, + pub vendor_id: u16, + pub product_id: u16, +} + +impl UsbControlAttachedDevice { + fn valid(self) -> bool { + self.port != 0 + } +} + #[derive(MsgOnSocket, Debug)] pub enum UsbControlResult { Ok { port: u8 }, @@ -140,7 +160,7 @@ pub enum UsbControlResult { NoSuchDevice, NoSuchPort, FailedToOpenDevice, - Device { port: u8, vid: u16, pid: u16 }, + Devices([UsbControlAttachedDevice; USB_CONTROL_MAX_PORTS]), } impl Display for UsbControlResult { @@ -153,7 +173,13 @@ impl Display for UsbControlResult { NoSuchDevice => write!(f, "no_such_device"), NoSuchPort => write!(f, "no_such_port"), FailedToOpenDevice => write!(f, "failed_to_open_device"), - Device { port, vid, pid } => write!(f, "device {} {:04x} {:04x}", port, vid, pid), + Devices(devices) => { + write!(f, "devices")?; + for d in devices.iter().filter(|d| d.valid()) { + write!(f, " {} {:04x} {:04x}", d.port, d.vendor_id, d.product_id)?; + } + std::result::Result::Ok(()) + } } } } -- cgit 1.4.1