gen4.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #include "core/common_defines.h"
  3. #include <stdint.h>
  4. #define GEN4_CONFIG_SIZE (32)
  5. #define GEN4_REVISION_SIZE (5)
  6. #define GEN4_PASSWORD_LEN (4)
  7. #define GEN4_ATS_MAX_LEN (16)
  8. #define GEN4_ATQA_LEN (2)
  9. #define GEN4_CRC_LEN (2)
  10. typedef enum {
  11. Gen4ProtocolMfClassic = 0x00,
  12. Gen4ProtocolMfUltralight = 0x01,
  13. } Gen4Protocol;
  14. typedef struct {
  15. uint8_t bytes[GEN4_PASSWORD_LEN];
  16. } Gen4Password;
  17. typedef enum {
  18. Gen4UIDLengthSingle = 0x00,
  19. Gen4UIDLengthDouble = 0x01,
  20. Gen4UIDLengthTriple = 0x02
  21. } Gen4UIDLength;
  22. typedef enum {
  23. Gen4UltralightModeUL_EV1 = 0x00,
  24. Gen4UltralightModeNTAG = 0x01,
  25. Gen4UltralightModeUL_C = 0x02,
  26. Gen4UltralightModeUL = 0x03
  27. } Gen4UltralightMode;
  28. typedef enum {
  29. // for writing original (shadow) data
  30. Gen4ShadowModePreWrite = 0x00,
  31. // written data can be read once before restored to original
  32. Gen4ShadowModeRestore = 0x01,
  33. // shadow mode disabled
  34. Gen4ShadowModeDisabled = 0x02,
  35. // apparently for UL?
  36. Gen4ShadowModeHighSpeedDisabled = 0x03,
  37. // work with new UMC. With old UMC is untested
  38. Gen4ShadowModeSplit = 0x04,
  39. } Gen4ShadowMode;
  40. typedef enum {
  41. // gen2 card behavour
  42. Gen4DirectWriteBlock0ModeEnabled = 0x00,
  43. // common card behavour
  44. Gen4DirectWriteBlock0ModeDisabled = 0x01,
  45. // default mode. same behavour as Gen4DirectWriteBlock0ModeActivate
  46. Gen4DirectWriteBlock0ModeDefault = 0x02,
  47. } Gen4DirectWriteBlock0Mode;
  48. typedef union {
  49. uint8_t data_raw[GEN4_CONFIG_SIZE];
  50. struct {
  51. Gen4Protocol protocol;
  52. Gen4UIDLength uid_len_code;
  53. Gen4Password password;
  54. Gen4ShadowMode gtu_mode;
  55. uint8_t ats_len;
  56. uint8_t ats[GEN4_ATS_MAX_LEN]; // mb another class?
  57. uint8_t atqa[GEN4_ATQA_LEN];
  58. uint8_t sak;
  59. Gen4UltralightMode mfu_mode;
  60. uint8_t total_blocks;
  61. Gen4DirectWriteBlock0Mode direct_write_mode;
  62. uint8_t crc[GEN4_CRC_LEN];
  63. } FURI_PACKED data_parsed;
  64. } Gen4Config;
  65. typedef struct {
  66. uint8_t data[GEN4_REVISION_SIZE];
  67. } Gen4Revision;
  68. typedef struct {
  69. Gen4Config config;
  70. Gen4Revision revision;
  71. } Gen4;
  72. Gen4* gen4_alloc();
  73. void gen4_free(Gen4* instance);
  74. void gen4_reset(Gen4* instance);
  75. void gen4_copy(Gen4* dest, const Gen4* source);
  76. bool gen4_password_is_set(const Gen4Password* instance);
  77. void gen4_password_reset(Gen4Password* instance);
  78. void gen4_password_copy(Gen4Password* dest, const Gen4Password* source);
  79. const char* gen4_get_shadow_mode_name(Gen4ShadowMode mode);
  80. const char* gen4_get_direct_write_mode_name(Gen4DirectWriteBlock0Mode mode);
  81. const char* gen4_get_uid_len_num(Gen4UIDLength code);
  82. const char* gen4_get_configuration_name(const Gen4Config* config);