nfc.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. nfc->scene_save_name = nfc_scene_save_name_alloc();
  67. nfc->scene_save_success = nfc_scene_save_success_alloc();
  68. nfc->scene_file_select = nfc_scene_file_select_alloc();
  69. nfc->scene_saved_menu = nfc_scene_saved_menu_alloc();
  70. nfc->scene_set_type = nfc_scene_set_type_alloc();
  71. nfc->scene_set_sak = nfc_scene_set_sak_alloc();
  72. nfc->scene_set_atqa = nfc_scene_set_atqa_alloc();
  73. nfc->scene_set_uid = nfc_scene_set_uid_alloc();
  74. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_start);
  75. return nfc;
  76. }
  77. void nfc_free(Nfc* nfc) {
  78. furi_assert(nfc);
  79. // Submenu
  80. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
  81. submenu_free(nfc->submenu);
  82. // DialogEx
  83. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewDialogEx);
  84. dialog_ex_free(nfc->dialog_ex);
  85. // Popup
  86. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
  87. popup_free(nfc->popup);
  88. // TextInput
  89. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewTextInput);
  90. text_input_free(nfc->text_input);
  91. // ByteInput
  92. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewByteInput);
  93. byte_input_free(nfc->byte_input);
  94. // Detect
  95. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewDetect);
  96. nfc_detect_free(nfc->nfc_detect);
  97. // Emulate
  98. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewEmulate);
  99. nfc_emulate_free(nfc->nfc_emulate);
  100. // EMV
  101. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewEmv);
  102. nfc_emv_free(nfc->nfc_emv);
  103. // Mifare Ultralight
  104. view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewMifareUl);
  105. nfc_mifare_ul_free(nfc->nfc_mifare_ul);
  106. // Worker
  107. nfc_worker_stop(nfc->nfc_common.worker);
  108. nfc_worker_free(nfc->nfc_common.worker);
  109. // Scenes
  110. nfc_scene_start_free(nfc->scene_start);
  111. nfc_scene_read_card_free(nfc->scene_read_card);
  112. nfc_scene_read_card_success_free(nfc->scene_read_card_success);
  113. nfc_scene_card_menu_free(nfc->scene_card_menu);
  114. nfc_scene_not_implemented_free(nfc->scene_not_implemented);
  115. nfc_scene_debug_menu_free(nfc->scene_debug_menu);
  116. nfc_scene_debug_detect_free(nfc->scene_debug_detect);
  117. nfc_scene_debug_emulate_free(nfc->scene_debug_emulate);
  118. nfc_scene_debug_read_emv_free(nfc->scene_debug_read_emv);
  119. nfc_scene_debug_read_mifare_ul_free(nfc->scene_debug_read_mifare_ul);
  120. nfc_scene_emulate_uid_free(nfc->scene_emulate_uid);
  121. nfc_scene_save_name_free(nfc->scene_save_name);
  122. nfc_scene_save_success_free(nfc->scene_save_success);
  123. nfc_scene_file_select_free(nfc->scene_file_select);
  124. nfc_scene_saved_menu_free(nfc->scene_saved_menu);
  125. nfc_scene_set_type_free(nfc->scene_set_type);
  126. nfc_scene_set_sak_free(nfc->scene_set_sak);
  127. nfc_scene_set_atqa_free(nfc->scene_set_atqa);
  128. nfc_scene_set_uid_free(nfc->scene_set_uid);
  129. // View Dispatcher
  130. view_dispatcher_free(nfc->nfc_common.view_dispatcher);
  131. // GUI
  132. furi_record_close("gui");
  133. nfc->gui = NULL;
  134. // Notifications
  135. furi_record_close("notification");
  136. nfc->notifications = NULL;
  137. free(nfc);
  138. }
  139. int32_t nfc_task(void* p) {
  140. Nfc* nfc = nfc_alloc();
  141. view_dispatcher_run(nfc->nfc_common.view_dispatcher);
  142. nfc_free(nfc);
  143. return 0;
  144. }
  145. void nfc_set_text_store(Nfc* nfc, const char* text, ...) {
  146. va_list args;
  147. va_start(args, text);
  148. vsnprintf(nfc->text_store, sizeof(nfc->text_store), text, args);
  149. va_end(args);
  150. }