nfc_magic_scene_mf_classic_write_check.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "../nfc_magic_app_i.h"
  2. void nfc_magic_scene_mf_classic_write_check_view_callback(WriteProblemsEvent event, void* context) {
  3. NfcMagicApp* instance = context;
  4. NfcMagicAppWriteProblemsContext* problems_context = &instance->write_problems_context;
  5. if(event == WriteProblemsEventCenterPressed) {
  6. if(problems_context->problem_index == problems_context->problems_total - 1) {
  7. // Continue to the next scene
  8. if(instance->gen2_poller_is_wipe_mode) {
  9. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneWipe);
  10. } else {
  11. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneWrite);
  12. }
  13. } else {
  14. // Move to the next problem
  15. problems_context->problem_index++;
  16. problems_context->problem_index_abs++;
  17. write_problems_set_problem_index(
  18. instance->write_problems, problems_context->problem_index);
  19. for(uint8_t i = problems_context->problem_index_abs;
  20. i < GEN2_POLLER_WRITE_PROBLEMS_LEN;
  21. i++) {
  22. if(problems_context->problems.all_problems & (1 << i)) {
  23. write_problems_set_content(instance->write_problems, gen2_problem_strings[i]);
  24. problems_context->problem_index_abs = i;
  25. break;
  26. }
  27. }
  28. }
  29. } else if(event == WriteProblemsEventLeftPressed) {
  30. if(problems_context->problem_index == 0) {
  31. // Exit to the previous scene
  32. scene_manager_search_and_switch_to_previous_scene(
  33. instance->scene_manager, NfcMagicSceneMfClassicMenu);
  34. } else {
  35. // Move to the previous problem
  36. problems_context->problem_index--;
  37. problems_context->problem_index_abs--;
  38. write_problems_set_problem_index(
  39. instance->write_problems, problems_context->problem_index);
  40. for(uint8_t i = problems_context->problem_index_abs;
  41. i < GEN2_POLLER_WRITE_PROBLEMS_LEN;
  42. i--) {
  43. if(problems_context->problems.all_problems & (1 << i)) {
  44. write_problems_set_content(instance->write_problems, gen2_problem_strings[i]);
  45. problems_context->problem_index_abs = i;
  46. break;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. void nfc_magic_scene_mf_classic_write_check_on_enter(void* context) {
  53. NfcMagicApp* instance = context;
  54. Gen2PollerWriteProblems problems = gen2_poller_check_target_problems(instance->target_dev);
  55. if(!instance->gen2_poller_is_wipe_mode) {
  56. problems.all_problems |=
  57. gen2_poller_check_source_problems(instance->source_dev).all_problems;
  58. }
  59. FURI_LOG_D("GEN2", "Problems: %d", problems.all_problems);
  60. WriteProblems* write_problems = instance->write_problems;
  61. uint8_t problems_count = 0;
  62. uint8_t current_problem = 0;
  63. furi_assert(!problems.no_data, "No MFC data in nfc device");
  64. // Set the uid_locked problem to true as we have a Mifare Classic card
  65. problems.uid_locked = true;
  66. // Count the number of problems
  67. for(uint8_t i = 0; i < GEN2_POLLER_WRITE_PROBLEMS_LEN; i++) {
  68. if(problems.all_problems & (1 << i)) {
  69. problems_count++;
  70. }
  71. }
  72. // Init the view
  73. write_problems_set_callback(
  74. write_problems, nfc_magic_scene_mf_classic_write_check_view_callback, instance);
  75. write_problems_set_problems_total(write_problems, problems_count);
  76. write_problems_set_problem_index(write_problems, current_problem);
  77. // Set the first problem
  78. for(uint8_t i = current_problem; i < GEN2_POLLER_WRITE_PROBLEMS_LEN; i++) {
  79. if(problems.all_problems & (1 << i)) {
  80. write_problems_set_content(instance->write_problems, gen2_problem_strings[i]);
  81. instance->write_problems_context.problem_index_abs = i;
  82. break;
  83. }
  84. }
  85. // Save the problems context
  86. instance->write_problems_context.problem_index = current_problem;
  87. instance->write_problems_context.problems_total = problems_count;
  88. instance->write_problems_context.problems = problems;
  89. // Setup and start worker
  90. view_dispatcher_switch_to_view(instance->view_dispatcher, NfcMagicAppViewWriteProblems);
  91. }
  92. bool nfc_magic_scene_mf_classic_write_check_on_event(void* context, SceneManagerEvent event) {
  93. NfcMagicApp* instance = context;
  94. UNUSED(event);
  95. UNUSED(context);
  96. UNUSED(instance);
  97. bool consumed = false;
  98. return consumed;
  99. }
  100. void nfc_magic_scene_mf_classic_write_check_on_exit(void* context) {
  101. NfcMagicApp* instance = context;
  102. instance->write_problems_context.problem_index = 0;
  103. instance->write_problems_context.problems_total = 0;
  104. instance->write_problems_context.problems.all_problems = 0;
  105. write_problems_reset(instance->write_problems);
  106. }