diff --git a/.github/workflows/cargo_check.yml b/.github/workflows/cargo_check.yml index a6c4c4696cca73994152d3ee1422399374e7f768..c54fc9e34ab5309e19d28dc4f9894bbcba72637f 100644 --- a/.github/workflows/cargo_check.yml +++ b/.github/workflows/cargo_check.yml @@ -64,17 +64,23 @@ jobs: command: check args: --target thumbv7em-none-eabi --release --features ram_storage + - name: Check OpenSK verbose + uses: actions-rs/cargo@v1 + with: + command: check + args: --target thumbv7em-none-eabi --release --features verbose + - name: Check OpenSK debug_ctap,with_ctap1 uses: actions-rs/cargo@v1 with: command: check args: --target thumbv7em-none-eabi --release --features debug_ctap,with_ctap1 - - name: Check OpenSK debug_ctap,with_ctap1,panic_console,debug_allocations + - name: Check OpenSK debug_ctap,with_ctap1,panic_console,debug_allocations,verbose uses: actions-rs/cargo@v1 with: command: check - args: --target thumbv7em-none-eabi --release --features debug_ctap,with_ctap1,panic_console,debug_allocations + args: --target thumbv7em-none-eabi --release --features debug_ctap,with_ctap1,panic_console,debug_allocations,verbose - name: Check examples uses: actions-rs/cargo@v1 diff --git a/Cargo.toml b/Cargo.toml index 3155106e9d79fc478ea7c9669c79fefd6124b884..1d1ad6e18f6a1651f9c5a59a5d4d4f70640e6c5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,12 +18,13 @@ arrayref = "0.3.6" subtle = { version = "2.2", default-features = false, features = ["nightly"] } [features] -std = ["cbor/std", "crypto/std", "crypto/derive_debug"] +debug_allocations = ["libtock/debug_allocations"] debug_ctap = ["crypto/derive_debug"] -with_ctap1 = ["crypto/with_ctap1"] panic_console = ["libtock/panic_console"] -debug_allocations = ["libtock/debug_allocations"] +std = ["cbor/std", "crypto/std", "crypto/derive_debug"] ram_storage = [] +verbose = ["debug_ctap"] +with_ctap1 = ["crypto/with_ctap1"] [dev-dependencies] elf2tab = "0.4.0" diff --git a/deploy.py b/deploy.py index 486750d9ef574465622c4aff4dbd37b01cef4fc8..ddbd2e55cd0999324d591a7fcdb522e62169b966 100755 --- a/deploy.py +++ b/deploy.py @@ -705,6 +705,15 @@ if __name__ == "__main__": "output messages before starting blinking the LEDs on the " "board."), ) + main_parser.add_argument( + "--debug", + action="append_const", + const="debug_ctap", + dest="features", + help=("Compiles and installs the OpenSK application in debug mode " + "(i.e. more debug messages will be sent over the console port " + "such as hexdumps of packets)."), + ) main_parser.add_argument( "--debug-allocations", action="append_const", @@ -713,6 +722,14 @@ if __name__ == "__main__": help=("The console will be used to output allocator statistics every " "time an allocation/deallocation happens."), ) + main_parser.add_argument( + "--verbose", + action="append_const", + const="verbose", + dest="features", + help=("The console will be used to output verbose information about the " + "OpenSK application. This also automatically activates --debug."), + ) main_parser.add_argument( "--no-u2f", action=RemoveConstAction, @@ -731,15 +748,6 @@ if __name__ == "__main__": "This is useful to allow flashing multiple OpenSK authenticators " "in a row without them being considered clones."), ) - main_parser.add_argument( - "--debug", - action="append_const", - const="debug_ctap", - dest="features", - help=("Compiles and installs the OpenSK application in debug mode " - "(i.e. more debug messages will be sent over the console port " - "such as hexdumps of packets)."), - ) main_parser.add_argument( "--no-persistent-storage", action="append_const", diff --git a/run_desktop_tests.sh b/run_desktop_tests.sh index 864b8fecca526ddc56726348472de28b8876a347..e38735315eb892bf2b5e74b225afffa3400b055d 100755 --- a/run_desktop_tests.sh +++ b/run_desktop_tests.sh @@ -34,8 +34,9 @@ cargo check --release --target=thumbv7em-none-eabi --features debug_ctap cargo check --release --target=thumbv7em-none-eabi --features panic_console cargo check --release --target=thumbv7em-none-eabi --features debug_allocations cargo check --release --target=thumbv7em-none-eabi --features ram_storage +cargo check --release --target=thumbv7em-none-eabi --features verbose cargo check --release --target=thumbv7em-none-eabi --features debug_ctap,with_ctap1 -cargo check --release --target=thumbv7em-none-eabi --features debug_ctap,with_ctap1,panic_console,debug_allocations +cargo check --release --target=thumbv7em-none-eabi --features debug_ctap,with_ctap1,panic_console,debug_allocations,verbose echo "Checking that examples build properly..." cargo check --release --target=thumbv7em-none-eabi --examples diff --git a/src/usb_ctap_hid.rs b/src/usb_ctap_hid.rs index 421e70b08e13a5a7d8e61dbf4dbac535fbec6e25..7e63754e24df7be59b20a2c73f0ad623186f25d6 100644 --- a/src/usb_ctap_hid.rs +++ b/src/usb_ctap_hid.rs @@ -165,6 +165,57 @@ pub fn send_or_recv(buf: &mut [u8; 64]) -> SendOrRecvStatus { pub fn recv_with_timeout( buf: &mut [u8; 64], timeout_delay: Duration<isize>, +) -> Option<SendOrRecvStatus> { + #[cfg(feature = "verbose")] + writeln!( + Console::new(), + "Receiving packet with timeout of {}ms", + timeout_delay.ms(), + ) + .unwrap(); + + let result = recv_with_timeout_detail(buf, timeout_delay); + + #[cfg(feature = "verbose")] + { + if let Some(SendOrRecvStatus::Received) = result { + writeln!(Console::new(), "Received packet = {:02x?}", buf as &[u8]).unwrap(); + } + } + + result +} + +// Same as send_or_recv, but with a timeout. +// If the timeout elapses, return None. +pub fn send_or_recv_with_timeout( + buf: &mut [u8; 64], + timeout_delay: Duration<isize>, +) -> Option<SendOrRecvStatus> { + #[cfg(feature = "verbose")] + writeln!( + Console::new(), + "Sending packet with timeout of {}ms = {:02x?}", + timeout_delay.ms(), + buf as &[u8] + ) + .unwrap(); + + let result = send_or_recv_with_timeout_detail(buf, timeout_delay); + + #[cfg(feature = "verbose")] + { + if let Some(SendOrRecvStatus::Received) = result { + writeln!(Console::new(), "Received packet = {:02x?}", buf as &[u8]).unwrap(); + } + } + + result +} + +fn recv_with_timeout_detail( + buf: &mut [u8; 64], + timeout_delay: Duration<isize>, ) -> Option<SendOrRecvStatus> { let result = syscalls::allow(DRIVER_NUMBER, allow_nr::RECEIVE, buf); if result.is_err() { @@ -225,7 +276,7 @@ pub fn recv_with_timeout( // Cancel USB transaction if necessary. if status.get().is_none() { - #[cfg(feature = "debug_ctap")] + #[cfg(feature = "verbose")] writeln!(Console::new(), "Cancelling USB receive due to timeout").unwrap(); let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CANCEL, 0, 0) }; match result_code { @@ -249,9 +300,7 @@ pub fn recv_with_timeout( status.get() } -// Same as send_or_recv, but with a timeout. -// If the timeout elapses, return None. -pub fn send_or_recv_with_timeout( +fn send_or_recv_with_timeout_detail( buf: &mut [u8; 64], timeout_delay: Duration<isize>, ) -> Option<SendOrRecvStatus> { @@ -317,7 +366,7 @@ pub fn send_or_recv_with_timeout( // Cancel USB transaction if necessary. if status.get().is_none() { - #[cfg(feature = "debug_ctap")] + #[cfg(feature = "verbose")] writeln!(Console::new(), "Cancelling USB transaction due to timeout").unwrap(); let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CANCEL, 0, 0) }; match result_code {