Skip to content

Commit 60a7bae

Browse files
liuX10weeTike
authored andcommitted
[nrf fromtree] 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]> (cherry picked from commit 8e9fa6a)
1 parent a710f43 commit 60a7bae

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
@@ -2507,35 +2507,11 @@ uint8_t bt_conn_enc_key_size(const struct bt_conn *conn)
25072507
return 0;
25082508
}
25092509

2510-
if (IS_ENABLED(CONFIG_BT_CLASSIC) &&
2511-
conn->type == BT_CONN_TYPE_BR) {
2512-
struct bt_hci_cp_read_encryption_key_size *cp;
2513-
struct bt_hci_rp_read_encryption_key_size *rp;
2514-
struct net_buf *buf;
2515-
struct net_buf *rsp;
2516-
uint8_t key_size;
2517-
2518-
buf = bt_hci_cmd_alloc(K_FOREVER);
2519-
if (!buf) {
2520-
return 0;
2521-
}
2522-
2523-
cp = net_buf_add(buf, sizeof(*cp));
2524-
cp->handle = sys_cpu_to_le16(conn->handle);
2525-
2526-
if (bt_hci_cmd_send_sync(BT_HCI_OP_READ_ENCRYPTION_KEY_SIZE,
2527-
buf, &rsp)) {
2528-
return 0;
2529-
}
2530-
2531-
rp = (void *)rsp->data;
2532-
2533-
key_size = rp->status ? 0 : rp->key_size;
2534-
2535-
net_buf_unref(rsp);
2536-
2537-
return key_size;
2510+
#if defined(CONFIG_BT_CLASSIC)
2511+
if (conn->type == BT_CONN_TYPE_BR) {
2512+
return conn->br.link_key ? conn->br.link_key->enc_key_size : 0;
25382513
}
2514+
#endif /* CONFIG_BT_CLASSIC */
25392515

25402516
if (IS_ENABLED(CONFIG_BT_SMP)) {
25412517
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
@@ -223,6 +223,7 @@ enum {
223223

224224
struct bt_keys_link_key {
225225
bt_addr_t addr;
226+
uint8_t enc_key_size;
226227
uint8_t storage_start[0] __aligned(sizeof(void *));
227228
uint8_t flags;
228229
uint8_t val[16];

0 commit comments

Comments
 (0)