diff --git a/components/bt/esp_ble_mesh/v1.1/api/models/include/esp_ble_mesh_blob_model_api.h b/components/bt/esp_ble_mesh/v1.1/api/models/include/esp_ble_mesh_blob_model_api.h index 165450ed56..0f9097262a 100644 --- a/components/bt/esp_ble_mesh/v1.1/api/models/include/esp_ble_mesh_blob_model_api.h +++ b/components/bt/esp_ble_mesh/v1.1/api/models/include/esp_ble_mesh_blob_model_api.h @@ -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. */ diff --git a/components/bt/esp_ble_mesh/v1.1/api/models/include/esp_ble_mesh_dfu_model_api.h b/components/bt/esp_ble_mesh/v1.1/api/models/include/esp_ble_mesh_dfu_model_api.h index 6ef42d3dd8..f2b2d121c1 100644 --- a/components/bt/esp_ble_mesh/v1.1/api/models/include/esp_ble_mesh_dfu_model_api.h +++ b/components/bt/esp_ble_mesh/v1.1/api/models/include/esp_ble_mesh_dfu_model_api.h @@ -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 */ diff --git a/components/bt/esp_ble_mesh/v1.1/dfu/dfu_cli.c b/components/bt/esp_ble_mesh/v1.1/dfu/dfu_cli.c index e5ff20c328..21eea26d43 100644 --- a/components/bt/esp_ble_mesh/v1.1/dfu/dfu_cli.c +++ b/components/bt/esp_ble_mesh/v1.1/dfu/dfu_cli.c @@ -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: */ diff --git a/components/bt/esp_ble_mesh/v1.1/include/mesh_v1.1/dfu/dfu_cli.h b/components/bt/esp_ble_mesh/v1.1/include/mesh_v1.1/dfu/dfu_cli.h index 531e359994..306af5fbad 100644 --- a/components/bt/esp_ble_mesh/v1.1/include/mesh_v1.1/dfu/dfu_cli.h +++ b/components/bt/esp_ble_mesh/v1.1/include/mesh_v1.1/dfu/dfu_cli.h @@ -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: */ diff --git a/components/bt/esp_ble_mesh/v1.1/include/mesh_v1.1/mbt/blob.h b/components/bt/esp_ble_mesh/v1.1/include/mesh_v1.1/mbt/blob.h index 29199360a4..bd797e41ff 100644 --- a/components/bt/esp_ble_mesh/v1.1/include/mesh_v1.1/mbt/blob.h +++ b/components/bt/esp_ble_mesh/v1.1/include/mesh_v1.1/mbt/blob.h @@ -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. */ diff --git a/components/bt/esp_ble_mesh/v1.1/mbt/blob.h b/components/bt/esp_ble_mesh/v1.1/mbt/blob.h index c539219d9e..79d09d89f4 100644 --- a/components/bt/esp_ble_mesh/v1.1/mbt/blob.h +++ b/components/bt/esp_ble_mesh/v1.1/mbt/blob.h @@ -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 diff --git a/components/bt/esp_ble_mesh/v1.1/mbt/blob_cli.c b/components/bt/esp_ble_mesh/v1.1/mbt/blob_cli.c index 9132829a23..435ef3b5bc 100644 --- a/components/bt/esp_ble_mesh/v1.1/mbt/blob_cli.c +++ b/components/bt/esp_ble_mesh/v1.1/mbt/blob_cli.c @@ -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); } diff --git a/components/bt/esp_ble_mesh/v1.1/mbt/blob_srv.c b/components/bt/esp_ble_mesh/v1.1/mbt/blob_srv.c index 3540a6abea..88fe61ad0b 100644 --- a/components/bt/esp_ble_mesh/v1.1/mbt/blob_srv.c +++ b/components/bt/esp_ble_mesh/v1.1/mbt/blob_srv.c @@ -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))