nfc_device.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_ultralight.h"
  9. #include "protocols/mifare_classic.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #define NFC_DEV_NAME_MAX_LEN 22
  14. #define NFC_READER_DATA_MAX_SIZE 64
  15. #define NFC_DICT_KEY_BATCH_SIZE 10
  16. #define NFC_APP_FILENAME_PREFIX "NFC"
  17. #define NFC_APP_FILENAME_EXTENSION ".nfc"
  18. #define NFC_APP_SHADOW_EXTENSION ".shd"
  19. typedef void (*NfcLoadingCallback)(void* context, bool state);
  20. typedef enum {
  21. NfcDeviceProtocolUnknown,
  22. NfcDeviceProtocolEMV,
  23. NfcDeviceProtocolMifareUl,
  24. NfcDeviceProtocolMifareClassic,
  25. NfcDeviceProtocolMifareDesfire,
  26. NfcDeviceProtocolNfcV
  27. } NfcProtocol;
  28. typedef enum {
  29. NfcDeviceSaveFormatUid,
  30. NfcDeviceSaveFormatBankCard,
  31. NfcDeviceSaveFormatMifareUl,
  32. NfcDeviceSaveFormatMifareClassic,
  33. NfcDeviceSaveFormatMifareDesfire,
  34. NfcDeviceSaveFormatNfcV,
  35. } NfcDeviceSaveFormat;
  36. typedef struct {
  37. uint8_t data[NFC_READER_DATA_MAX_SIZE];
  38. uint16_t size;
  39. } NfcReaderRequestData;
  40. typedef struct {
  41. MfClassicDict* dict;
  42. uint8_t current_sector;
  43. } NfcMfClassicDictAttackData;
  44. typedef enum {
  45. NfcReadModeAuto,
  46. NfcReadModeMfClassic,
  47. NfcReadModeMfUltralight,
  48. NfcReadModeMfDesfire,
  49. NfcReadModeEMV,
  50. NfcReadModeNFCA,
  51. } NfcReadMode;
  52. typedef struct {
  53. FurryHalNfcDevData nfc_data;
  54. NfcProtocol protocol;
  55. NfcReadMode read_mode;
  56. union {
  57. NfcReaderRequestData reader_data;
  58. NfcMfClassicDictAttackData mf_classic_dict_attack_data;
  59. MfUltralightAuth mf_ul_auth;
  60. };
  61. union {
  62. MfUltralightData mf_ul_data;
  63. MfClassicData mf_classic_data;
  64. };
  65. FuriString* parsed_data;
  66. } NfcDeviceData;
  67. typedef struct {
  68. Storage* storage;
  69. DialogsApp* dialogs;
  70. NfcDeviceData dev_data;
  71. char dev_name[NFC_DEV_NAME_MAX_LEN + 1];
  72. FuriString* load_path;
  73. FuriString* folder;
  74. NfcDeviceSaveFormat format;
  75. bool shadow_file_exist;
  76. NfcLoadingCallback loading_cb;
  77. void* loading_cb_ctx;
  78. } NfcDevice;
  79. NfcDevice* nfc_device_alloc();
  80. void nfc_device_free(NfcDevice* nfc_dev);
  81. void nfc_device_set_name(NfcDevice* dev, const char* name);
  82. bool nfc_device_save(NfcDevice* dev, const char* dev_name);
  83. bool nfc_device_save_shadow(NfcDevice* dev, const char* dev_name);
  84. bool nfc_device_load(NfcDevice* dev, const char* file_path, bool show_dialog);
  85. bool nfc_device_load_key_cache(NfcDevice* dev);
  86. void nfc_device_data_clear(NfcDeviceData* dev);
  87. void nfc_device_clear(NfcDevice* dev);
  88. bool nfc_device_delete(NfcDevice* dev, bool use_load_path);
  89. bool nfc_device_restore(NfcDevice* dev, bool use_load_path);
  90. void nfc_device_set_loading_callback(NfcDevice* dev, NfcLoadingCallback callback, void* context);
  91. #ifdef __cplusplus
  92. }
  93. #endif