gen4.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "gen4.h"
  2. #include "core/check.h"
  3. Gen4* gen4_alloc() {
  4. Gen4* instance = malloc(sizeof(Gen4));
  5. return instance;
  6. }
  7. void gen4_free(Gen4* instance) {
  8. furi_check(instance);
  9. free(instance);
  10. }
  11. void gen4_reset(Gen4* instance) {
  12. furi_check(instance);
  13. memset(&instance->config, 0, sizeof(Gen4Config));
  14. memset(&instance->revision, 0, sizeof(Gen4Revision));
  15. }
  16. void gen4_copy(Gen4* dest, const Gen4* source) {
  17. furi_check(dest);
  18. furi_check(source);
  19. memcpy(dest, source, sizeof(Gen4));
  20. }
  21. bool gen4_password_is_set(const Gen4Password* instance) {
  22. furi_check(instance);
  23. return (instance->bytes[0] || instance->bytes[1] || instance->bytes[2] || instance->bytes[3]);
  24. }
  25. void gen4_password_reset(Gen4Password* instance) {
  26. furi_check(instance);
  27. memset(instance->bytes, 0, GEN4_PASSWORD_LEN);
  28. }
  29. void gen4_password_copy(Gen4Password* dest, const Gen4Password* source) {
  30. furi_check(dest);
  31. furi_check(source);
  32. memcpy(dest->bytes, source->bytes, GEN4_PASSWORD_LEN);
  33. }
  34. const char* gen4_get_shadow_mode_name(Gen4ShadowMode mode) {
  35. switch(mode) {
  36. case Gen4ShadowModePreWrite:
  37. return "Pre-Write";
  38. case Gen4ShadowModeRestore:
  39. return "Restore";
  40. case Gen4ShadowModeDisabled:
  41. return "Disabled";
  42. case Gen4ShadowModeHighSpeedDisabled:
  43. return "Disabled (High-speed)";
  44. case Gen4ShadowModeSplit:
  45. return "Split";
  46. default:
  47. return "Unknown";
  48. }
  49. }
  50. const char* gen4_get_direct_write_mode_name(Gen4DirectWriteBlock0Mode mode) {
  51. switch(mode) {
  52. case Gen4DirectWriteBlock0ModeEnabled:
  53. return "Enabled";
  54. case Gen4DirectWriteBlock0ModeDisabled:
  55. return "Disabled";
  56. case Gen4DirectWriteBlock0ModeDefault:
  57. return "Default";
  58. default:
  59. return "Unknown";
  60. }
  61. }
  62. const char* gen4_get_uid_len_num(Gen4UIDLength code) {
  63. switch(code) {
  64. case Gen4UIDLengthSingle:
  65. return "4";
  66. case Gen4UIDLengthDouble:
  67. return "7";
  68. case Gen4UIDLengthTriple:
  69. return "10";
  70. default:
  71. return "Unknown";
  72. }
  73. }
  74. const char* gen4_get_configuration_name(const Gen4Config* config) {
  75. switch(config->data_parsed.protocol) {
  76. case Gen4ProtocolMfClassic: {
  77. switch(config->data_parsed.total_blocks) {
  78. case 255:
  79. return "MIFARE Classic 4K";
  80. case 63:
  81. return "MIFARE Classic 1K";
  82. case 19:
  83. return "MIFARE Classic Mini (0.3K)";
  84. default:
  85. return "Unknown";
  86. }
  87. } break;
  88. case Gen4ProtocolMfUltralight: {
  89. switch(config->data_parsed.total_blocks) {
  90. case 63:
  91. return "MIFARE Ultralight";
  92. case 127:
  93. return "NTAG 2XX";
  94. default:
  95. return "Unknown";
  96. }
  97. } break;
  98. default:
  99. return "Unknown";
  100. break;
  101. };
  102. }