Skip to content

Commit 585c1f9

Browse files
jori-nordicnashif
authored andcommitted
Bluetooth: Host: Refactor auto feature exchange
Add a bool fn so there is some room for a comment explaining why this is not guarded by an IS_ENABLED(). Also add an optimization when building with an onboard controller. Signed-off-by: Jonathan Rico <[email protected]>
1 parent 3f17bdf commit 585c1f9

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,30 @@ static bool uses_symmetric_2mbit_phy(struct bt_conn *conn)
16831683
return false;
16841684
}
16851685

1686+
static bool can_initiate_feature_exchange(struct bt_conn *conn)
1687+
{
1688+
/* Spec says both central and peripheral can send the command. However,
1689+
* peripheral-initiated feature exchange is an optional feature.
1690+
*
1691+
* We provide an optimization if we are in the same image as the
1692+
* controller, as we know at compile time whether it supports or not
1693+
* peripheral feature exchange.
1694+
*/
1695+
bool onboard_controller = IS_ENABLED(CONFIG_BT_CTLR);
1696+
bool supports_peripheral_feature_exchange = IS_ENABLED(CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG);
1697+
bool is_central = IS_ENABLED(CONFIG_BT_CENTRAL) && conn->role == BT_HCI_ROLE_CENTRAL;
1698+
1699+
if (is_central) {
1700+
return true;
1701+
}
1702+
1703+
if (onboard_controller && supports_peripheral_feature_exchange) {
1704+
return true;
1705+
}
1706+
1707+
return BT_FEAT_LE_PER_INIT_FEAT_XCHG(bt_dev.le.features);
1708+
}
1709+
16861710
static void perform_auto_initiated_procedures(struct bt_conn *conn, void *unused)
16871711
{
16881712
int err;
@@ -1705,8 +1729,7 @@ static void perform_auto_initiated_procedures(struct bt_conn *conn, void *unused
17051729
}
17061730

17071731
if (!atomic_test_bit(conn->flags, BT_CONN_LE_FEATURES_EXCHANGED) &&
1708-
((conn->role == BT_HCI_ROLE_CENTRAL) ||
1709-
BT_FEAT_LE_PER_INIT_FEAT_XCHG(bt_dev.le.features))) {
1732+
can_initiate_feature_exchange(conn)) {
17101733
err = bt_hci_le_read_remote_features(conn);
17111734
if (err) {
17121735
LOG_ERR("Failed read remote features (%d)", err);

0 commit comments

Comments
 (0)