mesh: Add storage of Mesh Private Beacon settings
authorBrian Gix <brian.gix@intel.com>
Thu, 8 Oct 2020 17:59:48 +0000 (10:59 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 10:11:34 +0000 (15:41 +0530)
If current storage does not exist in node.json, the Mesh Private
Beacon will be disabled.

mesh/mesh-config-json.c
mesh/mesh-config.h

index ce4d328..9ee4dc6 100644 (file)
@@ -1338,6 +1338,19 @@ static void parse_features(json_object *jconfig, struct mesh_config_node *node)
                        node->modes.beacon = mode;
        }
 
+       if (json_object_object_get_ex(jconfig, "mpb", &jvalue)) {
+               mode = get_mode(jvalue);
+               if (mode <= MESH_MODE_UNSUPPORTED)
+                       node->modes.mpb = mode;
+
+               if (node->modes.mpb == MESH_MODE_ENABLED) {
+                       if (json_object_object_get_ex(jconfig, "mpbPeriod",
+                                                               &jvalue))
+                               node->modes.mpb_period =
+                                               json_object_get_int(jvalue);
+               }
+       }
+
        if (!json_object_object_get_ex(jconfig, "relay", &jrelay))
                return;
 
@@ -1577,6 +1590,18 @@ bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword,
        return save_config(cfg->jnode, cfg->node_dir_path);
 }
 
+bool mesh_config_write_mode_ex(struct mesh_config *cfg, const char *keyword,
+                                                       int value, bool save)
+{
+       if (!cfg)
+               return false;
+
+       if (save)
+               return mesh_config_write_mode(cfg, keyword, value);
+       else
+               return write_mode(cfg->jnode, keyword, value);
+}
+
 static bool write_relay_mode(json_object *jobj, uint8_t mode,
                                        uint8_t count, uint16_t interval)
 {
@@ -1623,6 +1648,21 @@ bool mesh_config_write_relay_mode(struct mesh_config *cfg, uint8_t mode,
        return save_config(cfg->jnode, cfg->node_dir_path);
 }
 
+bool mesh_config_write_mpb(struct mesh_config *cfg, uint8_t mode,
+                                                               uint8_t period)
+{
+
+       if (!cfg || !write_mode(cfg->jnode, "mpb", mode))
+               return false;
+
+       if (mode) {
+               if (!write_int(cfg->jnode, "mpbPeriod", period))
+                       return false;
+       }
+
+       return save_config(cfg->jnode, cfg->node_dir_path);
+}
+
 bool mesh_config_write_net_transmit(struct mesh_config *cfg, uint8_t cnt,
                                                        uint16_t interval)
 {
@@ -1747,6 +1787,14 @@ static struct mesh_config *create_config(const char *cfg_path,
        if (!write_mode(jnode, "beacon", modes->beacon))
                return NULL;
 
+       if (!write_mode(jnode, "mpb", modes->mpb))
+               return NULL;
+
+       if (modes->mpb) {
+               if (!write_int(jnode, "mpbPeriod", modes->mpb_period))
+                       return NULL;
+       }
+
        /* Sequence number */
        json_object_object_add(jnode, sequenceNumber,
                                        json_object_new_int(node->seq_number));
index ed1b610..3cb20b8 100644 (file)
@@ -60,6 +60,8 @@ struct mesh_config_modes {
        uint8_t friend;
        uint8_t proxy;
        uint8_t beacon;
+       uint8_t mpb;
+       uint8_t mpb_period;
 };
 
 struct mesh_config_netkey {
@@ -140,9 +142,13 @@ bool mesh_config_write_seq_number(struct mesh_config *cfg, uint32_t seq,
 bool mesh_config_write_unicast(struct mesh_config *cfg, uint16_t unicast);
 bool mesh_config_write_relay_mode(struct mesh_config *cfg, uint8_t mode,
                                        uint8_t count, uint16_t interval);
+bool mesh_config_write_mpb(struct mesh_config *cfg, uint8_t mode,
+                                                               uint8_t period);
 bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl);
 bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword,
                                                                int value);
+bool mesh_config_write_mode_ex(struct mesh_config *cfg, const char *keyword,
+                                                       int value, bool save);
 bool mesh_config_comp_page_add(struct mesh_config *cfg, uint8_t page,
                                                uint8_t *data, uint16_t size);
 void mesh_config_comp_page_del(struct mesh_config *cfg, uint8_t page);