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>
This commit is contained in:
Johan Hedberg 2019-03-27 14:53:36 +01:00 committed by Johan Hedberg
commit c6fa295e6a
4 changed files with 15 additions and 7 deletions

View file

@ -50,7 +50,7 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx,
}
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 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers)
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;

View file

@ -660,7 +660,7 @@ int bt_mesh_proxy_prov_enable(void)
return 0;
}
int bt_mesh_proxy_prov_disable(void)
int bt_mesh_proxy_prov_disable(bool disconnect)
{
int i;
@ -680,12 +680,21 @@ int bt_mesh_proxy_prov_disable(void)
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;
}

View file

@ -15,7 +15,7 @@ int bt_mesh_proxy_send(struct bt_conn *conn, u8_t type,
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);

View file

@ -739,7 +739,7 @@ static int mesh_commit(void)
}
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++) {