gen4.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include <stdint.h>
  3. #define GEN4_CONFIG_SIZE (32)
  4. #define GEN4_REVISION_SIZE (5)
  5. #define GEN4_PASSWORD_LEN (4)
  6. #define GEN4_ATS_MAX_LEN (16)
  7. #define GEN4_ATQA_LEN (2)
  8. #define GEN4_CRC_LEN (2)
  9. typedef enum {
  10. Gen4ProtocolMfClassic = 0x00,
  11. Gen4ProtocolMfUltralight = 0x01,
  12. } Gen4Protocol;
  13. typedef union {
  14. uint32_t value;
  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. #pragma pack(push, 1)
  51. struct {
  52. Gen4Protocol protocol;
  53. Gen4UIDLength uid_len_code;
  54. Gen4Password password;
  55. Gen4ShadowMode gtu_mode;
  56. uint8_t ats_len;
  57. uint8_t ats[GEN4_ATS_MAX_LEN]; // mb another class?
  58. uint8_t atqa[GEN4_ATQA_LEN];
  59. uint8_t sak;
  60. Gen4UltralightMode mfu_mode;
  61. uint8_t total_blocks;
  62. Gen4DirectWriteBlock0Mode direct_write_mode;
  63. uint8_t crc[GEN4_CRC_LEN];
  64. } data_parsed;
  65. #pragma pack(pop)
  66. } Gen4Config;
  67. typedef struct {
  68. uint8_t data[GEN4_REVISION_SIZE];
  69. } Gen4Revision;
  70. typedef struct {
  71. Gen4Config config;
  72. Gen4Revision revision;
  73. } Gen4;
  74. Gen4* gen4_alloc();
  75. void gen4_free(Gen4* instance);
  76. void gen4_reset(Gen4* instance);
  77. void gen4_copy(Gen4* dest, const Gen4* source);
  78. char* gen4_get_shadow_mode_name(Gen4ShadowMode mode);
  79. char* gen4_get_direct_write_mode_name(Gen4DirectWriteBlock0Mode mode);
  80. char* gen4_get_uid_len_num(Gen4UIDLength code);
  81. char* gen4_get_configuration_name(const Gen4Config* config);