mifare_nested_worker.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include <lib/nfc/nfc_device.h>
  3. #define NESTED_FOLDER EXT_PATH("nfc/.nested")
  4. typedef struct MifareNestedWorker MifareNestedWorker;
  5. typedef enum {
  6. MifareNestedWorkerStateReady,
  7. MifareNestedWorkerStateCheck,
  8. MifareNestedWorkerStateCollecting,
  9. MifareNestedWorkerStateCollectingStatic,
  10. MifareNestedWorkerStateValidating,
  11. MifareNestedWorkerStateStop,
  12. } MifareNestedWorkerState;
  13. typedef enum {
  14. MifareNestedWorkerEventReserved = 1000,
  15. MifareNestedWorkerEventNoTagDetected,
  16. MifareNestedWorkerEventNoncesCollected,
  17. MifareNestedWorkerEventCollecting,
  18. MifareNestedWorkerEventNewNonce,
  19. MifareNestedWorkerEventKeyChecked,
  20. MifareNestedWorkerEventKeysFound,
  21. MifareNestedWorkerEventNeedKey,
  22. MifareNestedWorkerEventAttackFailed,
  23. MifareNestedWorkerEventCalibrating,
  24. MifareNestedWorkerEventStaticEncryptedNonce,
  25. MifareNestedWorkerEventNeedPrediction,
  26. MifareNestedWorkerEventProcessingKeys,
  27. MifareNestedWorkerEventNeedKeyRecovery,
  28. MifareNestedWorkerEventNeedCollection,
  29. MifareNestedWorkerEventHardnestedStatesFound
  30. } MifareNestedWorkerEvent;
  31. typedef bool (*MifareNestedWorkerCallback)(MifareNestedWorkerEvent event, void* context);
  32. MifareNestedWorker* mifare_nested_worker_alloc();
  33. void mifare_nested_worker_change_state(
  34. MifareNestedWorker* mifare_nested_worker,
  35. MifareNestedWorkerState state);
  36. void mifare_nested_worker_free(MifareNestedWorker* mifare_nested_worker);
  37. void mifare_nested_worker_stop(MifareNestedWorker* mifare_nested_worker);
  38. void mifare_nested_worker_start(
  39. MifareNestedWorker* mifare_nested_worker,
  40. MifareNestedWorkerState state,
  41. NfcDeviceData* dev_data,
  42. MifareNestedWorkerCallback callback,
  43. void* context);
  44. typedef struct {
  45. uint32_t key_type;
  46. uint32_t block;
  47. uint32_t target_nt[2];
  48. uint32_t target_ks[2];
  49. uint8_t parity[2][4];
  50. bool collected;
  51. bool skipped;
  52. bool hardnested;
  53. } Nonces;
  54. typedef struct {
  55. uint32_t cuid;
  56. uint32_t sector_count;
  57. // 40 (or 16/5) sectors, 2 keys (A/B), 3 tries
  58. Nonces* nonces[40][2][3];
  59. uint32_t tries;
  60. // unique first bytes
  61. uint32_t hardnested_states;
  62. } NonceList_t;
  63. typedef struct {
  64. uint32_t total_keys;
  65. uint32_t checked_keys;
  66. uint32_t found_keys;
  67. uint32_t added_keys;
  68. uint32_t sector_keys;
  69. bool tag_lost;
  70. } KeyInfo_t;