diff --git a/samples/boards/nrf52/mesh/onoff-app/prj.conf b/samples/boards/nrf52/mesh/onoff-app/prj.conf index 175a0f72372..ba7e5194a7d 100644 --- a/samples/boards/nrf52/mesh/onoff-app/prj.conf +++ b/samples/boards/nrf52/mesh/onoff-app/prj.conf @@ -41,6 +41,7 @@ CONFIG_BT_MESH_LOW_POWER=n CONFIG_BT_MESH_FRIEND=n CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=16 CONFIG_BT_MESH_ADV_BUF_COUNT=20 +CONFIG_BT_MESH_TX_SEG_MAX=6 CONFIG_BT_MESH_PB_GATT=y CONFIG_BT_MESH_PB_ADV=y diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/prj.conf b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/prj.conf index b7f27b6bf85..a4794f6efdb 100644 --- a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/prj.conf +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/prj.conf @@ -39,6 +39,7 @@ CONFIG_BT_MESH_LOW_POWER=n CONFIG_BT_MESH_FRIEND=n CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=16 CONFIG_BT_MESH_ADV_BUF_COUNT=20 +CONFIG_BT_MESH_TX_SEG_MAX=6 CONFIG_BT_MESH_PB_GATT=y CONFIG_BT_MESH_PB_ADV=y diff --git a/subsys/bluetooth/host/mesh/Kconfig b/subsys/bluetooth/host/mesh/Kconfig index 7d8a81d8ab5..410a51b16d5 100644 --- a/subsys/bluetooth/host/mesh/Kconfig +++ b/subsys/bluetooth/host/mesh/Kconfig @@ -155,13 +155,12 @@ config BT_MESH_ADV_BUF_COUNT default 6 range 6 256 help - 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. + 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). config BT_MESH_IVU_DIVIDER int "Divider for IV Update state refresh timer" @@ -214,6 +213,30 @@ config BT_MESH_RX_SDU_MAX to the default value, unless you really need to optimize memory usage. +config BT_MESH_TX_SEG_MAX + int "Maximum number of segments in outgoing messages" + default 3 + range 2 32 + help + 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. + config BT_MESH_RELAY bool "Relay support" help diff --git a/subsys/bluetooth/host/mesh/transport.c b/subsys/bluetooth/host/mesh/transport.c index 88dcac782ce..8f83f424946 100644 --- a/subsys/bluetooth/host/mesh/transport.c +++ b/subsys/bluetooth/host/mesh/transport.c @@ -34,6 +34,13 @@ #include "settings.h" #include "transport.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) @@ -64,7 +71,7 @@ static struct seg_tx { struct bt_mesh_subnet *sub; - struct net_buf *seg[BT_MESH_TX_SEG_COUNT]; + struct net_buf *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/subsys/bluetooth/host/mesh/transport.h b/subsys/bluetooth/host/mesh/transport.h index c9234bf317b..26f4393b130 100644 --- a/subsys/bluetooth/host/mesh/transport.h +++ b/subsys/bluetooth/host/mesh/transport.h @@ -6,10 +6,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff +#define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff -#define BT_MESH_TX_SEG_COUNT (CONFIG_BT_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)