devices: usb: clean up intercepted_control_transfer

Rearrange the control request type match to check the request and
recipient together in a tuple (along with direction, which will be
different for a Get Descriptor request, to be added in the next commit).

No functional change.

BUG=b:180238956
BUG=chromium:1030778
TEST=Share USB device with Crostini

Change-Id: I51badd8f8b067a5e19216a92257c2b75c2041663
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2811860
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
Daniel Verkamp 2021-04-05 14:40:01 -07:00 committed by Commit Bot
parent 7b17f50df9
commit 425e4aad1e

View file

@ -95,43 +95,48 @@ impl HostDevice {
fn intercepted_control_transfer(&mut self, xhci_transfer: &XhciTransfer) -> Result<bool> { fn intercepted_control_transfer(&mut self, xhci_transfer: &XhciTransfer) -> Result<bool> {
let direction = self.control_request_setup.get_direction(); let direction = self.control_request_setup.get_direction();
let recipient = self.control_request_setup.get_recipient(); let recipient = self.control_request_setup.get_recipient();
let standard_request = self.control_request_setup.get_standard_request(); let standard_request = if let Some(req) = self.control_request_setup.get_standard_request()
{
if direction != ControlRequestDataPhaseTransferDirection::HostToDevice { req
// Only host to device requests are intercepted currently. } else {
// Unknown control requests will be passed through to the device.
return Ok(false); return Ok(false);
} };
let status = match standard_request { let (status, bytes_transferred) = match (standard_request, recipient, direction) {
Some(StandardControlRequest::SetAddress) => { (
if recipient != ControlRequestRecipient::Device { StandardControlRequest::SetAddress,
return Ok(false); ControlRequestRecipient::Device,
} ControlRequestDataPhaseTransferDirection::HostToDevice,
) => {
usb_debug!("host device handling set address"); usb_debug!("host device handling set address");
let addr = self.control_request_setup.value as u32; let addr = self.control_request_setup.value as u32;
self.set_address(addr); self.set_address(addr);
TransferStatus::Completed (TransferStatus::Completed, 0)
} }
Some(StandardControlRequest::SetConfiguration) => { (
if recipient != ControlRequestRecipient::Device { StandardControlRequest::SetConfiguration,
return Ok(false); ControlRequestRecipient::Device,
} ControlRequestDataPhaseTransferDirection::HostToDevice,
) => {
usb_debug!("host device handling set config"); usb_debug!("host device handling set config");
self.set_config()? (self.set_config()?, 0)
} }
Some(StandardControlRequest::SetInterface) => { (
if recipient != ControlRequestRecipient::Interface { StandardControlRequest::SetInterface,
return Ok(false); ControlRequestRecipient::Interface,
} ControlRequestDataPhaseTransferDirection::HostToDevice,
) => {
usb_debug!("host device handling set interface"); usb_debug!("host device handling set interface");
self.set_interface()? (self.set_interface()?, 0)
} }
Some(StandardControlRequest::ClearFeature) => { (
if recipient != ControlRequestRecipient::Endpoint { StandardControlRequest::ClearFeature,
return Ok(false); ControlRequestRecipient::Endpoint,
} ControlRequestDataPhaseTransferDirection::HostToDevice,
) => {
usb_debug!("host device handling clear feature"); usb_debug!("host device handling clear feature");
self.clear_feature()? (self.clear_feature()?, 0)
} }
_ => { _ => {
// Other requests will be passed through to the device. // Other requests will be passed through to the device.
@ -140,7 +145,7 @@ impl HostDevice {
}; };
xhci_transfer xhci_transfer
.on_transfer_complete(&status, 0) .on_transfer_complete(&status, bytes_transferred)
.map_err(Error::TransferComplete)?; .map_err(Error::TransferComplete)?;
Ok(true) Ok(true)
} }