3#include <lib/nfc/protocols/iso14443_3a/iso14443_3a.h>
4#include <mbedtls/include/mbedtls/des.h>
10#define MF_ULTRALIGHT_TEARING_FLAG_DEFAULT (0xBD)
12#define MF_ULTRALIGHT_CMD_GET_VERSION (0x60)
13#define MF_ULTRALIGHT_CMD_READ_PAGE (0x30)
14#define MF_ULTRALIGHT_CMD_FAST_READ (0x3A)
15#define MF_ULTRALIGHT_CMD_SECTOR_SELECT (0xC2)
16#define MF_ULTRALIGHT_CMD_COMP_WRITE (0xA0)
17#define MF_ULTRALIGHT_CMD_WRITE_PAGE (0xA2)
18#define MF_ULTRALIGHT_CMD_FAST_WRITE (0xA6)
19#define MF_ULTRALIGHT_CMD_READ_SIG (0x3C)
20#define MF_ULTRALIGHT_CMD_READ_CNT (0x39)
21#define MF_ULTRALIGHT_CMD_INCR_CNT (0xA5)
22#define MF_ULTRALIGHT_CMD_CHECK_TEARING (0x3E)
23#define MF_ULTRALIGHT_CMD_PWD_AUTH (0x1B)
24#define MF_ULTRALIGHT_CMD_AUTH (0x1A)
25#define MF_ULTRALIGHT_CMD_VCSL (0x4B)
27#define MF_ULTRALIGHT_CMD_ACK (0x0A)
28#define MF_ULTRALIGHT_CMD_NACK (0x00)
29#define MF_ULTRALIGHT_CMD_AUTH_NAK (0x04)
31#define MF_ULTRALIGHT_MAX_CNTR_VAL (0x00FFFFFF)
32#define MF_ULTRALIGHT_MAX_PAGE_NUM (510)
33#define MF_ULTRALIGHT_PAGE_SIZE (4U)
34#define MF_ULTRALIGHT_SIGNATURE_SIZE (32)
35#define MF_ULTRALIGHT_COUNTER_SIZE (3)
36#define MF_ULTRALIGHT_COUNTER_NUM (3)
37#define MF_ULTRALIGHT_TEARING_FLAG_SIZE (1)
38#define MF_ULTRALIGHT_TEARING_FLAG_NUM (3)
39#define MF_ULTRALIGHT_AUTH_PASSWORD_SIZE (4)
40#define MF_ULTRALIGHT_AUTH_PACK_SIZE (2)
42#define MF_ULTRALIGHT_C_AUTH_RESPONSE_SIZE (9)
43#define MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE (16)
44#define MF_ULTRALIGHT_C_AUTH_DATA_SIZE (MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE)
45#define MF_ULTRALIGHT_C_AUTH_IV_BLOCK_SIZE (8)
46#define MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE (8)
47#define MF_ULTRALIGHT_C_AUTH_RND_A_BLOCK_OFFSET (0)
48#define MF_ULTRALIGHT_C_AUTH_RND_B_BLOCK_OFFSET (8)
49#define MF_ULTRALIGHT_C_ENCRYPTED_PACK_SIZE (MF_ULTRALIGHT_C_AUTH_DATA_SIZE + 1)
52 MfUltralightErrorNone,
53 MfUltralightErrorNotPresent,
54 MfUltralightErrorProtocol,
55 MfUltralightErrorAuth,
56 MfUltralightErrorTimeout,
60 MfUltralightTypeOrigin,
61 MfUltralightTypeNTAG203,
62 MfUltralightTypeMfulC,
65 MfUltralightTypeNTAG213,
66 MfUltralightTypeNTAG215,
67 MfUltralightTypeNTAG216,
68 MfUltralightTypeNTAGI2C1K,
69 MfUltralightTypeNTAGI2C2K,
70 MfUltralightTypeNTAGI2CPlus1K,
71 MfUltralightTypeNTAGI2CPlus2K,
77 MfUltralightFeatureSupportReadVersion = (1U << 0),
78 MfUltralightFeatureSupportReadSignature = (1U << 1),
79 MfUltralightFeatureSupportReadCounter = (1U << 2),
80 MfUltralightFeatureSupportCheckTearingFlag = (1U << 3),
81 MfUltralightFeatureSupportFastRead = (1U << 4),
82 MfUltralightFeatureSupportIncCounter = (1U << 5),
83 MfUltralightFeatureSupportFastWrite = (1U << 6),
84 MfUltralightFeatureSupportCompatibleWrite = (1U << 7),
85 MfUltralightFeatureSupportPasswordAuth = (1U << 8),
86 MfUltralightFeatureSupportVcsl = (1U << 9),
87 MfUltralightFeatureSupportSectorSelect = (1U << 10),
88 MfUltralightFeatureSupportSingleCounter = (1U << 11),
89 MfUltralightFeatureSupportAsciiMirror = (1U << 12),
90 MfUltralightFeatureSupportCounterInMemory = (1U << 13),
91 MfUltralightFeatureSupportDynamicLock = (1U << 14),
92 MfUltralightFeatureSupportAuthenticate = (1U << 15),
93} MfUltralightFeatureSupport;
96 uint8_t data[MF_ULTRALIGHT_PAGE_SIZE];
107 uint8_t prod_subtype;
108 uint8_t prod_ver_major;
109 uint8_t prod_ver_minor;
110 uint8_t storage_size;
111 uint8_t protocol_type;
115 uint8_t data[MF_ULTRALIGHT_SIGNATURE_SIZE];
120 uint8_t data[MF_ULTRALIGHT_COUNTER_SIZE];
128 uint8_t data[MF_ULTRALIGHT_AUTH_PASSWORD_SIZE];
132 uint8_t data[MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE];
136 uint8_t data[MF_ULTRALIGHT_AUTH_PACK_SIZE];
140 MfUltralightMirrorNone,
141 MfUltralightMirrorUid,
142 MfUltralightMirrorCounter,
143 MfUltralightMirrorUidCounter,
144} MfUltralightMirrorConf;
151 bool strg_mod_en : 1;
153 uint8_t mirror_byte : 2;
154 MfUltralightMirrorConf mirror_conf : 2;
164 bool nfc_cnt_pwd_prot : 1;
166 bool nfc_dis_sec1 : 1;
180 MfUltralightType type;
187 uint16_t pages_total;
188 uint32_t auth_attempts;
212const uint8_t* mf_ultralight_get_uid(
const MfUltralightData* data,
size_t* uid_len);
214bool mf_ultralight_set_uid(
MfUltralightData* data,
const uint8_t* uid,
size_t uid_len);
220uint16_t mf_ultralight_get_pages_total(MfUltralightType type);
222uint32_t mf_ultralight_get_feature_support_set(MfUltralightType type);
224uint16_t mf_ultralight_get_config_page_num(MfUltralightType type);
226uint8_t mf_ultralight_get_write_end_page(MfUltralightType type);
228uint8_t mf_ultralight_get_pwd_page_num(MfUltralightType type);
230bool mf_ultralight_is_page_pwd_or_pack(MfUltralightType type, uint16_t page_num);
232bool mf_ultralight_support_feature(
const uint32_t feature_set,
const uint32_t features_to_check);
238bool mf_ultralight_detect_protocol(
const Iso14443_3aData* iso14443_3a_data);
242void mf_ultralight_3des_shift_data(uint8_t*
const arr);
248void mf_ultralight_3des_encrypt(
249 mbedtls_des3_context* ctx,
252 const uint8_t* input,
253 const uint8_t length,
256void mf_ultralight_3des_decrypt(
257 mbedtls_des3_context* ctx,
260 const uint8_t* input,
261 const uint8_t length,
NfcDeviceNameType
Verbosity level of the displayed NFC device name.
Definition nfc_device_base.h:14
Definition hid_profile.c:33
Definition iso14443_3a.h:58
Definition mf_ultralight.h:135
Definition mf_ultralight.h:127
Definition mf_ultralight.h:131
Definition mf_ultralight.h:178
Definition mf_ultralight.h:95
Definition mf_ultralight.h:99
Definition mf_ultralight.h:114
Definition mf_ultralight.h:123
Definition mf_ultralight.h:103
Generic NFC device interface.
Definition nfc_device_base_i.h:142
Definition mf_ultralight.h:118