Bluetooth: Mesh: Add support for sending Get Composition Data
Add Get Composition Data support to the Configuration Client Model. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
588887c9b7
commit
3d1ce43eb0
4 changed files with 122 additions and 1 deletions
|
@ -18,7 +18,12 @@
|
|||
*/
|
||||
|
||||
/** Mesh Configuration Client Model Context */
|
||||
struct bt_mesh_cli {
|
||||
struct bt_mesh_cfg_cli {
|
||||
struct bt_mesh_model *model;
|
||||
|
||||
struct k_sem op_sync;
|
||||
u32_t op_pending;
|
||||
void *op_param;
|
||||
};
|
||||
|
||||
extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
|
||||
|
@ -27,6 +32,9 @@ extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
|
|||
BT_MESH_MODEL(BT_MESH_MODEL_ID_CFG_CLI, \
|
||||
bt_mesh_cfg_cli_op, NULL, cli_data)
|
||||
|
||||
int bt_mesh_cfg_comp_data_get(u16_t net_idx, u16_t addr, u8_t page,
|
||||
u8_t *status, struct net_buf_simple *comp);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -35,6 +35,9 @@ static const struct {
|
|||
} const model_init[] = {
|
||||
{ BT_MESH_MODEL_ID_CFG_SRV, bt_mesh_conf_init },
|
||||
{ BT_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_init },
|
||||
#if defined(CONFIG_BT_MESH_CFG_CLI)
|
||||
{ BT_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_init },
|
||||
#endif
|
||||
};
|
||||
|
||||
void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
|
||||
|
|
|
@ -21,6 +21,114 @@
|
|||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
|
||||
#include "common/log.h"
|
||||
|
||||
#include "foundation.h"
|
||||
|
||||
#define MSG_TIMEOUT K_SECONDS(10)
|
||||
|
||||
struct comp_data {
|
||||
u8_t *status;
|
||||
struct net_buf_simple *comp;
|
||||
};
|
||||
|
||||
static struct bt_mesh_cfg_cli *cli;
|
||||
|
||||
static void comp_data_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct comp_data *param;
|
||||
size_t to_copy;
|
||||
|
||||
BT_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 (cli->op_pending != OP_DEV_COMP_DATA_STATUS) {
|
||||
BT_WARN("Unexpected Composition Data Status");
|
||||
return;
|
||||
}
|
||||
|
||||
param = cli->op_param;
|
||||
|
||||
*(param->status) = net_buf_simple_pull_u8(buf);
|
||||
to_copy = min(net_buf_simple_tailroom(param->comp), buf->len);
|
||||
net_buf_simple_add_mem(param->comp, buf->data, to_copy);
|
||||
|
||||
k_sem_give(&cli->op_sync);
|
||||
}
|
||||
|
||||
const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
|
||||
{ OP_DEV_COMP_DATA_STATUS, 15, comp_data_status },
|
||||
BT_MESH_MODEL_OP_END,
|
||||
};
|
||||
|
||||
int bt_mesh_cfg_comp_data_get(u16_t net_idx, u16_t addr, u8_t page,
|
||||
u8_t *status, struct net_buf_simple *comp)
|
||||
{
|
||||
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 1 + 4);
|
||||
struct bt_mesh_msg_ctx ctx = {
|
||||
.net_idx = net_idx,
|
||||
.app_idx = BT_MESH_KEY_DEV,
|
||||
.addr = addr,
|
||||
.send_ttl = BT_MESH_TTL_DEFAULT,
|
||||
};
|
||||
struct comp_data param = {
|
||||
.status = status,
|
||||
.comp = comp,
|
||||
};
|
||||
int err;
|
||||
|
||||
if (!cli) {
|
||||
BT_ERR("No available Configuration Client context!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (cli->op_pending) {
|
||||
BT_WARN("Another synchronous operation pending");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
bt_mesh_model_msg_init(msg, OP_DEV_COMP_DATA_GET);
|
||||
net_buf_simple_add_u8(msg, page);
|
||||
|
||||
err = bt_mesh_model_send(cli->model, &ctx, msg, NULL, NULL);
|
||||
if (err) {
|
||||
BT_ERR("model_send() failed (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_DEV_COMP_DATA_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
BT_DBG("primary %u", primary);
|
||||
|
||||
if (!primary) {
|
||||
BT_ERR("Configuration Client only allowed in primary element");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!model->user_data) {
|
||||
BT_ERR("No Configuration Client context provided");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cli = model->user_data;
|
||||
cli->model = model;
|
||||
|
||||
/* Configuration Model security is device-key based */
|
||||
model->keys[0] = BT_MESH_KEY_DEV;
|
||||
|
||||
k_sem_init(&cli->op_sync, 0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -115,6 +115,8 @@
|
|||
int bt_mesh_conf_init(struct bt_mesh_model *model, bool primary);
|
||||
int bt_mesh_health_init(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
void bt_mesh_heartbeat(u16_t src, u16_t dst, u8_t hops, u16_t feat);
|
||||
|
||||
void bt_mesh_attention(struct bt_mesh_model *model, u8_t time);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue