M5Unit-NFC 0.0.3 git rev:59f5362
Loading...
Searching...
No Matches
m5::nfc::NFCLayerA Class Reference

Common interface layer for each chip of the NFC-A reader. More...

#include <nfc_layer_a.hpp>

Inheritance diagram for m5::nfc::NFCLayerA:
m5::nfc::NFCLayerInterface

Public Member Functions

 NFCLayerA (m5::unit::UnitMFRC522 &u)
 
 NFCLayerA (m5::unit::UnitWS1850S &u)
 
 NFCLayerA (m5::unit::UnitST25R3916 &u)
 
 NFCLayerA (m5::unit::CapST25R3916 &u)
 
bool isActive (const m5::nfc::a::PICC &picc) const
 Is the specified PICC currently active?
 
const m5::nfc::a::PICCactivatedPICC () const
 Retrieve the currently activated PICC.
 
override
virtual bool transceive (uint8_t *rx, uint16_t &rx_len, const uint8_t *tx, const uint16_t tx_len, const uint32_t timeout_ms) override
 Transceive (RF command)
 
virtual m5::nfc::NFCForumTag supportsNFCTag () const override
 activePICC's NDEF type
 
virtual file_system_feature_t supportsFilesystem () const override
 activePICC's File system
 
virtual m5::nfc::isodep::IsoDEPisoDEP () override
 ISO-DEP interface (nullptr if not supported)
 
virtual uint16_t maximum_fifo_depth () const override
 Maximum FIFO depth.
 
Detection and activation
bool request (uint16_t &atqa)
 Send REQA to discover a PICC in IDLE.
 
bool wakeup (uint16_t &atqa)
 Send WUPA to wake a PICC from IDLE or HALT.
 
bool detect (m5::nfc::a::PICC &picc, const uint32_t timeout_ms=100U)
 Detect single idle PICC.
 
bool detect (std::vector< m5::nfc::a::PICC > &piccs, const uint32_t timeout_ms=1000U)
 Detect idle PICCs.
 
bool select (m5::nfc::a::PICC &picc)
 Select a PICC (anti-collision + SELECT cascade to ACTIVE)
 
bool activate (const m5::nfc::a::PICC &picc, const bool force_rats=false)
 Activate a specific PICC (anti-collision against the given PICC)
 
bool reactivate (const m5::nfc::a::PICC &picc, const bool force_rats=false)
 Wake and activate a specific PICC by PICC.
 
bool reactivate ()
 Reactivate the previously selected PICC.
 
For activated PICC
bool deactivate ()
 Send HLTA to the currently selected PICC (deactivate)
 
bool identify (m5::nfc::a::PICC &picc)
 Identify the specified PICC type.
 
bool read4 (uint8_t rx[4], const uint8_t addr)
 Read the 1 page.
 
bool read16 (uint8_t rx[16], const uint8_t addr)
 Read the 1 block / 4 page (16 bytes)
 
bool read (uint8_t *rx, uint16_t &rx_len, const uint8_t saddr, const m5::nfc::a::mifare::classic::Key &key=m5::nfc::a::mifare::classic::DEFAULT_KEY)
 Read any bytes from user area.
 
bool read (uint8_t *rx, uint16_t &rx_len, const uint8_t saddr, const m5::nfc::a::mifare::plus::AESKey &key)
 Read any bytes from user area (MIFARE Plus SL3)
 
bool write4 (const uint8_t addr, const uint8_t *tx, const uint16_t tx_len, const bool safety=true)
 Write the 1 page (4 bytes)
 
bool write16 (const uint8_t addr, const uint8_t *tx, const uint16_t tx_len, const bool safety=true)
 Write the 1 block / 4 page (16 bytes)
 
bool write (const uint8_t saddr, const uint8_t *tx, const uint16_t tx_len, const m5::nfc::a::mifare::classic::Key &key=m5::nfc::a::mifare::classic::DEFAULT_KEY)
 Write any bytes to user area.
 
bool write (const uint8_t addr, const uint8_t *tx, const uint16_t tx_len, const m5::nfc::a::mifare::plus::AESKey &key)
 Write any bytes to user area (MIFARE Plus SL3)
 
bool dump (const m5::nfc::a::mifare::classic::Key &mkey=m5::nfc::a::mifare::classic::DEFAULT_KEY)
 Dump all blocks/files.
 
bool dump (const uint8_t block)
 Dump 1 block.
 
For MIFARE classic
Note
For activated PICC
bool mifareClassicAuthenticateA (const uint8_t block, const m5::nfc::a::mifare::classic::Key &key=m5::nfc::a::mifare::classic::DEFAULT_KEY)
 Authentication by KeyA for MIFARE classic.
 
bool mifareClassicAuthenticateB (const uint8_t block, const m5::nfc::a::mifare::classic::Key &key=m5::nfc::a::mifare::classic::DEFAULT_KEY)
 Authentication by KeyB for MIFARE classic.
 
bool mifareClassicReadAccessCondition (uint8_t &c123, const uint8_t block)
 Read the specific block access conditions.
 
bool mifareClassicWriteAccessCondition (const uint8_t block, const uint8_t c123, const m5::nfc::a::mifare::classic::Key &akey, const m5::nfc::a::mifare::classic::Key &bkey)
 Write the specific block access conditions.
 
bool mifareClassicIsValueBlock (bool &is_value_block, const uint8_t block)
 Is specific block the value block?
 
bool mifareClassicReadValueBlock (int32_t &value, const uint8_t block)
 Read the specific block as the value block.
 
bool mifareClassicWriteValueBlock (const uint8_t block, const int32_t value)
 Write the specific block as the value block.
 
bool mifareClassicDecrementValueBlock (const uint8_t block, const uint32_t delta, const bool transfer=true)
 Decrement value of the value block.
 
bool mifareClassicIncrementValueBlock (const uint8_t block, const uint32_t delta, const bool transfer=true)
 Increment value of the value block.
 
bool mifareClassicTransferValueBlock (const uint8_t block)
 Transfer inner buffer value to block.
 
bool mifareClassicRestoreValueBlock (const uint8_t block)
 Restore block value to inner buffer.
 
For MIFARE ultralight
Note
For activated PICC
bool mifareUltralightChangeFormatToNDEF ()
 Write change to NFC Type-2 (NDEF) format for MIFARE Ultralight/C.
 
For MIFARE ultralightC
Note
For activated PICC
bool mifareUltralightCAuthenticate (const uint8_t key[16])
 Authentication for MIFARE UltralightC.
 
For MIFARE Plus
Note
For activated PICC
bool mifarePlusUpgradeSecurityLevel1 (const m5::nfc::a::mifare::plus::AESKey &card_config_key=m5::nfc::a::mifare::plus::DEFAULT_KEY, const m5::nfc::a::mifare::plus::AESKey &card_master_key=m5::nfc::a::mifare::plus::DEFAULT_KEY, const m5::nfc::a::mifare::plus::AESKey &l2_switch_key=m5::nfc::a::mifare::plus::DEFAULT_KEY, const m5::nfc::a::mifare::plus::AESKey &l3_switch_key=m5::nfc::a::mifare::plus::DEFAULT_KEY, const m5::nfc::a::mifare::plus::AESKey &aes_sector_key=m5::nfc::a::mifare::plus::DEFAULT_FF_KEY, const m5::nfc::a::mifare::classic::Key &key_a=m5::nfc::a::mifare::classic::DEFAULT_KEY, const m5::nfc::a::mifare::classic::Key &key_b=m5::nfc::a::mifare::classic::DEFAULT_KEY)
 Upgrade security level to SL1 (Classic compatibility mode)
 
bool mifarePlusUpgradeSecurityLevel2 (const m5::nfc::a::mifare::plus::AESKey &sl2_switch_key=m5::nfc::a::mifare::plus::DEFAULT_KEY)
 Upgrade security level to SL2 (AES over CRYPTO1)
 
bool mifarePlusUpgradeSecurityLevel3 (const m5::nfc::a::mifare::plus::AESKey &l3_switch_key=m5::nfc::a::mifare::plus::DEFAULT_KEY)
 Upgrade security level to SL3 (AES)
 
For NDEF
Note
For activated PICC
bool ndefIsValidFormat (bool &valid)
 Is the PICC data in NDEF format?
 
bool ndefPrepareDesfireLight ()
 Prepare NDEF files on MIFARE DESFire Light.
 
bool ndefPrepareDesfire (const uint32_t max_ndef_size)
 Prepare NDEF files on MIFARE DESFire (EV1/EV2/EV3)
 
bool ndefRead (m5::nfc::ndef::TLV &msg)
 Read NDEF Message TLV.
 
bool ndefRead (std::vector< m5::nfc::ndef::TLV > &tlvs, const m5::nfc::ndef::TagBits tagBits=m5::nfc::ndef::tagBitsAll)
 Read any NDEF TLV.
 
bool ndefWrite (const m5::nfc::ndef::TLV &msg)
 Write NDEF message.
 
bool ndefWrite (const std::vector< m5::nfc::ndef::TLV > &tlvs)
 Write any NDEF Messages TLV.
 
- Public Member Functions inherited from m5::nfc::NFCLayerInterface
virtual bool transmit (const uint8_t *tx, const uint16_t tx_len, const uint32_t timeout_ms)
 Transmit only.
 
virtual bool receive (uint8_t *rx, uint16_t &rx_len, const uint32_t timeout_ms)
 Receive only.
 
virtual uint8_t maximum_read_blocks () const
 Maximum read blocks for NFC-F.
 
virtual uint8_t maximum_write_blocks () const
 Maximum write blocks for NFC-F.
 

Protected Member Functions

virtual bool read (uint8_t *rx, uint16_t &rx_len, const uint16_t saddr) override
 Read NDEF (block)
 
virtual bool write (const uint16_t saddr, const uint8_t *tx, const uint16_t tx_len) override
 Write NDEF (block)
 
virtual uint16_t first_user_block () const override
 First user block.
 
virtual uint16_t last_user_block () const override
 Last user block.
 
virtual uint16_t user_area_size () const
 User area size (bytes)
 
virtual uint16_t unit_size_read () const override
 Unit size for read.
 
virtual uint16_t unit_size_write () const override
 Unit size for write.
 
bool identify_picc (m5::nfc::a::PICC &picc)
 
m5::nfc::a::Type identify_picc_st25ta ()
 
uint8_t identify_plus_sl03 ()
 
bool read_using_fast (uint8_t *rx, uint16_t &rx_len, const uint8_t saddr)
 
bool read_using_read16 (uint8_t *rx, uint16_t &rx_len, const uint8_t saddr, const m5::nfc::a::mifare::classic::Key &key)
 
bool write_using_write4 (const uint8_t addr, const uint8_t *tx, const uint16_t tx_len)
 
bool write_using_write16 (const uint8_t addr, const uint8_t *tx, const uint16_t tx_len, const m5::nfc::a::mifare::classic::Key &key)
 
bool nfca_request_ats (m5::nfc::a::ATS &ats, const uint8_t fsdi=5, const uint8_t cid=0)
 
bool nfca_deselect ()
 
bool mifare_get_version_L3 (uint8_t ver[8])
 
bool mifare_get_version_L4_raw (uint8_t *ver, uint16_t &ver_len)
 
bool mifare_get_version_L4_wrapped (uint8_t *ver, uint16_t &ver_len)
 
bool mifare_plus_authenticateAES (const uint16_t key_no, const m5::nfc::a::mifare::plus::AESKey &key)
 
bool mifare_plus_authenticateAES_L3 (const uint16_t key_no, const m5::nfc::a::mifare::plus::AESKey &key)
 
bool mifare_plus_read_plain_nomac (const uint16_t block, const uint8_t count, std::vector< uint8_t > &out)
 
bool mifare_plus_read_plain_mac (const uint16_t block, const uint8_t count, std::vector< uint8_t > &out)
 
bool mifare_plus_read_mac_l4 (const uint16_t block, const uint8_t count, std::vector< uint8_t > &out, const bool plain)
 
bool mifare_plus_write_mac_l4 (const uint16_t block, const uint8_t *data, const uint16_t data_len, const bool plain)
 
bool mifare_classic_value_block (const m5::nfc::a::Command cmd, const uint8_t block, const uint32_t arg=0)
 
bool mifare_ultralightC_authenticate1 (uint8_t ek[8])
 
bool mifare_ultralightC_authenticate2 (uint8_t rx_ek[8], const uint8_t tx_ek[16])
 
bool ntag_read_page (uint8_t *rx, uint16_t &rx_len, const uint8_t spage, const uint8_t epage)
 
bool ntag_write_page (const uint8_t page, const uint8_t tx[4])
 
bool dump_sector_structure (const m5::nfc::a::PICC &picc, const m5::nfc::a::mifare::classic::Key &key)
 
bool dump_sector (const uint8_t sector)
 
bool dump_sector_mifare_plus_sl3 (const uint8_t sector)
 
bool dump_page_structure (const uint16_t maxPage)
 
bool dump_page (const uint8_t page, const uint16_t maxPage)
 
bool dump_mifare_plus_sl3 (const m5::nfc::a::mifare::plus::AESKey &key)
 
bool dump_desfire ()
 
bool dump_desfire_light ()
 
bool dump_st25ta ()
 

Static Protected Member Functions

static bool push_back_picc (std::vector< m5::nfc::a::PICC > &v, const m5::nfc::a::PICC &picc)
 

Protected Attributes

m5::nfc::a::PICC _activePICC {}
 
m5::nfc::ndef::NDEFLayer _ndef
 
m5::nfc::isodep::IsoDEP _isoDEP
 

Detailed Description

Common interface layer for each chip of the NFC-A reader.

Member Function Documentation

◆ activate()

bool m5::nfc::NFCLayerA::activate ( const m5::nfc::a::PICC & picc,
const bool force_rats = false )

Activate a specific PICC (anti-collision against the given PICC)

Parameters
piccPICC
force_ratsForce Request_rats (For Plus SL1/2)
Returns
True if successful
Precondition
PICC is READY state
Postcondition
PICC transitions: READY -> ACTIVE on successful response

◆ activatedPICC()

const m5::nfc::a::PICC & m5::nfc::NFCLayerA::activatedPICC ( ) const
inline

Retrieve the currently activated PICC.

Returns
Active PICC
Note
Returns an empty PICC if no PICC is selected (no ACTIVE state)

◆ deactivate()

bool m5::nfc::NFCLayerA::deactivate ( )

Send HLTA to the currently selected PICC (deactivate)

Returns
True if successful
Precondition
A PICC is in the ACTIVE state
Postcondition
PICC transitions: ACTIVE -> HALT on a successful response

◆ detect() [1/2]

bool m5::nfc::NFCLayerA::detect ( m5::nfc::a::PICC & picc,
const uint32_t timeout_ms = 100U )

Detect single idle PICC.

Parameters
[out]piccDetected PICC
timeout_msPolling time budget in milliseconds
Returns
True if detected
Note
The detected PICC is typically put into HALT during enumeration to allow discovering others
To identify the type, call NFCLayerA::identify
Warning
The type of activated PICC is determined solely by SAK and is provisional

◆ detect() [2/2]

bool m5::nfc::NFCLayerA::detect ( std::vector< m5::nfc::a::PICC > & piccs,
const uint32_t timeout_ms = 1000U )

Detect idle PICCs.

Parameters
[out]piccsDetected PICC PICCs (one per activated PICC candidate)
timeout_msPolling time budget in milliseconds
Returns
True if detected
Note
The detected PICC is typically put into HALT during enumeration to allow discovering others
To identify the type, call NFCLayerA::identify
Warning
The type of activated PICC is determined solely by SAK and is provisional

◆ dump() [1/2]

bool m5::nfc::NFCLayerA::dump ( const m5::nfc::a::mifare::classic::Key & mkey = m5::nfc::a::mifare::classic::DEFAULT_KEY)

Dump all blocks/files.

Parameters
keyMIFARE classic key for Classic
Returns
True if successful
Precondition
All blocks must be authenticatable using the specified key if MIFARE classic

◆ dump() [2/2]

bool m5::nfc::NFCLayerA::dump ( const uint8_t block)

Dump 1 block.

Parameters
addrBlock address
Returns
True if successful
Note
The sector to which the block belongs is dumped
Precondition
The block must be authenticated if MIFARE classic/PlusS3

◆ first_user_block()

virtual uint16_t m5::nfc::NFCLayerA::first_user_block ( ) const
inlineoverrideprotectedvirtual

First user block.

Implements m5::nfc::NFCLayerInterface.

◆ identify()

bool m5::nfc::NFCLayerA::identify ( m5::nfc::a::PICC & picc)

Identify the specified PICC type.

Classification Based on AN10883

Parameters
[in/out]picc PICC
Returns
True if successful
Warning
Before calling, the previously active PICC is deactivated

◆ isActive()

bool m5::nfc::NFCLayerA::isActive ( const m5::nfc::a::PICC & picc) const
inline

Is the specified PICC currently active?

Parameters
piccPICC to check
Returns
True if this PICC is the one currently selected (ACTIVE state)

◆ isoDEP()

virtual m5::nfc::isodep::IsoDEP * m5::nfc::NFCLayerA::isoDEP ( )
inlineoverridevirtual

ISO-DEP interface (nullptr if not supported)

Reimplemented from m5::nfc::NFCLayerInterface.

◆ last_user_block()

virtual uint16_t m5::nfc::NFCLayerA::last_user_block ( ) const
inlineoverrideprotectedvirtual

Last user block.

Implements m5::nfc::NFCLayerInterface.

◆ maximum_fifo_depth()

uint16_t m5::nfc::NFCLayerA::maximum_fifo_depth ( ) const
overridevirtual

Maximum FIFO depth.

Implements m5::nfc::NFCLayerInterface.

◆ mifareClassicAuthenticateA()

bool m5::nfc::NFCLayerA::mifareClassicAuthenticateA ( const uint8_t block,
const m5::nfc::a::mifare::classic::Key & key = m5::nfc::a::mifare::classic::DEFAULT_KEY )

Authentication by KeyA for MIFARE classic.

Parameters
blockAuthentication block
keyMIFARE classic key
Returns
True if successful

◆ mifareClassicAuthenticateB()

bool m5::nfc::NFCLayerA::mifareClassicAuthenticateB ( const uint8_t block,
const m5::nfc::a::mifare::classic::Key & key = m5::nfc::a::mifare::classic::DEFAULT_KEY )

Authentication by KeyB for MIFARE classic.

Parameters
blockAuthentication block
keyMIFARE classic key
Returns
True if successful

◆ mifareClassicDecrementValueBlock()

bool m5::nfc::NFCLayerA::mifareClassicDecrementValueBlock ( const uint8_t block,
const uint32_t delta,
const bool transfer = true )

Decrement value of the value block.

Parameters
blockBlock
deltaDelta
transferTransfer immediately if true
Returns
True if successful
Warning
When transfer == false, the result is stored only in the internal buffer and is not written to the PICC
Use mifareClassicTransferValueBlock for writing from the internal buffer to PICC
Precondition
The specified block is authenticated
The specified block must be a value block

◆ mifareClassicIncrementValueBlock()

bool m5::nfc::NFCLayerA::mifareClassicIncrementValueBlock ( const uint8_t block,
const uint32_t delta,
const bool transfer = true )

Increment value of the value block.

Parameters
blockBlock
deltaDelta
transferTransfer immediately if true
Returns
True if successful
Warning
When transfer == false, the result is stored only in the internal buffer and is not written to the PICC
Use mifareClassicTransferValueBlock for writing from the internal buffer to PICC
Precondition
The specified block is authenticated
The specified block must be a rechargeable value block

◆ mifareClassicIsValueBlock()

bool m5::nfc::NFCLayerA::mifareClassicIsValueBlock ( bool & is_value_block,
const uint8_t block )

Is specific block the value block?

Parameters
[out]is_value_blocktrue if block is the value block
blockBlock
keyMIFARE classic key
Returns
True if successful
Precondition
The specified block is authenticated

◆ mifareClassicReadAccessCondition()

bool m5::nfc::NFCLayerA::mifareClassicReadAccessCondition ( uint8_t & c123,
const uint8_t block )

Read the specific block access conditions.

Parameters
[out]c123Access bits Bit2:C1 Bit1:C2 Bit0:C3
blockBlock
Returns
True if successful

Access conditions for the sector trailer

C1 C2 C3 KeyA read KeyA write Access bits read Access bits write KeyB read KeyB write
0 0 0 never keyA keyA never keyA keyA
0 1 0 never never keyA never keyA never
1 0 0 never keyB keyA/B never never keyB
1 1 0 never never keyA/B never never never
0 0 1 never keyA keyA keyA keyA keyA
0 1 1 never keyB keyA/B keyB never keyB
1 0 1 never never keyA/B keyB never never
1 1 1 never never keyA/B never never never

Access conditions for data blocks

C1 C2 C3 read write increment decrement,transfer, restore Application
0 0 0 keyA/B keyA/B keyA/B keyA/B transport configuration
0 1 0 keyA/B never neve never read/write block
1 0 0 keyA/B keyB never never read/write block
1 1 0 keyA/B keyB keyB keyA/B value block
0 0 1 keyA/B never never keyA/B value block
0 1 1 keyB keyB never never read/write block
1 0 1 keyB never never never read/write block
1 1 1 never never never never read/write block
Precondition
The authentication of the sector trailer to which the block belongs is in place

◆ mifareClassicReadValueBlock()

bool m5::nfc::NFCLayerA::mifareClassicReadValueBlock ( int32_t & value,
const uint8_t block )

Read the specific block as the value block.

Parameters
[out]valueValue
blockBlock
Returns
True if successful
Precondition
The specified block is authenticated

◆ mifareClassicRestoreValueBlock()

bool m5::nfc::NFCLayerA::mifareClassicRestoreValueBlock ( const uint8_t block)

Restore block value to inner buffer.

Parameters
blockBlock
Returns
True if successful
Precondition
The specified block is authenticated
The specified block must be a value block

◆ mifareClassicTransferValueBlock()

bool m5::nfc::NFCLayerA::mifareClassicTransferValueBlock ( const uint8_t block)

Transfer inner buffer value to block.

Parameters
blockBlock
Returns
True if successful
Precondition
The specified block is authenticated
The specified block must be a value block

◆ mifareClassicWriteAccessCondition()

bool m5::nfc::NFCLayerA::mifareClassicWriteAccessCondition ( const uint8_t block,
const uint8_t c123,
const m5::nfc::a::mifare::classic::Key & akey,
const m5::nfc::a::mifare::classic::Key & bkey )

Write the specific block access conditions.

Parameters
blockBlock
c123Access bits Bit2:C1 Bit1:C2 Bit0:C3
akeyKeyA
bkeyKeyB
Returns
True if successful
See also
About access condition mifareClassicReadAccessCondition
Warning
Since writes are performed in 16-byte units, key information must also be entered correctly
Precondition
The authentication of the sector trailer to which the block belongs is in place

◆ mifareClassicWriteValueBlock()

bool m5::nfc::NFCLayerA::mifareClassicWriteValueBlock ( const uint8_t block,
const int32_t value )

Write the specific block as the value block.

Parameters
blockBlock
valueValue
Returns
True if successful
Precondition
The specified block is authenticated

◆ mifarePlusUpgradeSecurityLevel1()

Upgrade security level to SL1 (Classic compatibility mode)

Parameters
card_config_keyCard Configuration Key (AES)
card_master_keyCard Master Key (AES)
l2_switch_keyLevel 2 Switch Key (AES, for MIFARE Plus X/EV2 SL2 only)
l3_switch_keyLevel 3 Switch Key (AES, for SL3)
aes_sector_keyAES sector key (for SL2/SL3, written to 0x4000+)
key_aCrypto1 Key A (applies to all sectors)
key_bCrypto1 Key B (applies to all sectors)
Warning
This operation is irreversible
Access bits will be reset to the transport configuration

◆ mifarePlusUpgradeSecurityLevel2()

bool m5::nfc::NFCLayerA::mifarePlusUpgradeSecurityLevel2 ( const m5::nfc::a::mifare::plus::AESKey & sl2_switch_key = m5::nfc::a::mifare::plus::DEFAULT_KEY)

Upgrade security level to SL2 (AES over CRYPTO1)

Parameters
sl2_switch_keySL2 Switch Key (AES)
Warning
This operation is irreversible
Note
Only supported on MIFARE Plus X / EV2

◆ mifarePlusUpgradeSecurityLevel3()

bool m5::nfc::NFCLayerA::mifarePlusUpgradeSecurityLevel3 ( const m5::nfc::a::mifare::plus::AESKey & l3_switch_key = m5::nfc::a::mifare::plus::DEFAULT_KEY)

Upgrade security level to SL3 (AES)

Parameters
l3_switch_keyLevel 3 Switch Key (AES)
Warning
This operation is irreversible
Note
For Plus X/EV2, the PICC must be in SL2; otherwise SL1 is required

◆ mifareUltralightChangeFormatToNDEF()

bool m5::nfc::NFCLayerA::mifareUltralightChangeFormatToNDEF ( )

Write change to NFC Type-2 (NDEF) format for MIFARE Ultralight/C.

Returns
True if successful
Note
Returns true if the data is already in NDEF format or if the PICC is an NTAG
Warning
Only MIFARE Ultralight series
Changes are irreversible and cannot be undone
If the relevant area has already been overwritten, changes may not be possible

◆ ndefIsValidFormat()

bool m5::nfc::NFCLayerA::ndefIsValidFormat ( bool & valid)

Is the PICC data in NDEF format?

Parameters
[out]validTrue if NDEF format
Returns
True if successful

◆ ndefPrepareDesfire()

bool m5::nfc::NFCLayerA::ndefPrepareDesfire ( const uint32_t max_ndef_size)

Prepare NDEF files on MIFARE DESFire (EV1/EV2/EV3)

Parameters
max_ndef_sizeMax size for NDEF file
Returns
True if successful

◆ ndefPrepareDesfireLight()

bool m5::nfc::NFCLayerA::ndefPrepareDesfireLight ( )

Prepare NDEF files on MIFARE DESFire Light.

Returns
True if successful

◆ ndefRead() [1/2]

bool m5::nfc::NFCLayerA::ndefRead ( m5::nfc::ndef::TLV & msg)

Read NDEF Message TLV.

Parameters
[out]msgMessage If it does not exist, a Null TLV is returned
Returns
True if successful
Note
If multiple messages of the same type exist, return the first one
Warning
Only PICC cards supporting NDEF are valid

◆ ndefRead() [2/2]

bool m5::nfc::NFCLayerA::ndefRead ( std::vector< m5::nfc::ndef::TLV > & tlvs,
const m5::nfc::ndef::TagBits tagBits = m5::nfc::ndef::tagBitsAll )

Read any NDEF TLV.

Parameters
[out]tlvsMessage vector
tagBitsBit indicating the group of NDEF tags to be read
Returns
True if successful
Warning
Only PICC cards supporting NDEF are valid

◆ ndefWrite() [1/2]

bool m5::nfc::NFCLayerA::ndefWrite ( const m5::nfc::ndef::TLV & msg)

Write NDEF message.

Parameters
msgMessage (NDEF Message)
Returns
True if successful
Note
Other existing tags will be preserved
Warning
Existing NDEF message TLVs will be overwritten
Only PICC cards supporting NDEF are valid

◆ ndefWrite() [2/2]

bool m5::nfc::NFCLayerA::ndefWrite ( const std::vector< m5::nfc::ndef::TLV > & tlvs)

Write any NDEF Messages TLV.

Parameters
tlvsMessage vector
Returns
True if successful
Note
Write starting from the beginning of the user area
Warning
Existing NDEF Message TLVs will be overwritten,
so exercise caution if Lock/Memory control is present
Only PICC cards supporting NDEF are valid

◆ reactivate() [1/2]

bool m5::nfc::NFCLayerA::reactivate ( )
inline

Reactivate the previously selected PICC.

This function attempts to recover communication with the currently stored _activePICC when the PICC has entered the HALT state, for example due to a protocol error, timeout, or loss of RF field synchronization. Internally performs a WUPA (Wake-Up) followed by anti-collision and SELECT sequence using the last known PICC

Returns
True if successful
Precondition
A valid`_activePICC is stored (i.e., at least one PICC was previously activated)
Note
Use this to recover from transient communication errors without performing a full REQA/detect cycle

◆ reactivate() [2/2]

bool m5::nfc::NFCLayerA::reactivate ( const m5::nfc::a::PICC & picc,
const bool force_rats = false )

Wake and activate a specific PICC by PICC.

Parameters
piccTarget PICC
force_ratsForce Request_rats (For Plus SL1/2)
Returns
True if successful
Postcondition
PICC transitions: IDLE/HALT -> READY -> ACTIVE on a successful sequence

◆ read() [1/3]

bool m5::nfc::NFCLayerA::read ( uint8_t * rx,
uint16_t & rx_len,
const uint16_t saddr )
overrideprotectedvirtual

Read NDEF (block)

Implements m5::nfc::NFCLayerInterface.

◆ read() [2/3]

bool m5::nfc::NFCLayerA::read ( uint8_t * rx,
uint16_t & rx_len,
const uint8_t saddr,
const m5::nfc::a::mifare::classic::Key & key = m5::nfc::a::mifare::classic::DEFAULT_KEY )

Read any bytes from user area.

Continue reading only the user area from the first block of the user area until rx_len is satisfied

Parameters
rxBuffer
[in/out]rx_len in:buffer size, out:actual read size
saddrReading start block/page address
Returns
True if successful
Warning
For FAST_READ-compatible PICC, the rx is in 4-byte units. for others, it is in 16-byte units
Precondition
Target blocks must be authenticatable using the specified key if MIFARE classic

◆ read() [3/3]

bool m5::nfc::NFCLayerA::read ( uint8_t * rx,
uint16_t & rx_len,
const uint8_t saddr,
const m5::nfc::a::mifare::plus::AESKey & key )

Read any bytes from user area (MIFARE Plus SL3)

Parameters
rxBuffer
[in/out]rx_len in:buffer size, out:actual read size
saddrReading start block address
keyAES sector key (for MIFARE Plus SL3)
Returns
True if successful
Warning
The rx is in 16-byte units
Precondition
Target blocks must be authenticatable using the specified key

◆ read16()

bool m5::nfc::NFCLayerA::read16 ( uint8_t rx[16],
const uint8_t addr )

Read the 1 block / 4 page (16 bytes)

Parameters
rxBuffer (at least 16 bytes)
addrBlock/Page address
Returns
True if successful
Precondition
The block must be authenticated if MIFARE classic

◆ read4()

bool m5::nfc::NFCLayerA::read4 ( uint8_t rx[4],
const uint8_t addr )

Read the 1 page.

Parameters
rxBuffer (at least 4 bytes)
addrBlock/Page address
Returns
True if successful
Warning
Only PICC supporting the FAST_READ command is possible

◆ request()

bool m5::nfc::NFCLayerA::request ( uint16_t & atqa)

Send REQA to discover a PICC in IDLE.

Parameters
[out]atqaATQA received from PICC
Returns
True if successful
Postcondition
PICC transitions: IDLE -> READY on successful response

◆ select()

bool m5::nfc::NFCLayerA::select ( m5::nfc::a::PICC & picc)

Select a PICC (anti-collision + SELECT cascade to ACTIVE)

Parameters
[out]piccThe fully activated PICC (single- or multi-cascade)
Returns
True if successful
Warning
The type of activated PICC is determined solely by SAK and is provisional
Note
To identify the type, call NFCLayerA::identify
Precondition
A PICC is in the READY state (after REQA/WUPA)
Postcondition
PICC transitions: READY -> ACTIVE on successful response

◆ supportsFilesystem()

file_system_feature_t m5::nfc::NFCLayerA::supportsFilesystem ( ) const
overridevirtual

activePICC's File system

Reimplemented from m5::nfc::NFCLayerInterface.

◆ supportsNFCTag()

m5::nfc::NFCForumTag m5::nfc::NFCLayerA::supportsNFCTag ( ) const
overridevirtual

activePICC's NDEF type

Reimplemented from m5::nfc::NFCLayerInterface.

◆ transceive()

bool m5::nfc::NFCLayerA::transceive ( uint8_t * rx,
uint16_t & rx_len,
const uint8_t * tx,
const uint16_t tx_len,
const uint32_t timeout_ms )
overridevirtual

Transceive (RF command)

Reimplemented from m5::nfc::NFCLayerInterface.

◆ unit_size_read()

virtual uint16_t m5::nfc::NFCLayerA::unit_size_read ( ) const
inlineoverrideprotectedvirtual

Unit size for read.

Implements m5::nfc::NFCLayerInterface.

◆ unit_size_write()

virtual uint16_t m5::nfc::NFCLayerA::unit_size_write ( ) const
inlineoverrideprotectedvirtual

Unit size for write.

Implements m5::nfc::NFCLayerInterface.

◆ user_area_size()

virtual uint16_t m5::nfc::NFCLayerA::user_area_size ( ) const
inlineprotectedvirtual

User area size (bytes)

Implements m5::nfc::NFCLayerInterface.

◆ wakeup()

bool m5::nfc::NFCLayerA::wakeup ( uint16_t & atqa)

Send WUPA to wake a PICC from IDLE or HALT.

Parameters
[out]atqaATQA received from PICC
Returns
True if successful
Postcondition
PICC transitions: IDLE/HALT -> READY on successful response

◆ write() [1/3]

bool m5::nfc::NFCLayerA::write ( const uint16_t saddr,
const uint8_t * tx,
const uint16_t tx_len )
overrideprotectedvirtual

Write NDEF (block)

Implements m5::nfc::NFCLayerInterface.

◆ write() [2/3]

bool m5::nfc::NFCLayerA::write ( const uint8_t addr,
const uint8_t * tx,
const uint16_t tx_len,
const m5::nfc::a::mifare::plus::AESKey & key )

Write any bytes to user area (MIFARE Plus SL3)

Parameters
addrWriting start block address
txBuffer
tx_lenBuffer size
keyAES sector key (for MIFARE Plus SL3)
Returns
True if successful
Warning
The tx is in 16-byte units
Precondition
Target blocks must be authenticatable using the specified key

◆ write() [3/3]

bool m5::nfc::NFCLayerA::write ( const uint8_t saddr,
const uint8_t * tx,
const uint16_t tx_len,
const m5::nfc::a::mifare::classic::Key & key = m5::nfc::a::mifare::classic::DEFAULT_KEY )

Write any bytes to user area.

Continue writing only the user area from the first block of the user area until tx_len is satisfied

Parameters
saddrWriting start block/page address
txBuffer
tx_lenbuffer size
Returns
True if successful
Warning
For NTAG and Ultralight series, the tx is in 4-byte units; for others, it is in 16-byte units
If the value is less than the unit, it is padded with 0x00
Precondition
Target blocks must be authenticatable using the specified key if MIFARE classic

◆ write16()

bool m5::nfc::NFCLayerA::write16 ( const uint8_t addr,
const uint8_t * tx,
const uint16_t tx_len,
const bool safety = true )

Write the 1 block / 4 page (16 bytes)

Parameters
addrBlock/Page address
txBuffef
tx_lenBuffer size
safetyFail to write to out of the user memory area if true (safety measure)
Returns
True if successful
Warning
If the tx_len is less than 16 bytes, the remaining space is filled with 0x00
If the tx_len is larger than 16 bytes, only the first 16 bytes will be written
Precondition
The block must be authenticated if MIFARE classic

◆ write4()

bool m5::nfc::NFCLayerA::write4 ( const uint8_t addr,
const uint8_t * tx,
const uint16_t tx_len,
const bool safety = true )

Write the 1 page (4 bytes)

Parameters
addrBlock/Page address
txBuffer
tx_lenBuffer size
safetyFail to write to out of the user memory area if true (safety measure)
Returns
True if successful
Warning
Supports NTAG and Ultralight series only
If the tx_len is less than 4 bytes, the remaining space is filled with 0x00
If the tx_len is larger than 4 bytes, only the first 4 bytes will be written