gen4_poller_i.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // written data is discarded
  31. Gen4PollerShadowModeIgnore = 0x02,
  32. // apparently for UL?
  33. Gen4PollerShadowModeHighSpeedIgnore = 0x03
  34. } Gen4PollerShadowMode;
  35. typedef enum {
  36. Gen4PollerStateIdle,
  37. Gen4PollerStateRequestMode,
  38. Gen4PollerStateRequestWriteData,
  39. Gen4PollerStateWrite,
  40. Gen4PollerStateWipe,
  41. Gen4PollerStateChangePassword,
  42. Gen4PollerStateSetDefaultConfig,
  43. Gen4PollerStateGetCurrentConfig,
  44. Gen4PollerStateGetRevision,
  45. Gen4PollerStateSuccess,
  46. Gen4PollerStateFail,
  47. Gen4PollerStateNum,
  48. } Gen4PollerState;
  49. struct Gen4Poller {
  50. NfcPoller* poller;
  51. Iso14443_3aPoller* iso3_poller;
  52. Gen4PollerState state;
  53. uint32_t password;
  54. BitBuffer* tx_buffer;
  55. BitBuffer* rx_buffer;
  56. uint16_t current_block;
  57. uint16_t total_blocks;
  58. NfcProtocol protocol;
  59. const NfcDeviceData* data;
  60. uint32_t new_password;
  61. uint8_t config[GEN4_POLLER_CONFIG_SIZE_MAX];
  62. Gen4PollerEvent gen4_event;
  63. Gen4PollerEventData gen4_event_data;
  64. Gen4PollerCallback callback;
  65. void* context;
  66. };
  67. Gen4PollerError gen4_poller_set_config(
  68. Gen4Poller* instance,
  69. uint32_t password,
  70. const uint8_t* config,
  71. size_t config_size,
  72. bool fuse);
  73. Gen4PollerError gen4_poller_write_block(
  74. Gen4Poller* instance,
  75. uint32_t password,
  76. uint8_t block_num,
  77. const uint8_t* data);
  78. Gen4PollerError
  79. gen4_poller_change_password(Gen4Poller* instance, uint32_t pwd_current, uint32_t pwd_new);
  80. Gen4PollerError
  81. gen4_poller_get_revision(Gen4Poller* instance, uint32_t password, uint8_t* revision_result);
  82. Gen4PollerError
  83. gen4_poller_get_config(Gen4Poller* instance, uint32_t password, uint8_t* config_result);
  84. #ifdef __cplusplus
  85. }
  86. #endif