Skip to content

Commit 0f4fde3

Browse files
KyraLengfeldcarlescufi
authored andcommitted
Bluetooth: Mesh: add API to set chunk send interval
This commit adds a KConfig option and an API to set the interval in which chunks get send, in milliseconds. Signed-off-by: Kyra Lengfeld <[email protected]>
1 parent 9fdf074 commit 0f4fde3

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

include/zephyr/bluetooth/mesh/blob_cli.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ struct blob_cli_broadcast_ctx {
282282
* and broadcast_complete calls.
283283
*/
284284
bool is_inited;
285+
/* Defines a time in ms by which the broadcast API postpones sending the message to a next
286+
* target or completing the broadcast.
287+
*/
288+
uint32_t post_send_delay_ms;
285289
};
286290
/** INTERNAL_HIDDEN @endcond */
287291

@@ -299,7 +303,7 @@ struct bt_mesh_blob_cli {
299303
struct k_work_delayable retry;
300304
/* Represents Client Timeout timer in a timestamp. Used in Pull mode only. */
301305
int64_t cli_timestamp;
302-
struct k_work complete;
306+
struct k_work_delayable complete;
303307
uint16_t pending;
304308
uint8_t retries;
305309
uint8_t sending : 1,
@@ -309,6 +313,7 @@ struct bt_mesh_blob_cli {
309313
const struct bt_mesh_blob_io *io;
310314
const struct bt_mesh_blob_cli_inputs *inputs;
311315
const struct bt_mesh_blob_xfer *xfer;
316+
uint32_t chunk_interval_ms;
312317
uint16_t block_count;
313318
uint16_t chunk_idx;
314319
uint16_t mtu_size;
@@ -419,6 +424,22 @@ uint8_t bt_mesh_blob_cli_xfer_progress_active_get(struct bt_mesh_blob_cli *cli);
419424
*/
420425
bool bt_mesh_blob_cli_is_busy(struct bt_mesh_blob_cli *cli);
421426

427+
/** @brief Set chunk sending interval in ms
428+
*
429+
* This function is optional, and can be used to define how fast chunks are sent in the BLOB Client
430+
* Model.
431+
* Without an added delay, for example a Bluetooth Mesh DFU can cause network blockage by
432+
* constantly sending the next chunks, especially if the chunks are sent to group addresses or
433+
* multiple unicast addresses.
434+
*
435+
* @note: Big intervals may cause timeouts. Increasing the @c timeout_base accordingly can
436+
* circumvent this.
437+
*
438+
* @param cli BLOB Transfer Client instance.
439+
* @param interval_ms the delay before each chunk is sent out in ms.
440+
*/
441+
void bt_mesh_blob_cli_set_chunk_interval_ms(struct bt_mesh_blob_cli *cli, uint32_t interval_ms);
442+
422443
/** @cond INTERNAL_HIDDEN */
423444
extern const struct bt_mesh_model_op _bt_mesh_blob_cli_op[];
424445
extern const struct bt_mesh_model_cb _bt_mesh_blob_cli_cb;

subsys/bluetooth/mesh/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,18 @@ config BT_MESH_TX_BLOB_CHUNK_SIZE
935935
see also: BT_MESH_TX_SEG_MAX,
936936
and the maximum SDU a node can receive.
937937

938+
config BT_MESH_TX_BLOB_CHUNK_SEND_INTERVAL
939+
int "BLOB Client chunk send interval"
940+
default 0
941+
range 0 2147483647
942+
help
943+
Set the interval in milliseconds in which chunks are sent during the BLOB transfer.
944+
Note: Without a delay between each sent chunk, the network might become too busy with the
945+
BLOB transfer for other communications to succeed.
946+
Note: Timing restrictions, like the timeout base, should be considered or changed
947+
accordingly when setting this interval. Otherwise, the interval might be too big for the
948+
timeout settings and cause timeouts.
949+
938950
endif # BT_MESH_BLOB_CLI
939951

940952
menu "BLOB models common configuration"

subsys/bluetooth/mesh/blob_cli.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ static void broadcast_complete(struct bt_mesh_blob_cli *cli)
407407

408408
static void tx_complete(struct k_work *work)
409409
{
410-
struct bt_mesh_blob_cli *cli =
411-
CONTAINER_OF(work, struct bt_mesh_blob_cli, tx.complete);
410+
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
411+
struct bt_mesh_blob_cli *cli = CONTAINER_OF(dwork, struct bt_mesh_blob_cli, tx.complete);
412412

413413
if (!cli->tx.ctx.is_inited || !cli->tx.sending) {
414414
return;
@@ -540,7 +540,7 @@ void blob_cli_broadcast(struct bt_mesh_blob_cli *cli,
540540

541541
void blob_cli_broadcast_tx_complete(struct bt_mesh_blob_cli *cli)
542542
{
543-
k_work_submit(&cli->tx.complete);
543+
k_work_schedule(&cli->tx.complete, K_MSEC(cli->tx.ctx.post_send_delay_ms));
544544
}
545545

546546
void blob_cli_broadcast_rsp(struct bt_mesh_blob_cli *cli,
@@ -932,6 +932,7 @@ static void chunk_send(struct bt_mesh_blob_cli *cli)
932932
.send = chunk_tx,
933933
.next = chunk_send_end,
934934
.acked = false,
935+
.post_send_delay_ms = cli->chunk_interval_ms,
935936
};
936937

937938
if (cli->xfer->mode == BT_MESH_BLOB_XFER_MODE_PULL) {
@@ -1462,9 +1463,10 @@ static int blob_cli_init(const struct bt_mesh_model *mod)
14621463

14631464
cli->mod = mod;
14641465

1466+
bt_mesh_blob_cli_set_chunk_interval_ms(cli, CONFIG_BT_MESH_TX_BLOB_CHUNK_SEND_INTERVAL);
14651467
cli->tx.cli_timestamp = 0ll;
14661468
k_work_init_delayable(&cli->tx.retry, retry_timeout);
1467-
k_work_init(&cli->tx.complete, tx_complete);
1469+
k_work_init_delayable(&cli->tx.complete, tx_complete);
14681470

14691471
return 0;
14701472
}
@@ -1649,3 +1651,8 @@ bool bt_mesh_blob_cli_is_busy(struct bt_mesh_blob_cli *cli)
16491651
{
16501652
return cli->state != BT_MESH_BLOB_CLI_STATE_NONE;
16511653
}
1654+
1655+
void bt_mesh_blob_cli_set_chunk_interval_ms(struct bt_mesh_blob_cli *cli, uint32_t interval_ms)
1656+
{
1657+
cli->chunk_interval_ms = interval_ms;
1658+
}

0 commit comments

Comments
 (0)