From ed187ebccd53a8a735d6befc1fcaffc8394b6fc2 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 19 May 2017 05:01:43 +0200 Subject: [PATCH] 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 --- subsys/bluetooth/host/conn_internal.h | 1 + subsys/bluetooth/host/hci_core.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index e679d42b9a0..a47052b8b90 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -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, diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 9297d88bf9e..85b9eff491d 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -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; } } @@ -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; } } @@ -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); }