nfc_scene_nfc_data_info.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. (protocol == NfcDeviceProtocolMifareClassic)) {
  17. widget_add_button_element(
  18. widget, GuiButtonTypeRight, "More", nfc_scene_nfc_data_info_widget_callback, nfc);
  19. text_scroll_height = 52;
  20. } else {
  21. text_scroll_height = 64;
  22. }
  23. FuriString* temp_str;
  24. temp_str = furi_string_alloc();
  25. // Set name if present
  26. if(nfc->dev->dev_name[0] != '\0') {
  27. furi_string_printf(temp_str, "\ec%s\n", nfc->dev->dev_name);
  28. }
  29. // Set tag type
  30. if(protocol == NfcDeviceProtocolEMV) {
  31. furi_string_cat_printf(temp_str, "\e#EMV Bank Card\n");
  32. } else if(protocol == NfcDeviceProtocolMifareUl) {
  33. furi_string_cat_printf(
  34. temp_str, "\e#%s\n", nfc_mf_ul_type(dev_data->mf_ul_data.type, true));
  35. } else if(protocol == NfcDeviceProtocolMifareClassic) {
  36. furi_string_cat_printf(
  37. temp_str, "\e#%s\n", nfc_mf_classic_type(dev_data->mf_classic_data.type));
  38. } else if(protocol == NfcDeviceProtocolMifareDesfire) {
  39. furi_string_cat_printf(temp_str, "\e#MIFARE DESfire\n");
  40. } else {
  41. furi_string_cat_printf(temp_str, "\e#Unknown ISO tag\n");
  42. }
  43. // Set tag iso data
  44. char iso_type = FURI_BIT(nfc_data->sak, 5) ? '4' : '3';
  45. furi_string_cat_printf(temp_str, "ISO 14443-%c (NFC-A)\n", iso_type);
  46. furi_string_cat_printf(temp_str, "UID:");
  47. for(size_t i = 0; i < nfc_data->uid_len; i++) {
  48. furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
  49. }
  50. furi_string_cat_printf(temp_str, "\nATQA: %02X %02X ", nfc_data->atqa[1], nfc_data->atqa[0]);
  51. furi_string_cat_printf(temp_str, " SAK: %02X", nfc_data->sak);
  52. // Set application specific data
  53. if(protocol == NfcDeviceProtocolMifareDesfire) {
  54. MifareDesfireData* data = &dev_data->mf_df_data;
  55. uint32_t bytes_total = 1UL << (data->version.sw_storage >> 1);
  56. uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0;
  57. furi_string_cat_printf(temp_str, "\n%lu", bytes_total);
  58. if(data->version.sw_storage & 1) {
  59. furi_string_push_back(temp_str, '+');
  60. }
  61. furi_string_cat_printf(temp_str, " bytes, %lu bytes free\n", bytes_free);
  62. uint16_t n_apps = 0;
  63. uint16_t n_files = 0;
  64. for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
  65. n_apps++;
  66. for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
  67. n_files++;
  68. }
  69. }
  70. furi_string_cat_printf(temp_str, "%d Application", n_apps);
  71. if(n_apps != 1) {
  72. furi_string_push_back(temp_str, 's');
  73. }
  74. furi_string_cat_printf(temp_str, ", %d file", n_files);
  75. if(n_files != 1) {
  76. furi_string_push_back(temp_str, 's');
  77. }
  78. } else if(protocol == NfcDeviceProtocolMifareUl) {
  79. MfUltralightData* data = &dev_data->mf_ul_data;
  80. furi_string_cat_printf(
  81. temp_str, "\nPages Read %d/%d", data->data_read / 4, data->data_size / 4);
  82. if(data->data_size > data->data_read) {
  83. furi_string_cat_printf(temp_str, "\nPassword-protected");
  84. } else if(data->auth_success) {
  85. MfUltralightConfigPages* config_pages = mf_ultralight_get_config_pages(data);
  86. if(config_pages) {
  87. furi_string_cat_printf(
  88. temp_str,
  89. "\nPassword: %02X %02X %02X %02X",
  90. config_pages->auth_data.pwd.raw[0],
  91. config_pages->auth_data.pwd.raw[1],
  92. config_pages->auth_data.pwd.raw[2],
  93. config_pages->auth_data.pwd.raw[3]);
  94. furi_string_cat_printf(
  95. temp_str,
  96. "\nPACK: %02X %02X",
  97. config_pages->auth_data.pack.raw[0],
  98. config_pages->auth_data.pack.raw[1]);
  99. }
  100. }
  101. } else if(protocol == NfcDeviceProtocolMifareClassic) {
  102. MfClassicData* data = &dev_data->mf_classic_data;
  103. uint8_t sectors_total = mf_classic_get_total_sectors_num(data->type);
  104. uint8_t keys_total = sectors_total * 2;
  105. uint8_t keys_found = 0;
  106. uint8_t sectors_read = 0;
  107. mf_classic_get_read_sectors_and_keys(data, &sectors_read, &keys_found);
  108. furi_string_cat_printf(temp_str, "\nKeys Found %d/%d", keys_found, keys_total);
  109. furi_string_cat_printf(temp_str, "\nSectors Read %d/%d", sectors_read, sectors_total);
  110. }
  111. // Add text scroll widget
  112. widget_add_text_scroll_element(
  113. widget, 0, 0, 128, text_scroll_height, furi_string_get_cstr(temp_str));
  114. furi_string_free(temp_str);
  115. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  116. }
  117. bool nfc_scene_nfc_data_info_on_event(void* context, SceneManagerEvent event) {
  118. Nfc* nfc = context;
  119. NfcProtocol protocol = nfc->dev->dev_data.protocol;
  120. bool consumed = false;
  121. if(event.type == SceneManagerEventTypeCustom) {
  122. if(event.event == GuiButtonTypeRight) {
  123. if(protocol == NfcDeviceProtocolMifareDesfire) {
  124. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfDesfireData);
  125. consumed = true;
  126. } else if(protocol == NfcDeviceProtocolMifareUl) {
  127. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightData);
  128. consumed = true;
  129. } else if(protocol == NfcDeviceProtocolMifareClassic) {
  130. scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicData);
  131. consumed = true;
  132. }
  133. }
  134. }
  135. return consumed;
  136. }
  137. void nfc_scene_nfc_data_info_on_exit(void* context) {
  138. Nfc* nfc = context;
  139. widget_reset(nfc->widget);
  140. }