Bluetooth: Mesh: Improve outgoing segment count configuration

The Mesh specification doesn't support more than 32 transport layer
segments, the way the number was so far derived from the advertising
buffer count could result in a highre numbe than 32, thereby wasting
memory. Make the number of supported segments build-time configurable
through a new BT_MESH_TX_SEG_MAX configuration option.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2018-07-23 20:47:12 +03:00 committed by Johan Hedberg
commit 8c1c1641fe
5 changed files with 42 additions and 11 deletions

View file

@ -41,6 +41,7 @@ CONFIG_BT_MESH_LOW_POWER=n
CONFIG_BT_MESH_FRIEND=n CONFIG_BT_MESH_FRIEND=n
CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=16 CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=16
CONFIG_BT_MESH_ADV_BUF_COUNT=20 CONFIG_BT_MESH_ADV_BUF_COUNT=20
CONFIG_BT_MESH_TX_SEG_MAX=6
CONFIG_BT_MESH_PB_GATT=y CONFIG_BT_MESH_PB_GATT=y
CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_PB_ADV=y

View file

@ -39,6 +39,7 @@ CONFIG_BT_MESH_LOW_POWER=n
CONFIG_BT_MESH_FRIEND=n CONFIG_BT_MESH_FRIEND=n
CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=16 CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=16
CONFIG_BT_MESH_ADV_BUF_COUNT=20 CONFIG_BT_MESH_ADV_BUF_COUNT=20
CONFIG_BT_MESH_TX_SEG_MAX=6
CONFIG_BT_MESH_PB_GATT=y CONFIG_BT_MESH_PB_GATT=y
CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_PB_ADV=y

View file

@ -155,13 +155,12 @@ config BT_MESH_ADV_BUF_COUNT
default 6 default 6
range 6 256 range 6 256
help help
Number of advertising buffers available. The transport layer Number of advertising buffers available. This should be chosen
reserves ADV_BUF_COUNT - 3 buffers for outgoing segments. The based on what kind of features the local node shoule have. E.g.
maximum outgoing SDU size is 12 times this number (out of which a relay will perform better the more buffers it has. Another
4 or 8 bytes is used for the Transport Layer MIC). For thing to consider is outgoing segmented messages. There must
example, 5 segments means the maximum SDU size is 60 bytes, be at least three more advertising buffers than the maximum
which leaves 56 bytes for application layer data using a supported outgoing segment count (BT_MESH_TX_SEG_MAX).
4-byte MIC and 52 bytes using an 8-byte MIC.
config BT_MESH_IVU_DIVIDER config BT_MESH_IVU_DIVIDER
int "Divider for IV Update state refresh timer" 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 to the default value, unless you really need to optimize memory
usage. 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 config BT_MESH_RELAY
bool "Relay support" bool "Relay support"
help help

View file

@ -34,6 +34,13 @@
#include "settings.h" #include "settings.h"
#include "transport.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 AID_MASK ((u8_t)(BIT_MASK(6)))
#define SEG(data) ((data)[0] >> 7) #define SEG(data) ((data)[0] >> 7)
@ -64,7 +71,7 @@
static struct seg_tx { static struct seg_tx {
struct bt_mesh_subnet *sub; 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; u64_t seq_auth;
u16_t dst; u16_t dst;
u8_t seg_n:5, /* Last segment index */ u8_t seg_n:5, /* Last segment index */

View file

@ -6,10 +6,9 @@
* SPDX-License-Identifier: Apache-2.0 * 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 (CONFIG_BT_MESH_TX_SEG_MAX * 12)
#define BT_MESH_TX_SDU_MAX (BT_MESH_TX_SEG_COUNT * 12)
#define TRANS_CTL_OP_MASK ((u8_t)BIT_MASK(7)) #define TRANS_CTL_OP_MASK ((u8_t)BIT_MASK(7))
#define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK) #define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK)