Skip to content

Commit 8e9fa6a

Browse files
liuX10cfriedt
authored andcommitted
bluetooth: remove blocking operation in bt_conn_get_info
bt_conn_get_info API is used to retrieve connection-related information. However, bt_conn_get_info sends the HCI command BT_HCI_OP_READ_ENCRYPTION_KEY_SIZE to retrieve current key_size, causing excessive blocking time. Signed-off-by: Xiang Liu <[email protected]>
1 parent b71d290 commit 8e9fa6a

File tree

4 files changed

+19
-31
lines changed

4 files changed

+19
-31
lines changed

subsys/bluetooth/host/classic/br.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ static bool br_sufficient_key_size(struct bt_conn *conn)
143143
key_size = rp->key_size;
144144
net_buf_unref(rsp);
145145

146+
if (conn->br.link_key) {
147+
conn->br.link_key->enc_key_size = key_size;
148+
}
149+
146150
LOG_DBG("Encryption key size is %u", key_size);
147151

148152
if (conn->sec_level == BT_SECURITY_L4) {

subsys/bluetooth/host/conn.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,35 +2493,11 @@ uint8_t bt_conn_enc_key_size(const struct bt_conn *conn)
24932493
return 0;
24942494
}
24952495

2496-
if (IS_ENABLED(CONFIG_BT_CLASSIC) &&
2497-
conn->type == BT_CONN_TYPE_BR) {
2498-
struct bt_hci_cp_read_encryption_key_size *cp;
2499-
struct bt_hci_rp_read_encryption_key_size *rp;
2500-
struct net_buf *buf;
2501-
struct net_buf *rsp;
2502-
uint8_t key_size;
2503-
2504-
buf = bt_hci_cmd_alloc(K_FOREVER);
2505-
if (!buf) {
2506-
return 0;
2507-
}
2508-
2509-
cp = net_buf_add(buf, sizeof(*cp));
2510-
cp->handle = sys_cpu_to_le16(conn->handle);
2511-
2512-
if (bt_hci_cmd_send_sync(BT_HCI_OP_READ_ENCRYPTION_KEY_SIZE,
2513-
buf, &rsp)) {
2514-
return 0;
2515-
}
2516-
2517-
rp = (void *)rsp->data;
2518-
2519-
key_size = rp->status ? 0 : rp->key_size;
2520-
2521-
net_buf_unref(rsp);
2522-
2523-
return key_size;
2496+
#if defined(CONFIG_BT_CLASSIC)
2497+
if (conn->type == BT_CONN_TYPE_BR) {
2498+
return conn->br.link_key ? conn->br.link_key->enc_key_size : 0;
25242499
}
2500+
#endif /* CONFIG_BT_CLASSIC */
25252501

25262502
if (IS_ENABLED(CONFIG_BT_SMP)) {
25272503
return conn->le.keys ? conn->le.keys->enc_size : 0;

subsys/bluetooth/host/hci_core.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,9 +1077,16 @@ static void hci_disconn_complete(struct net_buf *buf)
10771077
* If only for one connection session bond was set, clear keys
10781078
* database row for this connection.
10791079
*/
1080-
if (conn->type == BT_CONN_TYPE_BR && conn->br.link_key != NULL &&
1081-
atomic_test_and_clear_bit(conn->flags, BT_CONN_BR_NOBOND)) {
1082-
bt_keys_link_key_clear(conn->br.link_key);
1080+
if (conn->type == BT_CONN_TYPE_BR && conn->br.link_key != NULL) {
1081+
/*
1082+
* If the connection link is paired but not bond, remove
1083+
* the link key upon disconnection.
1084+
*/
1085+
if (atomic_test_and_clear_bit(conn->flags, BT_CONN_BR_NOBOND)) {
1086+
bt_keys_link_key_clear(conn->br.link_key);
1087+
}
1088+
1089+
conn->br.link_key->enc_key_size = 0;
10831090
}
10841091
#endif
10851092
bt_conn_unref(conn);

subsys/bluetooth/host/keys.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ enum {
217217

218218
struct bt_keys_link_key {
219219
bt_addr_t addr;
220+
uint8_t enc_key_size;
220221
uint8_t storage_start[0] __aligned(sizeof(void *));
221222
uint8_t flags;
222223
uint8_t val[16];

0 commit comments

Comments
 (0)