diff --git a/apps/blemesh/syscfg.yml b/apps/blemesh/syscfg.yml index b8bdb6512..e17e32c7f 100644 --- a/apps/blemesh/syscfg.yml +++ b/apps/blemesh/syscfg.yml @@ -34,6 +34,9 @@ syscfg.vals: BLE_MESH: 1 MSYS_1_BLOCK_COUNT: 48 + BLE_MESH_ADV_BUF_COUNT: 20 + BLE_MESH_TX_SEG_MAX: 6 + BLE_MESH_DEBUG: 1 BLE_MESH_DEBUG_NET: 1 BLE_MESH_DEBUG_TRANS: 1 diff --git a/apps/blemesh_light/syscfg.yml b/apps/blemesh_light/syscfg.yml index 556a844ee..8f2c1ec4c 100644 --- a/apps/blemesh_light/syscfg.yml +++ b/apps/blemesh_light/syscfg.yml @@ -37,6 +37,9 @@ syscfg.vals: MSYS_1_BLOCK_COUNT: 80 + BLE_MESH_ADV_BUF_COUNT: 20 + BLE_MESH_TX_SEG_MAX: 6 + BLE_MESH: 1 BLE_MESH_SHELL: 1 BLE_MESH_PROV: 1 @@ -48,7 +51,6 @@ syscfg.vals: BLE_MESH_CFG_CLI: 1 BLE_MESH_HEALTH_CLI: 0 BLE_MESH_SHELL_MODELS: 1 - BLE_MESH_TESTING: 1 BLE_MESH_OOB_OUTPUT_ACTIONS: 0 BLE_MESH_SETTINGS: 0 CONFIG_NFFS: 0 diff --git a/apps/blemesh_shell/syscfg.yml b/apps/blemesh_shell/syscfg.yml index 227359c52..b08fa29fb 100644 --- a/apps/blemesh_shell/syscfg.yml +++ b/apps/blemesh_shell/syscfg.yml @@ -33,6 +33,9 @@ syscfg.vals: MSYS_1_BLOCK_COUNT: 80 + BLE_MESH_ADV_BUF_COUNT: 20 + BLE_MESH_TX_SEG_MAX: 6 + BLE_MESH: 1 BLE_MESH_SHELL: 1 BLE_MESH_PROV: 1 diff --git a/nimble/host/mesh/include/mesh/glue.h b/nimble/host/mesh/include/mesh/glue.h index b458ffebf..d330ecbc5 100644 --- a/nimble/host/mesh/include/mesh/glue.h +++ b/nimble/host/mesh/include/mesh/glue.h @@ -373,6 +373,7 @@ static inline unsigned int find_msb_set(u32_t op) #define CONFIG_BT_MESH_STORE_TIMEOUT MYNEWT_VAL(BLE_MESH_STORE_TIMEOUT) #define CONFIG_BT_MESH_IVU_DIVIDER MYNEWT_VAL(BLE_MESH_IVU_DIVIDER) #define CONFIG_BT_DEVICE_NAME MYNEWT_VAL(BLE_MESH_DEVICE_NAME) +#define CONFIG_BT_MESH_TX_SEG_MAX MYNEWT_VAL(BLE_MESH_TX_SEG_MAX) #define printk console_printf @@ -454,4 +455,6 @@ settings_load(void) #endif /* MYNEWT_VAL(MYNEWT_VAL_BLE_MESH_SETTINGS) */ +#define BUILD_ASSERT(cond) _Static_assert(cond, "") + #endif diff --git a/nimble/host/mesh/src/transport.c b/nimble/host/mesh/src/transport.c index 702f11ca5..e6f857b9a 100644 --- a/nimble/host/mesh/src/transport.c +++ b/nimble/host/mesh/src/transport.c @@ -28,6 +28,13 @@ #include "transport.h" #include "testing.h" +/* The transport layer needs at least three buffers for itself to avoid + * deadlocks. Ensure that there are a sufficient number of advertising + * buffers available compared to the maximum supported outgoing segment + * count. + */ +BUILD_ASSERT(CONFIG_BT_MESH_ADV_BUF_COUNT >= (CONFIG_BT_MESH_TX_SEG_MAX + 3)); + #define AID_MASK ((u8_t)(BIT_MASK(6))) #define SEG(data) ((data)[0] >> 7) @@ -58,7 +65,7 @@ static struct seg_tx { struct bt_mesh_subnet *sub; - struct os_mbuf *seg[BT_MESH_TX_SEG_COUNT]; + struct os_mbuf *seg[CONFIG_BT_MESH_TX_SEG_MAX]; u64_t seq_auth; u16_t dst; u8_t seg_n:5, /* Last segment index */ diff --git a/nimble/host/mesh/src/transport.h b/nimble/host/mesh/src/transport.h index d676f782e..ac6b3f8ee 100644 --- a/nimble/host/mesh/src/transport.h +++ b/nimble/host/mesh/src/transport.h @@ -11,8 +11,7 @@ #define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff -#define BT_MESH_TX_SEG_COUNT (MYNEWT_VAL(BLE_MESH_ADV_BUF_COUNT) - 3) -#define BT_MESH_TX_SDU_MAX (BT_MESH_TX_SEG_COUNT * 12) +#define BT_MESH_TX_SDU_MAX (CONFIG_BT_MESH_TX_SEG_MAX * 12) #define TRANS_CTL_OP_MASK ((u8_t)BIT_MASK(7)) #define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK) diff --git a/nimble/host/mesh/syscfg.yml b/nimble/host/mesh/syscfg.yml index 598ec8694..5f9ade452 100644 --- a/nimble/host/mesh/syscfg.yml +++ b/nimble/host/mesh/syscfg.yml @@ -117,14 +117,13 @@ syscfg.defs: BLE_MESH_ADV_BUF_COUNT: description: > - Number of advertising buffers available. The transport layer - reserves ADV_BUF_COUNT - 3 buffers for outgoing segments. The - maximum outgoing SDU size is 12 times this number (out of which - 4 or 8 bytes is used for the Transport Layer MIC). For - example, 5 segments means the maximum SDU size is 60 bytes, - which leaves 56 bytes for application layer data using a - 4-byte MIC and 52 bytes using an 8-byte MIC. - value: 10 + Number of advertising buffers available. This should be chosen + based on what kind of features the local node shoule have. E.g. + a relay will perform better the more buffers it has. Another + thing to consider is outgoing segmented messages. There must + be at least three more advertising buffers than the maximum + supported outgoing segment count (BT_MESH_TX_SEG_MAX). + value: 6 BLE_MESH_IVU_DIVIDER: description: > @@ -169,6 +168,28 @@ syscfg.defs: usage. value: 384 + BLE_MESH_TX_SEG_MAX: + description: > + Maximum number of segments supported for outgoing messages. + This value should typically be fine-tuned based on what + models the local node supports, i.e. what's the largest + message payload that the node needs to be able to send. + This value affects memory and call stack consumption, which + is why the default is lower than the maximum that the + specification would allow (32 segments). + + The maximum outgoing SDU size is 12 times this number (out of + which 4 or 8 bytes is used for the Transport Layer MIC). For + example, 5 segments means the maximum SDU size is 60 bytes, + which leaves 56 bytes for application layer data using a + 4-byte MIC and 52 bytes using an 8-byte MIC. + + Be sure to specify a sufficient number of advertising buffers + when setting this option to a higher value. There must be at + least three more advertising buffers (BT_MESH_ADV_BUF_COUNT) + as there are outgoing segments. + value: 3 + BLE_MESH_RELAY: description: > Support for acting as a Mesh Relay Node.