nfc_scene_nfc_data_info.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "../nfc_i.h"
  2. void nfc_scene_nfc_data_info_widget_callback(GuiButtonType result, InputType type, void* context) {
  3. Nfc* nfc = context;
  4. if(type == InputTypeShort) {
  5. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  6. }
  7. }
  8. void nfc_scene_nfc_data_info_on_enter(void* context) {
  9. Nfc* nfc = context;
  10. Widget* widget = nfc->widget;
  11. FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
  12. NfcDeviceData* dev_data = &nfc->dev->dev_data;
  13. NfcProtocol protocol = dev_data->protocol;
  14. uint8_t text_scroll_height = 0;
  15. if((protocol == NfcDeviceProtocolMifareDesfire) || (protocol == NfcDeviceProtocolMifareUl)) {
  16. widget_add_button_element(
  17. widget, GuiButtonTypeRight, "More", nfc_scene_nfc_data_info_widget_callback, nfc);
  18. text_scroll_height = 52;
  19. } else {
  20. text_scroll_height = 64;
  21. }
  22. string_t temp_str;
  23. string_init(temp_str);
  24. // Set name if present
  25. if(nfc->dev->dev_name[0] != '\0') {
  26. string_printf(temp_str, "\ec%s\n", nfc->dev->dev_name);
  27. }
  28. // Set tag type
  29. if(protocol == NfcDeviceProtocolEMV) {
  30. string_cat_printf(temp_str, "\e#EMV Bank Card\n");
  31. } else if(protocol == NfcDeviceProtocolMifareUl) {
  32. string_cat_printf(temp_str, "\e#%s\n", nfc_mf_ul_type(dev_data->mf_ul_data.type, true));
  33. } else if(protocol == NfcDeviceProtocolMifareClassic) {
  34. string_cat_printf(
  35. temp_str, "\e#%s\n", nfc_mf_classic_type(dev_data->mf_classic_data.type));
  36. } else if(protocol == NfcDeviceProtocolMifareDesfire) {
  37. string_cat_printf(temp_str, "\e#MIFARE DESfire\n");
  38. } else {
  39. string_cat_printf(temp_str, "\e#Unknown ISO tag\n");
  40. }
  41. // Set tag iso data
  42. char iso_type = FURI_BIT(nfc_data->sak, 5) ? '4' : '3';
  43. string_cat_printf(temp_str, "ISO 14443-%c (NFC-A)\n", iso_type);
  44. string_cat_printf(temp_str, "UID:");
  45. for(size_t i = 0; i < nfc_data->uid_len; i++) {
  46. string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
  47. }
  48. string_cat_printf(temp_str, "\nATQA: %02X %02X ", nfc_data->atqa[1], nfc_data->atqa[0]);
  49. string_cat_printf(temp_str, " SAK: %02X", nfc_data->sak);
  50. // Set application specific data
  51. if(protocol == NfcDeviceProtocolMifareDesfire) {
  52. MifareDesfireData* data = &dev_data->mf_df_data;
  53. uint32_t bytes_total = 1 << (data->version.sw_storage >> 1);
  54. uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0;
  55. string_cat_printf(temp_str, "\n%d", bytes_total);
  56. if(data->version.sw_storage & 1) {
  57. string_push_back(temp_str, '+');
  58. }
  59. string_cat_printf(temp_str, " bytes, %d bytes free\n", bytes_free);
  60. uint16_t n_apps = 0;
  61. uint16_t n_files = 0;
  62. for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
  63. n_apps++;
  64. for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
  65. n_files++;
  66. }
  67. }
  68. string_cat_printf(temp_str, "%d Application", n_apps);
  69. if(n_apps != 1) {
  70. string_push_back(temp_str, 's');
  71. }
  72. string_cat_printf(temp_str, ", %d file", n_files);
  73. if(n_files != 1) {
  74. string_push_back(temp_str, 's');
  75. }
  76. } else if(protocol == NfcDeviceProtocolMifareUl) {
  77. MfUltralightData* data = &dev_data->mf_ul_data;
  78. string_cat_printf(
  79. temp_str, "\nPages Read %d/%d", data->data_read / 4, data->data_size / 4);
  80. if(data->data_size > data->data_read) {
  81. string_cat_printf(temp_str, "\nPassword-protected");
  82. }
  83. } else if(protocol == NfcDeviceProtocolMifareClassic) {
  84. MfClassicData* data = &dev_data->mf_classic_data;
  85. uint8_t sectors_total = mf_classic_get_total_sectors_num(data->type);
  86. uint8_t keys_total = sectors_total * 2;
  87. uint8_t keys_found = 0;
  88. uint8_t sectors_read = 0;
  89. mf_classic_get_read_sectors_and_keys(data, &sectors_read, &keys_found);
  90. string_cat_printf(temp_str, "\nKeys Found %d/%d", keys_found, keys_total);
  91. string_cat_printf(temp_str, "\nSectors Read %d/%d", sectors_read, sectors_total);
  92. }
  93. // Add text scroll widget
  94. widget_add_text_scroll_element(
  95. widget, 0, 0, 128, text_scroll_height, string_get_cstr(temp_str));
  96. string_clear(temp_str);
  97. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  98. }
  99. bool nfc_scene_nfc_data_info_on_event(void* context, SceneManagerEvent event) {
  100. Nfc* nfc = context;
  101. NfcProtocol protocol = nfc->dev->dev_data.protocol;
  102. bool consumed = false;
  103. if(event.type == SceneManagerEventTypeCustom) {
  104. if(event.event == GuiButtonTypeRight) {
  105. if(protocol == NfcDeviceProtocolMifareDesfire) {
  106. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfDesfireApp);
  107. consumed = true;
  108. } else if(protocol == NfcDeviceProtocolMifareUl) {
  109. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightData);
  110. consumed = true;
  111. }
  112. }
  113. }
  114. return consumed;
  115. }
  116. void nfc_scene_nfc_data_info_on_exit(void* context) {
  117. Nfc* nfc = context;
  118. widget_reset(nfc->widget);
  119. }