nRF5 SDK v17.1.0
Type 4 Tag NDEF detection procedure

The NDEF detection procedure module provides functions to perform the NDEF detection procedure, which is used to retrieve the NDEF message from the data of a tag. For the API documentation of this module, refer to High-level NDEF Detection Procedure.

To execute a full NDEF detection procedure, you must run its subprocedures in the following order:

  1. NDEF tag application select procedure.
  2. Capability container (CC) select procedure.
  3. Capability container read procedure.
  4. NDEF select procedure.
  5. NDEF read procedure.

After a successful NDEF detection procedure, you can also write data to the NDEF file. To do it, you need to perform an NDEF update procedure.

Note that this module uses three other modules. APDU reader/writer is used to generate and decode APDU commands and responses which are sent or received by Adafruit NFC Shield library over NFC. Apart from that, the payload of APDU responses is analyzed by Capability Container file parser and stored within the structure that represents Type 4 Tag content.

NDEF detection procedure examples

The following code example shows how to perform an NDEF detection procedure for a Type 4 Tag:

ret_code_t err_code;
// Static declaration of Type 4 Tag structure.
NFC_T4T_CC_DESC_DEF(cc_file, MAX_TLV_BLOCKS);
static uint8_t ndef_files_buffs[MAX_TLV_BLOCKS][TAG_TYPE_4_NDEF_FILE_SIZE];
if (err_code != NRF_SUCCESS)
{
//Error during NDEF tag application select procedure.
return err_code;
}
err_code = nfc_t4t_cc_select();
if (err_code != NRF_SUCCESS)
{
//Error during capability container select procedure.
return err_code;
}
err_code = nfc_t4t_cc_read(cc_file);
if (err_code != NRF_SUCCESS)
{
//Error during capability container read procedure.
return err_code;
}
nfc_t4t_tlv_block_t * p_tlv_block = cc_file->p_tlv_block_array;
uint32_t i;
for (i = 0; i < cc_file->tlv_count; i++)
{
if ((p_tlv_block->type == NDEF_FILE_CONTROL_TLV) ||
{
err_code = nfc_t4t_file_select(p_tlv_block->value.file_id);
if (err_code != NRF_SUCCESS)
{
//Error during NDEF select procedure.
return err_code;
}
err_code = nfc_t4t_ndef_read(cc_file, ndef_files_buffs[i], TAG_TYPE_4_NDEF_FILE_SIZE);
if (err_code != NRF_SUCCESS)
{
//Error during NDEF read procedure.
return err_code;
}
}
p_tlv_block++;
}
// Print the tag data.

After a successful NDEF detection procedure, you can also write data to the NDEF file using the following code:

uint8_t new_ndef_file_buff[] = ...; //Buffer that will be written to all possible NDEF files within Type 4 Tag.
p_tlv_block = cc_file->p_tlv_block_array;
for (i = 0; i < cc_file->tlv_count; i++)
{
if ((p_tlv_block->type == NDEF_FILE_CONTROL_TLV) ||
{
err_code = nfc_t4t_file_select(p_tlv_block->value.file_id);
if (err_code != NRF_SUCCESS)
{
//Error during NDEF Select Procedure.
return err_code;
}
err_code = nfc_t4t_ndef_update(cc_file, new_ndef_file_buff, sizeof(new_ndef_file_buff));
if (err_code != NRF_SUCCESS)
{
//Error during NDEF update procedure.
return err_code;
}
}
p_tlv_block++;
}

Note that the NDEF detection procedure is equivalent to reading and parsing of the data of a tag. This activity for Type 4 Tag slightly differs from reading and parsing NFC Type 2 Tag data. In case of Type 2 Tag, the whole tag data can be first read and then parsed. For Type 4 Tag, reading and parsing is not clearly seperated - it occurs in turns. This is necessary because the metadata of a tag (the CC file retrieved at the beginning of NDEF detection procedure) is later used to finish this procedure.

APDU reader/writer

Capability Container file parser


Documentation feedback | Developer Zone | Subscribe | Updated