picopass_i.h 3.7 KB

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