nfc_scene_emv_read_success.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "../nfc_i.h"
  2. #include "../helpers/nfc_emv_parser.h"
  3. #include <dolphin/dolphin.h>
  4. void nfc_scene_emv_read_success_widget_callback(
  5. GuiButtonType result,
  6. InputType type,
  7. void* 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_emv_read_success_on_enter(void* context) {
  14. Nfc* nfc = context;
  15. EmvData* emv_data = &nfc->dev->dev_data.emv_data;
  16. FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
  17. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  18. // Setup Custom Widget view
  19. // Add frame
  20. widget_add_frame_element(nfc->widget, 0, 0, 128, 64, 6);
  21. // Add buttons
  22. widget_add_button_element(
  23. nfc->widget, GuiButtonTypeLeft, "Retry", nfc_scene_emv_read_success_widget_callback, nfc);
  24. widget_add_button_element(
  25. nfc->widget, GuiButtonTypeRight, "Save", nfc_scene_emv_read_success_widget_callback, nfc);
  26. // Add card name
  27. widget_add_string_element(
  28. nfc->widget, 64, 3, AlignCenter, AlignTop, FontSecondary, nfc->dev->dev_data.emv_data.name);
  29. // Add card number
  30. string_t pan_str;
  31. string_init(pan_str);
  32. for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
  33. string_cat_printf(pan_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
  34. }
  35. string_strim(pan_str);
  36. widget_add_string_element(
  37. nfc->widget, 64, 13, AlignCenter, AlignTop, FontSecondary, string_get_cstr(pan_str));
  38. string_clear(pan_str);
  39. // Parse country code
  40. string_t country_name;
  41. string_init(country_name);
  42. if((emv_data->country_code) &&
  43. nfc_emv_parser_get_country_name(nfc->dev->storage, emv_data->country_code, country_name)) {
  44. string_t disp_country;
  45. string_init_printf(disp_country, "Reg:%s", country_name);
  46. widget_add_string_element(
  47. nfc->widget, 7, 23, AlignLeft, AlignTop, FontSecondary, string_get_cstr(disp_country));
  48. string_clear(disp_country);
  49. }
  50. string_clear(country_name);
  51. // Parse currency code
  52. string_t currency_name;
  53. string_init(currency_name);
  54. if((emv_data->currency_code) &&
  55. nfc_emv_parser_get_currency_name(
  56. nfc->dev->storage, emv_data->currency_code, currency_name)) {
  57. string_t disp_currency;
  58. string_init_printf(disp_currency, "Cur:%s", currency_name);
  59. widget_add_string_element(
  60. nfc->widget,
  61. 121,
  62. 23,
  63. AlignRight,
  64. AlignTop,
  65. FontSecondary,
  66. string_get_cstr(disp_currency));
  67. string_clear(disp_currency);
  68. }
  69. string_clear(currency_name);
  70. char temp_str[32];
  71. // Add ATQA
  72. snprintf(temp_str, sizeof(temp_str), "ATQA: %02X%02X", nfc_data->atqa[0], nfc_data->atqa[1]);
  73. widget_add_string_element(nfc->widget, 121, 32, AlignRight, AlignTop, FontSecondary, temp_str);
  74. // Add UID
  75. snprintf(
  76. temp_str,
  77. sizeof(temp_str),
  78. "UID: %02X %02X %02X %02X",
  79. nfc_data->uid[0],
  80. nfc_data->uid[1],
  81. nfc_data->uid[2],
  82. nfc_data->uid[3]);
  83. widget_add_string_element(nfc->widget, 7, 42, AlignLeft, AlignTop, FontSecondary, temp_str);
  84. // Add SAK
  85. snprintf(temp_str, sizeof(temp_str), "SAK: %02X", nfc_data->sak);
  86. widget_add_string_element(nfc->widget, 121, 42, AlignRight, AlignTop, FontSecondary, temp_str);
  87. // Add expiration date
  88. if(emv_data->exp_mon) {
  89. char exp_str[16];
  90. snprintf(
  91. exp_str, sizeof(exp_str), "Exp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
  92. widget_add_string_element(nfc->widget, 7, 32, AlignLeft, AlignTop, FontSecondary, exp_str);
  93. }
  94. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  95. }
  96. bool nfc_scene_emv_read_success_on_event(void* context, SceneManagerEvent event) {
  97. Nfc* nfc = context;
  98. bool consumed = false;
  99. if(event.type == SceneManagerEventTypeCustom) {
  100. if(event.event == GuiButtonTypeLeft) {
  101. scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
  102. consumed = true;
  103. } else if(event.event == GuiButtonTypeRight) {
  104. // Clear device name
  105. nfc_device_set_name(nfc->dev, "");
  106. nfc->dev->format = NfcDeviceSaveFormatBankCard;
  107. scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
  108. consumed = true;
  109. }
  110. } else if(event.type == SceneManagerEventTypeBack) {
  111. scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
  112. consumed = true;
  113. }
  114. return consumed;
  115. }
  116. void nfc_scene_emv_read_success_on_exit(void* context) {
  117. Nfc* nfc = context;
  118. // Clear view
  119. widget_reset(nfc->widget);
  120. }