[nRF Connect SDK](Urgent)Re-bonding with Android

Target nRF52832(nrf52dk_nrf52832)
SDK NCS v1.9.1

prj.conf
CONFIG_BT_MAX_PAIRED=4
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y

BT_CONN_CB_DEFINE(conn_callbacks) = {
	.connected    = connected,
	.disconnected = disconnected,
#ifdef CONFIG_BT_SECURITY_ENABLED
	.security_changed = security_changed,
#endif
	.le_param_req = le_param_req_kbd,
	.le_param_updated = le_param_updated,
	.le_phy_updated = le_phy_updated,
	.le_data_len_updated = le_data_length_updated

};


static void security_changed(struct bt_conn *conn, bt_security_t level,
			     enum bt_security_err err)
{
	const bt_addr_le_t* addr = bt_conn_get_dst(conn);
	...
}


If Nordic BLE reach max pairing, BLE delete its pairing, but Android has previous pairing.
What if I should do in that case? I found err was 2 when pairing was deleted.

Please let me have sample to make pairing again.
Thanks!

  • I found that if err is not 0, I call following two functions then BLE initiate pairing process again.
    Is it good sequence? Or let me have good solution.

    bt_set_bondable(true);
    bt_conn_set_security(conn, BT_SECURITY_L4);

  • Hi,

    Generally, if the bond is delete on the nRF and not deleted on the phone, any subsequent reconnections will fail and the only way to solve this is to also delete the bond on the phone. To avoid this, try to avoid having to delete bonds on the nRF (increase the maximum amount of bonds to a level you will normally not reach, provided you have enough flash for it).

    Tim Hwang said:

    I found that if err is not 0, I call following two functions then BLE initiate pairing process again.
    Is it good sequence? Or let me have good solution.

    bt_set_bondable(true);
    bt_conn_set_security(conn, BT_SECURITY_L4);

    I do not see how this would fix the issue you described in your initial post, but perhaps there is something I am not getting. Perhaps you can elaborate?

  • 1. Our usage requires lots of Android(+iOS) with one BLE device, so that BLE can delete its pairing.
    2. As this case subject, I want to make bonding again without user action. If security_changed() have error (not 0), I call bt_conn_set_security(). BLE initiate bonding process. I want double check if it is fine.

    Thanks.

  • I see. The fact remains that the bond has to be deleted on the Android device if deleted on the nRF, but other than that what you describe is fine. You can use bt_set_bondable() to enable or disable bonding, and you can use bt_conn_set_security() to encrypt a link (and start bonding if a bond does not already exist).

Related