10#ifndef M5_UNIT_UNIFIED_NFC_NFC_A_NFCA_HPP
11#define M5_UNIT_UNIFIED_NFC_NFC_A_NFCA_HPP
106 return t >= Type::MIFARE_Classic_Mini && t <= Type::MIFARE_Classic_4K;
112 return t >= Type::MIFARE_Ultralight && t <= Type::MIFARE_UltralightC;
118 return t >= Type::NTAG_203 && t <= Type::NTAG_216;
124 return t == Type::NTAG_4XX;
130 return t >= Type::MIFARE_Plus_2K && t <= Type::MIFARE_Plus_SE;
142 return t >= Type::MIFARE_DESFire_2K && t <= Type::MIFARE_DESFire_Light;
154 return t >= Type::ST25TA_2K && t <= Type::ST25TA_64K;
172 return (t >= Type::MIFARE_Ultralight && t <= Type::MIFARE_UltralightC) ||
is_ntag2(t);
178 return t >= Type::NTAG_210 && t <= Type::NTAG_216;
190 return ((sak & 0x24) == 0x20);
195 return ((sak & 0x24) == 0x00);
203Type sak_to_type(
const uint8_t sak);
205Type version3_to_type(
const uint8_t info[8]);
207Type version4_to_type(uint8_t& sub,
const uint8_t info[8]);
209Type historical_bytes_to_type(uint8_t& sub,
const uint16_t atqa,
const uint8_t sak,
const uint8_t* bytes,
213uint16_t get_number_of_blocks(
const Type t);
215uint16_t get_number_of_user_blocks(
const Type t);
217uint16_t get_user_area_size(
const Type t);
223uint16_t get_unit_size(
const Type t);
225uint16_t get_number_of_sectors(
const Type t);
227uint16_t get_first_user_block(
const Type t);
229uint16_t get_last_user_block(
const Type t);
231bool is_user_block(
const Type t,
const uint16_t block);
247uint8_t calculate_bcc8(
const uint8_t* data,
const uint32_t len);
250const uint8_t* get_version3_response(
const Type t);
270 inline bool validTA()
const
274 inline bool validTB()
const
278 inline bool validTC()
const
282 inline uint8_t fsci()
const
286 inline Bitrate maximumBitrateDR()
const
290 inline Bitrate maximumBitrateDS()
const
292 return validTA() ?
static_cast<Bitrate>((
TA >> 4) & 0x07) : Bitrate::Invalid;
294 inline bool supportsAsymmetricSpeed()
const
296 return validTA() && (
TA & 0x80);
298 inline uint8_t fwi()
const
300 return validTB() ? (
TB >> 4) : 0x00;
302 inline uint8_t sfgi()
const
304 return validTB() ? (
TB & 0x0F) : 0x00;
306 inline uint32_t sfgt_fc()
const
308 const uint8_t
v = sfgi();
309 return (
v == 0 ||
v == 15) ? 0u : (256u * 16u * (1u <<
v));
311 inline uint32_t sfgt_ms(
const float fc)
const
313 const uint32_t sfgt = sfgt_fc();
314 if (!sfgt || fc <= 0.0f) {
317 const float us = (
static_cast<float>(sfgt) / fc) * 1e6f;
318 uint32_t ms =
static_cast<uint32_t
>(us / 1000.f);
321 inline bool supportsNAD()
const
323 return validTC() && (
TC & 0x01);
325 inline bool supportsCID()
const
327 return validTC() && (
TC & 0x02);
365 memcpy(buf,
uid +
size - 4, 4);
378 bool emulate(
const Type t,
const uint8_t*
uid,
const uint8_t uid_len);
415 return type == Type::MIFARE_Plus_SE;
525 return (
a.size ==
b.size) && (
a.sak ==
b.sak) && (
a.type ==
b.type) && (
a.blocks ==
b.blocks) &&
526 std::memcmp(
a.uid,
b.uid, 10) == 0;
581constexpr uint32_t TIMEOUT_REQ_WUP{4};
582constexpr uint32_t TIMEOUT_SELECT{8};
583constexpr uint32_t TIMEOUT_ANTICOLL{8};
584constexpr uint32_t TIMEOUT_HALT{2};
585constexpr uint32_t TIMEOUT_GET_VERSION{5};
586constexpr uint32_t TIMEOUT_3DES{10};
587constexpr uint32_t TIMEOUT_AUTH1{4};
588constexpr uint32_t TIMEOUT_AUTH2{16};
589constexpr uint32_t TIMEOUT_READ{12};
590constexpr uint32_t TIMEOUT_FAST_READ{2};
591constexpr uint32_t TIMEOUT_FAST_READ_4PAGE{4};
592constexpr uint32_t TIMEOUT_FAST_READ_12PAGE{4};
593constexpr uint32_t TIMEOUT_FAST_READ_32PAGE{12};
594constexpr uint32_t TIMEOUT_WRITE1{5};
595constexpr uint32_t TIMEOUT_WRITE2{10};
596constexpr uint32_t TIMEOUT_VALUE_BLOCK{5};
597constexpr uint32_t TIMEOUT_RATS{5};
598constexpr uint32_t TIMEOUT_DESELECT{8};
603constexpr uint8_t ACK_NIBBLE{0x0A};
615constexpr uint8_t IC_REFERENCE_ST25TA512B{0xE5};
616constexpr uint8_t IC_REFERENCE_ST25TA02KB{0xE2};
617constexpr uint8_t IC_REFERENCE_ST25TA02KB_D{0xF2};
618constexpr uint8_t IC_REFERENCE_ST25TA02KB_P{0xA2};
619constexpr uint8_t PRODUCT_CODE_ST25TA16K{0xC5};
620constexpr uint8_t PRODUCT_CODE_ST25TA64K{0xC4};
626 return (ic_ref_or_product_code == IC_REFERENCE_ST25TA512B)
628 : ((ic_ref_or_product_code == IC_REFERENCE_ST25TA02KB ||
629 ic_ref_or_product_code == IC_REFERENCE_ST25TA02KB_D ||
630 ic_ref_or_product_code == IC_REFERENCE_ST25TA02KB_P)
632 : ((ic_ref_or_product_code == PRODUCT_CODE_ST25TA16K) ? Type::ST25TA_16K
633 : (ic_ref_or_product_code == PRODUCT_CODE_ST25TA64K) ? Type::ST25TA_64K
650 uint8_t event_counter_config;
652 uint8_t product_version;
654 uint16_t memory_size;
655 uint8_t ic_reference_code;
656 } __attribute__((packed));
663 uint16_t memory_size;
664 uint8_t product_code;
665 } __attribute__((packed_));
672 uint16_t memory_size;
673 uint8_t product_code;
674 } __attribute__((packed));
685 inline Type type()
const
689} __attribute__((packed));
Top level namespace of M5stack.
uint8_t file_system_feature_t
Alias for file_system_feature_t.
Definition nfc.hpp:62
constexpr file_system_feature_t FILE_SYSTEM_FLAT_MEMORY
Block/Page base R/W (flat memory)
Definition nfc.hpp:63
constexpr file_system_feature_t FILE_SYSTEM_DESFIRE
MIFARE DESFire (multi file base)
Definition nfc.hpp:65
Bitrate
Communication bitrate.
Definition nfc.hpp:52
constexpr file_system_feature_t FILE_SYSTEM_ISO7816_4
ISO 7816-4 (multi file base)
Definition nfc.hpp:64
NFCForumTag
NFC Forum Tag Type.
Definition nfc.hpp:39
m5::nfc::NFCForumTag get_nfc_forum_tag_type(const Type t)
Get NFC Forum Tag Type from PICC type.
Definition nfca.cpp:591
uint16_t get_unit_size(const Type t)
Get the unit size of 1 block / 1 page.
Definition nfca.cpp:341
uint16_t get_last_user_block(const Type t)
Gets the last user area block.
Definition nfca.cpp:358
file_system_feature_t get_file_system_feature(const Type t)
Get file system fearure bits.
Definition nfca.cpp:376
uint16_t get_number_of_blocks(const Type t)
Gets the number of blocks.
Definition nfca.cpp:321
uint16_t get_user_area_size(const Type t)
Gets the user area bytes.
Definition nfca.cpp:335
bool is_user_block(const Type t, const uint16_t block)
Is block user area?
Definition nfca.cpp:364
uint16_t get_first_user_block(const Type t)
Gets the first user area block.
Definition nfca.cpp:352
bool is_file_system_memory(const Type t)
Memory file system?
Definition nfca.hpp:236
bool is_mifare_desfire(const Type t)
Is type MIFARE DESFire?
Definition nfca.hpp:140
Command
ISO-14443-3/4,MIFARE,NTAG commands.
Definition nfca.hpp:538
@ AUTH_WITH_KEY_A
MIFARE Classic. Authentication with Key A.
@ RATS
Request for Answer to Select.
@ LOCK_SIG
NTAG 210u Lock/Unlock signature.
@ PERSONALIZE_UID_USAGE
MIFARE Classic Personalize UID Usage.
@ COMMIT_PERSO
MIFARE Plus. CommitPerso.
@ GET_VERSION
NTAG 21x/UL EV1,Nano Gets the version information.
@ WRITE_BLOCK
MIFARE Classic. write.
@ FAST_READ
NTAG 21x. excluding 210u. Read multiple pages.
@ SELECT_CL3
Anticollison/Select CL3.
@ WRITE_PAGE
MIFARE Ultralight/C and NTAG write.
@ SELCT_CL1_OPT
Select CL1 and switch bit rate to fc/64 after receive SAK.
@ AUTH_WITH_KEY_B
MIFARE Classic. Authentication with Key B.
@ SELECT_CL1
Anticollison/Select CL1.
@ INCREMENT
MIFARE Classic. increment value block.
@ AUTHENTICATE_1
MIFARE UltralightC. Authentication 1st.
@ SELECT_CL2
Anticollison/Select CL2.
@ PWD_AUTH
NTAG 21x excluding 210u. Authentication for protected area.
@ SET_MOD_TYPE
MIFARE Classic SET_MOD_TYPE.
@ SELCT_CL2_OPT
Select CL2 and switch bit rate to fc/64 after receive SAK.
@ DECREMENT
MIFARE Classic. decrement value block.
@ SELCT_CL3_OPT
Select CL3 and switch bit rate to fc/64 after receive SAK.
@ RESTORE
MIFARE Classic. reads the contents of a value block into the internal Transfer Buffer.
@ AUTHENTICATE_2
MIFARE UltralightC. Authentication 2nd.
@ READ_SIG
NTAG 21x Read NXP ECC signature.
@ READ_CNT
NTAG 213/5/6. Read counter value.
@ WRITE_SIG
NTAG 210u Write custom signature.
@ TRANSFER
MIFARE Classic. writes the contents of the internal Transfer Buffer to a block.
@ WRITE_PERSO
MIFARE Plus. WritePerso.
bool is_iso14443_3(const Type t)
Is ISO 14443-3?
Definition nfca.hpp:164
Type get_type(const uint8_t ic_ref_or_product_code)
Gets the type from IC reference or product code.
Definition nfca.hpp:624
bool is_ntag4(const Type t)
Is type NTAG4xx?
Definition nfca.hpp:122
bool is_ntag2(const Type t)
Is type NTAG2xx?
Definition nfca.hpp:116
bool supports_NFC(const Type t)
Does the specified type function as NFC?
Definition nfca.hpp:170
bool operator==(const PICC &a, const PICC &b)
Equal?
Definition nfca.hpp:523
bool is_sak_completed(const uint8_t sak)
SAK completed? (Does not comply with ISO/IEC 14443-4)
Definition nfca.hpp:193
bool is_sak_completed_14443_4(const uint8_t sak)
SAK completed? (Complies with ISO/IEC 14443-4)
Definition nfca.hpp:188
bool is_mifare(const Type t)
Is type MIFARE?
Definition nfca.hpp:146
constexpr uint16_t SYSTEM_FILE_ID
System file for ST25TA.
Definition nfca.hpp:611
bool is_iso14443_4(const Type t)
Is ISO 14443-4?
Definition nfca.hpp:158
bool has_fast_read(const Type t)
Has FAST_READ command?
Definition nfca.hpp:176
bool is_st25ta(const Type t)
Is ST25TA series?
Definition nfca.hpp:152
bool is_mifare_classic_compatible(const Type t, const uint8_t sl)
Is type MIFARE classic compatible? (Plus SL1)
Definition nfca.hpp:134
bool operator!=(const PICC &a, const PICC &b)
Not equal?
Definition nfca.hpp:529
Type
Type of the PICC.
Definition nfca.hpp:31
@ MIFARE_Ultralight_EV1_1
MIFARE Ultralight EV1 MF0UL11.
@ MIFARE_Ultralight_EV1_2
MIFARE Ultralight EV1 MF0UL21.
@ MIFARE_Plus_4K
MIFARE Plus 4K.
@ MIFARE_Ultralight_Nano
MIFARE Ultralight Nano.
@ MIFARE_DESFire_4K
MIFARE DESFire 4K.
@ MIFARE_Classic_Mini
Also known as MIFARE Standard mini.
@ MIFARE_DESFire_2K
MIFARE DESFire 2K.
@ MIFARE_Ultralight
MIFARE Ultralight.
@ MIFARE_DESFire_8K
MIFARE DESFire 8K.
@ MIFARE_Classic_1K
Also known as MIFARE Standard 1K.
@ MIFARE_UltralightC
MIFARE UltralightC.
@ MIFARE_Plus_SE
MIFARE Plus SE 1K.
@ MIFARE_Plus_2K
MIFARE Plus 2K.
@ MIFARE_DESFire_Light
MIFARE DESFire Light.
@ ISO_18092
PICC compliant with ISO/IEC 18092.
@ MIFARE_Classic_2K
Also known as MIFARE Standard 2K.
@ MIFARE_Classic_4K
Also known as MIFARE Standard 4K.
@ ISO_14443_4
PICC compliant with ISO/IEC 14443-4.
bool is_mifare_ultralight(const Type t)
Is type MIFARE Ultralight series?
Definition nfca.hpp:110
bool has_sak_dependent_bit(const uint8_t sak)
SAK uncompleted?
Definition nfca.hpp:182
SubTypeDESFire
Sub type for MIFARE DESFire.
Definition nfca.hpp:93
bool is_mifare_plus(const Type t)
Is type MIFARE Plus?
Definition nfca.hpp:128
bool is_file_system_file(const Type t)
File base file system?
Definition nfca.hpp:241
SubTypePlus
Sub type for MIFARE Plus.
Definition nfca.hpp:80
bool is_mifare_classic(const Type t)
Is type MIFARE Classic?
Definition nfca.hpp:104
Answer to request.
Definition nfca.hpp:256
uint8_t TA
Interface DS/DR.
Definition nfca.hpp:262
uint8_t historical_len
Length of historical bytes.
Definition nfca.hpp:268
std::array< uint8_t, 32 > historical
Historical bytes(optional)
Definition nfca.hpp:267
uint8_t TL
Length byte.
Definition nfca.hpp:260
uint8_t T0
Format byte.
Definition nfca.hpp:261
uint8_t TC
Code protocol options.
Definition nfca.hpp:264
uint8_t TB
Interface FWI/SFGI.
Definition nfca.hpp:263
PICC for NFC-A.
Definition nfca.hpp:335
uint8_t sak
The SAK (Select acknowledge) returned from the PICC after successful selection.
Definition nfca.hpp:338
file_system_feature_t fileSystemFeature() const
File system features.
Definition nfca.hpp:507
bool isFileSystemFile() const
Supports NFC?
Definition nfca.hpp:515
uint16_t userAreaSize() const
Total user area size.
Definition nfca.hpp:458
bool supportsNFC() const
Supports NFC?
Definition nfca.hpp:487
uint16_t atqa
ATQA.
Definition nfca.hpp:341
bool isMifareClassic() const
Is MIFARE classic? (include Plus compatible SL)
Definition nfca.hpp:388
uint8_t size
UID size 4, 7 or 10.
Definition nfca.hpp:339
uint16_t lastUserBlock() const
Total size.
Definition nfca.hpp:473
bool isFileSystemMemory() const
Supports NFC?
Definition nfca.hpp:511
bool isMifareClassicCompatible() const
Is MIFARE?
Definition nfca.hpp:422
bool isMifare() const
Is MIFARE?
Definition nfca.hpp:383
bool isMifarePlusSE() const
Is MIFARE Plus SE?
Definition nfca.hpp:413
std::string typeAsString() const
Gets the type string.
Definition nfca.cpp:609
uint8_t security_level
Security level for Plus.
Definition nfca.hpp:352
bool valid() const
Valid?
Definition nfca.hpp:356
ATS ats
Definition nfca.hpp:343
bool isST25TA() const
Is ST25TA?
Definition nfca.hpp:442
uint16_t firstUserBlock() const
Gets the first user block/page address.
Definition nfca.hpp:469
void tail4(uint8_t buf[4]) const
Retrieve the last 4 bytes of UID.
Definition nfca.hpp:362
uint16_t unitSize() const
Read/Write unit size.
Definition nfca.hpp:463
SubTypePlus sub_type_plus
For Plus.
Definition nfca.hpp:347
bool emulate(const Type t, const uint8_t *uid, const uint8_t uid_len)
Emulation settings.
Definition nfca.cpp:641
bool isMifareUltralight() const
Is MIFARE Ultralight series?
Definition nfca.hpp:393
uint16_t blocks
Number of the blocks or pages.
Definition nfca.hpp:342
bool isNTAG2() const
Is NTAG?
Definition nfca.hpp:432
bool isMifarePlusS() const
Is MIFARE Plus S?
Definition nfca.hpp:408
bool requiresPlusSL3PlainRead() const
Requires plain mode for SL3 read? (Plus S and SE don't support encrypted read)
Definition nfca.hpp:418
std::string uidAsString() const
Gets the uid string.
Definition nfca.cpp:597
bool supportsNDEF() const
Supports NDEF?
Definition nfca.hpp:492
uint16_t totalSize() const
Total size.
Definition nfca.hpp:451
uint8_t uid[10]
uid (Valid up to the value of size)
Definition nfca.hpp:340
bool isMifarePlusX() const
Is MIFARE Plus X?
Definition nfca.hpp:403
bool isISO14443_4() const
Is ISO1443-4?
Definition nfca.hpp:437
SubTypeDESFire sub_type_desfire
For DESFire.
Definition nfca.hpp:348
uint8_t sub_type
uint8_t access
Definition nfca.hpp:346
bool isMifarePlus() const
Is MIFARE Plus?
Definition nfca.hpp:398
bool isMifareDESFire() const
Is MIFARE DESFire? (include Light)
Definition nfca.hpp:427
bool isUserBlock(const uint8_t block) const
Is user block?
Definition nfca.hpp:478
Type type
PICC type.
Definition nfca.hpp:337
bool canFastRead() const
Can use FAST_READ command?
Definition nfca.hpp:502
NFCForumTag nfcForumTagType() const
NFC ForumTag.
Definition nfca.hpp:497
ST25TA series system file.
Definition nfca.hpp:641