picopass_scene_read_card_success.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "../picopass_i.h"
  2. #include <dolphin/dolphin.h>
  3. void picopass_scene_read_card_success_widget_callback(
  4. GuiButtonType result,
  5. InputType type,
  6. void* context) {
  7. furi_assert(context);
  8. Picopass* picopass = context;
  9. if(type == InputTypeShort) {
  10. view_dispatcher_send_custom_event(picopass->view_dispatcher, result);
  11. }
  12. }
  13. void picopass_scene_read_card_success_on_enter(void* context) {
  14. Picopass* picopass = context;
  15. FuriString* csn_str = furi_string_alloc_set("CSN:");
  16. FuriString* credential_str = furi_string_alloc();
  17. FuriString* wiegand_str = furi_string_alloc();
  18. FuriString* sio_str = furi_string_alloc();
  19. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  20. // Send notification
  21. notification_message(picopass->notifications, &sequence_success);
  22. // Setup view
  23. PicopassBlock* AA1 = picopass->dev->dev_data.AA1;
  24. PicopassPacs* pacs = &picopass->dev->dev_data.pacs;
  25. Widget* widget = picopass->widget;
  26. uint8_t csn[PICOPASS_BLOCK_LEN];
  27. memcpy(csn, &AA1->data[PICOPASS_CSN_BLOCK_INDEX], PICOPASS_BLOCK_LEN);
  28. for(uint8_t i = 0; i < PICOPASS_BLOCK_LEN; i++) {
  29. furi_string_cat_printf(csn_str, " %02X", csn[i]);
  30. }
  31. // Neither of these are valid. Indicates the block was all 0x00 or all 0xff
  32. if(pacs->record.bitLength == 0 || pacs->record.bitLength == 255) {
  33. furi_string_cat_printf(wiegand_str, "Read Failed");
  34. if(pacs->se_enabled) {
  35. furi_string_cat_printf(credential_str, "SE enabled");
  36. }
  37. widget_add_button_element(
  38. widget,
  39. GuiButtonTypeLeft,
  40. "Retry",
  41. picopass_scene_read_card_success_widget_callback,
  42. picopass);
  43. } else {
  44. size_t bytesLength = 1 + pacs->record.bitLength / 8;
  45. furi_string_set(credential_str, "");
  46. for(uint8_t i = PICOPASS_BLOCK_LEN - bytesLength; i < PICOPASS_BLOCK_LEN; i++) {
  47. furi_string_cat_printf(credential_str, " %02X", pacs->credential[i]);
  48. }
  49. if(pacs->record.valid) {
  50. furi_string_cat_printf(
  51. wiegand_str, "FC: %u CN: %u", pacs->record.FacilityCode, pacs->record.CardNumber);
  52. } else {
  53. furi_string_cat_printf(wiegand_str, "%d bits", pacs->record.bitLength);
  54. }
  55. if(pacs->sio) {
  56. furi_string_cat_printf(sio_str, "+SIO");
  57. }
  58. widget_add_button_element(
  59. widget,
  60. GuiButtonTypeLeft,
  61. "Retry",
  62. picopass_scene_read_card_success_widget_callback,
  63. picopass);
  64. widget_add_button_element(
  65. widget,
  66. GuiButtonTypeRight,
  67. "More",
  68. picopass_scene_read_card_success_widget_callback,
  69. picopass);
  70. }
  71. widget_add_string_element(
  72. widget, 64, 5, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(csn_str));
  73. widget_add_string_element(
  74. widget, 64, 20, AlignCenter, AlignCenter, FontPrimary, furi_string_get_cstr(wiegand_str));
  75. widget_add_string_element(
  76. widget,
  77. 64,
  78. 36,
  79. AlignCenter,
  80. AlignCenter,
  81. FontSecondary,
  82. furi_string_get_cstr(credential_str));
  83. widget_add_string_element(
  84. widget, 64, 46, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(sio_str));
  85. furi_string_free(csn_str);
  86. furi_string_free(credential_str);
  87. furi_string_free(wiegand_str);
  88. furi_string_free(sio_str);
  89. view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
  90. }
  91. bool picopass_scene_read_card_success_on_event(void* context, SceneManagerEvent event) {
  92. Picopass* picopass = context;
  93. bool consumed = false;
  94. if(event.type == SceneManagerEventTypeCustom) {
  95. if(event.event == GuiButtonTypeLeft) {
  96. consumed = scene_manager_previous_scene(picopass->scene_manager);
  97. } else if(event.event == GuiButtonTypeRight) {
  98. // Clear device name
  99. picopass_device_set_name(picopass->dev, "");
  100. scene_manager_next_scene(picopass->scene_manager, PicopassSceneCardMenu);
  101. consumed = true;
  102. }
  103. }
  104. return consumed;
  105. }
  106. void picopass_scene_read_card_success_on_exit(void* context) {
  107. Picopass* picopass = context;
  108. // Clear view
  109. widget_reset(picopass->widget);
  110. }