passy_scene_read_success.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "../passy_i.h"
  2. #include <dolphin/dolphin.h>
  3. #define ASN_EMIT_DEBUG 0
  4. #include <lib/asn1/DG1.h>
  5. #define TAG "PassySceneReadCardSuccess"
  6. void passy_scene_read_success_on_enter(void* context) {
  7. Passy* passy = context;
  8. dolphin_deed(DolphinDeedNfcReadSuccess);
  9. notification_message(passy->notifications, &sequence_success);
  10. furi_string_reset(passy->text_box_store);
  11. FuriString* str = passy->text_box_store;
  12. if(passy->read_type == PassyReadDG1) {
  13. DG1_t* dg1 = 0;
  14. dg1 = calloc(1, sizeof *dg1);
  15. assert(dg1);
  16. asn_dec_rval_t rval = asn_decode(
  17. 0,
  18. ATS_DER,
  19. &asn_DEF_DG1,
  20. (void**)&dg1,
  21. bit_buffer_get_data(passy->DG1),
  22. bit_buffer_get_size_bytes(passy->DG1));
  23. if(rval.code == RC_OK) {
  24. FURI_LOG_I(TAG, "ASN.1 decode success");
  25. char payloadDebug[384] = {0};
  26. memset(payloadDebug, 0, sizeof(payloadDebug));
  27. (&asn_DEF_DG1)
  28. ->op->print_struct(&asn_DEF_DG1, dg1, 1, print_struct_callback, payloadDebug);
  29. if(strlen(payloadDebug) > 0) {
  30. FURI_LOG_D(TAG, "DG1: %s", payloadDebug);
  31. } else {
  32. FURI_LOG_D(TAG, "Received empty Payload");
  33. }
  34. furi_string_cat_printf(str, "%s\n", dg1->mrz.buf);
  35. } else {
  36. FURI_LOG_E(TAG, "ASN.1 decode failed: %d. %d consumed", rval.code, rval.consumed);
  37. furi_string_cat_printf(str, "%s\n", bit_buffer_get_data(passy->DG1));
  38. }
  39. free(dg1);
  40. dg1 = 0;
  41. } else if(passy->read_type == PassyReadDG2) {
  42. furi_string_cat_printf(str, "Saved to disk");
  43. }
  44. text_box_set_font(passy->text_box, TextBoxFontText);
  45. text_box_set_text(passy->text_box, furi_string_get_cstr(passy->text_box_store));
  46. view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewTextBox);
  47. }
  48. bool passy_scene_read_success_on_event(void* context, SceneManagerEvent event) {
  49. Passy* passy = context;
  50. bool consumed = false;
  51. if(event.type == SceneManagerEventTypeCustom) {
  52. } else if(event.type == SceneManagerEventTypeBack) {
  53. scene_manager_search_and_switch_to_previous_scene(
  54. passy->scene_manager, PassySceneMainMenu);
  55. consumed = true;
  56. }
  57. return consumed;
  58. }
  59. void passy_scene_read_success_on_exit(void* context) {
  60. Passy* passy = context;
  61. // Clear view
  62. text_box_reset(passy->text_box);
  63. }