Skip to contentSkip to conversation

Bluetooth: hci_event: Fix sending HCI_OP_READ_ENC_KEY_SIZE

PATCH Applied Luiz Augusto von Dentz 2 participants 2 messages Apr 15, 2024 – Apr 16, 2024

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: hci_event: Fix sending HCI_OP_READ_ENC_KEY_SIZE

From: Luiz Augusto von Dentz <[email protected]>

The code shall always check if HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE has been set before attempting to use HCI_OP_READ_ENC_KEY_SIZE.

Fixes c569242cd492 ("Bluetooth: hci_event: set the conn encrypted before conn establishes")
---
 include/net/bluetooth/hci_core.h | 4 ++++
 net/bluetooth/hci_event.c        | 5 ++---
 2 files changed, 6 insertions(+), 3 deletions(-)
include/net/bluetooth/hci_core.h +4 -0
index f0e1f1ae39c5..94bae125ac11 100644
@@ -1918,6 +1918,10 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 #define privacy_mode_capable(dev) (use_ll_privacy(dev) && \
 				   (hdev->commands[39] & 0x04))
 
+#define read_key_size_capable(dev) \
+	((dev)->commands[20] & 0x10 && \
+	 !test_bit(HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE, &hdev->quirks))
+
 /* Use enhanced synchronous connection if command is supported and its quirk
  * has not been set.
  */
net/bluetooth/hci_event.c +2 -3
index 539bbbe26176..9a38e155537e 100644
@@ -3217,7 +3217,7 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
 			if (key) {
 				set_bit(HCI_CONN_ENCRYPT, &conn->flags);
 
-				if (!(hdev->commands[20] & 0x10)) {
+				if (!read_key_size_capable(hdev)) {
 					conn->enc_key_size = HCI_LINK_KEY_SIZE;
 				} else {
 					cp.handle = cpu_to_le16(conn->handle);
@@ -3665,8 +3665,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
 		 * controller really supports it. If it doesn't, assume
 		 * the default size (16).
 		 */
-		if (!(hdev->commands[20] & 0x10) ||
-		    test_bit(HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE, &hdev->quirks)) {
+		if (!read_key_size_capable(hdev)) {
 			conn->enc_key_size = HCI_LINK_KEY_SIZE;
 			goto notify;
 		}
Signature · 1 line
2.44.0
#1 lore raw
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 9 lines · On Mon, 15 Apr 2024 13:43:38 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

The code shall always check if HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE has been set before attempting to use HCI_OP_READ_ENC_KEY_SIZE.

Fixes c569242cd492 ("Bluetooth: hci_event: set the conn encrypted before conn establishes")

[...]

Here is the summary with links:
- [v1] Bluetooth: hci_event: Fix sending HCI_OP_READ_ENC_KEY_SIZE

    https://git.kernel.org/bluetooth/bluetooth-next/c/54a3de664f08

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html