Bluetooth: Mesh: Fix disconnecting existing provisioning bearers
If PB-GATT is disabled while there are connected clients, those
clients must be disconnected. Add a 'disconnect` parameter to
bt_mesh_proxy_prov_disable() to handle scenarios when we don't want to
disconnect (e.g. right after successfully finishing provisioning) and
tose where we do want to disconnect (e.g. user requesting to disable
the provisioning bearer).
Also make sure that we always update advertising, so that a stale
advertising set isn't left in the controller.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
diff --git a/subsys/bluetooth/host/mesh/main.c b/subsys/bluetooth/host/mesh/main.c
index b2b025a..49f0364 100644
--- a/subsys/bluetooth/host/mesh/main.c
+++ b/subsys/bluetooth/host/mesh/main.c
@@ -50,7 +50,7 @@
}
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
- if (bt_mesh_proxy_prov_disable() == 0) {
+ if (bt_mesh_proxy_prov_disable(false) == 0) {
pb_gatt_enabled = true;
} else {
pb_gatt_enabled = false;
@@ -184,8 +184,7 @@
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) &&
(bearers & BT_MESH_PROV_GATT)) {
- bt_mesh_proxy_prov_disable();
- bt_mesh_adv_update();
+ bt_mesh_proxy_prov_disable(true);
}
return 0;
diff --git a/subsys/bluetooth/host/mesh/proxy.c b/subsys/bluetooth/host/mesh/proxy.c
index e971201..bcda829 100644
--- a/subsys/bluetooth/host/mesh/proxy.c
+++ b/subsys/bluetooth/host/mesh/proxy.c
@@ -660,7 +660,7 @@
return 0;
}
-int bt_mesh_proxy_prov_disable(void)
+int bt_mesh_proxy_prov_disable(bool disconnect)
{
int i;
@@ -680,12 +680,21 @@
for (i = 0; i < ARRAY_SIZE(clients); i++) {
struct bt_mesh_proxy_client *client = &clients[i];
- if (client->conn && client->filter_type == PROV) {
+ if (!client->conn || client->filter_type != PROV) {
+ continue;
+ }
+
+ if (disconnect) {
+ bt_conn_disconnect(client->conn,
+ BT_HCI_ERR_REMOTE_USER_TERM_CONN);
+ } else {
bt_mesh_pb_gatt_close(client->conn);
client->filter_type = NONE;
}
}
+ bt_mesh_adv_update();
+
return 0;
}
diff --git a/subsys/bluetooth/host/mesh/proxy.h b/subsys/bluetooth/host/mesh/proxy.h
index ca7a5a0..a4bddbe 100644
--- a/subsys/bluetooth/host/mesh/proxy.h
+++ b/subsys/bluetooth/host/mesh/proxy.h
@@ -15,7 +15,7 @@
struct net_buf_simple *msg);
int bt_mesh_proxy_prov_enable(void);
-int bt_mesh_proxy_prov_disable(void);
+int bt_mesh_proxy_prov_disable(bool disconnect);
int bt_mesh_proxy_gatt_enable(void);
int bt_mesh_proxy_gatt_disable(void);
diff --git a/subsys/bluetooth/host/mesh/settings.c b/subsys/bluetooth/host/mesh/settings.c
index b4af1b9..ad3e38f 100644
--- a/subsys/bluetooth/host/mesh/settings.c
+++ b/subsys/bluetooth/host/mesh/settings.c
@@ -739,7 +739,7 @@
}
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
- bt_mesh_proxy_prov_disable();
+ bt_mesh_proxy_prov_disable(true);
}
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {