gen4_poller.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include <nfc/nfc.h>
  3. #include <nfc/protocols/nfc_protocol.h>
  4. #include <nfc/protocols/mf_classic/mf_classic.h>
  5. #include <nfc/protocols/mf_ultralight/mf_ultralight.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define GEN4_CMD_PREFIX (0xCF)
  10. #define GEN4_CMD_GET_CFG (0xC6)
  11. #define GEN4_CMD_WRITE (0xCD)
  12. #define GEN4_CMD_READ (0xCE)
  13. #define GEN4_CMD_SET_CFG (0xF0)
  14. #define GEN4_CMD_FUSE_CFG (0xF1)
  15. #define GEN4_CMD_SET_PWD (0xFE)
  16. typedef enum {
  17. Gen4PollerErrorNone,
  18. Gen4PollerErrorTimeout,
  19. Gen4PollerErrorProtocol,
  20. } Gen4PollerError;
  21. typedef enum {
  22. Gen4PollerEventTypeCardDetected,
  23. Gen4PollerEventTypeRequestMode,
  24. Gen4PollerEventTypeRequestDataToWrite,
  25. Gen4PollerEventTypeRequestNewPassword,
  26. Gen4PollerEventTypeSuccess,
  27. Gen4PollerEventTypeFail,
  28. } Gen4PollerEventType;
  29. typedef enum {
  30. Gen4PollerModeWipe,
  31. Gen4PollerModeWrite,
  32. Gen4PollerModeSetPassword,
  33. Gen4PollerModeSetDefaultCfg,
  34. Gen4PollerModeGetCfg,
  35. Gen4PollerModeGetRevision,
  36. Gen4PollerModeSetShadowMode,
  37. Gen4PollerModeSetDirectWriteBlock0Mode
  38. } Gen4PollerMode;
  39. typedef struct {
  40. Gen4PollerMode mode;
  41. } Gen4PollerEventDataRequestMode;
  42. typedef struct {
  43. NfcProtocol protocol;
  44. const NfcDeviceData* data;
  45. } Gen4PollerEventDataRequestDataToWrite;
  46. typedef struct {
  47. uint32_t password;
  48. } Gen4PollerEventDataRequestNewPassword;
  49. typedef union {
  50. Gen4PollerEventDataRequestMode request_mode;
  51. Gen4PollerEventDataRequestDataToWrite request_data;
  52. Gen4PollerEventDataRequestNewPassword request_password;
  53. uint8_t display_config[32];
  54. uint8_t revision_data[5];
  55. } Gen4PollerEventData;
  56. typedef struct {
  57. Gen4PollerEventType type;
  58. Gen4PollerEventData* data;
  59. } Gen4PollerEvent;
  60. typedef NfcCommand (*Gen4PollerCallback)(Gen4PollerEvent event, void* context);
  61. typedef struct Gen4Poller Gen4Poller;
  62. Gen4PollerError gen4_poller_detect(Nfc* nfc, uint32_t password);
  63. Gen4Poller* gen4_poller_alloc(Nfc* nfc);
  64. void gen4_poller_free(Gen4Poller* instance);
  65. void gen4_poller_set_password(Gen4Poller* instance, uint32_t password);
  66. void gen4_poller_start(Gen4Poller* instance, Gen4PollerCallback callback, void* context);
  67. void gen4_poller_stop(Gen4Poller* instance);
  68. #ifdef __cplusplus
  69. }
  70. #endif