gen4_poller.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include "gen4.h"
  3. #include <nfc/nfc.h>
  4. #include <nfc/protocols/nfc_protocol.h>
  5. #include <nfc/protocols/mf_classic/mf_classic.h>
  6. #include <nfc/protocols/mf_ultralight/mf_ultralight.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. // TODO: cleanup, check gen4_poller_i.c defines
  11. #define GEN4_CMD_PREFIX (0xCF)
  12. #define GEN4_CMD_GET_CFG (0xC6)
  13. #define GEN4_CMD_GET_REVISION (0xCC)
  14. #define GEN4_CMD_WRITE (0xCD)
  15. #define GEN4_CMD_READ (0xCE)
  16. #define GEN4_CMD_SET_CFG (0xF0)
  17. #define GEN4_CMD_FUSE_CFG (0xF1)
  18. #define GEN4_CMD_SET_PWD (0xFE)
  19. typedef enum {
  20. Gen4PollerErrorNone,
  21. Gen4PollerErrorTimeout,
  22. Gen4PollerErrorProtocol,
  23. } Gen4PollerError;
  24. typedef enum {
  25. Gen4PollerEventTypeCardDetected,
  26. Gen4PollerEventTypeRequestMode,
  27. Gen4PollerEventTypeRequestDataToWrite,
  28. Gen4PollerEventTypeRequestNewPassword,
  29. Gen4PollerEventTypeSuccess,
  30. Gen4PollerEventTypeFail,
  31. } Gen4PollerEventType;
  32. typedef enum {
  33. Gen4PollerModeWipe,
  34. Gen4PollerModeWrite,
  35. Gen4PollerModeSetPassword,
  36. Gen4PollerModeGetInfo,
  37. Gen4PollerModeSetDefaultCfg,
  38. Gen4PollerModeSetShadowMode,
  39. Gen4PollerModeSetDirectWriteBlock0Mode
  40. } Gen4PollerMode;
  41. typedef struct {
  42. Gen4PollerMode mode;
  43. } Gen4PollerEventDataRequestMode;
  44. typedef struct {
  45. NfcProtocol protocol;
  46. const NfcDeviceData* data;
  47. } Gen4PollerEventDataRequestDataToWrite;
  48. typedef struct {
  49. Gen4Password password;
  50. } Gen4PollerEventDataRequestNewPassword;
  51. typedef union {
  52. Gen4PollerEventDataRequestMode request_mode;
  53. Gen4PollerEventDataRequestDataToWrite request_data;
  54. Gen4PollerEventDataRequestNewPassword request_password;
  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, Gen4Password password, Gen4* gen4_data);
  63. Gen4Poller* gen4_poller_alloc(Nfc* nfc);
  64. void gen4_poller_free(Gen4Poller* instance);
  65. void gen4_poller_set_password(Gen4Poller* instance, Gen4Password password);
  66. void gen4_poller_start(Gen4Poller* instance, Gen4PollerCallback callback, void* context);
  67. void gen4_poller_stop(Gen4Poller* instance);
  68. const Gen4* gen4_poller_get_gen4_data(const Gen4Poller* instance);
  69. void gen4_poller_struct_set_direct_write_block_0_mode(
  70. Gen4Poller* instance,
  71. Gen4DirectWriteBlock0Mode mode);
  72. void gen4_poller_struct_set_shadow_mode(Gen4Poller* instance, Gen4ShadowMode mode);
  73. #ifdef __cplusplus
  74. }
  75. #endif