URI messages and records

URI messages contain exactly one URI record, which in turn contains an address that an NFC polling device can open. In the most typical use case, the URI record contains a web address like “http://www.nordicsemi.com” that the polling device opens in a web browser.

URI records consist of a URI field (the actual address) and a URI identifier that specifies the protocol of the URI and is prepended to the URI. See nfc_ndef_uri_rec_id for the available protocols.

The URI records module provides functions for creating the record, and the URI messages module provides functions for creating and encoding the message.

The following code snippets show how to generate a URI message. First, define the URI string and create a buffer for the message:

static const uint8_t m_url[] =
    {'n', 'o', 'r', 'd', 'i', 'c', 's', 'e', 'm', 'i', '.', 'c', 'o', 'm'}; //URL "nordicsemi.com"

uint8_t m_ndef_msg_buf[256];

Then create the URI message with one URI record. As parameters, provide the URI identifier code (NFC_URI_HTTP_WWW in this example), the URI string, the length of the URI string, the message buffer, and the size of the available memory in the buffer:

int err;

err = nfc_ndef_uri_msg_encode( NFC_URI_HTTP_WWW,
                                m_url,
                                sizeof(m_url),
                                m_ndef_msg_buf,
                                &len);

if (err < 0) {
     printk("Cannot encode message!\n");
     return err;
}

API documentation

URI messages

Header file: include/nfc/ndef/uri_msg.h
Source file: subsys/nfc/ndef/uri_msg.c
group nfc_uri_msg

Generation of NFC NDEF messages with a URI record.

Functions

int nfc_ndef_uri_msg_encode(enum nfc_ndef_uri_rec_id uri_id_code, uint8_t const *const uri_data, uint8_t uri_data_len, uint8_t *buf, uint32_t *len)

Encode an NFC NDEF URI message.

This function encodes an NFC NDEF message into a buffer.

Parameters
  • uri_id_code: URI identifier code that defines the protocol field of the URI.

  • uri_data: Pointer to the URI string. The string should not contain the protocol field if the protocol was specified in uri_id_code.

  • uri_data_len: Length of the URI string.

  • buf: Pointer to the buffer for the message.

  • len: Size of the available memory for the message as input. Size of the generated message as output.

Return Value
  • 0: If the description was successfully created.

  • -EINVAL: If the URI string was invalid (equal to NULL).

  • -ENOMEM: If the predicted message size is bigger than the provided buffer space.

  • Other: Other codes might be returned depending on the function nfc_ndef_msg_encode.

URI records

Header file: include/nfc/ndef/uri_rec.h
Source file: subsys/nfc/ndef/uri_rec.c
group nfc_uri_rec

Generation of NFC NDEF URI record descriptions.

Defines

NFC_NDEF_URI_RECORD_DESC_DEF(name, uri_id_code_arg, uri_data_arg, uri_data_len_arg)

Macro for generating a description of a URI record.

This macro initializes an instance of an NFC NDEF record description of a URI record.

Note

The record descriptor is declared as automatic variable, which implies that the NDEF message encoding (see nfc_ndef_uri_msg_encode) must be done in the same variable scope.

Parameters
  • name: Name for accessing record descriptor.

  • uri_id_code_arg: URI identifier code that defines the protocol field of the URI.

  • uri_data_arg: Pointer to the URI string. The string should not contain the protocol field if the protocol was specified in uri_id_code.

  • uri_data_len_arg: Length of the URI string.

NFC_NDEF_URI_RECORD_DESC(name)

Macro for accessing the NFC NDEF URI record descriptor instance that was created with NFC_NDEF_URI_RECORD_DESC_DEF.

Enums

enum nfc_ndef_uri_rec_id

URI identifier codes according to “URI Record Type Definition” (denotation “NFCForum-TS-RTD_URI_1.0” published on 2006-07-24) chapter 3.2.2.

Values:

enumerator NFC_URI_NONE

No prepending is done.

enumerator NFC_URI_HTTP_WWW

“http://www.”

enumerator NFC_URI_HTTPS_WWW

“https://www.”

enumerator NFC_URI_HTTP

“http:”

enumerator NFC_URI_HTTPS

“https:”

enumerator NFC_URI_TEL

“tel:”

enumerator NFC_URI_MAILTO

“mailto:”

enumerator NFC_URI_FTP_ANONYMOUS

“ftp://anonymous:anonymous@”

enumerator NFC_URI_FTP_FTP

“ftp://ftp.”

enumerator NFC_URI_FTPS

“ftps://”

enumerator NFC_URI_SFTP

“sftp://”

enumerator NFC_URI_SMB

“smb://”

enumerator NFC_URI_NFS

“nfs://”

enumerator NFC_URI_FTP

“ftp://”

enumerator NFC_URI_DAV

“dav://”

enumerator NFC_URI_NEWS

“news:”

enumerator NFC_URI_TELNET

“telnet://”

enumerator NFC_URI_IMAP

“imap:”

enumerator NFC_URI_RTSP

“rtsp://”

enumerator NFC_URI_URN

“urn:”

enumerator NFC_URI_POP

“pop:”

enumerator NFC_URI_SIP

“sip:”

enumerator NFC_URI_SIPS

“sips:”

enumerator NFC_URI_TFTP

“tftp:”

enumerator NFC_URI_BTSPP

“btspp://”

enumerator NFC_URI_BTL2CAP

“btl2cap://”

enumerator NFC_URI_BTGOEP

“btgoep://”

enumerator NFC_URI_TCPOBEX

“tcpobex://”

enumerator NFC_URI_IRDAOBEX

“irdaobex://”

enumerator NFC_URI_FILE

“file://”

enumerator NFC_URI_URN_EPC_ID

“urn:epc:id:”

enumerator NFC_URI_URN_EPC_TAG

“urn:epc:tag:”

enumerator NFC_URI_URN_EPC_PAT

“urn:epc:pat:”

enumerator NFC_URI_URN_EPC_RAW

“urn:epc:raw:”

enumerator NFC_URI_URN_EPC

“urn:epc:”

enumerator NFC_URI_URN_NFC

“urn:nfc:”

enumerator NFC_URI_RFU

No prepending is done. Reserved for future use.

Functions

int nfc_ndef_uri_rec_payload_encode(struct nfc_ndef_uri_rec_payload *input, uint8_t *buff, uint32_t *len)

Construct the payload for a URI record.

This function encodes the payload according to the URI record definition. It implements an API compatible with payload_constructor_t.

Parameters
  • input: Pointer to the description of the payload.

  • buff: Pointer to payload destination. If NULL, function will calculate the expected size of the URI record payload.

  • len: Size of available memory to write as input. Size of generated payload as output.

Return Value
  • 0: If the payload was encoded successfully.

  • -ENOMEM: If the predicted payload size is bigger than the provided buffer space.

Variables

const uint8_t nfc_ndef_uri_rec_type

External reference to the type field of the URI record, defined in the file uri_rec.c. It is used in the NFC_NDEF_URI_RECORD_DESC_DEF macro.

struct nfc_ndef_uri_rec_payload
#include <uri_rec.h>

Type of description of the payload of a URI record.

Public Members

enum nfc_ndef_uri_rec_id uri_id_code

URI identifier code.

const uint8_t *uri_data

Pointer to a URI string.

uint8_t uri_data_len

Length of the URI string.