Skip to content

Commit a9a830a

Browse files
committed
Bluetooth: hci_event: Fix sending HCI_OP_READ_ENC_KEY_SIZE
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: c569242 ("Bluetooth: hci_event: set the conn encrypted before conn establishes") Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent b23d98d commit a9a830a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,10 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
19071907
#define privacy_mode_capable(dev) (use_ll_privacy(dev) && \
19081908
(hdev->commands[39] & 0x04))
19091909

1910+
#define read_key_size_capable(dev) \
1911+
((dev)->commands[20] & 0x10 && \
1912+
!test_bit(HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE, &hdev->quirks))
1913+
19101914
/* Use enhanced synchronous connection if command is supported and its quirk
19111915
* has not been set.
19121916
*/

net/bluetooth/hci_event.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,7 +3218,7 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
32183218
if (key) {
32193219
set_bit(HCI_CONN_ENCRYPT, &conn->flags);
32203220

3221-
if (!(hdev->commands[20] & 0x10)) {
3221+
if (!read_key_size_capable(hdev)) {
32223222
conn->enc_key_size = HCI_LINK_KEY_SIZE;
32233223
} else {
32243224
cp.handle = cpu_to_le16(conn->handle);
@@ -3666,8 +3666,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
36663666
* controller really supports it. If it doesn't, assume
36673667
* the default size (16).
36683668
*/
3669-
if (!(hdev->commands[20] & 0x10) ||
3670-
test_bit(HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE, &hdev->quirks)) {
3669+
if (!read_key_size_capable(hdev)) {
36713670
conn->enc_key_size = HCI_LINK_KEY_SIZE;
36723671
goto notify;
36733672
}

0 commit comments

Comments
 (0)