Skip to content

Commit

Permalink
Bluetooth: Mesh: enable scanner before enabling proxy gatt
Browse files Browse the repository at this point in the history
Once proxy gatt is enabled, due to the nature of gatt advertisements
being continuous, the controller will reject starting the scanner after
enabling proxy gatt. As such we should start the scanner first.

Currently the order works as we are using k_work to postpone the proxy
gatt service registration, because services can't be registered between
initializing BT and loading the settings.
Once we start using the new settings priority feature, we are sure to
envoke enabling proxy gatt after loading the settings, so the delayed
enabling can and should be removed.

This preventetive fix has been tested by running relevant bsim tests
after rearranging in which order the settings of the subsystems are
loaded via `h_commit`.

Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
  • Loading branch information
KyraLengfeld authored and kartben committed Dec 19, 2024
1 parent 2000ae6 commit b65f53d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions subsys/bluetooth/mesh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ int bt_mesh_resume(void)
return err;
}

err = bt_mesh_scan_enable();
if (err) {
LOG_WRN("Re-enabling scanning failed (err %d)", err);
atomic_set_bit(bt_mesh.flags, BT_MESH_SUSPENDED);
return err;
}

if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && bt_mesh_is_provisioned()) {
err = bt_mesh_proxy_gatt_enable();
if (err) {
Expand All @@ -540,13 +547,6 @@ int bt_mesh_resume(void)
}
}

err = bt_mesh_scan_enable();
if (err) {
LOG_WRN("Re-enabling scanning failed (err %d)", err);
atomic_set_bit(bt_mesh.flags, BT_MESH_SUSPENDED);
return err;
}

bt_mesh_hb_resume();

if (bt_mesh_beacon_enabled() ||
Expand Down Expand Up @@ -630,6 +630,10 @@ int bt_mesh_start(void)
bt_mesh_beacon_enable();
}

if (!IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) {
bt_mesh_scan_enable();
}

if (!IS_ENABLED(CONFIG_BT_MESH_PROV) || !bt_mesh_prov_active() ||
bt_mesh_prov_link.bearer->type == BT_MESH_PROV_ADV) {
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
Expand All @@ -647,8 +651,6 @@ int bt_mesh_start(void)

if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) {
bt_mesh_lpn_init();
} else {
bt_mesh_scan_enable();
}

if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
Expand Down

0 comments on commit b65f53d

Please sign in to comment.