From 841b9cc8ba6b468d795358d39737a5869334907f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Wed, 18 Jul 2018 11:49:36 +0200 Subject: [PATCH] mesh: Add option to not compile Mesh settings/storage --- nimble/host/mesh/include/mesh/glue.h | 21 ++++++++++++++------- nimble/host/mesh/pkg.yml | 6 ++++-- nimble/host/mesh/src/glue.c | 9 ++++++++- nimble/host/mesh/src/mesh.c | 6 +++--- nimble/host/mesh/src/settings.c | 6 ++++++ 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/nimble/host/mesh/include/mesh/glue.h b/nimble/host/mesh/include/mesh/glue.h index 26455e821..cad834a05 100644 --- a/nimble/host/mesh/include/mesh/glue.h +++ b/nimble/host/mesh/include/mesh/glue.h @@ -41,7 +41,9 @@ #include "tinycrypt/cmac_mode.h" #include "tinycrypt/ecc_dh.h" +#if MYNEWT_VAL(BLE_MESH_SETTINGS) #include "config/config.h" +#endif #define u8_t uint8_t #define s8_t int8_t @@ -430,13 +432,8 @@ void net_buf_slist_merge_slist(struct net_buf_slist_t *list, struct net_buf_slist_t *list_to_append); #define NET_BUF_SLIST_FOR_EACH_NODE(head, var) STAILQ_FOREACH(var, head, omp_next) -/** - * Load serialized items from registered persistence sources. Handlers for - * serialized item subtrees registered earlier will be called for encountered - * values. - * - * @return 0 on success, non-zero on failure. - */ +#if MYNEWT_VAL(BLE_MESH_SETTINGS) + #define settings_load conf_load int settings_bytes_from_str(char *val_str, void *vp, int *len); char *settings_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len); @@ -445,4 +442,14 @@ char *settings_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len); #define BT_SETTINGS_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1) #define settings_save_one conf_save_one +#else + +static inline int +settings_load(void) +{ + return 0; +} + +#endif /* MYNEWT_VAL(MYNEWT_VAL_BLE_MESH_SETTINGS) */ + #endif diff --git a/nimble/host/mesh/pkg.yml b/nimble/host/mesh/pkg.yml index c06e18180..4163fe8de 100644 --- a/nimble/host/mesh/pkg.yml +++ b/nimble/host/mesh/pkg.yml @@ -30,14 +30,16 @@ pkg.deps: - "@apache-mynewt-core/kernel/os" - "@apache-mynewt-core/util/mem" - "@apache-mynewt-core/crypto/tinycrypt" - - "@apache-mynewt-core/encoding/base64" - - "@apache-mynewt-core/sys/config" - nimble - nimble/host pkg.deps.BLE_MESH_SHELL: - "@apache-mynewt-core/sys/shell" +pkg.deps.BLE_MESH_SETTINGS: + - "@apache-mynewt-core/encoding/base64" + - "@apache-mynewt-core/sys/config" + pkg.req_apis: - log - stats diff --git a/nimble/host/mesh/src/glue.c b/nimble/host/mesh/src/glue.c index adee86629..5933bb5ca 100644 --- a/nimble/host/mesh/src/glue.c +++ b/nimble/host/mesh/src/glue.c @@ -17,13 +17,16 @@ * under the License. */ -#include "base64/base64.h" #include "mesh/glue.h" #include "adv.h" #ifndef MYNEWT #include "nimble/nimble_port.h" #endif +#if MYNEWT_VAL(BLE_MESH_SETTINGS) +#include "base64/base64.h" +#endif + #define BT_DBG_ENABLED (MYNEWT_VAL(BLE_MESH_DEBUG)) #if MYNEWT_VAL(BLE_EXT_ADV) @@ -827,6 +830,8 @@ void net_buf_slist_merge_slist(struct net_buf_slist_t *list, STAILQ_INIT(list); } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) + int settings_bytes_from_str(char *val_str, void *vp, int *len) { *len = base64_decode(val_str, vp); @@ -844,3 +849,5 @@ char *settings_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len) return buf; } +#endif /* MYNEWT_VAL(BLE_MESH_SETTINGS) */ + diff --git a/nimble/host/mesh/src/mesh.c b/nimble/host/mesh/src/mesh.c index ac8bd5f72..4d5ed6c47 100644 --- a/nimble/host/mesh/src/mesh.c +++ b/nimble/host/mesh/src/mesh.c @@ -236,9 +236,9 @@ int bt_mesh_init(uint8_t own_addr_type, const struct bt_mesh_prov *prov, ble_gap_mesh_cb_register(bt_mesh_gap_event, NULL); - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - bt_mesh_settings_init(); - } +#if (MYNEWT_VAL(BLE_MESH_SETTINGS)) + bt_mesh_settings_init(); +#endif return 0; } diff --git a/nimble/host/mesh/src/settings.c b/nimble/host/mesh/src/settings.c index 5b103eaf0..189692d3a 100644 --- a/nimble/host/mesh/src/settings.c +++ b/nimble/host/mesh/src/settings.c @@ -4,6 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "syscfg/syscfg.h" + +#if MYNEWT_VAL(BLE_MESH_SETTINGS) + #define BT_DBG_ENABLED MYNEWT_VAL(BLE_MESH_DEBUG_SETTINGS) #include "mesh/mesh.h" @@ -1573,3 +1577,5 @@ void bt_mesh_settings_init(void) k_delayed_work_init(&pending_store, store_pending); } + +#endif /* MYNEWT_VAL(BLE_MESH_SETTINGS) */