Bluetooth: Bond Management Service (BMS)
This sample demonstrates how to use the Bond Management Service (BMS).
Requirements
The sample supports the following development kits:
The following board variants do not have DFU capabilities:
S115:
Hardware platform
PCA
Board target
PCA10156
bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
nRF54L15 DK (emulating nRF54L10)
PCA10156
bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
nRF54L15 DK (emulating nRF54L05)
PCA10156
bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
PCA10184
bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice
PCA10214
bm_nrf54ls05dk/nrf54ls05b/cpuapp/s115_softdevice
PCA10188
bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice
S145:
Hardware platform
PCA
Board target
PCA10156
bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice
nRF54L15 DK (emulating nRF54L10)
PCA10156
bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice
nRF54L15 DK (emulating nRF54L05)
PCA10156
bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice
PCA10184
bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice
PCA10214
bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice
PCA10188
bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice
The following board variants have DFU capabilities:
S115:
Hardware platform
PCA
Board target
PCA10156
bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
nRF54L15 DK (emulating nRF54L10)
PCA10156
bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
nRF54L15 DK (emulating nRF54L05)
PCA10156
bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
PCA10184
bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice/mcuboot
PCA10214
bm_nrf54ls05dk/nrf54ls05b/cpuapp/s115_softdevice/mcuboot
PCA10188
bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice/mcuboot
S145:
Hardware platform
PCA
Board target
PCA10156
bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice/mcuboot
nRF54L15 DK (emulating nRF54L10)
PCA10156
bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice/mcuboot
nRF54L15 DK (emulating nRF54L05)
PCA10156
bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot
PCA10184
bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice/mcuboot
PCA10214
bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice/mcuboot
PCA10188
bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice/mcuboot
Overview
When connected, the sample waits for the client’s requests to perform any bond-deleting operation.
Allow list
By default, the sample does not use allow-list advertising, which means that any nearby device can connect and bond with the device. Bonded devices are stored in internal non-volatile memory (NVM) and are remembered across power cycles.
You can enable allow-list advertising by setting the CONFIG_BLE_ADV_USE_ALLOW_LIST Kconfig option to y in the base Kconfig fragment (prj.conf).
When enabled, only previously bonded devices are allowed to reconnect, which allows faster reconnection and prevents unknown devices from connecting.
When allow-list advertising is enabled and you want to add a new bonded device, existing bonds must first be deleted. This can be done through user interaction, as described in the user interface section.
User interface
- Button 0:
When pairing with authentication, press this button to confirm the passkey shown in the COM listener and complete pairing with the other device. See Testing.
- Button 1:
Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device.
When pairing with authentication, press this button to reject the passkey shown in the COM listener to prevent pairing with the other device.
- LED 0:
Lit when the device is initialized.
- LED 1:
Lit when a device is connected.
Building and running
This sample can be found under samples/bluetooth/ble_bms/ 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 to the kit that runs this sample with a terminal emulator (for example, the Serial Terminal app).
Reset the kit.
In the Serial Terminal, observe that the
BLE BMS sample initializedmessage is printed.Observe that the
Advertising as nRF_BM_BMSmessage is printed. You can configure the advertising name using theCONFIG_SAMPLE_BLE_DEVICE_NAMEKconfig option. For information on how to do this, see Configuring Kconfig.Open nRF Connect for Desktop.
Open the Bluetooth Low Energy app and select the connected device that is used for communication.
Connect to the device from the app. If the device is not advertising, reset the board with the Reset Board option in Visual Studio Code or by pressing the reset button on the development kit.
Bind with the device:
Click the Settings button for the device in the app.
Select Pair.
Select Keyboard and display in the IO capabilities setting.
Select Perform Bonding.
Click Pair.
Check the logs to verify that the connection security is updated.
Disconnect the device in the app.
Reconnect again and verify that the connection security is updated automatically.
Verify that the Feature Characteristic of the Bond Management Service displays
10 08 02. This means that the following features are supported:Deletion of the bonds for the current connection of the requesting device.
Deletion of all bonds on the Server with the Authorization Code.
Deletion of all bonds on the Server except the ones of the requesting device with the Authorization Code.
Write
03to the Bond Management Service Control Point Characteristic.03is the command to delete the current bond.Disconnect the device to trigger the bond deletion procedures.
Delete the bond information of the central device in the app:
Click the Settings button for the device in the app.
Click Delete bond information.
Reconnect the devices and verify that the connection security is not updated.
Bond both devices again.
Write
06 41 42 43 44to the Bond Management Service Control Point Characteristic.06is the command to delete all bonds on the server, followed by the authorization codeABCD(ASCII0x41 0x42 0x43 0x44).Disconnect the device to trigger the bond deletion procedures.
Delete the bond information of the central device again.
Reconnect the devices again and verify that the connection security is not updated.
Note
The default authorization code ABCD (ASCII 0x41 0x42 0x43 0x44) is configurable through the CONFIG_SAMPLE_BLE_BMS_AUTHORIZATION_CODE Kconfig option.
The maximum allowed length is BLE_BMS_AUTH_CODE_MAX_LEN (127 bytes), which comes from the BMS control point definition.
Authorization codes up to 127 bytes are supported. You may configure the code to any value within this limit as needed.
If this security feature is not required, it can be enabled or disabled using the CONFIG_SAMPLE_BLE_BMS_USE_AUTHORIZATION_CODE Kconfig option.
After changing the configuration, rebuild the sample and test how bond deletion behaves with or without an authorization code.