nfc_maker.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include "nfc_maker.h"
  2. const CardDef cards[CardMAX] = {
  3. // MfUltralight
  4. [CardNtag203] =
  5. {
  6. .name = "NTAG 203 (144B)",
  7. .size = 0x12 * NTAG_DATA_AREA_UNIT_SIZE,
  8. .protocol = NfcProtocolMfUltralight,
  9. .generator = NfcDataGeneratorTypeNTAG203,
  10. },
  11. [CardNtag213] =
  12. {
  13. .name = "NTAG 213 (144B)",
  14. .size = 0x12 * NTAG_DATA_AREA_UNIT_SIZE,
  15. .protocol = NfcProtocolMfUltralight,
  16. .generator = NfcDataGeneratorTypeNTAG213,
  17. },
  18. [CardNtag215] =
  19. {
  20. .name = "NTAG 215 (496B)",
  21. .size = 0x3E * NTAG_DATA_AREA_UNIT_SIZE,
  22. .protocol = NfcProtocolMfUltralight,
  23. .generator = NfcDataGeneratorTypeNTAG215,
  24. },
  25. [CardNtag216] =
  26. {
  27. .name = "NTAG 216 (872B)",
  28. .size = 0x6D * NTAG_DATA_AREA_UNIT_SIZE,
  29. .protocol = NfcProtocolMfUltralight,
  30. .generator = NfcDataGeneratorTypeNTAG216,
  31. },
  32. [CardNtagI2C1K] =
  33. {
  34. .name = "NTAG I2C 1K (872B)",
  35. .size = 0x6D * NTAG_DATA_AREA_UNIT_SIZE,
  36. .protocol = NfcProtocolMfUltralight,
  37. .generator = NfcDataGeneratorTypeNTAGI2C1k,
  38. },
  39. [CardNtagI2C2K] =
  40. {
  41. .name = "NTAG I2C 2K (1872B)",
  42. .size = 0xEA * NTAG_DATA_AREA_UNIT_SIZE,
  43. .protocol = NfcProtocolMfUltralight,
  44. .generator = NfcDataGeneratorTypeNTAGI2C2k,
  45. },
  46. // MfClassic (size excludes sector trailers and MAD1/2 sectors)
  47. [CardMfClassicMini] =
  48. {
  49. .name = "MIFARE Classic Mini 0.3K",
  50. .size = (5 - 1) * (4 - 1) * MF_CLASSIC_BLOCK_SIZE,
  51. .protocol = NfcProtocolMfClassic,
  52. .generator = NfcDataGeneratorTypeMfClassicMini,
  53. },
  54. [CardMfClassic1K4b] =
  55. {
  56. .name = "MIFARE Classic 1K UID4",
  57. .size = (16 - 1) * (4 - 1) * MF_CLASSIC_BLOCK_SIZE,
  58. .protocol = NfcProtocolMfClassic,
  59. .generator = NfcDataGeneratorTypeMfClassic1k_4b,
  60. },
  61. [CardMfClassic1K7b] =
  62. {
  63. .name = "MIFARE Classic 1K UID7",
  64. .size = (16 - 1) * (4 - 1) * MF_CLASSIC_BLOCK_SIZE,
  65. .protocol = NfcProtocolMfClassic,
  66. .generator = NfcDataGeneratorTypeMfClassic1k_7b,
  67. },
  68. [CardMfClassic4K4b] =
  69. {
  70. .name = "MIFARE Classic 4K UID4",
  71. .size = (((32 - 2) * (4 - 1)) + ((8) * (16 - 1))) * MF_CLASSIC_BLOCK_SIZE,
  72. .protocol = NfcProtocolMfClassic,
  73. .generator = NfcDataGeneratorTypeMfClassic4k_4b,
  74. },
  75. [CardMfClassic4K7b] =
  76. {
  77. .name = "MIFARE Classic 4K UID7",
  78. .size = (((32 - 2) * (4 - 1)) + ((8) * (16 - 1))) * MF_CLASSIC_BLOCK_SIZE,
  79. .protocol = NfcProtocolMfClassic,
  80. .generator = NfcDataGeneratorTypeMfClassic4k_7b,
  81. },
  82. };
  83. static bool nfc_maker_custom_event_callback(void* context, uint32_t event) {
  84. furi_assert(context);
  85. NfcMaker* app = context;
  86. return scene_manager_handle_custom_event(app->scene_manager, event);
  87. }
  88. static bool nfc_maker_back_event_callback(void* context) {
  89. furi_assert(context);
  90. NfcMaker* app = context;
  91. return scene_manager_handle_back_event(app->scene_manager);
  92. }
  93. NfcMaker* nfc_maker_alloc() {
  94. NfcMaker* app = malloc(sizeof(NfcMaker));
  95. app->gui = furi_record_open(RECORD_GUI);
  96. // View Dispatcher and Scene Manager
  97. app->view_dispatcher = view_dispatcher_alloc();
  98. app->scene_manager = scene_manager_alloc(&nfc_maker_scene_handlers, app);
  99. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  100. view_dispatcher_set_custom_event_callback(
  101. app->view_dispatcher, nfc_maker_custom_event_callback);
  102. view_dispatcher_set_navigation_event_callback(
  103. app->view_dispatcher, nfc_maker_back_event_callback);
  104. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  105. // Gui Modules
  106. app->submenu = submenu_alloc();
  107. view_dispatcher_add_view(
  108. app->view_dispatcher, NfcMakerViewSubmenu, submenu_get_view(app->submenu));
  109. app->text_input = text_input_alloc();
  110. view_dispatcher_add_view(
  111. app->view_dispatcher, NfcMakerViewTextInput, text_input_get_view(app->text_input));
  112. app->byte_input = byte_input_alloc();
  113. view_dispatcher_add_view(
  114. app->view_dispatcher, NfcMakerViewByteInput, byte_input_get_view(app->byte_input));
  115. app->popup = popup_alloc();
  116. view_dispatcher_add_view(app->view_dispatcher, NfcMakerViewPopup, popup_get_view(app->popup));
  117. // Nfc Device
  118. app->nfc_device = nfc_device_alloc();
  119. return app;
  120. }
  121. void nfc_maker_free(NfcMaker* app) {
  122. furi_assert(app);
  123. // Nfc Device
  124. nfc_device_free(app->nfc_device);
  125. if(app->ndef_buffer) {
  126. free(app->ndef_buffer);
  127. }
  128. // Gui modules
  129. view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewSubmenu);
  130. submenu_free(app->submenu);
  131. view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewTextInput);
  132. text_input_free(app->text_input);
  133. view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewByteInput);
  134. byte_input_free(app->byte_input);
  135. view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewPopup);
  136. popup_free(app->popup);
  137. // View Dispatcher and Scene Manager
  138. view_dispatcher_free(app->view_dispatcher);
  139. scene_manager_free(app->scene_manager);
  140. // Records
  141. furi_record_close(RECORD_GUI);
  142. free(app);
  143. }
  144. int32_t nfc_maker(void* p) {
  145. UNUSED(p);
  146. NfcMaker* app = nfc_maker_alloc();
  147. scene_manager_set_scene_state(app->scene_manager, NfcMakerSceneStart, NfcMakerSceneHttps);
  148. scene_manager_next_scene(app->scene_manager, NfcMakerSceneStart);
  149. view_dispatcher_run(app->view_dispatcher);
  150. nfc_maker_free(app);
  151. return 0;
  152. }