nfc_device.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include "mifare_ultralight.h"
  5. #define NFC_DEV_NAME_MAX_LEN 22
  6. #define NFC_FILE_NAME_MAX_LEN 120
  7. typedef enum {
  8. NfcDeviceNfca,
  9. NfcDeviceNfcb,
  10. NfcDeviceNfcf,
  11. NfcDeviceNfcv,
  12. } NfcDeviceType;
  13. typedef enum {
  14. NfcDeviceProtocolUnknown,
  15. NfcDeviceProtocolEMV,
  16. NfcDeviceProtocolMifareUl,
  17. } NfcProtocol;
  18. typedef enum {
  19. NfcDeviceSaveFormatUid,
  20. NfcDeviceSaveFormatBankCard,
  21. NfcDeviceSaveFormatMifareUl,
  22. } NfcDeviceSaveFormat;
  23. typedef struct {
  24. uint8_t uid_len;
  25. uint8_t uid[10];
  26. uint8_t atqa[2];
  27. uint8_t sak;
  28. NfcDeviceType device;
  29. NfcProtocol protocol;
  30. } NfcDeviceCommonData;
  31. typedef struct {
  32. char name[32];
  33. uint8_t aid[16];
  34. uint16_t aid_len;
  35. uint8_t number[10];
  36. uint8_t number_len;
  37. uint8_t exp_mon;
  38. uint8_t exp_year;
  39. uint16_t country_code;
  40. uint16_t currency_code;
  41. } NfcEmvData;
  42. typedef struct {
  43. NfcDeviceCommonData nfc_data;
  44. union {
  45. NfcEmvData emv_data;
  46. MifareUlData mf_ul_data;
  47. };
  48. } NfcDeviceData;
  49. typedef struct {
  50. NfcDeviceData dev_data;
  51. char dev_name[NFC_DEV_NAME_MAX_LEN + 1];
  52. char file_name[NFC_FILE_NAME_MAX_LEN];
  53. NfcDeviceSaveFormat format;
  54. bool shadow_file_exist;
  55. } NfcDevice;
  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_clear(NfcDevice* dev);
  62. bool nfc_device_delete(NfcDevice* dev);
  63. bool nfc_device_restore(NfcDevice* dev);