nfc_device.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <lib/nfc/helpers/mf_classic_dict.h>
  8. #include <lib/nfc/protocols/emv.h>
  9. #include <lib/nfc/protocols/mifare_ultralight.h>
  10. #include <lib/nfc/protocols/mifare_classic.h>
  11. #include <lib/nfc/protocols/mifare_desfire.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #define NFC_DEV_NAME_MAX_LEN 22
  16. #define NFC_READER_DATA_MAX_SIZE 64
  17. #define NFC_DICT_KEY_BATCH_SIZE 50
  18. #define NFC_APP_FOLDER ANY_PATH("nfc")
  19. #define NFC_APP_EXTENSION ".nfc"
  20. #define NFC_APP_SHADOW_EXTENSION ".shd"
  21. typedef void (*NfcLoadingCallback)(void* context, bool state);
  22. typedef enum {
  23. NfcDeviceProtocolUnknown,
  24. NfcDeviceProtocolEMV,
  25. NfcDeviceProtocolMifareUl,
  26. NfcDeviceProtocolMifareClassic,
  27. NfcDeviceProtocolMifareDesfire,
  28. } NfcProtocol;
  29. typedef enum {
  30. NfcDeviceSaveFormatUid,
  31. NfcDeviceSaveFormatBankCard,
  32. NfcDeviceSaveFormatMifareUl,
  33. NfcDeviceSaveFormatMifareClassic,
  34. NfcDeviceSaveFormatMifareDesfire,
  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. } NfcMfClassicDictAttackData;
  43. typedef struct {
  44. FuriHalNfcDevData nfc_data;
  45. NfcProtocol protocol;
  46. union {
  47. NfcReaderRequestData reader_data;
  48. NfcMfClassicDictAttackData mf_classic_dict_attack_data;
  49. };
  50. union {
  51. EmvData emv_data;
  52. MfUltralightData mf_ul_data;
  53. MfClassicData mf_classic_data;
  54. MifareDesfireData mf_df_data;
  55. };
  56. FuriString* parsed_data;
  57. } NfcDeviceData;
  58. typedef struct {
  59. Storage* storage;
  60. DialogsApp* dialogs;
  61. NfcDeviceData dev_data;
  62. char dev_name[NFC_DEV_NAME_MAX_LEN + 1];
  63. FuriString* load_path;
  64. NfcDeviceSaveFormat format;
  65. bool shadow_file_exist;
  66. NfcLoadingCallback loading_cb;
  67. void* loading_cb_ctx;
  68. } NfcDevice;
  69. NfcDevice* nfc_device_alloc();
  70. void nfc_device_free(NfcDevice* nfc_dev);
  71. void nfc_device_set_name(NfcDevice* dev, const char* name);
  72. bool nfc_device_save(NfcDevice* dev, const char* dev_name);
  73. bool nfc_device_save_shadow(NfcDevice* dev, const char* dev_name);
  74. bool nfc_device_load(NfcDevice* dev, const char* file_path, bool show_dialog);
  75. bool nfc_device_load_key_cache(NfcDevice* dev);
  76. bool nfc_file_select(NfcDevice* dev);
  77. void nfc_device_data_clear(NfcDeviceData* dev);
  78. void nfc_device_clear(NfcDevice* dev);
  79. bool nfc_device_delete(NfcDevice* dev, bool use_load_path);
  80. bool nfc_device_restore(NfcDevice* dev, bool use_load_path);
  81. void nfc_device_set_loading_callback(NfcDevice* dev, NfcLoadingCallback callback, void* context);
  82. #ifdef __cplusplus
  83. }
  84. #endif