Type 4 Tag

The Type 4 Tag library implements NFC Type 4 Tag functionality based on the NFC Forum document Type 4 Tag Technical Specification Version 1.0.

Overview

A Type 4 Tag provides a more sophisticated NFC tag implementation compared to Type 2 Tag. It uses the ISO-DEP (ISO14443-4A) protocol for communication and provides a file system containing Elementary Files (EFs).

For detailed information about the Type 4 Tag protocol, data exchange, and APDU handling, see the Type 4 Tag nrfxlib documentation.

The library supports three different modes of emulation:

Mode

Description

Read-only NDEF

NDEF file cannot be modified. Only field status and read events are signaled.

Read-write NDEF

NDEF file can be modified. Changes to NDEF content are signaled through callback.

Raw ISO-DEP

All APDUs are signaled through the callback. Application handles responses.

Note

Raw ISO-DEP mode is supported by the nrfxlib library but is not implemented in Bare Metal (no sample or application support).

Configuration

To enable the library, set the CONFIG_NFC_T4T_NRFXLIB Kconfig option.

Usage

The sequence of initialization functions determines the emulation mode.

NDEF emulation mode

For read-only or read-write NDEF tag emulation:

  1. Register callback and initialize.

    Implement a callback function to handle NFC events and register it using the nfc_t4t_setup() function:

    static void nfc_callback(void *context,
                             nfc_t4t_event_t event,
                             const uint8_t *data,
                             size_t data_length,
                             uint32_t flags)
    {
        switch (event) {
        case NFC_T4T_EVENT_FIELD_ON:
            /* NFC field detected */
            break;
        case NFC_T4T_EVENT_FIELD_OFF:
            /* NFC field removed */
            break;
        case NFC_T4T_EVENT_NDEF_READ:
            /* NDEF data has been read */
            break;
        case NFC_T4T_EVENT_NDEF_UPDATED:
            /* NDEF content was updated (read-write mode) */
            break;
        default:
            break;
        }
    }
    
    int err = nfc_t4t_setup(nfc_callback, NULL);
    if (err != 0) {
        /* Handle error */
    }
    
  2. Set NDEF payload.

    First encode the NDEF file (see NDEF file) for use as the tag payload. Then pass the resulting buffer to one of the following:

    1. For read-only mode, use the nfc_t4t_ndef_staticpayload_set() function:

      static const uint8_t ndef_msg[] = { /* NDEF message data */ };
      
      err = nfc_t4t_ndef_staticpayload_set(ndef_msg, sizeof(ndef_msg));
      if (err != 0) {
          /* Handle error */
      }
      
    2. For read-write mode, use the nfc_t4t_ndef_rwpayload_set() function:

      static uint8_t ndef_buffer[1024];
      
      /* Initialize ndef_buffer with initial NDEF message */
      err = nfc_t4t_ndef_rwpayload_set(ndef_buffer, sizeof(ndef_buffer));
      if (err != 0) {
          /* Handle error */
      }
      
  3. Start emulation.

    err = nfc_t4t_emulation_start();
    if (err != 0) {
        /* Handle error */
    }
    

Events

The library signals the following events through the registered callback:

Event

Description

NFC_T4T_EVENT_FIELD_ON

External reader polling detected

NFC_T4T_EVENT_FIELD_OFF

External reader polling ended

NFC_T4T_EVENT_NDEF_READ

Reader has read static NDEF data (read-only mode)

NFC_T4T_EVENT_NDEF_UPDATED

Reader has written to NDEF data (read-write mode)

NFC_T4T_EVENT_DATA_TRANSMITTED

Response PDU sent in raw mode

NFC_T4T_EVENT_DATA_IND

APDU fragment received in raw mode

Parameters

You can configure the following parameters using the nfc_t4t_parameter_set() function:

Dependencies

This library requires the following drivers and libraries:

The NFC: Text record for Type 4 Tag sample demonstrates how to use this library.

API reference

Header file: nrfxlib/nfc/include/nfc_t4t_lib.h
Library: nrfxlib/nfc/lib/

Type 4 Tag library API reference