Bluetooth: Mesh: Limit number of Bluetooth connections used by mesh

When a remote devices establishes a ble connection with the mesh device
with default identity and there are more available connection slots, the
mesh stack will try to restart connectable advertisements (either
pb-gatt or proxy depending on the provisioning state). This makes
difficult for an application to advertise own connectable advertisements
as the mesh stack will not let a chance the app to start advertising.

This change adds a Kconfig option that limits number of connection slots
that the mesh stack can use for own connectable advertisements.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
This commit is contained in:
Pavel Vasilyev 2022-11-23 13:46:55 +01:00 committed by Carles Cufí
commit 2b0fbd86a1
6 changed files with 15 additions and 7 deletions

View file

@ -212,6 +212,14 @@ config BT_MESH_PROXY_FILTER_SIZE
enough so that proxy client can communicate with several devices through
this proxy server node using the default accept list filter type.
config BT_MESH_MAX_CONN
int "Maximum number of simultaneous connections used by the stack"
default BT_MAX_CONN
range 1 BT_MAX_CONN
help
Maximum number of simultaneous Bluetooth connections that the Bluetooth
mesh stack can use.
endif # BT_CONN
config BT_MESH_ACCESS_LAYER_MSG

View file

@ -302,7 +302,7 @@ static void scan_recv(const struct bt_le_scan_recv_info *info,
return;
}
if (bt_mesh_proxy_conn_count_get() == CONFIG_BT_MAX_CONN) {
if (!bt_mesh_proxy_has_avail_conn()) {
return;
}

View file

@ -271,7 +271,7 @@ int bt_mesh_pb_gatt_srv_adv_start(void)
BT_DBG("");
if (!service_registered || bt_mesh_is_provisioned() ||
bt_mesh_proxy_conn_count_get() == CONFIG_BT_MAX_CONN) {
!bt_mesh_proxy_has_avail_conn()) {
return -ENOTSUP;
}

View file

@ -277,7 +277,7 @@ void bt_mesh_proxy_role_cleanup(struct bt_mesh_proxy_role *role)
bt_mesh_adv_gatt_update();
}
int bt_mesh_proxy_conn_count_get(void)
bool bt_mesh_proxy_has_avail_conn(void)
{
return conn_count;
return conn_count < CONFIG_BT_MESH_MAX_CONN;
}

View file

@ -57,6 +57,6 @@ struct bt_mesh_proxy_role *bt_mesh_proxy_role_setup(struct bt_conn *conn,
proxy_recv_cb_t recv);
void bt_mesh_proxy_role_cleanup(struct bt_mesh_proxy_role *role);
int bt_mesh_proxy_conn_count_get(void);
bool bt_mesh_proxy_has_avail_conn(void);
#endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_PROXY_MSG_H_ */

View file

@ -556,7 +556,7 @@ static int gatt_proxy_advertise(struct bt_mesh_subnet *sub)
BT_DBG("");
if (bt_mesh_proxy_conn_count_get() == CONFIG_BT_MAX_CONN) {
if (!bt_mesh_proxy_has_avail_conn()) {
BT_DBG("Connectable advertising deferred (max connections)");
return -ENOMEM;
}
@ -847,7 +847,7 @@ static void gatt_connected(struct bt_conn *conn, uint8_t err)
proxy_msg_recv);
/* Try to re-enable advertising in case it's possible */
if (bt_mesh_proxy_conn_count_get() < CONFIG_BT_MAX_CONN) {
if (bt_mesh_proxy_has_avail_conn()) {
bt_mesh_adv_gatt_update();
}
}