Skip to content

Commit

Permalink
usb_mode: support BMC as USB-host
Browse files Browse the repository at this point in the history
API is extended with usb mode = 3; BMC as USB-host
  • Loading branch information
svenrademakers committed Sep 19, 2023
1 parent b5f5579 commit 85ccb54
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bmcd/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,17 @@ async fn set_usb_mode(bmc: &BmcApplication, query: Query) -> LegacyResult<()> {
let mode_num = i32::from_str(mode_str)
.map_err(|_| LegacyResponse::bad_request("Parameter `mode` is not a number"))?;

let mode = mode_num
let mode = (mode_num & 0x3)
.try_into()
.map_err(|_| LegacyResponse::bad_request("Parameter `mode` can be either 0 or 1"))?;

bmc.usb_boot(node, true).await?;
let route = (mode_num & 0x4)
.try_into()
.expect("conversion of single bit cannot fail");

let cfg = match mode {
UsbMode::Device => UsbConfig::UsbA(node),
UsbMode::Host => UsbConfig::Node(node, UsbRoute::UsbA),
UsbMode::Host => UsbConfig::Node(node, route),
};

bmc.configure_usb(cfg)
Expand Down

0 comments on commit 85ccb54

Please sign in to comment.