From 92a61aa0cd9a28056e6979f01a72b8742702dbfe Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sat, 16 Apr 2022 19:13:05 +0100 Subject: Implement XAP 'secure' core requirements (#16843) Co-authored-by: Drashna Jaelre Co-authored-by: Stefan Kerkmann --- quantum/process_keycode/process_secure.c | 39 ++++++++++++++++++++++++++++++++ quantum/process_keycode/process_secure.h | 15 ++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 quantum/process_keycode/process_secure.c create mode 100644 quantum/process_keycode/process_secure.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_secure.c b/quantum/process_keycode/process_secure.c new file mode 100644 index 0000000000..827ace597a --- /dev/null +++ b/quantum/process_keycode/process_secure.c @@ -0,0 +1,39 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "secure.h" +#include "process_secure.h" +#include "quantum_keycodes.h" + +bool preprocess_secure(uint16_t keycode, keyrecord_t *record) { + if (secure_is_unlocking()) { + if (!record->event.pressed) { + secure_keypress_event(record->event.key.row, record->event.key.col); + } + + // Normal keypresses should be disabled until the sequence is completed + return false; + } + + return true; +} + +bool process_secure(uint16_t keycode, keyrecord_t *record) { +#ifndef SECURE_DISABLE_KEYCODES + if (!record->event.pressed) { + if (keycode == SECURE_LOCK) { + secure_lock(); + return false; + } + if (keycode == SECURE_UNLOCK) { + secure_unlock(); + return false; + } + if (keycode == SECURE_TOGGLE) { + secure_is_locked() ? secure_unlock() : secure_lock(); + return false; + } + } +#endif + return true; +} \ No newline at end of file diff --git a/quantum/process_keycode/process_secure.h b/quantum/process_keycode/process_secure.h new file mode 100644 index 0000000000..2814264b92 --- /dev/null +++ b/quantum/process_keycode/process_secure.h @@ -0,0 +1,15 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include "action.h" + +/** \brief Intercept keycodes and detect unlock sequences + */ +bool preprocess_secure(uint16_t keycode, keyrecord_t *record); + +/** \brief Handle any secure specific keycodes + */ +bool process_secure(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3