From f1c737149402fcf201d58b6602bbc10828f2357d Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 16 Aug 2019 14:33:01 +0200 Subject: [PATCH] Bluetooth: SMP: Stop new pairing early if MAX_PAIR has been reached Stop the pairing procedure in the request phase if no storage is available for the keys. This avoids the pairing procedure from failing during the key distribution phase. Signed-off-by: Joakim Andersson --- include/bluetooth/conn.h | 2 +- subsys/bluetooth/host/smp.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/bluetooth/conn.h b/include/bluetooth/conn.h index b9ba626c21a..1ab90c3a0f3 100644 --- a/include/bluetooth/conn.h +++ b/include/bluetooth/conn.h @@ -303,7 +303,7 @@ typedef enum __packed { * * This function may return error if required level of security is not possible * to achieve due to local or remote device limitation (e.g., input output - * capabilities). + * capabilities), or if the maximum number of paired devices has been reached. * * @param conn Connection object. * @param sec Requested security level. diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index b9601dacea5..baee012e4f6 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -2422,6 +2422,13 @@ int bt_smp_send_security_req(struct bt_conn *conn) return -EINVAL; } + if (!conn->le.keys) { + conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst); + if (!conn->le.keys) { + return -ENOMEM; + } + } + if (smp_init(smp) != 0) { return -ENOBUFS; } @@ -2457,6 +2464,13 @@ static u8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf) return BT_SMP_ERR_ENC_KEY_SIZE; } + if (!conn->le.keys) { + conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst); + if (!conn->le.keys) { + return BT_SMP_ERR_UNSPECIFIED; + } + } + /* If we already sent a security request then the SMP context * is already initialized. */ @@ -2601,6 +2615,13 @@ int bt_smp_send_pairing_req(struct bt_conn *conn) return -EINVAL; } + if (!conn->le.keys) { + conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst); + if (!conn->le.keys) { + return -ENOMEM; + } + } + if (smp_init(smp)) { return -ENOBUFS; }