[PATCH BlueZ 13/20] tools/mesh-cfgclient: Save remote node feature setting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Save the information for remote node's relay, friend, proxy and
secure network beacon settings.
---
 tools/mesh/cfgcli.c  |  14 +++-
 tools/mesh/mesh-db.c | 160 +++++++++++++++++++++++++++++++++++--------
 tools/mesh/mesh-db.h |   5 ++
 3 files changed, 151 insertions(+), 28 deletions(-)

diff --git a/tools/mesh/cfgcli.c b/tools/mesh/cfgcli.c
index b30edca19..b5f39df18 100644
--- a/tools/mesh/cfgcli.c
+++ b/tools/mesh/cfgcli.c
@@ -594,6 +594,8 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data,
 
 		bt_shell_printf("Node %4.4x: Config Beacon Status 0x%02x\n",
 				src, data[0]);
+
+		saved = mesh_db_node_set_beacon(src, data[0] != 0);
 		break;
 
 	case OP_CONFIG_RELAY_STATUS:
@@ -602,6 +604,10 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data,
 
 		bt_shell_printf("Node %4.4x: Relay 0x%02x, cnt %d, steps %d\n",
 				src, data[0], data[1] & 0x7, data[1] >> 3);
+
+		saved = mesh_db_node_set_relay(src, data[0], data[1] & 7,
+						((data[1] >> 3) + 1) * 10);
+
 		break;
 
 	case OP_CONFIG_PROXY_STATUS:
@@ -610,6 +616,8 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data,
 
 		bt_shell_printf("Node %4.4x Proxy state 0x%02x\n",
 				src, data[0]);
+
+		saved = mesh_db_node_set_proxy(src, data[0]);
 		break;
 
 	case OP_CONFIG_DEFAULT_TTL_STATUS:
@@ -618,7 +626,6 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data,
 
 		bt_shell_printf("Node %4.4x Default TTL %d\n", src, data[0]);
 		saved = mesh_db_node_set_ttl(src, data[0]);
-
 		break;
 
 	case OP_CONFIG_MODEL_PUB_STATUS:
@@ -838,6 +845,9 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data,
 
 		bt_shell_printf("Node %4.4x: Net transmit cnt %d, steps %d\n",
 				src, data[0] & 7, data[0] >> 3);
+
+		saved = mesh_db_node_set_net_transmit(src, data[0] & 7,
+						((data[0] >> 3) + 1) * 10);
 		break;
 
 	/* Per Mesh Profile 4.3.2.54 */
@@ -855,6 +865,8 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data,
 
 		bt_shell_printf("Node %4.4x Friend state 0x%02x\n",
 				src, data[0]);
+
+		saved = mesh_db_node_set_friend(src, data[0]);
 		break;
 	}
 
diff --git a/tools/mesh/mesh-db.c b/tools/mesh/mesh-db.c
index 46efb81ea..3290c5b8e 100644
--- a/tools/mesh/mesh-db.c
+++ b/tools/mesh/mesh-db.c
@@ -137,12 +137,12 @@ static void release_config(void)
 	cfg = NULL;
 }
 
-static json_object *get_node_by_unicast(uint16_t unicast)
+static json_object *get_node_by_unicast(json_object *jcfg, uint16_t unicast)
 {
 	json_object *jarray;
 	int i, sz;
 
-	if (!json_object_object_get_ex(cfg->jcfg, "nodes", &jarray))
+	if (!json_object_object_get_ex(jcfg, "nodes", &jarray))
 		return NULL;
 
 	if (!jarray || json_object_get_type(jarray) != json_type_array)
@@ -655,7 +655,7 @@ bool mesh_db_node_set_ttl(uint16_t unicast, uint8_t ttl)
 	if (!cfg || !cfg->jcfg)
 		return false;
 
-	jnode = get_node_by_unicast(unicast);
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
 	if (!jnode)
 		return false;
 
@@ -665,12 +665,135 @@ bool mesh_db_node_set_ttl(uint16_t unicast, uint8_t ttl)
 	return save_config();
 }
 
+static bool add_transmit_info(json_object *jobj, int cnt, int interval,
+							const char *desc)
+{
+	json_object *jtxmt;
+
+	json_object_object_del(jobj, desc);
+	jtxmt = json_object_new_object();
+
+	if (!write_int(jtxmt, "count", cnt))
+		goto fail;
+
+	if (!write_int(jtxmt, "interval", interval))
+		goto fail;
+
+	json_object_object_add(jobj, desc, jtxmt);
+	return true;
+
+fail:
+	json_object_put(jtxmt);
+	return false;
+}
+
+bool mesh_db_node_set_net_transmit(uint16_t unicast, uint8_t cnt,
+							uint16_t interval)
+{
+	json_object *jnode;
+
+	if (!cfg || !cfg->jcfg)
+		return false;
+
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
+	if (!jnode)
+		return false;
+
+	if (!add_transmit_info(jnode, cnt, interval, "networkTransmit"))
+		return false;
+
+	return save_config();
+}
+
+static bool set_feature(json_object *jnode, const char *desc, uint8_t feature)
+{
+	json_object *jobj;
+
+	if (feature > MESH_MODE_UNSUPPORTED)
+		return false;
+
+	jobj = json_object_object_get(jnode, "features");
+	if (!jobj) {
+		jobj = json_object_new_object();
+		json_object_object_add(jnode, "features", jobj);
+	}
+
+	if (!write_int(jobj, desc, feature))
+		return false;
+
+	return save_config();
+}
+
+bool mesh_db_node_set_relay(uint16_t unicast, uint8_t relay, uint8_t cnt,
+							uint16_t interval)
+{
+	json_object *jnode;
+
+	if (!cfg || !cfg->jcfg)
+		return false;
+
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
+	if (!jnode)
+		return false;
+
+	if (relay < MESH_MODE_UNSUPPORTED &&
+		!add_transmit_info(jnode, cnt, interval, "relayRetransmit"))
+		return false;
+
+	return set_feature(jnode, "relay", relay);
+}
+
+bool mesh_db_node_set_proxy(uint16_t unicast, uint8_t proxy)
+{
+	json_object *jnode;
+
+	if (!cfg || !cfg->jcfg)
+		return false;
+
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
+	if (!jnode)
+		return false;
+
+	return set_feature(jnode, "proxy", proxy);
+}
+
+bool mesh_db_node_set_friend(uint16_t unicast, uint8_t friend)
+{
+	json_object *jnode;
+
+	if (!cfg || !cfg->jcfg)
+		return false;
+
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
+	if (!jnode)
+		return false;
+
+	return set_feature(jnode, "friend", friend);
+}
+
+bool mesh_db_node_set_beacon(uint16_t unicast, bool enabled)
+{
+	json_object *jnode;
+
+	if (!cfg || !cfg->jcfg)
+		return false;
+
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
+	if (!jnode)
+		return false;
+
+	if (!write_bool(jnode, "secureNetworkBeacon", enabled))
+		return false;
+
+	return save_config();
+}
+
 static json_object *get_element(uint16_t unicast, uint16_t ele_addr)
 {
 	json_object *jnode, *jarray;
 	int i, ele_cnt;
 
-	jnode = get_node_by_unicast(unicast);
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
 	if (!jnode)
 		return false;
 
@@ -993,23 +1116,6 @@ bool mesh_db_node_model_overwrt_sub_virt(uint16_t unicast, uint16_t ele,
 	return sub_overwrite(unicast, ele, vendor, mod_id, buf);
 }
 
-static bool add_transmit_info(json_object *jobj, int cnt, int interval,
-							const char *desc)
-{
-	json_object *jtxmt;
-
-	jtxmt = json_object_new_object();
-
-	if (!write_int(jtxmt, "count", cnt))
-		return false;
-
-	if (!write_int(jtxmt, "interval", interval))
-		return false;
-
-	json_object_object_add(jobj, desc, jtxmt);
-	return true;
-}
-
 bool mesh_db_node_model_set_pub(uint16_t unicast, uint16_t ele_addr,
 					bool vendor, uint32_t mod_id,
 					struct model_pub *pub, bool virt)
@@ -1113,7 +1219,7 @@ bool mesh_db_node_add_net_key(uint16_t unicast, uint16_t idx)
 	if (!cfg || !cfg->jcfg)
 		return false;
 
-	jnode = get_node_by_unicast(unicast);
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
 	if (!jnode)
 		return false;
 
@@ -1127,7 +1233,7 @@ bool mesh_db_node_del_net_key(uint16_t unicast, uint16_t net_idx)
 	if (!cfg || !cfg->jcfg)
 		return false;
 
-	jnode = get_node_by_unicast(unicast);
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
 	if (!jnode)
 		return false;
 
@@ -1143,7 +1249,7 @@ static bool key_update(uint16_t unicast, int16_t idx, bool updated,
 	if (!cfg || !cfg->jcfg)
 		return false;
 
-	jnode = get_node_by_unicast(unicast);
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
 	if (!jnode)
 		return false;
 
@@ -1180,7 +1286,7 @@ bool mesh_db_node_add_app_key(uint16_t unicast, uint16_t idx)
 	if (!cfg || !cfg->jcfg)
 		return false;
 
-	jnode = get_node_by_unicast(unicast);
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
 	if (!jnode)
 		return false;
 
@@ -1194,7 +1300,7 @@ bool mesh_db_node_del_app_key(uint16_t unicast, uint16_t idx)
 	if (!cfg || !cfg->jcfg)
 		return false;
 
-	jnode = get_node_by_unicast(unicast);
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
 	if (!jnode)
 		return false;
 
@@ -1635,7 +1741,7 @@ bool mesh_db_node_set_composition(uint16_t unicast, uint8_t *data, uint16_t len)
 	if (!cfg || !cfg->jcfg)
 		return false;
 
-	jnode = get_node_by_unicast(unicast);
+	jnode = get_node_by_unicast(cfg->jcfg, unicast);
 	if (!jnode)
 		return false;
 
diff --git a/tools/mesh/mesh-db.h b/tools/mesh/mesh-db.h
index 147fbf98c..b3b0bce79 100644
--- a/tools/mesh/mesh-db.h
+++ b/tools/mesh/mesh-db.h
@@ -37,6 +37,11 @@ bool mesh_db_add_provisioner(const char *name, uint8_t uuid[16],
 				uint16_t group_low, uint16_t group_high);
 bool mesh_db_node_set_net_transmit(uint16_t unicast, uint8_t cnt,
 							uint16_t interval);
+bool mesh_db_node_set_relay(uint16_t unicast, uint8_t relay, uint8_t cnt,
+							uint16_t interval);
+bool mesh_db_node_set_proxy(uint16_t unicast, uint8_t proxy);
+bool mesh_db_node_set_friend(uint16_t unicast, uint8_t friend);
+bool mesh_db_node_set_beacon(uint16_t unicast, bool enabled);
 bool mesh_db_node_add_net_key(uint16_t unicast, uint16_t idx);
 bool mesh_db_node_del_net_key(uint16_t unicast, uint16_t idx);
 bool mesh_db_node_update_net_key(uint16_t unicast, uint16_t idx, bool updated);
-- 
2.31.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux