summaryrefslogtreecommitdiff
path: root/mesh/node.c
diff options
context:
space:
mode:
authorBrian Gix <brian.gix@intel.com>2020-10-08 11:05:47 -0700
committerBrian Gix <brian.gix@gmail.com>2023-01-30 16:14:41 -0800
commitebb219614108b3e227b9fde2ff3fdb8ec99512f7 (patch)
tree0293ed4025e6ed368222458d3e81a69fcf04a473 /mesh/node.c
parent5ba57cf85140e2087fef0e617608ee33a04c5449 (diff)
downloadbluez-ebb219614108b3e227b9fde2ff3fdb8ec99512f7.tar.gz
mesh: Add internal Mesh Private Beacon model
Adds recgnition that the Mesh Private Beacon model is internal and foundational, without bindings.
Diffstat (limited to 'mesh/node.c')
-rw-r--r--mesh/node.c67
1 files changed, 61 insertions, 6 deletions
diff --git a/mesh/node.c b/mesh/node.c
index a2a330518..ed3212685 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -32,6 +32,7 @@
#include "mesh/model.h"
#include "mesh/cfgmod.h"
#include "mesh/remprv.h"
+#include "mesh/prv-beacon.h"
#include "mesh/util.h"
#include "mesh/error.h"
#include "mesh/dbus.h"
@@ -100,6 +101,8 @@ struct mesh_node {
uint8_t proxy;
uint8_t friend;
uint8_t beacon;
+ uint8_t mpb;
+ uint8_t mpb_period;
};
struct node_import {
@@ -206,6 +209,8 @@ static void set_defaults(struct mesh_node *node)
{
node->lpn = MESH_MODE_UNSUPPORTED;
node->proxy = MESH_MODE_UNSUPPORTED;
+ node->mpb = MESH_MODE_DISABLED;
+ node->mpb_period = NET_MPB_REFRESH_DEFAULT;
node->friend = (mesh_friendship_supported()) ? MESH_MODE_DISABLED :
MESH_MODE_UNSUPPORTED;
node->beacon = (mesh_beacon_enabled()) ? MESH_MODE_ENABLED :
@@ -403,7 +408,7 @@ static bool init_storage_dir(struct mesh_node *node)
return rpl_init(node->storage_dir);
}
-static void update_net_settings(struct mesh_node *node)
+static void init_net_settings(struct mesh_node *node)
{
struct mesh_net *net = node->net;
@@ -415,6 +420,8 @@ static void update_net_settings(struct mesh_node *node)
node->relay.cnt, node->relay.interval);
mesh_net_set_snb_mode(net, node->beacon == MESH_MODE_ENABLED);
+ mesh_net_set_mpb_mode(net, node->mpb == MESH_MODE_ENABLED,
+ node->mpb_period, true);
}
static bool init_from_storage(struct mesh_config_node *db_node,
@@ -442,6 +449,8 @@ static bool init_from_storage(struct mesh_config_node *db_node,
node->relay.cnt = db_node->modes.relay.cnt;
node->relay.interval = db_node->modes.relay.interval;
node->beacon = db_node->modes.beacon;
+ node->mpb = db_node->modes.mpb;
+ node->mpb_period = db_node->modes.mpb_period;
l_debug("relay %2.2x, proxy %2.2x, lpn %2.2x, friend %2.2x",
node->relay.mode, node->proxy, node->lpn, node->friend);
@@ -495,7 +504,7 @@ static bool init_from_storage(struct mesh_config_node *db_node,
mesh_net_set_seq_num(node->net, node->seq_number);
mesh_net_set_default_ttl(node->net, node->ttl);
- update_net_settings(node);
+ init_net_settings(node);
/* Initialize configuration server model */
cfgmod_server_init(node, PRIMARY_ELE_IDX);
@@ -504,6 +513,9 @@ static bool init_from_storage(struct mesh_config_node *db_node,
remote_prov_server_init(node, PRIMARY_ELE_IDX);
remote_prov_client_init(node, PRIMARY_ELE_IDX);
+ /* Initialize Private Beacon server model */
+ prv_beacon_server_init(node, PRIMARY_ELE_IDX);
+
node->cfg = cfg;
return true;
@@ -839,6 +851,36 @@ uint8_t node_beacon_mode_get(struct mesh_node *node)
return node->beacon;
}
+bool node_mpb_mode_set(struct mesh_node *node, bool enable, uint8_t period)
+{
+ bool res;
+ uint8_t beacon;
+
+ if (!node)
+ return false;
+
+ beacon = enable ? MESH_MODE_ENABLED : MESH_MODE_DISABLED;
+ res = mesh_config_write_mpb(node->cfg, beacon, period);
+
+ if (res) {
+ node->mpb = beacon;
+ node->mpb_period = period;
+ mesh_net_set_mpb_mode(node->net, enable, period, false);
+ }
+
+ return res;
+}
+
+uint8_t node_mpb_mode_get(struct mesh_node *node, uint8_t *period)
+{
+ if (!node)
+ return MESH_MODE_DISABLED;
+
+ *period = node->mpb_period;
+
+ return node->mpb;
+}
+
bool node_friend_mode_set(struct mesh_node *node, bool enable)
{
bool res;
@@ -951,6 +993,8 @@ static void convert_node_to_storage(struct mesh_node *node,
db_node->modes.relay.cnt = node->relay.cnt;
db_node->modes.relay.interval = node->relay.interval;
db_node->modes.beacon = node->beacon;
+ db_node->modes.mpb = node->mpb;
+ db_node->modes.mpb_period = node->mpb_period;
db_node->ttl = node->ttl;
db_node->seq_number = node->seq_number;
@@ -1173,9 +1217,16 @@ static bool get_sig_models_from_properties(struct mesh_node *node,
while (l_dbus_message_iter_next_entry(&mods, &m_id, &var)) {
uint32_t id = SET_ID(SIG_VENDOR, m_id);
- /* Allow Config Server Model only on the primary element */
- if (ele->idx != PRIMARY_ELE_IDX && id == CONFIG_SRV_MODEL)
- return false;
+ /*
+ * Allow Config Server & Private Beacon Models only on
+ * the primary element
+ */
+ if (ele->idx != PRIMARY_ELE_IDX) {
+ if (id == CONFIG_SRV_MODEL)
+ return false;
+ if (id == PRV_BEACON_SRV_MODEL)
+ return false;
+ }
if (!mesh_model_add(node, ele->models, id, &var))
return false;
@@ -1278,6 +1329,7 @@ static bool get_element_properties(struct mesh_node *node, const char *path,
*/
if (ele->idx == PRIMARY_ELE_IDX) {
mesh_model_add(node, ele->models, CONFIG_SRV_MODEL, NULL);
+ mesh_model_add(node, ele->models, PRV_BEACON_SRV_MODEL, NULL);
mesh_model_add(node, ele->models, REM_PROV_SRV_MODEL, NULL);
if (node->provisioner)
mesh_model_add(node, ele->models, REM_PROV_CLI_MODEL,
@@ -1397,13 +1449,16 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
l_queue_foreach(node->pages, save_pages, node);
- update_net_settings(node);
+ init_net_settings(node);
/* Initialize internal server models */
cfgmod_server_init(node, PRIMARY_ELE_IDX);
remote_prov_server_init(node, PRIMARY_ELE_IDX);
remote_prov_client_init(node, PRIMARY_ELE_IDX);
+ /* Initialize Private Beacon server model */
+ prv_beacon_server_init(node, PRIMARY_ELE_IDX);
+
node->busy = true;
return true;