gen4_poller.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. } Gen4PollerMode;
  34. typedef struct {
  35. Gen4PollerMode mode;
  36. } Gen4PollerEventDataRequestMode;
  37. typedef struct {
  38. NfcProtocol protocol;
  39. const NfcDeviceData* data;
  40. } Gen4PollerEventDataRequestDataToWrite;
  41. typedef struct {
  42. uint32_t password;
  43. } Gen4PollerEventDataRequestNewPassword;
  44. typedef union {
  45. Gen4PollerEventDataRequestMode request_mode;
  46. Gen4PollerEventDataRequestDataToWrite request_data;
  47. Gen4PollerEventDataRequestNewPassword request_password;
  48. } Gen4PollerEventData;
  49. typedef struct {
  50. Gen4PollerEventType type;
  51. Gen4PollerEventData* data;
  52. } Gen4PollerEvent;
  53. typedef NfcCommand (*Gen4PollerCallback)(Gen4PollerEvent event, void* context);
  54. typedef struct Gen4Poller Gen4Poller;
  55. Gen4PollerError gen4_poller_detect(Nfc* nfc, uint32_t password);
  56. Gen4Poller* gen4_poller_alloc(Nfc* nfc);
  57. void gen4_poller_free(Gen4Poller* instance);
  58. void gen4_poller_set_password(Gen4Poller* instance, uint32_t password);
  59. void gen4_poller_start(Gen4Poller* instance, Gen4PollerCallback callback, void* context);
  60. void gen4_poller_stop(Gen4Poller* instance);
  61. #ifdef __cplusplus
  62. }
  63. #endif