nfc_scene_read_emv_app_success.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 = nfc_emv_parser_get_aid_name(emv_data->aid, emv_data->aid_len, aid);
  22. if(!aid_found) {
  23. for(uint8_t i = 0; i < emv_data->aid_len; i++) {
  24. string_cat_printf(aid, "%02X", emv_data->aid[i]);
  25. }
  26. }
  27. nfc_text_store_set(
  28. nfc,
  29. NFC_SCENE_READ_SUCCESS_SHIFT "UID: %02X %02X %02X %02X \n" NFC_SCENE_READ_SUCCESS_SHIFT
  30. "Application:\n%s",
  31. nfc_data->uid[0],
  32. nfc_data->uid[1],
  33. nfc_data->uid[2],
  34. nfc_data->uid[3],
  35. string_get_cstr(aid));
  36. string_clear(aid);
  37. dialog_ex_set_text(dialog_ex, nfc->text_store, 8, 16, AlignLeft, AlignTop);
  38. dialog_ex_set_context(dialog_ex, nfc);
  39. dialog_ex_set_result_callback(dialog_ex, nfc_scene_read_emv_app_success_dialog_callback);
  40. // Send notification
  41. if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneReadEmvAppSuccess) ==
  42. NFC_SEND_NOTIFICATION_TRUE) {
  43. notification_message(nfc->notifications, &sequence_success);
  44. scene_manager_set_scene_state(
  45. nfc->scene_manager, NfcSceneReadEmvAppSuccess, NFC_SEND_NOTIFICATION_FALSE);
  46. }
  47. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
  48. }
  49. bool nfc_scene_read_emv_app_success_on_event(void* context, SceneManagerEvent event) {
  50. Nfc* nfc = (Nfc*)context;
  51. if(event.type == SceneManagerEventTypeCustom) {
  52. if(event.event == DialogExResultLeft) {
  53. return scene_manager_previous_scene(nfc->scene_manager);
  54. } else if(event.event == DialogExResultRight) {
  55. scene_manager_next_scene(nfc->scene_manager, NfcSceneRunEmvAppConfirm);
  56. return true;
  57. }
  58. }
  59. return false;
  60. }
  61. void nfc_scene_read_emv_app_success_on_exit(void* context) {
  62. Nfc* nfc = (Nfc*)context;
  63. DialogEx* dialog_ex = nfc->dialog_ex;
  64. dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
  65. dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
  66. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  67. dialog_ex_set_left_button_text(dialog_ex, NULL);
  68. dialog_ex_set_right_button_text(dialog_ex, NULL);
  69. dialog_ex_set_result_callback(dialog_ex, NULL);
  70. dialog_ex_set_context(dialog_ex, NULL);
  71. }