diff options
author | Zach Reizner <zachr@google.com> | 2019-03-18 20:58:31 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-27 01:36:47 -0700 |
commit | aff94ca6da90b92503558b6ba7aa68e1180afd87 (patch) | |
tree | 74fc34c90d1f6e10e6e921dddea389bdd51ad3e6 /vm_control/src/lib.rs | |
parent | d99cd0ae0b21d29d4e5145b889f97e9f6cd11b69 (diff) | |
download | crosvm-aff94ca6da90b92503558b6ba7aa68e1180afd87.tar crosvm-aff94ca6da90b92503558b6ba7aa68e1180afd87.tar.gz crosvm-aff94ca6da90b92503558b6ba7aa68e1180afd87.tar.bz2 crosvm-aff94ca6da90b92503558b6ba7aa68e1180afd87.tar.lz crosvm-aff94ca6da90b92503558b6ba7aa68e1180afd87.tar.xz crosvm-aff94ca6da90b92503558b6ba7aa68e1180afd87.tar.zst crosvm-aff94ca6da90b92503558b6ba7aa68e1180afd87.zip |
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 <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'vm_control/src/lib.rs')
-rw-r--r-- | vm_control/src/lib.rs | 32 |
1 files changed, 29 insertions, 3 deletions
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(()) + } } } } |