seos_scene_read_success.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "../seos_i.h"
  2. #include <dolphin/dolphin.h>
  3. #define TAG "SeosSceneReadCardSuccess"
  4. void seos_scene_read_success_widget_callback(GuiButtonType result, InputType type, void* context) {
  5. furi_assert(context);
  6. Seos* seos = context;
  7. if(type == InputTypeShort) {
  8. view_dispatcher_send_custom_event(seos->view_dispatcher, result);
  9. }
  10. }
  11. void seos_scene_read_success_on_enter(void* context) {
  12. Seos* seos = context;
  13. SeosCredential* credential = seos->credential;
  14. Widget* widget = seos->widget;
  15. dolphin_deed(DolphinDeedNfcReadSuccess);
  16. FuriString* primary_str = furi_string_alloc_set("SIO Captured");
  17. FuriString* secondary_str_label = furi_string_alloc();
  18. FuriString* secondary_str_value = furi_string_alloc();
  19. FuriString* details_str = furi_string_alloc();
  20. furi_string_set(secondary_str_label, "Diversifier:");
  21. for(size_t i = 0; i < credential->diversifier_len; i++) {
  22. furi_string_cat_printf(secondary_str_value, "%02X", credential->diversifier[i]);
  23. }
  24. // RID
  25. if(credential->sio_len > 3 && credential->sio[2] == 0x81) {
  26. size_t len = credential->sio[3];
  27. furi_string_set(details_str, "RID:");
  28. for(size_t i = 0; i < len; i++) {
  29. furi_string_cat_printf(details_str, "%02X", credential->sio[4 + i]);
  30. }
  31. if(len >= 4 && credential->sio[3 + 1] == 0x01) {
  32. furi_string_cat_printf(details_str, "(retail)");
  33. } else if(len == 2) {
  34. furi_string_cat_printf(details_str, "(ER)");
  35. } else {
  36. furi_string_cat_printf(details_str, "(other)");
  37. }
  38. }
  39. widget_add_button_element(
  40. widget, GuiButtonTypeLeft, "Save", seos_scene_read_success_widget_callback, seos);
  41. widget_add_button_element(
  42. widget, GuiButtonTypeRight, "Emulate", seos_scene_read_success_widget_callback, seos);
  43. widget_add_string_element(
  44. widget, 64, 5, AlignCenter, AlignCenter, FontPrimary, furi_string_get_cstr(primary_str));
  45. widget_add_string_element(
  46. widget,
  47. 64,
  48. 20,
  49. AlignCenter,
  50. AlignCenter,
  51. FontSecondary,
  52. furi_string_get_cstr(secondary_str_label));
  53. widget_add_string_element(
  54. widget,
  55. 64,
  56. 30,
  57. AlignCenter,
  58. AlignCenter,
  59. FontSecondary,
  60. furi_string_get_cstr(secondary_str_value));
  61. widget_add_string_element(
  62. widget, 64, 45, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(details_str));
  63. furi_string_free(primary_str);
  64. furi_string_free(secondary_str_label);
  65. furi_string_free(secondary_str_value);
  66. furi_string_free(details_str);
  67. view_dispatcher_switch_to_view(seos->view_dispatcher, SeosViewWidget);
  68. }
  69. bool seos_scene_read_success_on_event(void* context, SceneManagerEvent event) {
  70. Seos* seos = context;
  71. bool consumed = false;
  72. if(event.type == SceneManagerEventTypeCustom) {
  73. if(event.event == GuiButtonTypeLeft) {
  74. scene_manager_next_scene(seos->scene_manager, SeosSceneSaveName);
  75. consumed = true;
  76. } else if(event.event == GuiButtonTypeRight) {
  77. scene_manager_next_scene(seos->scene_manager, SeosSceneSavedMenu);
  78. consumed = true;
  79. }
  80. } else if(event.type == SceneManagerEventTypeBack) {
  81. scene_manager_search_and_switch_to_previous_scene(seos->scene_manager, SeosSceneMainMenu);
  82. consumed = true;
  83. }
  84. return consumed;
  85. }
  86. void seos_scene_read_success_on_exit(void* context) {
  87. Seos* seos = context;
  88. // Clear view
  89. widget_reset(seos->widget);
  90. }