-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth: conn: move auto-init procedures to system workqueue #77703
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1660,9 +1660,133 @@ | |||||||||||||||||||||
|
||||||||||||||||||||||
/* Group Connected BT_CONN only in this */ | ||||||||||||||||||||||
#if defined(CONFIG_BT_CONN) | ||||||||||||||||||||||
/* We don't want the application to get a PHY update callback upon connection | ||||||||||||||||||||||
* establishment on 2M PHY. Therefore we must prevent issuing LE Set PHY | ||||||||||||||||||||||
* in this scenario. | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
static bool skip_auto_phy_update_on_conn_establishment(struct bt_conn *conn) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
#if defined(CONFIG_BT_USER_PHY_UPDATE) | ||||||||||||||||||||||
if (IS_ENABLED(CONFIG_BT_AUTO_PHY_UPDATE) && | ||||||||||||||||||||||
IS_ENABLED(CONFIG_BT_EXT_ADV) && | ||||||||||||||||||||||
BT_DEV_FEAT_LE_EXT_ADV(bt_dev.le.features)) { | ||||||||||||||||||||||
Check notice on line 1672 in subsys/bluetooth/host/conn.c GitHub Actions / Run compliance checks on patch series (PR)You may want to run clang-format on this change
|
||||||||||||||||||||||
if (conn->le.phy.tx_phy == BT_HCI_LE_PHY_2M && | ||||||||||||||||||||||
conn->le.phy.rx_phy == BT_HCI_LE_PHY_2M) { | ||||||||||||||||||||||
return true; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
#else | ||||||||||||||||||||||
ARG_UNUSED(conn); | ||||||||||||||||||||||
#endif /* defined(CONFIG_BT_USER_PHY_UPDATE) */ | ||||||||||||||||||||||
|
||||||||||||||||||||||
return false; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
static void perform_auto_initiated_procedures(struct bt_conn *conn, void *unused) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
int err; | ||||||||||||||||||||||
|
||||||||||||||||||||||
ARG_UNUSED(unused); | ||||||||||||||||||||||
|
||||||||||||||||||||||
LOG_DBG("[%p] Running auto-initiated procedures", conn); | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (conn->state != BT_CONN_CONNECTED) { | ||||||||||||||||||||||
/* It is possible that connection was disconnected directly from | ||||||||||||||||||||||
* connected callback so we must check state before doing | ||||||||||||||||||||||
* connection parameters update. | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
return; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (atomic_test_and_set_bit(conn->flags, BT_CONN_AUTO_INIT_PROCEDURES_DONE)) { | ||||||||||||||||||||||
/* We have already run the auto-initiated procedures */ | ||||||||||||||||||||||
return; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (!atomic_test_bit(conn->flags, BT_CONN_LE_FEATURES_EXCHANGED) && | ||||||||||||||||||||||
((conn->role == BT_HCI_ROLE_CENTRAL) || | ||||||||||||||||||||||
BT_FEAT_LE_PER_INIT_FEAT_XCHG(bt_dev.le.features))) { | ||||||||||||||||||||||
err = bt_hci_le_read_remote_features(conn); | ||||||||||||||||||||||
if (err) { | ||||||||||||||||||||||
LOG_ERR("Failed read remote features (%d)", err); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if (conn->state != BT_CONN_CONNECTED) { | ||||||||||||||||||||||
return; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (IS_ENABLED(CONFIG_BT_REMOTE_VERSION) && | ||||||||||||||||||||||
!atomic_test_bit(conn->flags, BT_CONN_AUTO_VERSION_INFO)) { | ||||||||||||||||||||||
err = bt_hci_read_remote_version(conn); | ||||||||||||||||||||||
if (err) { | ||||||||||||||||||||||
LOG_ERR("Failed read remote version (%d)", err); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if (conn->state != BT_CONN_CONNECTED) { | ||||||||||||||||||||||
return; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (IS_ENABLED(CONFIG_BT_AUTO_PHY_UPDATE) && | ||||||||||||||||||||||
BT_FEAT_LE_PHY_2M(bt_dev.le.features) && | ||||||||||||||||||||||
!skip_auto_phy_update_on_conn_establishment(conn)) { | ||||||||||||||||||||||
err = bt_le_set_phy(conn, 0U, BT_HCI_LE_PHY_PREFER_2M, | ||||||||||||||||||||||
BT_HCI_LE_PHY_PREFER_2M, | ||||||||||||||||||||||
BT_HCI_LE_PHY_CODED_ANY); | ||||||||||||||||||||||
Check notice on line 1734 in subsys/bluetooth/host/conn.c GitHub Actions / Run compliance checks on patch series (PR)You may want to run clang-format on this change
|
||||||||||||||||||||||
if (err) { | ||||||||||||||||||||||
LOG_ERR("Failed LE Set PHY (%d)", err); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if (conn->state != BT_CONN_CONNECTED) { | ||||||||||||||||||||||
return; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (IS_ENABLED(CONFIG_BT_AUTO_DATA_LEN_UPDATE) && | ||||||||||||||||||||||
BT_FEAT_LE_DLE(bt_dev.le.features)) { | ||||||||||||||||||||||
if (bt_drv_quirk_no_auto_dle()) { | ||||||||||||||||||||||
uint16_t tx_octets, tx_time; | ||||||||||||||||||||||
|
||||||||||||||||||||||
err = bt_hci_le_read_max_data_len(&tx_octets, &tx_time); | ||||||||||||||||||||||
if (!err) { | ||||||||||||||||||||||
err = bt_le_set_data_len(conn, | ||||||||||||||||||||||
tx_octets, tx_time); | ||||||||||||||||||||||
if (err) { | ||||||||||||||||||||||
Check notice on line 1752 in subsys/bluetooth/host/conn.c GitHub Actions / Run compliance checks on patch series (PR)You may want to run clang-format on this change
|
||||||||||||||||||||||
LOG_ERR("Failed to set data len (%d)", err); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
/* No need to auto-initiate DLE procedure. | ||||||||||||||||||||||
* It is done by the controller. | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
LOG_DBG("[%p] Successfully ran auto-initiated procedures", conn); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/* Executes procedures after a connection is established: | ||||||||||||||||||||||
* - read remote features | ||||||||||||||||||||||
* - read remote version | ||||||||||||||||||||||
* - update PHY | ||||||||||||||||||||||
* - update data length | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
static void auto_initiated_procedures(struct k_work *unused) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
ARG_UNUSED(unused); | ||||||||||||||||||||||
|
||||||||||||||||||||||
bt_conn_foreach(BT_CONN_TYPE_LE, perform_auto_initiated_procedures, NULL); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
static K_WORK_DEFINE(procedures_on_connect, auto_initiated_procedures); | ||||||||||||||||||||||
|
||||||||||||||||||||||
static void schedule_auto_initiated_procedures(struct bt_conn *conn) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
LOG_DBG("[%p] Scheduling auto-init procedures", conn); | ||||||||||||||||||||||
k_work_submit(&procedures_on_connect); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+1781
to
+1785
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should still have it. As it is the start of an async operation and the log in If you really don't want it, feel free to NAK and I'll remove. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a huge deal and it may be useful :) |
||||||||||||||||||||||
|
||||||||||||||||||||||
void bt_conn_connected(struct bt_conn *conn) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
schedule_auto_initiated_procedures(conn); | ||||||||||||||||||||||
bt_l2cap_connected(conn); | ||||||||||||||||||||||
notify_connected(conn); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No log message if
bt_hci_le_read_max_data_len
fails?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just copy-pasting stuff around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning to have this PR be a single cherry-pickable commit. And have another one for logs and cosmetic changes,
IS_ENABLED()
etc..