nfc_device.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <storage/storage.h>
  5. #include <dialogs/dialogs.h>
  6. #include "./furi_hal_nfc.h"
  7. #include "helpers/mf_classic_dict.h"
  8. #include "protocols/mifare_classic.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #define NFC_DEV_NAME_MAX_LEN 22
  13. #define NFC_READER_DATA_MAX_SIZE 64
  14. #define NFC_DICT_KEY_BATCH_SIZE 10
  15. #define NFC_APP_FILENAME_PREFIX "NFC"
  16. #define NFC_APP_FILENAME_EXTENSION ".nfc"
  17. #define NFC_APP_SHADOW_EXTENSION ".shd"
  18. typedef void (*NfcLoadingCallback)(void* context, bool state);
  19. typedef enum {
  20. NfcDeviceProtocolUnknown,
  21. NfcDeviceProtocolMifareClassic,
  22. } NfcProtocol;
  23. typedef enum {
  24. NfcDeviceSaveFormatUid,
  25. NfcDeviceSaveFormatMifareClassic,
  26. } NfcDeviceSaveFormat;
  27. typedef struct {
  28. uint8_t data[NFC_READER_DATA_MAX_SIZE];
  29. uint16_t size;
  30. } NfcReaderRequestData;
  31. typedef struct {
  32. MfClassicDict* dict;
  33. uint8_t current_sector;
  34. } NfcMfClassicDictAttackData;
  35. typedef enum {
  36. NfcReadModeAuto,
  37. NfcReadModeMfClassic,
  38. NfcReadModeNFCA,
  39. } NfcReadMode;
  40. typedef struct {
  41. FurryHalNfcDevData nfc_data;
  42. NfcProtocol protocol;
  43. NfcReadMode read_mode;
  44. union {
  45. NfcReaderRequestData reader_data;
  46. NfcMfClassicDictAttackData mf_classic_dict_attack_data;
  47. };
  48. union {
  49. MfClassicData mf_classic_data;
  50. };
  51. FuriString* parsed_data;
  52. } NfcDeviceData;
  53. typedef struct {
  54. Storage* storage;
  55. DialogsApp* dialogs;
  56. NfcDeviceData dev_data;
  57. char dev_name[NFC_DEV_NAME_MAX_LEN + 1];
  58. FuriString* load_path;
  59. FuriString* folder;
  60. NfcDeviceSaveFormat format;
  61. bool shadow_file_exist;
  62. NfcLoadingCallback loading_cb;
  63. void* loading_cb_ctx;
  64. } NfcDevice;
  65. NfcDevice* nfc_device_alloc();
  66. void nfc_device_free(NfcDevice* nfc_dev);
  67. void nfc_device_set_name(NfcDevice* dev, const char* name);
  68. bool nfc_device_save(NfcDevice* dev, const char* dev_name);
  69. bool nfc_device_save_shadow(NfcDevice* dev, const char* dev_name);
  70. bool nfc_device_load(NfcDevice* dev, const char* file_path, bool show_dialog);
  71. bool nfc_device_load_key_cache(NfcDevice* dev);
  72. void nfc_device_data_clear(NfcDeviceData* dev);
  73. void nfc_device_clear(NfcDevice* dev);
  74. bool nfc_device_delete(NfcDevice* dev, bool use_load_path);
  75. bool nfc_device_restore(NfcDevice* dev, bool use_load_path);
  76. void nfc_device_set_loading_callback(NfcDevice* dev, NfcLoadingCallback callback, void* context);
  77. #ifdef __cplusplus
  78. }
  79. #endif