mesh: Initialize net modes based on node configuration
authorInga Stotland <inga.stotland@intel.com>
Fri, 6 Dec 2019 20:57:49 +0000 (12:57 -0800)
committerAnupam Roy <anupam.r@samsung.com>
Wed, 18 Dec 2019 11:49:13 +0000 (17:19 +0530)
This correctly initializes net settings related to node features
based on node configuration: either defaults in the case of
a newly node created/provisioned/imported node or the configured
values read from stored existing node.

Change-Id: Id0d7a7e2ba2ea7e4dc3cdc17b241250581a14af1
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
mesh/mesh-defs.h
mesh/net.c
mesh/node.c

index 8f28fc8..9353d73 100644 (file)
 #define APP_IDX_DEV_REMOTE     0x6fff
 #define APP_IDX_DEV_LOCAL      0x7fff
 
+#define DEFAULT_SEQUENCE_NUMBER 0x000000
+
 #define IS_UNASSIGNED(x)       ((x) == UNASSIGNED_ADDRESS)
 #define IS_UNICAST(x)          (((x) > UNASSIGNED_ADDRESS) && \
                                        ((x) < VIRTUAL_ADDRESS_LOW))
index 5b9622b..83fa31b 100644 (file)
@@ -677,20 +677,9 @@ struct mesh_net *mesh_net_new(struct mesh_node *node)
        net = l_new(struct mesh_net, 1);
 
        net->node = node;
-       net->pkt_id = 0;
-       net->bea_id = 0;
-
-       net->beacon_enable = true;
-       net->proxy_enable = false;
-       net->relay.enable = false;
-
-       net->seq_num = 0x000000;
-       net->src_addr = 0x0000;
-       net->default_ttl = 0x7f;
-
-       net->provisioner = false;
+       net->seq_num = DEFAULT_SEQUENCE_NUMBER;
+       net->default_ttl = TTL_MASK;
 
-       net->test_mode = false;
        memset(&net->prov_caps, 0, sizeof(net->prov_caps));
        net->prov_caps.algorithms = 1;
 
index d173059..9d7deed 100644 (file)
@@ -56,7 +56,6 @@
 #define DEFAULT_LOCATION 0x0000
 
 #define DEFAULT_CRPL 10
-#define DEFAULT_SEQUENCE_NUMBER 0
 
 enum request_type {
        REQUEST_TYPE_JOIN,
@@ -218,6 +217,7 @@ static int compare_model_id(const void *a, const void *b, void *user_data)
        return 0;
 }
 
+
 struct mesh_node *node_find_by_addr(uint16_t addr)
 {
        if (!IS_UNICAST(addr))
@@ -477,12 +477,34 @@ static bool init_storage_dir(struct mesh_node *node)
        return true;
 }
 
+static void update_net_settings(struct mesh_node *node)
+{
+       uint8_t mode;
+
+       mode = node->proxy;
+       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
+               mesh_net_set_proxy_mode(node->net, mode == MESH_MODE_ENABLED);
+
+       mode = node->friend;
+       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
+               mesh_net_set_friend_mode(node->net, mode == MESH_MODE_ENABLED);
+
+       mode = node->relay.mode;
+       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
+               mesh_net_set_relay_mode(node->net, mode == MESH_MODE_ENABLED,
+                                       node->relay.cnt, node->relay.interval);
+
+       mode = node->beacon;
+       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
+               mesh_net_set_beacon_mode(node->net, mode == MESH_MODE_ENABLED);
+}
+
 static bool init_from_storage(struct mesh_config_node *db_node,
                        const uint8_t uuid[16], struct mesh_config *cfg,
                        void *user_data)
 {
        unsigned int num_ele;
-       uint8_t mode;
+
        struct mesh_node *node = node_new(uuid);
 
        if (!nodes)
@@ -545,22 +567,7 @@ static bool init_from_storage(struct mesh_config_node *db_node,
        mesh_net_set_seq_num(node->net, node->seq_number);
        mesh_net_set_default_ttl(node->net, node->ttl);
 
-       mode = node->proxy;
-       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-               mesh_net_set_proxy_mode(node->net, mode == MESH_MODE_ENABLED);
-
-       mode = node->friend;
-       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-               mesh_net_set_friend_mode(node->net, mode == MESH_MODE_ENABLED);
-
-       mode = node->relay.mode;
-       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-               mesh_net_set_relay_mode(node->net, mode == MESH_MODE_ENABLED,
-                                       node->relay.cnt, node->relay.interval);
-
-       mode = node->beacon;
-       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-               mesh_net_set_beacon_mode(node->net, mode == MESH_MODE_ENABLED);
+       update_net_settings(node);
 
        /* Initialize configuration server model */
        cfgmod_server_init(node, PRIMARY_ELE_IDX);
@@ -1365,6 +1372,8 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
                        return false;
        }
 
+       update_net_settings(node);
+
        mesh_config_save(node->cfg, true, NULL, NULL);
 
        /* Initialize configuration server model */