Loading...
Searching...
No Matches
ntag4xx.h
1#pragma once
2
3#include <lib/nfc/protocols/iso14443_4a/iso14443_4a.h>
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9#define NTAG4XX_UID_SIZE (7)
10#define NTAG4XX_BATCH_SIZE (4)
11#define NTAG4XX_BATCH_EXTRA_BITS 4
12#define NTAG4XX_FAB_KEY_SIZE_BITS_4 4
13#define NTAG4XX_FAB_KEY_SIZE_BITS_1 1
14#define NTAG4XX_PROD_WEEK_SIZE_BITS 7
15
16#define NTAG4XX_CMD_GET_VERSION (0x60)
17
18typedef enum {
19 Ntag4xxErrorNone,
20 Ntag4xxErrorNotPresent,
21 Ntag4xxErrorProtocol,
22 Ntag4xxErrorTimeout,
23} Ntag4xxError;
24
25typedef enum {
26 Ntag4xxType413DNA,
27 Ntag4xxType424DNA,
28 Ntag4xxType424DNATT,
29 Ntag4xxType426QDNA,
30 Ntag4xxType426QDNATT,
31
32 Ntag4xxTypeUnknown,
33 Ntag4xxTypeNum,
34} Ntag4xxType;
35
36#pragma pack(push, 1)
37typedef struct {
38 uint8_t hw_vendor;
39 uint8_t hw_type;
40 uint8_t hw_subtype;
41 uint8_t hw_major;
42 uint8_t hw_minor;
43 uint8_t hw_storage;
44 uint8_t hw_proto;
45
46 uint8_t sw_vendor;
47 uint8_t sw_type;
48 uint8_t sw_subtype;
49 uint8_t sw_major;
50 uint8_t sw_minor;
51 uint8_t sw_storage;
52 uint8_t sw_proto;
53
54 uint8_t uid[NTAG4XX_UID_SIZE];
55 // [36b batch][5b fab key][7b prod week]
56 // 5b fab key is split 4b in last byte of batch and 1b in prod week
57 // Due to endianness, they appear swapped in the struct definition
58 uint8_t batch[NTAG4XX_BATCH_SIZE];
59 struct {
60 uint8_t fab_key_4b : NTAG4XX_FAB_KEY_SIZE_BITS_4;
61 uint8_t batch_extra : NTAG4XX_BATCH_EXTRA_BITS;
62 };
63 struct {
64 uint8_t prod_week : NTAG4XX_PROD_WEEK_SIZE_BITS;
65 uint8_t fab_key_1b : NTAG4XX_FAB_KEY_SIZE_BITS_1;
66 };
67 uint8_t prod_year;
68 struct {
69 uint8_t fab_key_id;
70 } optional;
72#pragma pack(pop)
73
74typedef struct {
75 Iso14443_4aData* iso14443_4a_data;
76 Ntag4xxVersion version;
77 FuriString* device_name;
79
80extern const NfcDeviceBase nfc_device_ntag4xx;
81
82// Virtual methods
83
84Ntag4xxData* ntag4xx_alloc(void);
85
86void ntag4xx_free(Ntag4xxData* data);
87
88void ntag4xx_reset(Ntag4xxData* data);
89
90void ntag4xx_copy(Ntag4xxData* data, const Ntag4xxData* other);
91
92bool ntag4xx_verify(Ntag4xxData* data, const FuriString* device_type);
93
94bool ntag4xx_load(Ntag4xxData* data, FlipperFormat* ff, uint32_t version);
95
96bool ntag4xx_save(const Ntag4xxData* data, FlipperFormat* ff);
97
98bool ntag4xx_is_equal(const Ntag4xxData* data, const Ntag4xxData* other);
99
100const char* ntag4xx_get_device_name(const Ntag4xxData* data, NfcDeviceNameType name_type);
101
102const uint8_t* ntag4xx_get_uid(const Ntag4xxData* data, size_t* uid_len);
103
104bool ntag4xx_set_uid(Ntag4xxData* data, const uint8_t* uid, size_t uid_len);
105
106Iso14443_4aData* ntag4xx_get_base_data(const Ntag4xxData* data);
107
108// Helpers
109
110Ntag4xxType ntag4xx_get_type_from_version(const Ntag4xxVersion* const version);
111
112#ifdef __cplusplus
113}
114#endif
NfcDeviceNameType
Verbosity level of the displayed NFC device name.
Definition nfc_device_base.h:14
Definition flipper_format.c:17
Definition string.c:4
Definition iso14443_4a.h:42
Generic NFC device interface.
Definition nfc_device_base_i.h:142
Definition ntag4xx.h:74
Definition ntag4xx.h:37