diff --git a/include/bluetooth/conn.h b/include/bluetooth/conn.h index b9ba626c21a779..1ab90c3a0f3f08 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 b9601dacea552f..baee012e4f6c81 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; }