From 86ac86c6ca5d14e71e569964f5128f50ed8484c6 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 5 Dec 2017 09:35:57 +0200 Subject: [PATCH] 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 --- subsys/bluetooth/host/mesh/cfg_srv.c | 10 ++++++---- subsys/bluetooth/host/mesh/proxy.c | 18 ++++++++++++++---- subsys/bluetooth/host/mesh/proxy.h | 3 +++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/host/mesh/cfg_srv.c b/subsys/bluetooth/host/mesh/cfg_srv.c index 8cb8e23759f..456ddad2c48 100644 --- a/subsys/bluetooth/host/mesh/cfg_srv.c +++ b/subsys/bluetooth/host/mesh/cfg_srv.c @@ -801,8 +801,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model, struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; if (sub->net_idx != BT_MESH_KEY_UNUSED) { - sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED; - sub->node_id_start = 0; + bt_mesh_proxy_identity_stop(sub); } } @@ -2234,8 +2233,11 @@ static void node_identity_set(struct bt_mesh_model *model, */ if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) { - sub->node_id = node_id; - sub->node_id_start = node_id ? k_uptime_get_32() : 0; + if (node_id) { + bt_mesh_proxy_identity_start(sub); + } else { + bt_mesh_proxy_identity_stop(sub); + } bt_mesh_adv_update(); } diff --git a/subsys/bluetooth/host/mesh/proxy.c b/subsys/bluetooth/host/mesh/proxy.c index 6f89dfabcd2..edef3c0b7d6 100644 --- a/subsys/bluetooth/host/mesh/proxy.c +++ b/subsys/bluetooth/host/mesh/proxy.c @@ -337,6 +337,18 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub) } } +void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub) +{ + sub->node_id = BT_MESH_NODE_IDENTITY_RUNNING; + sub->node_id_start = k_uptime_get_32(); +} + +void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub) +{ + sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED; + sub->node_id_start = 0; +} + int bt_mesh_proxy_identity_enable(void) { /* FIXME: Add support for multiple subnets */ @@ -360,8 +372,7 @@ int bt_mesh_proxy_identity_enable(void) return 0; } - sub->node_id = BT_MESH_NODE_IDENTITY_RUNNING; - sub->node_id_start = k_uptime_get_32(); + bt_mesh_proxy_identity_start(sub); bt_mesh_adv_update(); return 0; @@ -1081,8 +1092,7 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub) active, remaining); node_id_adv(sub); } else { - sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED; - sub->node_id_start = 0; + bt_mesh_proxy_identity_stop(sub); BT_DBG("Node ID stopped"); } } diff --git a/subsys/bluetooth/host/mesh/proxy.h b/subsys/bluetooth/host/mesh/proxy.h index dfe19714fe0..ca7a5a09265 100644 --- a/subsys/bluetooth/host/mesh/proxy.h +++ b/subsys/bluetooth/host/mesh/proxy.h @@ -28,6 +28,9 @@ struct net_buf_simple *bt_mesh_proxy_get_buf(void); s32_t bt_mesh_proxy_adv_start(void); void bt_mesh_proxy_adv_stop(void); +void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub); +void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub); + bool bt_mesh_proxy_relay(struct net_buf_simple *buf, u16_t dst); void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, u16_t addr);