Skip to contentSkip to conversation

tools/mesh-cfgclient: Record remote node's default TTL

PATCH Applied Inga Stotland 2 participants 2 messages Mar 4, 2020 – Mar 5, 2020 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/mesh-cfgclient: Record remote node's default TTL

This adds code to save the value of a remote node's default TTL upon receiving Config Default TTL Status message.

Also, cleanup leftover "#if 0" clause

---
 tools/mesh/cfgcli.c  |  1 +
 tools/mesh/mesh-db.c | 25 ++++++++++++++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)
tools/mesh/cfgcli.c +1 -0
index 0aea7e553..33e77d878 100644
@@ -557,6 +557,7 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data,
 			return true;
 
 		bt_shell_printf("Node %4.4x Default TTL %d\n", src, data[0]);
+		mesh_db_node_ttl_set(src, data[0]);
 
 		break;
 
tools/mesh/mesh-db.c +18 -7
index 41114f40f..4a26a667e 100644
@@ -434,6 +434,24 @@ bool mesh_db_node_net_key_add(uint16_t unicast, uint16_t idx)
 	return add_node_key(jnode, "netKeys", idx);
 }
 
+bool mesh_db_node_ttl_set(uint16_t unicast, uint8_t ttl)
+{
+	json_object *jnode;
+
+	if (!cfg || !cfg->jcfg)
+		return false;
+
+	jnode = get_node_by_unicast(unicast);
+	if (!jnode)
+		return false;
+
+	if (!write_int(jnode, "defaultTTL", ttl))
+		return false;
+
+	return mesh_config_save((struct mesh_config *) cfg, true,
+								NULL, NULL);
+}
+
 static void jarray_key_del(json_object *jarray, int16_t idx)
 {
 	int i, sz = json_object_array_length(jarray);
@@ -923,13 +941,6 @@ bool mesh_db_create(const char *fname, const uint8_t token[8],
 		goto fail;
 
 	json_object_object_add(jcfg, "appKeys", jarray);
-#if 0
-	jarray = json_object_new_array();
-	if (!jarray)
-		goto fail;
-
-	json_object_object_add(jcfg, "groups", jarray);
-#endif
 
 	if (!mesh_config_save((struct mesh_config *) cfg, true, NULL, NULL))
 		goto fail;
Signature · 1 line
2.21.1
Applied
#1 lore raw

Applied

Quoted 64 lines · Inga Stotland

This adds code to save the value of a remote node's default TTL upon receiving Config Default TTL Status message.

Also, cleanup leftover "#if 0" clause

---
 tools/mesh/cfgcli.c  |  1 +
 tools/mesh/mesh-db.c | 25 ++++++++++++++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)
tools/mesh/cfgcli.c +1 -0
index 0aea7e553..33e77d878 100644
@@ -557,6 +557,7 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data,
 			return true;
 
 		bt_shell_printf("Node %4.4x Default TTL %d\n", src, data[0]);
+		mesh_db_node_ttl_set(src, data[0]);
 
 		break;
 
tools/mesh/mesh-db.c +18 -7
index 41114f40f..4a26a667e 100644
@@ -434,6 +434,24 @@ bool mesh_db_node_net_key_add(uint16_t unicast, uint16_t idx)
 	return add_node_key(jnode, "netKeys", idx);
 }
 
+bool mesh_db_node_ttl_set(uint16_t unicast, uint8_t ttl)
+{
+	json_object *jnode;
+
+	if (!cfg || !cfg->jcfg)
+		return false;
+
+	jnode = get_node_by_unicast(unicast);
+	if (!jnode)
+		return false;
+
+	if (!write_int(jnode, "defaultTTL", ttl))
+		return false;
+
+	return mesh_config_save((struct mesh_config *) cfg, true,
+								NULL, NULL);
+}
+
 static void jarray_key_del(json_object *jarray, int16_t idx)
 {
 	int i, sz = json_object_array_length(jarray);
@@ -923,13 +941,6 @@ bool mesh_db_create(const char *fname, const uint8_t token[8],
 		goto fail;
 
 	json_object_object_add(jcfg, "appKeys", jarray);
-#if 0
-	jarray = json_object_new_array();
-	if (!jarray)
-		goto fail;
-
-	json_object_object_add(jcfg, "groups", jarray);
-#endif
 
 	if (!mesh_config_save((struct mesh_config *) cfg, true, NULL, NULL))
 		goto fail;