From 83d5402fe830973f943bde085d80f0d3643e811a Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 5 Aug 2022 10:50:47 +0200 Subject: [PATCH] Bluetooth: host: Fix SMP local keys check when starting encryption Fix SMP check of existing local keys when attempting to start security with required security mode 1 level 4. The logic for checking the conditions was wrong, leading to a situation where encryption would be attempted to be started by the central instead of initiating a new pairing procedure. This would fail when the connection was encrypted and the connection would be disconnected. Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/smp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 5132ad7495..899fab954d 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -357,15 +357,15 @@ static bool smp_keys_check(struct bt_conn *conn) return false; } - if (conn->required_sec_level > BT_SECURITY_L2 && + if (conn->required_sec_level >= BT_SECURITY_L3 && !(conn->le.keys->flags & BT_KEYS_AUTHENTICATED)) { return false; } - if (conn->required_sec_level > BT_SECURITY_L3 && - !(conn->le.keys->flags & BT_KEYS_AUTHENTICATED) && - !(conn->le.keys->keys & BT_KEYS_LTK_P256) && - !(conn->le.keys->enc_size == BT_SMP_MAX_ENC_KEY_SIZE)) { + if (conn->required_sec_level >= BT_SECURITY_L4 && + !((conn->le.keys->flags & BT_KEYS_AUTHENTICATED) && + (conn->le.keys->keys & BT_KEYS_LTK_P256) && + (conn->le.keys->enc_size == BT_SMP_MAX_ENC_KEY_SIZE))) { return false; }