gen4_poller.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. Gen4PollerModeGetInfo,
  34. Gen4PollerModeSetDefaultCfg,
  35. Gen4PollerModeSetShadowMode,
  36. Gen4PollerModeSetDirectWriteBlock0Mode
  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. struct {
  53. uint8_t config_data[32];
  54. uint8_t revision_data[5];
  55. };
  56. } Gen4PollerEventData;
  57. typedef struct {
  58. Gen4PollerEventType type;
  59. Gen4PollerEventData* data;
  60. } Gen4PollerEvent;
  61. typedef NfcCommand (*Gen4PollerCallback)(Gen4PollerEvent event, void* context);
  62. typedef struct Gen4Poller Gen4Poller;
  63. Gen4PollerError gen4_poller_detect(Nfc* nfc, uint32_t password);
  64. Gen4Poller* gen4_poller_alloc(Nfc* nfc);
  65. void gen4_poller_free(Gen4Poller* instance);
  66. void gen4_poller_set_password(Gen4Poller* instance, uint32_t password);
  67. void gen4_poller_start(Gen4Poller* instance, Gen4PollerCallback callback, void* context);
  68. void gen4_poller_stop(Gen4Poller* instance);
  69. #ifdef __cplusplus
  70. }
  71. #endif