Skip to content

Commit 8b51b60

Browse files
Johan Hedbergjhedberg
authored andcommitted
Bluetooth: Mesh: Proxy: Don't try to advertise when it's not possible
If we have the maximum number of supported connections, then it doesn't make sense to try to do connectable advertising. Signed-off-by: Johan Hedberg <[email protected]>
1 parent e4cac81 commit 8b51b60

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

subsys/bluetooth/host/mesh/proxy.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,20 +503,24 @@ static ssize_t proxy_recv(struct bt_conn *conn,
503503
return len;
504504
}
505505

506+
static int conn_count;
507+
506508
static void proxy_connected(struct bt_conn *conn, u8_t err)
507509
{
508510
struct bt_mesh_proxy_client *client;
509511
int i;
510512

511513
BT_DBG("conn %p err 0x%02x", conn, err);
512514

515+
conn_count++;
516+
513517
/* Since we use ADV_OPT_ONE_TIME */
514518
proxy_adv_enabled = false;
515519

516-
#if CONFIG_BT_MAX_CONN > 1
517520
/* Try to re-enable advertising in case it's possible */
518-
bt_mesh_adv_update();
519-
#endif
521+
if (conn_count < CONFIG_BT_MAX_CONN) {
522+
bt_mesh_adv_update();
523+
}
520524

521525
for (client = NULL, i = 0; i < ARRAY_SIZE(clients); i++) {
522526
if (!clients[i].conn) {
@@ -542,6 +546,8 @@ static void proxy_disconnected(struct bt_conn *conn, u8_t reason)
542546

543547
BT_DBG("conn %p reason 0x%02x", conn, reason);
544548

549+
conn_count--;
550+
545551
for (i = 0; i < ARRAY_SIZE(clients); i++) {
546552
struct bt_mesh_proxy_client *client = &clients[i];
547553

@@ -1087,6 +1093,11 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
10871093

10881094
BT_DBG("");
10891095

1096+
if (conn_count == CONFIG_BT_MAX_CONN) {
1097+
BT_WARN("Connectable advertising deferred (max connections)");
1098+
return remaining;
1099+
}
1100+
10901101
if (!sub) {
10911102
BT_WARN("No subnets to advertise on");
10921103
return remaining;

0 commit comments

Comments
 (0)