picopass_scene_device_info.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "../picopass_i.h"
  2. #include <dolphin/dolphin.h>
  3. void picopass_scene_device_info_widget_callback(
  4. GuiButtonType result,
  5. InputType type,
  6. void* context) {
  7. Picopass* picopass = context;
  8. if(type == InputTypeShort) {
  9. view_dispatcher_send_custom_event(picopass->view_dispatcher, result);
  10. }
  11. }
  12. void picopass_scene_device_info_on_enter(void* context) {
  13. Picopass* picopass = context;
  14. FuriString* csn_str = furi_string_alloc_set("CSN:");
  15. FuriString* credential_str = furi_string_alloc();
  16. FuriString* wiegand_str = furi_string_alloc();
  17. FuriString* sio_str = furi_string_alloc();
  18. dolphin_deed(DolphinDeedNfcReadSuccess);
  19. // Setup view
  20. PicopassBlock* AA1 = picopass->dev->dev_data.AA1;
  21. PicopassPacs* pacs = &picopass->dev->dev_data.pacs;
  22. Widget* widget = picopass->widget;
  23. uint8_t csn[RFAL_PICOPASS_BLOCK_LEN] = {0};
  24. memcpy(csn, AA1[PICOPASS_CSN_BLOCK_INDEX].data, RFAL_PICOPASS_BLOCK_LEN);
  25. for(uint8_t i = 0; i < RFAL_PICOPASS_BLOCK_LEN; i++) {
  26. furi_string_cat_printf(csn_str, "%02X ", csn[i]);
  27. }
  28. if(pacs->record.bitLength == 0 || pacs->record.bitLength == 255) {
  29. // Neither of these are valid. Indicates the block was all 0x00 or all 0xff
  30. furi_string_cat_printf(wiegand_str, "Invalid PACS");
  31. } else {
  32. size_t bytesLength = pacs->record.bitLength / 8;
  33. if(pacs->record.bitLength % 8 > 0) {
  34. // Add extra byte if there are bits remaining
  35. bytesLength++;
  36. }
  37. furi_string_set(credential_str, "");
  38. for(uint8_t i = RFAL_PICOPASS_BLOCK_LEN - bytesLength; i < RFAL_PICOPASS_BLOCK_LEN; i++) {
  39. furi_string_cat_printf(credential_str, " %02X", pacs->credential[i]);
  40. }
  41. if(pacs->record.valid) {
  42. furi_string_cat_printf(
  43. wiegand_str, "FC: %u CN: %u", pacs->record.FacilityCode, pacs->record.CardNumber);
  44. } else {
  45. furi_string_cat_printf(wiegand_str, "%d bits", pacs->record.bitLength);
  46. }
  47. if(pacs->sio) {
  48. furi_string_cat_printf(sio_str, "+SIO");
  49. }
  50. }
  51. widget_add_string_element(
  52. widget, 64, 5, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(csn_str));
  53. widget_add_string_element(
  54. widget, 64, 20, AlignCenter, AlignCenter, FontPrimary, furi_string_get_cstr(wiegand_str));
  55. widget_add_string_element(
  56. widget,
  57. 64,
  58. 36,
  59. AlignCenter,
  60. AlignCenter,
  61. FontSecondary,
  62. furi_string_get_cstr(credential_str));
  63. widget_add_string_element(
  64. widget, 64, 46, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(sio_str));
  65. furi_string_free(csn_str);
  66. furi_string_free(credential_str);
  67. furi_string_free(wiegand_str);
  68. furi_string_free(sio_str);
  69. widget_add_button_element(
  70. picopass->widget,
  71. GuiButtonTypeLeft,
  72. "Back",
  73. picopass_scene_device_info_widget_callback,
  74. picopass);
  75. view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
  76. }
  77. bool picopass_scene_device_info_on_event(void* context, SceneManagerEvent event) {
  78. Picopass* picopass = context;
  79. bool consumed = false;
  80. if(event.type == SceneManagerEventTypeCustom) {
  81. if(event.event == GuiButtonTypeLeft) {
  82. consumed = scene_manager_previous_scene(picopass->scene_manager);
  83. } else if(event.event == PicopassCustomEventViewExit) {
  84. view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
  85. consumed = true;
  86. }
  87. } else if(event.type == SceneManagerEventTypeBack) {
  88. view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
  89. consumed = true;
  90. }
  91. return consumed;
  92. }
  93. void picopass_scene_device_info_on_exit(void* context) {
  94. Picopass* picopass = context;
  95. // Clear views
  96. widget_reset(picopass->widget);
  97. }