seader_i.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #pragma once
  2. #include <stdlib.h> // malloc
  3. #include <stdint.h> // uint32_t
  4. #include <stdarg.h> // __VA_ARGS__
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <furi.h>
  8. #include <furi_hal.h>
  9. #include <gui/gui.h>
  10. #include <gui/view_dispatcher.h>
  11. #include <gui/scene_manager.h>
  12. #include <notification/notification_messages.h>
  13. #include <seader_icons.h>
  14. #include <gui/modules/submenu.h>
  15. #include <gui/modules/popup.h>
  16. #include <gui/modules/loading.h>
  17. #include <gui/modules/text_input.h>
  18. #include <gui/modules/text_box.h>
  19. #include <gui/modules/widget.h>
  20. #include <input/input.h>
  21. #include <lib/nfc/nfc.h>
  22. #include <nfc/nfc_poller.h>
  23. #include <nfc/nfc_device.h>
  24. #include <nfc/helpers/nfc_data_generator.h>
  25. // ASN1
  26. #include <asn_system.h>
  27. #include <asn_internal.h>
  28. #include <asn_codecs_prim.h>
  29. #include <asn_codecs.h>
  30. #include <asn_application.h>
  31. #include <Payload.h>
  32. #include <FrameProtocol.h>
  33. #include "plugin/interface.h"
  34. #include <flipper_application/flipper_application.h>
  35. #include <flipper_application/plugins/plugin_manager.h>
  36. #include <loader/firmware_api/firmware_api.h>
  37. #include "protocol/picopass_poller.h"
  38. #include "scenes/seader_scene.h"
  39. #include "seader_bridge.h"
  40. #include "seader.h"
  41. #include "ccid.h"
  42. #include "uart.h"
  43. #include "lrc.h"
  44. #include "t_1.h"
  45. #include "seader_worker.h"
  46. #include "seader_credential.h"
  47. #include "apdu_log.h"
  48. #define WORKER_ALL_RX_EVENTS \
  49. (WorkerEvtStop | WorkerEvtRxDone | WorkerEvtCfgChange | WorkerEvtLineCfgSet | \
  50. WorkerEvtCtrlLineSet | WorkerEvtSamTxComplete)
  51. #define WORKER_ALL_TX_EVENTS (WorkerEvtTxStop | WorkerEvtSamRx)
  52. #define SEADER_TEXT_STORE_SIZE 128
  53. enum SeaderCustomEvent {
  54. // Reserve first 100 events for button types and indexes, starting from 0
  55. SeaderCustomEventReserved = 100,
  56. SeaderCustomEventViewExit,
  57. SeaderCustomEventWorkerExit,
  58. SeaderCustomEventByteInputDone,
  59. SeaderCustomEventTextInputDone,
  60. SeaderCustomEventPollerDetect,
  61. SeaderCustomEventPollerSuccess,
  62. };
  63. typedef enum {
  64. WorkerEvtStop = (1 << 0),
  65. WorkerEvtRxDone = (1 << 1),
  66. WorkerEvtTxStop = (1 << 2),
  67. WorkerEvtSamRx = (1 << 3),
  68. WorkerEvtSamTxComplete = (1 << 4),
  69. WorkerEvtCfgChange = (1 << 5),
  70. WorkerEvtLineCfgSet = (1 << 6),
  71. WorkerEvtCtrlLineSet = (1 << 7),
  72. } WorkerEvtFlags;
  73. typedef struct {
  74. uint16_t total_lines;
  75. uint16_t current_line;
  76. } SeaderAPDURunnerContext;
  77. struct Seader {
  78. bool revert_power;
  79. bool is_debug_enabled;
  80. SeaderWorker* worker;
  81. ViewDispatcher* view_dispatcher;
  82. Gui* gui;
  83. NotificationApp* notifications;
  84. SceneManager* scene_manager;
  85. SeaderUartBridge* uart;
  86. SeaderCredential* credential;
  87. SamCommand_PR samCommand;
  88. char text_store[SEADER_TEXT_STORE_SIZE + 1];
  89. FuriString* text_box_store;
  90. // Common Views
  91. Submenu* submenu;
  92. Popup* popup;
  93. Loading* loading;
  94. TextInput* text_input;
  95. TextBox* text_box;
  96. Widget* widget;
  97. Nfc* nfc;
  98. NfcPoller* poller;
  99. PicopassPoller* picopass_poller;
  100. NfcDevice* nfc_device;
  101. PluginManager* plugin_manager;
  102. PluginWiegand* plugin_wiegand;
  103. APDULog* apdu_log;
  104. SeaderAPDURunnerContext apdu_runner_ctx;
  105. };
  106. struct SeaderPollerContainer {
  107. Iso14443_4aPoller* iso14443_4a_poller;
  108. MfClassicPoller* mfc_poller;
  109. PicopassPoller* picopass_poller;
  110. };
  111. typedef enum {
  112. SeaderViewMenu,
  113. SeaderViewPopup,
  114. SeaderViewLoading,
  115. SeaderViewTextInput,
  116. SeaderViewTextBox,
  117. SeaderViewWidget,
  118. SeaderViewUart,
  119. } SeaderView;
  120. void seader_text_store_set(Seader* seader, const char* text, ...);
  121. void seader_text_store_clear(Seader* seader);
  122. void seader_blink_start(Seader* seader);
  123. void seader_blink_stop(Seader* seader);
  124. void seader_show_loading_popup(void* context, bool show);