Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement and fixes of "Secure" feature #16958

Merged
merged 21 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions quantum/process_keycode/process_secure.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

bool preprocess_secure(uint16_t keycode, keyrecord_t *record) {
if (secure_is_unlocking()) {
if (!record->event.pressed) {
// !pressed will trigger on any already held keys (such as layer keys),
// and cause the request secure check to prematurely fail.
if (record->event.pressed) {
secure_keypress_event(record->event.key.row, record->event.key.col);
}

Expand Down Expand Up @@ -36,4 +38,4 @@ bool process_secure(uint16_t keycode, keyrecord_t *record) {
}
#endif
return true;
}
}
13 changes: 13 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,16 @@ const char *get_u16_str(uint16_t curr_num, char curr_pad) {
last_pad = curr_pad;
return get_numeric_str(buf, sizeof(buf), curr_num, curr_pad);
}

#if defined(SECURE_ENABLE)
__attribute__((weak)) bool secure_hook_user(secure_status_t secure_status) {
return true;
}
__attribute__((weak)) bool secure_hook_kb(secure_status_t secure_status) {
return secure_hook_user(secure_status);
}

void secure_hook_quantum(secure_status_t secure_status) {
secure_hook_kb(secure_status);
}
#endif
9 changes: 9 additions & 0 deletions quantum/secure.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "secure.h"
#include "timer.h"
#include "action_layer.h"

#ifndef SECURE_UNLOCK_TIMEOUT
# define SECURE_UNLOCK_TIMEOUT 5000
Expand All @@ -29,18 +30,26 @@ secure_status_t secure_get_status(void) {

void secure_lock(void) {
secure_status = SECURE_LOCKED;
secure_hook_quantum(secure_status);
}

void secure_unlock(void) {
secure_status = SECURE_UNLOCKED;
idle_time = timer_read32();
secure_hook_quantum(secure_status);
}

void secure_request_unlock(void) {
if (secure_status == SECURE_LOCKED) {
secure_status = SECURE_PENDING;
unlock_time = timer_read32();
// If keys are being held when this is triggered, they may not be released properly
// this can result in stuck keys, mods and layers. To prevent that, manually
// clear these, when it is triggered.
clear_keyboard();
layer_clear();
}
secure_hook_quantum(secure_status);
}

void secure_activity_event(void) {
Expand Down
12 changes: 12 additions & 0 deletions quantum/secure.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ void secure_keypress_event(uint8_t row, uint8_t col);
/** \brief Handle various secure subsystem background tasks
*/
void secure_task(void);

/** \brief quantum hook called when changing secure status device
*/
void secure_hook_quantum(secure_status_t secure_status);
drashna marked this conversation as resolved.
Show resolved Hide resolved

/** \brief user hook called when changing secure status device
*/
bool secure_hook_user(secure_status_t secure_status);

/** \brief keyboard hook called when changing secure status device
*/
bool secure_hook_kb(secure_status_t secure_status);