Skip to content

Commit ed187eb

Browse files
cvinayakjhedberg
authored andcommitted
Bluetooth: Fix auto PHY update on connection
Since the PHY update complete event can be generated due to the procedure being initiated by the peer, use a flag to differentiate between local auto update initiated on connection complete versus peer initiated anytime in the connection. This is necessary to avoid repeated initiation of auto-update procedures intended only to be issued on connection complete. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent ce88189 commit ed187eb

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

subsys/bluetooth/host/conn_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum {
2424
BT_CONN_BR_NOBOND, /* SSP no bond pairing tracker */
2525
BT_CONN_BR_PAIRING_INITIATOR, /* local host starts authentication */
2626
BT_CONN_CLEANUP, /* Disconnected, pending cleanup */
27+
BT_CONN_AUTO_PHY_UPDATE, /* Auto-update PHY */
2728

2829
/* Total number of flags - must be at the end of the enum */
2930
BT_CONN_NUM_FLAGS,

subsys/bluetooth/host/hci_core.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,10 +802,10 @@ static void le_conn_complete(struct net_buf *buf)
802802
}
803803
}
804804

805-
if (BT_FEAT_LE_PHY_2M(bt_dev.le.features) ||
806-
BT_FEAT_LE_PHY_CODED(bt_dev.le.features)) {
805+
if (BT_FEAT_LE_PHY_2M(bt_dev.le.features)) {
807806
err = hci_le_set_phy(conn);
808807
if (!err) {
808+
atomic_set_bit(conn->flags, BT_CONN_AUTO_PHY_UPDATE);
809809
goto done;
810810
}
811811
}
@@ -834,12 +834,13 @@ static void le_remote_feat_complete(struct net_buf *buf)
834834
sizeof(conn->le.features));
835835
}
836836

837-
if (BT_FEAT_LE_PHY_2M(bt_dev.le.features) ||
838-
BT_FEAT_LE_PHY_CODED(bt_dev.le.features)) {
837+
if (BT_FEAT_LE_PHY_2M(bt_dev.le.features) &&
838+
BT_FEAT_LE_PHY_2M(conn->le.features)) {
839839
int err;
840840

841841
err = hci_le_set_phy(conn);
842842
if (!err) {
843+
atomic_set_bit(conn->flags, BT_CONN_AUTO_PHY_UPDATE);
843844
goto done;
844845
}
845846
}
@@ -864,8 +865,13 @@ static void le_phy_update_complete(struct net_buf *buf)
864865
BT_DBG("PHY updated: status: 0x%x, tx: %u, rx: %u",
865866
evt->status, evt->tx_phy, evt->rx_phy);
866867

868+
if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_AUTO_PHY_UPDATE)) {
869+
goto done;
870+
}
871+
867872
update_conn_param(conn);
868873

874+
done:
869875
bt_conn_unref(conn);
870876
}
871877

0 commit comments

Comments
 (0)