mifare_nested_scene_check.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "../mifare_nested_i.h"
  2. enum {
  3. MifareNestedSceneCheckStateTagSearch,
  4. MifareNestedSceneCheckStateTagFound,
  5. };
  6. bool mifare_nested_check_worker_callback(MifareNestedWorkerEvent event, void* context) {
  7. furi_assert(context);
  8. MifareNested* mifare_nested = context;
  9. view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, event);
  10. return true;
  11. }
  12. static void mifare_nested_scene_check_setup_view(MifareNested* mifare_nested) {
  13. Popup* popup = mifare_nested->popup;
  14. popup_reset(popup);
  15. uint32_t state =
  16. scene_manager_get_scene_state(mifare_nested->scene_manager, MifareNestedSceneCheck);
  17. if(state == MifareNestedSceneCheckStateTagSearch) {
  18. popup_set_icon(mifare_nested->popup, 0, 8, &I_ApplyTag);
  19. popup_set_text(
  20. mifare_nested->popup, "Apply tag to\nthe back", 128, 32, AlignRight, AlignCenter);
  21. } else {
  22. popup_set_icon(popup, 12, 23, &I_Loading);
  23. popup_set_header(popup, "Checking\nDon't move...", 52, 32, AlignLeft, AlignCenter);
  24. }
  25. view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewPopup);
  26. }
  27. void mifare_nested_scene_check_on_enter(void* context) {
  28. MifareNested* mifare_nested = context;
  29. scene_manager_set_scene_state(
  30. mifare_nested->scene_manager,
  31. MifareNestedSceneCheck,
  32. MifareNestedSceneCheckStateTagSearch);
  33. mifare_nested_scene_check_setup_view(mifare_nested);
  34. // Setup and start worker
  35. mifare_nested_worker_start(
  36. mifare_nested->worker,
  37. MifareNestedWorkerStateCheck,
  38. &mifare_nested->nfc_dev->dev_data,
  39. mifare_nested_check_worker_callback,
  40. mifare_nested);
  41. mifare_nested_blink_start(mifare_nested);
  42. }
  43. bool mifare_nested_scene_check_on_event(void* context, SceneManagerEvent event) {
  44. MifareNested* mifare_nested = context;
  45. bool consumed = false;
  46. if(event.type == SceneManagerEventTypeCustom) {
  47. if(event.event == MifareNestedWorkerEventNoncesCollected) {
  48. scene_manager_next_scene(
  49. mifare_nested->scene_manager, MifareNestedSceneNoncesCollected);
  50. consumed = true;
  51. } else if(event.event == MifareNestedWorkerEventAttackFailed) {
  52. scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneFailed);
  53. consumed = true;
  54. } else if(event.event == MifareNestedWorkerEventCollecting) {
  55. if(mifare_nested->run == NestedRunAttack) {
  56. if(mifare_nested->settings->only_hardnested) {
  57. FURI_LOG_I("MifareNested", "Using Hard Nested because user settings");
  58. mifare_nested->collecting_type = MifareNestedWorkerStateCollectingHard;
  59. }
  60. scene_manager_next_scene(
  61. mifare_nested->scene_manager, MifareNestedSceneCollecting);
  62. } else {
  63. scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneCheckKeys);
  64. }
  65. consumed = true;
  66. } else if(event.event == MifareNestedWorkerEventNoTagDetected) {
  67. scene_manager_set_scene_state(
  68. mifare_nested->scene_manager,
  69. MifareNestedSceneCheck,
  70. MifareNestedSceneCheckStateTagSearch);
  71. mifare_nested_scene_check_setup_view(mifare_nested);
  72. consumed = true;
  73. }
  74. }
  75. return consumed;
  76. }
  77. void mifare_nested_scene_check_on_exit(void* context) {
  78. MifareNested* mifare_nested = context;
  79. mifare_nested_worker_stop(mifare_nested->worker);
  80. scene_manager_set_scene_state(
  81. mifare_nested->scene_manager,
  82. MifareNestedSceneCheck,
  83. MifareNestedSceneCheckStateTagSearch);
  84. // Clear view
  85. popup_reset(mifare_nested->popup);
  86. mifare_nested_blink_stop(mifare_nested);
  87. }