You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.0 KiB

  1. // Copyright 2022 QMK
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. /**
  5. * \file
  6. *
  7. * \defgroup secure Secure API
  8. *
  9. * \brief Exposes a set of functionality to act as a virtual padlock for your device
  10. * ...as long as that padlock is made of paper and it's currently raining.
  11. *
  12. * \{
  13. */
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. /** \brief Available secure states
  17. */
  18. typedef enum {
  19. SECURE_LOCKED,
  20. SECURE_PENDING,
  21. SECURE_UNLOCKED,
  22. } secure_status_t;
  23. /** \brief Query current secure state
  24. */
  25. secure_status_t secure_get_status(void);
  26. /** \brief Helper to check if unlocking is currently locked
  27. */
  28. #define secure_is_locked() (secure_get_status() == SECURE_LOCKED)
  29. /** \brief Helper to check if unlocking is currently in progress
  30. */
  31. #define secure_is_unlocking() (secure_get_status() == SECURE_PENDING)
  32. /** \brief Helper to check if unlocking is currently unlocked
  33. */
  34. #define secure_is_unlocked() (secure_get_status() == SECURE_UNLOCKED)
  35. /** \brief Lock down the device
  36. */
  37. void secure_lock(void);
  38. /** \brief Force unlock the device
  39. *
  40. * \warning bypasses user unlock sequence
  41. */
  42. void secure_unlock(void);
  43. /** \brief Begin listening for an unlock sequence
  44. */
  45. void secure_request_unlock(void);
  46. /** \brief Flag to the secure subsystem that user activity has happened
  47. *
  48. * Call when some user activity has happened and the device should remain unlocked
  49. */
  50. void secure_activity_event(void);
  51. /** \brief Flag to the secure subsystem that user has triggered a keypress
  52. *
  53. * Call to trigger processing of the unlock sequence
  54. */
  55. void secure_keypress_event(uint8_t row, uint8_t col);
  56. /** \brief Handle various secure subsystem background tasks
  57. */
  58. void secure_task(void);
  59. /** \brief quantum hook called when changing secure status device
  60. */
  61. void secure_hook_quantum(secure_status_t secure_status);
  62. /** \brief user hook called when changing secure status device
  63. */
  64. bool secure_hook_user(secure_status_t secure_status);
  65. /** \brief keyboard hook called when changing secure status device
  66. */
  67. bool secure_hook_kb(secure_status_t secure_status);
  68. /** \} */