Re: Pairing/bonding Zephyr API? Pairing info?

Johan Hedberg

Hi Frank,

On 5 Feb 2019, at 15.25, frv <F.Vieren@...> wrote:
If the pairing process has succeeded is bonding automatically done?
I don't really understand the comment in the Bluetooth API for the function call:
"For the vast majority of applications calling this function shouldn’t be needed."

void bt_set_bondable(bool enable)

"Set/clear the Bonding flag in the Authentication Requirements of SMP Pairing Request/Response data. The initial value of this flag depends on BT_BONDABLE Kconfig setting. For the vast majority of applications calling this function shouldn’t be needed."

BTW I don't find this API any longer in Bluetooth code (V1.14), probably no longer valid?
Why do you say that? It’s still there in include/bluetooth/conn.h. However, the comment is correct - Zephyr defaults to bondable, so you only need to touch this stuff if you want to perform qualification tests on non-bondable mode.


Also is there an API call to see if the device is already paired? Because after a board startup(power cycle) I don't want to set a new passkey if the device is already paired.

In my case the BLE peripheral sets a random fixed passkey at startup and the connecting central needs to set this passkey after initiating the pairing process.
You can iterate through existing bonds using the bt_foreach_bond() API, however it’s not clear to me why your application would need to use it - if a device is bonded then the previously stored LTK will be used, and if it’s not bonded then a new pairing process will be triggered. Note that you need to have flash storage support enabled, including CONFIG_BT_SETTINGS, in order for the bonding information to be persistently stored and reloaded after a power cycle.


Join to automatically receive all group messages.