Skip to content

Commit

Permalink
nk3am: Remove blocking UP check
Browse files Browse the repository at this point in the history
Since this commit [0] that changed the threshold from 3 to 1, the
blocking loop in the user presence check for the NK3AM does no longer
have any functional effect.  But it has undesired side effects, for
example skipping the UI update for a second so that the blinking effect
is not triggered, and delaying the handling of cancelled requests.

This patch removes the unnecessary blocking loop.  The button
implementation still requires 100 ticks to trigger a button press.

Fixes: #93

[0] 35dac8d
  • Loading branch information
robin-nitrokey committed Mar 5, 2024
1 parent b95e8d9 commit 95fedf7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
- fido-authenticator: Implement the largeBlobKey extension and the largeBlobs command ([fido-authenticator#38][])
- Report errors when loading the configuration during initialization and disable opcard if an error occured ([#394][])
- piv: Fix crash when changing PUK ([piv-authenticator#38][])
- Fix LED during user presence check for NK3AM ([#93][])

[#93]: https://github.com/Nitrokey/nitrokey-3-firmware/issues/93
[#394]: https://github.com/Nitrokey/nitrokey-3-firmware/pull/394
[fido-authenticator#38]: https://github.com/Nitrokey/fido-authenticator/issues/38
[piv-authenticator#38]: https://github.com/Nitrokey/piv-authenticator/issues/38
Expand Down
40 changes: 1 addition & 39 deletions components/boards/src/nk3am/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,7 @@ impl HardwareButtons {

impl UserPresence for HardwareButtons {
fn check_user_presence(&mut self, clock: &mut dyn Clock) -> consent::Level {
// essentially a blocking call for up to ~30secs
// this outer loop accumulates *presses* from the
// inner loop & maintains (loading) delays.

let mut counter: u8 = 0;
let threshold: u8 = 1;

let start_time = clock.uptime();
let timeout_at = start_time + Duration::from_millis(1_000);
let mut next_check = start_time + Duration::from_millis(25);

loop {
let cur_time = clock.uptime();

// timeout reached
if cur_time > timeout_at {
break;
}
// loop until next check shall be done
if cur_time < next_check {
continue;
}

if self.is_pressed(Button::A) {
counter += 1;
// with press -> delay 25ms
next_check = cur_time + Duration::from_millis(25);
} else {
// w/o press -> delay 100ms
next_check = cur_time + Duration::from_millis(100);
}

if counter >= threshold {
break;
}
}

// consent, if we've counted 3 "presses"
if counter >= threshold {
if self.is_pressed(Button::A) {
consent::Level::Normal
} else {
consent::Level::None
Expand Down

0 comments on commit 95fedf7

Please sign in to comment.