nfc_scene_mf_classic_read_success.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "../nfc_i.h"
  2. #include <dolphin/dolphin.h>
  3. void nfc_scene_mf_classic_read_success_widget_callback(
  4. GuiButtonType result,
  5. InputType type,
  6. void* context) {
  7. furi_assert(context);
  8. Nfc* nfc = context;
  9. if(type == InputTypeShort) {
  10. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  11. }
  12. }
  13. void nfc_scene_mf_classic_read_success_on_enter(void* context) {
  14. Nfc* nfc = context;
  15. NfcDeviceData* dev_data = &nfc->dev->dev_data;
  16. MfClassicData* mf_data = &dev_data->mf_classic_data;
  17. string_t str_tmp;
  18. string_init(str_tmp);
  19. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  20. // Setup view
  21. Widget* widget = nfc->widget;
  22. widget_add_button_element(
  23. widget, GuiButtonTypeLeft, "Retry", nfc_scene_mf_classic_read_success_widget_callback, nfc);
  24. widget_add_button_element(
  25. widget, GuiButtonTypeRight, "More", nfc_scene_mf_classic_read_success_widget_callback, nfc);
  26. if(string_size(nfc->dev->dev_data.parsed_data)) {
  27. widget_add_text_box_element(
  28. nfc->widget,
  29. 0,
  30. 0,
  31. 128,
  32. 32,
  33. AlignLeft,
  34. AlignTop,
  35. string_get_cstr(nfc->dev->dev_data.parsed_data),
  36. true);
  37. } else {
  38. widget_add_string_element(
  39. widget,
  40. 0,
  41. 0,
  42. AlignLeft,
  43. AlignTop,
  44. FontSecondary,
  45. mf_classic_get_type_str(mf_data->type));
  46. widget_add_string_element(
  47. widget, 0, 11, AlignLeft, AlignTop, FontSecondary, "ISO 14443-3 (Type A)");
  48. string_printf(str_tmp, "UID:");
  49. for(size_t i = 0; i < dev_data->nfc_data.uid_len; i++) {
  50. string_cat_printf(str_tmp, " %02X", dev_data->nfc_data.uid[i]);
  51. }
  52. widget_add_string_element(
  53. widget, 0, 22, AlignLeft, AlignTop, FontSecondary, string_get_cstr(str_tmp));
  54. uint8_t sectors_total = mf_classic_get_total_sectors_num(mf_data->type);
  55. uint8_t keys_total = sectors_total * 2;
  56. uint8_t keys_found = 0;
  57. uint8_t sectors_read = 0;
  58. mf_classic_get_read_sectors_and_keys(mf_data, &sectors_read, &keys_found);
  59. string_printf(str_tmp, "Keys Found: %d/%d", keys_found, keys_total);
  60. widget_add_string_element(
  61. widget, 0, 33, AlignLeft, AlignTop, FontSecondary, string_get_cstr(str_tmp));
  62. string_printf(str_tmp, "Sectors Read: %d/%d", sectors_read, sectors_total);
  63. widget_add_string_element(
  64. widget, 0, 44, AlignLeft, AlignTop, FontSecondary, string_get_cstr(str_tmp));
  65. }
  66. string_clear(str_tmp);
  67. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  68. }
  69. bool nfc_scene_mf_classic_read_success_on_event(void* context, SceneManagerEvent event) {
  70. Nfc* nfc = context;
  71. bool consumed = false;
  72. if(event.type == SceneManagerEventTypeCustom) {
  73. if(event.event == GuiButtonTypeLeft) {
  74. scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
  75. consumed = true;
  76. } else if(event.event == GuiButtonTypeRight) {
  77. // Clear device name
  78. nfc_device_set_name(nfc->dev, "");
  79. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicMenu);
  80. consumed = true;
  81. }
  82. } else if(event.type == SceneManagerEventTypeBack) {
  83. scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
  84. consumed = true;
  85. }
  86. return consumed;
  87. }
  88. void nfc_scene_mf_classic_read_success_on_exit(void* context) {
  89. Nfc* nfc = context;
  90. // Clear view
  91. widget_reset(nfc->widget);
  92. }