summaryrefslogtreecommitdiff
path: root/quantum/secure.h
blob: ae9b5b9045213c99853d6392c4d8c3dac77ac13e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2022 QMK
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

/**
 * \file
 *
 * \defgroup secure Secure API
 *
 * \brief Exposes a set of functionality to act as a virtual padlock for your device
 * ...as long as that padlock is made of paper and it's currently raining.
 *
 * \{
 */

#include <stdint.h>
#include <stdbool.h>

/** \brief Available secure states
 */
typedef enum {
    SECURE_LOCKED,
    SECURE_PENDING,
    SECURE_UNLOCKED,
} secure_status_t;

/** \brief Query current secure state
 */
secure_status_t secure_get_status(void);

/** \brief Helper to check if unlocking is currently locked
 */
#define secure_is_locked() (secure_get_status() == SECURE_LOCKED)

/** \brief Helper to check if unlocking is currently in progress
 */
#define secure_is_unlocking() (secure_get_status() == SECURE_PENDING)

/** \brief Helper to check if unlocking is currently unlocked
 */
#define secure_is_unlocked() (secure_get_status() == SECURE_UNLOCKED)

/** \brief Lock down the device
 */
void secure_lock(void);

/** \brief Force unlock the device
 *
 * \warning bypasses user unlock sequence
 */
void secure_unlock(void);

/** \brief Begin listening for an unlock sequence
 */
void secure_request_unlock(void);

/** \brief Flag to the secure subsystem that user activity has happened
 *
 * Call when some user activity has happened and the device should remain unlocked
 */
void secure_activity_event(void);

/** \brief Flag to the secure subsystem that user has triggered a keypress
 *
 * Call to trigger processing of the unlock sequence
 */
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);

/** \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);

/** \} */