metroflip_i.h 5.0 KB

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