metroflip_i.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 <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 <lib/nfc/nfc.h>
  32. #include <nfc/nfc_poller.h>
  33. #include <nfc/nfc_scanner.h>
  34. #include <datetime.h>
  35. #include <dolphin/dolphin.h>
  36. #include <locale/locale.h>
  37. #include <stdio.h>
  38. #include <strings.h>
  39. #include <flipper_application/flipper_application.h>
  40. #include <loader/firmware_api/firmware_api.h>
  41. #include "scenes/metroflip_scene.h"
  42. #include "scenes/navigo_structs.h"
  43. typedef struct {
  44. Gui* gui;
  45. SceneManager* scene_manager;
  46. ViewDispatcher* view_dispatcher;
  47. NotificationApp* notifications;
  48. Submenu* submenu;
  49. TextInput* text_input;
  50. TextBox* text_box;
  51. ByteInput* byte_input;
  52. Popup* popup;
  53. uint8_t mac_buf[GAP_MAC_ADDR_SIZE];
  54. FuriString* text_box_store;
  55. Widget* widget;
  56. Nfc* nfc;
  57. NfcPoller* poller;
  58. NfcScanner* scanner;
  59. NfcDevice* nfc_device;
  60. MfClassicKeyCache* mfc_key_cache;
  61. // card details:
  62. uint32_t balance_lari;
  63. uint8_t balance_tetri;
  64. uint32_t card_number;
  65. size_t sec_num;
  66. float value;
  67. char currency[4];
  68. char card_type[32];
  69. // Navigo specific context
  70. NavigoContext* navigo_context;
  71. } Metroflip;
  72. enum MetroflipCustomEvent {
  73. // Reserve first 100 events for button types and indexes, starting from 0
  74. MetroflipCustomEventReserved = 100,
  75. MetroflipCustomEventViewExit,
  76. MetroflipCustomEventByteInputDone,
  77. MetroflipCustomEventTextInputDone,
  78. MetroflipCustomEventWorkerExit,
  79. MetroflipCustomEventPollerDetect,
  80. MetroflipCustomEventPollerSuccess,
  81. MetroflipCustomEventPollerFail,
  82. MetroflipCustomEventPollerSelectFailed,
  83. MetroflipCustomEventPollerFileNotFound,
  84. MetroflipCustomEventCardLost,
  85. MetroflipCustomEventCardDetected,
  86. MetroflipCustomEventWrongCard
  87. };
  88. typedef enum {
  89. MetroflipPollerEventTypeStart,
  90. MetroflipPollerEventTypeCardDetect,
  91. MetroflipPollerEventTypeSuccess,
  92. MetroflipPollerEventTypeFail,
  93. } MetroflipPollerEventType;
  94. typedef enum {
  95. MetroflipViewSubmenu,
  96. MetroflipViewTextInput,
  97. MetroflipViewByteInput,
  98. MetroflipViewPopup,
  99. MetroflipViewMenu,
  100. MetroflipViewLoading,
  101. MetroflipViewTextBox,
  102. MetroflipViewWidget,
  103. MetroflipViewUart,
  104. } MetroflipView;
  105. typedef enum {
  106. SUCCESSFUL,
  107. INCOMPLETE_KEYFILE,
  108. MISSING_KEYFILE
  109. } KeyfileManager;
  110. KeyfileManager manage_keyfiles(char uid_str[]);
  111. void metroflip_app_blink_start(Metroflip* metroflip);
  112. void metroflip_app_blink_stop(Metroflip* metroflip);
  113. #ifdef FW_ORIGIN_Official
  114. #define submenu_add_lockable_item( \
  115. submenu, label, index, callback, callback_context, locked, locked_message) \
  116. if(!(locked)) submenu_add_item(submenu, label, index, callback, callback_context)
  117. #endif
  118. void metroflip_exit_widget_callback(GuiButtonType result, InputType type, void* context);
  119. ///////////////////////////////// Calypso /////////////////////////////////
  120. #define Metroflip_POLLER_MAX_BUFFER_SIZE 1024
  121. #define epoch 852073200
  122. void locale_format_datetime_cat(FuriString* out, const DateTime* dt, bool time);
  123. extern uint8_t read_file[5];
  124. extern uint8_t apdu_success[2];
  125. extern uint8_t select_app[8];
  126. void byte_to_binary(uint8_t byte, char* bits);
  127. int binary_to_decimal(const char binary[]);
  128. int bit_slice_to_dec(const char* bit_representation, int start, int end);
  129. void dec_to_bits(char dec_representation, char* bit_representation);