From cbec9ffbc0cae1ea8030381a25dd3bee0ab3b77a Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 22 Jun 2021 16:56:37 +0200 Subject: [PATCH] Bluetooth: conn: Move ACL callback handlers to ACL group Move the notify_le_phy_updated, notify_le_data_len_updated, notify_le_param_updated, notify_remote_info, notify_disconnected and notify_connected functions to the ACL group. Signed-off-by: Emil Gydesen --- subsys/bluetooth/host/conn.c | 195 ++++++++++++++++++----------------- 1 file changed, 98 insertions(+), 97 deletions(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 9a9fb3dc1a4..24669f954eb 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -84,6 +84,7 @@ static struct bt_conn sco_conns[CONFIG_BT_MAX_SCO_CONN]; #if defined(CONFIG_BT_CONN) static void deferred_work(struct k_work *work); static void tx_complete_work(struct k_work *work); +static void notify_connected(struct bt_conn *conn); #endif /* CONFIG_BT_CONN */ struct k_sem *bt_conn_get_pkts(struct bt_conn *conn) @@ -129,103 +130,6 @@ static inline const char *state2str(bt_conn_state_t state) } } -static void notify_connected(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->connected) { - cb->connected(conn, conn->err); - } - } - - if (!conn->err) { - bt_gatt_connected(conn); - } -} - -static void notify_disconnected(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->disconnected) { - cb->disconnected(conn, conn->err); - } - } -} - -#if defined(CONFIG_BT_REMOTE_INFO) -void notify_remote_info(struct bt_conn *conn) -{ - struct bt_conn_remote_info remote_info; - struct bt_conn_cb *cb; - int err; - - err = bt_conn_get_remote_info(conn, &remote_info); - if (err) { - BT_DBG("Notify remote info failed %d", err); - return; - } - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->remote_info_available) { - cb->remote_info_available(conn, &remote_info); - } - } -} -#endif /* defined(CONFIG_BT_REMOTE_INFO) */ - -void notify_le_param_updated(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - /* If new connection parameters meet requirement of pending - * parameters don't send slave conn param request anymore on timeout - */ - if (atomic_test_bit(conn->flags, BT_CONN_SLAVE_PARAM_SET) && - conn->le.interval >= conn->le.interval_min && - conn->le.interval <= conn->le.interval_max && - conn->le.latency == conn->le.pending_latency && - conn->le.timeout == conn->le.pending_timeout) { - atomic_clear_bit(conn->flags, BT_CONN_SLAVE_PARAM_SET); - } - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->le_param_updated) { - cb->le_param_updated(conn, conn->le.interval, - conn->le.latency, - conn->le.timeout); - } - } -} - -#if defined(CONFIG_BT_USER_DATA_LEN_UPDATE) -void notify_le_data_len_updated(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->le_data_len_updated) { - cb->le_data_len_updated(conn, &conn->le.data_len); - } - } -} -#endif - -#if defined(CONFIG_BT_USER_PHY_UPDATE) -void notify_le_phy_updated(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->le_phy_updated) { - cb->le_phy_updated(conn, &conn->le.phy); - } - } -} -#endif - static void tx_free(struct bt_conn_tx *tx) { tx->cb = NULL; @@ -1249,6 +1153,103 @@ uint8_t bt_conn_index(struct bt_conn *conn) /* Group Connected BT_CONN only in this */ #if defined(CONFIG_BT_CONN) +static void notify_connected(struct bt_conn *conn) +{ + struct bt_conn_cb *cb; + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->connected) { + cb->connected(conn, conn->err); + } + } + + if (!conn->err) { + bt_gatt_connected(conn); + } +} + +static void notify_disconnected(struct bt_conn *conn) +{ + struct bt_conn_cb *cb; + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->disconnected) { + cb->disconnected(conn, conn->err); + } + } +} + +#if defined(CONFIG_BT_REMOTE_INFO) +void notify_remote_info(struct bt_conn *conn) +{ + struct bt_conn_remote_info remote_info; + struct bt_conn_cb *cb; + int err; + + err = bt_conn_get_remote_info(conn, &remote_info); + if (err) { + BT_DBG("Notify remote info failed %d", err); + return; + } + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->remote_info_available) { + cb->remote_info_available(conn, &remote_info); + } + } +} +#endif /* defined(CONFIG_BT_REMOTE_INFO) */ + +void notify_le_param_updated(struct bt_conn *conn) +{ + struct bt_conn_cb *cb; + + /* If new connection parameters meet requirement of pending + * parameters don't send slave conn param request anymore on timeout + */ + if (atomic_test_bit(conn->flags, BT_CONN_SLAVE_PARAM_SET) && + conn->le.interval >= conn->le.interval_min && + conn->le.interval <= conn->le.interval_max && + conn->le.latency == conn->le.pending_latency && + conn->le.timeout == conn->le.pending_timeout) { + atomic_clear_bit(conn->flags, BT_CONN_SLAVE_PARAM_SET); + } + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->le_param_updated) { + cb->le_param_updated(conn, conn->le.interval, + conn->le.latency, + conn->le.timeout); + } + } +} + +#if defined(CONFIG_BT_USER_DATA_LEN_UPDATE) +void notify_le_data_len_updated(struct bt_conn *conn) +{ + struct bt_conn_cb *cb; + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->le_data_len_updated) { + cb->le_data_len_updated(conn, &conn->le.data_len); + } + } +} +#endif + +#if defined(CONFIG_BT_USER_PHY_UPDATE) +void notify_le_phy_updated(struct bt_conn *conn) +{ + struct bt_conn_cb *cb; + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->le_phy_updated) { + cb->le_phy_updated(conn, &conn->le.phy); + } + } +} +#endif + bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) { struct bt_conn_cb *cb;