gen4_poller_i.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. Gen4PollerStateSuccess,
  43. Gen4PollerStateFail,
  44. Gen4PollerStateNum,
  45. } Gen4PollerState;
  46. struct Gen4Poller {
  47. NfcPoller* poller;
  48. Iso14443_3aPoller* iso3_poller;
  49. Gen4PollerState state;
  50. uint32_t password;
  51. BitBuffer* tx_buffer;
  52. BitBuffer* rx_buffer;
  53. uint16_t current_block;
  54. uint16_t total_blocks;
  55. NfcProtocol protocol;
  56. const NfcDeviceData* data;
  57. uint32_t new_password;
  58. uint8_t config[GEN4_POLLER_CONFIG_SIZE_MAX];
  59. Gen4PollerEvent gen4_event;
  60. Gen4PollerEventData gen4_event_data;
  61. Gen4PollerCallback callback;
  62. void* context;
  63. };
  64. Gen4PollerError gen4_poller_set_config(
  65. Gen4Poller* instance,
  66. uint32_t password,
  67. const uint8_t* config,
  68. size_t config_size,
  69. bool fuse);
  70. Gen4PollerError gen4_poller_write_block(
  71. Gen4Poller* instance,
  72. uint32_t password,
  73. uint8_t block_num,
  74. const uint8_t* data);
  75. Gen4PollerError
  76. gen4_poller_change_password(Gen4Poller* instance, uint32_t pwd_current, uint32_t pwd_new);
  77. #ifdef __cplusplus
  78. }
  79. #endif