Skip to content
Snippets Groups Projects
Unverified Commit 284b1426 authored by gendx's avatar gendx Committed by GitHub
Browse files

Merge pull request #83 from gendx/verbose-feature

Add a --verbose parameter to print all USB packets at the OpenSK level.
parents 57e79c18 93d8df29
No related branches found
No related tags found
No related merge requests found
...@@ -64,17 +64,23 @@ jobs: ...@@ -64,17 +64,23 @@ jobs:
command: check command: check
args: --target thumbv7em-none-eabi --release --features ram_storage 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 - name: Check OpenSK debug_ctap,with_ctap1
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: check command: check
args: --target thumbv7em-none-eabi --release --features debug_ctap,with_ctap1 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 uses: actions-rs/cargo@v1
with: with:
command: check 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 - name: Check examples
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
......
...@@ -18,12 +18,13 @@ arrayref = "0.3.6" ...@@ -18,12 +18,13 @@ arrayref = "0.3.6"
subtle = { version = "2.2", default-features = false, features = ["nightly"] } subtle = { version = "2.2", default-features = false, features = ["nightly"] }
[features] [features]
std = ["cbor/std", "crypto/std", "crypto/derive_debug"] debug_allocations = ["libtock/debug_allocations"]
debug_ctap = ["crypto/derive_debug"] debug_ctap = ["crypto/derive_debug"]
with_ctap1 = ["crypto/with_ctap1"]
panic_console = ["libtock/panic_console"] panic_console = ["libtock/panic_console"]
debug_allocations = ["libtock/debug_allocations"] std = ["cbor/std", "crypto/std", "crypto/derive_debug"]
ram_storage = [] ram_storage = []
verbose = ["debug_ctap"]
with_ctap1 = ["crypto/with_ctap1"]
[dev-dependencies] [dev-dependencies]
elf2tab = "0.4.0" elf2tab = "0.4.0"
......
...@@ -705,6 +705,15 @@ if __name__ == "__main__": ...@@ -705,6 +705,15 @@ if __name__ == "__main__":
"output messages before starting blinking the LEDs on the " "output messages before starting blinking the LEDs on the "
"board."), "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( main_parser.add_argument(
"--debug-allocations", "--debug-allocations",
action="append_const", action="append_const",
...@@ -713,6 +722,14 @@ if __name__ == "__main__": ...@@ -713,6 +722,14 @@ if __name__ == "__main__":
help=("The console will be used to output allocator statistics every " help=("The console will be used to output allocator statistics every "
"time an allocation/deallocation happens."), "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( main_parser.add_argument(
"--no-u2f", "--no-u2f",
action=RemoveConstAction, action=RemoveConstAction,
...@@ -731,15 +748,6 @@ if __name__ == "__main__": ...@@ -731,15 +748,6 @@ if __name__ == "__main__":
"This is useful to allow flashing multiple OpenSK authenticators " "This is useful to allow flashing multiple OpenSK authenticators "
"in a row without them being considered clones."), "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( main_parser.add_argument(
"--no-persistent-storage", "--no-persistent-storage",
action="append_const", action="append_const",
......
...@@ -34,8 +34,9 @@ cargo check --release --target=thumbv7em-none-eabi --features debug_ctap ...@@ -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 panic_console
cargo check --release --target=thumbv7em-none-eabi --features debug_allocations 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 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
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..." echo "Checking that examples build properly..."
cargo check --release --target=thumbv7em-none-eabi --examples cargo check --release --target=thumbv7em-none-eabi --examples
......
...@@ -165,6 +165,57 @@ pub fn send_or_recv(buf: &mut [u8; 64]) -> SendOrRecvStatus { ...@@ -165,6 +165,57 @@ pub fn send_or_recv(buf: &mut [u8; 64]) -> SendOrRecvStatus {
pub fn recv_with_timeout( pub fn recv_with_timeout(
buf: &mut [u8; 64], buf: &mut [u8; 64],
timeout_delay: Duration<isize>, 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> { ) -> Option<SendOrRecvStatus> {
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::RECEIVE, buf); let result = syscalls::allow(DRIVER_NUMBER, allow_nr::RECEIVE, buf);
if result.is_err() { if result.is_err() {
...@@ -225,7 +276,7 @@ pub fn recv_with_timeout( ...@@ -225,7 +276,7 @@ pub fn recv_with_timeout(
// Cancel USB transaction if necessary. // Cancel USB transaction if necessary.
if status.get().is_none() { if status.get().is_none() {
#[cfg(feature = "debug_ctap")] #[cfg(feature = "verbose")]
writeln!(Console::new(), "Cancelling USB receive due to timeout").unwrap(); writeln!(Console::new(), "Cancelling USB receive due to timeout").unwrap();
let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CANCEL, 0, 0) }; let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CANCEL, 0, 0) };
match result_code { match result_code {
...@@ -249,9 +300,7 @@ pub fn recv_with_timeout( ...@@ -249,9 +300,7 @@ pub fn recv_with_timeout(
status.get() status.get()
} }
// Same as send_or_recv, but with a timeout. fn send_or_recv_with_timeout_detail(
// If the timeout elapses, return None.
pub fn send_or_recv_with_timeout(
buf: &mut [u8; 64], buf: &mut [u8; 64],
timeout_delay: Duration<isize>, timeout_delay: Duration<isize>,
) -> Option<SendOrRecvStatus> { ) -> Option<SendOrRecvStatus> {
...@@ -317,7 +366,7 @@ pub fn send_or_recv_with_timeout( ...@@ -317,7 +366,7 @@ pub fn send_or_recv_with_timeout(
// Cancel USB transaction if necessary. // Cancel USB transaction if necessary.
if status.get().is_none() { if status.get().is_none() {
#[cfg(feature = "debug_ctap")] #[cfg(feature = "verbose")]
writeln!(Console::new(), "Cancelling USB transaction due to timeout").unwrap(); writeln!(Console::new(), "Cancelling USB transaction due to timeout").unwrap();
let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CANCEL, 0, 0) }; let result_code = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CANCEL, 0, 0) };
match result_code { match result_code {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment