Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenSK
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
koenigl2
OpenSK
Commits
111cf6f9
Commit
111cf6f9
authored
4 years ago
by
tamaf96
Browse files
Options
Downloads
Patches
Plain Diff
match TockError enum to CommandError to access result_code
parent
f1932980
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main.rs
+7
-4
7 additions, 4 deletions
src/main.rs
src/usb_ctap_hid.rs
+71
-58
71 additions, 58 deletions
src/usb_ctap_hid.rs
with
78 additions
and
62 deletions
src/main.rs
+
7
−
4
View file @
111cf6f9
...
...
@@ -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"
),
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/usb_ctap_hid.rs
+
71
−
58
View file @
111cf6f9
...
...
@@ -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!
(
"Un
expected error when stopping alarm: {:?}"
,
command_err
.return_code
),
_
=>
panic!
(
"Un
reachable"
),
}
}
}
...
...
@@ -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!
(
"Un
expected error when stopping alarm: {:?}"
,
err
.return_code
),
_
=>
panic!
(
"Un
reachable"
),
}
},
}
...
...
@@ -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
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment