Bluetooth: NFC pairing

The NFC pairing sample demonstrates Bluetooth® LE out-of-band pairing using an NFC tag and the NFC TNEP protocol. You can use it to test the touch-to-pair feature between Nordic Semiconductor’s devices and an NFC polling device with Bluetooth LE support, for example, a mobile phone.

The sample shows the usage of NFC NDEF Connection Handover messages and records and TNEP for tag device with the Connection Handover service. It provides minimal Bluetooth functionality in Peripheral role and on GATT level it implements only the Device Information Service.

The sample supports pairing in one of the following modes:

  • LE Secure Connections Just Works pairing

  • LE Secure Connections OOB pairing

  • Legacy OOB pairing

  • Legacy Just Works pairing

  • Negotiated Handover (TNEP protocol) - two-way OOB pairing

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF52 DK

PCA10040

nrf52dk_nrf52832

nrf52dk_nrf52832

nRF52833 DK

PCA10100

nrf52833dk_nrf52833

nrf52833dk_nrf52833

The sample has the following additional requirements:

  • NFC polling device (for example, a smartphone or a tablet with NFC support).

  • NFC polling device with TNEP support (when testing the two-way OOB pairing). You can use the corresponding Bluetooth: Central NFC pairing as an NFC Polling Device.

Overview

When the application starts, it initializes and starts the NFCT peripheral that is used for pairing. The application does not start advertising immediately, but only when the NFC tag is read by an NFC polling device, for example a smartphone or a tablet with NFC support, or when the exchange of data over the TNEP Connection Handover Service has completed. The message that the tag sends to the NFC device contains the data required to initiate pairing. To start the NFC data transfer, the NFC device must touch the NFC antenna that is connected to the development kit.

After reading the tag or exchanging data over TNEP, the initiator can connect and pair with the device that is advertising. The connection state of the device is signaled by the LEDs. When the connection is lost due to a timeout, the library automatically triggers direct advertising.

NFC data exchange

This sample can exchange OOB data with an NFC Forum Polling device with TNEP support or can be read as a Static Tag by NFC Forum Polling Devices that do not support TNEP.

Static Handover

A tag in the Static Handover mode, contains a Handover Select Message with carrier information NDEF records or a single Carrier Configuration Record.

Static Handover

Negotiated Handover

In Negotiated Handover, two NFC Forum Devices identify a matching set of alternative carriers by exchanging lists of potential alternative carriers. In case of the OOB data for Bluetooth LE, the NFC devices can exchange OOB data in a two-way manner. Handover messages are exchanged using the TNEP Single Response communication mode. The NFC Poller Device can have the Handover Requester or Handover Selector Device role. The role is assumed based on the first NDEF message from the NFC Tag.

You can configure this sample to take the Connection Handover Selector role or the Connection Requester role. The Connection Handover Selector role is default for this sample. You can change the default role by choosing CONFIG_NFC_TAG_CH_SELECTOR or CONFIG_NFC_TAG_CH_REQUESTER.

Negotiated Handover

User interface

Button 4:

Removes all bonded devices and terminates current connections.

LED 1:

Indicates that a Bluetooth connection is established.

LED 2:

Indicates that an NFC field is present.

Building and running

This sample can be found under samples/bluetooth/peripheral_nfc_pairing in the nRF Connect SDK folder structure.

See Building and programming an application for information about how to build and program the application.

Testing

After programming the sample to your development kit, complete the following steps to test it:

Testing with NFC Poller Device

  1. Touch the NFC antenna with the smartphone or tablet and observe that LED 2 is lit.

  2. Confirm pairing with Nordic_NFC_pairing in a pop-up window on the smartphone or tablet and observe that LED 1 lights up.

  3. Move the smartphone or tablet away from the NFC antenna and observe that LED 2 turns off.

Testing with NFC TNEP Poller Device

  1. Touch the NFC antenna with the NFC Poller Device, for example Bluetooth: Central NFC pairing and observe that LED 2 is lit.

  2. Observe the output log. The content of the exchanged NDEF messages is printed there.

  3. Check the security level of the paring on the terminal.

  4. Move the NFC antenna away from the NFC Poller Device.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the Type 4 Tag library from nrfxlib:

It uses the following Zephyr libraries: