nfc_scene_read_emv_app_success.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "../nfc_i.h"
  2. #include "../helpers/nfc_emv_parser.h"
  3. #include <dolphin/dolphin.h>
  4. void nfc_scene_read_emv_app_widget_callback(GuiButtonType result, InputType type, void* context) {
  5. Nfc* nfc = context;
  6. if(type == InputTypeShort) {
  7. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  8. }
  9. }
  10. void nfc_scene_read_emv_app_success_on_enter(void* context) {
  11. Nfc* nfc = context;
  12. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  13. // Setup view
  14. FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
  15. EmvData* emv_data = &nfc->dev->dev_data.emv_data;
  16. Widget* widget = nfc->widget;
  17. widget_add_button_element(
  18. widget, GuiButtonTypeLeft, "Retry", nfc_scene_read_emv_app_widget_callback, nfc);
  19. widget_add_button_element(
  20. widget, GuiButtonTypeRight, "Run app", nfc_scene_read_emv_app_widget_callback, nfc);
  21. widget_add_string_element(widget, 36, 5, AlignLeft, AlignTop, FontPrimary, "Found EMV App");
  22. widget_add_icon_element(widget, 8, 5, &I_Medium_chip_22x21);
  23. // Display UID
  24. string_t temp_str;
  25. string_init_printf(temp_str, "UID:");
  26. for(size_t i = 0; i < nfc_data->uid_len; i++) {
  27. string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
  28. }
  29. widget_add_string_element(
  30. widget, 36, 18, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str));
  31. string_reset(temp_str);
  32. // Display application
  33. string_printf(temp_str, "App: ");
  34. string_t aid;
  35. string_init(aid);
  36. bool aid_found =
  37. nfc_emv_parser_get_aid_name(nfc->dev->storage, emv_data->aid, emv_data->aid_len, aid);
  38. if(!aid_found) {
  39. for(uint8_t i = 0; i < emv_data->aid_len; i++) {
  40. string_cat_printf(aid, "%02X", emv_data->aid[i]);
  41. }
  42. }
  43. string_cat(temp_str, aid);
  44. widget_add_string_element(
  45. widget, 7, 29, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str));
  46. string_clear(temp_str);
  47. string_clear(aid);
  48. // Send notification
  49. if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneReadEmvAppSuccess) ==
  50. NFC_SEND_NOTIFICATION_TRUE) {
  51. notification_message(nfc->notifications, &sequence_success);
  52. scene_manager_set_scene_state(
  53. nfc->scene_manager, NfcSceneReadEmvAppSuccess, NFC_SEND_NOTIFICATION_FALSE);
  54. }
  55. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  56. }
  57. bool nfc_scene_read_emv_app_success_on_event(void* context, SceneManagerEvent event) {
  58. Nfc* nfc = context;
  59. bool consumed = false;
  60. if(event.type == SceneManagerEventTypeCustom) {
  61. if(event.event == GuiButtonTypeLeft) {
  62. consumed = scene_manager_previous_scene(nfc->scene_manager);
  63. } else if(event.event == GuiButtonTypeRight) {
  64. scene_manager_next_scene(nfc->scene_manager, NfcSceneRunEmvAppConfirm);
  65. consumed = true;
  66. }
  67. }
  68. return consumed;
  69. }
  70. void nfc_scene_read_emv_app_success_on_exit(void* context) {
  71. Nfc* nfc = context;
  72. // Clear views
  73. widget_reset(nfc->widget);
  74. }