M5Unit-NFC 0.0.3 git rev:59f5362
Loading...
Searching...
No Matches
nfcv.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_UNIFIED_NFC_NFC_V_NFCV_HPP
11#define M5_UNIT_UNIFIED_NFC_NFC_V_NFCV_HPP
12
13#include "nfc/nfc.hpp"
14#include <cstdint>
15#include <string>
16#include <cstring>
17#include <vector>
18
19namespace m5 {
20namespace nfc {
25namespace v {
26
31enum class Type : uint8_t {
32 Unknown,
33
37 NXP,
38
43 TI,
44
45 ST_LRI,
46 ST_ST25V,
47 ST_ST25DV,
48 ST,
49
51 Fujitsu,
52
53 Unclassified,
54};
55
58const uint8_t option_flag{0x40};
59const uint8_t address_flag{0x20};
60const uint8_t select_flag{0x10};
61const uint8_t inventory_flag{0x04};
62const uint8_t data_rate_flag{0x02};
63const uint8_t subcarrior_flag{0x01};
64const uint8_t nb_slots_flag{0x20}; // if inventory_flag is 1
65const uint8_t AFI_flag{0x10}; // // if inventory_flag is 1
66constexpr uint8_t MAX_BLOCK_SIZE{32};
68
73enum class ModulationMode : uint8_t {
74 OneOf4,
75 OneOf256,
76};
77
79inline m5::nfc::NFCForumTag get_nfc_forum_tag_type(const Type t)
80{
81 return (t != Type::Unknown) ? NFCForumTag::Type5 : NFCForumTag::None;
82}
83
88struct PICC {
89 uint8_t uid[8]{};
91 uint8_t dsfID{};
92 uint8_t afi{};
93 uint8_t icRef{};
94 uint8_t block_size{};
95 uint8_t _pad{}; //
96 uint16_t blocks{};
97
98 inline bool valid() const
99 {
100 return (uid[0] == 0xE0) && blocks && block_size;
101 }
102 inline uint8_t manufacturerCode() const
103 {
104 return valid() ? uid[1] : 0xFF;
105 }
106 inline uint8_t icIdentifier() const
107 {
108 return valid() ? uid[2] : 0x00;
109 }
110 inline uint8_t icReference() const
111 {
112 return valid() ? icRef : 0xFF;
113 }
114
115 //
116 inline uint16_t totalSize() const
117 {
118 return blocks * block_size;
119 }
121 inline uint16_t userAreaSize() const
122 {
123 return totalSize(); // Same as totalSize
124 }
127 {
128 return get_nfc_forum_tag_type(type);
129 }
130
132 inline uint16_t firstUserBlock() const
133 {
134 return valid() ? 0 : 0xFFFF;
135 }
137 inline uint16_t lastUserBlock() const
138 {
139 return valid() ? (blocks - 1) : 0xFFFF;
140 }
141
143 std::string uidAsString() const;
145 std::string typeAsString() const;
146};
147
149inline bool operator==(const PICC& a, const PICC& b)
150{
151 return std::memcmp(a.uid, b.uid, 8) == 0;
152}
154inline bool operator!=(const PICC& a, const PICC& b)
155{
156 return !(a == b);
157}
158
165Type identify_type(const PICC& picc);
166
171enum class Command : uint8_t {
172 Inventory = 0x01,
173 StayQuiet = 0x02,
174 Select = 0x25,
175 ResetToReady = 0x26,
176 GetSystemInformaion = 0x2B,
177 ExtendedGetSystemInfo = 0x3B,
178 ReadSingleBlock = 0x20,
180 WriteSingleBlock = 0x21,
182};
183
186constexpr uint32_t TIMEOUT_INVENTORY{16};
187constexpr uint32_t TIMEOUT_STAY_QUIET{16};
188constexpr uint32_t TIMEOUT_SELECT{16};
189constexpr uint32_t TIMEOUT_RESET_TO_READY{16};
190constexpr uint32_t TIMEOUT_GET_SYSTEM_INFORMATION{20};
191constexpr uint32_t TIMEOUT_READ_SINGLE_BLOCK{20};
192constexpr uint32_t TIMEOUT_WRITE_SINGLE_BLOCK{30};
194
206uint32_t encode_VCD(std::vector<uint8_t>& out, const ModulationMode mode, const uint8_t* buffer, const uint32_t length,
207 const bool high_rate = true, const bool add_crc = true);
208
216bool decode_VICC(std::vector<uint8_t>& out, const uint8_t* buffer, const uint32_t length,
217 const uint32_t ignore_bits = 16);
218
219} // namespace v
220} // namespace nfc
221} // namespace m5
222#endif
@ NXP
NXP Semiconductors.
NFC-A definitions.
NFC-B definitions.
Top level namespace of M5stack.
NFC related definitions.
NFC-V definitions.
NFC definitions.
NFCForumTag
NFC Forum Tag Type.
Definition nfc.hpp:39
Type
Type of the PICC.
Definition nfcv.hpp:31
@ ST_ST25DV
ST25DV.
@ TI_TAGIT_2048
Tag-it 2048.
@ NXP_ICODE_SLI
ICODE SLI.
@ TI_TAGIT_HF_I
Tag-it HF-I Standard.
@ NXP_ICODE_SLIX_2
ICODE SLIX2.
@ TI_TAGIT_HF_I_Pro
Tag-it HF-I Pro.
@ TI_TAGIT_HF_I_Plus
Tag-it HF-I Plus.
@ TI
TI (Unclassified)
@ NXP_ICODE_SLIX
ICODE SLIX.
@ ST
ST (Unclassified)
Command
ISO/IEC 15693 Command.
Definition nfcv.hpp:171
@ ExtendedReadSingleBlock
EXTENDED READ SINGLE BLOCK.
@ GetSystemInformaion
GET SYSTEM INFORMATION.
@ ExtendedGetSystemInfo
EXTENDED GET SYSTEM INFORMATION.
@ Inventory
IVENTORY.
@ ExtendedWriteSingleBlock
EXTENDED WRITE SINGLE BLOCK.
@ ResetToReady
RESET TO READY.
@ ReadSingleBlock
READ SINGLE BLOCK.
@ StayQuiet
STAY QUIET.
@ WriteSingleBlock
WRITE SINGLE BLOCK.
ModulationMode
Definition nfcv.hpp:73
@ OneOf256
1 out of 256 pulse-position modulation
@ OneOf4
1 out of 4 pulse-position modulation
PICC for NFC-V.
Definition nfcv.hpp:88
std::string uidAsString() const
Gets the uid string.
Definition nfcv.cpp:375
uint16_t userAreaSize() const
Total user area size.
Definition nfcv.hpp:121
Type type
Type.
Definition nfcv.hpp:90
uint16_t lastUserBlock() const
Gets the last user block.
Definition nfcv.hpp:137
uint8_t afi
Application Family Identifier.
Definition nfcv.hpp:92
NFCForumTag nfcForumTagType() const
NFC ForumTag.
Definition nfcv.hpp:126
uint8_t uid[8]
UID (MSB-first)
Definition nfcv.hpp:89
uint16_t blocks
Number of blocks.
Definition nfcv.hpp:96
std::string typeAsString() const
Gets the type string.
Definition nfcv.cpp:385
uint16_t firstUserBlock() const
Gets the first user block.
Definition nfcv.hpp:132
uint8_t dsfID
Data Storage Format Identifier.
Definition nfcv.hpp:91
uint8_t block_size
Byte size of 1 block.
Definition nfcv.hpp:94
uint8_t icRef
IC Reference.
Definition nfcv.hpp:93