nfc.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "nfc_i.h"
  2. #include "api-hal-nfc.h"
  3. #include "app_scene.h"
  4. Nfc* nfc_alloc() {
  5. Nfc* nfc = furi_alloc(sizeof(Nfc));
  6. nfc->nfc_common.worker = nfc_worker_alloc();
  7. nfc->nfc_common.view_dispatcher = view_dispatcher_alloc();
  8. view_dispatcher_enable_queue(nfc->nfc_common.view_dispatcher);
  9. view_dispatcher_enable_navigation(nfc->nfc_common.view_dispatcher, nfc);
  10. // Open GUI record
  11. nfc->gui = furi_record_open("gui");
  12. view_dispatcher_attach_to_gui(
  13. nfc->nfc_common.view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
  14. // Open Notification record
  15. nfc->notifications = furi_record_open("notification");
  16. // Submenu
  17. nfc->submenu = submenu_alloc();
  18. view_dispatcher_add_view(
  19. nfc->nfc_common.view_dispatcher, NfcViewMenu, submenu_get_view(nfc->submenu));
  20. // Dialog
  21. nfc->dialog_ex = dialog_ex_alloc();
  22. view_dispatcher_add_view(
  23. nfc->nfc_common.view_dispatcher, NfcViewDialogEx, dialog_ex_get_view(nfc->dialog_ex));
  24. // Popup
  25. nfc->popup = popup_alloc();
  26. view_dispatcher_add_view(
  27. nfc->nfc_common.view_dispatcher, NfcViewPopup, popup_get_view(nfc->popup));
  28. // Text Input
  29. nfc->text_input = text_input_alloc();
  30. view_dispatcher_add_view(
  31. nfc->nfc_common.view_dispatcher, NfcViewTextInput, text_input_get_view(nfc->text_input));
  32. // Byte Input
  33. nfc->byte_input = byte_input_alloc();
  34. view_dispatcher_add_view(
  35. nfc->nfc_common.view_dispatcher, NfcViewByteInput, byte_input_get_view(nfc->byte_input));
  36. // Detect
  37. nfc->nfc_detect = nfc_detect_alloc(&nfc->nfc_common);
  38. view_dispatcher_add_view(
  39. nfc->nfc_common.view_dispatcher, NfcViewDetect, nfc_detect_get_view(nfc->nfc_detect));
  40. // Emulate
  41. nfc->nfc_emulate = nfc_emulate_alloc(&nfc->nfc_common);
  42. view_dispatcher_add_view(
  43. nfc->nfc_common.view_dispatcher, NfcViewEmulate, nfc_emulate_get_view(nfc->nfc_emulate));
  44. // EMV
  45. nfc->nfc_emv = nfc_emv_alloc(&nfc->nfc_common);
  46. view_dispatcher_add_view(
  47. nfc->nfc_common.view_dispatcher, NfcViewEmv, nfc_emv_get_view(nfc->nfc_emv));
  48. // Mifare Ultralight
  49. nfc->nfc_mifare_ul = nfc_mifare_ul_alloc(&nfc->nfc_common);
  50. view_dispatcher_add_view(
  51. nfc->nfc_common.view_dispatcher,
  52. NfcViewMifareUl,
  53. nfc_mifare_ul_get_view(nfc->nfc_mifare_ul));
  54. // Scene allocation
  55. nfc->scene_start = nfc_scene_start_alloc();
  56. nfc->scene_read_card = nfc_scene_read_card_alloc();
  57. nfc->scene_read_card_success = nfc_scene_read_card_success_alloc();
  58. nfc->scene_card_menu = nfc_scene_card_menu_alloc();
  59. nfc->scene_not_implemented = nfc_scene_not_implemented_alloc();
  60. nfc->scene_debug_menu = nfc_scene_debug_menu_alloc();
  61. nfc->scene_debug_detect = nfc_scene_debug_detect_alloc();
  62. nfc->scene_debug_emulate = nfc_scene_debug_emulate_alloc();
  63. nfc->scene_debug_read_emv = nfc_scene_debug_read_emv_alloc();
  64. nfc->scene_debug_read_mifare_ul = nfc_scene_debug_read_mifare_ul_alloc();
  65. nfc->scene_emulate_uid = nfc_scene_emulate_uid_alloc();
  66. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_start);
  67. return nfc;
  68. }
  69. void nfc_free(Nfc* nfc) {
  70. furi_assert(nfc);
  71. // Submenu
  72. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
  73. submenu_free(nfc->submenu);
  74. // DialogEx
  75. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewDialogEx);
  76. dialog_ex_free(nfc->dialog_ex);
  77. // Popup
  78. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
  79. popup_free(nfc->popup);
  80. // TextInput
  81. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewTextInput);
  82. text_input_free(nfc->text_input);
  83. // ByteInput
  84. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewByteInput);
  85. byte_input_free(nfc->byte_input);
  86. // Detect
  87. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewDetect);
  88. nfc_detect_free(nfc->nfc_detect);
  89. // Emulate
  90. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewEmulate);
  91. nfc_emulate_free(nfc->nfc_emulate);
  92. // EMV
  93. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewEmv);
  94. nfc_emv_free(nfc->nfc_emv);
  95. // Mifare Ultralight
  96. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewMifareUl);
  97. nfc_mifare_ul_free(nfc->nfc_mifare_ul);
  98. // Worker
  99. nfc_worker_stop(nfc->nfc_common.worker);
  100. nfc_worker_free(nfc->nfc_common.worker);
  101. // Scenes
  102. nfc_scene_start_free(nfc->scene_start);
  103. nfc_scene_read_card_free(nfc->scene_read_card);
  104. nfc_scene_read_card_success_free(nfc->scene_read_card_success);
  105. nfc_scene_card_menu_free(nfc->scene_card_menu);
  106. nfc_scene_not_implemented_free(nfc->scene_not_implemented);
  107. nfc_scene_debug_menu_free(nfc->scene_debug_menu);
  108. nfc_scene_debug_detect_free(nfc->scene_debug_detect);
  109. nfc_scene_debug_emulate_free(nfc->scene_debug_emulate);
  110. nfc_scene_debug_read_emv_free(nfc->scene_debug_read_emv);
  111. nfc_scene_debug_read_mifare_ul_free(nfc->scene_debug_read_mifare_ul);
  112. nfc_scene_emulate_uid_free(nfc->scene_emulate_uid);
  113. // View Dispatcher
  114. view_dispatcher_free(nfc->nfc_common.view_dispatcher);
  115. // GUI
  116. furi_record_close("gui");
  117. nfc->gui = NULL;
  118. // Notifications
  119. furi_record_close("notification");
  120. nfc->notifications = NULL;
  121. free(nfc);
  122. }
  123. int32_t nfc_task(void* p) {
  124. Nfc* nfc = nfc_alloc();
  125. view_dispatcher_run(nfc->nfc_common.view_dispatcher);
  126. nfc_free(nfc);
  127. return 0;
  128. }
  129. void nfc_set_text_store(Nfc* nfc, const char* text, ...) {
  130. va_list args;
  131. va_start(args, text);
  132. vsnprintf(nfc->text_store, sizeof(nfc->text_store), text, args);
  133. va_end(args);
  134. }