gen2_poller.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include <nfc/nfc.h>
  3. #include <nfc/protocols/nfc_generic_event.h>
  4. #include <nfc/protocols/mf_classic/mf_classic.h>
  5. #include <nfc/protocols/iso14443_3a/iso14443_3a.h>
  6. #include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
  7. #include <nfc/nfc_device.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef enum {
  12. Gen2PollerErrorNone,
  13. Gen2PollerErrorNotPresent,
  14. Gen2PollerErrorProtocol,
  15. Gen2PollerErrorAuth,
  16. Gen2PollerErrorTimeout,
  17. Gen2PollerErrorAccess,
  18. } Gen2PollerError;
  19. // Possible write problems, sorted by priority top to bottom
  20. typedef enum {
  21. Gen2PollerWriteProblemNoData, // Shouldn't happen, mfc_data missing in nfc device
  22. Gen2PollerWriteProblemLockedAccessBits, // Access bits on the target card don't allow writing in some cases
  23. Gen2PollerWriteProblemMissingTargetKeys, // Keys to write some sectors are not available
  24. Gen2PollerWriteProblemMissingSourceData, // The source dump is incomplete
  25. Gen2PollerWriteProblemNone, // Everything OK
  26. } Gen2PollerWriteProblem;
  27. typedef enum {
  28. Gen2PollerEventTypeDetected,
  29. Gen2PollerEventTypeRequestMode,
  30. Gen2PollerEventTypeRequestDataToWrite,
  31. Gen2PollerEventTypeRequestTargetData,
  32. Gen2PollerEventTypeSuccess,
  33. Gen2PollerEventTypeFail,
  34. } Gen2PollerEventType;
  35. typedef enum {
  36. Gen2PollerModeWipe,
  37. Gen2PollerModeWrite,
  38. } Gen2PollerMode;
  39. typedef struct {
  40. Gen2PollerMode mode;
  41. } Gen2PollerEventDataRequestMode;
  42. typedef struct {
  43. const MfClassicData* mfc_data;
  44. } Gen2PollerEventDataRequestDataToWrite;
  45. typedef struct {
  46. const MfClassicData* mfc_data;
  47. } Gen2PollerEventDataRequestTargetData;
  48. typedef union {
  49. Gen2PollerEventDataRequestMode poller_mode;
  50. Gen2PollerEventDataRequestDataToWrite data_to_write;
  51. Gen2PollerEventDataRequestTargetData target_data;
  52. } Gen2PollerEventData;
  53. typedef struct {
  54. Gen2PollerEventType type;
  55. Gen2PollerEventData* data;
  56. } Gen2PollerEvent;
  57. typedef NfcCommand (*Gen2PollerCallback)(Gen2PollerEvent event, void* context);
  58. typedef struct Gen2Poller Gen2Poller;
  59. Gen2PollerError gen2_poller_detect(Nfc* nfc);
  60. Gen2Poller* gen2_poller_alloc(Nfc* nfc);
  61. void gen2_poller_free(Gen2Poller* instance);
  62. void gen2_poller_start(Gen2Poller* instance, Gen2PollerCallback callback, void* context);
  63. void gen2_poller_stop(Gen2Poller* instance);
  64. Gen2PollerWriteProblem gen2_poller_can_write_everything(NfcDevice* device);
  65. #ifdef __cplusplus
  66. }
  67. #endif