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
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 is finished. 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.
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.
A tag in the Static Handover mode, contains a Handover Select Message with carrier information NDEF records or a single Carrier Configuration Record.
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.
This sample can be configured 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
The sample supports the following development kits:
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.
- Button 1:
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.
This sample can be found under
samples/bluetooth/peripheral_nfc_pairing in the nRF Connect SDK folder structure.
See Building and programming a sample application for information about how to build and program the application.
After programming the sample to your development kit, test it by performing the following steps:
Testing with NFC Poller Device¶
Touch the NFC antenna with the smartphone or tablet and observe that LED 2 is lit.
Confirm pairing with
Nordic_NFC_pairingin a pop-up window on the smartphone or tablet and observe that LED 1 lights up.
Move the smartphone or tablet away from the NFC antenna and observe that LED 2 turns off.
Testing with NFC TNEP Poller Device¶
Touch the NFC antenna with the NFC Poller Device, for example Bluetooth: Central NFC pairing and observe that LED 2 is lit.
Observe the output log. The content of the exchanged NDEF messages is printed there.
Check the security level of the paring on the terminal.
Move the NFC antenna away from the NFC Poller Device.
This sample uses the following nRF Connect SDK libraries:
In addition, it uses the Type 4 Tag library from nrfxlib:
The sample uses the following Zephyr libraries: