mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-11 12:35:26 +00:00
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:
parent
7b17f50df9
commit
425e4aad1e
1 changed files with 32 additions and 27 deletions
|
@ -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 {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
}
|
||||||
|
(
|
||||||
|
StandardControlRequest::SetConfiguration,
|
||||||
|
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 {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
}
|
||||||
|
(
|
||||||
|
StandardControlRequest::SetInterface,
|
||||||
|
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 {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
}
|
||||||
|
(
|
||||||
|
StandardControlRequest::ClearFeature,
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue