seos_scene_info.c 3.4 KB

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