picopass_scene_device_info.c 3.7 KB

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