nRF5 SDK v17.1.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
Custom NDEF records

Generation of NFC NDEF records for NFC messages. More...

Modules

 NFC NDEF Record generator module configuration
 

Data Structures

struct  nfc_ndef_record_desc_t
 NDEF record descriptor. More...
 
struct  nfc_ndef_bin_payload_desc_t
 Binary data descriptor containing the payload for the record. More...
 

Macros

#define NDEF_RECORD_IL_MASK   0x08
 Mask of the ID field presence bit in the flags byte of an NDEF record.
 
#define NDEF_RECORD_TNF_MASK   0x07
 Mask of the TNF value field in the first byte of an NDEF record.
 
#define NDEF_RECORD_SR_MASK   0x10
 Mask of the SR flag. If set, this flag indicates that the PAYLOAD_LENGTH field has a size of 1 byte. Otherwise, PAYLOAD_LENGTH has 4 bytes.
 
#define NDEF_RECORD_PAYLOAD_LEN_LONG_SIZE   4
 Size of the Payload Length field in a long NDEF record.
 
#define NDEF_RECORD_PAYLOAD_LEN_SHORT_SIZE   1
 Size of the Payload Length field in a short NDEF record.
 
#define NDEF_RECORD_ID_LEN_SIZE   1
 Size of the ID Length field in an NDEF record.
 
#define NDEF_RECORD_LOCATION_MASK   (NDEF_LONE_RECORD)
 Mask of the Record Location bits in the NDEF record's flags byte.
 
#define NFC_NDEF_GENERIC_RECORD_DESC_DEF(NAME,TNF,P_ID,ID_LEN,P_TYPE,TYPE_LEN,P_PAYLOAD_CONSTRUCTOR,P_PAYLOAD_DESCRIPTOR)
 Macro for creating and initializing an NFC NDEF record descriptor for a generic record. More...
 
#define NFC_NDEF_GENERIC_RECORD_DESC(NAME)   (NAME##_ndef_generic_record_desc)
 Macro for accessing the NFC NDEF record descriptor instance that you created with NFC_NDEF_GENERIC_RECORD_DESC_DEF.
 
#define NFC_NDEF_RECORD_BIN_DATA_DEF(NAME,TNF,P_ID, ID_LEN,P_TYPE,TYPE_LEN,P_PAYLOAD,PAYLOAD_LEN)
 Macro for creating and initializing an NFC NDEF record descriptor for a record with binary payload. More...
 
#define NFC_NDEF_RECORD_BIN_DATA(NAME)   (NAME##_nfc_ndef_bin_record_desc)
 Macro for accessing the NFC NDEF record descriptor instance that you created with NFC_NDEF_RECORD_BIN_DATA_DEF.
 
#define NFC_NDEF_BIN_PAYLOAD_DESC(NAME)   (NAME##_nfc_ndef_bin_payload_desc)
 Macro for accessing the binary data descriptor that contains the payload of the record that you created with NFC_NDEF_RECORD_BIN_DATA_DEF.
 

Typedefs

typedef ret_code_t(* p_payload_constructor_t )(void *p_payload_descriptor, uint8_t *p_buffer, uint32_t *p_len)
 Payload constructor type. More...
 

Enumerations

enum  nfc_ndef_record_tnf_t {
  TNF_EMPTY = 0x00,
  TNF_WELL_KNOWN = 0x01,
  TNF_MEDIA_TYPE = 0x02,
  TNF_ABSOLUTE_URI = 0x03,
  TNF_EXTERNAL_TYPE = 0x04,
  TNF_UNKNOWN_TYPE = 0x05,
  TNF_UNCHANGED = 0x06,
  TNF_RESERVED = 0x07
}
 Type Name Format (TNF) Field Values. More...
 
enum  nfc_ndef_record_location_t {
  NDEF_FIRST_RECORD = 0x80,
  NDEF_MIDDLE_RECORD = 0x00,
  NDEF_LAST_RECORD = 0x40,
  NDEF_LONE_RECORD = 0xC0
}
 Record position within the NDEF message. More...
 

Functions

ret_code_t nfc_ndef_record_encode (nfc_ndef_record_desc_t const *p_ndef_record_desc, nfc_ndef_record_location_t record_location, uint8_t *p_record_buffer, uint32_t *p_record_len)
 Function for encoding an NDEF record. More...
 
ret_code_t nfc_ndef_bin_payload_memcopy (nfc_ndef_bin_payload_desc_t *p_payload_descriptor, uint8_t *p_buffer, uint32_t *p_len)
 Function for constructing the payload for an NFC NDEF record from binary data. More...
 

Detailed Description

Generation of NFC NDEF records for NFC messages.

Macro Definition Documentation

#define NFC_NDEF_GENERIC_RECORD_DESC_DEF (   NAME,
  TNF,
  P_ID,
  ID_LEN,
  P_TYPE,
  TYPE_LEN,
  P_PAYLOAD_CONSTRUCTOR,
  P_PAYLOAD_DESCRIPTOR 
)
Value:
nfc_ndef_record_desc_t NAME##_ndef_generic_record_desc = \
{ \
.tnf = TNF, \
\
.id_length = ID_LEN, \
.p_id = P_ID, \
\
.type_length = TYPE_LEN, \
.p_type = P_TYPE, \
\
.payload_constructor = (p_payload_constructor_t)P_PAYLOAD_CONSTRUCTOR, \
.p_payload_descriptor = (void *) P_PAYLOAD_DESCRIPTOR \
}

Macro for creating and initializing an NFC NDEF record descriptor for a generic record.

This macro creates and initializes an instance of type nfc_ndef_record_desc_t.

Use the macro NFC_NDEF_GENERIC_RECORD_DESC to access the NDEF record descriptor instance.

Note
The record descriptor is declared as automatic variable, which implies that the NDEF record encoding must be done in the same variable scope.
Parameters
[in]NAMEName of the created descriptor instance.
[in]TNFType Name Format (TNF) value for the record.
[in]P_IDPointer to the ID string.
[in]ID_LENLength of the ID string.
[in]P_TYPEPointer to the type string.
[in]TYPE_LENLength of the type string.
[in]P_PAYLOAD_CONSTRUCTORPointer to the payload constructor function. The constructor must be of type p_payload_constructor_t.
[in]P_PAYLOAD_DESCRIPTORPointer to the data for the payload constructor.
#define NFC_NDEF_RECORD_BIN_DATA_DEF (   NAME,
  TNF,
  P_ID,
  ID_LEN,
  P_TYPE,
  TYPE_LEN,
  P_PAYLOAD,
  PAYLOAD_LEN 
)
Value:
nfc_ndef_bin_payload_desc_t NAME##_nfc_ndef_bin_payload_desc = \
{ \
.p_payload = P_PAYLOAD, \
.payload_length = PAYLOAD_LEN \
}; \
\
nfc_ndef_record_desc_t NAME##_nfc_ndef_bin_record_desc = \
{ \
.tnf = TNF, \
\
.id_length = ID_LEN, \
.p_id = P_ID, \
\
.type_length = TYPE_LEN, \
.p_type = P_TYPE, \
\
.p_payload_descriptor = (void *) &NAME##_nfc_ndef_bin_payload_desc \
}

Macro for creating and initializing an NFC NDEF record descriptor for a record with binary payload.

This macro creates and initializes a static instance of type nfc_ndef_record_desc_t and a binary data descriptor containing the payload data.

Use the macro NFC_NDEF_RECORD_BIN_DATA to access the NDEF record descriptor instance.

Note
The record descriptor is declared as automatic variable, which implies that the NDEF record encoding must be done in the same variable scope.
Parameters
[in]NAMEName of the created descriptor instance.
[in]TNFType Name Format (TNF) value for the record.
[in]P_IDPointer to the ID string.
[in]ID_LENLength of the ID string.
[in]P_TYPEPointer to the type string.
[in]TYPE_LENLength of the type string.
[in]P_PAYLOADPointer to the payload data that will be copied to the payload field.
[in]PAYLOAD_LENLength of the payload.

Typedef Documentation

typedef ret_code_t(* p_payload_constructor_t)(void *p_payload_descriptor, uint8_t *p_buffer, uint32_t *p_len)

Payload constructor type.

A payload constructor is a function for constructing the payload of an NDEF record.

Parameters
[in]p_payload_descriptorPointer to the input data for the constructor.
[out]p_bufferPointer to the payload destination. If NULL, function will calculate the expected size of the record payload.
[in,out]p_lenSize of the available memory to write as input. Size of the generated record payload as output. The implementation must check if the payload will fit in the provided buffer. This must be checked by the caller function.
Return values
NRF_SUCCESSIf the function completed successfully.
NRF_ERROR_xxxIf an error occurred.

Enumeration Type Documentation

Record position within the NDEF message.

Values to specify the location of a record within the NDEF message.

Enumerator
NDEF_FIRST_RECORD 

First record.

NDEF_MIDDLE_RECORD 

Middle record.

NDEF_LAST_RECORD 

Last record.

NDEF_LONE_RECORD 

Only one record in the message.

Type Name Format (TNF) Field Values.

Values to specify the TNF of a record.

Enumerator
TNF_EMPTY 

The value indicates that there is no type or payload associated with this record.

TNF_WELL_KNOWN 

NFC Forum well-known type [NFC RTD].

TNF_MEDIA_TYPE 

Media-type as defined in RFC 2046 [RFC 2046].

TNF_ABSOLUTE_URI 

Absolute URI as defined in RFC 3986 [RFC 3986].

TNF_EXTERNAL_TYPE 

NFC Forum external type [NFC RTD].

TNF_UNKNOWN_TYPE 

The value indicates that there is no type associated with this record.

TNF_UNCHANGED 

The value is used for the record chunks used in chunked payload.

TNF_RESERVED 

The value is reserved for future use.

Function Documentation

ret_code_t nfc_ndef_bin_payload_memcopy ( nfc_ndef_bin_payload_desc_t p_payload_descriptor,
uint8_t *  p_buffer,
uint32_t *  p_len 
)

Function for constructing the payload for an NFC NDEF record from binary data.

This function copies data from a binary buffer to the payload field of the NFC NDEF record.

Parameters
[in]p_payload_descriptorPointer to the descriptor of the binary data location and size.
[out]p_bufferPointer to the payload destination. If NULL, function will calculate the expected size of the record payload.
[in,out]p_lenSize of the available memory for the payload as input. Size of the copied payload as output.
Return values
NRF_SUCCESSIf the function completed successfully.
NRF_ERROR_NO_MEMIf the payload size is bigger than the provided buffer space.
ret_code_t nfc_ndef_record_encode ( nfc_ndef_record_desc_t const *  p_ndef_record_desc,
nfc_ndef_record_location_t  record_location,
uint8_t *  p_record_buffer,
uint32_t *  p_record_len 
)

Function for encoding an NDEF record.

This function encodes an NDEF record according to the provided record descriptor.

Parameters
[in]p_ndef_record_descPointer to the record descriptor.
[in]record_locationLocation of the record within the NDEF message.
[out]p_record_bufferPointer to the record destination. If NULL, function will calculate the expected size of the record.
[in,out]p_record_lenSize of the available memory for the record as input. Size of the generated record as output.
Return values
NRF_SUCCESSIf the record was encoded successfully.
NRF_ERROR_NO_MEMIf the predicted record size is bigger than the provided buffer space.
NRF_ERROR_INVALID_PARAMIf the location of the record is erroneous.
OtherOther codes might be returned depending on the NDEF record payload constructor implementation.

Documentation feedback | Developer Zone | Subscribe | Updated