nfc_scene_nfc_data_info.c 6.0 KB

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