Skip to content

Commit

Permalink
caf: ble_state: Remove TX power update using HCI command on connected
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Pekka Niskanen <[email protected]>
  • Loading branch information
MarekPieta authored and anangl committed Sep 5, 2023
1 parent 9a9e46b commit 787e2af
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 85 deletions.
8 changes: 2 additions & 6 deletions doc/nrf/libraries/caf/ble_state.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
29 changes: 4 additions & 25 deletions subsys/caf/modules/Kconfig.ble_state
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
54 changes: 0 additions & 54 deletions subsys/caf/modules/ble_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <caf/events/module_state_event.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit 787e2af

Please sign in to comment.