picopass_i.h 3.8 KB

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