Bluetooth: NFC pairing
The NFC pairing sample demonstrates Bluetooth® LE out-of-band pairing using an NFC tag. 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 provides minimal Bluetooth functionality in Peripheral role and on GATT level it implements only the Device Information Service.
The sample supports only LE Secure Connections OOB pairing. Pairing requests without the OOB data from the NFC tag are rejected.
Requirements
The sample supports the following development kits:
The following board variants do not have DFU capabilities:
S115:
Hardware platform |
PCA |
Board target |
|---|---|---|
PCA10156 |
|
|
nRF54L15 DK (emulating nRF54L10) |
PCA10156 |
|
nRF54L15 DK (emulating nRF54L05) |
PCA10156 |
|
nRF54LM20 DK (emulating nRF54LM20A) |
PCA10184 |
|
S145:
Hardware platform |
PCA |
Board target |
|---|---|---|
PCA10156 |
|
|
nRF54L15 DK (emulating nRF54L10) |
PCA10156 |
|
nRF54L15 DK (emulating nRF54L05) |
PCA10156 |
|
nRF54LM20 DK (emulating nRF54LM20A) |
PCA10184 |
|
The following board variants have DFU capabilities:
S115:
Hardware platform |
PCA |
Board target |
|---|---|---|
PCA10156 |
|
|
nRF54L15 DK (emulating nRF54L10) |
PCA10156 |
|
nRF54L15 DK (emulating nRF54L05) |
PCA10156 |
|
nRF54LM20 DK (emulating nRF54LM20A) |
PCA10184 |
|
S145:
Hardware platform |
PCA |
Board target |
|---|---|---|
PCA10156 |
|
|
nRF54L15 DK (emulating nRF54L10) |
PCA10156 |
|
nRF54L15 DK (emulating nRF54L05) |
PCA10156 |
|
nRF54LM20 DK (emulating nRF54LM20A) |
PCA10184 |
|
The sample additionally requires an NFC polling device (for example, a smartphone or a tablet with NFC support).
Overview
When the application starts, it initializes and starts the NFCT peripheral that is used for pairing. The application primarily uses allow list advertising and only allows bonded devices to connect. When the NFC tag is read by an NFC polling device, for example, a smartphone or a tablet with NFC support, the application advertises without the allow list to allow non-bonded devices to connect. 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 the initiator can connect and pair with the device that is advertising. The connection state of the device is signaled by the LEDs.
NFC data exchange
From the NFC perspective, the sample implements a Type 4 Tag that contains a Handover Select Message with carrier information NDEF records.
User interface
- Button 1:
Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device.
- Button 2:
Start advertising, allowing already bonded devices to connect.
- LED 0:
Lit when the device is initialized.
- LED 1:
Lit when a device is connected.
- LED 2:
Lit when an NFC field is present.
Security
The sample integrates Bluetooth: Peer Manager (backed by Bare Metal Zephyr Memory Storage (BM_ZMS) for persistent storage) to support pairing and bonding.
The following security parameters are configured:
Parameter |
Value |
Effect |
|---|---|---|
Bonding |
True |
Supports storing of pairing information (bonding data). |
MITM protection |
False |
Man-in-the-middle protection not required. |
LE Secure Connections |
True |
Supports LESC pairing. |
I/O capabilities |
None |
Authentication relies on the out-of-band data exchanged over NFC instead of a display or keyboard, as described in Overview. |
This sample configures the following services and their characteristics with these specific operation modes and required security levels:
Service |
Characteristic |
Operation |
Required security level |
Effect |
|---|---|---|---|---|
Device Information Service |
All characteristics |
Read |
Open, no security |
Any connected device can read device information. |
See Testing for the pairing and bonding steps.
Building and running
This sample can be found under samples/bluetooth/peripheral_nfc_pairing/ in the Bare Metal folder structure.
For details on how to create, configure, and program a sample, see Getting Started with the samples.
Testing
Compile and program the application.
Connect the device to the computer.
Connect to the kit with a terminal emulator (for example, the Serial Terminal app). Note that the kit has two UARTs, where only one will output the log.
Reset the kit.
In the Serial Terminal, observe that the
BLE Peripheral NFC Pairing sample started.message is printed.Touch the NFC antenna with the smartphone or tablet and observe that LED 2 is lit.
Confirm pairing with nRF_BM_Nordic_NFC_pairing in 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.
Disconnect and then reconnect the smartphone or tablet to the device. Observe that the connection is accepted. Use Button 2 to start advertising if it stops.
Disconnect, delete the bond information on the smartphone or tablet, and attempt to reconnect. Observe that the connection is rejected or pairing fails. Connection requests from non-bonded devices are rejected.
To be able to connect again, pair the smartphone or tablet with the device using NFC.
Dependencies
This sample has the following Bare Metal dependencies:
In addition, it uses the Type 4 Tag from sdk-nrfxlib.
See NFC libraries for more information about the NFC libraries.