Skip to content

Commit 4e1b595

Browse files
PavelVPVrlubos
authored andcommitted
[nrf fromtree] 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 <[email protected]> (cherry picked from commit 2b0fbd8)
1 parent 2201729 commit 4e1b595

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

subsys/bluetooth/mesh/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ config BT_MESH_PROXY_FILTER_SIZE
212212
enough so that proxy client can communicate with several devices through
213213
this proxy server node using the default accept list filter type.
214214

215+
config BT_MESH_MAX_CONN
216+
int "Maximum number of simultaneous connections used by the stack"
217+
default BT_MAX_CONN
218+
range 1 BT_MAX_CONN
219+
help
220+
Maximum number of simultaneous Bluetooth connections that the Bluetooth
221+
mesh stack can use.
222+
215223
endif # BT_CONN
216224

217225
config BT_MESH_ACCESS_LAYER_MSG

subsys/bluetooth/mesh/gatt_cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static void scan_recv(const struct bt_le_scan_recv_info *info,
302302
return;
303303
}
304304

305-
if (bt_mesh_proxy_conn_count_get() == CONFIG_BT_MAX_CONN) {
305+
if (!bt_mesh_proxy_has_avail_conn()) {
306306
return;
307307
}
308308

subsys/bluetooth/mesh/pb_gatt_srv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ int bt_mesh_pb_gatt_srv_adv_start(void)
271271
BT_DBG("");
272272

273273
if (!service_registered || bt_mesh_is_provisioned() ||
274-
bt_mesh_proxy_conn_count_get() == CONFIG_BT_MAX_CONN) {
274+
!bt_mesh_proxy_has_avail_conn()) {
275275
return -ENOTSUP;
276276
}
277277

subsys/bluetooth/mesh/proxy_msg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void bt_mesh_proxy_role_cleanup(struct bt_mesh_proxy_role *role)
277277
bt_mesh_adv_gatt_update();
278278
}
279279

280-
int bt_mesh_proxy_conn_count_get(void)
280+
bool bt_mesh_proxy_has_avail_conn(void)
281281
{
282-
return conn_count;
282+
return conn_count < CONFIG_BT_MESH_MAX_CONN;
283283
}

subsys/bluetooth/mesh/proxy_msg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ struct bt_mesh_proxy_role *bt_mesh_proxy_role_setup(struct bt_conn *conn,
5757
proxy_recv_cb_t recv);
5858
void bt_mesh_proxy_role_cleanup(struct bt_mesh_proxy_role *role);
5959

60-
int bt_mesh_proxy_conn_count_get(void);
60+
bool bt_mesh_proxy_has_avail_conn(void);
6161

6262
#endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_PROXY_MSG_H_ */

subsys/bluetooth/mesh/proxy_srv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ static int gatt_proxy_advertise(struct bt_mesh_subnet *sub)
556556

557557
BT_DBG("");
558558

559-
if (bt_mesh_proxy_conn_count_get() == CONFIG_BT_MAX_CONN) {
559+
if (!bt_mesh_proxy_has_avail_conn()) {
560560
BT_DBG("Connectable advertising deferred (max connections)");
561561
return -ENOMEM;
562562
}
@@ -847,7 +847,7 @@ static void gatt_connected(struct bt_conn *conn, uint8_t err)
847847
proxy_msg_recv);
848848

849849
/* Try to re-enable advertising in case it's possible */
850-
if (bt_mesh_proxy_conn_count_get() < CONFIG_BT_MAX_CONN) {
850+
if (bt_mesh_proxy_has_avail_conn()) {
851851
bt_mesh_adv_gatt_update();
852852
}
853853
}

0 commit comments

Comments
 (0)