Skip to content

Commit 1a039f1

Browse files
MarekPietarlubos
authored andcommitted
caf: modules: ble_adv: Power down on disconnection with reason 0x15
Force power down if bonded peer disconnects with reason 0x15 (Remote Device Terminated due to Power Off). Jira: NCSDK-24458 Signed-off-by: Marek Pieta <[email protected]> Signed-off-by: Pekka Niskanen <[email protected]> Signed-off-by: Divya Pillai <[email protected]>
1 parent caca10f commit 1a039f1

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

doc/nrf/libraries/caf/ble_adv.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The following Kconfig options are available for this module:
1919

2020
* :kconfig:option:`CONFIG_CAF_BLE_ADV`
2121
* :kconfig:option:`CONFIG_CAF_BLE_ADV_PM_EVENTS`
22+
* :kconfig:option:`CONFIG_CAF_BLE_ADV_POWER_DOWN_ON_DISCONNECTION_REASON_0X15`
2223
* :kconfig:option:`CONFIG_CAF_BLE_ADV_DIRECT_ADV`
2324
* :kconfig:option:`CONFIG_CAF_BLE_ADV_FAST_ADV`
2425
* :kconfig:option:`CONFIG_CAF_BLE_ADV_FAST_ADV_TIMEOUT`
@@ -98,6 +99,17 @@ This is done to ensure that the user does not try to connect to the device that
9899

99100
The :kconfig:option:`CONFIG_CAF_BLE_ADV_GRACE_PERIOD` is enabled by default if the Swift Pair advertising data provider is enabled in the configuration.
100101

102+
Force power down on bonded peer power off
103+
-----------------------------------------
104+
105+
You can use the :kconfig:option:`CONFIG_CAF_BLE_ADV_POWER_DOWN_ON_DISCONNECTION_REASON_0X15` Kconfig option to force power down when a bonded peer disconnects with reason ``0x15`` (Remote Device Terminated due to Power Off).
106+
On a Bluetooth LE peer event (:c:struct:`ble_peer_event`) reporting :c:enumerator:`PEER_STATE_DISCONNECTED` (:c:member:`ble_peer_event.state`) with reason ``0x15`` (:c:member:`ble_peer_event.reason`), the module performs the following:
107+
108+
* Instantly stops Bluetooth LE advertising (the module enters power down state).
109+
* Submits a force power down event (:c:struct:`force_power_down_event`).
110+
111+
You can use this feature to prevent a bonded peer from waking up until activity on the peripheral is detected.
112+
101113
Implementation details
102114
**********************
103115

@@ -127,7 +139,7 @@ The Bluetooth LE bond module broadcasts information related to bond control usin
127139
The |ble_adv| reacts on :c:struct:`ble_peer_operation_event` related to the Bluetooth peer change or erase advertising.
128140
The module performs one of the following operations:
129141

130-
* If there is a peer connected over Bluetooth, the |ble_adv| triggers disconnection and submits a :c:struct:`ble_peer_event` with :c:member:`ble_peer_event.state` set to :c:enum:`PEER_STATE_DISCONNECTING` to let other application modules prepare for the planned disconnection.
142+
* If there is a peer connected over Bluetooth, the |ble_adv| triggers disconnection and submits a :c:struct:`ble_peer_event` with :c:member:`ble_peer_event.state` set to :c:enumerator:`PEER_STATE_DISCONNECTING` to let other application modules prepare for the planned disconnection.
131143
* Otherwise, the Bluetooth advertising with the newly selected Bluetooth local identity is started.
132144

133145
Avoiding connection requests from unbonded centrals when bonded

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,11 @@ Common Application Framework (CAF)
10141014
* Added :c:member:`ble_peer_event.reason` to inform about reason code related to state of the Bluetooth LE peer.
10151015
The field is used to propagate information about error code related to a connection establishment failure and disconnection reason.
10161016

1017+
* :ref:`caf_ble_adv`:
1018+
1019+
* Added the :kconfig:option:`CONFIG_CAF_BLE_ADV_POWER_DOWN_ON_DISCONNECTION_REASON_0X15` Kconfig option.
1020+
You can use this option to force system power down when a bonded peer disconnects with reason ``0x15`` (Remote Device Terminated due to Power Off).
1021+
10171022
Shell libraries
10181023
---------------
10191024

subsys/caf/modules/Kconfig.ble_adv

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ config CAF_BLE_ADV_PM_EVENTS
1818
depends on CAF_PM_EVENTS
1919
default y
2020

21+
config CAF_BLE_ADV_POWER_DOWN_ON_DISCONNECTION_REASON_0X15
22+
bool "Force power down on disconnection with reason 0x15"
23+
depends on CAF_BLE_ADV_PM_EVENTS
24+
select CAF_FORCE_POWER_DOWN_EVENTS
25+
help
26+
Force power down when a bonded peer disconnects with reason 0x15
27+
(Remote Device Terminated due to Power Off). The module instantly
28+
stops Bluetooth LE advertising and submits a force_power_down event.
29+
2130
config CAF_BLE_ADV_DIRECT_ADV
2231
bool "Advertise to bonded peer directly"
2332
depends on SETTINGS

subsys/caf/modules/ble_adv.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define MODULE ble_adv
1818
#include <caf/events/module_state_event.h>
1919
#include <caf/events/ble_common_event.h>
20+
#include <caf/events/force_power_down_event.h>
2021
#include <caf/events/power_event.h>
2122

2223
#include <zephyr/logging/log.h>
@@ -876,6 +877,22 @@ static bool handle_ble_peer_event(const struct ble_peer_event *event)
876877
break;
877878

878879
case PEER_STATE_DISCONNECTED:
880+
if (IS_ENABLED(CONFIG_CAF_BLE_ADV_POWER_DOWN_ON_DISCONNECTION_REASON_0X15)) {
881+
bt_addr_le_t addr;
882+
883+
bond_addr_get(cur_identity, &addr);
884+
/* Check if disconnected peer was bonded. */
885+
if (bt_addr_le_cmp(&addr, BT_ADDR_LE_ANY) &&
886+
!bt_addr_le_cmp(&addr, bt_conn_get_dst(event->id))) {
887+
if ((event->reason == BT_HCI_ERR_REMOTE_POWER_OFF) &&
888+
(state != STATE_OFF)) {
889+
LOG_INF("Bonded peer power off, force system power down");
890+
update_state(STATE_OFF);
891+
force_power_down();
892+
}
893+
}
894+
}
895+
879896
if (state != STATE_OFF) {
880897
req_new_adv_session = true;
881898
req_fast_adv = true;

0 commit comments

Comments
 (0)