Skip to content

Commit 0a79085

Browse files
KyraLengfeldhenrikbrixandersen
authored andcommitted
Bluetooth: Mesh: add Kconfig options for BLOB chunk size
The MBT server, as the MBT client currently sets the maximum chunk size according to maximum supported segments in the accesss layer. This might be suboptimal for some use cases. The added Kconfig options give customers the option to fine tune it themselves. Future work will include addition of an API for the customer to modify it also during runtime. Signed-off-by: Kyra Lengfeld <[email protected]>
1 parent e8db417 commit 0a79085

File tree

6 files changed

+52
-15
lines changed

6 files changed

+52
-15
lines changed

include/zephyr/bluetooth/mesh/blob_srv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct bt_mesh_blob_srv_cb {
127127
const struct bt_mesh_blob_io **io);
128128
};
129129

130-
/** @brief BLOB Transfer Server instance. */
130+
/** @brief BLOB Transfer Server model instance. */
131131
struct bt_mesh_blob_srv {
132132
/** Event handler callbacks. */
133133
const struct bt_mesh_blob_srv_cb *cb;

subsys/bluetooth/mesh/Kconfig

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,18 @@ config BT_MESH_BLOB_REPORT_TIMEOUT
895895
help
896896
The timer value that Pull BLOB Transfer Server uses to report missed chunks.
897897

898+
config BT_MESH_RX_BLOB_CHUNK_SIZE
899+
depends on !BT_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT
900+
int "BLOB Server chunk size"
901+
default 8
902+
range 8 377
903+
help
904+
Set the chunk size for the BLOB Server.
905+
The actual maximum chunk size depends on how many segments are
906+
possible and will be clamped to the max possible if set above.
907+
see also: BT_MESH_RX_SEG_MAX,
908+
and the maximum SDU a node can receive.
909+
898910
endif # BT_MESH_BLOB_SRV
899911

900912
menuconfig BT_MESH_BLOB_CLI
@@ -911,11 +923,27 @@ config BT_MESH_BLOB_CLI_BLOCK_RETRIES
911923
Controls the number of times the client will attempt to resend missing
912924
chunks to the BLOB receivers for every block.
913925

914-
endif
926+
config BT_MESH_TX_BLOB_CHUNK_SIZE
927+
depends on !BT_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT
928+
int "BLOB Client chunk size"
929+
default 8
930+
range 1 377
931+
help
932+
Set the chunk size for the BLOB Client.
933+
The actual maximum chunk size depends on how many segments are
934+
possible and will be clamped to the max possible if set above.
935+
see also: BT_MESH_TX_SEG_MAX,
936+
and the maximum SDU a node can receive.
937+
938+
endif # BT_MESH_BLOB_CLI
915939

916940
menu "BLOB models common configuration"
917941
visible if BT_MESH_BLOB_SRV || BT_MESH_BLOB_CLI
918942

943+
config BT_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT
944+
bool "Align chunk size to max segmented message size"
945+
default y
946+
919947
config BT_MESH_BLOB_CHUNK_COUNT_MAX
920948
int "Maximum chunk count per block"
921949
default 256

subsys/bluetooth/mesh/blob.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
#define BLOB_CHUNK_SIZE_MAX(sdu_max) ((sdu_max) - BLOB_CHUNK_SDU_OVERHEAD)
2828
#define BLOB_CHUNK_SDU_LEN(chunk_size) (BLOB_CHUNK_SDU_OVERHEAD + (chunk_size))
2929

30+
#if CONFIG_BT_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT || \
31+
CONFIG_BT_MESH_RX_BLOB_CHUNK_SIZE > BLOB_CHUNK_SIZE_MAX(BT_MESH_RX_SDU_MAX)
32+
#define BLOB_RX_CHUNK_SIZE BLOB_CHUNK_SIZE_MAX(BT_MESH_RX_SDU_MAX)
33+
#else
34+
#define BLOB_RX_CHUNK_SIZE CONFIG_BT_MESH_RX_BLOB_CHUNK_SIZE
35+
#endif
36+
37+
#if CONFIG_BT_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT || \
38+
CONFIG_BT_MESH_TX_BLOB_CHUNK_SIZE > BLOB_CHUNK_SIZE_MAX(BT_MESH_TX_SDU_MAX)
39+
#define BLOB_TX_CHUNK_SIZE BLOB_CHUNK_SIZE_MAX(BT_MESH_TX_SDU_MAX)
40+
#else
41+
#define BLOB_TX_CHUNK_SIZE CONFIG_BT_MESH_TX_BLOB_CHUNK_SIZE
42+
#endif
43+
3044
/* Utility macros for calculating log2 of a number at compile time.
3145
* Used to determine the log2 representation of the block size, which
3246
* is configured as a raw number, but encoded as log2.

subsys/bluetooth/mesh/blob_cli.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ LOG_MODULE_REGISTER(bt_mesh_blob_cli);
1919
SYS_SLIST_FOR_EACH_CONTAINER((sys_slist_t *)&(cli)->inputs->targets, \
2020
target, n)
2121

22-
#define CHUNK_SIZE_MAX BLOB_CHUNK_SIZE_MAX(BT_MESH_TX_SDU_MAX)
23-
2422
/* The Maximum BLOB Poll Interval - T_MBPI */
2523
#define BLOB_POLL_TIME_MAX_SECS 30
2624

@@ -1496,7 +1494,7 @@ int bt_mesh_blob_cli_caps_get(struct bt_mesh_blob_cli *cli,
14961494
cli->caps.min_block_size_log = 0x06;
14971495
cli->caps.max_block_size_log = 0x20;
14981496
cli->caps.max_chunks = CONFIG_BT_MESH_BLOB_CHUNK_COUNT_MAX;
1499-
cli->caps.max_chunk_size = CHUNK_SIZE_MAX;
1497+
cli->caps.max_chunk_size = BLOB_TX_CHUNK_SIZE;
15001498
cli->caps.max_size = 0xffffffff;
15011499
cli->caps.mtu_size = 0xffff;
15021500
cli->caps.modes = BT_MESH_BLOB_XFER_MODE_ALL;
@@ -1521,9 +1519,9 @@ int bt_mesh_blob_cli_send(struct bt_mesh_blob_cli *cli,
15211519
return -EBUSY;
15221520
}
15231521

1524-
if (!(xfer->mode & BT_MESH_BLOB_XFER_MODE_ALL) ||
1525-
xfer->block_size_log < 0x06 || xfer->block_size_log > 0x20 ||
1526-
xfer->chunk_size < 8 || xfer->chunk_size > CHUNK_SIZE_MAX) {
1522+
if (!(xfer->mode & BT_MESH_BLOB_XFER_MODE_ALL) || xfer->block_size_log < 0x06 ||
1523+
xfer->block_size_log > 0x20 || xfer->chunk_size < 8 ||
1524+
xfer->chunk_size > BLOB_TX_CHUNK_SIZE) {
15271525
LOG_ERR("Incompatible transfer parameters");
15281526
return -EINVAL;
15291527
}

subsys/bluetooth/mesh/blob_io_flash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ static int wr_chunk(const struct bt_mesh_blob_io *io,
117117
chunk->data, chunk->size);
118118
}
119119

120-
uint8_t buf[ROUND_UP(BLOB_CHUNK_SIZE_MAX(BT_MESH_RX_SDU_MAX),
121-
WRITE_BLOCK_SIZE)];
120+
uint8_t buf[ROUND_UP(BLOB_RX_CHUNK_SIZE, WRITE_BLOCK_SIZE)];
122121
off_t area_offset = flash->offset + block->offset + chunk->offset;
123122
int i = 0;
124123

subsys/bluetooth/mesh/blob_srv.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <zephyr/logging/log.h>
1717
LOG_MODULE_REGISTER(bt_mesh_blob_srv);
1818

19-
#define CHUNK_SIZE_MAX BLOB_CHUNK_SIZE_MAX(BT_MESH_RX_SDU_MAX)
2019
#define MTU_SIZE_MAX (BT_MESH_RX_SDU_MAX - BT_MESH_MIC_SHORT)
2120

2221
/* The Receive BLOB Timeout Timer */
@@ -53,9 +52,8 @@ static inline uint32_t block_count_get(const struct bt_mesh_blob_srv *srv)
5352

5453
static inline uint32_t max_chunk_size(const struct bt_mesh_blob_srv *srv)
5554
{
56-
return MIN((srv->state.mtu_size - 2 -
57-
BT_MESH_MODEL_OP_LEN(BT_MESH_BLOB_OP_CHUNK)),
58-
CHUNK_SIZE_MAX);
55+
return MIN((srv->state.mtu_size - 2 - BT_MESH_MODEL_OP_LEN(BT_MESH_BLOB_OP_CHUNK)),
56+
BLOB_RX_CHUNK_SIZE);
5957
}
6058

6159
static inline uint32_t max_chunk_count(const struct bt_mesh_blob_srv *srv)
@@ -822,7 +820,7 @@ static int handle_info_get(const struct bt_mesh_model *mod, struct bt_mesh_msg_c
822820
net_buf_simple_add_u8(&rsp, BLOB_BLOCK_SIZE_LOG_MIN);
823821
net_buf_simple_add_u8(&rsp, BLOB_BLOCK_SIZE_LOG_MAX);
824822
net_buf_simple_add_le16(&rsp, CONFIG_BT_MESH_BLOB_CHUNK_COUNT_MAX);
825-
net_buf_simple_add_le16(&rsp, CHUNK_SIZE_MAX);
823+
net_buf_simple_add_le16(&rsp, BLOB_RX_CHUNK_SIZE);
826824
net_buf_simple_add_le32(&rsp, CONFIG_BT_MESH_BLOB_SIZE_MAX);
827825
net_buf_simple_add_le16(&rsp, MTU_SIZE_MAX);
828826
net_buf_simple_add_u8(&rsp, BT_MESH_BLOB_XFER_MODE_ALL);

0 commit comments

Comments
 (0)