gen4_poller.h 2.2 KB

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