Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions subsys/bluetooth/host/classic/br.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ static bool br_sufficient_key_size(struct bt_conn *conn)
key_size = rp->key_size;
net_buf_unref(rsp);

if (conn->br.link_key) {
conn->br.link_key->enc_key_size = key_size;
}

LOG_DBG("Encryption key size is %u", key_size);

if (conn->sec_level == BT_SECURITY_L4) {
Expand Down
32 changes: 4 additions & 28 deletions subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2493,35 +2493,11 @@ uint8_t bt_conn_enc_key_size(const struct bt_conn *conn)
return 0;
}

if (IS_ENABLED(CONFIG_BT_CLASSIC) &&
conn->type == BT_CONN_TYPE_BR) {
struct bt_hci_cp_read_encryption_key_size *cp;
struct bt_hci_rp_read_encryption_key_size *rp;
struct net_buf *buf;
struct net_buf *rsp;
uint8_t key_size;

buf = bt_hci_cmd_alloc(K_FOREVER);
if (!buf) {
return 0;
}

cp = net_buf_add(buf, sizeof(*cp));
cp->handle = sys_cpu_to_le16(conn->handle);

if (bt_hci_cmd_send_sync(BT_HCI_OP_READ_ENCRYPTION_KEY_SIZE,
buf, &rsp)) {
return 0;
}

rp = (void *)rsp->data;

key_size = rp->status ? 0 : rp->key_size;

net_buf_unref(rsp);

return key_size;
#if defined(CONFIG_BT_CLASSIC)
if (conn->type == BT_CONN_TYPE_BR) {
return conn->br.link_key ? conn->br.link_key->enc_key_size : 0;
}
#endif /* CONFIG_BT_CLASSIC */

if (IS_ENABLED(CONFIG_BT_SMP)) {
return conn->le.keys ? conn->le.keys->enc_size : 0;
Expand Down
13 changes: 10 additions & 3 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,16 @@ static void hci_disconn_complete(struct net_buf *buf)
* If only for one connection session bond was set, clear keys
* database row for this connection.
*/
if (conn->type == BT_CONN_TYPE_BR && conn->br.link_key != NULL &&
atomic_test_and_clear_bit(conn->flags, BT_CONN_BR_NOBOND)) {
bt_keys_link_key_clear(conn->br.link_key);
if (conn->type == BT_CONN_TYPE_BR && conn->br.link_key != NULL) {
/*
* If the connection link is paired but not bond, remove
* the link key upon disconnection.
*/
if (atomic_test_and_clear_bit(conn->flags, BT_CONN_BR_NOBOND)) {
bt_keys_link_key_clear(conn->br.link_key);
}

conn->br.link_key->enc_key_size = 0;
}
#endif
bt_conn_unref(conn);
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/host/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ enum {

struct bt_keys_link_key {
bt_addr_t addr;
uint8_t enc_key_size;
uint8_t storage_start[0] __aligned(sizeof(void *));
uint8_t flags;
uint8_t val[16];
Expand Down