Skip to content

Commit

Permalink
Bluetooth: Fix auto PHY update on connection
Browse files Browse the repository at this point in the history
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 <vich@nordicsemi.no>
  • Loading branch information
cvinayak authored and jhedberg committed May 19, 2017
1 parent ce88189 commit ed187eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions subsys/bluetooth/host/conn_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum {
BT_CONN_BR_NOBOND, /* SSP no bond pairing tracker */
BT_CONN_BR_PAIRING_INITIATOR, /* local host starts authentication */
BT_CONN_CLEANUP, /* Disconnected, pending cleanup */
BT_CONN_AUTO_PHY_UPDATE, /* Auto-update PHY */

/* Total number of flags - must be at the end of the enum */
BT_CONN_NUM_FLAGS,
Expand Down
14 changes: 10 additions & 4 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,10 @@ static void le_conn_complete(struct net_buf *buf)
}
}

if (BT_FEAT_LE_PHY_2M(bt_dev.le.features) ||
BT_FEAT_LE_PHY_CODED(bt_dev.le.features)) {
if (BT_FEAT_LE_PHY_2M(bt_dev.le.features)) {
err = hci_le_set_phy(conn);
if (!err) {
atomic_set_bit(conn->flags, BT_CONN_AUTO_PHY_UPDATE);
goto done;
}
}
Expand Down Expand Up @@ -834,12 +834,13 @@ static void le_remote_feat_complete(struct net_buf *buf)
sizeof(conn->le.features));
}

if (BT_FEAT_LE_PHY_2M(bt_dev.le.features) ||
BT_FEAT_LE_PHY_CODED(bt_dev.le.features)) {
if (BT_FEAT_LE_PHY_2M(bt_dev.le.features) &&
BT_FEAT_LE_PHY_2M(conn->le.features)) {
int err;

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

if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_AUTO_PHY_UPDATE)) {
goto done;
}

update_conn_param(conn);

done:
bt_conn_unref(conn);
}

Expand Down

0 comments on commit ed187eb

Please sign in to comment.