fsm.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Motenpoche
  2. *
  3. * (c) 2023 Daniele Lacamera <root@danielinux.net>
  4. *
  5. *
  6. * Motenpoche is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Motenpoche is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  19. *
  20. */
  21. #include <stdint.h>
  22. #include "ui.h"
  23. #include "display.h"
  24. #include "bsp/board.h"
  25. #include "fsm.h"
  26. #include "ui.h"
  27. #include "cryptoengine.h"
  28. static enum vault_state vault_state = VAULT_OFF;
  29. static volatile int ui_event_pending = 0;
  30. static enum vault_state old_st = 0;
  31. void fsm_event_task(void)
  32. {
  33. /* UI trigger */
  34. if (ui_event_pending) {
  35. ui_event_pending = 0;
  36. ui_event_cb(old_st, fsm_get());
  37. }
  38. }
  39. /* state transactions: actions */
  40. void fsm_set(enum vault_state st)
  41. {
  42. old_st = vault_state;
  43. if (st == vault_state)
  44. return;
  45. /* Change state */
  46. vault_state = st;
  47. ui_event_cb(old_st, vault_state);
  48. if ((vault_state == VAULT_SETTINGS_MENU) &&
  49. (old_st == VAULT_VERIFY_PASSPHRASE)){
  50. /* Just logged in! */
  51. disk_crypto_activate(1);
  52. }
  53. }
  54. enum vault_state fsm_get(void)
  55. {
  56. return vault_state;
  57. }