diff --git a/Cargo.toml b/Cargo.toml index b8b170d..43987da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ description = "usb-device driver for CTAPHID" categories = ["embedded", "no-std"] [dependencies] -ctap-types = "0.1.0" ctaphid-dispatch = "0.1.0" embedded-time = "0.12" delog = "0.1.0" diff --git a/src/constants.rs b/src/constants.rs index efd05d8..d82a8b2 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -2,6 +2,4 @@ pub const INTERRUPT_POLL_MILLISECONDS: u8 = 5; pub const PACKET_SIZE: usize = 64; -// 1200 -// pub const MESSAGE_SIZE: usize = ctap_types::sizes::REALISTIC_MAX_MESSAGE_SIZE; pub const MESSAGE_SIZE: usize = 3072; diff --git a/src/pipe.rs b/src/pipe.rs index a4b6834..3bf3cf7 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -21,7 +21,6 @@ use core::sync::atomic::Ordering; use ctaphid_dispatch::command::Command; use ctaphid_dispatch::types::Requester; -use ctap_types::Error as AuthenticatorError; use trussed::interrupt::InterruptFlag; use ref_swap::OptionRefSwap; @@ -43,6 +42,30 @@ use crate::{ types::KeepaliveStatus, }; +// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#usb-hid-error +// unused variants: InvalidParameter, LockRequired, Other +enum AuthenticatorError { + ChannelBusy, + InvalidChannel, + InvalidCommand, + InvalidLength, + InvalidSeq, + Timeout, +} + +impl From for u8 { + fn from(error: AuthenticatorError) -> Self { + match error { + AuthenticatorError::InvalidCommand => 0x01, + AuthenticatorError::InvalidLength => 0x03, + AuthenticatorError::InvalidSeq => 0x04, + AuthenticatorError::Timeout => 0x05, + AuthenticatorError::ChannelBusy => 0x06, + AuthenticatorError::InvalidChannel => 0x0B, + } + } +} + /// The actual payload of given length is dealt with separately #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Request { @@ -621,7 +644,7 @@ impl<'alloc, 'pipe, 'interrupt, Bus: UsbBus> Pipe<'alloc, 'pipe, 'interrupt, Bus } fn start_sending_error_on_channel(&mut self, channel: u32, error: AuthenticatorError) { - self.buffer[0] = error as u8; + self.buffer[0] = error.into(); let response = Response::error_on_channel(channel); self.start_sending(response); }