Skip to content

Commit eeda1bf

Browse files
committed
Bluetooth: hci_event: Fix not indicating new connection for BIG Sync
BIG Sync (aka. Broadcast sink) requires to inform that the device is connected when a data path is active otherwise userspace could attempt to free resources allocated to the device object while scanning. Fixes: 1d11d70 ("Bluetooth: ISO: Pass BIG encryption info through QoS") Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent e7b0229 commit eeda1bf

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

net/bluetooth/hci_event.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,9 +2524,7 @@ static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
25242524
* Only those in BT_CONFIG or BT_CONNECTED states can be
25252525
* considered connected.
25262526
*/
2527-
if (conn &&
2528-
(conn->state == BT_CONFIG || conn->state == BT_CONNECTED) &&
2529-
!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
2527+
if (conn && (conn->state == BT_CONFIG || conn->state == BT_CONNECTED))
25302528
mgmt_device_connected(hdev, conn, name, name_len);
25312529

25322530
if (discov->state == DISCOVERY_STOPPED)
@@ -3758,8 +3756,9 @@ static void hci_remote_features_evt(struct hci_dev *hdev, void *data,
37583756
bacpy(&cp.bdaddr, &conn->dst);
37593757
cp.pscan_rep_mode = 0x02;
37603758
hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
3761-
} else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
3759+
} else {
37623760
mgmt_device_connected(hdev, conn, NULL, 0);
3761+
}
37633762

37643763
if (!hci_outgoing_auth_needed(hdev, conn)) {
37653764
conn->state = BT_CONNECTED;
@@ -3932,6 +3931,11 @@ static u8 hci_cc_le_setup_iso_path(struct hci_dev *hdev, void *data,
39323931
* last.
39333932
*/
39343933
hci_connect_cfm(conn, rp->status);
3934+
3935+
/* Notify device connected in case it is a BIG Sync */
3936+
if (!rp->status && test_bit(HCI_CONN_BIG_SYNC, &conn->flags))
3937+
mgmt_device_connected(hdev, conn, NULL, 0);
3938+
39353939
break;
39363940
}
39373941

@@ -5006,8 +5010,9 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev, void *data,
50065010
bacpy(&cp.bdaddr, &conn->dst);
50075011
cp.pscan_rep_mode = 0x02;
50085012
hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
5009-
} else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
5013+
} else {
50105014
mgmt_device_connected(hdev, conn, NULL, 0);
5015+
}
50115016

50125017
if (!hci_outgoing_auth_needed(hdev, conn)) {
50135018
conn->state = BT_CONNECTED;
@@ -5980,8 +5985,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
59805985
goto unlock;
59815986
}
59825987

5983-
if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
5984-
mgmt_device_connected(hdev, conn, NULL, 0);
5988+
mgmt_device_connected(hdev, conn, NULL, 0);
59855989

59865990
conn->sec_level = BT_SECURITY_LOW;
59875991
conn->state = BT_CONFIG;
@@ -7210,6 +7214,9 @@ static void hci_le_big_info_adv_report_evt(struct hci_dev *hdev, void *data,
72107214
/* Notify iso layer */
72117215
hci_connect_cfm(pa_sync, 0x00);
72127216

7217+
/* Notify MGMT layer */
7218+
mgmt_device_connected(hdev, pa_sync, NULL, 0);
7219+
72137220
unlock:
72147221
hci_dev_unlock(hdev);
72157222
}

net/bluetooth/mgmt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,6 +3126,7 @@ static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data,
31263126
static u8 link_to_bdaddr(u8 link_type, u8 addr_type)
31273127
{
31283128
switch (link_type) {
3129+
case ISO_LINK:
31293130
case LE_LINK:
31303131
switch (addr_type) {
31313132
case ADDR_LE_DEV_PUBLIC:
@@ -9618,6 +9619,9 @@ void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
96189619
u16 eir_len = 0;
96199620
u32 flags = 0;
96209621

9622+
if (test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
9623+
return;
9624+
96219625
/* allocate buff for LE or BR/EDR adv */
96229626
if (conn->le_adv_data_len > 0)
96239627
skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED,

0 commit comments

Comments
 (0)