Skip to contentSkip to conversation

mesh: validate configuration target

PATCH Applied Inga Stotland 2 participants 2 messages Nov 21, 2017 – Nov 23, 2017 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mesh: validate configuration target

Require obtaining node composition prior to sending configuration commands that assume knowledge about the node's element/model layout.

---
 mesh/config-client.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
mesh/config-client.c +25 -6
index d80f784e6..782781602 100644
@@ -461,16 +461,37 @@ static void cmd_del_app_key(const char *args)
 	cmd_app_key(args, OP_APPKEY_DELETE);
 }
 
+static bool verify_config_target(uint32_t dst)
+{
+	struct mesh_node *node;
+
+	if (IS_UNASSIGNED(dst)) {
+		rl_printf("Destination not set\n");
+		return false;
+	}
+
+	node = node_find_by_addr(dst);
+	if (!node) {
+		rl_printf("Node with unicast address %4.4x unknown\n", dst);
+		return false;
+	}
+
+	if (!node_get_composition(node)) {
+		rl_printf("Node composition for %4.4x unknown\n", dst);
+		return false;
+	}
+
+	return true;
+}
+
 static void cmd_bind(const char *args)
 {
 	uint16_t n;
 	uint8_t msg[32];
 	int parm_cnt;
 
-	if (IS_UNASSIGNED(target)) {
-		rl_printf("Destination not set\n");
+	if (!verify_config_target(target))
 		return;
-	}
 
 	parm_cnt = read_input_parameters(args);
 	if (parm_cnt != 3 && parm_cnt != 4) {
@@ -529,10 +550,8 @@ static void cmd_set_pub(const char *args)
 	uint8_t msg[32];
 	int parm_cnt;
 
-	if (IS_UNASSIGNED(target)) {
-		rl_printf("Destination not set\n");
+	if (!verify_config_target(target))
 		return;
-	}
 
 	n = mesh_opcode_set(OP_CONFIG_MODEL_PUB_SET, msg);
 
Signature · 1 line
2.13.6
maintainer Applied
#1 lore raw

Hi Inga,

Quoted 64 lines · Inga Stotland

Require obtaining node composition prior to sending configuration commands that assume knowledge about the node's element/model layout.

---
 mesh/config-client.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
mesh/config-client.c +25 -7
index d80f784e6..782781602 100644
@@ -461,16 +461,37 @@ static void cmd_del_app_key(const char *args)
        cmd_app_key(args, OP_APPKEY_DELETE);
 }
 
+static bool verify_config_target(uint32_t dst)
+{
+       struct mesh_node *node;
+
+       if (IS_UNASSIGNED(dst)) {
+               rl_printf("Destination not set\n");
+               return false;
+       }
+
+       node = node_find_by_addr(dst);
+       if (!node) {
+               rl_printf("Node with unicast address %4.4x unknown\n", dst);
+               return false;
+       }
+
+       if (!node_get_composition(node)) {
+               rl_printf("Node composition for %4.4x unknown\n", dst);
+               return false;
+       }
+
+       return true;
+}
+
 static void cmd_bind(const char *args)
 {
        uint16_t n;
        uint8_t msg[32];
        int parm_cnt;
 
-       if (IS_UNASSIGNED(target)) {
-               rl_printf("Destination not set\n");
+       if (!verify_config_target(target))
                return;
-       }
 
        parm_cnt = read_input_parameters(args);
        if (parm_cnt != 3 && parm_cnt != 4) {
@@ -529,10 +550,8 @@ static void cmd_set_pub(const char *args)
        uint8_t msg[32];
        int parm_cnt;
 
-       if (IS_UNASSIGNED(target)) {
-               rl_printf("Destination not set\n");
+       if (!verify_config_target(target))
                return;
-       }
 
        n = mesh_opcode_set(OP_CONFIG_MODEL_PUB_SET, msg);
 
--
Quoted 1 line

2.13.6

Applied, thanks.

Signature · 1 line
Luiz Augusto von Dentz