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. #define TAG "Gen4Poller"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define GEN4_POLLER_MAX_BUFFER_SIZE (64U)
  10. #define GEN4_POLLER_MAX_FWT (200000U)
  11. #define GEN4_POLLER_BLOCK_SIZE (16)
  12. #define GEN4_POLLER_BLOCKS_TOTAL (256)
  13. #define GEN4_POLLER_CONFIG_SIZE_MAX (30)
  14. typedef enum {
  15. Gen4PollerUIDLengthSingle = 0x00,
  16. Gen4PollerUIDLengthDouble = 0x01,
  17. Gen4PollerUIDLengthTriple = 0x02
  18. } Gen4PollerUIDLength;
  19. typedef enum {
  20. Gen4PollerUltralightModeUL_EV1 = 0x00,
  21. Gen4PollerUltralightModeNTAG = 0x01,
  22. Gen4PollerUltralightModeUL_C = 0x02,
  23. Gen4PollerUltralightModeUL = 0x03
  24. } Gen4PollerUltralightMode;
  25. typedef enum {
  26. // for writing original (shadow) data
  27. Gen4PollerShadowModePreWrite = 0x00,
  28. // written data can be read once before restored to original
  29. Gen4PollerShadowModeRestore = 0x01,
  30. // shadow mode disabled
  31. Gen4PollerShadowModeDisabled = 0x02,
  32. // apparently for UL?
  33. Gen4PollerShadowModeHighSpeedDisabled = 0x03,
  34. // work with new UMC. With old UMC is untested
  35. Gen4PollerShadowModeSplit = 0x04,
  36. } Gen4PollerShadowMode;
  37. typedef enum {
  38. // gen2 card behavour
  39. Gen4PollerDirectWriteBlock0ModeEnabled = 0x00,
  40. // common card behavour
  41. Gen4PollerDirectWriteBlock0ModeDisabled = 0x01,
  42. // default mode. same behavour as Gen4PollerDirectWriteBlock0ModeActivate
  43. Gen4PollerDirectWriteBlock0ModeDefault = 0x02,
  44. } Gen4PollerDirectWriteBlock0Mode;
  45. typedef enum {
  46. Gen4PollerStateIdle,
  47. Gen4PollerStateRequestMode,
  48. Gen4PollerStateRequestWriteData,
  49. Gen4PollerStateWrite,
  50. Gen4PollerStateWipe,
  51. Gen4PollerStateChangePassword,
  52. Gen4PollerStateSetDefaultConfig,
  53. Gen4PollerStateGetCurrentConfig,
  54. Gen4PollerStateGetRevision,
  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