Skip to content

Commit 2e7ed5f

Browse files
committed
Bluetooth: hci_sync: Use advertised PHYs on hci_le_ext_create_conn_sync
The extended advertising reports do report the PHYs so this store then in hci_conn so it can be later used in hci_le_ext_create_conn_sync to narrow the PHYs to be scanned since the controller will also perform a scan having a smaller set of PHYs shall reduce the time it takes to find and connect peers. Fixes: 288c902 ("Bluetooth: Enable all supported LE PHY by default") Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 9bf4e91 commit 2e7ed5f

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ struct hci_conn {
738738
__u8 le_per_adv_data[HCI_MAX_PER_AD_TOT_LEN];
739739
__u16 le_per_adv_data_len;
740740
__u16 le_per_adv_data_offset;
741+
__u8 le_adv_phy;
742+
__u8 le_adv_sec_phy;
741743
__u8 le_tx_phy;
742744
__u8 le_rx_phy;
743745
__s8 rssi;
@@ -1512,7 +1514,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
15121514
enum conn_reasons conn_reason);
15131515
struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
15141516
u8 dst_type, bool dst_resolved, u8 sec_level,
1515-
u16 conn_timeout, u8 role);
1517+
u16 conn_timeout, u8 role, u8 phy, u8 sec_phy);
15161518
void hci_connect_le_scan_cleanup(struct hci_conn *conn, u8 status);
15171519
struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
15181520
u8 sec_level, u8 auth_type,

net/bluetooth/hci_conn.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle)
12631263

12641264
struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
12651265
u8 dst_type, bool dst_resolved, u8 sec_level,
1266-
u16 conn_timeout, u8 role)
1266+
u16 conn_timeout, u8 role, u8 phy, u8 sec_phy)
12671267
{
12681268
struct hci_conn *conn;
12691269
struct smp_irk *irk;
@@ -1326,6 +1326,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
13261326
conn->dst_type = dst_type;
13271327
conn->sec_level = BT_SECURITY_LOW;
13281328
conn->conn_timeout = conn_timeout;
1329+
conn->le_adv_phy = phy;
1330+
conn->le_adv_sec_phy = sec_phy;
13291331

13301332
err = hci_connect_le_sync(hdev, conn);
13311333
if (err) {
@@ -2273,7 +2275,7 @@ struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
22732275
le = hci_connect_le(hdev, dst, dst_type, false,
22742276
BT_SECURITY_LOW,
22752277
HCI_LE_CONN_TIMEOUT,
2276-
HCI_ROLE_SLAVE);
2278+
HCI_ROLE_SLAVE, 0, 0);
22772279
else
22782280
le = hci_connect_le_scan(hdev, dst, dst_type,
22792281
BT_SECURITY_LOW,

net/bluetooth/hci_event.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6038,7 +6038,7 @@ static void hci_le_conn_update_complete_evt(struct hci_dev *hdev, void *data,
60386038
static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
60396039
bdaddr_t *addr,
60406040
u8 addr_type, bool addr_resolved,
6041-
u8 adv_type)
6041+
u8 adv_type, u8 phy, u8 sec_phy)
60426042
{
60436043
struct hci_conn *conn;
60446044
struct hci_conn_params *params;
@@ -6093,7 +6093,7 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
60936093

60946094
conn = hci_connect_le(hdev, addr, addr_type, addr_resolved,
60956095
BT_SECURITY_LOW, hdev->def_le_autoconnect_timeout,
6096-
HCI_ROLE_MASTER);
6096+
HCI_ROLE_MASTER, phy, sec_phy);
60976097
if (!IS_ERR(conn)) {
60986098
/* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned
60996099
* by higher layer that tried to connect, if no then
@@ -6128,8 +6128,9 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
61286128

61296129
static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
61306130
u8 bdaddr_type, bdaddr_t *direct_addr,
6131-
u8 direct_addr_type, s8 rssi, u8 *data, u8 len,
6132-
bool ext_adv, bool ctl_time, u64 instant)
6131+
u8 direct_addr_type, u8 phy, u8 sec_phy, s8 rssi,
6132+
u8 *data, u8 len, bool ext_adv, bool ctl_time,
6133+
u64 instant)
61336134
{
61346135
struct discovery_state *d = &hdev->discovery;
61356136
struct smp_irk *irk;
@@ -6217,7 +6218,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
62176218
* for advertising reports) and is already verified to be RPA above.
62186219
*/
62196220
conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, bdaddr_resolved,
6220-
type);
6221+
type, phy, sec_phy);
62216222
if (!ext_adv && conn && type == LE_ADV_IND &&
62226223
len <= max_adv_len(hdev)) {
62236224
/* Store report for later inclusion by
@@ -6363,7 +6364,8 @@ static void hci_le_adv_report_evt(struct hci_dev *hdev, void *data,
63636364
if (info->length <= max_adv_len(hdev)) {
63646365
rssi = info->data[info->length];
63656366
process_adv_report(hdev, info->type, &info->bdaddr,
6366-
info->bdaddr_type, NULL, 0, rssi,
6367+
info->bdaddr_type, NULL, 0,
6368+
HCI_ADV_PHY_1M, 0, rssi,
63676369
info->data, info->length, false,
63686370
false, instant);
63696371
} else {
@@ -6448,6 +6450,8 @@ static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, void *data,
64486450
if (legacy_evt_type != LE_ADV_INVALID) {
64496451
process_adv_report(hdev, legacy_evt_type, &info->bdaddr,
64506452
info->bdaddr_type, NULL, 0,
6453+
info->primary_phy,
6454+
info->secondary_phy,
64516455
info->rssi, info->data, info->length,
64526456
!(evt_type & LE_EXT_ADV_LEGACY_PDU),
64536457
false, instant);
@@ -6730,8 +6734,8 @@ static void hci_le_direct_adv_report_evt(struct hci_dev *hdev, void *data,
67306734

67316735
process_adv_report(hdev, info->type, &info->bdaddr,
67326736
info->bdaddr_type, &info->direct_addr,
6733-
info->direct_addr_type, info->rssi, NULL, 0,
6734-
false, false, instant);
6737+
info->direct_addr_type, HCI_ADV_PHY_1M, 0,
6738+
info->rssi, NULL, 0, false, false, instant);
67356739
}
67366740

67376741
hci_dev_unlock(hdev);

net/bluetooth/hci_sync.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6346,23 +6346,26 @@ static int hci_le_ext_create_conn_sync(struct hci_dev *hdev,
63466346

63476347
plen = sizeof(*cp);
63486348

6349-
if (scan_1m(hdev)) {
6349+
if (scan_1m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_1M ||
6350+
conn->le_adv_sec_phy == HCI_ADV_PHY_1M)) {
63506351
cp->phys |= LE_SCAN_PHY_1M;
63516352
set_ext_conn_params(conn, p);
63526353

63536354
p++;
63546355
plen += sizeof(*p);
63556356
}
63566357

6357-
if (scan_2m(hdev)) {
6358+
if (scan_2m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_2M ||
6359+
conn->le_adv_sec_phy == HCI_ADV_PHY_2M)) {
63586360
cp->phys |= LE_SCAN_PHY_2M;
63596361
set_ext_conn_params(conn, p);
63606362

63616363
p++;
63626364
plen += sizeof(*p);
63636365
}
63646366

6365-
if (scan_coded(hdev)) {
6367+
if (scan_coded(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_CODED ||
6368+
conn->le_adv_sec_phy == HCI_ADV_PHY_CODED)) {
63666369
cp->phys |= LE_SCAN_PHY_CODED;
63676370
set_ext_conn_params(conn, p);
63686371

net/bluetooth/l2cap_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7018,7 +7018,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
70187018
if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
70197019
hcon = hci_connect_le(hdev, dst, dst_type, false,
70207020
chan->sec_level, timeout,
7021-
HCI_ROLE_SLAVE);
7021+
HCI_ROLE_SLAVE, 0, 0);
70227022
else
70237023
hcon = hci_connect_le_scan(hdev, dst, dst_type,
70247024
chan->sec_level, timeout,

0 commit comments

Comments
 (0)