gen2_poller.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 union {
  21. uint8_t all_problems;
  22. struct {
  23. bool uid_locked : 1; // UID may be non-rewritable. Check data after writing
  24. bool no_data : 1; // Shouldn't happen, mfc_data missing in nfc device
  25. bool locked_access_bits : 1; // Access bits on the target card don't allow writing in some cases
  26. bool missing_target_keys : 1; // Keys to write some sectors are not available
  27. bool missing_source_data : 1; // The source dump is incomplete
  28. };
  29. } Gen2PollerWriteProblems;
  30. #define GEN2_POLLER_WRITE_PROBLEMS_LEN (5)
  31. extern char* gen2_problem_strings[];
  32. typedef enum {
  33. Gen2PollerEventTypeDetected,
  34. Gen2PollerEventTypeRequestMode,
  35. Gen2PollerEventTypeRequestDataToWrite,
  36. Gen2PollerEventTypeRequestTargetData,
  37. Gen2PollerEventTypeSuccess,
  38. Gen2PollerEventTypeFail,
  39. } Gen2PollerEventType;
  40. typedef enum {
  41. Gen2PollerModeWipe,
  42. Gen2PollerModeWrite,
  43. } Gen2PollerMode;
  44. typedef struct {
  45. Gen2PollerMode mode;
  46. } Gen2PollerEventDataRequestMode;
  47. typedef struct {
  48. const MfClassicData* mfc_data;
  49. } Gen2PollerEventDataRequestDataToWrite;
  50. typedef struct {
  51. const MfClassicData* mfc_data;
  52. } Gen2PollerEventDataRequestTargetData;
  53. typedef union {
  54. Gen2PollerEventDataRequestMode poller_mode;
  55. Gen2PollerEventDataRequestDataToWrite data_to_write;
  56. Gen2PollerEventDataRequestTargetData target_data;
  57. } Gen2PollerEventData;
  58. typedef struct {
  59. Gen2PollerEventType type;
  60. Gen2PollerEventData* data;
  61. } Gen2PollerEvent;
  62. typedef NfcCommand (*Gen2PollerCallback)(Gen2PollerEvent event, void* context);
  63. typedef struct Gen2Poller Gen2Poller;
  64. Gen2PollerError gen2_poller_detect(Nfc* nfc);
  65. Gen2Poller* gen2_poller_alloc(Nfc* nfc);
  66. void gen2_poller_free(Gen2Poller* instance);
  67. void gen2_poller_start(Gen2Poller* instance, Gen2PollerCallback callback, void* context);
  68. void gen2_poller_stop(Gen2Poller* instance);
  69. Gen2PollerWriteProblems gen2_poller_check_target_problems(NfcDevice* target_dev);
  70. Gen2PollerWriteProblems gen2_poller_check_source_problems(NfcDevice* source_dev);
  71. #ifdef __cplusplus
  72. }
  73. #endif