gen4_poller_i.h 2.7 KB

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