mesh: Move network config setup from storage.c to node.c
authorInga Stotland <inga.stotland@intel.com>
Sun, 14 Jul 2019 23:23:11 +0000 (16:23 -0700)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 17 Dec 2019 15:48:36 +0000 (21:18 +0530)
This commit moves initialization of configuration parameters
for node->net when the local node state is restored from stored
configuration. Old location: storage.c, new locaiton node.c.

Change-Id: I7e9577f6da3e6418eacdf2e97a95250ee1cb4357
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
mesh/node.c
mesh/storage.c

index c673cb7..3a3326e 100644 (file)
@@ -378,6 +378,7 @@ bool node_init_from_storage(struct mesh_node *node, void *data)
 {
        struct mesh_db_node *db_node = data;
        unsigned int num_ele;
+       uint8_t mode;
 
        node->comp = l_new(struct node_composition, 1);
        node->comp->cid = db_node->cid;
@@ -410,6 +411,33 @@ bool node_init_from_storage(struct mesh_node *node, void *data)
 
        node->primary = db_node->unicast;
 
+       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->lpn;
+       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);
+
+       if (!IS_UNASSIGNED(node->primary) &&
+               !mesh_net_register_unicast(node->net, node->primary, num_ele))
+               return false;
+
+       if (node->uuid)
+               mesh_net_id_uuid_set(node->net, node->uuid);
+
        /* Initialize configuration server model */
        mesh_config_srv_init(node, PRIMARY_ELE_IDX);
 
index 754e0a8..a337f2c 100644 (file)
@@ -55,51 +55,12 @@ static const char *storage_dir;
 static bool read_node_cb(struct mesh_db_node *db_node, void *user_data)
 {
        struct mesh_node *node = user_data;
-       struct mesh_net *net;
-       uint32_t seq_number;
-       uint8_t ttl, mode, cnt, num_ele;
-       uint16_t unicast, interval;
-       uint8_t *uuid;
 
        if (!node_init_from_storage(node, db_node)) {
                node_remove(node);
                return false;
        }
 
-       net = node_get_net(node);
-       seq_number = node_get_sequence_number(node);
-       mesh_net_set_seq_num(net, seq_number);
-       ttl = node_default_ttl_get(node);
-       mesh_net_set_default_ttl(net, ttl);
-
-       mode = node_proxy_mode_get(node);
-       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-               mesh_net_set_proxy_mode(net, mode == MESH_MODE_ENABLED);
-
-       mode = node_friend_mode_get(node);
-       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-               mesh_net_set_friend_mode(net, mode == MESH_MODE_ENABLED);
-
-       mode = node_relay_mode_get(node, &cnt, &interval);
-       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-               mesh_net_set_relay_mode(net, mode == MESH_MODE_ENABLED, cnt,
-                                                               interval);
-
-       mode = node_beacon_mode_get(node);
-       if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-               mesh_net_set_beacon_mode(net, mode == MESH_MODE_ENABLED);
-
-       unicast = db_node->unicast;
-       num_ele = node_get_num_elements(node);
-
-       if (!IS_UNASSIGNED(unicast) &&
-               !mesh_net_register_unicast(net, unicast, num_ele))
-               return false;
-
-       uuid = node_uuid_get(node);
-       if (uuid)
-               mesh_net_id_uuid_set(net, uuid);
-
        return true;
 }