nRF5 SDK v13.0.0
NFC BLE pairing library

The NFC BLE Pairing library is a high level module that uses NFC technology to establish a BLE connection. It integrates SDK modules such as Peer Manager, Advertising Module, and NFC Type 2 Tag to provide easy-to-use API for basic Connection Handover pairing scenarios. It is also a good starting point to develop more sophisticated pairing procedures.

Library supports four Connection Handover pairing modes:

Architecture overview

The library uses BLE pairing message generation to encode the Connection Handover NDEF message with BLE advertising data into the NFC Type 2 Tag. It also takes advantage of the Tag 2 Type emulation to dynamically change security key values on each NFC_T2T_EVENT_FIELD_ON event. For more information on BLE Connection Handover message, refer to the NFC Forum Application Document Bluetooth Secure Simple Pairing Using NFC.

Depending on the pairing mode, the library sets up proper Peer Manager security parameters and Connection Handover message data. It also generates random TK and LESC OOB keys values and responds to BLE authentication events. For more information on security parameters configuration, refer to the Bluetooth Core Specification Volume 3 Part H Chapter 2.

Advertising Module is used to automatically turn on fast advertising when NFC module detects the field and Tag data is obtained by the reader. Advertising is disabled after the BLE connection has been established or a timeout has occurred. The library also turns on directed advertising when connection timeout occurs due to link loss.

Library usage

Library usage is based on the Experimental: Heart Rate Application with BLE Pairing Using NFC Pairing Library example. To properly set up the library, perform the following steps:

  1. Configure Peer Manager security parameters settings - they are located in the SDK configuration header file.
  2. Add a library event handler - on_nfc_ble_pair_evt function to the BLE event dispatcher:
    /**@brief Function for dispatching a BLE stack event to all modules with a BLE stack event handler.
    *
    * @details This function is called from the BLE Stack event interrupt handler after a BLE stack
    * event has been received.
    *
    * @param[in] p_ble_evt Bluetooth stack event.
    */
    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    {
    pm_on_ble_evt(p_ble_evt);
    ble_hrs_on_ble_evt(&m_hrs, p_ble_evt);
    ble_bas_on_ble_evt(&m_bas, p_ble_evt);
    on_ble_evt(p_ble_evt);
    on_nfc_ble_pair_evt(p_ble_evt);
    nrf_ble_gatt_on_ble_evt(&m_gatt, p_ble_evt);
    }
  3. Initialize and enable the SoftDevice
  4. Initialize Peer Manager and Advertising Module with the fast advertising mode enabled
  5. Initialize the library by issuing a call to the nfc_ble_pair_init function:
    ble_stack_init();
    gap_params_init();
    gatt_init();
    peer_manager_init(erase_bonds);
    if (erase_bonds)
    {
    NRF_LOG_INFO("Bonds erased!\r\n");
    }
    advertising_init();
    nrf_ble_pairing_init();
    When these steps are finished, the library is ready to support establishing BLE connections by means of NFC. You can also call the nfc_ble_pair_mode_set function to change the pairing mode.

Documentation feedback | Developer Zone | Subscribe | Updated