Type 2 Tag parser
The nRF Connect SDK provides functionality to read the content of an NFC tag. Note that an nRF5 Series IC does not provide the hardware that is required for a polling device. If you want to create a polling device, you can use an ST25R3911B NFC shield together with an nRF5 Development Kit.
Using the NFC Reader ST25R3911B, you can read raw data from a Type 2 Tag, such as:
Number of TLV structures in the tag
Type 2 Tag internal bytes
Type 2 Tag lock bytes
Type 2 Tag capability container
Array of pointer to the TLV structures of the tag
See the NFC: Tag reader sample for more information on how to do this.
The following code example shows how to parse the raw data from a Type 2 Tag:
/* Buffer with raw data from a Type 2 Tag. */
uint8_t raw_tag_data[] = ..;
/* Declaration of Type 2 Tag structure which
* can contain a maximum of 10 TLV blocks.
*/
NFC_T2T_DESC_DEF(tag_data, 10);
struct nfc_t2t *t2t = &NFC_T2T_DESC(tag_data);
err = nfc_t2t_parse(t2t, raw_tag_data);
if (err) {
printk("Not enough memory to read the whole tag. Printing what has been read.\n");
}
/* Print the tag data. */
nfc_t2t_printout(t2t);
Note that the data can be further parsed by the Parser for messages and records, given that the type of the analyzed TLV block is NDEF TLV.
API documentation
NFC Type 2 Tag parser
include/nfc/t2t/t2t_parser.h
subsys/nfc/t2t/parser.c
- group nfc_t2t_parser
NFC Type 2 Tag parser.
Defines
-
NFC_T2T_DESC_DEF(_name, _max_blocks)
Create and initialize a Type 2 Tag descriptor.
This macro creates and initializes a static instance of an nfc_t2t structure and an array of Type 2 Tag TLV blocks descriptors.
Use the macro NFC_T2T_DESC to access the Type 2 Tag descriptor instance.
- Parameters
_name – [in] Name of the created descriptor instance.
_max_blocks – [in] Maximum number of Type 2 Tag TLV blocks descriptors that can be stored in the array.
-
NFC_T2T_DESC(_name)
Access the nfc_t2t instance that was created with NFC_T2T_DESC_DEF.
-
NFC_T2T_NFC_FORUM_DEFINED_DATA
Value indicating that the Type 2 Tag contains NFC Forum defined data.
-
NFC_T2T_UID_BCC_CASCADE_BYTE
Value used for calculating the first BCC byte of a Type 2 Tag serial number.
-
NFC_T2T_SUPPORTED_MAJOR_VERSION
Supported major version of the Type 2 Tag specification.
-
NFC_T2T_SUPPORTED_MINOR_VERSION
Supported minor version of the Type 2 Tag specification.
-
NFC_T2T_BLOCK_SIZE
Type 2 Tag block size in bytes.
-
NFC_T2T_CC_BLOCK_OFFSET
Offset of the Capability Container area in the Type 2 Tag.
-
NFC_T2T_FIRST_DATA_BLOCK_OFFSET
Offset of the data area in the Type 2 Tag.
Functions
-
void nfc_t2t_clear(struct nfc_t2t *t2t)
Clear the nfc_t2t structure.
- Parameters
t2t – [inout] Pointer to the structure that should be cleared.
-
int nfc_t2t_parse(struct nfc_t2t *t2t, const uint8_t *raw_data)
Parse raw data that was read from a Type 2 Tag.
This function parses the header and the following TLV blocks of a Type 2 Tag. The data is read from a buffer and stored in a nfc_t2t structure.
- Parameters
t2t – [out] Pointer to the structure that will be filled with parsed data.
raw_data – [in] Pointer to the buffer with raw data from the tag (should point at the first byte of the first block of the tag).
- Return values
0 – If the operation was successful. Otherwise, a (negative) error code is returned.
-
struct nfc_t2t_sn
- #include <parser.h>
Descriptor for the internal bytes of a Type 2 Tag.
Public Members
-
uint8_t manufacturer_id
Manufacturer ID (the most significant byte of the UID/serial number).
-
uint16_t serial_number_part_1
Bytes 5-4 of the tag UID.
-
uint32_t serial_number_part_2
Bytes 3-0 of the tag UID.
-
uint8_t check_byte_0
First block check character byte (XOR of the cascade tag byte, manufacturer ID byte, and the serial_number_part_1 bytes).
-
uint8_t check_byte_1
Second block check character byte (XOR of the serial_number_part_2 bytes).
-
uint8_t internal
Tag internal bytes.
-
uint8_t manufacturer_id
-
struct nfc_t2t_cc
- #include <parser.h>
Descriptor for the Capability Container (CC) bytes of a Type 2 Tag.
Public Members
-
uint8_t major_version
Major version of the supported Type 2 Tag specification.
-
uint8_t minor_version
Minor version of the supported Type 2 Tag specification.
-
uint16_t data_area_size
Size of the data area in bytes.
-
uint8_t read_access
Read access for the data area.
-
uint8_t write_access
Write access for the data area.
-
uint8_t major_version
-
struct nfc_t2t
- #include <parser.h>
Type 2 Tag descriptor.
Public Members
-
struct nfc_t2t_sn sn
Values within the serial number area of the tag.
-
uint16_t lock_bytes
Value of the lock bytes.
-
struct nfc_t2t_cc cc
Values within the Capability Container area of the tag.
-
const uint16_t max_tlv_blocks
Maximum number of TLV blocks that can be stored.
-
struct nfc_t2t_tlv_block *tlv_block_array
Pointer to the array for TLV blocks.
-
uint16_t tlv_count
Number of TLV blocks stored in the Type 2 Tag.
-
struct nfc_t2t_sn sn
-
NFC_T2T_DESC_DEF(_name, _max_blocks)
Type 2 Tag TLV blocks
include/nfc/t2t/tlv_block.h
- group nfc_t2t_tlv_block
Descriptor for a Type 2 Tag TLV block.
Defines
-
NFC_T2T_TLV_T_LENGTH
Length of a tag field.
-
NFC_T2T_TLV_L_SHORT_LENGTH
Length of a short length field.
-
NFC_T2T_TLV_L_LONG_LENGTH
Length of an extended length field.
-
NFC_T2T_TLV_L_FORMAT_FLAG
Value indicating the use of an extended length field.
-
NFC_T2T_TLV_NULL_TERMINATOR_LEN
Predefined length of the NULL and TERMINATOR TLV blocks.
-
NFC_T2T_TLV_LOCK_MEMORY_CTRL_LEN
Predefined length of the LOCK CONTROL and MEMORY CONTROL blocks.
Enums
-
enum nfc_t2t_tlv_block_types
Tag field values.
Possible values for the tag field in a TLV block.
Values:
-
enumerator NFC_T2T_TLV_NULL
Can be used for padding of memory areas.
-
enumerator NFC_T2T_TLV_LOCK_CONTROL
Defines details of the lock bits.
-
enumerator NFC_T2T_TLV_MEMORY_CONTROL
Identifies reserved memory areas.
-
enumerator NFC_T2T_TLV_NDEF_MESSAGE
Contains an NDEF message.
-
enumerator NFC_T2T_TLV_PROPRIETARY
Tag proprietary information.
-
enumerator NFC_T2T_TLV_TERMINATOR
Last TLV block in the data area.
-
enumerator NFC_T2T_TLV_NULL
-
struct nfc_t2t_tlv_block
- #include <tlv_block.h>
TLV block descriptor.
-
NFC_T2T_TLV_T_LENGTH