summary refs log tree commit diff
path: root/usb_util
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-05-01 17:34:32 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-05-10 15:26:01 -0700
commit9fb20d9c53b426d74a251f585a37183fe1137031 (patch)
tree70f5622df02dd48d26253165de66d87e2deae322 /usb_util
parent659b1779e2c24fe4c8acf8b91dae066d46743e64 (diff)
downloadcrosvm-9fb20d9c53b426d74a251f585a37183fe1137031.tar
crosvm-9fb20d9c53b426d74a251f585a37183fe1137031.tar.gz
crosvm-9fb20d9c53b426d74a251f585a37183fe1137031.tar.bz2
crosvm-9fb20d9c53b426d74a251f585a37183fe1137031.tar.lz
crosvm-9fb20d9c53b426d74a251f585a37183fe1137031.tar.xz
crosvm-9fb20d9c53b426d74a251f585a37183fe1137031.tar.zst
crosvm-9fb20d9c53b426d74a251f585a37183fe1137031.zip
usb: refactor intercepted control request handling
Certain control requests need to be intercepted for special handling
rather than being passed through directly to the device.  Clean up the
implementation of these intercepted requests by getting rid of the
confusing intermediate analyze_request_setup function and merging it
with the actual handling of each intercepted request in the new
execute_control_transfer function.  This keeps the custom handling all
in one place rather than scattered around the file and removes the need
for the extra HostToDeviceControlRequest enum.

Also add a check in get_standard_request to verify that the request is
indeed a standard control request so that the caller does not need to
check.

BUG=chromium:831850
TEST=Test adb on Crostini

Change-Id: I73b1db76941c39f124cfd0f51f14c15017ba9141
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1593714
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'usb_util')
-rw-r--r--usb_util/src/types.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/usb_util/src/types.rs b/usb_util/src/types.rs
index eaebc70..f40dd6c 100644
--- a/usb_util/src/types.rs
+++ b/usb_util/src/types.rs
@@ -59,7 +59,7 @@ pub const DATA_PHASE_DIRECTION_OFFSET: u8 = 7;
 /// Bit mask of data phase transfer direction.
 pub const DATA_PHASE_DIRECTION: u8 = 1u8 << DATA_PHASE_DIRECTION_OFFSET;
 // Types of data phase transfer directions.
-#[derive(PartialEq)]
+#[derive(Copy, Clone, PartialEq)]
 pub enum ControlRequestDataPhaseTransferDirection {
     HostToDevice = 0,
     DeviceToHost = 1,
@@ -175,6 +175,9 @@ impl UsbRequestSetup {
 
     /// Return the type of standard control request.
     pub fn get_standard_request(&self) -> Option<StandardControlRequest> {
+        if self.get_type() != ControlRequestType::Standard {
+            return None;
+        }
         match self.request {
             0x00 => Some(StandardControlRequest::GetStatus),
             0x01 => Some(StandardControlRequest::ClearFeature),