Sometimes also called tag provisioning or tag writing, tag encoding refers to the process of configuring an NFC tag and writing data to it in order to prepare it for use. For advanced tags this can include configuring filesystems and setting authentication keys, but for most uses of NFC tags, this just consists of formatting the tag for NDEF data and writing an initial NDEF message set to it. Note, this whitepaper is focused on the details of tag encoding, if you’re just looking for a tool to encode NFC tags, our free multi-platform TappyUSB ChromeApp might be just what you’re looking for.
What is an NDEF message
NDEF (NFC Data Exchange Format) can be thought of as a standard file format for NFC tags. While technically you can store whatever you want in an NFC tag’s memory, another NFC reader (or PCD in the official parlance) will not necessarily know how to handle that information. Therefore, the NDEF standard was developed to provide a highly memory-efficient standard format for storing data on NFC tags so that different PCDs will be able to interpret the content.
NDEF messages are a composite data type composed of one or more NDEF records, which
are composed of a header and zero or more bytes of data. The header provides some
information about the record’s position in the overall message as well as metadata
about the record itself. Perhaps the most important piece of metadata is the type
name field or TNF that informs the PCD what kind of record it is reading. There
are several standardized TNFs with different purposes, but by far the most commonly
used on is
0x01, which indicates that the record is one of a handful of datatypes
called the “well-known” types. A well-known record includes additional type data
that indicates exactly which type of well known record it is. There are a handful of
different well-known types, but the text type, which covers textual content, and
the URI type, which unsurprisingly covers URI/URL content are the most commonly used.
NFC Forum NDEF Tags
Different types of NFC tags have very different capabilities and memory layouts. Accordingly, the manner in which NDEF data is stored and discovered on a different types of tags also varies quite significantly. The NFC Forum has standardized the format and discovery method for NDEF data on several common tag technologies. The NTAG series from NXP comes from the factory already formatted for NDEF data, but most tags require an additional formatting step. The details of this formatting operation are outside the scope of this whitepaper, but the details are available in the NFC Forum Type 1/2/3/4/5 Tag Operation specifications.
How Android handles NDEF tags
The complete details of the Android tag dispatch system are too complex to be covered here, but, in general when an Android device encounters an NFC tag, it first checks to see sf it conforms to one of the NFC Forum operating specifications. If the tag is formatted for NDEF data, the device will extract the message then decide what to do based on the contents of the first record in the message. Depending on what apps are installed on the phone, what happens next can vary wildly, but for a stock Android device with no additional NFC apps, the following will occur:
Well-known text record
A simple NFC tag viewer application built into Android will be opened displaying all of the records on the message.
Well-known URI/URL record
The phone will attempt to open the URI contained in the record. For website links, this will result in the phone’s browser being opened to the website. Other URI types will similarly be handled by the appropriate app if one is present - SMS links for instance will open the default SMS application so the user can send an SMS to the phone number the tag specified.
Media vCard record
The contacts app will be opened with the information from the vCard prefilled so the user can easily add the person whose vCard is containted on the tag to their contacts.
Well known Bluetooth handover
The user will be prompted to pair to the Bluetooth device specified in the record.
Android WiFi record
Android 5.0 and later understands a special format for WiFi records. If the first record on a tag is one of these records, the user will be prompted to connect to this network using the credentials on the tag.
How iOS handles NDEF tags
Put simply, iOS currently does not handle NDEF messages at all. The NFC capabilities of iOS devices are dedicated to Apple Pay and currently do not perform any kind of NDEF discovery or tag dispatch.