add a compatibility gate on USB HID interface

If the SoC isn't compatible, don't try starting the U2F server.
This commit is contained in:
bunnie 2022-06-27 02:00:22 +08:00
parent 9cf48fcaa5
commit 0e5fb14894
4 changed files with 60 additions and 28 deletions

View file

@ -192,6 +192,8 @@ fn main() -> ! {
let mut rng = ctap_crypto::rng256::XousRng256::new(&xns); let mut rng = ctap_crypto::rng256::XousRng256::new(&xns);
// this call will block until the PDDB is mounted. // this call will block until the PDDB is mounted.
let usb = usb_device_xous::UsbHid::new(); let usb = usb_device_xous::UsbHid::new();
// only run the main loop if the SoC is compatible
if usb.is_soc_compatible() {
let mut ctap_state = CtapState::new(&mut rng, check_user_presence, boot_time); let mut ctap_state = CtapState::new(&mut rng, check_user_presence, boot_time);
let mut ctap_hid = CtapHid::new(); let mut ctap_hid = CtapHid::new();
loop { loop {
@ -228,6 +230,9 @@ fn main() -> ! {
} }
} }
} }
} else {
log::warn!("SoC rev is incompatible with USB HID operations, the U2F/FIDO2 server is not started");
}
} }
}); });

View file

@ -28,6 +28,9 @@ pub(crate) enum Opcode {
/// Blocks the caller, waiting for a U2F message /// Blocks the caller, waiting for a U2F message
U2fRxDeferred, U2fRxDeferred,
/// Query if the HID driver was able to start
IsSocCompatible,
/// Handle the USB interrupt /// Handle the USB interrupt
UsbIrqHandler, UsbIrqHandler,
/// Suspend/resume callback /// Suspend/resume callback

View file

@ -29,6 +29,24 @@ impl UsbHid {
conn conn
} }
} }
/// used to query if the HID core was able to start. Mainly to handle edge cases between updates.
pub fn is_soc_compatible(&self) -> bool {
match send_message(
self.conn,
Message::new_blocking_scalar(
Opcode::IsSocCompatible.to_usize().unwrap(),
0, 0, 0, 0
)
) {
Ok(xous::Result::Scalar1(code)) => {
match code {
0 => false,
_ => true
}
}
_ => panic!("Internal error: illegal return type"),
}
}
/// this will always trigger a reset, even if it's the same core we're switching to /// this will always trigger a reset, even if it's the same core we're switching to
pub fn switch_to_core(&self, core: UsbDeviceType) -> Result<(), xous::Error> { pub fn switch_to_core(&self, core: UsbDeviceType) -> Result<(), xous::Error> {
match send_message( match send_message(

View file

@ -112,6 +112,9 @@ fn main() -> ! {
// block any rx requests forever // block any rx requests forever
fido_listener = Some(msg); fido_listener = Some(msg);
} }
Some(Opcode::IsSocCompatible) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
xous::return_scalar(msg.sender, 0).expect("couldn't return compatibility status")
}),
Some(Opcode::Quit) => { Some(Opcode::Quit) => {
break; break;
} }
@ -200,6 +203,9 @@ fn main() -> ! {
usbmgmt.xous_resume(); usbmgmt.xous_resume();
lockstatus_force_update = true; // notify the status bar that yes, it does need to redraw the lock status, even if the value hasn't changed since the last read lockstatus_force_update = true; // notify the status bar that yes, it does need to redraw the lock status, even if the value hasn't changed since the last read
}), }),
Some(Opcode::IsSocCompatible) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
xous::return_scalar(msg.sender, 1).expect("couldn't return compatibility status")
}),
Some(Opcode::U2fRxDeferred) => { Some(Opcode::U2fRxDeferred) => {
if fido_listener_pid.is_none() { if fido_listener_pid.is_none() {
fido_listener_pid = msg.sender.pid(); fido_listener_pid = msg.sender.pid();