10#ifndef M5_UNIT_UNIFIED_NFC_NFC_A_NFCA_HPP
11#define M5_UNIT_UNIFIED_NFC_NFC_A_NFCA_HPP
114 return t >= Type::MIFARE_Classic_Mini && t <= Type::MIFARE_Classic_4K;
124 return t >= Type::MIFARE_Ultralight && t <= Type::MIFARE_UltralightC;
134 return t >= Type::NTAG_203 && t <= Type::NTAG_216;
144 return t == Type::NTAG_4XX;
154 return t >= Type::MIFARE_Plus_2K && t <= Type::MIFARE_Plus_SE;
175 return t >= Type::MIFARE_DESFire_2K && t <= Type::MIFARE_DESFire_Light;
195 return t >= Type::ST25TA_2K && t <= Type::ST25TA_64K;
225 return (t >= Type::MIFARE_Ultralight && t <= Type::MIFARE_UltralightC) ||
is_ntag2(t);
235 return t >= Type::NTAG_210 && t <= Type::NTAG_216;
255 return ((sak & 0x24) == 0x20);
264 return ((sak & 0x24) == 0x00);
273Type sak_to_type(
const uint8_t sak);
279Type version3_to_type(
const uint8_t info[8]);
286Type version4_to_type(uint8_t& sub,
const uint8_t info[8]);
296Type historical_bytes_to_type(uint8_t& sub,
const uint16_t atqa,
const uint8_t sak,
const uint8_t* bytes,
304uint16_t get_number_of_blocks(
const Type t);
310uint16_t get_number_of_user_blocks(
const Type t);
316uint16_t get_user_area_size(
const Type t);
323uint16_t get_unit_size(
const Type t);
329uint16_t get_number_of_sectors(
const Type t);
335uint16_t get_first_user_block(
const Type t);
341uint16_t get_last_user_block(
const Type t);
348bool is_user_block(
const Type t,
const uint16_t block);
381uint8_t calculate_bcc8(
const uint8_t* data,
const uint32_t len);
388const uint8_t* get_version3_response(
const Type t);
408 inline bool validTA()
const
412 inline bool validTB()
const
416 inline bool validTC()
const
420 inline uint8_t fsci()
const
424 inline Bitrate maximumBitrateDR()
const
427 return Bitrate::Invalid;
429 const uint8_t
v =
TA & 0x07;
432 inline Bitrate maximumBitrateDS()
const
435 return Bitrate::Invalid;
437 const uint8_t
v = (
TA >> 4) & 0x07;
440 inline bool supportsAsymmetricSpeed()
const
442 return validTA() && (
TA & 0x80);
444 inline uint8_t fwi()
const
446 return validTB() ? (
TB >> 4) : 0x00;
448 inline uint8_t sfgi()
const
450 return validTB() ? (
TB & 0x0F) : 0x00;
452 inline uint32_t sfgt_fc()
const
454 const uint8_t
v = sfgi();
455 return (
v == 0 ||
v == 15) ? 0u : (256u * 16u * (1u <<
v));
457 inline uint32_t sfgt_ms(
const float fc)
const
459 const uint32_t sfgt = sfgt_fc();
460 if (!sfgt || fc <= 0.0f) {
463 const float us = (
static_cast<float>(sfgt) / fc) * 1e6f;
464 uint32_t ms =
static_cast<uint32_t
>(us / 1000.f);
467 inline bool supportsNAD()
const
469 return validTC() && (
TC & 0x01);
471 inline bool supportsCID()
const
473 return validTC() && (
TC & 0x02);
511 memcpy(buf,
uid +
size - 4, 4);
524 bool emulate(
const Type t,
const uint8_t*
uid,
const uint8_t uid_len);
561 return type == Type::MIFARE_Plus_SE;
671 return (
a.size ==
b.size) && (
a.sak ==
b.sak) && (
a.type ==
b.type) && (
a.blocks ==
b.blocks) &&
672 std::memcmp(
a.uid,
b.uid, 10) == 0;
742 return static_cast<uint8_t
>(((fsdi & 0x0F) << 4) | (cid & 0x0F));
747constexpr uint32_t TIMEOUT_REQ_WUP{4};
748constexpr uint32_t TIMEOUT_SELECT{8};
749constexpr uint32_t TIMEOUT_ANTICOLL{8};
750constexpr uint32_t TIMEOUT_HALT{2};
751constexpr uint32_t TIMEOUT_GET_VERSION{5};
752constexpr uint32_t TIMEOUT_3DES{10};
753constexpr uint32_t TIMEOUT_AUTH1{4};
754constexpr uint32_t TIMEOUT_AUTH2{16};
755constexpr uint32_t TIMEOUT_READ{12};
756constexpr uint32_t TIMEOUT_FAST_READ{2};
757constexpr uint32_t TIMEOUT_FAST_READ_4PAGE{4};
758constexpr uint32_t TIMEOUT_FAST_READ_12PAGE{4};
759constexpr uint32_t TIMEOUT_FAST_READ_32PAGE{12};
760constexpr uint32_t TIMEOUT_WRITE1{5};
761constexpr uint32_t TIMEOUT_WRITE2{10};
762constexpr uint32_t TIMEOUT_VALUE_BLOCK{5};
763constexpr uint32_t TIMEOUT_RATS{5};
764constexpr uint32_t TIMEOUT_DESELECT{8};
769constexpr uint8_t ACK_NIBBLE{0x0A};
781constexpr uint8_t IC_REFERENCE_ST25TA512B{0xE5};
782constexpr uint8_t IC_REFERENCE_ST25TA02KB{0xE2};
783constexpr uint8_t IC_REFERENCE_ST25TA02KB_D{0xF2};
784constexpr uint8_t IC_REFERENCE_ST25TA02KB_P{0xA2};
785constexpr uint8_t PRODUCT_CODE_ST25TA16K{0xC5};
786constexpr uint8_t PRODUCT_CODE_ST25TA64K{0xC4};
792 return (ic_ref_or_product_code == IC_REFERENCE_ST25TA512B)
794 : ((ic_ref_or_product_code == IC_REFERENCE_ST25TA02KB ||
795 ic_ref_or_product_code == IC_REFERENCE_ST25TA02KB_D ||
796 ic_ref_or_product_code == IC_REFERENCE_ST25TA02KB_P)
798 : ((ic_ref_or_product_code == PRODUCT_CODE_ST25TA16K) ? Type::ST25TA_16K
799 : (ic_ref_or_product_code == PRODUCT_CODE_ST25TA64K) ? Type::ST25TA_64K
816 uint8_t event_counter_config;
818 uint8_t product_version;
820 uint16_t memory_size;
821 uint8_t ic_reference_code;
822 } __attribute__((packed));
829 uint16_t memory_size;
830 uint8_t product_code;
831 } __attribute__((packed_));
838 uint16_t memory_size;
839 uint8_t product_code;
840 } __attribute__((packed));
859} __attribute__((packed));
Top level namespace of M5Stack.
@ Invalid
Unknown / not yet decoded.
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 feature 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:361
bool is_mifare_desfire(const Type t)
Is type MIFARE DESFire?
Definition nfca.hpp:173
Command
ISO-14443-3/4,MIFARE,NTAG commands.
Definition nfca.hpp:684
@ 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:213
Type get_type(const uint8_t ic_ref_or_product_code)
Gets the type from IC reference or product code.
Definition nfca.hpp:790
bool is_ntag4(const Type t)
Is type NTAG4xx?
Definition nfca.hpp:142
bool is_ntag2(const Type t)
Is type NTAG2xx?
Definition nfca.hpp:132
bool supports_NFC(const Type t)
Does the specified type function as NFC?
Definition nfca.hpp:223
bool operator==(const PICC &a, const PICC &b)
Equal?
Definition nfca.hpp:669
bool is_sak_completed(const uint8_t sak)
SAK completed? (Does not comply with ISO/IEC 14443-4)
Definition nfca.hpp:262
uint8_t make_rats_param(const uint8_t fsdi, const uint8_t cid)
Build the RATS PARAM byte (ISO/IEC 14443-4)
Definition nfca.hpp:740
bool is_sak_completed_14443_4(const uint8_t sak)
SAK completed? (Complies with ISO/IEC 14443-4)
Definition nfca.hpp:253
bool is_mifare(const Type t)
Is type MIFARE?
Definition nfca.hpp:183
constexpr uint16_t SYSTEM_FILE_ID
System file for ST25TA.
Definition nfca.hpp:777
bool is_iso14443_4(const Type t)
Is ISO 14443-4?
Definition nfca.hpp:203
bool has_fast_read(const Type t)
Has FAST_READ command?
Definition nfca.hpp:233
bool is_st25ta(const Type t)
Is ST25TA series?
Definition nfca.hpp:193
bool is_mifare_classic_compatible(const Type t, const uint8_t sl)
Is type MIFARE classic compatible? (Plus SL1)
Definition nfca.hpp:163
bool operator!=(const PICC &a, const PICC &b)
Not equal?
Definition nfca.hpp:675
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:122
bool has_sak_dependent_bit(const uint8_t sak)
SAK incomplete?
Definition nfca.hpp:243
SubTypeDESFire
Sub type for MIFARE DESFire.
Definition nfca.hpp:93
bool is_mifare_plus(const Type t)
Is type MIFARE Plus?
Definition nfca.hpp:152
bool is_file_system_file(const Type t)
File base file system?
Definition nfca.hpp:370
SubTypePlus
Sub type for MIFARE Plus.
Definition nfca.hpp:80
bool is_mifare_classic(const Type t)
Is type MIFARE Classic?
Definition nfca.hpp:112
Answer to request.
Definition nfca.hpp:394
uint8_t TA
Interface DS/DR.
Definition nfca.hpp:400
uint8_t historical_len
Length of historical bytes.
Definition nfca.hpp:406
std::array< uint8_t, 32 > historical
Historical bytes(optional)
Definition nfca.hpp:405
uint8_t TL
Length byte.
Definition nfca.hpp:398
uint8_t T0
Format byte.
Definition nfca.hpp:399
uint8_t TC
Code protocol options.
Definition nfca.hpp:402
uint8_t TB
Interface FWI/SFGI.
Definition nfca.hpp:401
PICC for NFC-A.
Definition nfca.hpp:481
uint8_t sak
The SAK (Select acknowledge) returned from the PICC after successful selection.
Definition nfca.hpp:484
file_system_feature_t fileSystemFeature() const
File system features.
Definition nfca.hpp:653
bool isFileSystemFile() const
Supports NFC?
Definition nfca.hpp:661
uint16_t userAreaSize() const
Total user area size.
Definition nfca.hpp:604
bool supportsNFC() const
Supports NFC?
Definition nfca.hpp:633
uint16_t atqa
ATQA.
Definition nfca.hpp:487
bool isMifareClassic() const
Is MIFARE classic? (include Plus compatible SL)
Definition nfca.hpp:534
uint8_t size
UID size 4, 7 or 10.
Definition nfca.hpp:485
uint16_t lastUserBlock() const
Total size.
Definition nfca.hpp:619
bool isFileSystemMemory() const
Supports NFC?
Definition nfca.hpp:657
bool isMifareClassicCompatible() const
Is MIFARE?
Definition nfca.hpp:568
bool isMifare() const
Is MIFARE?
Definition nfca.hpp:529
bool isMifarePlusSE() const
Is MIFARE Plus SE?
Definition nfca.hpp:559
std::string typeAsString() const
Gets the type string.
Definition nfca.cpp:609
uint8_t security_level
Security level for Plus.
Definition nfca.hpp:498
bool valid() const
Valid?
Definition nfca.hpp:502
ATS ats
Definition nfca.hpp:489
bool isST25TA() const
Is ST25TA?
Definition nfca.hpp:588
uint16_t firstUserBlock() const
Gets the first user block/page address.
Definition nfca.hpp:615
void tail4(uint8_t buf[4]) const
Retrieve the last 4 bytes of UID.
Definition nfca.hpp:508
uint16_t unitSize() const
Read/Write unit size.
Definition nfca.hpp:609
SubTypePlus sub_type_plus
For Plus.
Definition nfca.hpp:493
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:539
uint16_t blocks
Number of the blocks or pages.
Definition nfca.hpp:488
bool isNTAG2() const
Is NTAG?
Definition nfca.hpp:578
bool isMifarePlusS() const
Is MIFARE Plus S?
Definition nfca.hpp:554
bool requiresPlusSL3PlainRead() const
Requires plain mode for SL3 read? (Plus S and SE don't support encrypted read)
Definition nfca.hpp:564
std::string uidAsString() const
Gets the uid string.
Definition nfca.cpp:597
bool supportsNDEF() const
Supports NDEF?
Definition nfca.hpp:638
uint16_t totalSize() const
Total size.
Definition nfca.hpp:597
uint8_t uid[10]
uid (Valid up to the value of size)
Definition nfca.hpp:486
bool isMifarePlusX() const
Is MIFARE Plus X?
Definition nfca.hpp:549
bool isISO14443_4() const
Is ISO14443-4?
Definition nfca.hpp:583
SubTypeDESFire sub_type_desfire
For DESFire.
Definition nfca.hpp:494
uint8_t sub_type
uint8_t access
Definition nfca.hpp:492
bool isMifarePlus() const
Is MIFARE Plus?
Definition nfca.hpp:544
bool isMifareDESFire() const
Is MIFARE DESFire? (include Light)
Definition nfca.hpp:573
bool isUserBlock(const uint8_t block) const
Is user block?
Definition nfca.hpp:624
Type type
PICC type.
Definition nfca.hpp:483
bool canFastRead() const
Can use FAST_READ command?
Definition nfca.hpp:648
NFCForumTag nfcForumTagType() const
NFC ForumTag.
Definition nfca.hpp:643
NFC-A activation configuration (RATS parameters)
Definition nfca.hpp:729
uint8_t fsdi
PCD's max receive frame size index 0..8 (16..256 bytes). Default 5 keeps current behavior.
Definition nfca.hpp:730
uint8_t cid
Card IDentifier 0..14.
Definition nfca.hpp:731
ST25TA series system file.
Definition nfca.hpp:807
Type type() const
Gets the ST25TA type.
Definition nfca.hpp:855