From 787e2afcf45860050b56c39eef4d5d15d1734a7f Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Mon, 4 Sep 2023 13:56:17 +0200 Subject: [PATCH] caf: ble_state: Remove TX power update using HCI command on connected Change removes the TX power update using a Bluetooth HCI command performed for SoftDevice Bluetooth LE Link Layer right after connection establishment. The Bluetooth controller's Kconfig option can be used to set the TX power used for both advertising and connections also for the SoftDevice Link Layer. Jira: NCSDK-20804 Signed-off-by: Marek Pieta Signed-off-by: Pekka Niskanen --- doc/nrf/libraries/caf/ble_state.rst | 8 +-- .../releases/release-notes-changelog.rst | 5 ++ subsys/caf/modules/Kconfig.ble_state | 29 ++-------- subsys/caf/modules/ble_state.c | 54 ------------------- 4 files changed, 11 insertions(+), 85 deletions(-) diff --git a/doc/nrf/libraries/caf/ble_state.rst b/doc/nrf/libraries/caf/ble_state.rst index 61a9c72f0982..ab8b5153a696 100644 --- a/doc/nrf/libraries/caf/ble_state.rst +++ b/doc/nrf/libraries/caf/ble_state.rst @@ -85,11 +85,7 @@ The |ble_state| keeps references to :c:struct:`bt_conn` objects to ensure that t When a new connection is established, the module calls :c:func:`bt_conn_ref` to increase the object reference counter. After :c:struct:`ble_peer_event` about disconnection or connection failure is received by all other application modules, the |ble_state| decrements the :c:struct:`bt_conn` object by using :c:func:`bt_conn_unref`. -Behavior with SoftDevice Link Layer -=================================== +Low Latency Packet Mode +======================= If Nordic Semiconductor's SoftDevice Bluetooth LE Link Layer is selected (:kconfig:option:`CONFIG_BT_LL_SOFTDEVICE`) and the :kconfig:option:`CONFIG_CAF_BLE_USE_LLPM` option is enabled, the |ble_state| sends a Bluetooth HCI command to enable the LLPM when Bluetooth is ready. - -If the SoftDevice Link Layer is selected, the |ble_state| also sets the TX power for connections. -The TX power is set according to Zephyr's Kconfig options related to selecting the default TX power. -This is necessary because the mentioned Kconfig options are not automatically applied by the Bluetooth stack if the SoftDevice Link Layer is selected. diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 6e285aa8a3cf..cfba162c1f29 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -794,6 +794,11 @@ Common Application Framework (CAF) * The library by improving broadcast of :c:struct:`module_state_event`. The event informing about entering either :c:enum:`MODULE_STATE_READY` or :c:enum:`MODULE_STATE_OFF` is not submitted until the CAF Bluetooth LE advertising module is initialized and ready. +* :ref:`caf_ble_state`: + + * Removed TX power update using a Bluetooth HCI command for SoftDevice Bluetooth LE Link Layer (:kconfig:option:`CONFIG_BT_LL_SOFTDEVICE`) right after a connection has been established. + The :kconfig:option:`CONFIG_BT_CTLR_TX_PWR` Kconfig option can be used to set the TX power for advertising and connections also for the SoftDevice Link Layer. + * :ref:`caf_power_manager`: * Reduced verbosity of logs denoting allowed power states from ``info`` to ``debug``. diff --git a/subsys/caf/modules/Kconfig.ble_state b/subsys/caf/modules/Kconfig.ble_state index f0f586402bd1..983611bf8870 100644 --- a/subsys/caf/modules/Kconfig.ble_state +++ b/subsys/caf/modules/Kconfig.ble_state @@ -8,12 +8,12 @@ menuconfig CAF_BLE_STATE bool "Bluetooth LE state module" depends on BT depends on BT_SMP - select BT_CTLR_TX_PWR_DYNAMIC_CONTROL if BT_LL_SOFTDEVICE select CAF_BLE_COMMON_EVENTS help - Module that enables Bluetooth, handles Zephyr's connection callbacks, propagates - information about the connection state and parameters by using Application Event Manager events - and exchanges GATT MTU on GATT Client. + Module that enables Bluetooth, handles Zephyr's connection callbacks, + propagates information about the connection state and parameters by + using Application Event Manager events and exchanges GATT MTU on GATT + Client. if CAF_BLE_STATE @@ -67,27 +67,6 @@ config CAF_BLE_USE_LLPM the possibility to reduce the connection interval to 1 ms for one link. LLPM parameters can be used for a given connection only if it's supported by both peripheral and central. -config CAF_BLE_STATE_TX_PWR - int - default 8 if BT_CTLR_TX_PWR_PLUS_8 - default 7 if BT_CTLR_TX_PWR_PLUS_7 - default 6 if BT_CTLR_TX_PWR_PLUS_6 - default 5 if BT_CTLR_TX_PWR_PLUS_5 - default 4 if BT_CTLR_TX_PWR_PLUS_4 - default 3 if BT_CTLR_TX_PWR_PLUS_3 - default 2 if BT_CTLR_TX_PWR_PLUS_2 - default 0 if BT_CTLR_TX_PWR_0 - default -4 if BT_CTLR_TX_PWR_MINUS_4 - default -8 if BT_CTLR_TX_PWR_MINUS_8 - default -12 if BT_CTLR_TX_PWR_MINUS_12 - default -16 if BT_CTLR_TX_PWR_MINUS_16 - default -20 if BT_CTLR_TX_PWR_MINUS_20 - default -30 if BT_CTLR_TX_PWR_MINUS_30 - default -40 if BT_CTLR_TX_PWR_MINUS_40 - help - For nrfxlib LL TX power has to be set using HCI commands. - Zephyr Kconfig options are ignored. - module = CAF_BLE_STATE module-str = caf module BLE state source "subsys/logging/Kconfig.template.log_config" diff --git a/subsys/caf/modules/ble_state.c b/subsys/caf/modules/ble_state.c index 89a4c7076a1e..85b10eab4938 100644 --- a/subsys/caf/modules/ble_state.c +++ b/subsys/caf/modules/ble_state.c @@ -20,12 +20,6 @@ #include "sdc_hci_vs.h" #endif /* CONFIG_BT_LL_SOFTDEVICE */ -#ifdef CONFIG_BT_CTLR -#define TX_PWR CONFIG_CAF_BLE_STATE_TX_PWR -#else -#define TX_PWR 0 -#endif /* CONFIG_BT_CTLR */ - #define MODULE ble_state #include @@ -71,47 +65,6 @@ static void disconnect_peer(struct bt_conn *conn) } } -static void set_tx_power(struct bt_conn *conn) -{ - uint16_t conn_handle; - - int err = bt_hci_get_conn_handle(conn, &conn_handle); - - if (err) { - LOG_ERR("No connection handle (err %d)", err); - } else { - struct bt_hci_cp_vs_write_tx_power_level *cp; - struct bt_hci_rp_vs_write_tx_power_level *rp; - struct net_buf *buf; - struct net_buf *rsp = NULL; - - buf = bt_hci_cmd_create(BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL, sizeof(*cp)); - if (!buf) { - LOG_ERR("Cannot allocate buffer to set TX power"); - return; - } - - cp = net_buf_add(buf, sizeof(*cp)); - cp->handle = sys_cpu_to_le16(conn_handle); - cp->handle_type = BT_HCI_VS_LL_HANDLE_TYPE_CONN; - cp->tx_power_level = TX_PWR; - - LOG_INF("Setting TX power to: %" PRId8, cp->tx_power_level); - - err = bt_hci_cmd_send_sync(BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL, buf, &rsp); - if (err) { - LOG_ERR("Cannot set TX power (err: %d)", err); - } else { - rp = (struct bt_hci_rp_vs_write_tx_power_level *)rsp->data; - LOG_INF("TX power returned by command: %" PRId8, rp->selected_tx_power); - } - - if (rsp) { - net_buf_unref(rsp); - } - } -} - static void broadcast_init_conn_params(struct bt_conn *conn) { struct bt_conn_info info; @@ -155,13 +108,6 @@ static void connected(struct bt_conn *conn, uint8_t error) return; } - /* For nrfxlib LL TX power level has to be set using HCI command. - * The default value set in Kconfig has no effect. - */ - if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE)) { - set_tx_power(conn); - } - if (IS_ENABLED(CONFIG_LOG)) { char addr_str[BT_ADDR_LE_STR_LEN];