diff options
author | Vadim Sukhomlinov <sukhomlinov@google.com> | 2021-07-16 23:51:06 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-24 23:49:46 +0000 |
commit | 5ae1c684271a117539858cb12252959dfe46803c (patch) | |
tree | 6c792a27812fdc159723bda6b768b210b88b3f28 /board/cr50/power_button.c | |
parent | ea35354507745b5763bb85479a26409920ed37b0 (diff) | |
download | chrome-ec-5ae1c684271a117539858cb12252959dfe46803c.tar.gz |
u2f: refactoring to split command processing and crypto
Split U2F crypto from U2F command processing by moving all crypto
code into boards/cr50 (platform hooks).
U2F state management is part of common code and passed to U2F crypto
as a parameter.
BUG=b:134594373
TEST=make BOARD=cr50 CRYPTO_TEST=1
console: u2f_test
test/tpmtest.py
FAFT U2F tests pass
Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com>
Change-Id: I85442cddb2959bd3102f7f6e6047134ede90951b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3034852
Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Diffstat (limited to 'board/cr50/power_button.c')
-rw-r--r-- | board/cr50/power_button.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/board/cr50/power_button.c b/board/cr50/power_button.c index 2d22966273..a13f450031 100644 --- a/board/cr50/power_button.c +++ b/board/cr50/power_button.c @@ -15,7 +15,6 @@ #include "system_chip.h" #include "task.h" #include "timer.h" -#include "u2f_impl.h" #define CPRINTS(format, args...) cprints(CC_RBOX, format, ## args) #define CPRINTF(format, args...) cprintf(CC_RBOX, format, ## args) @@ -308,6 +307,43 @@ static void power_button_init(void) DECLARE_HOOK(HOOK_INIT, power_button_init, HOOK_PRIO_DEFAULT); #endif /* CONFIG_U2F */ +/* ---- physical presence (using the laptop power button) ---- */ + +static timestamp_t last_press; + +/* how long do we keep the last button press as valid presence */ +#define PRESENCE_TIMEOUT (10 * SECOND) + +void power_button_record(void) +{ + if (ap_is_on() && rbox_powerbtn_is_pressed()) { + last_press = get_time(); +#ifdef CR50_DEV + CPRINTS("record pp"); +#endif + } +} + +enum touch_state pop_check_presence(int consume) +{ +#ifdef CRYPTO_TEST_SETUP + return POP_TOUCH_YES; +#else + int recent = ((last_press.val > 0) && + ((get_time().val - last_press.val) < PRESENCE_TIMEOUT)); + +#ifdef CR50_DEV + if (recent) + CPRINTS("User presence: consumed %d", consume); +#endif + if (consume) + last_press.val = 0; + + /* user physical presence on the power button */ + return recent ? POP_TOUCH_YES : POP_TOUCH_NO; +#endif +} + void board_physical_presence_enable(int enable) { #ifndef CONFIG_U2F |