M5Unit-NFC 0.0.3 git rev:59f5362
Loading...
Searching...
No Matches
ndef_layer.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_NFC_NFC_LAYER_NDEF_LAYER_HPP
11#define M5_UNIT_NFC_NFC_LAYER_NDEF_LAYER_HPP
12
13#include "nfc_layer.hpp"
14#include "nfc/ndef/ndef.hpp"
15#include <vector>
16
17namespace m5 {
18namespace nfc {
19class NFCLayerInterface;
20namespace isodep {
21class IsoDEP;
22}
23namespace ndef {
24
25class TLV;
26class Record;
27
28constexpr uint8_t NDEF_MAX_UNIT_SIZE_READ{32};
29constexpr uint8_t NDEF_MAX_CC_BLOCK_SIZE{32};
30
35class NDEFLayer {
36public:
37 explicit NDEFLayer(NFCLayerInterface& layer) : _interface{layer}
38 {
39 }
46 bool isValidFormat(bool& valid, const m5::nfc::NFCForumTag ftag);
47
55 bool read(const m5::nfc::NFCForumTag ftag, std::vector<m5::nfc::ndef::TLV>& tlvs,
65 bool write(const m5::nfc::NFCForumTag ftag, const std::vector<m5::nfc::ndef::TLV>& tlvs, const bool keep = true);
66
77 bool prepare_desfire(const uint32_t max_ndef_size);
78
109
110protected:
111 bool read_capability_container_type4_iso7816(m5::nfc::ndef::type4::CapabilityContainer& cc);
112 bool read_capability_container_type4_desfire(m5::nfc::ndef::type4::CapabilityContainer& cc);
113
114 bool read_type2(std::vector<m5::nfc::ndef::TLV>& tlvs, const m5::nfc::ndef::TagBits tagBits);
115 bool read_type3(m5::nfc::ndef::TLV& tlv);
116 bool read_type4(std::vector<m5::nfc::ndef::TLV>& tlvs, const m5::nfc::ndef::type4::FileControlTagBits fcBits);
117 bool read_type4_iso7816(std::vector<m5::nfc::ndef::TLV>& tlvs,
118 const m5::nfc::ndef::type4::FileControlTagBits fcBits);
119 bool read_type4_desfire(std::vector<m5::nfc::ndef::TLV>& tlvs,
120 const m5::nfc::ndef::type4::FileControlTagBits fcBits);
121 bool read_type5(std::vector<m5::nfc::ndef::TLV>& tlvs, const m5::nfc::ndef::TagBits tagBits);
122
123 bool write_type2(const std::vector<m5::nfc::ndef::TLV>& tlvs, const bool keep);
124 bool write_type3(const m5::nfc::ndef::TLV& tlv);
125 bool write_type4(const std::vector<m5::nfc::ndef::TLV>& tlvs);
126 bool write_type4_iso7816(const std::vector<m5::nfc::ndef::TLV>& tlvs, const type4::CapabilityContainer& cc,
127 isodep::IsoDEP& dep);
128 bool write_type4_desfire(const std::vector<m5::nfc::ndef::TLV>& tlvs, const type4::CapabilityContainer& cc,
129 isodep::IsoDEP& dep);
130 bool write_type5(const std::vector<m5::nfc::ndef::TLV>& tlvs, const bool keep);
131
132 std::vector<m5::nfc::ndef::TLV> merge_tlv(std::vector<m5::nfc::ndef::TLV>& old_tlvs,
133 const std::vector<m5::nfc::ndef::TLV>& tlvs);
134
137
144 bool read_nfcv(uint8_t* rx, const uint16_t offset, const uint16_t len);
153 bool write_nfcv(const uint16_t offset, const uint8_t* tx, const uint16_t len);
155
156private:
157 NFCLayerInterface& _interface;
158};
159
160} // namespace ndef
161} // namespace nfc
162} // namespace m5
163
164#endif
Common interface for NFC layer.
Definition nfc_layer.hpp:26
ISO Data Exchange Protocol.
Definition isoDEP.hpp:190
NDEF operations layer.
Definition ndef_layer.hpp:35
bool read_nfcv(uint8_t *rx, const uint16_t offset, const uint16_t len)
Read bytes from arbitrary byte offset (for NFC-V)
Definition ndef_layer.cpp:1337
bool readCapabilityContainer(m5::nfc::ndef::type2::CapabilityContainer &cc)
Read Type2 Capability Container.
Definition ndef_layer.cpp:622
bool prepare_desfire_light()
Prepare NDEF files on MIFARE DESFire Light.
Definition ndef_layer.cpp:205
bool writeCapabilityContainer(const m5::nfc::ndef::type5::CapabilityContainer &cc)
Write Type5 Capability Container.
Definition ndef_layer.cpp:776
bool write_nfcv(const uint16_t offset, const uint8_t *tx, const uint16_t len)
Write bytes to arbitrary byte offset (for NFC-V)
Definition ndef_layer.cpp:1376
bool read(const m5::nfc::NFCForumTag ftag, std::vector< m5::nfc::ndef::TLV > &tlvs, const m5::nfc::ndef::TagBits tagBits=m5::nfc::ndef::tagBitsMessage)
Read NDEF data.
Definition ndef_layer.cpp:785
bool write(const m5::nfc::NFCForumTag ftag, const std::vector< m5::nfc::ndef::TLV > &tlvs, const bool keep=true)
Write NDEF data.
Definition ndef_layer.cpp:1425
bool readAttributeBlock(m5::nfc::ndef::type3::AttributeBlock &ab)
Read Type3 Attribute Block.
Definition ndef_layer.cpp:647
bool isValidFormat(bool &valid, const m5::nfc::NFCForumTag ftag)
Check whether the tag is in NDEF format.
Definition ndef_layer.cpp:159
bool prepare_desfire(const uint32_t max_ndef_size)
Prepare NDEF files on MIFARE DESFire (EV1/EV2/EV3)
Definition ndef_layer.cpp:454
NDEF TLV container.
Definition ndef_tlv.hpp:27
For ISO-DEP.
Top level namespace of M5stack.
For NDEF.
NFC related definitions.
NDEF related.
uint8_t TagBits
TLV(Tag,Length,Value) tag bit group for type2/5.
Definition ndef.hpp:55
constexpr TagBits tagBitsMessage
Message only.
Definition ndef.hpp:113
NFCForumTag
NFC Forum Tag Type.
Definition nfc.hpp:39
Common layer for NFC related units.
Capability container for Type2.
Definition ndef.hpp:183
For Type 3 tag (T3T)
Definition ndef.hpp:254
Capability container for Type4.
Definition ndef.hpp:455
Capability container for Type5.
Definition ndef.hpp:495