feat(ble_mesh): adapt blob cli&srv to long packet
(cherry picked from commit a232b7c7af2672e0c3fecd7848824c39b3edbe63) Co-authored-by: luoxu <luoxu@espressif.com>
This commit is contained in:
@@ -186,6 +186,8 @@ struct esp_ble_mesh_blob_xfer {
|
||||
esp_ble_mesh_blob_xfer_mode_t mode; /*!< BLOB transfer mode. */
|
||||
uint8_t block_size_log; /*!< Logarithmic representation of the block size. */
|
||||
uint16_t chunk_size; /*!< Base chunk size. May be smaller for the last chunk. */
|
||||
/* Enhanced parameters for message context in blob chunks */
|
||||
esp_ble_mesh_msg_enh_params_t chunk_enh_params;
|
||||
};
|
||||
|
||||
/** BLOB transfer data block. */
|
||||
|
||||
@@ -782,6 +782,8 @@ struct esp_ble_mesh_dfu_cli_xfer_blob_params {
|
||||
uint8_t block_size_log;
|
||||
/** Base chunk size. May be smaller for the last chunk. */
|
||||
uint16_t chunk_size;
|
||||
/* Enhanced parameters for message context in blob chunks */
|
||||
esp_ble_mesh_msg_enh_params_t chunk_enh_params;
|
||||
};
|
||||
|
||||
/** Firmware Update Client transfer parameters */
|
||||
|
||||
@@ -1236,9 +1236,14 @@ int bt_mesh_dfu_cli_send(struct bt_mesh_dfu_cli *cli,
|
||||
cli->xfer.flags = 0U;
|
||||
|
||||
if (xfer->blob_params) {
|
||||
cli->xfer.flags |= FLAG_SKIP_CAPS_GET;
|
||||
cli->xfer.blob.block_size_log = xfer->blob_params->block_size_log;
|
||||
cli->xfer.blob.chunk_size = xfer->blob_params->chunk_size;
|
||||
if (xfer->blob_params->block_size_log &&
|
||||
xfer->blob_params->chunk_size) {
|
||||
cli->xfer.flags |= FLAG_SKIP_CAPS_GET;
|
||||
cli->xfer.blob.block_size_log = xfer->blob_params->block_size_log;
|
||||
cli->xfer.blob.chunk_size = xfer->blob_params->chunk_size;
|
||||
}
|
||||
memcpy(&cli->xfer.blob.chunk_enh_params, &xfer->blob_params->chunk_enh_params,
|
||||
sizeof(bt_mesh_msg_enh_params_t));
|
||||
}
|
||||
|
||||
/* Phase will be set based on target status messages: */
|
||||
|
||||
@@ -243,6 +243,8 @@ struct bt_mesh_dfu_cli_xfer_blob_params {
|
||||
uint8_t block_size_log;
|
||||
/** Base chunk size. May be smaller for the last chunk. */
|
||||
uint16_t chunk_size;
|
||||
/* Enhanced parameters for message context in blob chunks */
|
||||
bt_mesh_msg_enh_params_t chunk_enh_params;
|
||||
};
|
||||
|
||||
/** Firmware Update Client transfer parameters: */
|
||||
|
||||
@@ -141,6 +141,8 @@ struct bt_mesh_blob_xfer {
|
||||
uint8_t block_size_log;
|
||||
/** Base chunk size. May be smaller for the last chunk. */
|
||||
uint16_t chunk_size;
|
||||
/* Enhanced parameters for message context in blob chunks */
|
||||
bt_mesh_msg_enh_params_t chunk_enh_params;
|
||||
};
|
||||
|
||||
/** BLOB stream interaction mode. */
|
||||
|
||||
@@ -34,19 +34,37 @@
|
||||
#define BLOB_CHUNK_SIZE_MAX(sdu_max) ((sdu_max) - BLOB_CHUNK_SDU_OVERHEAD)
|
||||
#define BLOB_CHUNK_SDU_LEN(chunk_size) (BLOB_CHUNK_SDU_OVERHEAD + (chunk_size))
|
||||
|
||||
#if CONFIG_BLE_MESH_LONG_PACKET
|
||||
#if CONFIG_BLE_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT || \
|
||||
CONFIG_BLE_MESH_RX_BLOB_CHUNK_SIZE > BLOB_CHUNK_SIZE_MAX(BLE_MESH_EXT_RX_SDU_MAX)
|
||||
#define BLOB_RX_CHUNK_SIZE BLOB_CHUNK_SIZE_MAX(BLE_MESH_EXT_RX_SDU_MAX)
|
||||
#else
|
||||
#define BLOB_RX_CHUNK_SIZE CONFIG_BLE_MESH_RX_BLOB_CHUNK_SIZE
|
||||
#endif
|
||||
#else // CONFIG_BLE_MESH_LONG_PACKET
|
||||
#if CONFIG_BLE_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT || \
|
||||
CONFIG_BLE_MESH_RX_BLOB_CHUNK_SIZE > BLOB_CHUNK_SIZE_MAX(BLE_MESH_RX_SDU_MAX)
|
||||
#define BLOB_RX_CHUNK_SIZE BLOB_CHUNK_SIZE_MAX(BLE_MESH_RX_SDU_MAX)
|
||||
#else
|
||||
#define BLOB_RX_CHUNK_SIZE CONFIG_BLE_MESH_RX_BLOB_CHUNK_SIZE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_LONG_PACKET
|
||||
#if CONFIG_BLE_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT || \
|
||||
CONFIG_BLE_MESH_TX_BLOB_CHUNK_SIZE > BLOB_CHUNK_SIZE_MAX(BLE_MESH_EXT_TX_SDU_MAX)
|
||||
#define BLOB_TX_CHUNK_SIZE BLOB_CHUNK_SIZE_MAX(BLE_MESH_EXT_TX_SDU_MAX)
|
||||
#else
|
||||
#define BLOB_TX_CHUNK_SIZE CONFIG_BLE_MESH_TX_BLOB_CHUNK_SIZE
|
||||
#endif
|
||||
#else // CONFIG_BLE_MESH_LONG_PACKET
|
||||
#if CONFIG_BLE_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT || \
|
||||
CONFIG_BLE_MESH_TX_BLOB_CHUNK_SIZE > BLOB_CHUNK_SIZE_MAX(BLE_MESH_TX_SDU_MAX)
|
||||
#define BLOB_TX_CHUNK_SIZE BLOB_CHUNK_SIZE_MAX(BLE_MESH_TX_SDU_MAX)
|
||||
#else
|
||||
#define BLOB_TX_CHUNK_SIZE CONFIG_BLE_MESH_TX_BLOB_CHUNK_SIZE
|
||||
#endif
|
||||
#endif // CONFIG_BLE_MESH_LONG_PACKET
|
||||
|
||||
/* Utility macros for calculating log2 of a number at compile time.
|
||||
* Used to determine the log2 representation of the block size, which
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#if CONFIG_BLE_MESH_BLOB_CLI
|
||||
|
||||
#define CHUNK_SIZE_MAX BLOB_TX_CHUNK_SIZE
|
||||
|
||||
#define TARGETS_FOR_EACH(cli, target) \
|
||||
SYS_SLIST_FOR_EACH_CONTAINER((sys_slist_t *)&(cli)->inputs->targets, \
|
||||
target, n)
|
||||
@@ -49,7 +51,8 @@ _Static_assert((BLOB_BLOCK_STATUS_MSG_MAXLEN + BLE_MESH_MODEL_OP_LEN(BT_MESH_BLO
|
||||
BLE_MESH_MIC_SHORT) <= BLE_MESH_RX_SDU_MAX,
|
||||
"The BLOB Block Status message does not fit into the maximum incoming SDU size.");
|
||||
|
||||
NET_BUF_SIMPLE_DEFINE_STATIC(chunk_buf, BLE_MESH_TX_SDU_MAX);
|
||||
NET_BUF_SIMPLE_DEFINE_STATIC(chunk_buf, BLOB_CHUNK_SDU_LEN(CHUNK_SIZE_MAX));
|
||||
static bool chunk_sending;
|
||||
|
||||
struct block_status {
|
||||
enum bt_mesh_blob_status status;
|
||||
@@ -591,6 +594,12 @@ static int tx(struct bt_mesh_blob_cli *cli, uint16_t addr,
|
||||
.addr = addr,
|
||||
.send_ttl = cli->inputs->ttl,
|
||||
};
|
||||
|
||||
if (chunk_sending) {
|
||||
memcpy(&ctx.enh, &cli->xfer->chunk_enh_params,
|
||||
sizeof(bt_mesh_msg_enh_params_t));
|
||||
}
|
||||
|
||||
int err;
|
||||
|
||||
err = bt_mesh_model_send((struct bt_mesh_model *)cli->mod, &ctx, buf, &end_cb, cli);
|
||||
@@ -615,6 +624,10 @@ static void send_end(int err, void *user_data)
|
||||
{
|
||||
struct bt_mesh_blob_cli *cli = user_data;
|
||||
|
||||
if (chunk_sending) {
|
||||
chunk_sending = false;
|
||||
}
|
||||
|
||||
if (!cli->tx.ctx.is_inited) {
|
||||
return;
|
||||
}
|
||||
@@ -642,7 +655,12 @@ static void xfer_start_tx(struct bt_mesh_blob_cli *cli, uint16_t dst)
|
||||
net_buf_simple_add_le64(&buf, cli->xfer->id);
|
||||
net_buf_simple_add_le32(&buf, cli->xfer->size);
|
||||
net_buf_simple_add_u8(&buf, cli->xfer->block_size_log);
|
||||
#if CONFIG_BLE_MESH_LONG_PACKET
|
||||
/* todo: could let user select methold */
|
||||
net_buf_simple_add_le16(&buf, BLE_MESH_EXT_TX_SDU_MAX);
|
||||
#else
|
||||
net_buf_simple_add_le16(&buf, BLE_MESH_TX_SDU_MAX);
|
||||
#endif
|
||||
|
||||
tx(cli, dst, &buf);
|
||||
}
|
||||
@@ -959,6 +977,8 @@ static void chunk_send(struct bt_mesh_blob_cli *cli)
|
||||
chunk_size(cli->xfer, &cli->block, cli->chunk_idx));
|
||||
|
||||
cli->state = BT_MESH_BLOB_CLI_STATE_BLOCK_SEND;
|
||||
chunk_sending = true;
|
||||
|
||||
blob_cli_broadcast(cli, &ctx);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
|
||||
#if CONFIG_BLE_MESH_BLOB_SRV
|
||||
|
||||
#if CONFIG_BLE_MESH_LONG_PACKET
|
||||
#define MTU_SIZE_MAX (BLE_MESH_EXT_RX_SDU_MAX - BLE_MESH_MIC_SHORT)
|
||||
#else
|
||||
#define MTU_SIZE_MAX (BLE_MESH_RX_SDU_MAX - BLE_MESH_MIC_SHORT)
|
||||
#endif
|
||||
|
||||
/* The Receive BLOB Timeout Timer */
|
||||
#define SERVER_TIMEOUT_SECS(srv) (10 * (1 + (srv)->state.timeout_base))
|
||||
|
||||
Reference in New Issue
Block a user