Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp26912ybl; Tue, 10 Dec 2019 16:56:50 -0800 (PST) X-Google-Smtp-Source: APXvYqy/GGAoIoRhp1AnXAjuWgqkEkt/zd2WJKDl1gtD7zJGxWLwXAtLHEBZk7BbV5YoPSmt3d9z X-Received: by 2002:aca:4ad1:: with SMTP id x200mr721970oia.104.1576025810292; Tue, 10 Dec 2019 16:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576025810; cv=none; d=google.com; s=arc-20160816; b=kBX2RaFlvcD/eO42h+KlNee9grreg+8q9SjbKXexXqup8A+3HwJPl4f0oZZGr8VTe1 tJlEJWmUYRcYiCNodJAe4fbG4LpH4tH36rjy0KnveB+7iYlbU+PWogkyVmtC5qe7/Dky lQRtsdXHqBVTLz8PDty8F+AhBij7FSPb/q26izTtc5TeDy3/IfddqPaUPBFhm4gl+gsC yyET5a9iFjbucvaB/OputSXTIggott/F5uc3heZYO652tp9Lxdhm2ESSZjHH9NEU0fa5 i1ym7DaZmFnYFw2oDIwCEGgknCcr+MECNzzMkOaGI0RDSCGhh73Ah+5XDaapWsUMagWV SsEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=gQlC4HRpPF5hxfChQ3nyJJc3ZRThY2kAAtTVlW2Ja00=; b=le+3HInMN6AwLLuJVxwQzDHKi1qz5MAG/R1Z9tkk+gAIFlgjddEYndWbBjCC8Ut9Ov R9TMWN178LJtC//2aZXDTCgUOWTkTMFiKDyAQtnxqpo3lG5EVYPw9u5v6QcEjbo6HoGq NKcF2wwLtblzIOTrW0aCUgon4k5PQuVeAPmba1qaJjf0qMvNm6f8RvwJyw0W9glNQw9V jP9QiwzrHhvV7ilT0/zWZopp+ee6Q7JZwMmRg3i/SDVs9fKBNgI6Mh2u1ZdkvGJeTc3s ib/ix8dTEmmJZjdyT/IUCLB6htFDfTYTU9pLndO9GCwReokWIxNo0/vykpGE0ZFSCg4D Yx1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si93518otp.57.2019.12.10.16.56.21; Tue, 10 Dec 2019 16:56:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726364AbfLKA4S (ORCPT + 99 others); Tue, 10 Dec 2019 19:56:18 -0500 Received: from mga07.intel.com ([134.134.136.100]:20891 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfLKA4S (ORCPT ); Tue, 10 Dec 2019 19:56:18 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 16:56:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,301,1571727600"; d="scan'208";a="207494748" Received: from ingas-nuc1.sea.intel.com ([10.254.187.166]) by orsmga008.jf.intel.com with ESMTP; 10 Dec 2019 16:56:17 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ] mesh: Add mesh-main.conf file with general mesh configuration Date: Tue, 10 Dec 2019 16:56:16 -0800 Message-Id: <20191211005616.28722-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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. --- Makefile.mesh | 2 +- mesh/main.c | 10 +++-- mesh/mesh-main.conf | 43 +++++++++++++++++++ mesh/mesh.c | 102 +++++++++++++++++++++++++++++++++++++++++--- mesh/mesh.h | 8 +++- mesh/node.c | 12 +++--- 6 files changed, 162 insertions(+), 15 deletions(-) create mode 100644 mesh/mesh-main.conf diff --git a/Makefile.mesh b/Makefile.mesh index 90979cbc0..401122029 100644 --- a/Makefile.mesh +++ b/Makefile.mesh @@ -48,4 +48,4 @@ CLEANFILES += mesh/bluetooth-mesh.service endif 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 diff --git a/mesh/main.c b/mesh/main.c index 3c41acb75..010edcf85 100644 --- a/mesh/main.c +++ b/mesh/main.c @@ -39,6 +39,7 @@ #include "mesh/mesh-io.h" static const char *config_dir; +static const char *mesh_conf_fname; static int ctlr_index = MGMT_INDEX_NONE; static const struct option main_options[] = { @@ -99,8 +100,8 @@ static void request_name_callback(struct l_dbus *dbus, bool success, return; } - if (!mesh_init(config_dir, MESH_IO_TYPE_GENERIC, &ctlr_index, - mesh_ready_callback, dbus)) { + if (!mesh_init(config_dir, mesh_conf_fname, MESH_IO_TYPE_GENERIC, + &ctlr_index, mesh_ready_callback, dbus)) { l_error("Failed to initialize mesh"); l_main_quit(); } @@ -154,7 +155,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; @@ -182,6 +183,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; diff --git a/mesh/mesh-main.conf b/mesh/mesh-main.conf new file mode 100644 index 000000000..aca9e6fa5 --- /dev/null +++ b/mesh/mesh-main.conf @@ -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 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; diff --git a/mesh/mesh.h b/mesh/mesh.h index c72632b15..eb887723d 100644 --- a/mesh/mesh.h +++ b/mesh/mesh.h @@ -34,7 +34,8 @@ 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); @@ -46,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); diff --git a/mesh/node.c b/mesh/node.c index f8acc78c3..e1d01d9b3 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -265,12 +265,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; } @@ -1299,7 +1301,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")) { -- 2.21.0