mifare_nested_scene_check.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 == MifareNestedWorkerEventCollecting) {
  48. if(mifare_nested->run == NestedRunAttack) {
  49. if(mifare_nested->settings->only_hardnested) {
  50. FURI_LOG_I("MifareNested", "Using Hard Nested because user settings");
  51. mifare_nested->collecting_type = MifareNestedWorkerStateCollectingHard;
  52. }
  53. scene_manager_next_scene(
  54. mifare_nested->scene_manager, MifareNestedSceneCollecting);
  55. } else {
  56. scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneCheckKeys);
  57. }
  58. consumed = true;
  59. } else if(event.event == MifareNestedWorkerEventNoTagDetected) {
  60. scene_manager_set_scene_state(
  61. mifare_nested->scene_manager,
  62. MifareNestedSceneCheck,
  63. MifareNestedSceneCheckStateTagSearch);
  64. mifare_nested_scene_check_setup_view(mifare_nested);
  65. consumed = true;
  66. }
  67. }
  68. return consumed;
  69. }
  70. void mifare_nested_scene_check_on_exit(void* context) {
  71. MifareNested* mifare_nested = context;
  72. mifare_nested_worker_stop(mifare_nested->worker);
  73. scene_manager_set_scene_state(
  74. mifare_nested->scene_manager,
  75. MifareNestedSceneCheck,
  76. MifareNestedSceneCheckStateTagSearch);
  77. // Clear view
  78. popup_reset(mifare_nested->popup);
  79. mifare_nested_blink_stop(mifare_nested);
  80. }