mesh: Add mesh-main.conf file with general mesh configuration
authorInga Stotland <inga.stotland@intel.com>
Wed, 11 Dec 2019 00:56:16 +0000 (16:56 -0800)
committerAnupam Roy <anupam.r@samsung.com>
Wed, 18 Dec 2019 11:49:13 +0000 (17:19 +0530)
This adds key file with default settings for the mesh daemon.
The following settings are included:

    Beacon:          Default setting for to indicate whether
                     secure network beaconing is enabled for a
                     node whose Beacon state hasn't been configured
                     by a configuration client, i.e., this setting
                     apllies to a newly provisioned, created or
                     imported node.

    Relay:           Default setting for supporting relay

    Friendship:      Default setting for supporting Friendship

    CRPL:            Default depth of replay protection list.

    FriendQueueSize: Default size of friend queue: the number
                     of messages that each Friend node can store
                     for the Low Power node.

    ProvTimeout:     Provisioning timeout in seconds.

Change-Id: Ia5f40ef9d5d866e8d94a2ff5cac7cf6339015eca
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Makefile.mesh
mesh/main.c
mesh/mesh-main.conf [new file with mode: 0644]
mesh/mesh.c
mesh/mesh.h
mesh/node.c

index 2fb3731..54f2f67 100644 (file)
@@ -44,7 +44,7 @@ mesh_bluetooth_meshd_DEPENDENCIES = $(ell_dependencies) src/libshared-ell.la \
                                mesh/bluetooth-mesh.service
 
 EXTRA_DIST += mesh/bluetooth-mesh.conf mesh/bluetooth-mesh.service.in \
-               mesh/org.bluez.mesh.service
+                       mesh/org.bluez.mesh.service mesh/mesh-main.conf
 
 CLEANFILES += mesh/bluetooth-mesh.service
 
index bf91c94..de1d578 100644 (file)
@@ -114,6 +114,7 @@ int main(int argc, char *argv[])
        bool dbus_debug = false;
        struct l_dbus *dbus = NULL;
        const char *config_dir = NULL;
+       static const char *mesh_conf_fname;
        int index = MGMT_INDEX_NONE;
 
        if (!l_main_init())
@@ -131,7 +132,7 @@ int main(int argc, char *argv[])
                int opt;
                const char *str;
 
-               opt = getopt_long(argc, argv, "i:c:ndbh", main_options, NULL);
+               opt = getopt_long(argc, argv, "i:c:f:ndbh", main_options, NULL);
                if (opt < 0)
                        break;
 
@@ -159,6 +160,9 @@ int main(int argc, char *argv[])
                case 'c':
                        config_dir = optarg;
                        break;
+               case 'f':
+                       mesh_conf_fname = optarg;
+                       break;
                case 'b':
                        dbus_debug = true;
                        break;
@@ -173,8 +177,8 @@ int main(int argc, char *argv[])
                }
        }
 
-
-       if (!mesh_init(config_dir, MESH_IO_TYPE_GENERIC, &index)) {
+       if (!mesh_init(config_dir, mesh_conf_fname, MESH_IO_TYPE_GENERIC,
+                               &ctlr_index, mesh_ready_callback, dbus)) {
                l_error("Failed to initialize mesh");
                status = EXIT_FAILURE;
                goto done;
diff --git a/mesh/mesh-main.conf b/mesh/mesh-main.conf
new file mode 100644 (file)
index 0000000..aca9e6f
--- /dev/null
@@ -0,0 +1,43 @@
+[General]
+
+# Default setting for to indicate whether secure network beaconing
+# is enabled for a node whose Beacon state hasn't been configured
+# by a configuration client, i.e., for a newly provisioned, created
+# or imported node.
+# Defaults to true.
+#Beacon = true
+
+# Default setting for supporting relay. The setting applies
+# to all local nodes.
+# If the value is true, then a configuration client can either enable or disable
+# the relay feature per local node.
+# If the value is false, then the relay feature cannot be configured for
+# any local node.
+# Defaults to true.
+#Relay = true
+
+# Default setting for supporting Friendship. The setting applies
+# to all local nodes.
+# If the value is true, then a configuration client can either enable or disable
+# the Friendship feature per local node.
+# If the value is false, then the Friendship feature cannot be configured for
+# any local node.
+# Defaults to true.
+#Friendship = true
+
+# Default depth of replay protection list. This setting applies to
+# each individual node.
+# Valid range 1-65535.
+# Defaults to 100.
+#CRPL = 100
+
+# Default size of friend queue: the number of messages that each Friend node can
+# store for the Low Power node.
+# Valid range: 0-32.
+# Defaults to 32.
+#FriendQueueSize = 32
+
+# Provisioning timeout in seconds.
+# Setting this value to zero means there's no timeout.
+# Defaults to 60.
+#ProvTimeout = 60
index 66ebdc2..f2aee0b 100644 (file)
 
 /*
  * The default values for mesh configuration. Can be
- * overwritten by values from mesh.conf
+ * overwritten by values from mesh-main.conf
  */
 #define DEFAULT_PROV_TIMEOUT 60
-#define DEFAULT_ALGORITHMS 0x0001
+#define DEFAULT_CRPL 100
+#define DEFAULT_FRIEND_QUEUE_SZ 32
 
-/* TODO: add more default values */
+#define DEFAULT_ALGORITHMS 0x0001
 
 struct scan_filter {
        uint8_t id;
@@ -54,8 +55,15 @@ struct bt_mesh {
        prov_rx_cb_t prov_rx;
        void *prov_data;
        uint32_t prov_timeout;
+       bool beacon_enabled;
+       bool friend_support;
+       bool relay_support;
+       bool lpn_support;
+       bool proxy_support;
+       uint16_t crpl;
        uint16_t algorithms;
        uint16_t req_index;
+       uint8_t friend_queue_sz;
        uint8_t max_filters;
 };
 
@@ -69,7 +77,17 @@ struct join_data{
        uint8_t *uuid;
 };
 
-static struct bt_mesh mesh;
+static struct bt_mesh mesh = {
+       .algorithms = DEFAULT_ALGORITHMS,
+       .prov_timeout = DEFAULT_PROV_TIMEOUT,
+       .beacon_enabled = true,
+       .friend_support = true,
+       .relay_support = true,
+       .lpn_support = false,
+       .proxy_support = false,
+       .crpl = DEFAULT_CRPL,
+       .friend_queue_sz = DEFAULT_FRIEND_QUEUE_SZ
+};
 
 /* We allow only one outstanding Join request */
 static struct join_data *join_pending;
@@ -137,7 +155,77 @@ void mesh_unreg_prov_rx(prov_rx_cb_t cb)
        mesh_io_deregister_recv_cb(mesh.io, MESH_IO_FILTER_PROV);
 }
 
-bool mesh_init(const char *config_dir, enum mesh_io_type type, void *opts)
+bool mesh_beacon_enabled(void)
+{
+       return mesh.beacon_enabled;
+}
+
+bool mesh_relay_supported(void)
+{
+       return mesh.relay_support;
+}
+
+bool mesh_friendship_supported(void)
+{
+       return mesh.friend_support;
+}
+
+uint16_t mesh_get_crpl(void)
+{
+       return mesh.crpl;
+}
+
+uint8_t mesh_get_friend_queue_size(void)
+{
+       return mesh.friend_queue_sz;
+}
+
+static void parse_settings(const char *mesh_conf_fname)
+{
+       struct l_settings *settings;
+       char *str;
+       uint32_t value;
+
+       settings = l_settings_new();
+       if (!l_settings_load_from_file(settings, mesh_conf_fname))
+               return;
+
+       str = l_settings_get_string(settings, "General", "Beacon");
+       if (str) {
+               if (!strcasecmp(str, "true"))
+                       mesh.beacon_enabled = true;
+               l_free(str);
+       }
+
+       str = l_settings_get_string(settings, "General", "Relay");
+       if (str) {
+               if (!strcasecmp(str, "false"))
+                       mesh.relay_support = false;
+               l_free(str);
+       }
+
+       str = l_settings_get_string(settings, "General", "Friendship");
+       if (str) {
+               if (!strcasecmp(str, "false"))
+                       mesh.friend_support = false;
+               l_free(str);
+       }
+
+       if (l_settings_get_uint(settings, "General", "CRPL", &value) &&
+                       value <= 65535)
+               mesh.crpl = value;
+
+       if (l_settings_get_uint(settings, "General", "FriendQueueSize", &value)
+                       && value < 127)
+               mesh.friend_queue_sz = value;
+
+       if (l_settings_get_uint(settings, "General", "ProvTimeout", &value))
+               mesh.prov_timeout = value;
+}
+
+bool mesh_init(const char *config_dir, const char *mesh_conf_fname,
+                                       enum mesh_io_type type, void *opts,
+                                       mesh_ready_func_t cb, void *user_data)
 {
        struct mesh_io_caps caps;
 
@@ -155,6 +243,11 @@ bool mesh_init(const char *config_dir, enum mesh_io_type type, void *opts)
 
        l_info("Loading node configuration from %s", storage_dir);
 
+       if (!mesh_conf_fname)
+               mesh_conf_fname = CONFIGDIR "/mesh-main.conf";
+
+       parse_settings(mesh_conf_fname);
+
        if (!node_load_from_storage(storage_dir))
                return false;
 
index e0a3e1b..e4541bb 100644 (file)
 
 enum mesh_io_type;
 
+typedef void (*mesh_ready_func_t)(void *user_data, bool success);
 typedef void (*prov_rx_cb_t)(void *user_data, const uint8_t *data,
                                                                uint16_t len);
-bool mesh_init(const char *in_config_name, enum mesh_io_type type, void *opts);
+
+bool mesh_init(const char *config_dir, const char *mesh_conf_fname,
+                                        enum mesh_io_type type, void *opts,
+                                        mesh_ready_func_t cb, void *user_data);
 void mesh_cleanup(void);
 bool mesh_dbus_init(struct l_dbus *dbus);
 
@@ -43,3 +47,8 @@ bool mesh_reg_prov_rx(prov_rx_cb_t cb, void *user_data);
 void mesh_unreg_prov_rx(prov_rx_cb_t cb);
 const char *mesh_prov_status_str(uint8_t status);
 const char *mesh_get_storage_dir(void);
+bool mesh_beacon_enabled(void);
+bool mesh_relay_supported(void);
+bool mesh_friendship_supported(void);
+uint16_t mesh_get_crpl(void);
+uint8_t mesh_get_friend_queue_size(void);
index 40853cb..d2e959e 100644 (file)
@@ -264,12 +264,14 @@ static void add_internal_model(struct mesh_node *node, uint32_t mod_id,
 
 static void set_defaults(struct mesh_node *node)
 {
-       /* TODO: these values should come from mesh.conf */
        node->lpn = MESH_MODE_UNSUPPORTED;
        node->proxy = MESH_MODE_UNSUPPORTED;
-       node->friend = MESH_MODE_UNSUPPORTED;
-       node->beacon = MESH_MODE_DISABLED;
-       node->relay.mode = MESH_MODE_DISABLED;
+       node->friend = (mesh_friendship_supported()) ? MESH_MODE_DISABLED :
+                                                       MESH_MODE_UNSUPPORTED;
+       node->beacon = (mesh_beacon_enabled()) ? MESH_MODE_ENABLED :
+                                                       MESH_MODE_DISABLED;
+       node->relay.mode = (mesh_relay_supported()) ? MESH_MODE_DISABLED :
+                                                       MESH_MODE_UNSUPPORTED;
        node->ttl = TTL_MASK;
        node->seq_number = DEFAULT_SEQUENCE_NUMBER;
 }
@@ -1293,7 +1295,7 @@ static bool get_app_properties(struct mesh_node *node, const char *path,
        l_debug("path %s", path);
 
        node->comp = l_new(struct node_composition, 1);
-       node->comp->crpl = DEFAULT_CRPL;
+       node->comp->crpl = mesh_get_crpl();
 
        while (l_dbus_message_iter_next_entry(properties, &key, &variant)) {
                if (!cid && !strcmp(key, "CompanyID")) {