nfc_scene_read_emv_app_success.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "../nfc_i.h"
  2. #include "../helpers/nfc_emv_parser.h"
  3. #include <dolphin/dolphin.h>
  4. #define NFC_SCENE_READ_SUCCESS_SHIFT " "
  5. void nfc_scene_read_emv_app_success_dialog_callback(DialogExResult result, void* context) {
  6. Nfc* nfc = (Nfc*)context;
  7. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  8. }
  9. void nfc_scene_read_emv_app_success_on_enter(void* context) {
  10. Nfc* nfc = (Nfc*)context;
  11. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  12. // Setup view
  13. NfcDeviceCommonData* nfc_data = &nfc->dev->dev_data.nfc_data;
  14. NfcEmvData* emv_data = &nfc->dev->dev_data.emv_data;
  15. DialogEx* dialog_ex = nfc->dialog_ex;
  16. dialog_ex_set_left_button_text(dialog_ex, "Retry");
  17. dialog_ex_set_right_button_text(dialog_ex, "Run app");
  18. dialog_ex_set_header(dialog_ex, "Found EMV App", 36, 8, AlignLeft, AlignCenter);
  19. dialog_ex_set_icon(dialog_ex, 8, 13, &I_Medium_chip_22x21);
  20. // Display UID and AID
  21. string_t aid;
  22. string_init(aid);
  23. bool aid_found =
  24. nfc_emv_parser_get_aid_name(nfc->dev->storage, emv_data->aid, emv_data->aid_len, aid);
  25. if(!aid_found) {
  26. for(uint8_t i = 0; i < emv_data->aid_len; i++) {
  27. string_cat_printf(aid, "%02X", emv_data->aid[i]);
  28. }
  29. }
  30. nfc_text_store_set(
  31. nfc,
  32. NFC_SCENE_READ_SUCCESS_SHIFT "UID: %02X %02X %02X %02X \n" NFC_SCENE_READ_SUCCESS_SHIFT
  33. "Application:\n%s",
  34. nfc_data->uid[0],
  35. nfc_data->uid[1],
  36. nfc_data->uid[2],
  37. nfc_data->uid[3],
  38. string_get_cstr(aid));
  39. string_clear(aid);
  40. dialog_ex_set_text(dialog_ex, nfc->text_store, 8, 16, AlignLeft, AlignTop);
  41. dialog_ex_set_context(dialog_ex, nfc);
  42. dialog_ex_set_result_callback(dialog_ex, nfc_scene_read_emv_app_success_dialog_callback);
  43. // Send notification
  44. if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneReadEmvAppSuccess) ==
  45. NFC_SEND_NOTIFICATION_TRUE) {
  46. notification_message(nfc->notifications, &sequence_success);
  47. scene_manager_set_scene_state(
  48. nfc->scene_manager, NfcSceneReadEmvAppSuccess, NFC_SEND_NOTIFICATION_FALSE);
  49. }
  50. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
  51. }
  52. bool nfc_scene_read_emv_app_success_on_event(void* context, SceneManagerEvent event) {
  53. Nfc* nfc = (Nfc*)context;
  54. if(event.type == SceneManagerEventTypeCustom) {
  55. if(event.event == DialogExResultLeft) {
  56. return scene_manager_previous_scene(nfc->scene_manager);
  57. } else if(event.event == DialogExResultRight) {
  58. scene_manager_next_scene(nfc->scene_manager, NfcSceneRunEmvAppConfirm);
  59. return true;
  60. }
  61. }
  62. return false;
  63. }
  64. void nfc_scene_read_emv_app_success_on_exit(void* context) {
  65. Nfc* nfc = (Nfc*)context;
  66. DialogEx* dialog_ex = nfc->dialog_ex;
  67. dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
  68. dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
  69. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  70. dialog_ex_set_left_button_text(dialog_ex, NULL);
  71. dialog_ex_set_right_button_text(dialog_ex, NULL);
  72. dialog_ex_set_result_callback(dialog_ex, NULL);
  73. dialog_ex_set_context(dialog_ex, NULL);
  74. }