Skip to content

Commit 75f6793

Browse files
theob-prorlubos
authored andcommitted
[nrf fromtree] Bluetooth: Host: Abort pairing if disconnected
If disconnection has been triggered in between the security update and the call to `smp_pairing_complete` we need to abort the pairing. The disconnection may have been triggered by `bt_unpair`, in that case the keys will have been erased and it will lead to an assertion to continue as if nothing happened. To resolve this issue, at the beginning of `smp_pairing_complete` the `status` is set to `BT_SMP_ERR_UNSPECIFIED` if there is no connection. Signed-off-by: Théo Battrel <[email protected]> (cherry picked from commit cd264b2)
1 parent b57a748 commit 75f6793

File tree

1 file changed

+10
-2
lines changed
  • subsys/bluetooth/host

1 file changed

+10
-2
lines changed

subsys/bluetooth/host/smp.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,15 @@ static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
16321632
{
16331633
struct bt_conn *conn = smp->chan.chan.conn;
16341634

1635-
LOG_DBG("status 0x%x", status);
1635+
LOG_DBG("got status 0x%x", status);
1636+
1637+
if (conn->state != BT_CONN_CONNECTED) {
1638+
/* If disconnection has been triggered in between the security update
1639+
* and the call to this function we need to abort the pairing.
1640+
*/
1641+
LOG_WRN("Not connected!");
1642+
status = BT_SMP_ERR_UNSPECIFIED;
1643+
}
16361644

16371645
if (!status) {
16381646
#if defined(CONFIG_BT_BREDR)
@@ -1701,7 +1709,7 @@ static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
17011709

17021710
smp_reset(smp);
17031711

1704-
if (conn->sec_level != conn->required_sec_level) {
1712+
if (conn->state == BT_CONN_CONNECTED && conn->sec_level != conn->required_sec_level) {
17051713
bt_smp_start_security(conn);
17061714
}
17071715
}

0 commit comments

Comments
 (0)