Skip to content

Commit 6277775

Browse files
Johan Hedbergjhedberg
authored andcommitted
Bluetooth: Mesh: Add Proxy advertising support for multiple subnets
Until now the proxy server code would only advertise with the first subnet. Introduce tracking of what the last advertised subnet was, and give each subnet 10 seconds of advertising at a time. Signed-off-by: Johan Hedberg <[email protected]>
1 parent 364ce88 commit 6277775

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

subsys/bluetooth/host/mesh/proxy.c

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,16 +1018,57 @@ static int net_id_adv(struct bt_mesh_subnet *sub)
10181018
return 0;
10191019
}
10201020

1021-
static s32_t gatt_proxy_advertise(void)
1021+
static bool advertise_subnet(struct bt_mesh_subnet *sub)
1022+
{
1023+
if (sub->net_idx == BT_MESH_KEY_UNUSED) {
1024+
return false;
1025+
}
1026+
1027+
return (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING ||
1028+
bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED);
1029+
}
1030+
1031+
static struct bt_mesh_subnet *next_sub(void)
1032+
{
1033+
static int next_idx;
1034+
int i;
1035+
1036+
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
1037+
struct bt_mesh_subnet *sub;
1038+
1039+
sub = &bt_mesh.sub[(i + next_idx) % ARRAY_SIZE(bt_mesh.sub)];
1040+
if (advertise_subnet(sub)) {
1041+
next_idx = (next_idx + 1) % ARRAY_SIZE(bt_mesh.sub);
1042+
return sub;
1043+
}
1044+
}
1045+
1046+
return NULL;
1047+
}
1048+
1049+
static int sub_count(void)
1050+
{
1051+
int i, count = 0;
1052+
1053+
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
1054+
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
1055+
1056+
if (advertise_subnet(sub)) {
1057+
count++;
1058+
}
1059+
}
1060+
1061+
return count;
1062+
}
1063+
1064+
static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
10221065
{
1023-
/* TODO: Add support for multiple subnets */
1024-
struct bt_mesh_subnet *sub = &bt_mesh.sub[0];
10251066
s32_t remaining = K_FOREVER;
10261067

10271068
BT_DBG("");
10281069

1029-
if (sub->net_idx == BT_MESH_KEY_UNUSED) {
1030-
BT_WARN("First subnet is not valid");
1070+
if (!sub) {
1071+
BT_WARN("No subnets to advertise on");
10311072
return remaining;
10321073
}
10331074

@@ -1046,11 +1087,20 @@ static s32_t gatt_proxy_advertise(void)
10461087
}
10471088
}
10481089

1049-
if (sub->node_id == BT_MESH_NODE_IDENTITY_STOPPED &&
1050-
bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) {
1051-
net_id_adv(sub);
1090+
if (sub->node_id == BT_MESH_NODE_IDENTITY_STOPPED) {
1091+
if (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) {
1092+
net_id_adv(sub);
1093+
} else {
1094+
return gatt_proxy_advertise(next_sub());
1095+
}
1096+
}
1097+
1098+
if (sub_count() > 1 && (remaining > K_SECONDS(10) || remaining < 0)) {
1099+
remaining = K_SECONDS(10);
10521100
}
10531101

1102+
BT_DBG("Advertising %d ms for net_idx 0x%04x", remaining, sub->net_idx);
1103+
10541104
return remaining;
10551105
}
10561106
#endif /* GATT_PROXY */
@@ -1088,7 +1138,7 @@ s32_t bt_mesh_proxy_adv_start(void)
10881138

10891139
#if defined(CONFIG_BT_MESH_GATT_PROXY)
10901140
if (bt_mesh_is_provisioned()) {
1091-
return gatt_proxy_advertise();
1141+
return gatt_proxy_advertise(next_sub());
10921142
}
10931143
#endif /* GATT_PROXY */
10941144

0 commit comments

Comments
 (0)