Bluetooth: Mesh: Add async API for Large Comp Data Client
Add asynchronous API for Large Composition Data Client. Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
This commit is contained in:
parent
b99d4dbce2
commit
c4fa085ec4
5 changed files with 241 additions and 129 deletions
|
@ -19,44 +19,123 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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 \
|
#define BT_MESH_MODEL_LARGE_COMP_DATA_CLI(cli_data) \
|
||||||
BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_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, \
|
_bt_mesh_large_comp_data_cli_op, NULL, cli_data, \
|
||||||
&_bt_mesh_large_comp_data_cli_cb)
|
&_bt_mesh_large_comp_data_cli_cb)
|
||||||
|
|
||||||
/** @brief Send Large Composition Data Get message.
|
/** @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 net_idx Network index to encrypt with.
|
||||||
* @param addr Target node element address.
|
* @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 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.
|
* @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,
|
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.
|
/** @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 net_idx Network index to encrypt with.
|
||||||
* @param addr Target node element address.
|
* @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 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.
|
* @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,
|
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 */
|
/** @cond INTERNAL_HIDDEN */
|
||||||
extern const struct bt_mesh_model_op _bt_mesh_large_comp_data_cli_op[];
|
extern const struct bt_mesh_model_op _bt_mesh_large_comp_data_cli_op[];
|
||||||
|
|
|
@ -30,63 +30,68 @@ LOG_MODULE_REGISTER(bt_mesh_large_comp_data_cli);
|
||||||
#include "access.h"
|
#include "access.h"
|
||||||
#include "foundation.h"
|
#include "foundation.h"
|
||||||
|
|
||||||
/** Mesh Large Composition Data Client Model Context */
|
static struct bt_mesh_large_comp_data_cli *cli;
|
||||||
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 int32_t msg_timeout;
|
static int32_t msg_timeout;
|
||||||
|
|
||||||
static int large_comp_data_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
|
static int data_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
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;
|
struct bt_mesh_large_comp_data_rsp *rsp;
|
||||||
size_t to_copy;
|
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",
|
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,
|
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||||
bt_hex(buf->data, buf->len));
|
bt_hex(buf->data, buf->len));
|
||||||
|
|
||||||
if (!bt_mesh_msg_ack_ctx_match(&cli.ack_ctx, OP_LARGE_COMP_DATA_STATUS,
|
page = net_buf_simple_pull_u8(buf);
|
||||||
ctx->addr, (void **)&comp)) {
|
offset = net_buf_simple_pull_le16(buf);
|
||||||
return 0;
|
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);
|
if (cb) {
|
||||||
net_buf_simple_add_mem(comp, buf->data, to_copy);
|
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;
|
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,
|
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 *buf)
|
||||||
{
|
{
|
||||||
struct net_buf_simple *metadata;
|
return data_status(model, ctx, buf, OP_MODELS_METADATA_STATUS,
|
||||||
size_t to_copy;
|
(cli->cb && cli->cb->models_metadata_status ?
|
||||||
|
cli->cb->models_metadata_status : NULL));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct bt_mesh_model_op _bt_mesh_large_comp_data_cli_op[] = {
|
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)
|
static int large_comp_data_cli_init(struct bt_mesh_model *model)
|
||||||
{
|
{
|
||||||
if (!bt_mesh_model_in_primary(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;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
model->keys[0] = BT_MESH_KEY_DEV_ANY;
|
model->keys[0] = BT_MESH_KEY_DEV_ANY;
|
||||||
model->flags |= BT_MESH_MOD_DEVKEY_ONLY;
|
model->flags |= BT_MESH_MOD_DEVKEY_ONLY;
|
||||||
|
|
||||||
cli.model = model;
|
cli = model->user_data;
|
||||||
|
cli->model = model;
|
||||||
|
|
||||||
msg_timeout = 5000;
|
msg_timeout = 5000;
|
||||||
bt_mesh_msg_ack_ctx_init(&cli.ack_ctx);
|
bt_mesh_msg_ack_ctx_init(&cli->ack_ctx);
|
||||||
|
|
||||||
return 0;
|
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,
|
.init = large_comp_data_cli_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
int bt_mesh_large_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page,
|
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 net_buf_simple *comp)
|
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);
|
struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr);
|
||||||
const struct bt_mesh_msg_rsp_ctx rsp = {
|
const struct bt_mesh_msg_rsp_ctx rsp_ctx = {
|
||||||
.ack = &cli.ack_ctx,
|
.ack = &cli->ack_ctx,
|
||||||
.op = OP_LARGE_COMP_DATA_STATUS,
|
.op = status_op,
|
||||||
.user_data = comp,
|
.user_data = rsp,
|
||||||
.timeout = msg_timeout,
|
.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_u8(&msg, page);
|
||||||
net_buf_simple_add_le16(&msg, offset);
|
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,
|
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);
|
return data_get(net_idx, addr, OP_MODELS_METADATA_GET, OP_MODELS_METADATA_STATUS,
|
||||||
struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr);
|
page, offset, rsp);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,28 @@
|
||||||
|
|
||||||
#include "utils.h"
|
#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[])
|
static int cmd_large_comp_data_get(const struct shell *sh, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DEFINE(comp, 64);
|
NET_BUF_SIMPLE_DEFINE(comp, 64);
|
||||||
|
struct bt_mesh_large_comp_data_rsp rsp = {
|
||||||
|
.data = &comp,
|
||||||
|
};
|
||||||
uint8_t page;
|
uint8_t page;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
int err = 0;
|
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,
|
err = bt_mesh_large_comp_data_get(bt_mesh_shell_target_ctx.net_idx,
|
||||||
bt_mesh_shell_target_ctx.dst, page, offset,
|
bt_mesh_shell_target_ctx.dst, page, offset, &rsp);
|
||||||
&comp);
|
status_print(err, "Composition Data", bt_mesh_shell_target_ctx.dst, &rsp);
|
||||||
if (err) {
|
|
||||||
shell_print(sh, "Failed to send Large Composition Data Get (err=%d)", err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
shell_print(sh, "Large Composition Data Get len=%d", comp.len);
|
return err;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_models_metadata_get(const struct shell *sh, size_t argc, char *argv[])
|
static int cmd_models_metadata_get(const struct shell *sh, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DEFINE(metadata, 64);
|
NET_BUF_SIMPLE_DEFINE(metadata, 64);
|
||||||
|
struct bt_mesh_large_comp_data_rsp rsp = {
|
||||||
|
.data = &metadata,
|
||||||
|
};
|
||||||
uint8_t page;
|
uint8_t page;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
int err = 0;
|
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,
|
err = bt_mesh_models_metadata_get(bt_mesh_shell_target_ctx.net_idx,
|
||||||
bt_mesh_shell_target_ctx.dst, page, offset,
|
bt_mesh_shell_target_ctx.dst, page, offset, &rsp);
|
||||||
&metadata);
|
status_print(err, "Models Metadata", bt_mesh_shell_target_ctx.dst, &rsp);
|
||||||
if (err) {
|
|
||||||
shell_print(sh, "Failed to send Models Metadata Get (err=%d)", err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
shell_print(sh, "Models Metadata Get len=%d", metadata.len);
|
return err;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_STATIC_SUBCMD_SET_CREATE(
|
SHELL_STATIC_SUBCMD_SET_CREATE(
|
||||||
|
|
|
@ -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;
|
static struct bt_mesh_od_priv_proxy_cli od_priv_proxy_cli;
|
||||||
#endif
|
#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);
|
BT_MESH_SHELL_HEALTH_PUB_DEFINE(health_pub);
|
||||||
|
|
||||||
static struct bt_mesh_model root_models[] = {
|
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,
|
BT_MESH_MODEL_LARGE_COMP_DATA_SRV,
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI)
|
#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
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV)
|
#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV)
|
||||||
|
|
|
@ -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 DUMMY_2_BYTE_OP BT_MESH_MODEL_OP_2(0xff, 0xff)
|
||||||
#define BT_MESH_LCD_PAYLOAD_MAX \
|
#define BT_MESH_LCD_PAYLOAD_MAX \
|
||||||
(BT_MESH_TX_SDU_MAX - BT_MESH_MODEL_OP_LEN(DUMMY_2_BYTE_OP) - \
|
(BT_MESH_TX_SDU_MAX - BT_MESH_MODEL_OP_LEN(DUMMY_2_BYTE_OP) - \
|
||||||
|
LCD_STATUS_FIELDS_LEN - \
|
||||||
BT_MESH_MIC_SHORT) /* 378 bytes */
|
BT_MESH_MIC_SHORT) /* 378 bytes */
|
||||||
|
|
||||||
#define TEST_MODEL_CNT_CB(_dummy_op, _metadata) \
|
#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_prov prov;
|
||||||
static struct bt_mesh_cfg_cli cfg_cli;
|
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 */
|
/* Creates enough composition data to send a max SDU comp status message + 1 byte */
|
||||||
static struct bt_mesh_elem elements_1[] = {
|
static struct bt_mesh_elem elements_1[] = {
|
||||||
BT_MESH_ELEM(1,
|
BT_MESH_ELEM(1,
|
||||||
MODEL_LIST(BT_MESH_MODEL_CFG_SRV,
|
MODEL_LIST(BT_MESH_MODEL_CFG_SRV,
|
||||||
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
|
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_LARGE_COMP_DATA_SRV),
|
||||||
BT_MESH_MODEL_NONE),
|
BT_MESH_MODEL_NONE),
|
||||||
LISTIFY(88, DUMMY_ELEM, (,)),
|
LISTIFY(88, DUMMY_ELEM, (,)),
|
||||||
|
@ -84,7 +86,7 @@ static struct bt_mesh_elem elements_2[] = {
|
||||||
BT_MESH_ELEM(1,
|
BT_MESH_ELEM(1,
|
||||||
MODEL_LIST(BT_MESH_MODEL_CFG_SRV,
|
MODEL_LIST(BT_MESH_MODEL_CFG_SRV,
|
||||||
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
|
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_LARGE_COMP_DATA_SRV),
|
||||||
BT_MESH_MODEL_NONE),
|
BT_MESH_MODEL_NONE),
|
||||||
LISTIFY(186, DUMMY_ELEM, (,)),
|
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.
|
/* 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)
|
uint16_t offset_local, uint16_t total_size_local)
|
||||||
{
|
{
|
||||||
uint8_t byte_value[LCD_STATUS_FIELDS_LEN];
|
ASSERT_EQUAL(page_local, srv_rsp->page);
|
||||||
|
ASSERT_EQUAL(offset_local, srv_rsp->offset);
|
||||||
byte_value[0] = page_local;
|
ASSERT_EQUAL(total_size_local, srv_rsp->total_size);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compare response data with local data.
|
/* 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.
|
* * local_data: state is preserved.
|
||||||
* * prev_len: Set to NULL if irrelevant. Used for split and merge testing.
|
* * 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,
|
struct net_buf_simple *local_data, uint8_t page,
|
||||||
uint16_t offset, uint16_t total_size, uint16_t *prev_len)
|
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. */
|
/* Check that status field data matches local values. */
|
||||||
verify_status_fields(srv_rsp, page, offset, total_size);
|
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);
|
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 */
|
/* 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);
|
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;
|
uint16_t offset, total_size;
|
||||||
|
|
||||||
NET_BUF_SIMPLE_DEFINE(local_comp, 500);
|
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(&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);
|
bt_mesh_device_setup(&prov, &comp_1);
|
||||||
prov_and_conf(cli_cfg);
|
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 */
|
/* Get server composition data and check integrity */
|
||||||
ASSERT_OK(bt_mesh_large_comp_data_get(0, SRV_ADDR, page, offset, &srv_rsp));
|
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,
|
rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp, &local_comp, page, offset, total_size,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
@ -237,11 +237,18 @@ static void test_cli_split_comp_data_request(void)
|
||||||
uint16_t offset, total_size, prev_len = 0;
|
uint16_t offset, total_size, prev_len = 0;
|
||||||
|
|
||||||
NET_BUF_SIMPLE_DEFINE(local_comp, 200);
|
NET_BUF_SIMPLE_DEFINE(local_comp, 200);
|
||||||
NET_BUF_SIMPLE_DEFINE(srv_rsp_1, 64);
|
NET_BUF_SIMPLE_DEFINE(srv_rsp_comp_1, 64);
|
||||||
NET_BUF_SIMPLE_DEFINE(srv_rsp_2, 64);
|
NET_BUF_SIMPLE_DEFINE(srv_rsp_comp_2, 64);
|
||||||
net_buf_simple_init(&local_comp, 0);
|
net_buf_simple_init(&local_comp, 0);
|
||||||
net_buf_simple_init(&srv_rsp_1, 0);
|
net_buf_simple_init(&srv_rsp_comp_1, 0);
|
||||||
net_buf_simple_init(&srv_rsp_2, 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);
|
bt_mesh_device_setup(&prov, &comp_1);
|
||||||
prov_and_conf(cli_cfg);
|
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,
|
rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp_1, &local_comp, page, offset, total_size,
|
||||||
&prev_len);
|
&prev_len);
|
||||||
|
|
||||||
prev_len = srv_rsp_1.len;
|
prev_len = srv_rsp_comp_1.len;
|
||||||
offset += prev_len;
|
offset += prev_len;
|
||||||
|
|
||||||
/* Get next server composition data sample */
|
/* Get next server composition data sample */
|
||||||
|
@ -271,7 +278,7 @@ static void test_cli_split_comp_data_request(void)
|
||||||
&prev_len);
|
&prev_len);
|
||||||
|
|
||||||
/* Check data integrity of merged sample data */
|
/* 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();
|
PASS();
|
||||||
}
|
}
|
||||||
|
@ -283,9 +290,13 @@ static void test_cli_max_sdu_metadata_request(void)
|
||||||
uint16_t offset, total_size;
|
uint16_t offset, total_size;
|
||||||
|
|
||||||
NET_BUF_SIMPLE_DEFINE(local_metadata, 500);
|
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(&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);
|
bt_mesh_device_setup(&prov, &comp_2);
|
||||||
prov_and_conf(cli_cfg);
|
prov_and_conf(cli_cfg);
|
||||||
|
@ -306,7 +317,7 @@ static void test_cli_max_sdu_metadata_request(void)
|
||||||
|
|
||||||
/* Get server metadata and check integrity */
|
/* Get server metadata and check integrity */
|
||||||
ASSERT_OK(bt_mesh_models_metadata_get(0, SRV_ADDR, page, offset, &srv_rsp));
|
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,
|
rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp, &local_metadata, page, offset, total_size,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
@ -319,11 +330,18 @@ static void test_cli_split_metadata_request(void)
|
||||||
uint16_t offset, total_size, prev_len = 0;
|
uint16_t offset, total_size, prev_len = 0;
|
||||||
|
|
||||||
NET_BUF_SIMPLE_DEFINE(local_metadata, 500);
|
NET_BUF_SIMPLE_DEFINE(local_metadata, 500);
|
||||||
NET_BUF_SIMPLE_DEFINE(srv_rsp_1, 64);
|
NET_BUF_SIMPLE_DEFINE(srv_rsp_metadata_1, 64);
|
||||||
NET_BUF_SIMPLE_DEFINE(srv_rsp_2, 64);
|
NET_BUF_SIMPLE_DEFINE(srv_rsp_metadata_2, 64);
|
||||||
net_buf_simple_init(&local_metadata, 0);
|
net_buf_simple_init(&local_metadata, 0);
|
||||||
net_buf_simple_init(&srv_rsp_1, 0);
|
net_buf_simple_init(&srv_rsp_metadata_1, 0);
|
||||||
net_buf_simple_init(&srv_rsp_2, 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);
|
bt_mesh_device_setup(&prov, &comp_2);
|
||||||
prov_and_conf(cli_cfg);
|
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,
|
rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp_1, &local_metadata, page, offset,
|
||||||
total_size, &prev_len);
|
total_size, &prev_len);
|
||||||
|
|
||||||
prev_len = srv_rsp_1.len;
|
prev_len = srv_rsp_metadata_1.len;
|
||||||
offset += prev_len;
|
offset += prev_len;
|
||||||
|
|
||||||
/* Get next server composition data sample and check integrity */
|
/* 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);
|
total_size, &prev_len);
|
||||||
|
|
||||||
/* Check data integrity of merged sample data */
|
/* 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();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue