From 897a1d0d1cec1ba8bc811a335fc414f8fe1960f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Thu, 23 Nov 2023 12:09:18 +0100 Subject: [PATCH] Bluetooth: Mesh: suspend/resume advertising MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disables Mesh advertising when suspending, and enables advertising when resuming Mesh. Signed-off-by: HÃ¥vard Reierstad --- subsys/bluetooth/mesh/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 2c78ea227de..24bbd7c7e94 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -460,6 +460,13 @@ int bt_mesh_suspend(void) bt_mesh_model_foreach(model_suspend, NULL); + err = bt_mesh_adv_disable(); + if (err) { + atomic_clear_bit(bt_mesh.flags, BT_MESH_SUSPENDED); + LOG_WRN("Disabling advertisers failed (err %d)", err); + return err; + } + return 0; } @@ -488,6 +495,17 @@ int bt_mesh_resume(void) return -EALREADY; } + if (!IS_ENABLED(CONFIG_BT_EXT_ADV)) { + bt_mesh_adv_init(); + } + + err = bt_mesh_adv_enable(); + if (err) { + atomic_set_bit(bt_mesh.flags, BT_MESH_SUSPENDED); + LOG_WRN("Re-enabling advertisers failed (err %d)", err); + return err; + } + err = bt_mesh_scan_enable(); if (err) { LOG_WRN("Re-enabling scanning failed (err %d)", err);