nfc_device.h 2.4 KB

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