mesh: fix node default TTL
authorAurelien Jarno <aurelien@aurel32.net>
Fri, 18 Dec 2020 06:30:30 +0000 (12:00 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 28 Dec 2020 06:20:04 +0000 (11:50 +0530)
There is a confusion between the node default TTL (section 4.2.7) and
the publish TTL (section 4.2.2.5):

- The node default TTL can only take values 0x00, and 0x02 to 0x7f. The
  value 0xff is not prohibited.
- The publish TTL can take values 0x00 to 0x7f, as well as 0xff which
  means use the node default TTL.

Currently the default node TTL is set to 0xff (DEFAULT_TTL), and
read_default_ttl() also allows such a value. This patch fixes that to
use 0x7f (TTL_MASK) as the default value instead.

Note that the code handling OP_CONFIG_DEFAULT_TTL_SET correctly use 0x7f
(TTL_MASK) for the upper allowed limit.

Change-Id: If894a9eb88bd129293845c068e0b6f3685495a4c
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
mesh/cfgmod-server.c
mesh/mesh-config-json.c
mesh/node.c

index af48f9f..5eefedc 100644 (file)
@@ -158,8 +158,8 @@ static uint16_t config_pub_set(struct mesh_node *node, const uint8_t *pkt,
 
                /* Save model publication to config file */
                if (!mesh_config_model_pub_add(node_config_get(node), ele_addr,
-                                       vendor ? id : MODEL_ID(id),
-                                       vendor, &db_pub))
+                                               vendor ? id : MODEL_ID(id),
+                                               vendor, &db_pub))
                        status = MESH_STATUS_STORAGE_FAIL;
        }
 
@@ -168,7 +168,7 @@ static uint16_t config_pub_set(struct mesh_node *node, const uint8_t *pkt,
 }
 
 static uint16_t cfg_sub_get_msg(struct mesh_node *node, const uint8_t *pkt,
-                                                                       uint16_t size)
+                                                               uint16_t size)
 {
        uint16_t ele_addr, n, sub_len;
        uint32_t id;
@@ -214,8 +214,9 @@ static bool save_cfg_sub(struct mesh_node *node, uint16_t ele_addr,
 
        if (opcode == OP_CONFIG_MODEL_SUB_VIRT_OVERWRITE ||
                                        opcode == OP_CONFIG_MODEL_SUB_OVERWRITE)
+
                if (!mesh_config_model_sub_del_all(cfg, ele_addr, id, vendor))
-                               return false;
+                       return false;
 
        return mesh_config_model_sub_add(cfg, ele_addr, id, vendor, &db_sub);
 }
@@ -246,7 +247,6 @@ static uint16_t cfg_sub_add_msg(struct mesh_node *node, const uint8_t *pkt,
        if (msg[n] == MESH_STATUS_SUCCESS &&
                        !save_cfg_sub(node, ele_addr, id, vendor, NULL, false,
                                                                addr, opcode))
-
                msg[n] = MESH_STATUS_STORAGE_FAIL;
 
        if (vendor) {
@@ -318,6 +318,7 @@ static uint16_t config_sub_del_all(struct mesh_node *node, const uint8_t *pkt,
 
        if (msg[n] == MESH_STATUS_SUCCESS) {
                struct mesh_config *cfg = node_config_get(node);
+
                if (!mesh_config_model_sub_del_all(cfg, ele_addr,
                                                vendor ? id : MODEL_ID(id),
                                                vendor))
index f3ba1a0..d6bf61f 100644 (file)
@@ -321,7 +321,7 @@ static bool read_default_ttl(json_object *jobj, uint8_t *ttl)
        if (!val && errno == EINVAL)
                return false;
 
-       if (val < 0 || val == 1 || val > DEFAULT_TTL)
+       if (val < 0 || val == 1 || val > TTL_MASK)
                return false;
 
        *ttl = (uint8_t) val;
index 0ec9325..d2e420e 100644 (file)
@@ -610,7 +610,7 @@ struct l_queue *node_get_element_models(struct mesh_node *node, uint8_t ele_idx)
 uint8_t node_default_ttl_get(struct mesh_node *node)
 {
        if (!node)
-               return DEFAULT_TTL;
+               return TTL_MASK;
        return node->ttl;
 }