nfc_scene_read_emv_app_success.c 3.1 KB

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