diff options
author | Inga Stotland <inga.stotland@intel.com> | 2019-12-10 16:56:16 -0800 |
---|---|---|
committer | Brian Gix <brian.gix@intel.com> | 2019-12-16 14:52:36 -0800 |
commit | 4a1bea28b15b4ab9b9c962597162cb4070587763 (patch) | |
tree | 5c6cbdc6919d9dfa7fc10912b1ab43997d70467a /mesh/mesh.c | |
parent | cf0a39476e5f2bb8a4617b7e6482c17f3aafe6ee (diff) | |
download | bluez-4a1bea28b15b4ab9b9c962597162cb4070587763.tar.gz |
mesh: Add mesh-main.conf file with general mesh configuration
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.
Diffstat (limited to 'mesh/mesh.c')
-rw-r--r-- | mesh/mesh.c | 102 |
1 files changed, 97 insertions, 5 deletions
diff --git a/mesh/mesh.c b/mesh/mesh.c index 68cf0cd12..6d2f86b6d 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -37,12 +37,13 @@ /* * 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; @@ -55,8 +56,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; }; @@ -75,7 +83,17 @@ struct mesh_init_request { void *user_data; }; -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; @@ -155,7 +173,76 @@ static void io_ready_callback(void *user_data, bool result) l_free(req); } -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; @@ -175,6 +262,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; |