summaryrefslogtreecommitdiff
path: root/board/cr50/power_button.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/cr50/power_button.c')
-rw-r--r--board/cr50/power_button.c38
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