nfc_device.h 2.1 KB

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