Skip to content

Commit 86ac86c

Browse files
Johan Hedbergjhedberg
authored andcommitted
Bluetooth: Mesh: Add helpers for starting/stopping Node ID
We'll soon extend the start functionality with a bit more stuff (prioritizing the started subnet), so in order to avoid excessive code duplication, create helpers for these actions. Signed-off-by: Johan Hedberg <[email protected]>
1 parent 6277775 commit 86ac86c

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

subsys/bluetooth/host/mesh/cfg_srv.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
801801
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
802802

803803
if (sub->net_idx != BT_MESH_KEY_UNUSED) {
804-
sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED;
805-
sub->node_id_start = 0;
804+
bt_mesh_proxy_identity_stop(sub);
806805
}
807806
}
808807

@@ -2234,8 +2233,11 @@ static void node_identity_set(struct bt_mesh_model *model,
22342233
*/
22352234
if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) &&
22362235
bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) {
2237-
sub->node_id = node_id;
2238-
sub->node_id_start = node_id ? k_uptime_get_32() : 0;
2236+
if (node_id) {
2237+
bt_mesh_proxy_identity_start(sub);
2238+
} else {
2239+
bt_mesh_proxy_identity_stop(sub);
2240+
}
22392241
bt_mesh_adv_update();
22402242
}
22412243

subsys/bluetooth/host/mesh/proxy.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,18 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub)
337337
}
338338
}
339339

340+
void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub)
341+
{
342+
sub->node_id = BT_MESH_NODE_IDENTITY_RUNNING;
343+
sub->node_id_start = k_uptime_get_32();
344+
}
345+
346+
void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub)
347+
{
348+
sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED;
349+
sub->node_id_start = 0;
350+
}
351+
340352
int bt_mesh_proxy_identity_enable(void)
341353
{
342354
/* FIXME: Add support for multiple subnets */
@@ -360,8 +372,7 @@ int bt_mesh_proxy_identity_enable(void)
360372
return 0;
361373
}
362374

363-
sub->node_id = BT_MESH_NODE_IDENTITY_RUNNING;
364-
sub->node_id_start = k_uptime_get_32();
375+
bt_mesh_proxy_identity_start(sub);
365376
bt_mesh_adv_update();
366377

367378
return 0;
@@ -1081,8 +1092,7 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
10811092
active, remaining);
10821093
node_id_adv(sub);
10831094
} else {
1084-
sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED;
1085-
sub->node_id_start = 0;
1095+
bt_mesh_proxy_identity_stop(sub);
10861096
BT_DBG("Node ID stopped");
10871097
}
10881098
}

subsys/bluetooth/host/mesh/proxy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct net_buf_simple *bt_mesh_proxy_get_buf(void);
2828
s32_t bt_mesh_proxy_adv_start(void);
2929
void bt_mesh_proxy_adv_stop(void);
3030

31+
void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub);
32+
void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub);
33+
3134
bool bt_mesh_proxy_relay(struct net_buf_simple *buf, u16_t dst);
3235
void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, u16_t addr);
3336

0 commit comments

Comments
 (0)