hsw-nbt 1.2.0
OPTIGA Authenticate NBT Host Library for C
NFC data exchange format (NDEF) library

‍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

  • Record chunks

Usage

  1. 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.
  1. Encode the URI record

    uint8_t data_1[] = "infineon.com";
    uint8_t data_2[] = "github.com/infineon";
    ifx_blob_t uri_data_1;
    uri_data_1.buffer = data_1;
    uri_data_1.length = sizeof(data_1);
    ifx_blob_t uri_data_2;
    uri_data_2.buffer = data_2;
    uri_data_2.length = sizeof(data_2);
    // Create new URI record
    ifx_record_uri_new(&handles[0]);
    ifx_record_uri_new(&handles[1]);
    // Set identifier code of the URI record
    // Set URI field of the URI record
    ifx_record_uri_set_uri(&handles[0], &uri_data_1);
    ifx_record_uri_set_uri(&handles[1], &uri_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.
    @ IFX_URI_HTTPS
    @ IFX_URI_HTTPS_WWW
    Data storage for data and data length where both are required as parameters.
    Definition ifx-utils.h:189
    uint8_t * buffer
    Definition ifx-utils.h:194
    uint32_t length
    Definition ifx-utils.h:191
    Defines the handle for specific record type.
  1. Encode the NDEF message

    ifx_blob_t ndef_message;
    uint32_t number_of_records = 0x02;
    // Encode the record into the NDEF message
    ifx_status_t status = ifx_ndef_message_encode(&handles[0], number_of_records, &ndef_message);
    uint32_t ifx_status_t
    Custom return code type used by all Infineon host software libraries.
    Definition ifx-error.h:91
    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.
  1. Decode the NDEF message

    uint32_t no_of_records = 0x00;
    // Decode the NDEF message into array of NDEF records
    status = ifx_ndef_message_decode(&ndef_message, &no_of_records, (ifx_record_handle_t *)&handles);
    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.
  1. Decode the URI record

    uint8_t identifier_code = 0;
    ifx_blob_t uri, uri_identifier, identifier;
    // Get the URI record identifier code
    status = ifx_record_uri_get_identifier_code(&handles[0], &identifier_code);
    // Get the URI record URI field
    status = ifx_record_uri_get_uri(&handles[0], &uri);
    // Get the URI record identifier as string
    status = ifx_record_uri_get_identifier(&handles[0], &identifier);
    // Get the URI record combining URI field with identifier
    status = ifx_record_uri_get_uri_with_identifier(&handles[0], &uri_identifier);
    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.
  1. Release the memory allocated by the library

    // free-up the internally allocated memory.
    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.

hsw-ndef-archtitecture

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.

hsw-ndef-interaction

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