Skip to content
Snippets Groups Projects
Commit 111cf6f9 authored by tamaf96's avatar tamaf96
Browse files

match TockError enum to CommandError to access result_code

parent f1932980
Branches
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ use libtock::buttons::ButtonState;
#[cfg(feature = "debug_ctap")]
use libtock::console::Console;
use libtock::leds::LedsDriver;
use libtock::result::TockResult;
use libtock::result::{TockResult, TockError};
use libtock::timer;
#[cfg(feature = "debug_ctap")]
use libtock::timer::Timer;
......@@ -373,9 +373,12 @@ fn check_user_presence(cid: ChannelID) -> Result<(), Ctap2StatusCode> {
match keepalive.stop_alarm(keepalive_alarm) {
Ok(()) => (),
Err(err) => {
match err.return_code {
EALREADY => assert!(keepalive_expired.get()),
_ => panic!("Unexpected error when stopping alarm: {:?}", err.return_code),
match err {
TockError::Command(command_err) => match command_err.return_code {
EALREADY => assert!(keepalive_expired.get()),
_ => panic!("Unexpected error when stopping alarm: {:?}", command_err.return_code),
},
_ => panic!("Unreachable"),
}
}
}
......
......@@ -17,7 +17,7 @@ use core::cell::Cell;
use core::fmt::Write;
#[cfg(feature = "debug_ctap")]
use libtock::console::Console;
use libtock::result::{EALREADY, EBUSY, SUCCESS, TockResult};
use libtock::result::{EALREADY, EBUSY, TockResult, TockError};
use libtock::syscalls;
use libtock::timer::{Duration};
......@@ -281,19 +281,22 @@ fn recv_with_timeout_detail(
// Cleanup alarm callback.
match timeout.stop_alarm(timeout_alarm) {
Ok(()) => (),
Err(command_err) => {
match command_err.return_code {
EALREADY => {
if !timeout_expired.get() {
#[cfg(feature = "debug_ctap")]
writeln!(
Console::new(),
"The receive timeout already expired, but the callback wasn't executed."
)
.unwrap();
}
Err(err) => {
match err {
TockError::Command(command_err) => match command_err.return_code {
EALREADY => {
if !timeout_expired.get() {
#[cfg(feature = "debug_ctap")]
writeln!(
Console::new(),
"The receive timeout already expired, but the callback wasn't executed."
)
.unwrap();
}
},
_ => panic!("Unexpected error when stopping alarm: {:?}", command_err.return_code),
},
_ => panic!("Unexpected error when stopping alarm: {:?}", command_err.return_code),
_ => panic!("Unreachable"),
}
}
}
......@@ -302,23 +305,26 @@ fn recv_with_timeout_detail(
if status.get().is_none() {
#[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 {
// - SUCCESS means that we successfully cancelled the transaction.
// - EALREADY means that the transaction was already completed.
SUCCESS | EALREADY => (),
// - EBUSY means that the transaction is in progress.
EBUSY => {
// The app should wait for it, but it may never happen if the remote app crashes.
// We just return to avoid a deadlock.
#[cfg(feature = "debug_ctap")]
writeln!(Console::new(), "Couldn't cancel the USB receive").unwrap();
}
_ => panic!(
"Unexpected error when cancelling USB receive: {:?}",
result_code
),
}
let result = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CANCEL, 0, 0) };
match result {
// - Ok = SUCCESS means that we successfully cancelled the transaction.
Ok(x) => (),
Err(err) => match err.return_code {
// - EALREADY means that the transaction was already completed.
EALREADY => (),
// - EBUSY means that the transaction is in progress.
EBUSY => {
// The app should wait for it, but it may never happen if the remote app crashes.
// We just return to avoid a deadlock.
#[cfg(feature = "debug_ctap")]
writeln!(Console::new(), "Couldn't cancel the USB receive").unwrap();
}
_ => panic!(
"Unexpected error when cancelling USB receive: {:?}",
result_code
),
},
};
}
status.get()
......@@ -386,18 +392,21 @@ fn send_or_recv_with_timeout_detail(
match timeout.stop_alarm(timeout_alarm) {
Ok(()) => (),
Err(err) => {
match err.return_code {
EALREADY => {
if !timeout_expired.get() {
#[cfg(feature = "debug_ctap")]
writeln!(
Console::new(),
"The send/receive timeout already expired, but the callback wasn't executed."
)
.unwrap();
}
match err {
TockError::Command(command_err) => match command_err.return_code {
EALREADY => {
if !timeout_expired.get() {
#[cfg(feature = "debug_ctap")]
writeln!(
Console::new(),
"The send/receive timeout already expired, but the callback wasn't executed."
)
.unwrap();
}
},
_ => panic!("Unexpected error when stopping alarm: {:?}", command_err.return_code),
},
_ => panic!("Unexpected error when stopping alarm: {:?}", err.return_code),
_ => panic!("Unreachable"),
}
},
}
......@@ -406,23 +415,27 @@ fn send_or_recv_with_timeout_detail(
if status.get().is_none() {
#[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 {
// - SUCCESS means that we successfully cancelled the transaction.
// - EALREADY means that the transaction was already completed.
SUCCESS | EALREADY => (),
// - EBUSY means that the transaction is in progress.
EBUSY => {
// The app should wait for it, but it may never happen if the remote app crashes.
// We just return to avoid a deadlock.
#[cfg(feature = "debug_ctap")]
writeln!(Console::new(), "Couldn't cancel the transaction").unwrap();
}
_ => panic!(
"Unexpected error when cancelling USB transaction: {:?}",
result_code
),
}
let result = unsafe { syscalls::command(DRIVER_NUMBER, command_nr::CANCEL, 0, 0) };
match result {
// - Ok = SUCCESS means that we successfully cancelled the transaction.
Ok(x) => (),
Err(err) => match err.return_code {
// - EALREADY means that the transaction was already completed.
EALREADY => (),
// - EBUSY means that the transaction is in progress.
EBUSY => {
// The app should wait for it, but it may never happen if the remote app crashes.
// We just return to avoid a deadlock.
#[cfg(feature = "debug_ctap")]
writeln!(Console::new(), "Couldn't cancel the transaction").unwrap();
}
_ => panic!(
"Unexpected error when cancelling USB transaction: {:?}",
result_code
),
},
};
#[cfg(feature = "debug_ctap")]
writeln!(Console::new(), "Cancelled USB transaction!").unwrap();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment