From 039e3ca80e7e333dc9b726c6f4da1eaebdfe3265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Mon, 25 Oct 2021 10:09:15 +0200 Subject: [PATCH] host/mesh: add preprocessor directives for persistent storage After `settings` module was split among others it's necessary to compile methods depending on peristent storage only when it's enabled. --- nimble/host/mesh/src/access.c | 6 ++++++ nimble/host/mesh/src/app_keys.c | 14 ++++++++++++++ nimble/host/mesh/src/cfg.c | 5 ++++- nimble/host/mesh/src/heartbeat.c | 6 +++++- nimble/host/mesh/src/net.c | 10 ++++++++++ nimble/host/mesh/src/pb_gatt_srv.c | 2 +- nimble/host/mesh/src/proxy_msg.c | 2 +- nimble/host/mesh/src/proxy_msg.h | 2 +- nimble/host/mesh/src/rpl.c | 16 ++++++++++++++++ nimble/host/mesh/src/subnet.c | 18 +++++++++++++++++- nimble/host/mesh/src/transport.c | 6 ++++++ 11 files changed, 81 insertions(+), 6 deletions(-) diff --git a/nimble/host/mesh/src/access.c b/nimble/host/mesh/src/access.c index 28402885c..e498910db 100644 --- a/nimble/host/mesh/src/access.c +++ b/nimble/host/mesh/src/access.c @@ -875,6 +875,7 @@ bool bt_mesh_model_is_extended(struct bt_mesh_model *model) return model->flags & BT_MESH_MOD_EXTENDED; } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static int mod_set_bind(struct bt_mesh_model *mod, char *val) { int len, err, i; @@ -1246,6 +1247,7 @@ int bt_mesh_model_data_store(struct bt_mesh_model *mod, bool vnd, } return err; } +#endif static void commit_mod(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd, bool primary, void *user_data) @@ -1276,6 +1278,7 @@ void bt_mesh_model_settings_commit(void) bt_mesh_model_foreach(commit_mod, NULL); } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static struct conf_handler bt_mesh_sig_mod_conf_handler = { .ch_name = "bt_mesh", .ch_get = NULL, @@ -1291,9 +1294,11 @@ static struct conf_handler bt_mesh_vnd_mod_conf_handler = { .ch_commit = NULL, .ch_export = NULL, }; +#endif void bt_mesh_access_init(void) { + #if MYNEWT_VAL(BLE_MESH_SETTINGS) int rc; rc = conf_register(&bt_mesh_sig_mod_conf_handler); @@ -1304,4 +1309,5 @@ void bt_mesh_access_init(void) SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register bt_mesh_access conf"); + #endif } \ No newline at end of file diff --git a/nimble/host/mesh/src/app_keys.c b/nimble/host/mesh/src/app_keys.c index e13245af8..97589968d 100644 --- a/nimble/host/mesh/src/app_keys.c +++ b/nimble/host/mesh/src/app_keys.c @@ -76,6 +76,7 @@ static struct app_key *app_get(uint16_t app_idx) static void clear_app_key(uint16_t app_idx) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) char path[20]; int err; @@ -88,10 +89,12 @@ static void clear_app_key(uint16_t app_idx) } else { BT_DBG("Cleared AppKeyIndex 0x%03x", app_idx); } +#endif } static void store_app_key(uint16_t app_idx) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) const struct app_key *app; struct app_key_val key; char path[20]; @@ -120,8 +123,10 @@ static void store_app_key(uint16_t app_idx) } else { BT_DBG("Stored AppKey %s value"); } +#endif } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static struct app_key_update *app_key_update_find(uint16_t key_idx, struct app_key_update **free_slot) { @@ -146,9 +151,11 @@ static struct app_key_update *app_key_update_find(uint16_t key_idx, return match; } +#endif static void update_app_key_settings(uint16_t app_idx, bool store) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) struct app_key_update *update, *free_slot; uint8_t clear = store ? 0U : 1U; @@ -175,6 +182,7 @@ static void update_app_key_settings(uint16_t app_idx, bool store) free_slot->clear = clear; bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_APP_KEYS_PENDING); +#endif } static void app_key_evt(struct app_key *app, enum bt_mesh_key_evt evt) @@ -629,6 +637,7 @@ void bt_mesh_app_keys_reset(void) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static int app_key_set(int argc, char **argv, char *val) { struct app_key_val key; @@ -662,6 +671,7 @@ static int app_key_set(int argc, char **argv, char *val) return 0; } +#endif void bt_mesh_app_key_pending_store(void) { @@ -684,6 +694,7 @@ void bt_mesh_app_key_pending_store(void) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static struct conf_handler bt_mesh_app_key_conf_handler = { .ch_name = "bt_mesh", .ch_get = NULL, @@ -691,13 +702,16 @@ static struct conf_handler bt_mesh_app_key_conf_handler = { .ch_commit = NULL, .ch_export = NULL, }; +#endif void bt_mesh_app_key_init(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) int rc; rc = conf_register(&bt_mesh_app_key_conf_handler); SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register bt_mesh_app_key conf"); +#endif } \ No newline at end of file diff --git a/nimble/host/mesh/src/cfg.c b/nimble/host/mesh/src/cfg.c index e866cb791..ec68cac7b 100644 --- a/nimble/host/mesh/src/cfg.c +++ b/nimble/host/mesh/src/cfg.c @@ -250,6 +250,7 @@ bool bt_mesh_fixed_group_match(uint16_t addr) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static int cfg_set(int argc, char **argv, char *val) { struct cfg_val cfg; @@ -329,7 +330,6 @@ static void store_pending_cfg(void) } } - void bt_mesh_cfg_pending_store(void) { if (atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { @@ -346,15 +346,18 @@ static struct conf_handler bt_mesh_cfg_conf_handler = { .ch_commit = NULL, .ch_export = NULL, }; +#endif void bt_mesh_cfg_default_set(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) int rc; rc = conf_register(&bt_mesh_cfg_conf_handler); SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register bt_mesh_settings conf"); +#endif bt_mesh.default_ttl = CONFIG_BT_MESH_DEFAULT_TTL; bt_mesh.net_xmit = diff --git a/nimble/host/mesh/src/heartbeat.c b/nimble/host/mesh/src/heartbeat.c index 1d249b489..50cfdb6d5 100644 --- a/nimble/host/mesh/src/heartbeat.c +++ b/nimble/host/mesh/src/heartbeat.c @@ -371,6 +371,7 @@ void bt_mesh_hb_resume(void) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static int hb_pub_set(int argc, char **argv, char *val) { struct bt_mesh_hb_pub pub; @@ -447,14 +448,17 @@ static struct conf_handler bt_mesh_hb_pub_conf_handler = { .ch_set = hb_pub_set, .ch_commit = NULL, .ch_export = NULL, - }; +}; +#endif void bt_mesh_hb_pub_init(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) int rc; rc = conf_register(&bt_mesh_hb_pub_conf_handler); SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register bt_mesh_hb_pub conf"); +#endif } \ No newline at end of file diff --git a/nimble/host/mesh/src/net.c b/nimble/host/mesh/src/net.c index f994bcc74..a36160d77 100644 --- a/nimble/host/mesh/src/net.c +++ b/nimble/host/mesh/src/net.c @@ -148,22 +148,26 @@ static void msg_cache_add(struct bt_mesh_net_rx *rx) static void store_iv(bool only_duration) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_IV_PENDING); if (!only_duration) { /* Always update Seq whenever IV changes */ bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_SEQ_PENDING); } +#endif } static void store_seq(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) if (CONFIG_BT_MESH_SEQ_STORE_RATE > 1 && (bt_mesh.seq % CONFIG_BT_MESH_SEQ_STORE_RATE)) { return; } bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_SEQ_PENDING); +#endif } int bt_mesh_net_create(uint16_t idx, uint8_t flags, const uint8_t key[16], @@ -898,6 +902,7 @@ static void ivu_refresh(struct ble_npl_event *work) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static int net_set(int argc, char **argv, char *val) { struct net_val net; @@ -1031,11 +1036,13 @@ static struct conf_handler bt_mesh_seq_conf_handler = { .ch_commit = NULL, .ch_export = NULL, }; +#endif void bt_mesh_net_init(void) { int rc; +#if MYNEWT_VAL(BLE_MESH_SETTINGS) rc = conf_register(&bt_mesh_net_conf_handler); SYSINIT_PANIC_ASSERT_MSG(rc == 0, @@ -1051,6 +1058,7 @@ void bt_mesh_net_init(void) SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register bt_mesh_seq conf"); +#endif k_work_init_delayable(&bt_mesh.ivu_timer, ivu_refresh); @@ -1068,6 +1076,7 @@ void bt_mesh_net_init(void) assert(rc == 0); } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static void clear_iv(void) { int err; @@ -1204,6 +1213,7 @@ void bt_mesh_net_clear(void) bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING); bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_SEQ_PENDING); } +#endif void bt_mesh_net_settings_commit(void) { diff --git a/nimble/host/mesh/src/pb_gatt_srv.c b/nimble/host/mesh/src/pb_gatt_srv.c index d04948262..94dcd174a 100644 --- a/nimble/host/mesh/src/pb_gatt_srv.c +++ b/nimble/host/mesh/src/pb_gatt_srv.c @@ -104,7 +104,7 @@ static void proxy_msg_recv(struct bt_mesh_proxy_role *role) static bool service_registered; -static ssize_t gatt_recv(uint16_t conn_handle, uint16_t attr_handle, +static int gatt_recv(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { const uint8_t *data = ctxt->om->om_data; diff --git a/nimble/host/mesh/src/proxy_msg.c b/nimble/host/mesh/src/proxy_msg.c index 91b4ba694..1ed3acdc5 100644 --- a/nimble/host/mesh/src/proxy_msg.c +++ b/nimble/host/mesh/src/proxy_msg.c @@ -50,7 +50,7 @@ static uint8_t bufs[CONFIG_BT_MAX_CONN * CONFIG_BT_MESH_PROXY_MSG_LEN]; static struct bt_mesh_proxy_role roles[CONFIG_BT_MAX_CONN]; -ssize_t bt_mesh_proxy_msg_recv(struct bt_mesh_proxy_role *role, +int bt_mesh_proxy_msg_recv(struct bt_mesh_proxy_role *role, const void *buf, uint16_t len) { const uint8_t *data = buf; diff --git a/nimble/host/mesh/src/proxy_msg.h b/nimble/host/mesh/src/proxy_msg.h index befdb1f35..0e06c5cae 100644 --- a/nimble/host/mesh/src/proxy_msg.h +++ b/nimble/host/mesh/src/proxy_msg.h @@ -55,7 +55,7 @@ struct bt_mesh_proxy_client { struct ble_npl_callout send_beacons; }; -ssize_t bt_mesh_proxy_msg_recv(struct bt_mesh_proxy_role *role, +int bt_mesh_proxy_msg_recv(struct bt_mesh_proxy_role *role, const void *buf, uint16_t len); int bt_mesh_proxy_msg_send(struct bt_mesh_proxy_role *role, uint8_t type, struct os_mbuf *msg, void (*end)(uint16_t, void *), void *user_data); diff --git a/nimble/host/mesh/src/rpl.c b/nimble/host/mesh/src/rpl.c index bf5743e41..6fd08b2fe 100644 --- a/nimble/host/mesh/src/rpl.c +++ b/nimble/host/mesh/src/rpl.c @@ -34,6 +34,7 @@ static inline int rpl_idx(const struct bt_mesh_rpl *rpl) static void clear_rpl(struct bt_mesh_rpl *rpl) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) int err; char path[18]; @@ -51,10 +52,12 @@ static void clear_rpl(struct bt_mesh_rpl *rpl) (void)memset(rpl, 0, sizeof(*rpl)); atomic_clear_bit(store, rpl_idx(rpl)); +#endif } static void schedule_rpl_store(struct bt_mesh_rpl *entry, bool force) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) atomic_set_bit(store, rpl_idx(entry)); bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_RPL_PENDING); if (force @@ -64,11 +67,14 @@ static void schedule_rpl_store(struct bt_mesh_rpl *entry, bool force) ) { bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_RPL_PENDING); } +#endif } static void schedule_rpl_clear(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_RPL_PENDING); +#endif } void bt_mesh_rpl_update(struct bt_mesh_rpl *rpl, @@ -160,6 +166,7 @@ void bt_mesh_rpl_clear(void) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static struct bt_mesh_rpl *bt_mesh_rpl_find(uint16_t src) { int i; @@ -186,6 +193,7 @@ static struct bt_mesh_rpl *bt_mesh_rpl_alloc(uint16_t src) return NULL; } +#endif void bt_mesh_rpl_reset(void) { @@ -214,6 +222,7 @@ void bt_mesh_rpl_reset(void) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static int rpl_set(int argc, char **argv, char *val) { struct bt_mesh_rpl *entry; @@ -268,9 +277,11 @@ static int rpl_set(int argc, char **argv, char *val) (unsigned) entry->seq, entry->old_iv); return 0; } +#endif static void store_rpl(struct bt_mesh_rpl *entry) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) char buf[BT_SETTINGS_SIZE(sizeof(struct rpl_val))]; struct rpl_val rpl; char path[18]; @@ -302,6 +313,7 @@ static void store_rpl(struct bt_mesh_rpl *entry) } else { BT_DBG("Stored RPL"); } +#endif } static void store_pending_rpl(struct bt_mesh_rpl *rpl) @@ -345,6 +357,7 @@ void bt_mesh_rpl_pending_store(uint16_t addr) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static struct conf_handler bt_mesh_rpl_conf_handler = { .ch_name = "bt_mesh", .ch_get = NULL, @@ -352,13 +365,16 @@ static struct conf_handler bt_mesh_rpl_conf_handler = { .ch_commit = NULL, .ch_export = NULL, }; +#endif void bt_mesh_rpl_init(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) int rc; rc = conf_register(&bt_mesh_rpl_conf_handler); SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register bt_mesh_rpl conf"); +#endif } \ No newline at end of file diff --git a/nimble/host/mesh/src/subnet.c b/nimble/host/mesh/src/subnet.c index 71d7b3d1a..14aa8623f 100644 --- a/nimble/host/mesh/src/subnet.c +++ b/nimble/host/mesh/src/subnet.c @@ -73,6 +73,7 @@ static void subnet_evt(struct bt_mesh_subnet *sub, enum bt_mesh_key_evt evt) static void clear_net_key(uint16_t net_idx) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) char path[20]; int err; @@ -85,10 +86,12 @@ static void clear_net_key(uint16_t net_idx) } else { BT_DBG("Cleared NetKeyIndex 0x%03x", net_idx); } +#endif } static void store_subnet(uint16_t net_idx) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) const struct bt_mesh_subnet *sub; struct net_key_val key; char buf[BT_SETTINGS_SIZE(sizeof(struct net_key_val))]; @@ -123,8 +126,10 @@ static void store_subnet(uint16_t net_idx) } else { BT_DBG("Stored NetKey"); } +#endif } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static struct net_key_update *net_key_update_find(uint16_t key_idx, struct net_key_update **free_slot) { @@ -149,6 +154,7 @@ static struct net_key_update *net_key_update_find(uint16_t key_idx, return match; } +#endif uint8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub) { @@ -167,6 +173,7 @@ uint8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub) static void update_subnet_settings(uint16_t net_idx, bool store) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) struct net_key_update *update, *free_slot; uint8_t clear = store ? 0U : 1U; @@ -194,12 +201,15 @@ static void update_subnet_settings(uint16_t net_idx, bool store) free_slot->clear = clear; bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_NET_KEYS_PENDING); +#endif } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) void bt_mesh_subnet_store(uint16_t net_idx) { update_subnet_settings(net_idx, true); } +#endif static void key_refresh(struct bt_mesh_subnet *sub, uint8_t new_phase) { @@ -800,6 +810,7 @@ bool bt_mesh_net_cred_find(struct bt_mesh_net_rx *rx, struct os_mbuf *in, return false; } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static int net_key_set(int argc, char **argv, char *val) { struct net_key_val key; @@ -828,6 +839,7 @@ static int net_key_set(int argc, char **argv, char *val) net_idx, key.kr_phase, key.val[0], (key.kr_phase != BT_MESH_KR_NORMAL) ? key.val[1] : NULL); } +#endif void bt_mesh_subnet_pending_store(void) { @@ -850,20 +862,24 @@ void bt_mesh_subnet_pending_store(void) } } +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static struct conf_handler bt_mesh_net_key_conf_handler = { .ch_name = "bt_mesh", .ch_get = NULL, .ch_set = net_key_set, .ch_commit = NULL, .ch_export = NULL, - }; +}; +#endif void bt_mesh_net_key_init(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) int rc; rc = conf_register(&bt_mesh_net_key_conf_handler); SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register bt_mesh_net_key conf"); +#endif } \ No newline at end of file diff --git a/nimble/host/mesh/src/transport.c b/nimble/host/mesh/src/transport.c index b1d41dbf5..d563c9fa0 100644 --- a/nimble/host/mesh/src/transport.c +++ b/nimble/host/mesh/src/transport.c @@ -1638,7 +1638,9 @@ void bt_mesh_rx_reset(void) static void store_va_label(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_VA_PENDING); +#endif } void bt_mesh_trans_reset(void) @@ -1787,6 +1789,7 @@ uint8_t *bt_mesh_va_label_get(uint16_t addr) } #if CONFIG_BT_MESH_LABEL_COUNT > 0 +#if MYNEWT_VAL(BLE_MESH_SETTINGS) static struct virtual_addr *bt_mesh_va_get(uint16_t index) { if (index >= ARRAY_SIZE(virtual_addrs)) { @@ -1901,15 +1904,18 @@ static struct conf_handler bt_mesh_va_conf_handler = { .ch_commit = NULL, .ch_export = NULL, }; +#endif void bt_mesh_va_init(void) { +#if MYNEWT_VAL(BLE_MESH_SETTINGS) int rc; rc = conf_register(&bt_mesh_va_conf_handler); SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register bt_mesh_hb_pub conf"); +#endif } #else