picopass_i.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #pragma once
  2. #include "picopass.h"
  3. #include "picopass_device.h"
  4. #include "rfal_picopass.h"
  5. #include <furi.h>
  6. #include <gui/gui.h>
  7. #include <gui/view_dispatcher.h>
  8. #include <gui/scene_manager.h>
  9. #include <notification/notification_messages.h>
  10. #include <gui/modules/submenu.h>
  11. #include <gui/modules/popup.h>
  12. #include <gui/modules/loading.h>
  13. #include <gui/modules/text_input.h>
  14. #include <gui/modules/byte_input.h>
  15. #include <gui/modules/text_box.h>
  16. #include <gui/modules/widget.h>
  17. #include <input/input.h>
  18. #include "scenes/picopass_scene.h"
  19. #include "views/dict_attack.h"
  20. #include "views/loclass.h"
  21. #include <storage/storage.h>
  22. #include <lib/toolbox/path.h>
  23. #include <picopass_icons.h>
  24. #include <assets_icons.h>
  25. #include <nfc/nfc.h>
  26. #include <toolbox/keys_dict.h>
  27. #include "protocol/picopass_poller.h"
  28. #include "protocol/picopass_listener.h"
  29. #define PICOPASS_TEXT_STORE_SIZE 129
  30. #define PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME APP_ASSETS_PATH("iclass_elite_dict.txt")
  31. #define PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME APP_ASSETS_PATH("iclass_standard_dict.txt")
  32. #define PICOPASS_ICLASS_ELITE_DICT_USER_NAME APP_DATA_PATH("assets/iclass_elite_dict_user.txt")
  33. enum PicopassCustomEvent {
  34. // Reserve first 100 events for button types and indexes, starting from 0
  35. PicopassCustomEventReserved = 100,
  36. PicopassCustomEventViewExit,
  37. PicopassCustomEventWorkerExit,
  38. PicopassCustomEventByteInputDone,
  39. PicopassCustomEventTextInputDone,
  40. PicopassCustomEventDictAttackSkip,
  41. PicopassCustomEventDictAttackUpdateView,
  42. PicopassCustomEventLoclassGotMac,
  43. PicopassCustomEventLoclassGotStandardKey,
  44. PicopassCustomEventNrMacSaved,
  45. PicopassCustomEventPollerSuccess,
  46. PicopassCustomEventPollerFail,
  47. };
  48. typedef enum {
  49. EventTypeTick,
  50. EventTypeKey,
  51. } EventType;
  52. typedef struct {
  53. const char* name;
  54. uint16_t total_keys;
  55. uint16_t current_key;
  56. bool card_detected;
  57. } PicopassDictAttackContext;
  58. typedef struct {
  59. uint8_t key_to_write[PICOPASS_BLOCK_LEN];
  60. bool is_elite;
  61. } PicopassWriteKeyContext;
  62. typedef struct {
  63. size_t macs_collected;
  64. } PicopassLoclassContext;
  65. struct Picopass {
  66. ViewDispatcher* view_dispatcher;
  67. Gui* gui;
  68. NotificationApp* notifications;
  69. SceneManager* scene_manager;
  70. PicopassDevice* dev;
  71. Nfc* nfc;
  72. PicopassPoller* poller;
  73. PicopassListener* listener;
  74. KeysDict* dict;
  75. uint32_t last_error_notify_ticks;
  76. char text_store[PICOPASS_TEXT_STORE_SIZE];
  77. FuriString* text_box_store;
  78. uint8_t byte_input_store[PICOPASS_BLOCK_LEN];
  79. // Common Views
  80. Submenu* submenu;
  81. Popup* popup;
  82. Loading* loading;
  83. TextInput* text_input;
  84. ByteInput* byte_input;
  85. TextBox* text_box;
  86. Widget* widget;
  87. DictAttack* dict_attack;
  88. Loclass* loclass;
  89. PicopassDictAttackContext dict_attack_ctx;
  90. PicopassWriteKeyContext write_key_context;
  91. PicopassLoclassContext loclass_context;
  92. };
  93. typedef enum {
  94. PicopassViewMenu,
  95. PicopassViewPopup,
  96. PicopassViewLoading,
  97. PicopassViewTextInput,
  98. PicopassViewByteInput,
  99. PicopassViewTextBox,
  100. PicopassViewWidget,
  101. PicopassViewDictAttack,
  102. PicopassViewLoclass,
  103. } PicopassView;
  104. Picopass* picopass_alloc();
  105. void picopass_text_store_set(Picopass* picopass, const char* text, ...);
  106. void picopass_text_store_clear(Picopass* picopass);
  107. void picopass_blink_start(Picopass* picopass);
  108. void picopass_blink_emulate_start(Picopass* picopass);
  109. void picopass_blink_stop(Picopass* picopass);
  110. void picopass_show_loading_popup(void* context, bool show);
  111. /** Check if memory is set to pattern
  112. *
  113. * @warning zero size will return false
  114. *
  115. * @param[in] data Pointer to the byte array
  116. * @param[in] pattern The pattern
  117. * @param[in] size The byte array size
  118. *
  119. * @return True if memory is set to pattern, false otherwise
  120. */
  121. bool picopass_is_memset(const uint8_t* data, const uint8_t pattern, size_t size);