metroflip_i.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #pragma once
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. #include <stdlib.h>
  5. #include <gui/gui.h>
  6. #include <gui/view.h>
  7. #include <gui/modules/validators.h>
  8. #include <gui/view_dispatcher.h>
  9. #include <gui/scene_manager.h>
  10. #include "api/nfc/mf_classic_key_cache.h"
  11. #if __has_include(<assets_icons.h>)
  12. #include <assets_icons.h>
  13. #else
  14. extern const Icon I_RFIDDolphinReceive_97x61;
  15. #endif
  16. #include <flipper_application/plugins/composite_resolver.h>
  17. #include <loader/firmware_api/firmware_api.h>
  18. #include <flipper_application/plugins/plugin_manager.h>
  19. #include <loader/firmware_api/firmware_api.h>
  20. #include <flipper_application/flipper_application.h>
  21. #include <gui/modules/submenu.h>
  22. #include <gui/modules/popup.h>
  23. #include <gui/modules/loading.h>
  24. #include <gui/modules/text_input.h>
  25. #include <gui/modules/text_box.h>
  26. #include <gui/modules/widget.h>
  27. #include <gui/modules/byte_input.h>
  28. #include <gui/modules/popup.h>
  29. #include "scenes/metroflip_scene.h"
  30. #include <lib/flipper_format/flipper_format.h>
  31. #include <toolbox/name_generator.h>
  32. #include <lib/nfc/protocols/mf_ultralight/mf_ultralight.h>
  33. #include <lib/nfc/helpers/nfc_data_generator.h>
  34. #include <furi_hal_bt.h>
  35. #include <notification/notification_messages.h>
  36. #include "scenes/desfire.h"
  37. #include "scenes/nfc_detected_protocols.h"
  38. #include "scenes/keys.h"
  39. #include <lib/nfc/nfc.h>
  40. #include <nfc/nfc_poller.h>
  41. #include <nfc/nfc_scanner.h>
  42. #include <datetime.h>
  43. #include <dolphin/dolphin.h>
  44. #include <locale/locale.h>
  45. #include <stdio.h>
  46. #include <strings.h>
  47. #include <flipper_application/flipper_application.h>
  48. #include <loader/firmware_api/firmware_api.h>
  49. #include "scenes/metroflip_scene.h"
  50. #include "api/calypso/calypso_i.h"
  51. #define KEY_MASK_BIT_CHECK(key_mask_1, key_mask_2) (((key_mask_1) & (key_mask_2)) == (key_mask_1))
  52. typedef struct {
  53. Gui* gui;
  54. SceneManager* scene_manager;
  55. ViewDispatcher* view_dispatcher;
  56. NotificationApp* notifications;
  57. Submenu* submenu;
  58. TextInput* text_input;
  59. TextBox* text_box;
  60. ByteInput* byte_input;
  61. Popup* popup;
  62. uint8_t mac_buf[GAP_MAC_ADDR_SIZE];
  63. FuriString* text_box_store;
  64. Widget* widget;
  65. Nfc* nfc;
  66. NfcPoller* poller;
  67. NfcScanner* scanner;
  68. NfcDevice* nfc_device;
  69. MfClassicKeyCache* mfc_key_cache;
  70. NfcDetectedProtocols* detected_protocols;
  71. DesfireCardType desfire_card_type;
  72. //plugin manager
  73. PluginManager* plugin_manager;
  74. //api
  75. CompositeApiResolver* resolver;
  76. // card details:
  77. uint32_t balance_lari;
  78. uint8_t balance_tetri;
  79. uint32_t card_number;
  80. size_t sec_num;
  81. float value;
  82. char currency[4];
  83. const char* card_type;
  84. bool auto_mode;
  85. CardType mfc_card_type;
  86. NfcProtocol protocol;
  87. // Calypso specific context
  88. CalypsoContext* calypso_context;
  89. } Metroflip;
  90. enum MetroflipCustomEvent {
  91. // Reserve first 100 events for button types and indexes, starting from 0
  92. MetroflipCustomEventReserved = 100,
  93. MetroflipCustomEventViewExit,
  94. MetroflipCustomEventByteInputDone,
  95. MetroflipCustomEventTextInputDone,
  96. MetroflipCustomEventWorkerExit,
  97. MetroflipCustomEventPollerDetect,
  98. MetroflipCustomEventPollerSuccess,
  99. MetroflipCustomEventPollerFail,
  100. MetroflipCustomEventPollerSelectFailed,
  101. MetroflipCustomEventPollerFileNotFound,
  102. MetroflipCustomEventCardLost,
  103. MetroflipCustomEventCardDetected,
  104. MetroflipCustomEventWrongCard
  105. };
  106. typedef enum {
  107. MetroflipPollerEventTypeStart,
  108. MetroflipPollerEventTypeCardDetect,
  109. MetroflipPollerEventTypeSuccess,
  110. MetroflipPollerEventTypeFail,
  111. } MetroflipPollerEventType;
  112. typedef enum {
  113. MetroflipViewSubmenu,
  114. MetroflipViewTextInput,
  115. MetroflipViewByteInput,
  116. MetroflipViewPopup,
  117. MetroflipViewMenu,
  118. MetroflipViewLoading,
  119. MetroflipViewTextBox,
  120. MetroflipViewWidget,
  121. MetroflipViewUart,
  122. } MetroflipView;
  123. typedef enum {
  124. SUCCESSFUL,
  125. INCOMPLETE_KEYFILE,
  126. MISSING_KEYFILE
  127. } KeyfileManager;
  128. CardType determine_card_type(Nfc* nfc);
  129. #ifdef FW_ORIGIN_Official
  130. #define submenu_add_lockable_item( \
  131. submenu, label, index, callback, callback_context, locked, locked_message) \
  132. if(!(locked)) submenu_add_item(submenu, label, index, callback, callback_context)
  133. #endif
  134. char* bit_slice(const char* bit_representation, int start, int end);
  135. void metroflip_plugin_manager_alloc(Metroflip* app);
  136. ///////////////////////////////// Calypso / EN1545 /////////////////////////////////
  137. #define Metroflip_POLLER_MAX_BUFFER_SIZE 1024
  138. #define epoch 852073200
  139. void locale_format_datetime_cat(FuriString* out, const DateTime* dt, bool time);
  140. int binary_to_decimal(const char binary[]);