Peripheral: Nordic nRF52840 chipset with Zephyr
Central: Android smartphone
Bond is created and "pairing_complete" callback is called in peripheral. But when manually delete the bonding(from Bluetooth > [peripheral device]Unpair), how can the peripheral gets a notification?
BT_CONN_CB_DEFINE(conn_callbacks) = {
.connected = connected,
.disconnected = disconnected,
};
struct bt_conn_auth_cb cb = {
.cancel = cancel,
.oob_data_request = NULL,
.pairing_confirm = NULL,
.passkey_confirm = pass_confirm,
.passkey_display = pass_display,
.passkey_entry = NULL,
};
bt_conn_auth_cb_register(&cb);
struct bt_conn_auth_info_cb info_cb = {
.bond_deleted = bond_deleted, // ------> not getting called when central deletes the pairing
.pairing_complete = pairing_complete,
.pairing_failed = pairing_failed,
};
bt_conn_auth_info_cb_register(&info_cb);
The callbacks are implemented as usual. My question is, when user deletes the bonding(unpair) from smartphone:
- Why the peripheral not getting notification in "bond_deleted' callback?
- Is there any other way to get this notification?
- Or is this BLE concept?
- FYI:
- "disconnected" callback is getting called
- After disconnection, if I connect from another central, peripheral gets the "bond_deleted" called before bonded
The
bond_deleted
callback seems only being called when the bond removal is initiated by the local device, as seen here: https://github.com/zephyrproject-rtos/zephyr/pull/26876 where it was introduced. Maybe this callback is called for you when you bond a new central because the oldest one is being removed.Naturally, the peripheral can't be notified of the bond removal in the central in case the peripheral is disconnected (e.g. out of range) when being unbonded in the central.
If there is a connection ongoing while the central unbonds, then unfortunately it just disconnects without informing the peripheral that the central has removed its bond. The next time it connects (if it ever does so), it will need to perform a new pairing attempt in case it needs to communicate securely.
To solve the issue that the peripheral is not notified of the unbonding attempt, there is a BLE service for that: the Bond Management Service. See https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/bluetooth/peripheral_bms/README.html for an nRF Connect SDK implementation. I'm not sure if Android implements it though (I would be surprised if it did).