gen4_poller.h 2.1 KB

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