mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
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:
parent
9cf48fcaa5
commit
0e5fb14894
4 changed files with 60 additions and 28 deletions
|
|
@ -192,41 +192,46 @@ fn main() -> ! {
|
|||
let mut rng = ctap_crypto::rng256::XousRng256::new(&xns);
|
||||
// this call will block until the PDDB is mounted.
|
||||
let usb = usb_device_xous::UsbHid::new();
|
||||
let mut ctap_state = CtapState::new(&mut rng, check_user_presence, boot_time);
|
||||
let mut ctap_hid = CtapHid::new();
|
||||
loop {
|
||||
match usb.u2f_wait_incoming() {
|
||||
Ok(msg) => {
|
||||
log::trace!("FIDO listener got message: {:?}", msg);
|
||||
let now = ClockValue::new(tt.elapsed_ms() as i64, 1000);
|
||||
let reply = ctap_hid.process_hid_packet(&msg.packet, now, &mut ctap_state);
|
||||
// This block handles sending packets.
|
||||
for pkt_reply in reply {
|
||||
let mut reply = RawFidoMsg::default();
|
||||
reply.packet.copy_from_slice(&pkt_reply);
|
||||
let status = usb.u2f_send(reply);
|
||||
match status {
|
||||
Ok(()) => {
|
||||
log::trace!("Sent U2F packet");
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Error sending U2F packet: {:?}", e);
|
||||
// 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_hid = CtapHid::new();
|
||||
loop {
|
||||
match usb.u2f_wait_incoming() {
|
||||
Ok(msg) => {
|
||||
log::trace!("FIDO listener got message: {:?}", msg);
|
||||
let now = ClockValue::new(tt.elapsed_ms() as i64, 1000);
|
||||
let reply = ctap_hid.process_hid_packet(&msg.packet, now, &mut ctap_state);
|
||||
// This block handles sending packets.
|
||||
for pkt_reply in reply {
|
||||
let mut reply = RawFidoMsg::default();
|
||||
reply.packet.copy_from_slice(&pkt_reply);
|
||||
let status = usb.u2f_send(reply);
|
||||
match status {
|
||||
Ok(()) => {
|
||||
log::trace!("Sent U2F packet");
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Error sending U2F packet: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
match e {
|
||||
xous::Error::ProcessTerminated => { // unplug happened, reset the authenticator
|
||||
log::info!("CTAP unplug_reset");
|
||||
ctap_state.unplug_reset();
|
||||
},
|
||||
_ => {
|
||||
log::warn!("FIDO listener got an error: {:?}", e);
|
||||
Err(e) => {
|
||||
match e {
|
||||
xous::Error::ProcessTerminated => { // unplug happened, reset the authenticator
|
||||
log::info!("CTAP unplug_reset");
|
||||
ctap_state.unplug_reset();
|
||||
},
|
||||
_ => {
|
||||
log::warn!("FIDO listener got an error: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log::warn!("SoC rev is incompatible with USB HID operations, the U2F/FIDO2 server is not started");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ pub(crate) enum Opcode {
|
|||
/// Blocks the caller, waiting for a U2F message
|
||||
U2fRxDeferred,
|
||||
|
||||
/// Query if the HID driver was able to start
|
||||
IsSocCompatible,
|
||||
|
||||
/// Handle the USB interrupt
|
||||
UsbIrqHandler,
|
||||
/// Suspend/resume callback
|
||||
|
|
|
|||
|
|
@ -29,6 +29,24 @@ impl UsbHid {
|
|||
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
|
||||
pub fn switch_to_core(&self, core: UsbDeviceType) -> Result<(), xous::Error> {
|
||||
match send_message(
|
||||
|
|
|
|||
|
|
@ -112,6 +112,9 @@ fn main() -> ! {
|
|||
// block any rx requests forever
|
||||
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) => {
|
||||
break;
|
||||
}
|
||||
|
|
@ -200,6 +203,9 @@ fn main() -> ! {
|
|||
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
|
||||
}),
|
||||
Some(Opcode::IsSocCompatible) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
xous::return_scalar(msg.sender, 1).expect("couldn't return compatibility status")
|
||||
}),
|
||||
Some(Opcode::U2fRxDeferred) => {
|
||||
if fido_listener_pid.is_none() {
|
||||
fido_listener_pid = msg.sender.pid();
|
||||
|
|
|
|||
Loading…
Reference in a new issue