gen4_poller_i.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #pragma once
  2. #include "gen4_poller.h"
  3. #include <nfc/nfc_poller.h>
  4. #include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
  5. #include <bit_lib.h>
  6. #define TAG "Gen4Poller"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #define GEN4_POLLER_MAX_BUFFER_SIZE (64U)
  11. #define GEN4_POLLER_MAX_FWT (200000U)
  12. #define GEN4_POLLER_BLOCK_SIZE (16)
  13. #define GEN4_POLLER_BLOCKS_TOTAL (256)
  14. #define GEN4_POLLER_CONFIG_SIZE_MAX (30)
  15. typedef enum {
  16. Gen4PollerUIDLengthSingle = 0x00,
  17. Gen4PollerUIDLengthDouble = 0x01,
  18. Gen4PollerUIDLengthTriple = 0x02
  19. } Gen4PollerUIDLength;
  20. typedef enum {
  21. Gen4PollerUltralightModeUL_EV1 = 0x00,
  22. Gen4PollerUltralightModeNTAG = 0x01,
  23. Gen4PollerUltralightModeUL_C = 0x02,
  24. Gen4PollerUltralightModeUL = 0x03
  25. } Gen4PollerUltralightMode;
  26. typedef enum {
  27. // for writing original (shadow) data
  28. Gen4PollerShadowModePreWrite = 0x00,
  29. // written data can be read once before restored to original
  30. Gen4PollerShadowModeRestore = 0x01,
  31. // shadow mode disabled
  32. Gen4PollerShadowModeDisabled = 0x02,
  33. // apparently for UL?
  34. Gen4PollerShadowModeHighSpeedDisabled = 0x03,
  35. // work with new UMC. With old UMC is untested
  36. Gen4PollerShadowModeSplit = 0x04,
  37. } Gen4PollerShadowMode;
  38. typedef enum {
  39. // gen2 card behavour
  40. Gen4PollerDirectWriteBlock0ModeEnabled = 0x00,
  41. // common card behavour
  42. Gen4PollerDirectWriteBlock0ModeDisabled = 0x01,
  43. // default mode. same behavour as Gen4PollerDirectWriteBlock0ModeActivate
  44. Gen4PollerDirectWriteBlock0ModeDefault = 0x02,
  45. } Gen4PollerDirectWriteBlock0Mode;
  46. typedef enum {
  47. Gen4PollerStateIdle,
  48. Gen4PollerStateRequestMode,
  49. Gen4PollerStateRequestWriteData,
  50. Gen4PollerStateWrite,
  51. Gen4PollerStateWipe,
  52. Gen4PollerStateChangePassword,
  53. Gen4PollerStateGetInfo,
  54. Gen4PollerStateSetDefaultConfig,
  55. Gen4PollerStateSetShadowMode,
  56. Gen4PollerStateSetDirectWriteBlock0,
  57. Gen4PollerStateSuccess,
  58. Gen4PollerStateFail,
  59. Gen4PollerStateNum,
  60. } Gen4PollerState;
  61. struct Gen4Poller {
  62. NfcPoller* poller;
  63. Iso14443_3aPoller* iso3_poller;
  64. Gen4PollerState state;
  65. uint32_t password;
  66. BitBuffer* tx_buffer;
  67. BitBuffer* rx_buffer;
  68. uint16_t current_block;
  69. uint16_t total_blocks;
  70. NfcProtocol protocol;
  71. const NfcDeviceData* data;
  72. uint32_t new_password;
  73. uint8_t config[GEN4_POLLER_CONFIG_SIZE_MAX];
  74. Gen4PollerShadowMode shadow_mode;
  75. Gen4PollerDirectWriteBlock0Mode direct_write_block_0_mode;
  76. Gen4PollerEvent gen4_event;
  77. Gen4PollerEventData gen4_event_data;
  78. Gen4PollerCallback callback;
  79. void* context;
  80. };
  81. Gen4PollerError gen4_poller_set_config(
  82. Gen4Poller* instance,
  83. uint32_t password,
  84. const uint8_t* config,
  85. size_t config_size,
  86. bool fuse);
  87. Gen4PollerError gen4_poller_write_block(
  88. Gen4Poller* instance,
  89. uint32_t password,
  90. uint8_t block_num,
  91. const uint8_t* data);
  92. Gen4PollerError
  93. gen4_poller_change_password(Gen4Poller* instance, uint32_t pwd_current, uint32_t pwd_new);
  94. Gen4PollerError
  95. gen4_poller_get_revision(Gen4Poller* instance, uint32_t password, uint8_t* revision_result);
  96. Gen4PollerError
  97. gen4_poller_get_config(Gen4Poller* instance, uint32_t password, uint8_t* config_result);
  98. Gen4PollerError
  99. gen4_poller_set_shadow_mode(Gen4Poller* instance, uint32_t password, Gen4PollerShadowMode mode);
  100. Gen4PollerError gen4_poller_set_direct_write_block_0_mode(
  101. Gen4Poller* instance,
  102. uint32_t password,
  103. Gen4PollerDirectWriteBlock0Mode mode);
  104. #ifdef __cplusplus
  105. }
  106. #endif