C library to encode and decode the NDEF messages
The NFC data exchange format (NDEF) specification by NFC Forum defines a common data format to exchange information between NFC Forum devices. An NDEF message is composed of one or more NDEF records. Each NDEF record contains the record type information and a payload.
This C library provides support to build and parse the NDEF messages, with support for common NDEF record type definitions. This library is extensible for addition of new record type definitions.
Features
- Build and parse the NDEF messages
- Build and parse the NDEF records
- Supported records:
- URI record
- Bluetooth connection handover records (For static connection handover)
- Bluetooth record
(application/vnd.bluetooth.ep.oob)
- Bluetooth LE record
(application/vnd.bluetooth.le.oob)
- Handover select record
- Alternative carrier record
- Error record
- MIME type record
- External type record
Features not supported
Usage
Include the following headers
Infineon specific error code creation and parsing.
NDEF message encoding/decoding utility.
Model interface to create record types and set/get record fields.
Model interface to create URI record types and get/set record fields.
Provides utility functions and macros.
Encode the URI record
uint8_t data_1[] = "infineon.com";
uint8_t data_2[] = "github.com/infineon";
uri_data_1.
length =
sizeof(data_1);
uri_data_2.
length =
sizeof(data_2);
ifx_status_t ifx_record_uri_set_uri(ifx_record_handle_t *handle, const ifx_blob_t *uri)
Sets the URI value in the URI record details.
ifx_status_t ifx_record_uri_new(ifx_record_handle_t *handle)
Creates a new URI record and handle of the created record. This handle holds the values of the record...
ifx_status_t ifx_record_uri_set_identifier_code(ifx_record_handle_t *handle, uint8_t identifier_code)
Sets the identifier code in the URI record details.
Data storage for data and data length where both are required as parameters.
Defines the handle for specific record type.
Encode the NDEF message
uint32_t number_of_records = 0x02;
uint32_t ifx_status_t
Custom return code type used by all Infineon host software libraries.
ifx_status_t ifx_ndef_message_encode(const ifx_record_handle_t *record_handles, uint32_t number_of_records, ifx_blob_t *ndef_message)
Encodes the array of the NDEF record handles into the NDEF message.
Decode the NDEF message
uint32_t no_of_records = 0x00;
ifx_status_t ifx_ndef_message_decode(const ifx_blob_t *ndef_message, uint32_t *number_of_records, ifx_record_handle_t *record_handles)
Decodes the NDEF message buffer to the NDEF records array.
Decode the URI record
uint8_t identifier_code = 0;
ifx_status_t ifx_record_uri_get_identifier_code(const ifx_record_handle_t *handle, uint8_t *identifier_code)
Gets the identifier code from the URI record details.
ifx_status_t ifx_record_uri_get_uri(const ifx_record_handle_t *handle, ifx_blob_t *uri)
Gets the URI value field from the URI record.
ifx_status_t ifx_record_uri_get_identifier(const ifx_record_handle_t *handle, ifx_blob_t *identifier)
Gets the identifier bytes from the URI record.
ifx_status_t ifx_record_uri_get_uri_with_identifier(const ifx_record_handle_t *handle, ifx_blob_t *uri_with_identifier)
Gets the URI value along with the identifier from the URI record.
Release the memory allocated by the library
ifx_status_t ifx_ndef_record_release_resource(void)
This method will free-up the internally allocated memory for ndef registered records.
Architecture
This image shows the software architecture of the library.

Components
- NDEF message This component provides methods to encode array of records into an NDEF message and similarly decode an NDEF message into array of records.
- Record models This component contains the record models that are in-built supported by the library. These record models provide the structure for the record, which can be used to build the record. Example:
ifx_record_uri_set_uri(&record, "https://www.infineon.com")
- NDEF record This component contains the methods to encode and decode the NDEF record headers.
- Record payload encoders and decoders This component contains the payload encoders and decoders, which can be used to encode and decode the payload details into a byte array.
Interaction
Below UML diagram describes the interaction between the components.

Directory structure
The code is structured according to the Pitchfork Layout.
hsw-ndef
|-- .cmake/ # Includes sources for dependency management
|-- LICENSES/ # Includes list of licenses used for the library
|-- data/ # Includes Doxygen, cppcheck configuration files
|-- docs/ # Includes documentation source files, images, and the generated API reference
|-- include/ # Public Headers(.h) of the library
|-- src/ # Sources(.c) and Private headers(.h) of the library
|-- .clang-format # clang-format configuration file
|-- .gitignore # Library specific gitignore file
|-- CMakeLists.txt # CMake build configurations for the library
`-- README.md # Overview of the hsw-ndef library
Dependencies
- hsw-error This dependent library is used for creating and parsing an error information.
- hsw-utils This dependent library provides the utility methods such as for byte conversions, string conversions, bit operations, and encoders/decoders for 2-byte TLV data.
References
- NFC Data Exchange Format (NDEF), Technical Specification, NFC Forum™, NDEF 1.0
- NFC Record Type Definition (RTD), Technical Specification, NFC Forum™, RTD 1.0
- URI Record Type Definition (RTD), Technical Specification, NFC Forum™, RTD-URI 1.0
- Connection Handover, Technical Specification, NFC Forum™, CH 1.4
- Bluetooth® Secure Simple Pairing Using NFC, Application Document, NFC Forum™, BTSSP 1.3