diff --git a/include/zephyr/bluetooth/mesh/large_comp_data_cli.h b/include/zephyr/bluetooth/mesh/large_comp_data_cli.h index ae23cda468f..40ee0316637 100644 --- a/include/zephyr/bluetooth/mesh/large_comp_data_cli.h +++ b/include/zephyr/bluetooth/mesh/large_comp_data_cli.h @@ -19,44 +19,123 @@ extern "C" { #endif +struct bt_mesh_large_comp_data_cli; + +/** Large Composition Data response. */ +struct bt_mesh_large_comp_data_rsp { + /** Page number. */ + uint8_t page; + /** Offset within the page. */ + uint16_t offset; + /** Total size of the page. */ + uint16_t total_size; + /** Pointer to allocated buffer for storing received data. */ + struct net_buf_simple *data; +}; + +/** Large Composition Data Status messages callbacks */ +struct bt_mesh_large_comp_data_cli_cb { + /** @brief Optional callback for Large Composition Data Status message. + * + * Handles received Large Composition Data Status messages from a Large Composition Data + * Server. + * + * If the content of @c rsp is needed after exiting this callback, a user should + * deep copy it. + * + * @param cli Large Composition Data Client context. + * @param addr Address of the sender. + * @param rsp Response received from the server. + */ + void (*large_comp_data_status)(struct bt_mesh_large_comp_data_cli *cli, uint16_t addr, + struct bt_mesh_large_comp_data_rsp *rsp); + + /** @brief Optional callback for Models Metadata Status message. + * + * Handles received Models Metadata Status messages from a Large Composition Data + * Server. + * + * If the content of @c rsp is needed after exiting this callback, a user should + * deep copy it. + * + * @param cli Large Composition Data Client context. + * @param addr Address of the sender. + * @param rsp Response received from the server. + */ + void (*models_metadata_status)(struct bt_mesh_large_comp_data_cli *cli, uint16_t addr, + struct bt_mesh_large_comp_data_rsp *rsp); +}; + +/** Large Composition Data Client model context */ +struct bt_mesh_large_comp_data_cli { + /** Model entry pointer. */ + struct bt_mesh_model *model; + + /** Internal parameters for tracking message responses. */ + struct bt_mesh_msg_ack_ctx ack_ctx; + + /** Optional callback for Large Composition Data Status messages. */ + const struct bt_mesh_large_comp_data_cli_cb *cb; +}; + /** * - * @brief Large Composition Data Client model composition data entry. + * @brief Large Composition Data Client model Composition Data entry. + * + * @param cli_data Pointer to a @ref bt_mesh_large_comp_data_cli instance. */ -#define BT_MESH_MODEL_LARGE_COMP_DATA_CLI \ - BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_LARGE_COMP_DATA_CLI, \ - _bt_mesh_large_comp_data_cli_op, NULL, NULL, \ +#define BT_MESH_MODEL_LARGE_COMP_DATA_CLI(cli_data) \ + BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_LARGE_COMP_DATA_CLI, \ + _bt_mesh_large_comp_data_cli_op, NULL, cli_data, \ &_bt_mesh_large_comp_data_cli_cb) /** @brief Send Large Composition Data Get message. * - * This API is used to read a portion of a page of the Composition Data. + * This API is used to read a portion of a Composition Data Page. + * + * This API can be used asynchronously by setting @p rsp as NULL. This way, the + * method will not wait for a response and will return immediately after sending + * the command. + * + * When @c rsp is set, the user is responsible for providing a buffer for the + * Composition Data in @ref bt_mesh_large_comp_data_rsp::data. If a buffer is + * not provided, the metadata won't be copied. * * @param net_idx Network index to encrypt with. * @param addr Target node element address. - * @param page Composition Data page to read. + * @param page Composition Data Page to read. * @param offset Offset within the Composition Data Page. - * @param comp Output buffer for storing received Composition data. + * @param rsp Pointer to a struct storing the received response from + * the server, or NULL to not wait for a response. * * @return 0 on success, or (negative) error code on failure. */ int bt_mesh_large_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page, - size_t offset, struct net_buf_simple *comp); + size_t offset, struct bt_mesh_large_comp_data_rsp *rsp); /** @brief Send Models Metadata Get message. * - * This API is used to read a portion of a page of the Models Metadata state. + * This API is used to read a portion of a Models Metadata Page. + * + * This API can be used asynchronously by setting @p rsp as NULL. This way, the + * method will not wait for a response and will return immediately after sending + * the command. + * + * When @c rsp is set, a user is responsible for providing a buffer for + * metadata in @ref bt_mesh_large_comp_data_rsp::data. If a buffer is not + * provided, the metadata won't be copied. * * @param net_idx Network index to encrypt with. * @param addr Target node element address. - * @param page Models Metadata page to read. + * @param page Models Metadata Page to read. * @param offset Offset within the Models Metadata Page. - * @param metadata Output buffer for storing received Models Metadata. + * @param rsp Pointer to a struct storing the received response from + * the server, or NULL to not wait for a response. * * @return 0 on success, or (negative) error code on failure. */ int bt_mesh_models_metadata_get(uint16_t net_idx, uint16_t addr, uint8_t page, - size_t offset, struct net_buf_simple *metadata); + size_t offset, struct bt_mesh_large_comp_data_rsp *rsp); /** @cond INTERNAL_HIDDEN */ extern const struct bt_mesh_model_op _bt_mesh_large_comp_data_cli_op[]; diff --git a/subsys/bluetooth/mesh/large_comp_data_cli.c b/subsys/bluetooth/mesh/large_comp_data_cli.c index 47c8db5b1f5..614569d54ae 100644 --- a/subsys/bluetooth/mesh/large_comp_data_cli.c +++ b/subsys/bluetooth/mesh/large_comp_data_cli.c @@ -30,63 +30,68 @@ LOG_MODULE_REGISTER(bt_mesh_large_comp_data_cli); #include "access.h" #include "foundation.h" -/** Mesh Large Composition Data Client Model Context */ -static struct bt_mesh_large_comp_data_cli { - /** Composition data model entry pointer. */ - struct bt_mesh_model *model; - - /* Internal parameters for tracking message responses. */ - struct bt_mesh_msg_ack_ctx ack_ctx; -} cli; - +static struct bt_mesh_large_comp_data_cli *cli; static int32_t msg_timeout; -static int large_comp_data_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) +static int data_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf, uint32_t op, + void (*cb)(struct bt_mesh_large_comp_data_cli *cli, uint16_t addr, + struct bt_mesh_large_comp_data_rsp *rsp)) { - struct net_buf_simple *comp; - size_t to_copy; + struct bt_mesh_large_comp_data_rsp *rsp; + uint8_t page; + uint16_t offset; + uint16_t total_size; LOG_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - if (!bt_mesh_msg_ack_ctx_match(&cli.ack_ctx, OP_LARGE_COMP_DATA_STATUS, - ctx->addr, (void **)&comp)) { - return 0; + page = net_buf_simple_pull_u8(buf); + offset = net_buf_simple_pull_le16(buf); + total_size = net_buf_simple_pull_le16(buf); + + if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, op, ctx->addr, (void **)&rsp)) { + rsp->page = page; + rsp->offset = offset; + rsp->total_size = total_size; + + if (rsp->data) { + net_buf_simple_add_mem(rsp->data, buf->data, + MIN(net_buf_simple_tailroom(rsp->data), buf->len)); + } + + bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); } - to_copy = MIN(net_buf_simple_tailroom(comp), buf->len); - net_buf_simple_add_mem(comp, buf->data, to_copy); + if (cb) { + struct bt_mesh_large_comp_data_rsp status_rsp = { + .page = page, + .offset = offset, + .total_size = total_size, + .data = buf, + }; - bt_mesh_msg_ack_ctx_rx(&cli.ack_ctx); + cb(cli, ctx->addr, &status_rsp); + } return 0; } +static int large_comp_data_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) +{ + return data_status(model, ctx, buf, OP_LARGE_COMP_DATA_STATUS, + (cli->cb && cli->cb->large_comp_data_status ? + cli->cb->large_comp_data_status : NULL)); +} + static int models_metadata_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - struct net_buf_simple *metadata; - size_t to_copy; - - LOG_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", - ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, - bt_hex(buf->data, buf->len)); - - if (!bt_mesh_msg_ack_ctx_match(&cli.ack_ctx, OP_MODELS_METADATA_STATUS, - ctx->addr, (void **)&metadata)) { - return 0; - } - - metadata = (struct net_buf_simple *)cli.ack_ctx.user_data; - - to_copy = MIN(net_buf_simple_tailroom(metadata), buf->len); - net_buf_simple_add_mem(metadata, buf->data, to_copy); - - bt_mesh_msg_ack_ctx_rx(&cli.ack_ctx); - - return 0; + return data_status(model, ctx, buf, OP_MODELS_METADATA_STATUS, + (cli->cb && cli->cb->models_metadata_status ? + cli->cb->models_metadata_status : NULL)); } const struct bt_mesh_model_op _bt_mesh_large_comp_data_cli_op[] = { @@ -98,17 +103,18 @@ const struct bt_mesh_model_op _bt_mesh_large_comp_data_cli_op[] = { static int large_comp_data_cli_init(struct bt_mesh_model *model) { if (!bt_mesh_model_in_primary(model)) { - LOG_ERR("Configuration Client only allowed in primary element"); + LOG_ERR("Large Comp Data Client only allowed in primary element"); return -EINVAL; } model->keys[0] = BT_MESH_KEY_DEV_ANY; model->flags |= BT_MESH_MOD_DEVKEY_ONLY; - cli.model = model; + cli = model->user_data; + cli->model = model; msg_timeout = 5000; - bt_mesh_msg_ack_ctx_init(&cli.ack_ctx); + bt_mesh_msg_ack_ctx_init(&cli->ack_ctx); return 0; } @@ -117,40 +123,35 @@ const struct bt_mesh_model_cb _bt_mesh_large_comp_data_cli_cb = { .init = large_comp_data_cli_init, }; -int bt_mesh_large_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page, - size_t offset, struct net_buf_simple *comp) +static int data_get(uint16_t net_idx, uint16_t addr, uint32_t op, uint32_t status_op, uint8_t page, + size_t offset, struct bt_mesh_large_comp_data_rsp *rsp) { - BT_MESH_MODEL_BUF_DEFINE(msg, OP_LARGE_COMP_DATA_GET, 3); + BT_MESH_MODEL_BUF_DEFINE(msg, op, 3); struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); - const struct bt_mesh_msg_rsp_ctx rsp = { - .ack = &cli.ack_ctx, - .op = OP_LARGE_COMP_DATA_STATUS, - .user_data = comp, + const struct bt_mesh_msg_rsp_ctx rsp_ctx = { + .ack = &cli->ack_ctx, + .op = status_op, + .user_data = rsp, .timeout = msg_timeout, }; - bt_mesh_model_msg_init(&msg, OP_LARGE_COMP_DATA_GET); + bt_mesh_model_msg_init(&msg, op); net_buf_simple_add_u8(&msg, page); net_buf_simple_add_le16(&msg, offset); - return bt_mesh_msg_ackd_send(cli.model, &ctx, &msg, comp ? &rsp : NULL); + return bt_mesh_msg_ackd_send(cli->model, &ctx, &msg, rsp ? &rsp_ctx : NULL); +} + +int bt_mesh_large_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page, + size_t offset, struct bt_mesh_large_comp_data_rsp *rsp) +{ + return data_get(net_idx, addr, OP_LARGE_COMP_DATA_GET, OP_LARGE_COMP_DATA_STATUS, + page, offset, rsp); } int bt_mesh_models_metadata_get(uint16_t net_idx, uint16_t addr, uint8_t page, - size_t offset, struct net_buf_simple *metadata) + size_t offset, struct bt_mesh_large_comp_data_rsp *rsp) { - BT_MESH_MODEL_BUF_DEFINE(msg, OP_MODELS_METADATA_STATUS, 3); - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); - const struct bt_mesh_msg_rsp_ctx rsp = { - .ack = &cli.ack_ctx, - .op = OP_MODELS_METADATA_STATUS, - .user_data = metadata, - .timeout = msg_timeout, - }; - - bt_mesh_model_msg_init(&msg, OP_MODELS_METADATA_GET); - net_buf_simple_add_u8(&msg, page); - net_buf_simple_add_le16(&msg, offset); - - return bt_mesh_msg_ackd_send(cli.model, &ctx, &msg, metadata ? &rsp : NULL); + return data_get(net_idx, addr, OP_MODELS_METADATA_GET, OP_MODELS_METADATA_STATUS, + page, offset, rsp); } diff --git a/subsys/bluetooth/mesh/shell/large_comp_data.c b/subsys/bluetooth/mesh/shell/large_comp_data.c index d278bbfc936..750f7b318fd 100644 --- a/subsys/bluetooth/mesh/shell/large_comp_data.c +++ b/subsys/bluetooth/mesh/shell/large_comp_data.c @@ -11,9 +11,28 @@ #include "utils.h" +extern const struct shell *bt_mesh_shell_ctx_shell; + +static void status_print(int err, char *msg, uint16_t addr, struct bt_mesh_large_comp_data_rsp *rsp) +{ + if (err) { + shell_error(bt_mesh_shell_ctx_shell, + "Failed to send %s Get message (err %d)", msg, err); + return; + } + + shell_print(bt_mesh_shell_ctx_shell, + "%s [0x%04x]: page: %u offset: %u total size: %u", msg, addr, rsp->page, + rsp->offset, rsp->total_size); + shell_hexdump(bt_mesh_shell_ctx_shell, rsp->data->data, rsp->data->len); +} + static int cmd_large_comp_data_get(const struct shell *sh, size_t argc, char *argv[]) { NET_BUF_SIMPLE_DEFINE(comp, 64); + struct bt_mesh_large_comp_data_rsp rsp = { + .data = &comp, + }; uint8_t page; uint16_t offset; int err = 0; @@ -29,21 +48,18 @@ static int cmd_large_comp_data_get(const struct shell *sh, size_t argc, char *ar } err = bt_mesh_large_comp_data_get(bt_mesh_shell_target_ctx.net_idx, - bt_mesh_shell_target_ctx.dst, page, offset, - &comp); - if (err) { - shell_print(sh, "Failed to send Large Composition Data Get (err=%d)", err); - return err; - } + bt_mesh_shell_target_ctx.dst, page, offset, &rsp); + status_print(err, "Composition Data", bt_mesh_shell_target_ctx.dst, &rsp); - shell_print(sh, "Large Composition Data Get len=%d", comp.len); - - return 0; + return err; } static int cmd_models_metadata_get(const struct shell *sh, size_t argc, char *argv[]) { NET_BUF_SIMPLE_DEFINE(metadata, 64); + struct bt_mesh_large_comp_data_rsp rsp = { + .data = &metadata, + }; uint8_t page; uint16_t offset; int err = 0; @@ -59,16 +75,10 @@ static int cmd_models_metadata_get(const struct shell *sh, size_t argc, char *ar } err = bt_mesh_models_metadata_get(bt_mesh_shell_target_ctx.net_idx, - bt_mesh_shell_target_ctx.dst, page, offset, - &metadata); - if (err) { - shell_print(sh, "Failed to send Models Metadata Get (err=%d)", err); - return err; - } + bt_mesh_shell_target_ctx.dst, page, offset, &rsp); + status_print(err, "Models Metadata", bt_mesh_shell_target_ctx.dst, &rsp); - shell_print(sh, "Models Metadata Get len=%d", metadata.len); - - return 0; + return err; } SHELL_STATIC_SUBCMD_SET_CREATE( diff --git a/tests/bluetooth/mesh_shell/src/main.c b/tests/bluetooth/mesh_shell/src/main.c index e2b2a5ad60d..4e0394c234d 100644 --- a/tests/bluetooth/mesh_shell/src/main.c +++ b/tests/bluetooth/mesh_shell/src/main.c @@ -37,6 +37,10 @@ static struct bt_mesh_sol_pdu_rpl_cli srpl_cli; static struct bt_mesh_od_priv_proxy_cli od_priv_proxy_cli; #endif +#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) +struct bt_mesh_large_comp_data_cli large_comp_data_cli; +#endif + BT_MESH_SHELL_HEALTH_PUB_DEFINE(health_pub); static struct bt_mesh_model root_models[] = { @@ -83,7 +87,7 @@ static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_LARGE_COMP_DATA_SRV, #endif #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) - BT_MESH_MODEL_LARGE_COMP_DATA_CLI, + BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&large_comp_data_cli), #endif #if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV) diff --git a/tests/bsim/bluetooth/mesh/src/test_lcd.c b/tests/bsim/bluetooth/mesh/src/test_lcd.c index 7797a185474..1dc5fc70054 100644 --- a/tests/bsim/bluetooth/mesh/src/test_lcd.c +++ b/tests/bsim/bluetooth/mesh/src/test_lcd.c @@ -27,6 +27,7 @@ LOG_MODULE_REGISTER(test_lcd, LOG_LEVEL_INF); #define DUMMY_2_BYTE_OP BT_MESH_MODEL_OP_2(0xff, 0xff) #define BT_MESH_LCD_PAYLOAD_MAX \ (BT_MESH_TX_SDU_MAX - BT_MESH_MODEL_OP_LEN(DUMMY_2_BYTE_OP) - \ + LCD_STATUS_FIELDS_LEN - \ BT_MESH_MIC_SHORT) /* 378 bytes */ #define TEST_MODEL_CNT_CB(_dummy_op, _metadata) \ @@ -67,13 +68,14 @@ static const struct bt_mesh_test_cfg srv_cfg = { static struct bt_mesh_prov prov; static struct bt_mesh_cfg_cli cfg_cli; +static struct bt_mesh_large_comp_data_cli lcd_cli; /* Creates enough composition data to send a max SDU comp status message + 1 byte */ static struct bt_mesh_elem elements_1[] = { BT_MESH_ELEM(1, MODEL_LIST(BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_LARGE_COMP_DATA_CLI, + BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli), BT_MESH_MODEL_LARGE_COMP_DATA_SRV), BT_MESH_MODEL_NONE), LISTIFY(88, DUMMY_ELEM, (,)), @@ -84,7 +86,7 @@ static struct bt_mesh_elem elements_2[] = { BT_MESH_ELEM(1, MODEL_LIST(BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_LARGE_COMP_DATA_CLI, + BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli), BT_MESH_MODEL_LARGE_COMP_DATA_SRV), BT_MESH_MODEL_NONE), LISTIFY(186, DUMMY_ELEM, (,)), @@ -140,16 +142,12 @@ static void merge_and_compare_assert(struct net_buf_simple *sample1, struct net_ /* Assert that the received status fields are equal to local values. Buffer state is saved. */ -static void verify_status_fields(struct net_buf_simple *srv_rsp, uint8_t page_local, +static void verify_status_fields(struct bt_mesh_large_comp_data_rsp *srv_rsp, uint8_t page_local, uint16_t offset_local, uint16_t total_size_local) { - uint8_t byte_value[LCD_STATUS_FIELDS_LEN]; - - byte_value[0] = page_local; - memcpy(&byte_value[1], &offset_local, 2); - memcpy(&byte_value[3], &total_size_local, 2); - - ASSERT_TRUE(memcmp(srv_rsp->data, byte_value, LCD_STATUS_FIELDS_LEN) == 0); + ASSERT_EQUAL(page_local, srv_rsp->page); + ASSERT_EQUAL(offset_local, srv_rsp->offset); + ASSERT_EQUAL(total_size_local, srv_rsp->total_size); } /* Compare response data with local data. @@ -158,7 +156,7 @@ static void verify_status_fields(struct net_buf_simple *srv_rsp, uint8_t page_lo * * local_data: state is preserved. * * prev_len: Set to NULL if irrelevant. Used for split and merge testing. */ -static void rsp_equals_local_data_assert(uint16_t addr, struct net_buf_simple *srv_rsp, +static void rsp_equals_local_data_assert(uint16_t addr, struct bt_mesh_large_comp_data_rsp *srv_rsp, struct net_buf_simple *local_data, uint8_t page, uint16_t offset, uint16_t total_size, uint16_t *prev_len) { @@ -166,8 +164,6 @@ static void rsp_equals_local_data_assert(uint16_t addr, struct net_buf_simple *s /* Check that status field data matches local values. */ verify_status_fields(srv_rsp, page, offset, total_size); - /* Remove field data bytes before comparing comp data */ - net_buf_simple_pull_mem(srv_rsp, LCD_STATUS_FIELDS_LEN); net_buf_simple_save(local_data, &local_state); @@ -178,7 +174,7 @@ static void rsp_equals_local_data_assert(uint16_t addr, struct net_buf_simple *s } /* Check that local and rsp data are equal */ - ASSERT_TRUE(memcmp(srv_rsp->data, local_data->data, srv_rsp->len) == 0); + ASSERT_TRUE(memcmp(srv_rsp->data->data, local_data->data, srv_rsp->data->len) == 0); net_buf_simple_restore(local_data, &local_state); } @@ -200,9 +196,13 @@ static void test_cli_max_sdu_comp_data_request(void) uint16_t offset, total_size; NET_BUF_SIMPLE_DEFINE(local_comp, 500); - NET_BUF_SIMPLE_DEFINE(srv_rsp, 500); + NET_BUF_SIMPLE_DEFINE(srv_rsp_comp, 500); net_buf_simple_init(&local_comp, 0); - net_buf_simple_init(&srv_rsp, 0); + net_buf_simple_init(&srv_rsp_comp, 0); + + struct bt_mesh_large_comp_data_rsp srv_rsp = { + .data = &srv_rsp_comp, + }; bt_mesh_device_setup(&prov, &comp_1); prov_and_conf(cli_cfg); @@ -223,7 +223,7 @@ static void test_cli_max_sdu_comp_data_request(void) /* Get server composition data and check integrity */ ASSERT_OK(bt_mesh_large_comp_data_get(0, SRV_ADDR, page, offset, &srv_rsp)); - ASSERT_EQUAL(srv_rsp.len, BT_MESH_LCD_PAYLOAD_MAX); + ASSERT_EQUAL(srv_rsp_comp.len, BT_MESH_LCD_PAYLOAD_MAX); rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp, &local_comp, page, offset, total_size, NULL); @@ -237,11 +237,18 @@ static void test_cli_split_comp_data_request(void) uint16_t offset, total_size, prev_len = 0; NET_BUF_SIMPLE_DEFINE(local_comp, 200); - NET_BUF_SIMPLE_DEFINE(srv_rsp_1, 64); - NET_BUF_SIMPLE_DEFINE(srv_rsp_2, 64); + NET_BUF_SIMPLE_DEFINE(srv_rsp_comp_1, 64); + NET_BUF_SIMPLE_DEFINE(srv_rsp_comp_2, 64); net_buf_simple_init(&local_comp, 0); - net_buf_simple_init(&srv_rsp_1, 0); - net_buf_simple_init(&srv_rsp_2, 0); + net_buf_simple_init(&srv_rsp_comp_1, 0); + net_buf_simple_init(&srv_rsp_comp_2, 0); + + struct bt_mesh_large_comp_data_rsp srv_rsp_1 = { + .data = &srv_rsp_comp_1, + }; + struct bt_mesh_large_comp_data_rsp srv_rsp_2 = { + .data = &srv_rsp_comp_2, + }; bt_mesh_device_setup(&prov, &comp_1); prov_and_conf(cli_cfg); @@ -262,7 +269,7 @@ static void test_cli_split_comp_data_request(void) rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp_1, &local_comp, page, offset, total_size, &prev_len); - prev_len = srv_rsp_1.len; + prev_len = srv_rsp_comp_1.len; offset += prev_len; /* Get next server composition data sample */ @@ -271,7 +278,7 @@ static void test_cli_split_comp_data_request(void) &prev_len); /* Check data integrity of merged sample data */ - merge_and_compare_assert(&srv_rsp_1, &srv_rsp_2, &local_comp); + merge_and_compare_assert(&srv_rsp_comp_1, &srv_rsp_comp_2, &local_comp); PASS(); } @@ -283,9 +290,13 @@ static void test_cli_max_sdu_metadata_request(void) uint16_t offset, total_size; NET_BUF_SIMPLE_DEFINE(local_metadata, 500); - NET_BUF_SIMPLE_DEFINE(srv_rsp, 500); + NET_BUF_SIMPLE_DEFINE(srv_rsp_metadata, 500); net_buf_simple_init(&local_metadata, 0); - net_buf_simple_init(&srv_rsp, 0); + net_buf_simple_init(&srv_rsp_metadata, 0); + + struct bt_mesh_large_comp_data_rsp srv_rsp = { + .data = &srv_rsp_metadata, + }; bt_mesh_device_setup(&prov, &comp_2); prov_and_conf(cli_cfg); @@ -306,7 +317,7 @@ static void test_cli_max_sdu_metadata_request(void) /* Get server metadata and check integrity */ ASSERT_OK(bt_mesh_models_metadata_get(0, SRV_ADDR, page, offset, &srv_rsp)); - ASSERT_EQUAL(srv_rsp.len, BT_MESH_LCD_PAYLOAD_MAX); + ASSERT_EQUAL(srv_rsp_metadata.len, BT_MESH_LCD_PAYLOAD_MAX); rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp, &local_metadata, page, offset, total_size, NULL); @@ -319,11 +330,18 @@ static void test_cli_split_metadata_request(void) uint16_t offset, total_size, prev_len = 0; NET_BUF_SIMPLE_DEFINE(local_metadata, 500); - NET_BUF_SIMPLE_DEFINE(srv_rsp_1, 64); - NET_BUF_SIMPLE_DEFINE(srv_rsp_2, 64); + NET_BUF_SIMPLE_DEFINE(srv_rsp_metadata_1, 64); + NET_BUF_SIMPLE_DEFINE(srv_rsp_metadata_2, 64); net_buf_simple_init(&local_metadata, 0); - net_buf_simple_init(&srv_rsp_1, 0); - net_buf_simple_init(&srv_rsp_2, 0); + net_buf_simple_init(&srv_rsp_metadata_1, 0); + net_buf_simple_init(&srv_rsp_metadata_2, 0); + + struct bt_mesh_large_comp_data_rsp srv_rsp_1 = { + .data = &srv_rsp_metadata_1, + }; + struct bt_mesh_large_comp_data_rsp srv_rsp_2 = { + .data = &srv_rsp_metadata_2, + }; bt_mesh_device_setup(&prov, &comp_2); prov_and_conf(cli_cfg); @@ -344,7 +362,7 @@ static void test_cli_split_metadata_request(void) rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp_1, &local_metadata, page, offset, total_size, &prev_len); - prev_len = srv_rsp_1.len; + prev_len = srv_rsp_metadata_1.len; offset += prev_len; /* Get next server composition data sample and check integrity */ @@ -353,7 +371,7 @@ static void test_cli_split_metadata_request(void) total_size, &prev_len); /* Check data integrity of merged sample data */ - merge_and_compare_assert(&srv_rsp_1, &srv_rsp_2, &local_metadata); + merge_and_compare_assert(&srv_rsp_metadata_1, &srv_rsp_metadata_2, &local_metadata); PASS(); }