From 05354129e714eb19cbf52eb0640b97c8f282544b Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 22 Aug 2019 14:20:56 +0200 Subject: [PATCH] Bluetooth: SMP: Give security changed when rejecting LTK Give the security changed callback when the peripheral initiated security request and peer attempted to encrypt the connection but no LTK match was found. Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/hci_core.c | 1 + subsys/bluetooth/host/smp.c | 17 +++++++++++++++++ subsys/bluetooth/host/smp.h | 1 + 3 files changed, 19 insertions(+) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 2c103225cb6..9ec63fb987a 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3248,6 +3248,7 @@ static void le_ltk_request(struct net_buf *buf) #endif /* !CONFIG_BT_SMP_SC_PAIR_ONLY */ le_ltk_neg_reply(evt->handle); + bt_smp_keys_reject(conn); done: bt_conn_unref(conn); diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 28de92b7f9b..5f4ed0d17bd 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -5000,6 +5000,23 @@ bool bt_smp_keys_check(struct bt_conn *conn) return true; } +void bt_smp_keys_reject(struct bt_conn *conn) +{ + struct bt_smp *smp; + + smp = smp_chan_get(conn); + if (!smp) { + return; + } + + if (atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { + bt_conn_security_changed(smp->chan.chan.conn, + BT_SECURITY_ERR_PIN_OR_KEY_MISSING); + } + + smp_reset(smp); +} + static int bt_smp_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan) { int i; diff --git a/subsys/bluetooth/host/smp.h b/subsys/bluetooth/host/smp.h index a6354419eeb..c6a3b6a5138 100644 --- a/subsys/bluetooth/host/smp.h +++ b/subsys/bluetooth/host/smp.h @@ -128,6 +128,7 @@ int bt_smp_send_security_req(struct bt_conn *conn); void bt_smp_update_keys(struct bt_conn *conn); bool bt_smp_get_tk(struct bt_conn *conn, u8_t *tk); bool bt_smp_keys_check(struct bt_conn *conn); +void bt_smp_keys_reject(struct bt_conn *conn); int bt_smp_br_send_pairing_req(struct bt_conn *conn);